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 skmt As SQL
	Dim c As Cursor
	Dim c2 As Cursor
	Dim d As Cursor
	Dim s As Cursor
	Dim ListView1 As ListView
	Dim entro As String
	Dim gest As Button
	Dim lfila As Label
	Dim busca As EditText
	Dim colonia As String
	Private b_qr As Button
	Private qr As QRCode
	'    Dim sc As Zxing_scanner
	Dim CODIGO As String
	Dim STIME As String
	Dim ruta As String
	Dim q_buscar As String
	Private p_clientes As Panel
	Private CustomListView1 As CustomListView
	Private numerocliente As Label
	Private nombrecliente As Label
	Private direccion As Label
	Private cxc As Label
	Private p_datosclie As Panel
	Private b_buscar As Button
	Private CHECK As Int
	Private l_baseodia As Label
	Dim lista_punta As List
	Private CREDITO 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
	Root.LoadLayout("clientes")
	'Dim ruta As String
	entro ="2"
	' valido donde escribo el archivo de la base de datos de kmt
'	If File.ExternalWritable Then
'	   ruta = File.DirDefaultExternal
'	Else
	ruta = File.DirInternal
'	End If
	
	' se crea o no el archivo de la base de ddatos de kmt
	'NOTAS SI SE MODIFICA LA ESTRUCTURA SE QUITA EL IF Y SE VA DIRECTO A LA SENTENCIA FILE.COPY PARA QUE
	'TOME LA NUEVA ESTRUCTURA ES MUY IMPORTANTE TENER EL IF DE LO CONTRARIO SOLO LO ESCRIBE UNA VEZ Y LO BORRA
	'SI SE REGRESA A ESTE ACTIVIDAD.
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
	qr.initialize
End Sub

Sub B4XPage_Appear
	l_baseodia.Text = "Clientes del día de visita"
	CHECK = 0
	busca.Text = ""
	entro ="2"
	colonia = 0
	c=B4XPages.MainPage.skmt.ExecQuery($"select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info3 where  gestion = 0 AND CAT_CL_CODIGO <> ${"0"} AND CAT_CL_CODIGO <> ${"1"} ORDER BY CAST(CAT_CL_NUM_SERIEFISICO AS INTEGER) ASC"$)
	ListView1.Clear
	lfila.Text = "NOMBRE"
	
	CallSubDelayed(Tracker, "Track")
	CallSubDelayed(Tracker, "StartFLPSmall")
	If Tracker.FLP.IsInitialized And Tracker.FLP.GetLastKnownLocation.IsInitialized Then 'Si tenemos "UltimaUbicaccionConocida" la usamos.
		B4XPages.MainPage.lat_gps = Tracker.FLP.GetLastKnownLocation.Latitude
		B4XPages.MainPage.lon_gps = Tracker.FLP.GetLastKnownLocation.Longitude
'		Log($"Tenemos UUC: ${Tracker.FLP.GetLastKnownLocation.Latitude},${Tracker.FLP.GetLastKnownLocation.Longitude}"$)
		GPS_LocationChanged(Tracker.FLP.GetLastKnownLocation)
	End If
	
	CustomListView1.Clear
	For i = 0 To c.RowCount - 1
		c.Position = i
		CustomListView1.Add(CreateListItem(c.GetString("CAT_CL_NOMBRE"),c.GetString("CAT_CL_CALLE"),c.GetString("CAT_CL_CODIGO")),i)
		d = B4XPages.MainPage.skmt.ExecQuery($"select CLIENTE FROM ABONOSP WHERE CLIENTE = '${c.GetString("CAT_CL_CODIGO")}'"$)
		If d.RowCount = 0 Then
			cxc.Visible = False
		Else
			cxc.Visible = True
		End If
		
		d = B4XPages.MainPage.skmt.ExecQuery($"select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO FROM kmt_info3 WHERE CAT_CL_CODIGO = '${c.GetString("CAT_CL_CODIGO")}'"$)
'		LogColor(d.RowCount,Colors.Blue)
		If d.RowCount > 0 Then
			d.Position = 0
			If d.GetString("CAT_CL_BCREDITO") = "1" Then
				CREDITO.Visible = True
			Else
				CREDITO.Visible = False
			End If
			d.Close
		Else
			CREDITO.Visible = False
		End If
	Next
	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 = 13
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = ListView1.TwoLinesLayout.SecondLabel
			label2.TextSize = 13
			label2.TextColor = Colors.Black
			ListView1.AddTwoLines(c.GetString("CAT_CL_CODIGO"), c.GetString("CAT_CL_NOMBRE"))
		Next
	End If
	c.Close
	entro = "4"
	
