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
	
	Private CREDITO As Label
	Private p_transparenciaIniciaInicioFinVenta As Panel
	Private p_inicioFinVenta As Panel
	Private b_inicioVenta As Button
	Private b_finVenta As Button
	Private p_guardarPeso As Panel
	Private et_guardarPeso As EditText
	Private p_botonesGuardarPeso As Panel
	Private b_noVenta As Button
	Private b_guardarPeso As Button
	Private p_noVenta As Panel
	Private b_cancelaNoVenta As Button
	Private b_guardaNoVenta As Button
	Private p_botonesNoVenta As Panel
	Private et_comentarioNoVenta As EditText
	Private r_opcion5 As RadioButton
	Private r_opcion4 As RadioButton
	Private r_opcion3 As RadioButton
	Private r_opcion2 As RadioButton
	Private r_opcion1 As RadioButton
	Dim motivo As String
	Private p_camara As Panel
	Private b_foto_inci As Button
	Private b_cam As Button
	Private p_cam As Panel
	Private camEx As CameraExClass
	Private frontCamera As Boolean = False
	Dim laCam As C_Camara
	Dim fototomada As String = "0"
	Dim sDate As String
	Dim sTime As String
	Private nombreFoto As String
	Dim fotoCerrado As String = ""
	Private p_botonesCam As Panel
	Dim reqManager As DBRequestManager
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

	p_transparenciaIniciaInicioFinVenta.top = 0 : p_transparenciaIniciaInicioFinVenta.Left = 0
	p_transparenciaIniciaInicioFinVenta.Height = Root.Height : p_transparenciaIniciaInicioFinVenta.Width = Root.Width
	Subs.centraPanel(p_inicioFinVenta, Root.Width)
	p_guardarPeso.Top = p_inicioFinVenta.top : p_guardarPeso.left = p_inicioFinVenta.left
	Subs.centraPanel(p_noVenta, Root.Width)
	
	' 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
	reqManager.Initialize(Me, Starter.DBReqServer)
	laCam.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_info 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"
	
	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_info 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"
	If Subs.nosQuedamosEnVenta Then
		Dim enVentaUsuario As String = ""
		Dim enVentaPagina As String = ""
		Private ev As Cursor = Starter.skmt.ExecQuery("select * from cat_variables where cat_va_descripcion = 'EN_VENTA_USUARIO' or cat_va_descripcion = 'EN_VENTA_PAGINA'")
		If ev.RowCount > 0 Then
			For i = 0 To ev.RowCount - 1
				ev.Position = i
				If ev.GetString("CAT_VA_DESCRIPCION") = "EN_VENTA_USUARIO" Then
					enVentaUsuario = ev.GetString("CAT_VA_VALOR")
				Else If ev.GetString("CAT_VA_DESCRIPCION") = "EN_VENTA_PAGINA" Then
					enVentaPagina = ev.GetString("CAT_VA_VALOR")
				End If
			Next
			ventaIniciada
		End If
	End If
End Sub

Sub CreateListItem(nombre As String, direccion0 As String, cliente As String) As Panel
	Dim p As B4XView = xui.CreatePanel("")
	p.SetLayoutAnimated(0, 0, 0, 1, 220)
'	p.LoadLayout("datoscliente")
	p.LoadLayout("datosclienteBotones")
	p.Height= 100dip
	b_inicioVenta.Tag = cliente
'	p.Width = clv_orden.GetBase.Width
	nombrecliente.Text = nombre
	direccion.Text = direccion0
	numerocliente.Text = cliente
	p_datosclie.Tag = cliente
'	cxc.Text = mostrar3
'	Log(p.Width)
	Return p
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_info 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_info 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
'		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
	If p_transparenciaIniciaInicioFinVenta.Visible Then
		ToastMessageShow($"Es necesario ingresar "Peso" o "No Venta" para poder continuar"$, True)
		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_info 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_NOMBRE "$, 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_info 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_info2 where (CAT_CL_NOMBRE like ? OR CAT_CL_CODIGO LIKE ? OR CAT_CL_CALLE LIKE ?)and gestion = 0 order by CAT_CL_NOMBRE ", 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_info 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_info 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_info 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_info 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_info 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_info2 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_info 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_info 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_info 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

