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

	Private L_ventanoventa As Label
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")
'	ListView1.Left = Round(Root.Width/2)-(ListView1.Width/2)
	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 = 20
			Label1.TextColor = Colors.White
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 20
			label2.TextColor = Colors.White
			Label1.Height = 25dip
			label2.Height = 60dip
			
			ListView1.TwoLinesLayout.ItemHeight = 95dip
			Label1.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
			label2.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
			ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),"Cantidad #"& c.GetString("PC_NOART")& " SubTotal $"& Subs.calculaTotalConPromoXRango(c.GetString("PC_CLIENTE")))
		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"
	L_ventanoventa.Text = "Clientes con venta"
	ListView1.Clear
	ListView1.Height = Root.Height * 0.70
	p_ticketsdia.Height = Root.Height * 0.80
	p_ticketsdia.Width = Root.Width * 0.90
	
	c=B4XPages.MainPage.skmt.ExecQuery("select PC_CLIENTE,PC_MONTO,PC_NOART,(select CAT_CL_NOMBRE from kmt_info3 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
						
			
			Private s3 As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select * FROM PEDIDO WHERE PE_CLIENTE = ? and PE_RECALCULO <> ? OR PE_RECALCULO <> ? OR PE_RECALCULO IS NOT NULL",Array As String(C.GetString("PC_CLIENTE"),"","null"))
			LogColor(s3.RowCount,Colors.Yellow)
			If s3.RowCount > 0 Then
				
				Private s As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(pe_costo_tot),0) as TOTAL_CLIE, IFNULL(SUM(PE_CANT),0) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ? and (PE_RECALCULO = ? or PE_RECALCULO = ? or PE_RECALCULO IS NULL ) AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)",Array As String(C.GetString("PC_CLIENTE"),"","null"))
				s.Position=0
				Private s5 As Cursor = B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(PE_RECALCULOTOT),0) as TOTAL_CLIE,  IFNULL(SUM(PE_CANT),0) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ? and (PE_RECALCULO <> ? or PE_RECALCULO <> ? OR PE_RECALCULO IS NOT NULL) AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)",Array As String(C.GetString("PC_CLIENTE"),"","null"))
				s5.Position = 0
			
				
				
				
				Dim label1 As Label
				label1 = ListView1.TwoLinesLayout.Label
				label1.TextSize = 20
				label1.TextColor = Colors.White
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 20
				label2.TextColor = Colors.White
				label1.Height = 25dip
				label2.Height = 60dip

				ListView1.TwoLinesLayout.ItemHeight = 95dip
				label1.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
				label2.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
				Log(1)
'				ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& (s.GetString("CANT_CLIE") + s5.GetString("CANT_CLIE")) & " SubTotal $"& NumberFormat2(s.GetString("TOTAL_CLIE") + s5.GetString("TOTAL_CLIE"),0,2,2,True))
				ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& (s.GetString("CANT_CLIE") + s5.GetString("CANT_CLIE")) & " SubTotal $"& Subs.calculaTotalConPromoXRango(c.GetString("PC_CLIENTE")))
				s.Close
			Else If s3.RowCount = 0 Then
				Private s As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(pe_costo_tot),0) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ?", Array As String(C.GetString("PC_CLIENTE")))
				s.Position=0
				
				Dim label1 As Label
				label1 = ListView1.TwoLinesLayout.Label
				label1.TextSize = 20
				label1.TextColor = Colors.White
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 20
				label2.TextColor = Colors.White
				label1.Height = 25dip
				label2.Height = 60dip
			
				ListView1.TwoLinesLayout.ItemHeight = 95dip
				label1.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
				label2.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
				Log(2)
				ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& s.GetString("CANT_CLIE") & " SubTotal $"& Subs.calculaTotalConPromoXRango(c.GetString("PC_CLIENTE")))
				s.Close
			End If
		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"
	B4XPages.ShowPage("cliente")
End Sub