'	lista_punta.Initialize
'	Dim pol As Cursor = Starter.skmt.ExecQuery("SELECT LAT, LONG FROM POLIGONO")
'	If pol.RowCount > 0 Then
'		
'		For poli = 0 To pol.RowCount -1
'			pol.Position = poli
'			Dim coords As LatLng
'			coords.Initialize(pol.GetString("LAT"), pol.GetString("LONG"))
'			lista_punta.Add(coords)
'		Next
'	End If
	
End Sub



Sub GPS_LocationChanged (Location1 As Location)
'	LogColor($"Entrando a Cliente.GPS_LocationChanged"$, Colors.red)
	If Tracker.FLP.GetLastKnownLocation.IsInitialized And Tracker.FLP.GetLastKnownLocation.Latitude <> 0 Then
		B4XPages.MainPage.lat_gps = Tracker.FLP.GetLastKnownLocation.Latitude
		B4XPages.MainPage.lon_gps = Tracker.FLP.GetLastKnownLocation.Longitude
'		Log("Coords set to: " & B4XPages.MainPage.lat_gps & " and " & B4XPages.MainPage.lon_gps)
	End If
	
	
	CallSubDelayed(Tracker, "CreateLocationRequest")
End Sub

Sub CreateListItem(mostrar As String, mostrar1 As String, mostrar2 As String) As Panel
	Dim p As B4XView = xui.CreatePanel("")
	p.SetLayoutAnimated(0, 0, 0, 1, 220)
	p.LoadLayout("datoscliente")
	p.Height= 60dip
'	p.Width = clv_orden.GetBase.Width
	nombrecliente.Text = mostrar
	direccion.Text = mostrar1
	numerocliente.Text = mostrar2
	p_datosclie.Tag = mostrar2
'	cxc.Text = mostrar3
'	Log(p.Width)
	Return p
End Sub

Sub PointInPolygon(point As LatLng, polygon As List) As Boolean
	Dim x As Double = point.Longitude
	Dim y As Double = point.Latitude
    
	Dim inside As Boolean = False
	For i = 0 To polygon.Size - 1
		Dim j As Int = (i + 1) Mod polygon.Size
		Dim p1_1 As LatLng = polygon.Get(i)
		Dim p2_1 As LatLng = polygon.Get(j)
        
		Dim xi As Double = p1_1.Longitude
		Dim yi As Double = p1_1.Latitude
		Dim xj As Double = p2_1.Longitude
		Dim yj As Double = p2_1.Latitude
        
		Dim intersect As Boolean = ((yi > y) <> (yj > y)) And (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
		If intersect Then
			inside = Not(inside)
		End If
	Next
    
	Return inside
	
	
End Sub


Sub ListView1_ItemClick (Position As Int, value As Object)
	If colonia = 0 Then
		colonia = value
	End If
	If entro = "2" Then
		c2=B4XPages.MainPage.skmt.ExecQuery2("select CAT_CL_CALLE, CAT_CL_COLONIA, count(*) as cuantos from kmt_info3 where gestion = 0 and CAT_CL_COLONIA = ? GROUP BY CAT_CL_CALLE, CAT_CL_COLONIA order by CAT_CL_CALLE ",  Array As String(value))
		ListView1.Clear
		lfila.text = "Calle"
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CALLE"),c2.GetString("cuantos") )
			Next
		End If
		entro = "3"
	Else If entro = "3" Then
		c2=B4XPages.MainPage.skmt.ExecQuery2("select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info3 where  gestion = 0 and  CAT_CL_CALLE = ? AND CAT_CL_COLONIA = ? order by CAT_CL_NOMBRE ", Array As String(value, colonia))
		ListView1.Clear
		lfila.text = "Nombre"
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CODIGO"), c2.GetString("CAT_CL_NOMBRE"))
			Next
		End If
		entro = "4"
	Else If entro = "4" Then
		Dim mPoint As LatLng
		mPoint.Initialize(B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps)
	
'		If lista_punta.Size > 0 Then
'			Dim dentro As Boolean = PointInPolygon(mPoint, lista_punta)
'		Else
'			ToastMessageShow("El punto está FUERA del polígono", True)
'		End If


		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)
		Starter.pre_viejo = Subs.traeTotalClientepreventaparacredito
		s=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_STAY_STORE WHERE HSS_IN = ? AND HSS_CODIGO In (select cuenta from cuentaa)", Array As String("0"))
		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
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_OUT set HSO_INI = ?  where HSO_INI = 0 ", Array As Object(STIME))
		DateTime.TimeFormat = "HH:mm:ss"
		
		Subs.guardaClienteHoraInicio(value)
		
		B4XPages.ShowPage("Cliente")
	End If
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
	' BACK key pressed
	'Return True to close, False to cancel
