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
	Private p_ticketsdia As Panel
	
	Dim c As Cursor
	Dim S As Cursor
	Dim ruta As String
	Dim ListView1 As ListView
	Dim b_noventa As Button
	Dim nombre_boton As String
	Dim STIME As String
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("ticketsdia")
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
	c = B4XPages.MainPage.skmt.ExecQuery("select PC_CLIENTE,PC_MONTO,PC_NOART FROM PEDIDO_CLIENTE ORDER BY PC_FECHA 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 = 10
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 13
			label2.TextColor = Colors.Blue
			ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),"Cantidad #"& c.GetString("PC_NOART")& " SubTotal $"& c.GetString("PC_MONTO"))
		Next
	End If
End Sub

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

Sub B4XPage_Appear
	nombre_boton = "NOVENTA"
	c=B4XPages.MainPage.skmt.ExecQuery("select PC_CLIENTE,PC_MONTO,PC_NOART,(select CAT_CL_NOMBRE from kmt_info where cat_cl_codigo = pc_cliente ) as NOMBRE FROM PEDIDO_CLIENTE ORDER BY PC_FECHA asc")
	Dim noArticulos As Int = 0
	
	ListView1.Clear
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Dim x As Cursor = B4XPages.MainPage.skmt.ExecQuery($"select sum(PE_CANT) as PC_NOART from PEDIDO where PE_CLIENTE = '${c.GetString("PC_CLIENTE")}' AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)"$)
			If x.RowCount > 0 Then
				x.Position = 0
'				Log(x.GetString("PC_NOART"))
				noArticulos = x.GetString("PC_NOART")
			End If
			Dim label1 As Label
			label1 = ListView1.TwoLinesLayout.Label
			label1.TextSize = 10
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 13
			label2.TextColor = Colors.Blue
			ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& noArticulos & " SubTotal $"& c.GetString("PC_MONTO"))
		Next
	End If
	c.Close
End Sub

Sub Regresar_Click
	B4XPages.ShowPage("cliente")
End Sub
Sub Activity_KeyPress (key As Int) As Boolean
	' BACK key pressed
	If key=KeyCodes.KEYCODE_BACK Then
		' I want to capture the key here so I return True
		B4XPages.ShowPage("principal")
		'Return True
	End If
	' Returning False signals the system to handle the key
	Return False
End Sub
Sub ListView1_ItemLongClick (Position As Int, Value As Object)
	B4XPages.MainPage.skmt.ExecNonQuery("delete from CUENTAA")
	B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(Value))
	DateTime.TimeFormat = "HHmmss"
	STIME=DateTime.Time(DateTime.Now)
	s=B4XPages.MainPage.skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM HIST_STAY_STORE WHERE HSS_IN = 0 AND HSS_CODIGO In (select cuenta from cuentaa)")
	s.Position = 0
	If s.GetString("CUANTOS") = 1 Then
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_STORE set HSS_IN = ?  where HSS_IN = 0 AND HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(STIME))
	Else
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_STAY_STORE(HSS_CODIGO,  HSS_IN , HSS_OUT , HSS_TOT) VALUES (?,0,0,0)", Array As Object (Value))
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_STORE set HSS_IN = ?  where HSS_IN = 0 AND HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(STIME))
	End If
	DateTime.TimeFormat = "HH:mm:ss"
	Subs.guardaClienteHoraInicio(Value)
	B4XPages.MainPage.cliente.venimosDeTicketsDia = True
	B4XPages.ShowPage("cliente")
End Sub

Sub b_noventa_Click
	If nombre_boton = "NOVENTA" Then
		nombre_boton = "VENTA"
		b_noventa.Text ="VENTA"
		c=B4XPages.MainPage.skmt.ExecQuery("select NV_CLIENTE,NV_MOTIVO,NV_COMM, (select CAT_CL_NOMBRE from kmt_info where cat_cl_codigo = NV_CLIENTE ) as NOMBRE FROM NOVENTA ORDER BY NV_CLIENTE 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("NV_CLIENTE"),c.GetString("NOMBRE") &"  Motivo #"& c.GetString("NV_MOTIVO")& " Comentario $"& c.GetString("NV_COMM"))
			Next
		End If
	Else
		nombre_boton = "NOVENTA"
		b_noventa.Text ="NO VENTA"
		c=B4XPages.MainPage.skmt.ExecQuery("select PC_CLIENTE,PC_MONTO,PC_NOART,(select CAT_CL_NOMBRE from kmt_info where cat_cl_codigo = pc_cliente ) as NOMBRE FROM PEDIDO_CLIENTE ORDER BY PC_FECHA 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("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& c.GetString("PC_NOART")& " SubTotal $"& c.GetString("PC_MONTO"))
			Next
		End If
		c.Close
	End If
End Sub

Private Sub p_ticketsdia_Click
	
End Sub