Private Sub b_inicioVenta_Click
'	b_inicioVenta.Enabled = False
	Private cliente As String = Sender.As(Button).tag
	Starter.skmt.ExecNonQuery($"delete from cuentaa"$)
	Starter.skmt.ExecNonQuery($"insert into cuentaa (cuenta) values ('${cliente}')"$)
	Log($"insert into cuentaa (cuenta) values ('${cliente}')"$)
	c = Starter.skmt.ExecQuery("SELECT * FROM FOTOINICIAL")
	If c.RowCount = 0 Then
		p_camara.Visible = True
		InitializeCamera
		p_camara.Left = 0
		p_camara.Visible = True
		nombreFoto = "inicio"
		b_foto_inci.Text = "Foto tienda"
	Else
		p_transparenciaIniciaInicioFinVenta.Visible = True
		b_finVenta.Enabled = True
		Subs.bitacora(Subs.fechanormal(DateTime.Now), Subs.traeUsuarioDeBD, Subs.traeAlmacen, Subs.traeRuta, "Inicia Venta", cliente, Subs.fechanormal(DateTime.Now), "", Starter.lat_gps, Starter.lon_gps, "2", "", "", "")
		Starter.enVenta = True
		Subs.enVenta(1, "CLIENTES")
		LogColor($">>>>>> INICIA VENTA: ${Starter.enVenta} - ${cliente}"$, Colors.red)
		Log(Subs.traeRuta2(Subs.traeCliente))
	End If
	c = Starter.skmt.ExecQuery($"select PE_FOTO_CERRADO from PESOS where PE_CLIENTE = '${cliente}' and PE_FOTO_CERRADO = '1'"$)
	If c.RowCount > 0 Then
		fotoCerrado = "1"
	Else
		fotoCerrado = ""
	End If
	c.Close
	Log("CLIENTE: " & cliente)
	Log("FOTOCERRADO: " & fotoCerrado)
End Sub

Private Sub ventaIniciada
'	b_inicioVenta.Enabled = False
'	Private cliente As String = Sender.As(Button).tag
'	Starter.skmt.ExecNonQuery($"delete from cuentaa"$)
'	Starter.skmt.ExecNonQuery($"insert into cuentaa (cuenta) values ('${cliente}')"$)
'	Log($"insert into cuentaa (cuenta) values ('${cliente}')"$)
	p_transparenciaIniciaInicioFinVenta.Visible = True
	b_finVenta.Enabled = True
	Subs.bitacora(Subs.fechanormal(DateTime.Now), Subs.traeUsuarioDeBD, Subs.traeAlmacen, Subs.traeRuta, "Inicia Venta", Subs.traeCliente, Subs.fechanormal(DateTime.Now), "", Starter.lat_gps, Starter.lon_gps, "2", "", "", "")
	Starter.enVenta = True
	Subs.enVenta(1, "CLIENTES")
	LogColor($">>>>>> INICIA VENTA: ${Starter.enVenta} - ${Subs.traeCliente}"$, Colors.red)
	Log(Subs.traeRuta2(Subs.traeCliente))
End Sub

Private Sub b_finVenta_Click
	et_guardarPeso.Text = ""
	p_guardarPeso.Visible = True
'	b_inicioVenta.Enabled = True
'	b_finVenta.Enabled = False
End Sub

Private Sub p_transparenciaIniciaInicioFinVenta_Click
	Log("Fondo clicked")
	If b_finVenta.Enabled = False Then
		p_transparenciaIniciaInicioFinVenta.Visible = False
	Else
		ToastMessageShow($"Es necesario ingresar "Peso" o "No Venta" para poder continuar"$, True)
	End If
End Sub

Private Sub b_guardarPeso_Click
	If et_guardarPeso.Text <> "" And et_guardarPeso.Text <> "0" And IsNumber(et_guardarPeso.Text) Then
		Private peso As Double = et_guardarPeso.Text
		et_guardarPeso.Text = peso

		Subs.guardaPeso("VENTA", Subs.traeAlmacen, Subs.traeRuta2(Subs.traeCliente), Subs.traeUsuarioDeBD, Subs.traeCliente, peso, "", "", "")
		Subs.bitacora(Subs.fechanormal(DateTime.Now), Subs.traeUsuarioDeBD, Subs.traeAlmacen, Subs.traeRuta2(Subs.traeCliente), "Termina Venta", Subs.traeCliente, "", Subs.fechanormal(DateTime.Now), Starter.lat_gps, Starter.lon_gps, 2, "", "", $"Venta:${et_guardarPeso.text}"$)
		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		Starter.enVenta = False
		Subs.enVenta(0, "")
		p_guardarPeso.Visible = False
		p_transparenciaIniciaInicioFinVenta.Visible = False