'	If key=KeyCodes.KEYCODE_BACK Then
'		StartActivity(seleccion)
'		Return False
'	End If
	Return True
End Sub

Sub BUSCA_TextChanged (Old As String, New As String)
	If CHECK = 0 Then
		q_buscar = "%" & busca.Text & "%"
		c2=B4XPages.MainPage.skmt.ExecQuery2($"select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info3 where (CAT_CL_NOMBRE like ? OR CAT_CL_CODIGO LIKE ? OR CAT_CL_CALLE LIKE ?)and gestion = 0 AND CAT_CL_CODIGO <> ${"0"} AND CAT_CL_CODIGO <> ${"1"} order by CAT_CL_CODIGO "$, Array As String(q_buscar,q_buscar,q_buscar))
		ListView1.Clear
		lfila.text = "Nombre y Calle"
	
		CustomListView1.Clear
		For i = 0 To c2.RowCount - 1
			c2.Position = i
			CustomListView1.Add(CreateListItem(c2.GetString("CAT_CL_NOMBRE"),c2.GetString("CAT_CL_CALLE"),c2.GetString("CAT_CL_CODIGO")),i)
			d = B4XPages.MainPage.skmt.ExecQuery($"select CLIENTE FROM ABONOSP WHERE CLIENTE = '${c2.GetString("CAT_CL_CODIGO")}'"$)
			If d.RowCount = 0 Then
				cxc.Visible = False
			Else
				cxc.Visible = True
			End If
			
			d = B4XPages.MainPage.skmt.ExecQuery($"select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO FROM kmt_info3 WHERE CAT_CL_CODIGO = '${c2.GetString("CAT_CL_CODIGO")}'"$)
'		LogColor(d.RowCount,Colors.Blue)
			If d.RowCount > 0 Then
				d.Position = 0
'				LogColor(d.GetString("CAT_CL_BCREDITO"),Colors.Blue)
				If d.GetString("CAT_CL_BCREDITO") = "1" Then
					CREDITO.Visible = True
				Else
					CREDITO.Visible = False
				End If
				d.Close
			Else
				CREDITO.Visible = False
			End If
		Next
	
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				Dim label1 As Label
				label1 = ListView1.TwoLinesLayout.Label
				label1.TextSize = 9
				label1.TextColor = Colors.White
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 17
				label2.TextColor = Colors.White
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CODIGO"), c2.GetString("CAT_CL_NOMBRE") &" CALLE:  "& c2.GetString("CAT_CL_CALLE"))
			Next
		End If
		entro = "4"
		c2.Close
	Else If CHECK = 1 Then
		q_buscar = "%" & busca.Text & "%"
		c2=B4XPages.MainPage.skmt.ExecQuery2("select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info32 where (CAT_CL_NOMBRE like ? OR CAT_CL_CODIGO LIKE ? OR CAT_CL_CALLE LIKE ?)and gestion = 0 order by CAT_CL_CODIGO ", Array As String(q_buscar,q_buscar,q_buscar))
		ListView1.Clear
		lfila.text = "Nombre y Calle"
	
		CustomListView1.Clear
		For i = 0 To c2.RowCount - 1
			c2.Position = i
			CustomListView1.Add(CreateListItem(c2.GetString("CAT_CL_NOMBRE"),c2.GetString("CAT_CL_CALLE"),c2.GetString("CAT_CL_CODIGO")),i)
			d = B4XPages.MainPage.skmt.ExecQuery($"select CLIENTE FROM ABONOSP WHERE CLIENTE = '${c2.GetString("CAT_CL_CODIGO")}'"$)
			If d.RowCount = 0 Then
				cxc.Visible = False
			Else
				cxc.Visible = True
			End If
			d = B4XPages.MainPage.skmt.ExecQuery($"select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO FROM kmt_info32 WHERE CAT_CL_CODIGO = '${c2.GetString("CAT_CL_CODIGO")}'"$)
'		LogColor(d.RowCount,Colors.Blue)
			If d.RowCount > 0 Then
				d.Position = 0
				LogColor(d.GetString("CAT_CL_BCREDITO"),Colors.Blue)
				If d.GetString("CAT_CL_BCREDITO") = "1" Then
					CREDITO.Visible = True
				Else
					CREDITO.Visible = False
				End If
				d.Close
			Else
				CREDITO.Visible = False
			End If
		Next
	
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				Dim label1 As Label
				label1 = ListView1.TwoLinesLayout.Label
				label1.TextSize = 9
				label1.TextColor = Colors.White
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 17
				label2.TextColor = Colors.White
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CODIGO"), c2.GetString("CAT_CL_NOMBRE") &" CALLE:  "& c2.GetString("CAT_CL_CALLE"))
			Next
		End If
		entro = "4"
		c2.Close
	End If