Sub b_noventa_Click
	If nombre_boton = "NOVENTA" Then
		nombre_boton = "VENTA"
		b_noventa.Text ="VENTA"
		L_ventanoventa.Text = "Clientes sin 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"
		L_ventanoventa.Text = "Clientes con venta"
		ListView1.Clear
		c=B4XPages.MainPage.skmt.ExecQuery("select PC_CLIENTE,PC_MONTO,PC_NOART,(select CAT_CL_NOMBRE from kmt_info3 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
				Private s3 As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select * FROM PEDIDO WHERE PE_CLIENTE = ? and PE_RECALCULO <> ? OR PE_RECALCULO <> ? OR PE_RECALCULO IS NOT NULL",Array As String(C.GetString("PC_CLIENTE"),"","null"))
				LogColor(s3.RowCount,Colors.Yellow)
				If s3.RowCount > 0 Then
					Private s As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(pe_costo_tot),0) as TOTAL_CLIE, IFNULL(SUM(PE_CANT),0) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ? and (PE_RECALCULO = ? or PE_RECALCULO = ? or PE_RECALCULO IS NULL ) AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)",Array As String(C.GetString("PC_CLIENTE"),"","null"))
					s.Position=0
					Private s5 As Cursor = B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(PE_RECALCULOTOT),0) as TOTAL_CLIE, IFNULL(SUM(PE_CANT),0) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ? and (PE_RECALCULO <> ? or PE_RECALCULO <> ? OR PE_RECALCULO IS NOT NULL) AND PE_PROID NOT IN (SELECT CAT_PA_ID FROM PROMOS_COMP)",Array As String(C.GetString("PC_CLIENTE"),"","null"))
					s5.Position = 0
					Dim label1 As Label
					label1 = ListView1.TwoLinesLayout.Label
					label1.TextSize = 20
					label1.TextColor = Colors.White
					Dim label2 As Label
					label2 = ListView1.TwoLinesLayout.SecondLabel
					label2.TextSize = 20
					label2.TextColor = Colors.White
					label1.Height = 25dip
					label2.Height = 60dip

					ListView1.TwoLinesLayout.ItemHeight = 95dip
					label1.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
					label2.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
'					ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& (s.GetString("CANT_CLIE") + s5.GetString("CANT_CLIE")) & " SubTotal $"& NumberFormat2(s.GetString("TOTAL_CLIE") + s5.GetString("TOTAL_CLIE"),0,2,2,True))
					ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& (s.GetString("CANT_CLIE") + s5.GetString("CANT_CLIE")) & " SubTotal $"& Subs.calculaTotalConPromoXRango(c.GetString("PC_CLIENTE")))
					s.Close
				Else If s3.RowCount = 0 Then
					Private s As Cursor=B4XPages.MainPage.skmt.ExecQuery2("select iFNULL(sum(pe_costo_tot),0) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE = ?", Array As String(C.GetString("PC_CLIENTE")))
					s.Position=0

					Dim label1 As Label
					label1 = ListView1.TwoLinesLayout.Label
					label1.TextSize = 20
					label1.TextColor = Colors.White
					Dim label2 As Label
					label2 = ListView1.TwoLinesLayout.SecondLabel
					label2.TextSize = 20
					label2.TextColor = Colors.White
					label1.Height = 25dip
					label2.Height = 60dip

					ListView1.TwoLinesLayout.ItemHeight = 95dip
					label1.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
					label2.Typeface = Typeface.CreateNew(Typeface.DEFAULT_BOLD, Typeface.STYLE_BOLD)
					ListView1.AddTwoLines(c.GetString("PC_CLIENTE"),c.GetString("NOMBRE") &"   Cantidad #"& s.GetString("CANT_CLIE") & " SubTotal $"& Subs.calculaTotalConPromoXRango(s3.GetString("PE_CLIENTE")))
					s.Close
				End If
			
			Next
		End If
		c.Close
	End If
End Sub

Private Sub p_ticketsdia_Click
	
End Sub