B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore

	Dim g As GPS
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String
	
	Dim c As Cursor
	Dim ruta As String
	Dim Regresar As Button
	

	Dim ListView1 As ListView
	Dim L_CANT As Label
	Dim L_TOTAL As Label
	Dim borra As Button
	Dim Existe As String
	Dim result As String
	'    Dim lat_gps, lon_gps As String

	Private Titulo As Label
	Private b_desc As Button
	Private ListView2 As ListView
	Dim tgl As Toggle
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
	Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	'load the layout to Root
	ruta = File.DirInternal
	Root.LoadLayout("nota")
	borra.Visible = False
	Titulo.Text = "Acumulado"
	b_desc.Visible = False
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
'	skmt.Initialize(ruta,"kmt.db", True)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub B4XPage_Appear
	If Not(Starter.gps.GPSEnabled) Then
		ToastMessageShow("Es necesario tener el GPS encendido", True)
		StartActivity(Starter.gps.LocationSettingsIntent)
	End If
	L_CANT.Text =""
	L_TOTAL.Text=""
	c=B4XPages.MainPage.skmt.ExecQuery("select count(*) as EXISTE from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
	C.Position=0
	Existe = C.GetString("EXISTE")
	C.Close
	c=B4XPages.MainPage.skmt.ExecQuery("select HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) order by HVD_PRONOMBRE asc")
	ListView1.Clear
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Dim label1 As Label
			label1 = ListView1.TwoLinesLayout.Label
			label1.TextSize = 15
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 10
			label2.TextColor = Colors.Blue
			ListView1.AddTwoLines(c.GetString("HVD_PRONOMBRE"),"Cantidad #"& c.GetString("HVD_CANT")& " SubTotal $"& c.GetString("HVD_COSTO_TOT"))
		Next
	End If
	If Existe <> 0 Then
		c=B4XPages.MainPage.skmt.ExecQuery("select SUM(HVD_CANT) AS PC_NOART, SUM(HVD_COSTO_TOT) AS PC_MONTO from HIST_VENTAS where HVD_CLIENTE in (Select CUENTA from cuentaa)")
		C.Position=0
		L_CANT.Text = c.GetString("PC_NOART")
		L_TOTAL.Text = c.GetString("PC_MONTO")
	End If
End Sub

Sub GPS_LocationChanged (Location1 As Location)
	'lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
	'lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
End Sub

Sub Regresar_Click
	B4XPages.ShowPage("Cliente")
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
'	BACK key pressed
'	Return True To close, False To cancel
		B4XPages.ShowPage("Principal")
	Return False
End Sub

Sub ListView2_ItemClick (Position As Int, Value As Object)
	ListView2.Visible = False
	ListView1.Visible = True
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
	ListView2.Visible = True
	ListView1.Visible = False
	Dim label1 As Label
	For i=0 To 20
		label1 = ListView2.SingleLineLayout.Label
		label1.TextSize = 15
		label1.TextColor = Colors.Black
		ListView2.AddSingleLine(i)
	Next
End Sub