End Sub

Sub b_qr_Click
	Dim scan_width As Int
	Dim scan_height As Int
	scan_width = 400
	scan_height = 400
End Sub

Sub sc_result(atype As String,Values As String)
	CODIGO = Values
	c2=B4XPages.MainPage.skmt.ExecQuery2("select   COUNT(*) AS ENCONTRADO from kmt_info3 where CAT_CL_NUM_SERIEFISICO = ?  order by CAT_CL_NOMBRE ", Array As String(CODIGO))
	c2.Position =0
	If c2.GetString("ENCONTRADO") > 0 Then
		s=B4XPages.MainPage.skmt.ExecQuery2("select   CAT_CL_CODIGO from kmt_info3 where CAT_CL_NUM_SERIEFISICO = ?  order by CAT_CL_NOMBRE ", Array As String(CODIGO))
		s.Position =0
		B4XPages.MainPage.skmt.ExecNonQuery("delete from CUENTAA")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(s.GetString("CAT_CL_CODIGO")))
		s.Close
'		b_qr.Visible = False
		B4XPages.ShowPage("clientes")
	Else
		Msgbox("CODIGO " & CODIGO & " NO ENCONTRADO","AVISO") 'ignore
	End If
End Sub

Sub sc_noScan
	Log("nothing returned from the scan !!!!!")
End Sub

Sub calc_ean_checksum(number As String) As String           'this has now become redundant as I am only interested in QR Codes
	Dim i As Int
	Dim cO As Char
	Dim soma As Int
	Dim n As Int
	Dim digit As Float
	soma = 0
	For i=0 To number.Length - 1
		digit = number.SubString2(i,i+1)
		n= digit * ((i Mod 2) * 2 + 1)
		soma=soma+n
	Next
	Return number & ( ( 10 - ( soma Mod 10 )) Mod 10 )
End Sub

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

Private Sub p_clientes_Click
	'Nada aqui, solo esta para que los clics no se pasen hacia atras.
End Sub

Private Sub p_datosclie_Click
	If colonia = 0 Then
		colonia = Sender.As(Panel).tag
	End If
	If entro = "2" Then
		c2=B4XPages.MainPage.skmt.ExecQuery2("select CAT_CL_CALLE, CAT_CL_COLONIA, count(*) as cuantos from kmt_info3 where gestion = 0 and CAT_CL_COLONIA = ? GROUP BY CAT_CL_CALLE, CAT_CL_COLONIA order by CAT_CL_CALLE ",  Array As String(Sender.As(Panel).tag))
		ListView1.Clear
		lfila.text = "Calle"
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CALLE"),c2.GetString("cuantos") )
			Next
		End If
		entro = "3"
	Else If entro = "3" Then
		c2=B4XPages.MainPage.skmt.ExecQuery2("select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info3 where  gestion = 0 and  CAT_CL_CALLE = ? AND CAT_CL_COLONIA = ? order by CAT_CL_NOMBRE ", Array As String(Sender.As(Panel).tag, colonia))
		ListView1.Clear
		lfila.text = "Nombre"
		If c2.RowCount>0 Then
			For i=0 To c2.RowCount -1
				c2.Position=i
				ListView1.AddTwoLines(c2.GetString("CAT_CL_CODIGO"), c2.GetString("CAT_CL_NOMBRE"))
			Next
		End If
		entro = "4"
	Else If entro = "4" Then
		B4XPages.MainPage.skmt.ExecNonQuery("delete from CUENTAA")
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(Sender.As(Panel).tag))
		DateTime.TimeFormat = "HHmmss"
		STIME=DateTime.Time(DateTime.Now)
		
		s=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_STAY_STORE WHERE HSS_IN = ? AND HSS_CODIGO In (select cuenta from cuentaa)", Array As String("0"))
		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 (Sender.As(Panel).tag))
			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
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_OUT set HSO_INI = ?  where HSO_INI = 0 ", Array As Object(STIME))
		DateTime.TimeFormat = "HH:mm:ss"
		
		Subs.guardaClienteHoraInicio(Sender.As(Panel).tag)
		
		B4XPages.ShowPage("Cliente")
	End If
	