'		b_inicioVenta.Enabled = True
		b_finVenta.Enabled = False
		B4XPages.MainPage.clientes.B4XPage_Appear
		mandaPendientes
	End If
End Sub

Private Sub p_guardarPeso_Click
	
End Sub

Private Sub et_guardarPeso_TextChanged (Old As String, New As String)
	If Old <> New And IsNumber(New.trim) And New.trim <> "0" Then
		b_guardarPeso.Enabled = True
	Else
		b_guardarPeso.Enabled = False
	End If
End Sub

Private Sub b_noVenta_Click
	Log("No Venta")
	p_noVenta.Visible = True
	r_opcion1.Checked = True
	r_opcion2.Checked = False
	r_opcion3.Checked = False
	r_opcion4.Checked = False
	et_comentarioNoVenta.Text = ""
End Sub

Private Sub b_guardaNoVenta_Click
	If r_opcion1.Checked Then
		motivo = "CERRADO"
	Else If r_opcion2.Checked Then
		motivo = "NO COMPRA"
	Else If r_opcion3.Checked Then
		motivo = "CON PRODUCTO"
	Else If r_opcion4.Checked Then
		motivo = "NO ESTA EL ENCARGADO"
	Else
		motivo = "CANCELACION"
	End If
	
	Log("FOTOCERRADO: " & fotoCerrado)
	
	If motivo = "CERRADO" And fotoCerrado = "" Then
		nombreFoto = Subs.traeCliente & "_cerrado"
		p_camara.Height = Root.Height : p_camara.Width = Root.Width
		p_camara.Left = 0 : p_camara.top = 0
		Subs.centraPanel(p_cam, Root.Width)
		Subs.centraPanel(p_botonesCam, Root.Width)
		p_camara.Visible = True
		InitializeCamera
		p_camara.Visible = True
		p_camara.BringToFront
		b_foto_inci.Text = "Foto tienda"
	Else
		DateTime.DateFormat="yy-MM-dd HH:mm:ss"
		Dim fecha As String=DateTime.Date(DateTime.Now)
		Subs.guardaPeso("NO VENTA", Subs.traeAlmacen, Subs.traeRuta2(Subs.traeCliente), Subs.traeUsuarioDeBD, Subs.traeCliente, "0", motivo, et_comentarioNoVenta.text, fotoCerrado)
		Subs.bitacora(Subs.fechanormal(DateTime.Now), Subs.traeUsuarioDeBD, Subs.traeAlmacen, Subs.traeRuta, "No Venta", Subs.traeCliente, "", Subs.fechanormal(DateTime.Now), Starter.lat_gps, Starter.lon_gps, 2, motivo, et_comentarioNoVenta.text, $"Venta:${et_guardarPeso.text}"$)
		Starter.enVenta = False
		Subs.enVenta(0, "")
		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
		p_noVenta.Visible = False
		p_guardarPeso.Visible = False
		p_transparenciaIniciaInicioFinVenta.Visible = False
	End If
	mandaPendientes
	
'	DateTime.DateFormat="yy-MM-dd HH:mm:ss"
'	Dim fecha As String=DateTime.Date(DateTime.Now)
'
'	Subs.guardaPeso("NO VENTA", Subs.traeAlmacen, Subs.traeRuta2(Subs.traeCliente), Subs.traeUsuarioDeBD, Subs.traeCliente, "0", motivo, et_comentarioNoVenta.text)
'	Subs.bitacora(Subs.fechanormal(DateTime.Now), Subs.traeUsuarioDeBD, Subs.traeAlmacen, Subs.traeRuta, "No Venta", Subs.traeCliente, "", Subs.fechanormal(DateTime.Now), Starter.lat_gps, Starter.lon_gps, 2, motivo, et_comentarioNoVenta.text, $"Venta:${et_guardarPeso.text}"$)
'	Starter.enVenta = False
'	Subs.enVenta(0, "")
'	Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
'	p_noVenta.Visible = False
'	p_guardarPeso.Visible = False
'	p_transparenciaIniciaInicioFinVenta.Visible = False
End Sub

Private Sub b_cancelaNoVenta_Click
	p_noVenta.Visible = False
End Sub

Private Sub p_camara_Click
	
End Sub

Private Sub b_foto_inci_Click
	camEx.TakePicture
End Sub