'	Log(Sender.As(Panel).tag)
End Sub

Private Sub b_buscar_Click
	Log(CHECK)
	If CHECK = 0 Then
		l_baseodia.Text = "Clientes de base de datos"
		CHECK = 1
		busca.Text = ""
		entro ="2"
		colonia = 0
		c=B4XPages.MainPage.skmt.ExecQuery($"select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info32 where  gestion = 0 AND CAT_CL_CODIGO <> ${"0"} AND CAT_CL_CODIGO <> ${"1"} ORDER BY CAT_CL_CODIGO"$)
		ListView1.Clear
		lfila.Text = "NOMBRE"
		ListView1.Clear
		CustomListView1.Clear
		For i = 0 To c.RowCount - 1
			c.Position = i
			CustomListView1.Add(CreateListItem(c.GetString("CAT_CL_NOMBRE"),c.GetString("CAT_CL_CALLE"),c.GetString("CAT_CL_CODIGO")),i)
			d = B4XPages.MainPage.skmt.ExecQuery($"select CLIENTE FROM ABONOSP WHERE CLIENTE = '${c.GetString("CAT_CL_CODIGO")}'"$)
			If d.RowCount = 0 Then
				cxc.Visible = False
			Else
				cxc.Visible = True
			End If
			
			d = B4XPages.MainPage.skmt.ExecQuery($"select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO FROM kmt_info32 WHERE CAT_CL_CODIGO = '${c.GetString("CAT_CL_CODIGO")}'"$)
'		LogColor(d.RowCount,Colors.Blue)
			If d.RowCount > 0 Then
				d.Position = 0
				LogColor(d.GetString("CAT_CL_BCREDITO"),Colors.Blue)
				If d.GetString("CAT_CL_BCREDITO") = "1" Then
					CREDITO.Visible = True
					
				Else
					CREDITO.Visible = False
				End If
				d.Close
			Else
				CREDITO.Visible = False
			End If
		Next
		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 = 13
				label1.TextColor = Colors.Black
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 13
				label2.TextColor = Colors.Black
				ListView1.AddTwoLines(c.GetString("CAT_CL_CODIGO"), c.GetString("CAT_CL_NOMBRE"))
			Next
		End If
		c.Close
		entro = "4"
	
	Else If CHECK = 1 Then
		l_baseodia.Text = "Clientes del día de visita"
		CHECK = 0
		busca.Text = ""
		entro ="2"
		colonia = 0
		c=B4XPages.MainPage.skmt.ExecQuery($"select  CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info3 where  gestion = 0 AND CAT_CL_CODIGO <> ${"0"} AND CAT_CL_CODIGO <> ${"1"} ORDER BY CAT_CL_CODIGO"$)
		ListView1.Clear
		lfila.Text = "NOMBRE"
		ListView1.Clear
		CustomListView1.Clear
		For i = 0 To c.RowCount - 1
			c.Position = i
			CustomListView1.Add(CreateListItem(c.GetString("CAT_CL_NOMBRE"),c.GetString("CAT_CL_CALLE"),c.GetString("CAT_CL_CODIGO")),i)
			d = B4XPages.MainPage.skmt.ExecQuery($"select CLIENTE FROM ABONOSP WHERE CLIENTE = '${c.GetString("CAT_CL_CODIGO")}'"$)
			If d.RowCount = 0 Then
				cxc.Visible = False
			Else
				cxc.Visible = True
			End If
			
			d = B4XPages.MainPage.skmt.ExecQuery($"select IFNULL(CAT_CL_BCREDITO,0) AS CAT_CL_BCREDITO FROM kmt_info3 WHERE CAT_CL_CODIGO = '${c.GetString("CAT_CL_CODIGO")}'"$)
'		LogColor(d.RowCount,Colors.Blue)
			If d.RowCount > 0 Then
				d.Position = 0
				LogColor(d.GetString("CAT_CL_BCREDITO"),Colors.Blue)
				If d.GetString("CAT_CL_BCREDITO") = "1" Then
					CREDITO.Visible = True
				Else
					CREDITO.Visible = False
				End If
				d.Close
			Else
				CREDITO.Visible = False
			End If
		Next
		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 = 13
				label1.TextColor = Colors.Black
				Dim label2 As Label
				label2 = ListView1.TwoLinesLayout.SecondLabel
				label2.TextSize = 13
				label2.TextColor = Colors.Black
				ListView1.AddTwoLines(c.GetString("CAT_CL_CODIGO"), c.GetString("CAT_CL_NOMBRE"))
			Next
		End If
		c.Close
		entro = "4"
		
	End If
End Sub