Private Sub InitializeCamera
	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_CAMERA)
	Wait For B4XPage_PermissionResult (Permission As String, resulta As Boolean)
	If resulta Then
		camEx.Initialize(p_cam, frontCamera, Me, "Camera1")
		frontCamera = camEx.Front
	Else
		ToastMessageShow("No permission!!!", True)
	End If
End Sub

Sub Camera1_Ready (Success As Boolean)
	If Success Then
		camEx.SetJpegQuality(90)
		camEx.SetContinuousAutoFocus
		camEx.CommitParameters
		camEx.StartPreview
		Log(camEx.GetPreviewSize)
	Else
		ToastMessageShow("Cannot open camera.", True)
	End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
	If b_foto_inci.Text = "Foto tienda" Then
		DateTime.DateFormat="ddMMyyyyHHmmss"
		fototomada = DateTime.Now & $"_${nombreFoto}.jpg"$
		Dim filename As String = fototomada
		Dim dir As String = File.DirInternal
		camEx.SavePictureToFile(Data, dir, filename)
		camEx.StartPreview 'restart preview
		ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
		Dim Dirp As String = File.DirInternal
		Dim dir As String
		Dim Dir2 As String
		Try
			File.MakeDir(Dirp,"/adm")
			dir = "/adm"
			Log("creado en promotoria " & Dirp & dir)
		Catch
			dir = ""
			Log("creado en raiz")
		End Try
		Try
			File.MakeDir(Dirp & dir,"/reduccion")
			Dir2 = "/reduccion"
			Log("creado en promotoria " & Dirp & dir & Dir2)
		Catch
			Dir2 = ""
			Log("creado en raiz")
		End Try
		DateTime.DateFormat = "MM/dd/yyyy"
		DateTime.TimeFormat = "HH:mm:ss"
		sDate = DateTime.Date(DateTime.Now)
		sTime = DateTime.Time(DateTime.Now)
		camEx.SavePictureToFile(Data, Dirp&dir, filename)
		camEx.StartPreview 'restart preview
		ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename) & dir &"," & filename, True)
		Log("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename) & dir &"," & filename)
		
		Dim img As B4XBitmap = xui.LoadBitmapResize(File.DirInternal & dir, filename, 450, 600, True)
		Dim out As OutputStream = File.OpenOutput(File.DirInternal & dir & Dir2, filename, False)
		img.WriteToStream(out, 100, "PNG")
		out.Close
		If nombreFoto = "inicio" Then
			Starter.skmt.ExecNonQuery2("INSERT INTO FOTOINICIAL (RUTAA, ALMACEN, LATITUD, LONGITUD, FECHAHORA, FOTO, USUARIO) VALUES (?,?,?,?,?,?,?)",Array As Object(Subs.traeRuta, Subs.traeAlmacen, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps, sDate & " " & sTime, File.ReadBytes(File.DirInternal & dir & Dir2, fototomada), Subs.traeUsuarioDeBD))
			b_foto_inci.Text = "Foto usuario"
			ChangeCamera_Click
		Else
			fotoCerrado = fototomada
			p_camara.Visible = False
			StopCamera
		End If
	Else If b_foto_inci.Text = "Foto usuario" Then
		DateTime.DateFormat="ddMMyyyyHHmmss"
		fototomada = fototomada = DateTime.Now & $"_${nombreFoto}.jpg"$
		Dim filename As String = fototomada
		Dim dir As String = File.DirInternal
		camEx.SavePictureToFile(Data, dir, filename)
		camEx.StartPreview 'restart preview
		ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
		Dim Dirp As String = File.DirInternal
		Dim dir As String
		Dim Dir2 As String
		Try
			File.MakeDir(Dirp,"/adm")
			dir = "/adm"
			Log("creado en promotoria " & Dirp & dir)
		Catch
			dir = ""
			Log("creado en raiz")
		End Try
		Try
			File.MakeDir(Dirp & dir,"/reduccion")
			Dir2 = "/reduccion"
			Log("creado en promotoria " & Dirp & dir & Dir2)
		Catch
			dir = ""
			Log("creado en raiz")
		End Try
		DateTime.DateFormat = "MM/dd/yyyy"
		DateTime.TimeFormat = "HH:mm:ss"
		sDate = DateTime.Date(DateTime.Now)
		sTime = DateTime.Time(DateTime.Now)
		camEx.SavePictureToFile(Data, Dirp&dir, filename)
		camEx.StartPreview 'restart preview
		ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename) & dir &"," & filename, True)
		Log("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename) & dir &"," & filename)
		Dim img As B4XBitmap = xui.LoadBitmapResize(File.DirInternal & dir, filename, 450, 600, True)
		Dim out As OutputStream = File.OpenOutput(File.DirInternal & dir & Dir2, filename, False)
		img.WriteToStream(out, 100, "PNG")
		out.Close
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE FOTOINICIAL set FOTO2 = ? where USUARIO = ? and RUTAA = ? and ALMACEN = ? ", Array As Object (File.ReadBytes(File.DirInternal & dir & Dir2, fototomada), Subs.traeUsuarioDeBD,Subs.traeRuta, Subs.traeAlmacen ))
		b_foto_inci.Text = "Foto tienda"
		ChangeCamera_Click
		p_camara.Visible = False
		StopCamera
		If Subs.traeCliente = "0" Then
			B4XPages.MainPage.tipo_venta = "ABORDO"
		Else If Subs.traeCliente = "1" Then
			B4XPages.MainPage.tipo_venta = "RECARGA"
		Else
			B4XPages.MainPage.tipo_venta = "PREVENTA"
		End If
'		B4XPages.ShowPage("productos")
'		p_transparentePidePeso.Visible = True
	End If
End Sub

Sub ChangeCamera_Click
	camEx.Release
	frontCamera = Not(frontCamera)
	InitializeCamera
End Sub

Private Sub StopCamera
'	Capturing = False
	If camEx.IsInitialized Then
		camEx.Release
	End If
End Sub

Sub mandaPendientes
'	PEDIDO_CLIENTE (Pendientes)
	Log(">>>>>>>  MANDA PENDIENTES")
	Dim PCNoArts As String
	Dim PCMonto As String
	If Subs.traeUsuarioDeBD <> "KMTS1"  Then
		'PESOS (Pendientes)
		c = Starter.skmt.ExecQuery($"SELECT * FROM PESOS where PE_ENVIO_OK <> 1"$)
		Log($"PESOS PENDIENTE: ${c.RowCount}"$)
		If c.RowCount>0 Then
			For i = 0 To c.RowCount -1
				c.Position = i
				Dim cmd As DBCommand
				cmd.Initialize
'				cmd.Name = "insert_pedido2_ADM"
'				cmd.Parameters = Array As Object(c.GetString("PE_CEDIS"),c.GetString("PE_CEDIS"),c.GetString("PE_IDALMACEN"),c.GetString("PE_COSTO_TOT"),c.GetString("PE_COSTOU"),c.GetString("PE_CANT"),c.GetString("PE_PRONOMBRE"),c.GetString("PE_PROID"),c.GetString("PE_CLIENTE"),c.GetString("PE_FECHA"),c.GetString("PE_USUARIO"),Subs.traeRuta2(c.GetString("PE_CLIENTE")), c.GetString("PE_COSTO_SIN"),c.GetString("PE_DESC"),c.GetString("PE_FOLIO"),c.GetString("PE_CANTC"),c.GetString("PE_BCAJAS"),c.GetString("PE_TIPOPAGO"),c.GetString("PE_COMENTARIO"))
'				reqManager.ExecuteCommand(cmd , $"ins_pedidosPendientes_prods_${c.GetString("PE_CLIENTE")}_${c.GetString("PE_PROID")}"$)
'				Log($">>>>  INS_PEDIDO= ${C.GetString("PE_CEDIS")},${ALMACEN},${C.GetString("PE_COSTO_TOT")},${C.GetString("PE_COSTOU")},${C.GetString("PE_CANT")}, ${C.GetString("PE_PRONOMBRE")}, ${C.GetString("PE_PROID")}, ${C.GetString("PE_CLIENTE")}, ${C.GetString("PE_FECHA")}, ${C.GetString("PE_USUARIO")}, ${C.GetString("PE_RUTA")}, ${C.GetString("PE_COSTO_SIN")}, ${C.GetString("PE_DESC")}, ${c.GetString("PE_FOLIO")}, ${PCNoArts}, ${PCMonto}"$)
'				sql.insert_pedido_INTMEX=INSERT INTO INTMEX.PEDIDO (PE_CODPROMO,PE_FECHA_SINC,PE_IDALMACEN,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_COSTO_SIN, PE_DESCUENTO, PE_TIPO) VALUES ((?),SYSDATE,(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),nvl((?),0),(?))
'				sql.insert_pedido2_INTMEX=INSERT INTO INTMEX.PEDIDO (PE_CODPROMO,PE_FECHA_SINC,PE_IDALMACEN,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_COSTO_SIN, PE_DESCUENTO, PE_TIPO, PE_CANT_TOTAL, PE_VENTA_TOTAL) VALUES ((?),SYSDATE,(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),(?),nvl((?),0),(?),(?),(?))

				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insertPesos"
'				Log(c.GetString("PE_IDALMACEN")&", "&ALMACEN&", "&c.GetString("PE_COSTO_TOT")&", "&c.GetString("PE_COSTOU")&", "&c.GetString("PE_CANT")&", "&c.GetString("PE_PRONOMBRE")&", "&c.GetString("PE_PROID")&", "&c.GetString("PE_CLIENTE")&", "&c.GetString("PE_FECHA")&", "&c.GetString("PE_USUARIO")&", "&Subs.traeRuta2(c.GetString("PE_CLIENTE"))&", "& c.GetString("PE_COSTO_SIN")&", "&c.GetString("PE_DESC")&", "&c.GetString("PE_FOLIO")&", "& ALMACEN)
				cmd.Parameters = Array As Object(c.GetString("PE_IDALMACEN"),c.GetString("PE_RUTA"),c.GetString("PE_USUARIO"),c.GetString("PE_CLIENTE"),c.GetString("PE_PESO"),c.GetString("PE_FECHA"),c.GetString("PE_TIPO"),c.GetString("PE_COMENTARIO"),c.GetString("PE_FOTO_CERRADO"))
'				Log($">>>>  insertPesos= ${C.GetString("PE_IDALMACEN")},${c.GetString("PE_RUTA")},${C.GetString("PE_USUARIO")},${C.GetString("PE_CLIENTE")},${C.GetString("PE_PESO")}, ${C.GetString("PE_FECHA")}"$)
				reqManager.ExecuteCommand(cmd , $"insertPesos_${c.GetString("PE_CLIENTE")}"$)
			Next
		End If
		c.Close
	End If
End Sub


Sub JobDone(Job As HttpJob)
	Log("INICA JOBDONE CLIENTES - " & Job.Tag)
	If reqManager.reqsList.IsInitialized Then 'Si tenemos lista de requests, la procesamos.
		If reqManager.reqsList.IndexOf(Job.tag) <> -1 Then
			reqManager.reqsList.RemoveAt(reqManager.reqsList.IndexOf(Job.tag))
			LogColor($">>>>>> Recibimos y quitamos ${Job.tag.As(String).ToUpperCase}"$, Colors.Blue)
		End If
		LogColor(">>>>>> " & reqManager.reqsList.Size & " - " & reqManager.reqsList, Colors.Blue)
	End If
	If Job.Success = False Then
		LogColor("############################################", Colors.red)
		LogColor("######         JobError: " & Job.Tag & CRLF & Job.ErrorMessage, Colors.red)
		LogColor("############################################", Colors.red)
'		LogColor("Error2: " & Job.ErrorMessage, Colors.red)
'		LogColor("Error1: " & reqManager.HandleJob(Job).tag, Colors.red)
'		LogColor("Error: " & reqManager.HandleJob(Job).tag & " : " & Job.ErrorMessage, Colors.red)
'		Job.Release
	Else 'If Job Success then ...
		Try
			LogColor(" >> JobSuccess: '" & reqManager.HandleJob(Job).tag & CRLF & " >> Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.RGB(0,160,0))  'Mod por CHV - 211027
			If Job.JobName = "DBRequest" Then
				Dim RESULT As DBResult = reqManager.HandleJob(Job)
				If RESULT.Tag.As(String).StartsWith("insertPesos_") Then
					For Each records() As Object In RESULT.Rows
						Private id() = Regex.Split("_", RESULT.tag)
						If id.Length > 1 Then
							For Each k As String In RESULT.Columns.Keys
'							Log(RESULT.Tag & ": " & k & ": " & records(RESULT.Columns.Get(k)))
								Starter.skmt.ExecNonQuery($"update pesos set PE_ENVIO_OK = 1 where PE_CLIENTE = '${id(1)}'"$)
'							Log($"update bitacoragps set enviado = 1 where id = '${id(1)}'"$)
							Next
						End If
					Next
				End If
			End If
		Catch
			Log(LastException)
		End Try
	End If
	LogColor(">>>>> Job.Release Clientes - " & Job.Tag, Colors.RGB(179, 146, 0))
	Job.Release
End Sub