B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	Public rp As RuntimePermissions
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
'	Dim reqManager As DBRequestManager
	Dim rd As C_RespaldoDiario
	Dim reqManager As DBRequestManager
	Dim conectado As String
	Dim ime As IME
	Dim t1 As Timer
	Dim sb As StringBuilder
	Dim PHONE As Phone
	Dim g As GPS
	Dim trabajar As Button
'	Dim lat_gps, lon_gps As String
	Dim c As Cursor
	Dim d As Cursor
	Dim b As Cursor
	Dim e As Cursor
	Dim f As Cursor
	Dim D2 As Cursor
	Dim lv As ListView
	Dim cargar As Button
	Dim pendiente As Button
	Dim foto1() As Byte
	Dim usuario As String
	Dim connecta As Button
	Dim conn As String
	Dim Subir As Button
	Dim cmd As DBCommand
	Dim TOPE As Int
	Dim COUNT_CLIE As Int
	Dim fecha As String
	Dim drop As Double
	Dim efectiva As Double
	Dim L_MONTOD As Label
	Dim l_cuantosc As Label
	Dim l_drop As Label
	Dim l_efectiva As Label
	Dim l_ctast As Label
	Dim BUSCA As Button
	Dim Cuantos As String
	Dim l_cuantosn As Label
	Dim e_ruta As EditText
	Dim l_porvisitar As Label
	Dim b_mapa As Button
	Dim l_ruta As Label
	Dim ALMACEN As String
	Private img2 As ImageView
	Dim Listo1 As String
	Dim Listo2 As String
	Dim Listo3 As String
	Dim Listo4 As String
	Dim Listo5 As String
	Dim EJECUTANDO As String
	Dim RES As String
	Dim inve As String
	Dim cuantos_pedidosc As String
	Dim cuantos_pedido As String
	Dim cuantos_noventa As String
	Dim datos_iguales As String
	Dim p As PhoneId
	Dim imei As String
'	Dim SERVER As String
	Private inv As Button
	Private P1 As Panel
	Private CLAVE As EditText
	Private B_OK_PAS As Button
	Dim PASO As String
	Private USUARIO1 As EditText
	Dim connecta1 As Double
	Dim armafolio As String
	Private NUEVO As Button
	Private S_CC As Label
	Private S_CP As Label
	Private S_CH As Label
	Private PB2 As ProgressBar
	Private PB1 As ProgressBar
	Private L_P_1 As Label
	Private L_P_2 As Label
	Private L_P_3 As Label
	Private CARGA As String
	Private PORCENTAJE As String
	Private P_RESUMEN As Panel
	Private B_OK_RES As Button
	Private Resumen As Button
	Private L_CUANTOST As Label
	Private img3 As ImageView
	Private ImageView3 As ImageView
	Private ImageView5 As ImageView
	Private L_TICKPROM As Label
	Private L_MARCAS As ListView
	Private ImageView9 As ImageView
	Private E_RUTA2 As EditText
	Private resdia As ImageView
	Private hacer_ped As ImageView
	Private nvo_cliente As ImageView
	Private tickets_dia As ImageView
	Private l_monto_ks As Label
	Private l_monto_kp As Label
	Private l_monto_k As Label
	Private l_monto_c1 As Label
	Private l_monto_c2 As Label
	Private l_monto_c3 As Label
	Private l_encuesta As Label
	Private bpv1 As BatteryProgressView
	Dim batterystatus(11) As Int
	Private bu As BatteryUtilities
	Private L_NES As Label
	Private L_REAL As Label
	Private L_ALCANCE As Label
	Private L_VPLAN As Label
	Private L_VREAL As Label
	Private L_EFEC_VIS As Label
	Private L_VISITCC As Label
	Private L_EFEC_PV As Label
	Private L_EFEC_PURA As Label
	Private L_CTE_PROMO As Label
	Private L_REDEN_PROMO As Label
	Private L_LIN_TICK As Label
	Private SCROLL_RESDIA As ScrollView
	Private L_ACUMULADO As Label
	Private L_UNILEVER As Label
	Private L_RECHAZOP As Label
	Private L_RECHAZOM As Label
	Private L_VTA_3MES As Label
	Private L_VTA_2MES As Label
	Private L_VTA_1MES As Label
	Private L_MES_PY As Label
	Private L_FREC_DE_CREAL As Label
	Private L_FREC_DE_COBJ As Label
	Private L_COB_VISIT As Label
	Private L_VISIT_REAL As Label
	Private L_VISIT_PLAN As Label
	Private L_ECO As Label
	Private L_COB_CCC As Label
	Private L_CTES As Label
	Private L_VPO_VTA As Label
	Private L_VPO_OBJ As Label
	Private L_DS_VTA As Label
	Private L_DS_OBJ As Label
	Private L_DRA_VTA As Label
	Private L_DRA_OBJ As Label
	Private L_ALCANCEM As Label
	Private L_TENDENCIA As Label
	Private L_VTA_ACUM As Label
	Private L_OBJ_MES As Label
	Private L_DS_OBJD As Label
	Private L_DS_VTAD As Label
	Private LPT As String
	Private STEYIN As String
	Private STEYOUT As String
	Private L_PRIO As Label
	Private L_SECUND As Label
	Private L_COMP As Label
	Private stay_hh As String
	Private stay_mi As String
	Private stay_ss As String
	Dim sDate,sTime As String
	Dim HORAINGRESO As String
	Private L_QUALA As Label
	Private L_FERRERO As Label
	Private L_SANMARCOS As Label
	Private L_CAMPARI As Label
	Private L_IBERIA As Label
	Private L_BEPENSA As Label
	Private L_SCJ As Label
	Private L_MEDJ As Label
	Private L_DURACELL As Label
	Private L_GUNA As Label
	Private L_KIMB As Label
	Private L_TRESM As Label
	Private L_REDB As Label
	Private Btn_Ubicar As Button
	Private B_COMM As Button
	Private L_TOTAL_MM As Label
	Private L_TOTAL_VIVE As Label
	Private L_TOTAL_GUNA As Label
	Private L_TOTAL_BA As Label
	Private L_TOTAL_COMIS As Label
	Private L_TOTAL_MM_1 As Label
	Private L_TOTAL_VIVE_1 As Label
	Private L_TOTAL_GUNA_1 As Label
	Private L_TOTAL_BA_1 As Label
	Private L_TOTAL_COMIS_1 As Label
	Private B_OK_COMISS As Button
	Private Panel_C As Panel
	Private TitleHeight As Int = 50dip
	Private Title2Height As Int = 100dip
	Private DividerHeight As Int = 5dip
	Private CLV1 As CustomListView
	Private pnlTitle As B4XView
	Private xui As XUI
	Type TitleData (Title As String)
	Private B_MARCAS As Button
	Private Panel5 As Panel
	Private lblTitle As Label
	Private B_OK_PANEL5 As Button
	Private p_principal As Panel
	Private p_mandaInfo As Panel
	Dim s As Cursor
	Private Label22 As Label
	Private l_rutasuplencia As Label
	Dim userpiezas As String
	Private b_abordo As Button
	Private L_ABORDO As Label
	Private L_VENTA As Label
	Private L_PREVENTA As Label
	Private p_abordo As Panel
	Private Panel11 As Panel
	Private CLV_PICK_CIEGO As CustomListView
	Private P_PICK_CIEGO As Panel
	Dim ET_PICK_CIEGO As EditText
	Private L_PICK_CIEGO As Label
	Private P_CIEGO As Panel
	Dim Panel4 As Panel
	Dim q_buscar As String
	Private et_buspc As EditText
	Private b_tabulador As Button
	Private p_b_tabulador As Panel
	Private pnlCobranza As Panel
	Private clvCobranza As CustomListView
	Private pnlBtnCobranza As Panel
	Private btnCobranza As Button
	Private pnlBtnRegresar As Panel
	Private btnRegresar As Button
	Private l_Secuencia As Label
	Dim pnlContenedorCobranza As Panel
	Private l_Nombre As Label
	Private l_CuentaXCobrar As Label
	Private l_Abono As Label
	Private pnlCabecero As Panel
	Private lblAbono As Label
	Private lblSaldo As Label
	Private lblCliente As Label
	Private lblSec As Label
	Private pnlTotal As Panel
	Private lblTotal As Label
	Private lblVersion As Label
	Dim lista_punta As List
	Private p_prod As Panel
	Private lv_prod_Prin As ListView
	Private b_regreso As Button
	Private b_productos As Button
	
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("principal")
	rd.Initialize
	rd.vacuum
	EJECUTANDO=1
	Dim ruta As String
	img2.Visible =False
	ruta = File.DirInternal
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
	DateTime.DateFormat = "MM/dd/yyyy"
	fecha=DateTime.Date(DateTime.Now)
	B4XPages.MainPage.skmt.Initialize(ruta,"kmt.db", True)
	b=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	b.Close
	d=B4XPages.MainPage.skmt.ExecQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	d.Position=0
	e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as POR_VISITAR from kmt_info")
	e.Position=0
	f=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CAT_CL_RUTA from kmt_info")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	If l_ruta.Text = 0 Then
		l_ruta.Text =0
	Else
		f=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info")
		f.Position=0
		l_ruta.Text = f.GetString("CAT_CL_RUTA")
		f.Close
	End If
	If Cuantos  = 0 Then
		L_MONTOD.Text =0
		l_cuantosc.Text = 0
		l_cuantosn.Text = 0
		drop = 0
		l_drop.Text = 0
		efectiva = 0
		l_efectiva.text =0
		l_ctast.Text = d.GetString("TOTAL_VISITAR")
		l_porvisitar.Text = e.GetString("POR_VISITAR")
	Else
		c=B4XPages.MainPage.skmt.ExecQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente where PC_CLIENTE <> 0 AND PC_CLIENTE <> 1")
		b=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS from noventa")
		'where pc_fecha = ?", Array As String(fecha)
		c.Position=0
		b.Position=0
		L_MONTOD.Text = c.GetString("MONTO_DIA")
		l_cuantosc.Text = c.GetString("CLIENTES_DIA")
		l_cuantosn.Text = b.GetString("CUANTOS")
'		drop = c.GetString("MONTO_DIA") / c.GetString("CLIENTES_DIA")
		l_drop.Text = Round2(drop,2)
		efectiva = c.GetString("CLIENTES_DIA") / e.GetString("POR_VISITAR")
		l_efectiva.text = Round2(efectiva*100,2)
		l_ctast.Text = d.GetString("TOTAL_VISITAR")
		l_porvisitar.Text = e.GetString("POR_VISITAR")
		b.Close
		c.Close
	End If
	d.Close
	e.Close
'	CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
	s = B4XPages.MainPage.skmt.ExecQuery("select RS_RUTA FROM RUTA_SUPLENCIA")
	s.Position = 0
	If s.RowCount = 0 Then
		Label22.Visible = False
		l_rutasuplencia.Visible = False
	Else If s.RowCount > 0 Then
		Label22.Visible = True
		l_rutasuplencia.Visible = True
		l_rutasuplencia.Text = s.GetString("RS_RUTA")
	End If
	Starter.Skmt.ExecNonQuery($"create table if not exists kmt_info2 (${getTableColumnList(Starter.skmt, "kmt_info")})"$)
End Sub

Sub chkIfTableExists(db As SQL, table As String) As Boolean 'ignore
	Private t As Boolean = False 'ignore
	If db.IsInitialized Then
		Private c As Cursor = Starter.skmt.ExecQuery($"SELECT name FROM sqlite_master WHERE type='table' AND name='${table}'"$)
		If c.RowCount > 0 Then t = True
		c.Close
	End If
	Return t
End Sub

'Regresa solo los nombres de las columnas de una tabla dada.
Sub getTableColumnListName(db As SQL, table As String) As String 'ignore
	Private l As String = ""
	If chkIfTableExists(db, table) Then
		Private c As Cursor = Starter.skmt.ExecQuery($"pragma table_info(${table})"$)
		If c.RowCount > 0 Then
			For i = 0 To c.RowCount - 1
				c.Position = i
				If l.Length = 0 Then
					l = $"${c.GetString("name")}"$
				Else
					l = $"${l}, ${c.GetString("name")}"$
				End If
			Next
		End If
	Else
		Return "No existe la tabla."
	End If
	c.Close
	Return l
End Sub

Sub getTableColumnList(db As SQL, table As String) As String 'ignore
	Private l As String = ""
	If chkIfTableExists(db, table) Then
		Private c As Cursor = Starter.skmt.ExecQuery($"pragma table_info(${table})"$)
		If c.RowCount > 0 Then
			For i = 0 To c.RowCount - 1
				c.Position = i
				If l.Length = 0 Then
					l = $"${c.GetString("name")} ${c.GetString("type")}"$
				Else
					l = $"${l}, ${c.GetString("name")} ${c.GetString("type")}"$
				End If
			Next
		End If
	Else
		Return "No existe la tabla."
	End If
	c.Close
	Return l
End Sub

Sub B4XPage_Appear
'	nvo_cliente.Enabled = False
	rd.respaldaPedido
	rd.respaldaInventarios
	rd.respaldaPaquetes
	HORAINGRESO ="000000"
	Btn_Ubicar.Left = (Root.Width/2) - (Btn_Ubicar.Width/2)
	reqManager.Initialize(Me, Starter.DBReqServer)
	Log(Starter.DBReqServer)
	PASO =0
	If Not(Starter.gps.GPSEnabled) Then
		If Starter.marcaCel <> "Sony" Then ToastMessageShow("Es necesario tener el GPS encendido", True)
		StartActivity(Starter.gps.LocationSettingsIntent)
	End If
	c=B4XPages.MainPage.skmt.ExecQuery2("select count(*) as CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FECHA"))
	c.Position =0
	If c.GetString("CUANTOS") = 0 Then
		cmd.Initialize
		cmd.Name = "select_fecha"
		Log( Starter.DBReqServer)
		reqManager.ExecuteQuery(cmd , 0, "fecha")
		Msgbox("AJUSTAR FECHA","AVISO") 'ignore
		B4XPage_Appear
	Else
		c=B4XPages.MainPage.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FECHA"))
		c.Position=0
		Dim sDate,sTime As String
		DateTime.DateFormat = "yyyyMMdd"
		sDate=DateTime.Date(DateTime.Now)
		If c.GetString("CAT_VA_VALOR") > sDate Then
			Msgbox("AJUSTAR LA FECHA YA QUE ES MENOR AL SISTEMA" ,"AVISO") 'ignore
			c.Close
			B4XPage_Appear
		End If
		c.Close
	End If
	c.Close
	If EJECUTANDO =0 Then
		Listo1 = 0
		Listo2 = 0
		Listo3 = 0
		Listo4 = 0
		Listo5 = 0
		inve = 0
		img2.Visible =False
	End If
	DateTime.DateFormat = "MM/dd/yyyy"
	fecha=DateTime.Date(DateTime.Now)
	b=B4XPages.MainPage.skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente WHERE PC_CLIENTE <> 0  AND PC_CLIENTE <> 1")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	b.Close
'	If Starter.marcaCel <> "Sony" Then ToastMessageShow(Cuantos , True)
	d=B4XPages.MainPage.skmt.ExecQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	d.Position=0
	e=B4XPages.MainPage.skmt.ExecQuery("select count(*) as POR_VISITAR from kmt_info WHERE CAT_CL_CODIGO <>0 OR CAT_CL_CODIGO <>1 ")
	e.Position=0
	f=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CAT_CL_RUTA from kmt_info WHERE CAT_CL_CODIGO <>0 OR CAT_CL_CODIGO <>1 ")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	If l_ruta.Text = 0 Then
		l_ruta.Text =0
		p_b_tabulador.Visible = False
		pnlBtnCobranza.Visible = False
	Else
		p_b_tabulador.Visible = False
		pnlBtnCobranza.Visible = False
		f=B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info")
		f.Position=0
		l_ruta.Text = f.GetString("CAT_CL_RUTA")
		f.Close
	End If
	If Cuantos  = 0 Then
		L_MONTOD.Text =0
		l_cuantosc.Text = 0
		l_cuantosn.Text = 0
		L_CUANTOST.Text = 0
		drop = 0
		l_drop.Text = 0
		efectiva = 0
		l_efectiva.text =0
		l_ctast.Text = d.GetString("TOTAL_VISITAR")
		l_porvisitar.Text = e.GetString("POR_VISITAR")
		d.Close
		e.Close
		b=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS from noventa")
		b.Position=0
		l_cuantosn.Text = b.GetString("CUANTOS")
		b.close
	Else
		c=B4XPages.MainPage.skmt.ExecQuery("select  SUM(PE_COSTO_TOT) as MONTO_DIA, COUNT(DISTINCT(PE_CLIENTE)) AS CLIENTES_DIA  from PEDIDO WHERE PE_CLIENTE <> 0")
		b=B4XPages.MainPage.skmt.ExecQuery("select count(*) as CUANTOS from noventa")
		c.Position=0
		b.Position=0
		L_MONTOD.Text = c.GetString("MONTO_DIA")
		l_cuantosc.Text = c.GetString("CLIENTES_DIA")
	
		D2=B4XPages.MainPage.skmt.ExecQuery("select  COUNT(*) AS CUANTOS   from PEDIDO ")
		D2.Position = 0
		LPT = D2.GetString("CUANTOS") / l_cuantosc.Text
		D2.Close
		
		l_cuantosn.Text = b.GetString("CUANTOS")
		efectiva = c.GetString("CLIENTES_DIA") / e.GetString("POR_VISITAR")
		l_efectiva.text = Round2(efectiva*100,2)
		l_ctast.Text = d.GetString("TOTAL_VISITAR")
		d.Close
		l_porvisitar.Text = e.GetString("POR_VISITAR")
		L_CUANTOST.Text = l_cuantosc.Text + l_cuantosn.Text
		drop = L_CUANTOST.Text / l_porvisitar.Text
		l_drop.Text = Round(drop * 100)
		If L_CUANTOST.Text < 40 Then
			ImageView3.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
		Else If L_CUANTOST.Text > =  40  And L_CUANTOST.Text < 50 Then
			ImageView3.bitmap = LoadBitmap(File.DirAssets, "alerta_amarilla.png")
		Else
			ImageView3.Bitmap = LoadBitmap(File.DirAssets, "palomita_verde.png")
		End If
'		L_TICKPROM.Text =  Round2((c.GetString("MONTO_DIA") / c.GetString("CLIENTES_DIA")),2)
'		If c.GetString("MONTO_DIA") < 4000 Then
'			ImageView5.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
'		Else if c.GetString("MONTO_DIA") > =  4000  And c.GetString("MONTO_DIA") < 6250 Then
'			ImageView5.bitmap = LoadBitmap(File.DirAssets, "alerta_amarilla.png")
'		Else
'			ImageView5.Bitmap = LoadBitmap(File.DirAssets, "palomita_verde.png")
'		End If
		b.Close
		c.Close
	End If
	c.Close
	b.Close
	e.Close
	c=B4XPages.MainPage.skmt.ExecQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	c.Close
	bu.Initialize
	batterystatus = bu.BatteryInformation

	
	c=B4XPages.MainPage.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
'	B4XPages.MainPage.batt = batterystatus(0)
'	B4XPages.MainPage.montoActual = L_MONTOD.Text
'	B4XPages.MainPage.clientestotal = L_CUANTOST.Text
'	B4XPages.MainPage.clientesventa =  l_cuantosc.Text
'	B4XPages.MainPage.clientesvisitados = l_porvisitar.TEXT
'	B4XPages.MainPage.ALMACEN = ALMACEN
'	B4XPages.MainPage.rutapreventa =  l_ruta.text

	Dim conVen As Int = 0
	Dim sinVen As Int = 0

	Dim cursor As Cursor = Starter.skmt.ExecQuery($"SELECT SUM(PE_COSTO_TOT) AS PE_COSTO_TOT, COUNT(DISTINCT PE_CLIENTE) AS PE_CLIENTE FROM PEDIDO WHERE PE_FOLIO <> 'RECARGA'"$)
	If cursor.RowCount > 0 Then
		cursor.Position = 0
		B4XPages.MainPage.montoActual = cursor.GetString("PE_COSTO_TOT")
		B4XPages.MainPage.clientesventa = cursor.GetString("PE_CLIENTE")
		conVen = cursor.GetInt("PE_CLIENTE")
	End If
	Log("Clientes con venta: " & conVen)

	Dim cNoVenta As Cursor = Starter.skmt.ExecQuery($"SELECT COUNT(DISTINCT NV_CLIENTE) AS NV_CLIENTE FROM NOVENTA"$)
	If cNoVenta.RowCount > 0 Then
		cNoVenta.Position = 0
		sinVen = cNoVenta.GetInt("NV_CLIENTE")
		
		Log("Clientes sin venta: " & sinVen)

		Dim totClientes As Int = sinVen + conVen
		Log("Total clientes visitados: " & totClientes)
		
	End If


	B4XPages.MainPage.batt = batterystatus(0)
	B4XPages.MainPage.clientestotal = totClientes
	B4XPages.MainPage.clientesvisitados = l_porvisitar.Text
	B4XPages.MainPage.ALMACEN = ALMACEN
	B4XPages.MainPage.rutapreventa = l_ruta.Text
	
	'//////  Para el usuario global - Chv
	c=B4XPages.MainPage.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	B4XPages.MainPage.usuario = usuario
	c.Close
	'///////
	CallSub(Starter, "ENVIA_ULTIMA_GPS")
	
	
	s = B4XPages.MainPage.skmt.ExecQuery("select RS_RUTA FROM RUTA_SUPLENCIA")
	s.Position = 0
	If s.RowCount = 0 Then
		
		Label22.Visible = False
		l_rutasuplencia.Visible = False
		l_rutasuplencia.Text = ""
	
	Else If s.RowCount > 0 Then
	
		Label22.Visible = True
		l_rutasuplencia.Visible = True
		l_rutasuplencia.Text = s.GetString("RS_RUTA")
		
	End If
	s.Close
	
	s = B4XPages.MainPage.skmt.ExecQuery("select RUTAA FROM RUTAA")
	s.Position = 0
	If s.RowCount = 0 Then
		
		
		l_ruta.Text = 0
	
	Else If s.RowCount > 0 Then
	
		l_ruta.Text = s.GetString("RUTAA")
		
	End If
	
	If l_ruta.Text = "0" Then
		p_abordo.Visible = False
		b_productos.Visible = False
	Else 
		p_abordo.Visible = True
		b_productos.Visible = True
	End If
	
'	d = B4XPages.MainPage.skmt.ExecQuery("SELECT CAT_GP_ID, CAT_GP_NOMBRE FROM CAT_GUNAPROD2")
'	CLV_PICK_CIEGO.Clear
'	For i = 0 To d.RowCount - 1
'		d.Position = i
'		CLV_PICK_CIEGO.Add(CreateListItem(d.GetString("CAT_GP_ID"), d.GetString("CAT_GP_NOMBRE")),i)
'		Log(d.GetString("CAT_GP_ID"))
'		Log(d.GetString("CAT_GP_NOMBRE"))
'	Next
'	d.Close
	'-----------------------------
	
	Dim fg As Cursor = Starter.skmt.ExecQuery("SELECT IFNULL(SUM(CASE WHEN PE_FOLIO = 'PREVENTA_CREDITO' THEN PE_COSTO_TOT ELSE 0 END), 0) AS COSTO_CRED, IFNULL(SUM(CASE WHEN PE_FOLIO = 'PREVENTA_CONTADO' THEN PE_COSTO_TOT ELSE 0 END), 0) AS COSTO_CONTADO FROM PEDIDO WHERE PE_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND PE_FOLIO IN ('PREVENTA_CREDITO', 'PREVENTA_CONTADO')")

	fg.Position = 0
	Dim COSTO_CRED As Double = fg.GetDouble("COSTO_CRED")
	Dim COSTO_CONTADO As Double = fg.GetDouble("COSTO_CONTADO")

	Log("Costo Crédito: " & COSTO_CRED & "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
	Log("Costo Contado: " & COSTO_CONTADO & "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")

	If COSTO_CRED > 0 And COSTO_CRED < 1000 Then
		Msgbox2Async($"Se ha detectado venta a crédito menor a $1000 pesos. ¿Desea borrarla?"$, "Venta Mínima de Crédito", "Sí", "", "", LoadBitmap(File.DirAssets, "alert2.png"), False)
		Wait For Msgbox_Result (resultado As Int)
		If resultado = DialogResponse.POSITIVE Then
			Subs.borraPedidoCredito
		End If
	End If

	fg.Close
	
	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
	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
	checaPedido
	'-----------------------------
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 MapFragment1_LongClick (mPoint As LatLng)
	' Verificar si el punto está dentro del polígono
	If lista_punta.Size > 0 Then
		Dim dentro As Boolean = PointInPolygon(mPoint, lista_punta)
        
		If dentro Then
			ToastMessageShow("El punto está DENTRO del polígono", True)
		Else
			ToastMessageShow("El punto está FUERA del polígono", True)
		End If
	End If
End Sub


Sub Subir_Click
	CARGA = "SUBIR"
	p_mandaInfo.Width = Root.Width
	p_mandaInfo.Height = Root.Height
	P1.Visible = True
	P1.Left = (p_mandaInfo.Width/2) - (P1.Width/2)
	P1.top = (p_mandaInfo.Height/2) - (P1.Height/2)
	p_mandaInfo.Visible = True
	P1.BringToFront
	p_mandaInfo.BringToFront
	'trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	L_P_1.Visible = False
	S_CC.Visible = False
	L_P_3.Visible = False
	S_CH.Visible = False
	PB1.Visible = False
	Resumen.Visible= False
	L_P_2.Text = "Envio de Pedidos"
	L_P_3.Text = "Envio de Pedidos"
	S_CH.Text = "EN PROCESO"
	S_CP.Text = "EN PROCESO"
	PB1.Progress = 0
	PB2.Progress = 0
	'c=skmt.ExecQuery("SELECT sum(IFNULL(PE_DESC,0)) as DESCUENTO FROM PEDIDO")
	'c.Position =0
	'If c.GetString("DESCUENTO") > 0 And PASO = 0 Then
	'P1.Visible = True
	'ELSE IF c.GetString("DESCUENTO") = 0 Then
	PASO = 1
	'End If
	If PASO = 1 Then
		B4XPages.MainPage.skmt.ExecNonQuery2("delete from PEDIDO WHERE PE_PRONOMBRE = ? ", Array As Object("N/A") )
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE not In (select PE_CLIENTE from pedido)")
		c=B4XPages.MainPage.skmt.ExecQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
		c.Close
		c=B4XPages.MainPage.skmt.ExecQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "UPDATE_SHARK2_ACTUAL2_GPS"
				cmd.Parameters = Array As String(B4XPages.MainPage.montoActual, B4XPages.MainPage.clientestotal, B4XPages.MainPage.clientesventa,B4XPages.MainPage.clientesvisitados,B4XPages.MainPage.lat_gps,B4XPages.MainPage.lon_gps,B4XPages.MainPage.batt,0, 0, 0,B4XPages.MainPage.ALMACEN,B4XPages.MainPage.rutapreventa )
				reqManager.ExecuteCommand(cmd , "update_gps")
			Next
		End If
		c.Close

'		' ENVIO DE LOS CODIGOS QR
'		'c=skmt.ExecQuery2("SELECT CAT_CL_NUM_SERIEFISICO,CAT_CL_CODIGO ,CAT_CL_LONG,CAT_CL_LAT, CAT_CL_FOTO FROM kmt_info where CAT_CL_NUM_SERIEFISICO = ?", Array As String("OK"))
'		c=B4XPages.MainPage.skmt.ExecQuery("SELECT CODIGOKMTS, CODIGOB, LAT, LON FROM HIST_CODIGO_BARRAS" )
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_QR_2_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("CODIGOKMTS"),C.GetString("CODIGOB"),C.GetString("LON"),C.GetString("LAT"),ALMACEN,l_ruta.text )
'				reqManager.ExecuteCommand(cmd , "ins_QR")
'			Next
'		End If
'		c.Close
'
'		c=B4XPages.MainPage.skmt.ExecQuery("SELECT CAT_CL_NUM_SERIEFISICO, CAT_CL_CODIGO, CAT_CL_LONG, CAT_CL_LAT, CAT_CL_FOTO FROM kmt_info where CAT_CL_NUM_SERIEFISICO IS NOT NULL")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				's=skmt.ExecQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
'				's.Position =0
'				foto1 = c.GetBlob("CAT_CL_FOTO")
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_QR_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("CAT_CL_NUM_SERIEFISICO"),C.GetString("CAT_CL_CODIGO"),C.GetString("CAT_CL_LONG"),C.GetString("CAT_CL_LAT"),ALMACEN,l_ruta.text )
'				reqManager.ExecuteCommand(cmd , "ins_QR")
'			Next
'		End If
'		c.Close
		
'		'Envio de Pagares
'		c=B4XPages.MainPage.skmt.ExecQuery("SELECT * FROM PAGARES")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_pagares_IZCA"
'				cmd.Parameters = Array As Object(C.GetString("PA_ALMACEN"),Subs.traeRuta2(c.GetString("PA_CLIENTE")),C.GetString("PA_FECHA"),C.GetString("PA_CAPTURA"),C.GetString("PA_MONTO"),C.GetString("PA_USUARIO"),C.GetString("PA_CLIENTE") )
'				reqManager.ExecuteCommand(cmd , "ins_pagares")
'			Next
'		End If
'		c.Close
'		
'		'ABONOS
'		Dim ab As Cursor = B4XPages.MainPage.skmt.ExecQuery($"SELECT * from ABONOS where a_enviado is null"$)
'		Log(ab.RowCount)
'		If ab.RowCount > 0 Then
'			For i=0 To ab.RowCount -1
'				ab.Position = i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_abono_IZCA"
'				cmd.Parameters = Array As Object( ab.GetString("a_usuario"), ab.GetString("a_ruta"), ab.GetString("a_cliente"), ab.GetString("a_abono"), ab.GetString("a_fecha"),ALMACEN )
'				reqManager.ExecuteCommand(cmd , $"ins_abonosPendientes_${ab.GetString("a_cliente")}"$)
'				Log($"ins_abonosPendientes_${ab.GetString("a_cliente")}"$)
'			Next
'		End If
'		ab.Close
		
		' CLIENTES NUEVOS
'		Dim fotocn() As Byte
'		Dim Dirp As String = File.DirInternal
'		Dim Dir As String
'		Dim Dir2 As String
'		Dir = "/promotoriakmts"
		
		c=Starter.skmt.ExecQuery("SELECT CN_ID, CN_FECHA , CN_USER, CN_LAT, CN_LON, CN_NOMBRE, CN_DIRECCION, CN_FOTO, CN_ALMACEN, CN_RUTA, CN_GIRO, CN_SOLICITA, CN_COLONIA, CN_TELEFONO, CN_CP FROM CLIENTES_NUEVOS")
		If c.RowCount>0 Then
			For i = 0 To c.RowCount - 1
				c.Position = i
				Dim dia As Int = DateTime.GetDayOfWeek(DateTime.Now)
				If dia = 2  Then
					Dim dialetra As String = "LUNES"
				Else If dia = 3  Then
					Dim dialetra As String = "MARTES"
				Else If dia = 4  Then
					Dim dialetra As String = "MIERCOLES"
				Else If dia = 5  Then
					Dim dialetra As String = "JUEVES"
				Else If dia = 6  Then
					Dim dialetra As String = "VIERNES"
				Else If dia = 7  Then
					Dim dialetra As String = "SABADO"
				End If
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_clientesnuevos_SHARK24"
				Log(c.GetString("CN_ID")&"    ,"& c.GetString("CN_FECHA")&"    ,"& c.GetString("CN_USER")&"    ,"& c.GetString("CN_LAT")&"    ,"& c.GetString("CN_LON")&"    ,"& c.GetString("CN_NOMBRE")&"    ,"& c.GetString("CN_DIRECCION")&"    ,"&ALMACEN& c.GetString("CN_RUTA")&"    ,"& "En espera"&c.GetString("CN_GIRO")&"    ,"&dialetra& c.GetString("CN_SOLICITA")&"    ,"& c.GetString("CN_COLONIA")&"    ,"& c.GetString("CN_TELEFONO"))
				cmd.Parameters = Array As Object(c.GetString("CN_ID"), c.GetString("CN_FECHA"), c.GetString("CN_USER"), c.GetString("CN_LAT"), c.GetString("CN_LON"), c.GetString("CN_NOMBRE"), c.GetString("CN_DIRECCION"),ALMACEN, c.GetString("CN_RUTA"), "En espera",c.GetString("CN_GIRO"),dialetra, c.GetString("CN_SOLICITA"), c.GetString("CN_COLONIA"), c.GetString("CN_TELEFONO"), c.GetString("CN_CP"))
				reqManager.ExecuteCommand(cmd , "inst_clientesn")
			Next
		End If
		c.Close

'		c=B4XPages.MainPage.skmt.ExecQuery("SELECT  HE_CLIE, HE_RES, HE_FECHA, HE_TIPO FROM HIST_ENCUESTA")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_encuesta_INTMEX"
'				cmd.Parameters = Array As Object(C.GetString("HE_CLIE"),C.GetString("HE_RES"),C.GetString("HE_FECHA"), c.GetString("HE_TIPO"))
'				reqManager.ExecuteCommand(cmd , "inst_noventa")
'			Next
'		End If
'		c.Close
		
		' PEDIDO_CLIENTE
		Dim PCNoArts As String
		Dim PCMonto As String
		c = B4XPages.MainPage.skmt.ExecQuery("SELECT PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT, PC_COSTO_SIN, PC_RUTA, PC_ALMACEN, PC_FACTURA FROM PEDIDO_CLIENTE WHERE PC_CLIENTE <> '1' ")
		d = B4XPages.MainPage.skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDOSC FROM PEDIDO_CLIENTE WHERE PC_CLIENTE <> 1 ")
		If c.RowCount > 0 Then
			For i = 0 To c.RowCount - 1
				c.Position = i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_pedidos_SHARK2"
				PCNoArts = c.GetString("PC_NOART")
				PCMonto = c.GetString("PC_MONTO")
				cmd.Parameters = Array As Object(c.GetString("PC_CLIENTE"), c.GetString("PC_FECHA"), c.GetString("PC_USER"), c.GetString("PC_NOART"), c.GetString("PC_MONTO"), c.GetString("PC_LON"), c.GetString("PC_LAT"), ALMACEN, Subs.traeRuta2(c.GetString("PC_CLIENTE")), c.GetString("PC_COSTO_SIN"), c.GetString("PC_FACTURA"))
				reqManager.ExecuteCommand(cmd , "ins_pedidos")
				Log(">>>>>>  INSERT PEDIDO_CLIENTE")
			Next
		End If
		c.Close
		d.Position = 0
		cuantos_pedidosc = d.GetString("CUANTOS_PEDIDOSC")
		d.Close

		' PEDIDO
		c = B4XPages.MainPage.skmt.ExecQuery("SELECT PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO, PE_COSTO_SIN, PE_RUTA, PE_DESC, PE_FOLIO, PE_CANTC, PE_BCAJAS, PE_DIRIGIDA, PE_PRESENTACION, PE_UVM FROM PEDIDO WHERE PE_FOLIO <> 'RECARGA'")
		d = B4XPages.MainPage.skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
		If c.RowCount > 0 Then
			For i = 0 To c.RowCount - 1
				c.Position = i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_pedido4_SHARK2" 'CON TOTALES INCLUIDOS
'				Log(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")&", "&Subs.traeRuta2(c.GetString("PE_CLIENTE"))&", "& c.GetString("PE_COSTO_SIN")&", "&c.GetString("PE_DESC")&", "&c.GetString("PE_FOLIO")&", "& ALMACEN)
				If c.GetString("PE_FOLIO") = "PREVENTA_CONTADO" Then
					cmd.Parameters = Array As Object(ALMACEN,c.GetString("PE_CEDIS"),ALMACEN,c.GetString("PE_COSTO_TOT"),c.GetString("PE_COSTOU"),(c.GetString("PE_CANT")/c.GetString("PE_UVM")),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"),"PREVENTA",c.GetString("PE_DIRIGIDA"),c.GetString("PE_PRESENTACION"), c.GetString("PE_UVM"))
				Else If c.GetString("PE_FOLIO") = "PREVENTA_CREDITO" Then					
					cmd.Parameters = Array As Object(ALMACEN,c.GetString("PE_CEDIS"),ALMACEN,c.GetString("PE_COSTO_TOT"),c.GetString("PE_COSTOU"),(c.GetString("PE_CANT")/c.GetString("PE_UVM")),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"),"PREVENTA",c.GetString("PE_DIRIGIDA"),c.GetString("PE_PRESENTACION"), c.GetString("PE_UVM"))
				Else If c.GetString("PE_FOLIO") = "ABORDO" Then
					cmd.Parameters = Array As Object(ALMACEN,c.GetString("PE_CEDIS"),ALMACEN,c.GetString("PE_COSTO_TOT"),c.GetString("PE_COSTOU"),(c.GetString("PE_CANT")/c.GetString("PE_UVM")),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"),"ABORDO",c.GetString("PE_DIRIGIDA"),c.GetString("PE_PRESENTACION"), c.GetString("PE_UVM"))
				Else
					cmd.Parameters = Array As Object(ALMACEN,c.GetString("PE_CEDIS"),ALMACEN,c.GetString("PE_COSTO_TOT"),c.GetString("PE_COSTOU"),(c.GetString("PE_CANT")/c.GetString("PE_UVM")),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"),"VENTA",c.GetString("PE_DIRIGIDA"),c.GetString("PE_PRESENTACION"), c.GetString("PE_UVM"))
				End If
				reqManager.ExecuteCommand(cmd , $"ins_pedidosPendientes_prods_${c.GetString("PE_CLIENTE")}_${c.GetString("PE_PROID")}"$)
			Next
		End If
		c.Close
		d.Position=0
		cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
		d.Close

		' NOVENTA
		c=B4XPages.MainPage.skmt.ExecQuery("SELECT  NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON FROM NOVENTA")
		D=B4XPages.MainPage.skmt.ExecQuery("SELECT  COUNT(*) AS CUANTOS_NOVENTA FROM NOVENTA")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_noventa_SHARK2"
				cmd.Parameters = Array As Object(C.GetString("NV_CLIENTE"),C.GetString("NV_FECHA"),C.GetString("NV_USER"),C.GetString("NV_MOTIVO"),C.GetString("NV_COMM"),C.GetString("NV_LAT"),C.GetString("NV_LON"), ALMACEN, Subs.traeRuta2(c.GetString("NV_CLIENTE")))
				reqManager.ExecuteCommand(cmd , "inst_noventa")
			Next
		End If
		c.Close
		d.Position=0
		cuantos_noventa = D.GetString("CUANTOS_NOVENTA")
		d.Close

'		' GEO CERCA
'		c=B4XPages.MainPage.skmt.ExecQuery("Select HGCLIENTE, HGDATE, HGLAT, HGLON from HIST_GEOCERCA")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_geocerca_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("HGCLIENTE"),C.GetString("HGDATE"),C.GetString("HGLAT"),C.GetString("HGLON"))
'				reqManager.ExecuteCommand(cmd , "inst_noventa")
'			Next
'		End If
'		c.Close

'		' Cambio ubicaciones
'		c=B4XPages.MainPage.skmt.ExecQuery("Select CAT_CL_LAT, CAT_CL_LONG, CAT_CL_CODIGO, CAT_CL_BCOORDENADAS from kmt_info where CAT_CL_BCOORDENADAS <> 0")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "update_coordenadas_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("CAT_CL_LAT"),C.GetString("CAT_CL_LONG"),C.GetString("CAT_CL_CODIGO"),ALMACEN,Subs.traeRuta2(C.GetString("CAT_CL_CODIGO")))
'				reqManager.ExecuteCommand(cmd , "up_coordenadas")
'			Next
'		End If
'		c.Close
		
'		' Cambio atiende
'		c=B4XPages.MainPage.skmt.ExecQuery("Select CAT_CL_ATIENDE1, CAT_CL_CODIGO from kmt_info where CAT_CL_CODIGO IN (SELECT CLIENTE FROM ATIENDE)")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "update_atiende_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("CAT_CL_ATIENDE1"),C.GetString("CAT_CL_CODIGO"),ALMACEN,Subs.traeRuta2(C.GetString("CAT_CL_CODIGO")))
'				reqManager.ExecuteCommand(cmd , "up_coordenadas")
'			Next
'		End If
'		c.Close
		
'		' Cambio giro
'		c=B4XPages.MainPage.skmt.ExecQuery("Select CAT_CL_GIRO, CAT_CL_CODIGO from kmt_info where CAT_CL_CODIGO IN (SELECT CLIENTE FROM GIROS_ACTUAL)")
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "update_giro_SHARK2"
'				cmd.Parameters = Array As Object(C.GetString("CAT_CL_GIRO"),C.GetString("CAT_CL_CODIGO"),ALMACEN,Subs.traeRuta2(C.GetString("CAT_CL_CODIGO")))
'				reqManager.ExecuteCommand(cmd , "up_coordenadas")
'			Next
'		End If
		c.Close
		
'		'TABULADOR
'		c = Starter.skmt.ExecQuery("SELECT VEINTE, DIEZ, CINCO, DOS, PESO, CENTAVO, TOTAL FROM TABULADOR_MONEDAS")
'		d = Starter.skmt.ExecQuery("SELECT RUTAA FROM RUTAA")
'		b = Starter.skmt.ExecQuery("SELECT ID_ALMACEN FROM CAT_ALMACEN")
''		f = Starter.skmt.ExecQuery("SELECT HVD_FECHA FROM HIST_VENTAS")
'		d.Position = 0
'		b.Position = 0
'		f.Position = 0
'		If c.RowCount > 0 Then
'			For i = 0 To c.RowCount - 1
'				c.Position=i
'				Dim cmd As DBCommand
'				
'				Dim sDate,sTime As String
'				DateTime.DateFormat = "MM/dd/yyyy"
'				sDate=DateTime.Date(DateTime.Now)
'				sTime=DateTime.Time(DateTime.Now)
'				
''				Dim fechatabulador() As String = Regex.Split(" ", f.GetString("HVD_FECHA"))
''				Dim fechatabulador2() As String = Regex.Split("-", fechatabulador(0))
''				Dim fechatabulador3 As String = fechatabulador2(1)&"/"&fechatabulador2(2)&"/"&fechatabulador2(0)
'				cmd.Initialize
'				cmd.Name = "insert_tabulador_monedas_SHARK22"
'				cmd.Parameters = Array As Object(d.GetString("RUTAA"), b.GetString("ID_ALMACEN"),c.GetString("VEINTE"),c.GetString("DIEZ"),c.GetString("CINCO"),c.GetString("DOS"),c.GetString("PESO"),c.GetString("CENTAVO"),sDate, "PREVENTA")
'				reqManager.ExecuteCommand(cmd , "ins_tabulador_mon")
'			Next
'			c.Close
'			d.Close
'			b.Close
'			f.Close
'		End If
'
'		c = Starter.skmt.ExecQuery("SELECT MIL, QUINIENTOS, DOCIENTOS, CIEN, CINCUENTA, VEINTE FROM TABULADOR_BILLETES")
'		d = Starter.skmt.ExecQuery("SELECT RUTAA FROM RUTAA")
'		b = Starter.skmt.ExecQuery("SELECT ID_ALMACEN FROM CAT_ALMACEN")
''		f = Starter.skmt.ExecQuery("SELECT HVD_FECHA FROM HIST_VENTAS")
'		d.Position = 0
'		b.Position = 0
'		f.Position = 0
'		If c.RowCount > 0 Then
'			For i = 0 To c.RowCount - 1
'				c.Position=i
'				Dim cmd As DBCommand
'				
'				DateTime.DateFormat = "MM/dd/yyyy"
'				sDate=DateTime.Date(DateTime.Now)
'				sTime=DateTime.Time(DateTime.Now)
'				
''				Dim fechatabulador() As String = Regex.Split(" ", f.GetString("HVD_FECHA"))
''				Dim fechatabulador2() As String = Regex.Split("-", fechatabulador(0))
''				Dim fechatabulador3 As String = fechatabulador2(1)&"/"&fechatabulador2(2)&"/"&fechatabulador2(0)
'				cmd.Initialize
'				cmd.Name = "insert_tabulador_billetes_SHARK22"
'				cmd.Parameters = Array As Object(b.GetString("ID_ALMACEN"), d.GetString("RUTAA"),c.GetString("MIL"),c.GetString("QUINIENTOS"),c.GetString("DOCIENTOS"),c.GetString("CIEN"),c.GetString("CINCUENTA"),c.GetString("VEINTE"),sDate, "PREVENTA")
'				reqManager.ExecuteCommand(cmd , "ins_tabulador_bill")
'			Next
'			c.Close
'			d.Close
'			b.Close
'			f.Close
'		End If
'		'FIN TABULADOR

		' DROP
		t1.Initialize("T1", 30000) ' 1000 = 1 second
		t1.Enabled = True
		Dim sDate,sTime As String
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="insert_drop_SHARK2"
		cmd.Parameters = Array As Object(usuario,l_ruta.Text,sDate & sTime, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text,"ENVIO",ALMACEN,Application.VersionName)
		reqManager.ExecuteCommand(cmd , "inst_noventa")
		img2.Visible =True
		PORCENTAJE = Round(100/ (cuantos_noventa + cuantos_pedido + cuantos_pedidosc + 1))
		If Starter.marcaCel <> "Sony" Then ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)

'		'CUESTIONARIOS
'		c = B4XPages.MainPage.skmt.ExecQuery($"select * from cuestionario"$)
'		Private rutaActual As String = Subs.traeRuta
'		If c.RowCount > 0 Then
'			For x = 0 To c.RowCount - 1
'				c.Position = x
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_CUESTIONARIO_INTMEX"
'				cmd.Parameters = Array As Object(c.GetString("Q_IDCLIENTE"), rutaActual, ALMACEN, c.GetString("Q_FECHA"), c.GetString("Q_IDPREGUNTA"), c.GetString("Q_PREGUNTA"), c.GetString("Q_IDRESPUESTA"), C.GetString("Q_RESPUESTA"))
'				reqManager.ExecuteCommand(cmd , "ins_cuestionario")
'			Next
'		End If
'		c.Close
		
		
'		c = B4XPages.MainPage.skmt.ExecQuery("SELECT * FROM PEDIDO_CLIENTE WHERE PC_CLIENTE <> 01")
'		If c.RowCount > 0 Then
'			For i = 0 To c.RowCount - 1
'				c.Position = i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "select_piezas_IZCA"
'				cmd.Parameters = Array As Object(c.GetString("PC_CLIENTE"), ALMACEN,l_ruta.Text)
'				userpiezas = c.GetString("PC_CLIENTE")
'				reqManager.ExecuteQuery(cmd , 0, "piezas")
'			Next
'			
'		End If
		
	End If
End Sub


Sub cargar_Click
	Dim pedidodiaanterior As Boolean = False
	Dim cp As Cursor = B4XPages.MainPage.skmt.ExecQuery("select * from PEDIDO")
	If cp.RowCount > 0 Then
		cp.Position = 0
		Private fecha As String = cp.GetString("PE_FECHA")
		Dim fecha2() As String = Regex.Split("/",fecha)
		Dim dia As String = fecha2(1)
		Log(dia)
		Dim dia2 As String = DateTime.GetDayOfMonth(DateTime.Now)
		Log(dia & " , " & dia2)
		If dia < dia2 Then
			pedidodiaanterior = True
		End If
	End If
	If Not (pedidodiaanterior) Then
		CARGA = "CARGAR"
		p_mandaInfo.Width = Root.Width
		p_mandaInfo.Height = Root.Height
		P1.Left = (p_mandaInfo.Width/2) - (P1.Width/2)
		P1.top = (p_mandaInfo.Height/2) - (P1.Height/2)
		img2.Visible =True
		L_P_1.Visible = True
		S_CC.Visible = True
		Btn_Ubicar.Visible=False
		P1.Visible = True
		p_mandaInfo.Visible = True
		p_principal.Visible = False
		Subs.panelVisible(P1, 0, 0)
		Subs.centraPanel(P1, Root.Width)
		Subs.centraPanelV(P1, Root.Height)
'	trabajar.Visible = False
		NUEVO.Visible =False
		BUSCA.Visible=False
		connecta.Visible=False
		L_P_3.Visible = True
		S_CH.Visible = True
		PB1.Visible = True
		Resumen.Visible= False

		L_P_1.Text = "Catalogo de Clientes"
		L_P_2.Text = "Catalogos de Productos"
		L_P_3.Text = "Catalogos Historicos"
		S_CC.Text = "EN PROCESO"
		S_CH.Text = "EN PROCESO"
		S_CP.Text = "EN PROCESO"
		PB1.Progress = 0
		PB2.Progress = 0
		EJECUTANDO = 1

		'c=skmt.ExecQuery("CREATE TABLE kmt_info (pr_cd_credito NUMERIC,pr_cd_nombre TEXT,pr_cd_calle TEXT,pr_cd_numero TEXT,pr_cd_num_int TEXT,pr_cd_entrecalle1 TEXT,pr_cd_entrecalle2 TEXT,pr_cd_colonia TEXT,pr_cd_poblacion TEXT,pr_cd_edo TEXT,pr_cd_cp TEXT,pr_cd_zona TEXT,pr_cf_credito NUMERIC,pr_cf_saldotot NUMERIC,pr_cf_saldooper NUMERIC,pr_cf_saldof1 NUMERIC, pr_cf_penalizacion NUMERIC)")
		TOPE = 0
		' NUEVOS CLIENTE
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM RUTA_SUPLENCIA")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM RUTAA")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM GEOCERCA")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM COORDS_ALMACEN")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from CLIENTE_NUEVO")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from kmt_info")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from kmt_info2")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from cod_result")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from hist_gest")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod2")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod3")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod4")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from telefonos")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_VENTAS")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_PROMOS")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from PROMOS_COMP")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_VERIFICACION")
		Starter.skmt.ExecNonQuery("delete from CAT_GIRO")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM MARCAS_RUTAS")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_STAY_STORE")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_GEOCERCA")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_MARCAS_CUOTAS")
'		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_AVANCE")
		B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM ABONOSP")

		c = B4XPages.MainPage.skmt.ExecQuery2("select count(CAT_VA_DESCRIPCION) as HoraIngreso from cat_variables where CAT_VA_DESCRIPCION = ? ", Array As String("HoraIngreso"))
		c.Position = 0
		DateTime.TimeFormat = "HHmmss"
		'Valida si ya se cuenta con hora actualiza el valor si no lo inserta-----------
		If c.GetString("HoraIngreso") > 0 Then
			B4XPages.MainPage.skmt.ExecNonQuery2("Update cat_variables set CAT_VA_VALOR = ?  WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
		Else
			B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_VALOR,CAT_VA_DESCRIPCION)  VALUES (?,?)" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
		End If
		c.Close
		DateTime.TimeFormat = "HH:mm:ss"
		c=B4XPages.MainPage.skmt.ExecQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
		c.Close
'
		Dim sDate,sTime As String
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)

		Dim P As PhoneId
'	imei = P.GetDeviceId
		imei = "xxxx"
		cmd.Initialize
		cmd.Name ="insert_drop_SHARK2"
		cmd.Parameters = Array As Object(usuario,e_ruta.text,sDate,imei,sTime,"","","","","CARGA",ALMACEN,Application.VersionName)
		'usuario,l_ruta.Text,sDate & sTime, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text,"ENVIO",ALMACEN,Application.VersionName
		reqManager.ExecuteCommand(cmd , "inst_noventa")

		cmd.Initialize
		cmd.Name = "select_cat_gunaprod_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprod")
		
		cmd.Initialize
		cmd.Name = "select_cat_gunaprod2_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN,e_ruta.Text)
		reqManager.ExecuteQuery(cmd , 0, "gunaprod2")
		
'		cmd.Initialize
'		cmd.Name = "select_GEOCERCA_SHARK2"
'		cmd.Parameters = Array As Object(ALMACEN)
'		reqManager.ExecuteQuery(cmd , 0, "GEOCERCA")
		
		cmd.Initialize
		cmd.Name = "select_coords_almacen_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "coords_almacen")
		
'		cmd.Initialize
'		cmd.Name = "select_cat_gunaprod3_SHARK2"
'		cmd.Parameters = Array As Object(ALMACEN,e_ruta.Text)
'		reqManager.ExecuteQuery(cmd , 0, "gunaprod3")
'		
		cmd.Initialize
		cmd.Name = "select_cat_GIRO_SHARK2"
		reqManager.ExecuteQuery(cmd , 0, "giro")

'	cmd.Initialize
'	cmd.Name = "select_resum_apk_INTMEX"   ''' va el nombre de archivo de config
'	cmd.Parameters = Array As Object(ALMACEN)
'	reqManager.ExecuteQuery(cmd , 0, "resum_apk") ''' donde regresa la info ver job_done

		cmd.Initialize
		cmd.Name = "select_cat_paquetes_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
'		Log("ALMACEN = " & ALMACEN)

		cmd.Initialize
		cmd.Name = "select_cat_paquetess_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprodp")

		cmd.Initialize
		cmd.Name = "select_cat_detallepa_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "detallepaq")

		cmd.Initialize
		cmd.Name = "select_cat_clientes_SHARK2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "kmt_datos")

		cmd.Initialize
		cmd.Name = "select_cat_clientes_todos_SHARK2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "kmt_datos_todos")

		cmd.Initialize
		cmd.Name = "select_hist_datos_SHARK2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_datos")

		cmd.Initialize
		cmd.Name = "select_hist_promos_SHARK2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_promos")

'		cmd.Initialize
'		cmd.Name = "select_clientes_cuestionario_SHARK2"
'		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
'		reqManager.ExecuteQuery(cmd , 0, "clientes_cuestionario")

		cmd.Initialize
		cmd.Name = "select_hist_cliente_promos_SHARK2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
		
		cmd.Initialize
		cmd.Name = "select_nom_user_SHARK2"
		cmd.Parameters = Array As Object(usuario)
		reqManager.ExecuteQuery(cmd , 0, "nom_user")
		
		cmd.Initialize
		cmd.Name = "select_telefono_SHARK2"
		cmd.Parameters = Array As Object(usuario)
		reqManager.ExecuteQuery(cmd , 0, "telefono")
		
	
'	cmd.Initialize
'	cmd.Name = "select_HIST_MARCAS_CUOTAS_INTMEX"
'	cmd.Parameters = Array As Object( ALMACEN, e_ruta.text)
'	reqManager.ExecuteQuery(cmd , 0, "HIST_MARCAS_CUOTAS")
	
		If E_RUTA2.text <> "" Then
			
'			B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO RUTA_SUPLENCIA(RS_RUTA) VALUES(?)",Array As String(E_RUTA2.Text))
			
			E_RUTA2.Visible = False
			Panel11.Visible = False
			
			cmd.Initialize
			cmd.Name = "select_cat_clientes_SHARK2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "kmt_datos")
			
			cmd.Initialize
			cmd.Name = "select_cat_clientes_todos_SHARK2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "kmt_datos_todos")
	
			cmd.Initialize
			cmd.Name = "select_hist_datos_SHARK2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_datos")
	
			cmd.Initialize
			cmd.Name = "select_hist_promos_SHARK2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_promos")
	
			cmd.Initialize
			cmd.Name = "select_hist_cliente_promos_SHARK2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
		End If

		cmd.Initialize
		cmd.Name = "select_promo_comp_SHARK2"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_comp_promos")
	
'	cmd.Initialize
'	cmd.Name = "select_verificacion_INTMEX"
'	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
'	reqManager.ExecuteQuery(cmd , 0, "cat_verificacion")
	
		cmd.Initialize
		cmd.Name = "select_fecha"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "fecha")
	
'		cmd.Initialize
'		cmd.Name = "select_folio_SHARK2"
'		cmd.Parameters = Array As Object(ALMACEN, e_ruta.text)
'		reqManager.ExecuteQuery(cmd , 0, "folio")
	
'		cmd.Initialize
'		cmd.Name = "select_abonosp_SHARK2"
'		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
'		reqManager.ExecuteQuery(cmd , 0, "select_abonosp")
	
		cmd.Initialize
		cmd.Name = "select_marcas_rutas_SHARK2"
		cmd.Parameters = Array As Object( ALMACEN, e_ruta.text)
		reqManager.ExecuteQuery(cmd , 0, "marcas_rutas")
	
'	cmd.Initialize
'	cmd.Name = "select_CUEST_INTMEX"
'	cmd.Parameters = Array As Object(ALMACEN)
'	reqManager.ExecuteQuery(cmd , 0, "CUESTIONARIO")
	
'	cmd.Initialize
'	cmd.Name = "select_HIST_CUOTAS_INTMEX"
'	cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
'	reqManager.ExecuteQuery(cmd , 0, "CUOTAS")

'		cmd.Initialize
'		cmd.Name = "select_comis_cedex_IZCA"
'		cmd.Parameters = Array As Object( ALMACEN, e_ruta.text )
'		reqManager.ExecuteQuery(cmd , 0, "COMISIONES")
	
'		cmd.Initialize
'		cmd.Name = "select_hist_avance_IZCA" 'select * from HIST_AVANCE_MESACTUAL where HIST_AM_RUTA = ? and HIST_AM_IDALMACEN order by HIST_AM_MARCA
'		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
'		LogColor($"HIST_AVANCE Ruta=|${e_ruta.text}|, almacen=|${ALMACEN}|"$, Colors.Red)
'		reqManager.ExecuteQuery(cmd , 0, "hist_avance")
	
		cargar.Visible = False
		Subir.Visible = False
		inv.Visible = False
		If Starter.marcaCel <> "Sony" Then ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias" , True)
	Else
		Log("XXXX")
		MsgboxAsync("Para poder cargar día no puedes tener venta del día anterior. Por favor haz FIN DIA e intenta nuevamente.","Atención")
	End If
End Sub

Sub JobDone(Job As HttpJob)
	Log("JOBDONE PRINCIPAL")
	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($">>>>>> Quitamos ${Job.tag}"$, Colors.Blue)
		End If
		LogColor(">>>>>> " & reqManager.reqsList.Size & " - " & reqManager.reqsList, Colors.Blue)
	End If
	If Job.Success = False Then
		Log("ERROR")
		LogColor("Error: " & reqManager.HandleJob(Job).tag & " : " & Job.ErrorMessage, Colors.red)
		Log("ex")
		Log(2)
'		Job.Release
	Else 'If Job Success then ...
		Log(3)
		Log(ALMACEN)
		LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.RGB(0,160,0))  'Mod por CHV - 211027
		'Verificamos que el usuario guardado en BD sea VALIDO.
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "update_gps" Then
				For Each records() As Object In RESULT.Rows
					Log("==========================REGISTROS="&RESULT.Rows)
					For Each k As String In RESULT.Columns.Keys
						Log(RESULT.Tag & ": " & k & ": " & records(RESULT.Columns.Get(k)))
					Next
				Next
			End If
			If RESULT.Tag = "ins_pedidos" Then
				For Each records() As Object In RESULT.Rows
					Log("==========================REGISTROS="&RESULT.Rows)
					For Each k As String In RESULT.Columns.Keys
						Log(RESULT.Tag & ": " & k & ": " & records(RESULT.Columns.Get(k)))
					Next
				Next
			End If
			If RESULT.Tag = "usuarioA" Then 'query tag
				Private n As String = "Sin Usuario"
				For Each records() As Object In RESULT.Rows
					n = records(RESULT.Columns.Get("USUARIO"))
				Next
				LogColor("**************************"&n, Colors.Green)
				If n = "OKActivo"  Then
					Log("Usuario guardado en BD es 'Valido'")
				Else If n  = "OKExpirado" Then
					Msgbox("Usuario Expirado llamar al administrador","") 'ignore
					B4XPages.ShowPage("B4XMainPage")
				Else If n = "OKCancelado" Then
					Msgbox("Usuario Cancelado llamar al administrador","") 'ignore
					B4XPages.ShowPage("B4XMainPage")
				Else
					Msgbox("Usuario o password No validos","") 'ignore
					B4XPages.ShowPage("B4XMainPage")
				End If
				Log("*****************  "&n)
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "giro" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim giro  As String = records(RESULT.Columns.Get("CAT_GR_DESC"))
					
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_GIRO(GIRO) VALUES (?)", Array As Object (giro))
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				Listo3 =1
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
	   
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "kmt_datos" Then 'query tag
				S_CC.TEXT = "CARGANDO"
				For Each records() As Object In RESULT.Rows
					Dim CAT_CL_CODIGO As String = records(RESULT.Columns.Get("CAT_CL_CODIGO"))
					Dim CAT_CL_RUTA As String = records(RESULT.Columns.Get("CAT_CL_RUTA"))
					Dim CAT_CL_NOMBRE As String = records(RESULT.Columns.Get("CAT_CL_NOMBRE"))
					Dim CAT_CL_ATIENDE1 As String = records(RESULT.Columns.Get("CAT_CL_ATIENDE1"))
					Dim CAT_CL_ATIENTE2 As String = records(RESULT.Columns.Get("CAT_CL_ATIENTE2"))
					Dim CAT_CL_TELEFONO As String = records(RESULT.Columns.Get("CAT_CL_TELEFONO"))
					Dim CAT_CL_EMAIL As String = records(RESULT.Columns.Get("CAT_CL_EMAIL"))
					Dim CAT_CL_CALLE As String = records(RESULT.Columns.Get("CAT_CL_CALLE"))
					Dim CAT_CL_NOEXT As String = records(RESULT.Columns.Get("CAT_CL_NOEXT"))
					Dim CAT_CL_NOINT As String = records(RESULT.Columns.Get("CAT_CL_NOINT"))
					Dim CAT_CL_CALLE1 As String = records(RESULT.Columns.Get("CAT_CL_CALLE1"))
					Dim CAT_CL_CALLE2 As String = records(RESULT.Columns.Get("CAT_CL_CALLE2"))
					Dim CAT_CL_COLONIA As String = records(RESULT.Columns.Get("CAT_CL_COLONIA"))
					Dim CAT_CL_MUNI As String = records(RESULT.Columns.Get("CAT_CL_MUNI"))
					Dim CAT_CL_EDO As String = records(RESULT.Columns.Get("CAT_CL_EDO"))
					Dim CAT_CL_CP As String = records(RESULT.Columns.Get("CAT_CL_CP"))
					Dim CAT_CL_LONG As String = records(RESULT.Columns.Get("CAT_CL_LONG"))
					Dim CAT_CL_LAT As String = records(RESULT.Columns.Get("CAT_CL_LAT"))
					Dim CAT_CL_MTOCOMPRA As String = records(RESULT.Columns.Get("CAT_CL_MTOCOMPRA"))
					Dim CAT_CL_NUM_SERIEFISICO As String = records(RESULT.Columns.Get("CAT_CL_NUM_SERIEFISICO"))
					Dim CAT_CL_BCREDITO As String = records(RESULT.Columns.Get("CAT_CL_BCREDITO"))
					Dim CAT_CL_LIMITECREDITO As String = records(RESULT.Columns.Get("CAT_CL_LIMITECREDITO"))
					Dim CAT_CL_GIRO As String = records(RESULT.Columns.Get("CAT_CL_GIRO"))
'					Dim CAT_CL_LISTA_PRECIO As String = records(RESULT.Columns.Get("CAT_CL_LISTA_PRECIO"))
					Dim CAT_CL_TIPOCLIENTE As String = records(RESULT.Columns.Get("CAT_CL_TIPOCLIENTE"))
'					Dim CAT_CL_BCOORDENADAS As String = records(RESULT.Columns.Get("CAT_CL_BCOORDENADAS"))
					Dim CAT_CL_BCOORDENADAS As String = 0
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO kmt_info(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, CAT_CL_BCREDITO, CAT_CL_LIMITECREDITO, gestion,CAT_CL_BCOORDENADAS, CAT_CL_GIRO,CAT_CL_TIPOCLIENTE) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ,?,0,?,?,?)", Array As Object (CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, CAT_CL_BCREDITO, CAT_CL_LIMITECREDITO,CAT_CL_BCOORDENADAS,CAT_CL_GIRO,CAT_CL_TIPOCLIENTE))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_STAY_STORE(HSS_CODIGO,  HSS_IN , HSS_OUT , HSS_TOT) VALUES (?,0,0,0)", Array As Object (CAT_CL_CODIGO))
				Next
				Starter.skmt.ExecNonQuery2("INSERT INTO kmt_info(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, gestion) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,0) ",Array As Object ("0",e_ruta.TEXT, "VENTA ABORDO","null","null","null","null","null","null","null","null","null","null","null","null","NULL","null","NULL"))
				Starter.skmt.ExecNonQuery2("INSERT INTO kmt_info(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, gestion) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,0) ",Array As Object ("1",e_ruta.TEXT, "VENTA RECARGA","null","null","null","null","null","null","null","null","null","null","null","null","NULL","null","NULL"))
				Listo1 = 1
				S_CC.Text = "LISTO"
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Catalogo Clientes Actualizados." , True)
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim resultado As DBResult = reqManager.HandleJob(Job)
			If resultado.Tag = "piezas" Then 'query tag
'				B4XPages.MainPage.picking.cl_picking.Clear
				Dim piezasexiste As Int
				
				For Each records() As Object In resultado.Rows
					
					piezasexiste = records(resultado.Columns.Get("COUNT(*)"))
					Log(piezasexiste)
					DateTime.DateFormat = "MM/dd/yyyy"
					DateTime.TimeFormat = "HH:mm:ss"
					sDate=DateTime.Date(DateTime.Now)
					sTime=DateTime.Time(DateTime.Now)
					
					If piezasexiste =  0 Then
						
						Dim PCNoArts As String
						Dim PCMonto As String
						c = B4XPages.MainPage.skmt.ExecQuery2("SELECT * FROM PEDIDO_CLIENTE WHERE PC_CLIENTE = ? AND PC_CLIENTE <> 1", Array As String(userpiezas))
						
						If c.RowCount > 0 Then
							c.Position = 0
							PCNoArts = c.GetString("PC_NOART")
							PCMonto = c.GetString("PC_MONTO")
						End If
						
						Dim cmd As DBCommand
						cmd.Initialize
						cmd.Name = "insert_HVC_SHARK2"
						cmd.Parameters = Array As Object((sDate & " " & sTime), userpiezas, PCNoArts, PCMonto, ALMACEN, l_ruta.Text)
						reqManager.ExecuteCommand(cmd , "insert_hvc")
'						reqManager.ExecuteCommand(cmd , $"ins_abonosPendientes_${ab.GetString("a_cliente")}"$)
							
					End If
				Next
				

			End If
		End If
		
		
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "kmt_datos_todos" Then 'query tag
				S_CC.TEXT = "CARGANDO"
				For Each records() As Object In RESULT.Rows
					Dim CAT_CL_CODIGO As String = records(RESULT.Columns.Get("CAT_CL_CODIGO"))
					Dim CAT_CL_RUTA As String = records(RESULT.Columns.Get("CAT_CL_RUTA"))
					Dim CAT_CL_NOMBRE As String = records(RESULT.Columns.Get("CAT_CL_NOMBRE"))
					Dim CAT_CL_ATIENDE1 As String = records(RESULT.Columns.Get("CAT_CL_ATIENDE1"))
					Dim CAT_CL_ATIENTE2 As String = records(RESULT.Columns.Get("CAT_CL_ATIENTE2"))
					Dim CAT_CL_TELEFONO As String = records(RESULT.Columns.Get("CAT_CL_TELEFONO"))
					Dim CAT_CL_EMAIL As String = records(RESULT.Columns.Get("CAT_CL_EMAIL"))
					Dim CAT_CL_CALLE As String = records(RESULT.Columns.Get("CAT_CL_CALLE"))
					Dim CAT_CL_NOEXT As String = records(RESULT.Columns.Get("CAT_CL_NOEXT"))
					Dim CAT_CL_NOINT As String = records(RESULT.Columns.Get("CAT_CL_NOINT"))
					Dim CAT_CL_CALLE1 As String = records(RESULT.Columns.Get("CAT_CL_CALLE1"))
					Dim CAT_CL_CALLE2 As String = records(RESULT.Columns.Get("CAT_CL_CALLE2"))
					Dim CAT_CL_COLONIA As String = records(RESULT.Columns.Get("CAT_CL_COLONIA"))
					Dim CAT_CL_MUNI As String = records(RESULT.Columns.Get("CAT_CL_MUNI"))
					Dim CAT_CL_EDO As String = records(RESULT.Columns.Get("CAT_CL_EDO"))
					Dim CAT_CL_CP As String = records(RESULT.Columns.Get("CAT_CL_CP"))
					Dim CAT_CL_LONG As String = records(RESULT.Columns.Get("CAT_CL_LONG"))
					Dim CAT_CL_LAT As String = records(RESULT.Columns.Get("CAT_CL_LAT"))
					Dim CAT_CL_MTOCOMPRA As String = records(RESULT.Columns.Get("CAT_CL_MTOCOMPRA"))
					Dim CAT_CL_NUM_SERIEFISICO As String = records(RESULT.Columns.Get("CAT_CL_NUM_SERIEFISICO"))
					Dim CAT_CL_BCREDITO As String = records(RESULT.Columns.Get("CAT_CL_BCREDITO"))
					Dim CAT_CL_LIMITECREDITO As String = records(RESULT.Columns.Get("CAT_CL_LIMITECREDITO"))
					Dim CAT_CL_DIAS_VISITA As String = records(RESULT.Columns.Get("CAT_CL_DIAS_VISITA"))
					Dim CAT_CL_GIRO As String = records(RESULT.Columns.Get("CAT_CL_GIRO"))
					Dim CAT_CL_GIRO As String = records(RESULT.Columns.Get("CAT_CL_GIRO"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO kmt_info2(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, gestion, CAT_CL_DIAS_VISITA, CAT_CL_BCREDITO, CAT_CL_LIMITECREDITO,CAT_CL_GIRO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0, ?,?,?,?)", Array As Object (CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO,CAT_CL_DIAS_VISITA, CAT_CL_BCREDITO, CAT_CL_LIMITECREDITO,CAT_CL_GIRO))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_STAY_STORE(HSS_CODIGO,  HSS_IN , HSS_OUT , HSS_TOT) VALUES (?,0,0,0)", Array As Object (CAT_CL_CODIGO))
				Next
				Listo1 = 1
				S_CC.Text = "LISTO"
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Catalogo Clientes Actualizados." , True)
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "resum_apk" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HIST_RA_OBJMES As String = records(RESULT.Columns.Get("HIST_RA_OBJMES"))
					Dim HIST_RA_VENTA As String = records(RESULT.Columns.Get("HIST_RA_VENTA"))
					Dim HIST_RA_TENDENCIA As String = records(RESULT.Columns.Get("HIST_RA_TENDENCIA"))
					Dim HIST_RA_ALCANCE As String = records(RESULT.Columns.Get("HIST_RA_ALCANCE"))
					Dim HISR_RA_DRAOBJ As String = records(RESULT.Columns.Get("HISR_RA_DRAOBJ"))
					Dim HIST_RA_DRAVTA As String = records(RESULT.Columns.Get("HIST_RA_DRAVTA"))
					Dim HIST_RA_DSOBJ As String = records(RESULT.Columns.Get("HIST_RA_DSOBJ"))
					Dim HIST_RA_DSVTA As String = records(RESULT.Columns.Get("HIST_RA_DSVTA"))
					Dim HIST_RA_VPOOBJ As String = records(RESULT.Columns.Get("HIST_RA_VPOOBJ"))
					Dim HIST_RA_VPOVTA As String = records(RESULT.Columns.Get("HIST_RA_VPOVTA"))
					Dim HIST_RA_CTES As String = records(RESULT.Columns.Get("HIST_RA_CTES"))
					Dim HIST_RA_COBCCC As String = records(RESULT.Columns.Get("HIST_RA_COBCCC"))
					Dim HIST_RA_ECO As String = records(RESULT.Columns.Get("HIST_RA_ECO"))
					Dim HIST_RA_VISITPLAN As String = records(RESULT.Columns.Get("HIST_RA_VISITPLAN"))
					Dim HIST_RA_VISIREAL As String = records(RESULT.Columns.Get("HIST_RA_VISIREAL"))
					Dim HIST_RA_COBVISIT As String = records(RESULT.Columns.Get("HIST_RA_COBVISIT"))
					Dim HIST_RA_FRECCOMPOBJ As String = records(RESULT.Columns.Get("HIST_RA_FRECCOMPOBJ"))
					Dim HIST_RA_FRECCOMREAL As String = records(RESULT.Columns.Get("HIST_RA_FRECCOMREAL"))
					Dim HIST_RA_VENTAMES1 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES1"))
					Dim HIST_RA_VENTAMES2 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES2"))
					Dim HIST_RA_VENTAMES3 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES3"))
					Dim HIST_RA_VENTAMES4 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES4"))
					Dim HIST_RA_RECHAZO As String = records(RESULT.Columns.Get("HIST_RA_RECHAZO"))
					Dim HIST_RA_RECHAZOPORCEN As String = records(RESULT.Columns.Get("HIST_RA_RECHAZOPORCEN"))
					Dim HIST_RA_SEMANA1 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1"))
					Dim HIST_RA_SEMANA1_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_DIAS"))
					Dim HIST_RA_SEMANA1_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_DRA"))
					Dim HIST_RA_SEMANA2 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2"))
					Dim HIST_RA_SEMANA2_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_DIAS"))
					Dim HIST_RA_SEMANA2_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_DRA"))
					Dim HIST_RA_SEMANA3 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3"))
					Dim HIST_RA_SEMANA3_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_DIAS"))
					Dim HIST_RA_SEMANA3_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_DRA"))
					Dim HIST_RA_SEMANA4 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4"))
					Dim HIST_RA_SEMANA4_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_DIAS"))
					Dim HIST_RA_SEMANA4_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_DRA"))
					Dim HIST_RA_SEMANA5 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5"))
					Dim HIST_RA_SEMANA5_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_DIAS"))
					Dim HIST_RA_SEMANA5_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_DRA"))
					Dim HIST_RA_SEMANA1_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_LPT"))
					Dim HIST_RA_SEMANA2_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_LPT"))
					Dim HIST_RA_SEMANA3_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_LPT"))
					Dim HIST_RA_SEMANA4_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_LPT"))
					Dim HIST_RA_SEMANA5_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_LPT"))
					Dim HIST_RA_RUTA As String = records(RESULT.Columns.Get("HIST_RA_RUTA"))
					Dim HIST_RA_IDALMACEN As String = records(RESULT.Columns.Get("HIST_RA_IDALMACEN"))

					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_RESUM_APK(HIST_RA_OBJMES,HIST_RA_VENTA,HIST_RA_TENDENCIA,HIST_RA_ALCANCE,HISR_RA_DRAOBJ,HIST_RA_DRAVTA,HIST_RA_DSOBJ,HIST_RA_DSVTA,HIST_RA_VPOOBJ,HIST_RA_VPOVTA,HIST_RA_CTES,HIST_RA_COBCCC,HIST_RA_ECO,HIST_RA_VISITPLAN,HIST_RA_VISIREAL,HIST_RA_COBVISIT,HIST_RA_FRECCOMPOBJ,HIST_RA_FRECCOMREAL,HIST_RA_VENTAMES1,HIST_RA_VENTAMES2,HIST_RA_VENTAMES3,HIST_RA_VENTAMES4,HIST_RA_RECHAZO,HIST_RA_RECHAZOPORCEN,HIST_RA_SEMANA1,HIST_RA_SEMANA1_DIAS,HIST_RA_SEMANA1_DRA,HIST_RA_SEMANA2,HIST_RA_SEMANA2_DIAS,HIST_RA_SEMANA2_DRA,HIST_RA_SEMANA3,HIST_RA_SEMANA3_DIAS,HIST_RA_SEMANA3_DRA,HIST_RA_SEMANA4,HIST_RA_SEMANA4_DIAS,HIST_RA_SEMANA4_DRA,HIST_RA_SEMANA5,HIST_RA_SEMANA5_DIAS,HIST_RA_SEMANA5_DRA,HIST_RA_SEMANA1_LPT,HIST_RA_SEMANA2_LPT,HIST_RA_SEMANA3_LPT,HIST_RA_SEMANA4_LPT,HIST_RA_SEMANA5_LPT,HIST_RA_RUTA,HIST_RA_IDALMACEN) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (HIST_RA_OBJMES,HIST_RA_VENTA,HIST_RA_TENDENCIA,HIST_RA_ALCANCE,HISR_RA_DRAOBJ,HIST_RA_DRAVTA,HIST_RA_DSOBJ,HIST_RA_DSVTA,HIST_RA_VPOOBJ,HIST_RA_VPOVTA,HIST_RA_CTES,HIST_RA_COBCCC,HIST_RA_ECO,HIST_RA_VISITPLAN,HIST_RA_VISIREAL,HIST_RA_COBVISIT,HIST_RA_FRECCOMPOBJ,HIST_RA_FRECCOMREAL,HIST_RA_VENTAMES1,HIST_RA_VENTAMES2,HIST_RA_VENTAMES3,HIST_RA_VENTAMES4,HIST_RA_RECHAZO,HIST_RA_RECHAZOPORCEN,HIST_RA_SEMANA1,HIST_RA_SEMANA1_DIAS,HIST_RA_SEMANA1_DRA,HIST_RA_SEMANA2,HIST_RA_SEMANA2_DIAS,HIST_RA_SEMANA2_DRA,HIST_RA_SEMANA3,HIST_RA_SEMANA3_DIAS,HIST_RA_SEMANA3_DRA,HIST_RA_SEMANA4,HIST_RA_SEMANA4_DIAS,HIST_RA_SEMANA4_DRA,HIST_RA_SEMANA5,HIST_RA_SEMANA5_DIAS,HIST_RA_SEMANA5_DRA,HIST_RA_SEMANA1_LPT,HIST_RA_SEMANA2_LPT,HIST_RA_SEMANA3_LPT,HIST_RA_SEMANA4_LPT,HIST_RA_SEMANA5_LPT,HIST_RA_RUTA,HIST_RA_IDALMACEN))
					'				Msgbox("pasa","alo")
				Next
				Listo1 = 1
				S_CC.Text = "LISTO"
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Catalogo Resumen Actualizado." , True)
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_promos" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HP_CLIENTE As String = records(RESULT.Columns.Get("HP_CLIENTE"))
					Dim HP_CODIGO_PROMOCION As String = records(RESULT.Columns.Get("HP_CODIGO_PROMOCION"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_PROMOS(HP_CLIENTE, HP_CODIGO_PROMOCION) VALUES (?,?)", Array As Object (HP_CLIENTE, HP_CODIGO_PROMOCION))
				Next
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Historico Promociones Actualizado." , True)
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 60
				ELSE IF PB1.Progress = 60 Then
					PB1.Progress = 100
					S_CH.Text = "LISTO"
				End If
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_cliente_promos" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HCCP_CLIENTE As String = records(RESULT.Columns.Get("HCCP_CLIENTE"))
					Dim HCCP_PROMO As String = records(RESULT.Columns.Get("HCCP_PROMO"))
					Dim HCCP_CANT As String = records(RESULT.Columns.Get("HCCP_CANT"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_CLIENTE_CANT_PROMOS(HCCP_CLIENTE, HCCP_PROMO, HCCP_CANT) VALUES (?,?,?)", Array As Object (HCCP_CLIENTE, HCCP_PROMO,HCCP_CANT))
				Next
				If Starter.marcaCel <> "Sony" Then ToastMessageShow(" Historico Clientes Promociones Actualizado." , True)
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "GEOCERCA" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_AL_GEOCERCA As String = records(RESULT.Columns.Get("CAT_AL_GEOCERCA"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO GEOCERCA(ACTIVA) VALUES (?)", Array As Object (CAT_AL_GEOCERCA))
				Next
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "coords_almacen" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_AL_LATITUD As String = records(RESULT.Columns.Get("CAT_AL_LATITUD"))
					Dim CAT_AL_LONGITUD As String = records(RESULT.Columns.Get("CAT_AL_LONGITUD"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO COORDS_ALMACEN(LAT,LONG) VALUES (?,?)", Array As Object (CAT_AL_LATITUD,CAT_AL_LONGITUD))
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "HIST_MARCAS_CUOTAS" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HMC_MARCA As String = records(RESULT.Columns.Get("HMC_MARCA"))
					Dim HMC_TOTAL As String = records(RESULT.Columns.Get("HMC_TOTAL"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_MARCAS_CUOTAS(HMC_MARCA, HMC_TOTAL) VALUES (?,?)", Array As Object (HMC_MARCA, HMC_TOTAL))
				Next
				If Starter.marcaCel <> "Sony" Then ToastMessageShow(" Historico Marcas" , True)
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_comp_promos" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_PA_ID As String = records(RESULT.Columns.Get("CAT_PA_ID"))
					Dim CAT_PA_MAXPROM As String = records(RESULT.Columns.Get("CAT_PA_MAXPROM"))
					Dim CAT_PA_MAXPROMREC As String = records(RESULT.Columns.Get("CAT_PA_MAXPROMREC"))
					Dim CAT_PA_MAXPROMCLIE As String = records(RESULT.Columns.Get("CAT_PA_MAXPROMCLIE"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO PROMOS_COMP(CAT_PA_ID, CAT_PA_MAXPROM, CAT_PA_MAXPROMREC, CAT_PA_MAXPROMCLIE) VALUES (?,?,?,?)", Array As Object (CAT_PA_ID, CAT_PA_MAXPROM,CAT_PA_MAXPROMREC,CAT_PA_MAXPROMCLIE))
				Next
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 60
				ELSE IF PB1.Progress = 60 Then
					PB1.Progress = 100
					S_CH.Text = "LISTO"
				End If
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "cat_verificacion" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_VE_IDPROD As String = records(RESULT.Columns.Get("CAT_VE_IDPROD"))
					Dim CAT_VE_NOMBRE As String = records(RESULT.Columns.Get("CAT_VE_NOMBRE"))
					Dim CAT_VE_ORDEN As String = records(RESULT.Columns.Get("CAT_VE_ORDEN"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VERIFICACION(CAT_VE_IDPROD, CAT_VE_NOMBRE,CAT_VE_ORDEN) VALUES (?,?,?)", Array As Object (CAT_VE_IDPROD, CAT_VE_NOMBRE,CAT_VE_ORDEN))
				Next
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "marcas_rutas" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HVD_MARCA As String = records(RESULT.Columns.Get("HVD_MARCA"))
					Dim CLIENTES As String = records(RESULT.Columns.Get("CLIENTES"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO MARCAS_RUTAS(HVD_MARCA, CLIENTES) VALUES (?,?)", Array As Object (HVD_MARCA, CLIENTES))
				Next
			End If
		End If

		'CUOTAS
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "CUOTAS" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HC_RUTA As String = records(RESULT.Columns.Get("HC_RUTA"))
					Dim HC_CUOTA1 As String = records(RESULT.Columns.Get("HC_CUOTA1"))
					Dim HC_CUOTA2 As String = records(RESULT.Columns.Get("HC_CUOTA2"))
					Dim HC_CUOTA3 As String = records(RESULT.Columns.Get("HC_CUOTA3"))
					Dim HC_CUOTA4 As String = records(RESULT.Columns.Get("HC_CUOTA4"))
					Dim HC_CUOTA5 As String = records(RESULT.Columns.Get("HC_CUOTA5"))
					Dim HC_CUOTA6 As String = records(RESULT.Columns.Get("HC_CUOTA6"))
					Dim HC_META1 As String = records(RESULT.Columns.Get("HC_META1"))
					Dim HC_META2 As String = records(RESULT.Columns.Get("HC_META2"))
					Dim HC_META3 As String = records(RESULT.Columns.Get("HC_META3"))
					Dim HC_META4 As String = records(RESULT.Columns.Get("HC_META4"))
					Dim HC_META5 As String = records(RESULT.Columns.Get("HC_META5"))
					Dim HC_META6 As String = records(RESULT.Columns.Get("HC_META6"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_CUOTAS(HC_RUTA, HC_CUOTA1,HC_CUOTA2,HC_CUOTA3,HC_CUOTA4,HC_CUOTA5,HC_CUOTA6,HC_META1,HC_META2,HC_META3,HC_META4,HC_META5,HC_META6) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (HC_RUTA, HC_CUOTA1,HC_CUOTA2,HC_CUOTA3,HC_CUOTA4,HC_CUOTA5,HC_CUOTA6,HC_META1,HC_META2,HC_META3,HC_META4,HC_META5,HC_META6))
				Next
        
			End If
		End If
		'COMISIONES
		
'		If Job.JobName = "DBRequest" Then
'			Dim RESULT As DBResult = reqManager.HandleJob(Job)
'			If RESULT.Tag = "COMISIONES" Then 'query tag
'				For Each records() As Object In RESULT.Rows
'					Dim HCM_TOTAL_V As String = records(RESULT.Columns.Get("HCM_TOTAL_V"))
'					Dim HCM_TOTAL_VIVE As String = records(RESULT.Columns.Get("HCM_TOTAL_VIVE"))
'					Dim HCM_TOTAL_GUNA As String = records(RESULT.Columns.Get("HCM_TOTAL_GUNA"))
'					Dim HCM_TOTAL_BEB As String = records(RESULT.Columns.Get("HCM_TOTAL_BEB"))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_COMISIONES_MOVIL (HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB) VALUES (?,?,?,?)", Array As Object (HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB))
'				Next
'			End If
'		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod" Then 'query tag
				If PB2.Progress < 30 Then S_CP.Text = "CARGANDO" 'Mod por CHV - 20211028 Agregue el "If PB2.Progress < 30 then"
				For Each records() As Object In RESULT.Rows
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_DP_ID"))
					Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_DP_NOMBRE"))
					Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_DP_IMP1"))
					Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_DP_IMP2"))
					Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_DP_CLASIF"))
					Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_DP_STS"))
					Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_DP_TIPO"))
					Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_DP_SUBTIPO"))
					Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_DP_IMG"))
					Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_DP_ALMACEN"))
					Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_DP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_DP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_DP_INICIATIVA"))
'					Dim CAT_GP_TIPOPROD2 As String = records(RESULT.Columns.Get("CAT_DP_TIPOPROD2"))
					Dim CAT_GP_TIPOPROD2 As String = 0

					' --- Bloque de Precios ---
					Dim CAT_GP_PRECIO1 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO1"))
					Dim CAT_GP_PRECIO2 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO2"))
					Dim CAT_GP_PRECIO3 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO3"))
					Dim CAT_GP_PRECIO4 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO4"))
					Dim CAT_GP_PRECIO5 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO5"))
					Dim CAT_GP_PRECIO6 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO6"))
					Dim CAT_GP_PRECIO7 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO7"))
					Dim CAT_GP_PRECIO8 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO8"))
					Dim CAT_GP_PRECIO9 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO9"))
					Dim CAT_GP_PRECIO10 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO10"))
					Dim CAT_GP_PRECIO11 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO11"))

					' --- Bloque de Presentaciones ---
					Dim CAT_GP_PRESENTACION1 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION1"))
					Dim CAT_GP_PRESENTACION2 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION2"))
					Dim CAT_GP_PRESENTACION3 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION3"))
					Dim CAT_GP_PRESENTACION4 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION4"))
					Dim CAT_GP_PRESENTACION5 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION5"))
					Dim CAT_GP_PRESENTACION6 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION6"))
					Dim CAT_GP_PRESENTACION7 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION7"))
					Dim CAT_GP_PRESENTACION8 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION8"))
					Dim CAT_GP_PRESENTACION9 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION9"))
					Dim CAT_GP_PRESENTACION10 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION10"))
					Dim CAT_GP_PRESENTACION11 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION11"))

					' --- Bloque de UMV ---
					Dim CAT_GP_UMV1 As String = records(RESULT.Columns.Get("CAT_DP_UMV1"))
					Dim CAT_GP_UMV2 As String = records(RESULT.Columns.Get("CAT_DP_UMV2"))
					Dim CAT_GP_UMV3 As String = records(RESULT.Columns.Get("CAT_DP_UMV3"))
					Dim CAT_GP_UMV4 As String = records(RESULT.Columns.Get("CAT_DP_UMV4"))
					Dim CAT_GP_UMV5 As String = records(RESULT.Columns.Get("CAT_DP_UMV5"))
					Dim CAT_GP_UMV6 As String = records(RESULT.Columns.Get("CAT_DP_UMV6"))
					Dim CAT_GP_UMV7 As String = records(RESULT.Columns.Get("CAT_DP_UMV7"))
					Dim CAT_GP_UMV8 As String = records(RESULT.Columns.Get("CAT_DP_UMV8"))
					Dim CAT_GP_UMV9 As String = records(RESULT.Columns.Get("CAT_DP_UMV9"))
					Dim CAT_GP_UMV10 As String = records(RESULT.Columns.Get("CAT_DP_UMV10"))
					Dim CAT_GP_UMV11 As String = records(RESULT.Columns.Get("CAT_DP_UMV11"))

					' --- Bloque de Dirigida ---
					Dim CAT_GP_DIRIGIDA1 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA1"))
					Dim CAT_GP_DIRIGIDA2 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA2"))
					Dim CAT_GP_DIRIGIDA3 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA3"))
					Dim CAT_GP_DIRIGIDA4 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA4"))
					Dim CAT_GP_DIRIGIDA5 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA5"))
					Dim CAT_GP_DIRIGIDA6 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA6"))
					Dim CAT_GP_DIRIGIDA7 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA7"))
					Dim CAT_GP_DIRIGIDA8 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA8"))
					Dim CAT_GP_DIRIGIDA9 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA9"))
					Dim CAT_GP_DIRIGIDA10 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA10"))
					Dim CAT_GP_DIRIGIDA11 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA11"))
'					CAT_GP_INICIATIVA = 5
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_DEV))
					Dim CAT_GP_NOMBRE As String = CAT_GP_NOMBRE.Trim
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_IMP1, CAT_GP_IMP2, CAT_GP_CLASIF, CAT_GP_STS, CAT_GP_TIPO, CAT_GP_SUBTIPO, CAT_GP_IMG, CAT_GP_ALMACEN, CAT_GP_DEV, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA, CAT_GP_TIPOPROD2, CAT_GP_PRECIO1, CAT_GP_PRECIO2, CAT_GP_PRECIO3, CAT_GP_PRECIO4, CAT_GP_PRECIO5, CAT_GP_PRECIO6, CAT_GP_PRECIO7, CAT_GP_PRECIO8, CAT_GP_PRECIO9, CAT_GP_PRECIO10, CAT_GP_PRECIO11, CAT_GP_PRESENTACION1, CAT_GP_PRESENTACION2, CAT_GP_PRESENTACION3, CAT_GP_PRESENTACION4, CAT_GP_PRESENTACION5, CAT_GP_PRESENTACION6, CAT_GP_PRESENTACION7, CAT_GP_PRESENTACION8, CAT_GP_PRESENTACION9, CAT_GP_PRESENTACION10, CAT_GP_PRESENTACION11, CAT_GP_UMV1, CAT_GP_UMV2, CAT_GP_UMV3, CAT_GP_UMV4, CAT_GP_UMV5, CAT_GP_UMV6, CAT_GP_UMV7, CAT_GP_UMV8, CAT_GP_UMV9, CAT_GP_UMV10, CAT_GP_UMV11, CAT_GP_DIRIGIDA1, CAT_GP_DIRIGIDA2, CAT_GP_DIRIGIDA3, CAT_GP_DIRIGIDA4, CAT_GP_DIRIGIDA5, CAT_GP_DIRIGIDA6, CAT_GP_DIRIGIDA7, CAT_GP_DIRIGIDA8, CAT_GP_DIRIGIDA9, CAT_GP_DIRIGIDA10, CAT_GP_DIRIGIDA11) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Array As Object (CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_IMP1, CAT_GP_IMP2, CAT_GP_CLASIF, CAT_GP_STS, CAT_GP_TIPO, CAT_GP_SUBTIPO, CAT_GP_IMG, CAT_GP_ALMACEN, CAT_GP_DEV, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA, CAT_GP_TIPOPROD2, CAT_GP_PRECIO1, CAT_GP_PRECIO2, CAT_GP_PRECIO3, CAT_GP_PRECIO4, CAT_GP_PRECIO5, CAT_GP_PRECIO6, CAT_GP_PRECIO7, CAT_GP_PRECIO8, CAT_GP_PRECIO9, CAT_GP_PRECIO10, CAT_GP_PRECIO11, CAT_GP_PRESENTACION1, CAT_GP_PRESENTACION2, CAT_GP_PRESENTACION3, CAT_GP_PRESENTACION4, CAT_GP_PRESENTACION5, CAT_GP_PRESENTACION6, CAT_GP_PRESENTACION7, CAT_GP_PRESENTACION8, CAT_GP_PRESENTACION9, CAT_GP_PRESENTACION10, CAT_GP_PRESENTACION11, CAT_GP_UMV1, CAT_GP_UMV2, CAT_GP_UMV3, CAT_GP_UMV4, CAT_GP_UMV5, CAT_GP_UMV6, CAT_GP_UMV7, CAT_GP_UMV8, CAT_GP_UMV9, CAT_GP_UMV10, CAT_GP_UMV11, CAT_GP_DIRIGIDA1, CAT_GP_DIRIGIDA2, CAT_GP_DIRIGIDA3, CAT_GP_DIRIGIDA4, CAT_GP_DIRIGIDA5, CAT_GP_DIRIGIDA6, CAT_GP_DIRIGIDA7, CAT_GP_DIRIGIDA8, CAT_GP_DIRIGIDA9, CAT_GP_DIRIGIDA10, CAT_GP_DIRIGIDA11))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD,CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1,CAT_DP_PRECIO2,CAT_DP_PRECIO1) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD, CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1,CAT_DP_PRECIO2,CAT_DP_PRECIO1))
				Next
				Listo2=1
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Productos Actualizados." , True)
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod3" Then 'query tag
				If PB2.Progress < 30 Then S_CP.Text = "CARGANDO" 'Mod por CHV - 20211028 Agregue el "If PB2.Progress < 30 then"
				For Each records() As Object In RESULT.Rows
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_DP_ID"))
					Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_DP_NOMBRE"))
					Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_DP_IMP1"))
					Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_DP_IMP2"))
					Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_DP_PRECIO"))
					Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_DP_CLASIF"))
					Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_DP_STS"))
					Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_DP_TIPO"))
					Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_DP_SUBTIPO"))
					Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_DP_IMG"))
					Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_DP_ALMACEN"))
					'	Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_DP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_DP_INICIATIVA"))
					Dim CAT_DP_PRECIO4 As Float = records(RESULT.Columns.Get("CAT_DP_PRECIO4"))
					Dim CAT_DP_CONVERSION1 As Int = records(RESULT.Columns.Get("CAT_DP_CONVERSION1"))
'					CAT_GP_INICIATIVA = 5
'					skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_DEV) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_DEV))
					Dim CAT_GP_NOMBRE As String = CAT_GP_NOMBRE.Trim
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD3(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD,CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD, CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1))
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod2" Then 'query tag
				If PB2.Progress < 30 Then S_CP.Text = "CARGANDO" 'Mod por CHV - 20211028 Agregue el "If PB2.Progress < 30 then"
				For Each records() As Object In RESULT.Rows
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_DP_ID"))
					Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_DP_NOMBRE"))
					Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_DP_IMP1"))
					Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_DP_IMP2"))
					Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_DP_CLASIF"))
					Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_DP_STS"))
					Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_DP_TIPO"))
					Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_DP_SUBTIPO"))
					Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_DP_IMG"))
					Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_DP_ALMACEN"))
					Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_DP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_DP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_DP_INICIATIVA"))
					Dim CAT_GP_TIPOPROD2 As String = records(RESULT.Columns.Get("CAT_DP_TIPOPROD2"))

					' --- Bloque de Precios ---
					Dim CAT_GP_PRECIO1 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO1"))
					Dim CAT_GP_PRECIO2 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO2"))
					Dim CAT_GP_PRECIO3 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO3"))
					Dim CAT_GP_PRECIO4 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO4"))
					Dim CAT_GP_PRECIO5 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO5"))
					Dim CAT_GP_PRECIO6 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO6"))
					Dim CAT_GP_PRECIO7 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO7"))
					Dim CAT_GP_PRECIO8 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO8"))
					Dim CAT_GP_PRECIO9 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO9"))
					Dim CAT_GP_PRECIO10 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO10"))
					Dim CAT_GP_PRECIO11 As String = records(RESULT.Columns.Get("CAT_DP_PRECIO11"))

					' --- Bloque de Presentaciones ---
					Dim CAT_GP_PRESENTACION1 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION1"))
					Dim CAT_GP_PRESENTACION2 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION2"))
					Dim CAT_GP_PRESENTACION3 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION3"))
					Dim CAT_GP_PRESENTACION4 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION4"))
					Dim CAT_GP_PRESENTACION5 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION5"))
					Dim CAT_GP_PRESENTACION6 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION6"))
					Dim CAT_GP_PRESENTACION7 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION7"))
					Dim CAT_GP_PRESENTACION8 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION8"))
					Dim CAT_GP_PRESENTACION9 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION9"))
					Dim CAT_GP_PRESENTACION10 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION10"))
					Dim CAT_GP_PRESENTACION11 As String = records(RESULT.Columns.Get("CAT_DP_PRESENTACION11"))

					' --- Bloque de UMV ---
					Dim CAT_GP_UMV1 As String = records(RESULT.Columns.Get("CAT_DP_UMV1"))
					Dim CAT_GP_UMV2 As String = records(RESULT.Columns.Get("CAT_DP_UMV2"))
					Dim CAT_GP_UMV3 As String = records(RESULT.Columns.Get("CAT_DP_UMV3"))
					Dim CAT_GP_UMV4 As String = records(RESULT.Columns.Get("CAT_DP_UMV4"))
					Dim CAT_GP_UMV5 As String = records(RESULT.Columns.Get("CAT_DP_UMV5"))
					Dim CAT_GP_UMV6 As String = records(RESULT.Columns.Get("CAT_DP_UMV6"))
					Dim CAT_GP_UMV7 As String = records(RESULT.Columns.Get("CAT_DP_UMV7"))
					Dim CAT_GP_UMV8 As String = records(RESULT.Columns.Get("CAT_DP_UMV8"))
					Dim CAT_GP_UMV9 As String = records(RESULT.Columns.Get("CAT_DP_UMV9"))
					Dim CAT_GP_UMV10 As String = records(RESULT.Columns.Get("CAT_DP_UMV10"))
					Dim CAT_GP_UMV11 As String = records(RESULT.Columns.Get("CAT_DP_UMV11"))

					' --- Bloque de Dirigida ---
					Dim CAT_GP_DIRIGIDA1 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA1"))
					Dim CAT_GP_DIRIGIDA2 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA2"))
					Dim CAT_GP_DIRIGIDA3 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA3"))
					Dim CAT_GP_DIRIGIDA4 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA4"))
					Dim CAT_GP_DIRIGIDA5 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA5"))
					Dim CAT_GP_DIRIGIDA6 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA6"))
					Dim CAT_GP_DIRIGIDA7 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA7"))
					Dim CAT_GP_DIRIGIDA8 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA8"))
					Dim CAT_GP_DIRIGIDA9 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA9"))
					Dim CAT_GP_DIRIGIDA10 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA10"))
					Dim CAT_GP_DIRIGIDA11 As String = records(RESULT.Columns.Get("CAT_DP_DIRIGIDA11"))
'					CAT_GP_INICIATIVA = 5
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_DEV))
					Dim CAT_GP_NOMBRE As String = CAT_GP_NOMBRE.Trim
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_IMP1, CAT_GP_IMP2, CAT_GP_CLASIF, CAT_GP_STS, CAT_GP_TIPO, CAT_GP_SUBTIPO, CAT_GP_IMG, CAT_GP_ALMACEN, CAT_GP_DEV, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA, CAT_GP_TIPOPROD2, CAT_GP_PRECIO1, CAT_GP_PRECIO2, CAT_GP_PRECIO3, CAT_GP_PRECIO4, CAT_GP_PRECIO5, CAT_GP_PRECIO6, CAT_GP_PRECIO7, CAT_GP_PRECIO8, CAT_GP_PRECIO9, CAT_GP_PRECIO10, CAT_GP_PRECIO11, CAT_GP_PRESENTACION1, CAT_GP_PRESENTACION2, CAT_GP_PRESENTACION3, CAT_GP_PRESENTACION4, CAT_GP_PRESENTACION5, CAT_GP_PRESENTACION6, CAT_GP_PRESENTACION7, CAT_GP_PRESENTACION8, CAT_GP_PRESENTACION9, CAT_GP_PRESENTACION10, CAT_GP_PRESENTACION11, CAT_GP_UMV1, CAT_GP_UMV2, CAT_GP_UMV3, CAT_GP_UMV4, CAT_GP_UMV5, CAT_GP_UMV6, CAT_GP_UMV7, CAT_GP_UMV8, CAT_GP_UMV9, CAT_GP_UMV10, CAT_GP_UMV11, CAT_GP_DIRIGIDA1, CAT_GP_DIRIGIDA2, CAT_GP_DIRIGIDA3, CAT_GP_DIRIGIDA4, CAT_GP_DIRIGIDA5, CAT_GP_DIRIGIDA6, CAT_GP_DIRIGIDA7, CAT_GP_DIRIGIDA8, CAT_GP_DIRIGIDA9, CAT_GP_DIRIGIDA10, CAT_GP_DIRIGIDA11) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Array As Object (CAT_GP_ID, CAT_GP_NOMBRE, CAT_GP_IMP1, CAT_GP_IMP2, CAT_GP_CLASIF, CAT_GP_STS, CAT_GP_TIPO, CAT_GP_SUBTIPO, CAT_GP_IMG, CAT_GP_ALMACEN, CAT_GP_DEV, CAT_GP_TIPOPROD, CAT_GP_INICIATIVA, CAT_GP_TIPOPROD2, CAT_GP_PRECIO1, CAT_GP_PRECIO2, CAT_GP_PRECIO3, CAT_GP_PRECIO4, CAT_GP_PRECIO5, CAT_GP_PRECIO6, CAT_GP_PRECIO7, CAT_GP_PRECIO8, CAT_GP_PRECIO9, CAT_GP_PRECIO10, CAT_GP_PRECIO11, CAT_GP_PRESENTACION1, CAT_GP_PRESENTACION2, CAT_GP_PRESENTACION3, CAT_GP_PRESENTACION4, CAT_GP_PRESENTACION5, CAT_GP_PRESENTACION6, CAT_GP_PRESENTACION7, CAT_GP_PRESENTACION8, CAT_GP_PRESENTACION9, CAT_GP_PRESENTACION10, CAT_GP_PRESENTACION11, CAT_GP_UMV1, CAT_GP_UMV2, CAT_GP_UMV3, CAT_GP_UMV4, CAT_GP_UMV5, CAT_GP_UMV6, CAT_GP_UMV7, CAT_GP_UMV8, CAT_GP_UMV9, CAT_GP_UMV10, CAT_GP_UMV11, CAT_GP_DIRIGIDA1, CAT_GP_DIRIGIDA2, CAT_GP_DIRIGIDA3, CAT_GP_DIRIGIDA4, CAT_GP_DIRIGIDA5, CAT_GP_DIRIGIDA6, CAT_GP_DIRIGIDA7, CAT_GP_DIRIGIDA8, CAT_GP_DIRIGIDA9, CAT_GP_DIRIGIDA10, CAT_GP_DIRIGIDA11))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD,CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1,CAT_DP_PRECIO2,CAT_DP_PRECIO1) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD, CAT_GP_INICIATIVA,CAT_DP_PRECIO4,CAT_DP_CONVERSION1,CAT_DP_PRECIO2,CAT_DP_PRECIO1))
				Next
				Listo2=1
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Productos Actualizados." , True)
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprodp" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
					Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
					Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_GP_IMP1"))
					Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_GP_IMP2"))
					Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_GP_CLASIF"))
					Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_GP_STS"))
					Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_GP_TIPO"))
					Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_GP_SUBTIPO"))
					Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_GP_IMG"))
					Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_GP_ALMACEN"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
					CAT_GP_TIPOPROD = "5"
					If CAT_GP_ID = "PAQUNI003" Then
						CAT_GP_ALMACEN = 60
					End If
'					Log("XXXXXXX gunaprodp XXXXXXXXX  " & CAT_GP_ID & "|" & CAT_GP_IMP1 & "|" & CAT_GP_IMP2)
					Dim CAT_GP_NOMBRE As String = CAT_GP_NOMBRE.Trim
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO1,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO1,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Promociones  Actualizados." , True)
				Listo4=1
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprodps" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
					Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
					Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_GP_IMP1"))
					Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_GP_IMP2"))
					Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_GP_CLASIF"))
					Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_GP_STS"))
					Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_GP_TIPO"))
					Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_GP_SUBTIPO"))
					Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_GP_IMG"))
					Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_GP_ALMACEN"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
					Log("XXXXXXXX gunaprodps XXXXXXXX  " & records(RESULT.Columns.Get("CAT_GP_ID")) & "|" & records(RESULT.Columns.Get("CAT_GP_IMP1")))
					Dim CAT_GP_NOMBRE As String = CAT_GP_NOMBRE.Trim
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO1,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD4(CAT_GP_ID, CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
					Log("C4")
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
					Log("3")
				End If
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Promociones especiales  Actualizados." , True)

				Listo4=1
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "detallepaq" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_DP_ALMACEN  As String = records(RESULT.Columns.Get("CAT_DP_ALMACEN"))
					Dim CAT_DP_ID As String = records(RESULT.Columns.Get("CAT_DP_ID"))
					Dim CAT_DP_IDPROD As String = records(RESULT.Columns.Get("CAT_DP_IDPROD"))
					Dim CAT_DP_TIPO As String = records(RESULT.Columns.Get("CAT_DP_TIPO"))
					Dim CAT_DP_PZAS As String = records(RESULT.Columns.Get("CAT_DP_PZAS"))
					Dim CAT_DP_USUARIO  As String = records(RESULT.Columns.Get("CAT_DP_USUARIO"))
					Dim CAT_DP_FECHA As String = records(RESULT.Columns.Get("CAT_DP_FECHA"))
					Dim CAT_DP_REGALO  As String = records(RESULT.Columns.Get("CAT_DP_REGALO"))
					Dim CAT_DP_CLASIF  As String = records(RESULT.Columns.Get("CAT_DP_CLASIF"))
					Dim CAT_DP_PRECIO As String = records(RESULT.Columns.Get("CAT_DP_PRECIO"))
					Dim CAT_DP_PRECIO_SIMPTOS As String = records(RESULT.Columns.Get("CAT_DP_PRECIO_SIMPTOS"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_DETALLES_PAQ(CAT_DP_ALMACEN,CAT_DP_ID,CAT_DP_IDPROD,CAT_DP_TIPO,CAT_DP_PZAS,CAT_DP_USUARIO,CAT_DP_FECHA,CAT_DP_REGALO,CAT_DP_CLASIF,CAT_DP_PRECIO,CAT_DP_PRECIO_SIMPTOS) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_DP_ALMACEN,CAT_DP_ID,CAT_DP_IDPROD,CAT_DP_TIPO,CAT_DP_PZAS,CAT_DP_USUARIO,CAT_DP_FECHA,CAT_DP_REGALO,CAT_DP_CLASIF,CAT_DP_PRECIO,CAT_DP_PRECIO_SIMPTOS))
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				Listo3 =1
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
	   
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_datos" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HVD_CLIENTE As String = records(RESULT.Columns.Get("HVD_CLIENTE"))
					Dim HVD_PRONOMBRE As String = records(RESULT.Columns.Get("HVD_PRONOMBRE"))
					Dim HVD_CANT As String = records(RESULT.Columns.Get("HVD_CANT"))
					Dim HVD_COSTO_TOT As String = records(RESULT.Columns.Get("HVD_COSTO_TOT"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_VENTAS(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT) VALUES (?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT))
				Next
				Listo3 =1
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 60
				ELSE IF PB1.Progress = 60 Then
					PB1.Progress = 100
					S_CH.Text = "LISTO"
				End If
				If Starter.marcaCel <> "Sony" Then ToastMessageShow("Venta historico Actualizado." , True)
				If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
					B4XPage_Appear
					img2.Visible=False
					EJECUTANDO=0
				End If
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "variables" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim Cat_Va_Descripcion As String = records(RESULT.Columns.Get("CAT_VA_DESCRIPCION"))
					Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_VA_VALOR"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object (Cat_Va_Descripcion, Cat_Va_Valor))
				Next
			End If
		End If
    
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "CUESTIONARIO" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_VALOR"))
					B4XPages.MainPage.skmt.ExecNonQuery2("DELETE FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As Object ("CUESTIONARIO"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("CUESTIONARIO", Cat_Va_Valor))
				Next
			End If
		End If
    
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "valida_pedido" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CUANTOSP As Int = records(RESULT.Columns.Get("CUANTOSP"))
					If cuantos_pedido <= CUANTOSP Then
						' ToastMessageShow("rojo val ok 1 cuantosp." , True)
						datos_iguales = "ok"
						S_CP.Text = "INFO OK"
					Else
						If Starter.marcaCel <> "Sony" Then ToastMessageShow("No se cargo bien la info P. Sync Nuevamente" & CUANTOSP & " " & cuantos_pedido, True)
						S_CP.Text = "ENVIAR DATOS (K-2)"
					End If
				Next
			End If
		End If
    
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "valida_pedidoc" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CUANTOSC As Int = records(RESULT.Columns.Get("CUANTOSC"))
					If cuantos_pedidosc = CUANTOSC Then
						' ToastMessageShow("rojo val ok 1 cuantosp." , True)
						datos_iguales = "ok"
					Else
						If Starter.marcaCel <> "Sony" Then ToastMessageShow("No se cargo bien la info C. Sync Nuevamente"  & CUANTOSC & " " & cuantos_pedidosc, True)
					End If
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "valida_noventa" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CUANTOSN As Int = records(RESULT.Columns.Get("CUANTOSN"))
					If cuantos_noventa = CUANTOSN Then
						' ToastMessageShow("rojo val ok 1 cuantosp." , True)
						datos_iguales = "ok"
					Else
						If Starter.marcaCel <> "Sony" Then ToastMessageShow("No se cargo bien la info N. Sync Nuevamente"  & CUANTOSN & " " & cuantos_noventa, True)
					End If
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "ins_pedido" Then 'query tag
				For Each records() As Object In RESULT.Rows
					PB2.Progress = PB2.Progress + 5
					S_CP.Text = "SUBIENDO"
				Next
				PB2.Progress = 100
				S_CP.Text = "REVISANDO ..."
				Log("5")
			End If
		End If
	 
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "version" Then 'query tag
				For Each records() As Object In RESULT.Rows
					B4XPages.MainPage.skmt.ExecNonQuery("delete from VERSION")
					Dim CAT_VE_VERSION As String = records(RESULT.Columns.Get("CAT_VE_VERSION"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO VERSION(NOVERSION) VALUES (?)", Array As Object (CAT_VE_VERSION))
				Next
			End If
		End If
	 
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "count_cli" Then 'query tag
				For Each records() As Object In RESULT.Rows
					COUNT_CLIE = records(RESULT.Columns.Get("COUNT_CLIE"))
				Next
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "ruta" Then 'query tag
				Log("JOBDONE PRINCIPAL RUTA")
				Log(RESULT.Rows.Size)
				For Each records() As Object In RESULT.Rows
					Dim VALIDO As String = records(RESULT.Columns.Get("VALIDO"))
					Log("|"&VALIDO)
					If VALIDO = "OK" Then
						cargar.Visible = True
						Subir.Visible = True
						inv.Visible = True
						connecta.Visible = False
						If conn = "1" Then
							ToastMessageShow("Existe Conexión con el Servidor." , True)
						End If
					Else
						cargar.Visible = False
						Subir.Visible = False
						inv.Visible = False
						connecta.Visible = False
						ToastMessageShow("Ruta invalida." , True)
					End If
				Next
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "usuario" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim name2 As String = records(RESULT.Columns.Get("VALIDO"))
				Next
				If name2 = "OK" Then
					PASO = 1
				End If
				P1.Visible = False
				p_mandaInfo.Visible = False
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "fecha" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim FECHA_HOY As String = records(RESULT.Columns.Get("FECHA"))
					B4XPages.MainPage.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FECHA"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FECHA",FECHA_HOY))
				Next
			End If
		End If

'		If Job.JobName = "DBRequest" Then
'			Dim RESULT As DBResult = reqManager.HandleJob(Job)
'			If RESULT.Tag = "folio" Then 'query tag
'				For Each records() As Object In RESULT.Rows
'					Dim FOLIO As String = records(RESULT.Columns.Get("FOLIO"))
'					B4XPages.MainPage.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FOLIO"))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FOLIO",FOLIO))
'				Next
'			End If
'		End If
			
'		If Job.JobName = "DBRequest" Then
'			Dim RESULT As DBResult = reqManager.HandleJob(Job)
'			If RESULT.Tag = "hist_avance" Then 'query tag
'				For Each records() As Object In RESULT.Rows
'					Dim marca As String = records(RESULT.Columns.Get("HIST_AM_MARCA"))
'					Dim avance As String = records(RESULT.Columns.Get("HIST_AM_AVANCE"))
'					Dim objetivo As String = records(RESULT.Columns.Get("HIST_AM_OBJETIVO"))
'					Dim porcentaje1 As String = records(RESULT.Columns.Get("HIST_AM_PORCENTAJE"))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_AVANCE(HA_MARCA, HA_AVANCE, HA_OBJETIVO, HA_PORCENTAJE) VALUES (?,?,?,?)", Array As Object (marca, avance, objetivo, porcentaje1))
'				Next
'			End If
'		End If
		
'		If Job.JobName = "DBRequest" Then
'			Dim RESULT As DBResult = reqManager.HandleJob(Job)
'			If RESULT.Tag = "select_abonosp" Then 'query tag
'				For Each records() As Object In RESULT.Rows
'					Dim NOTA As String = records(RESULT.Columns.Get("NOTA"))
'					Dim CLIENTE As String = records(RESULT.Columns.Get("CLIENTE"))
'					Dim SALDO_PENDIENTE As String = records(RESULT.Columns.Get("SALDO_PENDIENTE"))
'					Dim DIA_VENCIMIENTO As String = records(RESULT.Columns.Get("DIA_VENCIMIENTO"))
'					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO ABONOSP(NOTA,CLIENTE,SALDO_PENDIENTE,DIA_VENCIMIENTO) VALUES (?,?,?,?)", Array As Object (NOTA, CLIENTE,SALDO_PENDIENTE,DIA_VENCIMIENTO))
'				Next
'			End If
'		End If
	End If
	
	If Job.JobName = "DBRequest" Then
		Dim RESULT As DBResult = reqManager.HandleJob(Job)
		If RESULT.Tag = "ins_cuestionario" Then 'query tag
			Subs.logJobDoneResultados(RESULT)
		End If

		Dim RESULT As DBResult = reqManager.HandleJob(Job)
		If RESULT.Tag = "test" Then 'query tag
			Log(">>>>>>>>>>>>>  TEST")
			Subs.logJobDoneResultados(RESULT)
		End If

		Dim RESULT As DBResult = reqManager.HandleJob(Job)
		If RESULT.Tag = "clientes_cuestionario" Then
			Log("Entramos a clientes_cuestionario - Regs:" & RESULT.Rows.Size)
			Starter.skmt.ExecNonQuery("delete from HIST_CUESTIONARIO")
			For Each records() As Object In RESULT.Rows
				Dim idCliente As String = records(RESULT.Columns.Get("HC_CLIENTE"))
				Starter.skmt.ExecNonQuery2("INSERT INTO HIST_CUESTIONARIO(HC_CLIENTE) VALUES (?)", Array As Object (idCliente))
			Next
		End If
	End If
	
	If Job.JobName = "DBRequest" Then
		Dim RESULT As DBResult = reqManager.HandleJob(Job)
		If RESULT.Tag = "telefono" Then 'query tag
			
			For Each records() As Object In RESULT.Rows
				Dim TELEFONO As String = ""
        
				If RESULT.Columns.Get("CAT_LO_IDTELEFONO") <> Null Then
					Dim index As Int = RESULT.Columns.Get("CAT_LO_IDTELEFONO")
					If records(index) <> Null Then
						TELEFONO = records(index)
					End If
				End If

				If TELEFONO <> "" Then
					B4XPages.MainPage.skmt.ExecNonQuery2("DELETE FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As Object("TELEFONO"))
					B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object("TELEFONO", TELEFONO))
				End If
			Next
		End If
	End If
	
	If resultado.Tag = "nom_user" Then
		For Each records() As Object In resultado.Rows
			Dim nombre_user As String = records(resultado.Columns.Get("CAT_LO_NOMBRE"))
			B4XPages.MainPage.skmt.ExecNonQuery2("DELETE FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As Object ("nom_usuario"))
			B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("nom_usuario", nombre_user))
		Next
	End If
	
	Job.Release
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
	'Return True to close, False to cancel
	If SCROLL_RESDIA.Visible Then
		SCROLL_RESDIA.Visible = False
		B_OK_RES_Click
		Return False
	Else if p_prod.Visible Then
		p_prod.Visible = False
		Return False
	Else if Panel5.Visible Then
		B_OK_PANEL5_Click
		Return False
	Else If pnlCobranza.Visible Then
		pnlCobranza.Visible = False
		Return False
	Else
		B4XPages.ShowPage("login")
	End If
	Return False
End Sub

Sub connecta_Click
	Log( Starter.DBReqServer)
	reqManager.Initialize(Me, Starter.DBReqServer)
	ime.HideKeyboard
	connecta1 = connecta1 + 1
'	imei = p.GetDeviceId
	imei = "xxxx"
	conn = "1"
'	Dim cmd As DBCommand
'	cmd.Initialize
'	cmd.Name = "select_version_INTMEX"
'	reqManager.ExecuteQuery(cmd , 0, "version")

	' Cuando nos conectamos verificamos que el usuario guardado en BD sea VALIDO.
'	c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO, PASS from usuarioa")
'	c.Position=0
'	If c.RowCount > 0  And c.GetString("USUARIO") <> "KMTS1" Then
'		Private usrT As String = c.GetString("USUARIO")
'		Private passT As String = c.GetString("PASS")
'		cmd.Initialize
'		cmd.Name = "select_usuario_guna_INTMEX_1"
'		Log(usrT & "|" & passT)
'		cmd.Parameters = Array As Object(usrT, passT)
'		reqManager.ExecuteQuery(cmd , 0, "usuarioA")
'	End If
'	c.Close

	Dim cmd As DBCommand
	cmd.Initialize

	cmd.Name = "select_ruta_SHARK23"
	cmd.Parameters = Array As Object(ALMACEN, e_ruta.text)
'	Log($"${ALMACEN},${e_ruta.text},${imei}"$)
	reqManager.ExecuteQuery(cmd , 0, "ruta")

	If e_ruta.Text = "KMTS1" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If

	If e_ruta.Text = "BERNA1" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If

	ToastMessageShow("Validando Conexión." , True)

'	If connecta1 / 2  = 1 Then
'		'Starter.DBReqServer = "http://177.244.63.54:1782"
'		'Starter.DBReqServer = "http://keymon.com.mx:1782"
'		'Starter.DBReqServer = "http://201.99.139.28:1782"
	''		Starter.DBReqServer = "http://187.189.244.154:1782"
	''		Starter.DBReqServer = "http://10.0.0.205:1782"
'	Else
'		'SERVER = "http://keymon.com.mx:1782"
'		'SERVER = "http://201.99.139.28:1782"
'		'SERVER = "http://177.244.63.54:1782"
	''		Starter.DBReqServer = "http://187.189.244.154:1782"
	''		SERVER = "http://10.0.0.205:1782"
'		reqManager.Initialize(Me, Starter.DBReqServer)
'	End If
End Sub

Sub BUSCA_Click
	B4XPages.ShowPage("TicketsDia")
End Sub

Sub b_mapa_Click
	Log("mapClic")
	B4XPages.GetPage("Mapas")
End Sub

Sub e_ruta_EnterPressed
	If e_ruta.Text = "FIN DIA" Then
		RES =  Msgbox2("Seguro que desea hacer el cierre todos los datos se borraran?","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))  'ignore
		If RES = DialogResponse.POSITIVE Then
			e_ruta.Text = ""
			Starter.skmt.ExecNonQuery("delete from CAT_GIRO")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from CLIENTE_NUEVO")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM GEOCERCA")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM ATIENDE")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM GIROS_ACTUAL")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM COORDS_ALMACEN")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from COORDENADAS")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from PICKCIEGO_HECHO")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from PAGARES")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from noventa")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from clie_act")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from kmt_info")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from kmt_info2")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod2")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod3")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod4")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_VENTAS")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_VERIFICACION")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_ENCUESTA")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_STAY_OUT")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_GPS")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_FACE")
			B4XPages.MainPage.skmt.ExecNonQuery("INSERT INTO HIST_STAY_OUT(HSO_INI, HSO_FIN) VALUES (0,0)")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_CODIGO_BARRAS")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM ABONOSP")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM ABONOS")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM PICK_CIEGO")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM RUTA_SUPLENCIA")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM RUTAA")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM CLIENTES_NUEVOS")
			Starter.skmt.ExecNonQuery("DELETE FROM TABULADOR_MONEDAS")
			Starter.skmt.ExecNonQuery("DELETE FROM TABULADOR_BILLETES")
			B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM ENV_MONTO_LIQ")
			B4XPage_Appear
			l_rutasuplencia.Visible = False
			Label22.Visible = False
			l_rutasuplencia.Text = ""
		End If
	End If
	If e_ruta.Text = "IWL" Then
		'	trabajar.Visible = False
		NUEVO.Visible =False
		BUSCA.Visible=False
		connecta.Visible=False
		img3.Visible =True
		Resumen.Visible= False
	End If
	If e_ruta.Text = "SUPLENCIA" Then
		E_RUTA2.Visible = True
		Panel11.Visible = True
'		ImageView9.Visible = True
		e_ruta.Text= ""
	End If
End Sub

Sub inv_Click
	img2.Visible =True
	EJECUTANDO = 1
	inve = 1
	B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod")
	B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod2")
	B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
	c=B4XPages.MainPage.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")
	
	cargar.Visible = False
	Subir.Visible = False
	connecta.Visible = True
	inv.Visible = False
	ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias" , True)
End Sub

Sub t1_tick
	cmd.Initialize
	cmd.Name = "select_cuantos_pedido_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedido")
	
	cmd.Initialize
	cmd.Name = "select_cuantos_noventa_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_noventa")
	
	cmd.Initialize
	cmd.Name = "select_cuantos_pedidoc_SHARK2"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedidoc")
	
	If PB2.Progress = 0 Then
		S_CP.Text = "ENVIAR DATOS (K-1)"
	End If
	img2.Visible=False
	t1.Enabled = False
End Sub

Sub B_OK_PAS_Click
	If CARGA = "SUBIR" And S_CP.Text = "INFO OK" Then
		P1.Visible = False
		p_mandaInfo.Visible = False
		Btn_Ubicar.Visible=True
		'trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		Subs.panelVisible(p_principal, 0, 0)
	Else If CARGA = "SUBIR" And S_CP.Text = "ERROR" Then
		Msgbox("Tiene que subir de nuevo la información","Atención") 'ignore
		P1.Visible = False
		p_mandaInfo.Visible = False
		'	trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		Subs.panelVisible(p_principal, 0, 0)
	Else if CARGA = "SUBIR" And S_CP.Text <> "INFO OK" Then
		RES =  Msgbox2("Seguro que desea abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If RES = DialogResponse.POSITIVE Then
			P1.Visible = False
'			trabajar.Visible = True
			NUEVO.Visible =True
			BUSCA.Visible=True
			connecta.Visible=True
			Resumen.Visible= True
			img2.Visible=False
			Subs.panelVisible(p_principal, 0, 0)
			ExitApplication
		End If
	End If
	If CARGA = "CARGAR" And S_CP.Text = "LISTO" And S_CC.Text = "LISTO" And S_CH.Text = "LISTO" Then
		P1.Visible = False
		p_mandaInfo.Visible = False
		p_mandaInfo.Visible = False
		Btn_Ubicar.Visible=True
		'trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		Subs.panelVisible(p_principal, 0, 0)
		
		Dim cn As Cursor = Starter.skmt.ExecQuery("SELECT * FROM CLIENTES_NUEVOS")
		If cn.RowCount > 0 Then
			For gh = 0 To cn.RowCount -1
				cn.Position = gh
				Starter.skmt.ExecNonQuery2("INSERT INTO kmt_info(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, gestion, CAT_CL_GIRO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,0,?) ", Array As Object (cn.GetString("CN_ID"),cn.GetString("CN_RUTA"), cn.GetString("CN_NOMBRE"),"null","null","null","null","null","null","null","null","null","null","null","null","null",cn.GetString("CN_LON"),cn.GetString("CN_LAT"), cn.GetString("CN_GIRO")))
			Next
		End If
		
		If E_RUTA2.Text <> "" Then
			B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO RUTA_SUPLENCIA(RS_RUTA) VALUES(?)",Array As String(E_RUTA2.Text))
		End If
		B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO RUTAA(RUTAA) VALUES(?)",Array As String(e_ruta.Text))
		checaPedido
		
		Dim c12  As Cursor = Starter.skmt.ExecQuery("Select  PE_PRONOMBRE, PE_PROID, PE_CANT FROM PEDIDO WHERE PE_FOLIO = 'PREVENTA'")
		If c12.RowCount > 0 Then
			For i = 0 To c12.RowCount - 1
				c12.Position = i
				Starter.skmt.ExecNonQuery($"UPDATE CAT_GUNAPROD SET CAT_GP_ALMACEN = CAT_GP_ALMACEN - ${c12.GetString("PE_CANT")}  WHERE CAT_GP_ID = '${c12.GetString("PE_PROID")}'"$)
			Next
		End If
		c12.Close
		
		Dim c13  As Cursor = Starter.skmt.ExecQuery("Select  PE_PRONOMBRE, PE_PROID, PE_CANT FROM PEDIDO WHERE PE_FOLIO = 'VENTA'")
		If c13.RowCount > 0 Then
			For i = 0 To c13.RowCount - 1
				c13.Position = i
				Starter.skmt.ExecNonQuery($"UPDATE CAT_GUNAPROD2 SET CAT_GP_ALMACEN = CAT_GP_ALMACEN - ${c13.GetString("PE_CANT")}  WHERE CAT_GP_ID = '${c13.GetString("PE_PROID")}'"$)
			Next
		End If
		c13.Close
		
		B4XPage_Appear
	Else if CARGA = "CARGAR" And (S_CP.Text <> "LISTO" Or S_CC.Text <> "LISTO" Or S_CH.Text <> "LISTO") Then
		RES =  Msgbox2("Seguro que desea abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
		If RES = DialogResponse.POSITIVE Then
			P1.Visible = False
			p_mandaInfo.Visible = False
'			trabajar.Visible = True
			NUEVO.Visible =True
			BUSCA.Visible=True
			connecta.Visible=True
			Resumen.Visible= True
			img2.Visible=False
			Subs.panelVisible(p_principal, 0, 0)
			B4XPages.MainPage.skmt.ExecNonQuery("delete from kmt_info")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cod_result")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from hist_gest")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod2")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod3")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from cat_gunaprod4")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from telefonos")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_VENTAS")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_PROMOS")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from PROMOS_COMP")
			B4XPages.MainPage.skmt.ExecNonQuery("delete from CAT_VERIFICACION")
			ExitApplication
		End If
	End If
End Sub

Sub NUEVO_Click
	
	' Verificar si el punto está dentro del polígono
	
	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)
'        
'		If dentro Then
'			ToastMessageShow("El punto está DENTRO del polígono", True)
			B4XPages.ShowPage("NuevoCliente")
'		Else
'			ToastMessageShow("El punto está FUERA del polígono", True)
'		End If
'	End If
	
End Sub

Sub B_OK_RES_Click
	'	trabajar.Visible = True
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
	Panel4.Visible = False
	SCROLL_RESDIA.Visible = False
	Btn_Ubicar.Visible=True
	p_principal.Visible = True
End Sub

Sub Resumen_Click
	P_RESUMEN.Visible = True

'	NUEVO.Visible =False
'	BUSCA.Visible=False
'	connecta.Visible=False
'	Subir.Visible=False
'	cargar.Visible=False
'	Resumen.Visible= False
End Sub

Sub P_RESUMEN_click
	
End Sub

Sub CARGA_Click
	B4XPages.ShowPage("Productos")
End Sub

Sub resdia_Click
	p_principal.Visible = False
	Btn_Ubicar.Visible=False
	SCROLL_RESDIA.Visible = True
	SCROLL_RESDIA.Panel.LoadLayout("RESDIA")
	SCROLL_RESDIA.Panel.Height = Panel4.Height
	Panel4.Visible = True

	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False

	d=B4XPages.MainPage.skmt.ExecQuery2("select COUNT(*) AS CUANTOS FROM HIST_ENCUESTA WHERE  HE_TIPO = ?", Array As String("TELEFONO"))
	d.Position = 0
	l_encuesta.Text = d.GetString("CUANTOS")
	d.Close

	L_MARCAS.CLEAR
	d=B4XPages.MainPage.skmt.ExecQuery2("select distinct HE_CLIE AS CLIENTE FROM HIST_ENCUESTA WHERE  HE_TIPO = ?", Array As String("TELEFONO"))
	If D.RowCount>0 Then
		For i=0 To D.RowCount -1
			D.Position=i
			c=B4XPages.MainPage.skmt.ExecQuery2("Select  HE_RES from HIST_ENCUESTA where  HE_CLIE = ?  AND HE_TIPO = ?", Array As String(d.GetString("CLIENTE"), "TELEFONO"))
			c.Position = 0
			Dim label1 As Label
			label1 = L_MARCAS.TwoLinesLayout.Label
			label1.TextSize = 13
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
			label2.TextSize = 13
			label2.TextColor = Colors.Black
			L_MARCAS.AddTwoLines(d.GetString("CLIENTE"),"TELEFONO :"  & c.GetString("HE_RES")  )
			c.Close
		Next
	End If
	d.Close

	c=B4XPages.MainPage.skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("RTEC"))
	c.Position = 0
	l_monto_k.Text = c.GetString("MONTO_DIA")
	If l_monto_k.Text = "null" Then
		l_monto_k.Text = "0"
	End If
	c.Close

	c=B4XPages.MainPage.skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("PING"))
	c.Position = 0
	l_monto_kp.Text = c.GetString("MONTO_DIA")
	If l_monto_kp.Text = "null" Then
		l_monto_kp.Text = "0"
	End If
	c.Close

'	c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("SALTY SNACKS"))
'	c.Position = 0
'	l_monto_ks.Text = c.GetString("MONTO_DIA")
'	If l_monto_ks.Text = "null" Then
'		l_monto_ks.Text = "0"
'	End If
	'
'	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 ")
	c.Position = 0
	l_monto_ks.Text = Subs.traeTotalCliente
	
	If l_monto_ks.Text = "null" Then
		l_monto_ks.Text = "0"
	End If
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As PREVENTA from pedido where PE_FOLIO = ? AND PE_CLIENTE <> 0", Array As String ("PREVENTA"))
	If c.RowCount > 0 Then
		c.Position = 0
		L_PREVENTA.Text = Subs.traeTotalClientepreventa
		If L_PREVENTA.TEXT = "null" Then
			L_PREVENTA.Text = "0"
		End If
	End If
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As VENTA from pedido where PE_FOLIO = ? AND PE_CLIENTE <> 0", Array As String ("VENTA"))
	If c.RowCount > 0 Then
		c.Position = 0
		L_VENTA.Text = Subs.traeTotalClienteventa
		If L_VENTA.TEXT = "null" Then
			L_VENTA.Text = "0"
		End If
	End If
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As ABORDO from pedido where PE_FOLIO = ? AND PE_CLIENTE = ?", Array As String ("ABORDO", "0"))
	If c.RowCount > 0 Then
		c.Position = 0
		L_ABORDO.Text = Subs.traeTotalClienteabordo
		If L_ABORDO.TEXT = "null" Then
			L_ABORDO.Text = "0"
		End If
	End If
	c.Close
	Dim cuantos_obj As String
	c=B4XPages.MainPage.skmt.ExecQuery("Select  count(*) AS TOTAL from HIST_MARCAS_CUOTAS   ")
	c.Position = 0
	cuantos_obj = c.GetString("TOTAL")
	c.Close

	If cuantos_obj > 0 Then
		c=B4XPages.MainPage.skmt.ExecQuery("Select  SUM( HMC_TOTAL) AS TOTAL from HIST_MARCAS_CUOTAS   ")
		c.Position = 0
		L_NES.Text = c.GetString("TOTAL")
		c.Close
	End If
	L_REAL.Text = l_monto_ks.Text
	L_ALCANCE.Text = Round2((L_NES.Text / L_REAL.Text + 1),2)
	L_VPLAN.Text = l_porvisitar.Text
	L_VREAL.Text = L_CUANTOST.text
	L_EFEC_VIS.Text = Round2(L_VREAL.text / L_VPLAN.Text,2)
	L_VISITCC.Text = l_cuantosc.text
	L_EFEC_PV.Text = Round2(L_VISITCC.Text / L_VREAL.Text,2)
	L_EFEC_PURA.Text = Round2(L_VISITCC.Text / L_VPLAN.Text,2)
	L_LIN_TICK.Text = LPT
	If l_monto_ks.Text <> "0" Then
		
		c=B4XPages.MainPage.skmt.ExecQuery2("Select  COUNT(DISTINCT(PE_CLIENTE)) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS =  ? ", Array As String(ALMACEN))
		c.Position = 0
		L_CTE_PROMO.Text = c.GetString("CUANTOS")
		c.Close
		d=B4XPages.MainPage.skmt.ExecQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("PRIORITARIO"))
		d.Position = 0
		'///////////////////////////////////////////////////////////////////////////////
		'////////////////////////////   ULTIMA LINEA ANTES DEL ERROR  //////////////////
		'////////// java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
		'
		'///  Al parecer d.GetString("MONTO_DIA") regresa null y la funcion numberFormat truena
		'/////////////////////////////////////////////////////////////////////////////////
		Log("|"&d.GetString("MONTO_DIA")&"|")
		'L_PRIO.Text = NumberFormat(d.GetString("MONTO_DIA"),0,2)
		L_PRIO.Text = d.GetString("MONTO_DIA")
		d.Close
		
		d=B4XPages.MainPage.skmt.ExecQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("ESTRATEGICO"))
		d.Position = 0
		L_SECUND.Text =d.GetString("MONTO_DIA")
		d.Close

		d=B4XPages.MainPage.skmt.ExecQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("COMPLEMENTARIO"))
		d.Position = 0
		L_COMP.Text =d.GetString("MONTO_DIA")
		d.Close
	Else
		L_PRIO.Text = "0"
		L_SECUND.Text = "0"
		L_COMP.Text = "0"
	End If
	
	c=B4XPages.MainPage.skmt.ExecQuery("Select  COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS = PE_PROID ")
	c.Position = 0
	If c.GetString("CUANTOS") > 0 Then
		d=B4XPages.MainPage.skmt.ExecQuery("Select  sum(pe_cant) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS = PE_PROID ")
		d.Position = 0
		L_CTE_PROMO.Text = d.GetString("CUANTOS")
		d.Close
		L_REDEN_PROMO.TEXT = Round2(L_VISITCC.Text / L_CTE_PROMO.Text,2)
	Else
		L_CTE_PROMO.Text = 0
		L_REDEN_PROMO.Text = 0
	End If
	c.Close
	d=B4XPages.MainPage.skmt.ExecQuery("Select  COUNT(*) AS CUANTOS FROM PEDIDO ")
	d.Position = 0
	L_LIN_TICK.Text = Round2(d.GetString("CUANTOS") / L_VISITCC.Text,2)
	d.Close

	d=B4XPages.MainPage.skmt.ExecQuery("Select  count(*) as CUANTOS  from HIST_CUOTAS ")
	d.Position = 0
	If d.GetString("CUANTOS") > 0 Then
		'	c=skmt.ExecQuery("Select  HC_CUOTA1,HC_CUOTA2,HC_CUOTA3 from HIST_CUOTAS ")
		'	c.Position = 0
		'	l_monto_c1.Text = Round( c.GetString("HC_CUOTA1") / 6)
		'	l_monto_c2.Text = Round(c.GetString("HC_CUOTA2") / 6)
		'	l_monto_c3.Text = Round(c.GetString("HC_CUOTA3") / 6)
		'	c.Close
	Else
		l_monto_c1.Text = 4000
		l_monto_c2.Text = 2000
		l_monto_c3.Text = 1000
	End If
	d.Close
End Sub

Sub hacer_ped_Click
	B4XPages.ShowPage("Clientes")
End Sub

Sub nvo_cliente_Click
	' Verificar si el punto está dentro del polígono
	
	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)
'        
'		If dentro Then
'			ToastMessageShow("El punto está DENTRO del polígono", True)
			B4XPages.ShowPage("NuevoCliente")
'		Else
'			ToastMessageShow("El punto está FUERA del polígono", True)
'		End If
'	End If
End Sub

Sub tickets_dia_Click
	B4XPages.ShowPage("TicketsDia")
End Sub

Sub GPS_LocationChanged (Location1 As Location)

End Sub

Sub Btn_Ubicar_Click
	rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
	Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
	If Result Then
		StartActivity(MAPA_RUTAS)
	End If
End Sub

'''''''''''''''''''''''''''''''''''' VALIDAR CARACTERES
Sub e_ruta_TextChanged (Old As String, New As String)
	Dim validChars As String ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
'	Log("Antes: " & Old & " | " & New)
	If Old <> "KMTS1" Then
'		Log("Desp: " & Old & " | " & New)
		Try
			If validChars.Contains(New.SubString(New.Length-1)) = False Then
				e_ruta.Text = New.SubString2(0, New.Length-1)
				e_ruta.SelectionStart = e_ruta.Text.Length
			End If
		Catch
			Log(LastException)
		End Try
	End If
End Sub

Sub B_COMM_Click
	Btn_Ubicar.Visible=False
	SCROLL_RESDIA.Visible = True
	SCROLL_RESDIA.Panel.LoadLayout("COMIS")
	SCROLL_RESDIA.Panel.Height = Panel_C.Height
	Panel4.Visible = False
	Panel_C.Visible = True
	
'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False
'	
'	If l_ruta.Text <> 0 Then
'		c=B4XPages.MainPage.skmt.ExecQuery("Select  HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB   from HIST_COMISIONES_MOVIL ")
'		c.Position = 0
'		L_TOTAL_BA.Text = c.GetString("HCM_TOTAL_BEB")
'		L_TOTAL_GUNA.Text = c.GetString("HCM_TOTAL_GUNA")
'		L_TOTAL_MM.Text = c.GetString("HCM_TOTAL_V")
'		L_TOTAL_VIVE.Text = c.GetString("HCM_TOTAL_VIVE")
'		c.Close
'		L_TOTAL_COMIS.Text = 0
'	Else
'		L_TOTAL_BA.Text = 0
'		L_TOTAL_GUNA.Text = 0
'		L_TOTAL_MM.Text = 0
'		L_TOTAL_VIVE.Text = 0
'		L_TOTAL_COMIS.Text = 0
'	End If
End Sub

Sub B_OK_COMISS_Click
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
	Panel_C.Visible = False
	SCROLL_RESDIA.Visible = False
	Btn_Ubicar.Visible=True
End Sub


Sub B_MARCAS_Click
'	SCROLL_RESDIA.Visible = False
'	Panel5.Visible = True
'	pnlTitle.Visible = False
'	pnlTitle.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, TitleHeight + DividerHeight)
'	pnlTitle.LoadLayout("CellTitle")
'	c=B4XPages.MainPage.skmt.ExecQuery("Select CAT_GP_CLASIF, sum(pe_costo_tot) As total from CATALOGO, pedido where pe_proid = cat_gp_id 	And pe_cliente <> 0 	group by cat_gp_clasif")
'	
'	CLV1.Clear
'	If c.RowCount>0 Then
'		For i=0 To c.RowCount -1
'			c.Position=i
'			AddTitle(c.GetString("CAT_GP_CLASIF"))
'				f=B4XPages.MainPage.skmt.ExecQuery2("select * from HIST_AVANCE where HA_MARCA = ?", Array As String(c.GetString("CAT_GP_CLASIF")))
'				f.Position=0
'				If f.RowCount > 0 Then
'					CLV1.AddTextItem("VENTA = $" & f.GetString("HA_AVANCE"),"1")
'					CLV1.AddTextItem("META  = $" & f.GetString("HA_OBJETIVO"),"1")
'					CLV1.AddTextItem("PORCENTAJE  = %" & (f.GetString("HA_PORCENTAJE")) ,"1")
'				End If
'				f.Close
'		Next
'	End If
'	c.Close

	SCROLL_RESDIA.Visible = False
	Panel5.Visible = True
	pnlTitle.Visible = False
	pnlTitle.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, TitleHeight + DividerHeight)
	pnlTitle.LoadLayout("CellTitle")
	c=B4XPages.MainPage.skmt.ExecQuery("Select CAT_GP_CLASIF, SUM(TOTAL) AS TOTAL FROM TOTAL_MARCAS GROUP BY CAT_GP_CLASIF")
	CLV1.Clear
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			AddTitle(c.GetString("CAT_GP_CLASIF"))
			If c.GetString("CAT_GP_CLASIF") = "PROMOS" Then
				d=B4XPages.MainPage.skmt.ExecQuery("SELECT SUM(PE_CANT) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS = PE_PROID")
				d.Position=0
				CLV1.AddTextItem("CANTIDAD DE PROMOS = " & d.GetString("CUANTOS"),"1")
				d.Close
			Else
				f=B4XPages.MainPage.skmt.ExecQuery2("select COUNT(*) AS CUANTOS from HIST_MARCAS_CUOTAS where HMC_MARCA = ?", Array As String(c.GetString("CAT_GP_CLASIF")))
				f.Position=0
				If f.GetString("CUANTOS") > 0 Then
					e=B4XPages.MainPage.skmt.ExecQuery2("select HMC_MARCA, HMC_TOTAL from HIST_MARCAS_CUOTAS where HMC_MARCA = ?", Array As String(c.GetString("CAT_GP_CLASIF")))
					e.Position=0
					d=B4XPages.MainPage.skmt.ExecQuery2("SELECT count(distinct(PE_CLIENTE)) AS CUANTOS FROM PEDIDO WHERE PE_PROID in (select CAT_GP_ID from cat_gunaprod WHERE CAT_GP_CLASIF =?)", Array As String (c.GetString("CAT_GP_CLASIF")))
					d.Position=0
					CLV1.AddTextItem("TOTAL  PREVENTA = $" & c.GetString("TOTAL"),"1")
					CLV1.AddTextItem("M E T A  = $" & e.GetString("HMC_TOTAL"),"1")
					CLV1.AddTextItem("FALTA  = $" & (e.GetString("HMC_TOTAL") - c.GetString("TOTAL")) ,"1")
					CLV1.AddTextItem("CLIENTES  = " & d.GetString("CUANTOS"),"1")
					d.Close
					e.Close
				Else
					d=B4XPages.MainPage.skmt.ExecQuery2("SELECT count(distinct(pe_cliente)) AS CUANTOS FROM PEDIDO WHERE PE_PROID in (select CAT_GP_ID from cat_gunaprod WHERE CAT_GP_CLASIF =?)", Array As String (c.GetString("CAT_GP_CLASIF")))
					d.Position=0
					CLV1.AddTextItem("TOTAL  PREVENTA = $" & c.GetString("TOTAL"),"1")
					CLV1.AddTextItem("M E T A  = $" & "1000","1")
					CLV1.AddTextItem("FALTA  = $" & (1000 - c.GetString("TOTAL")) ,"1")
					CLV1.AddTextItem("CLIENTES  = " & d.GetString("CUANTOS"),"1")
					d.Close
				End If
				f.Close
			End If
		Next
	End If
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery("Select HMC_MARCA,  HMC_TOTAL from HIST_MARCAS_CUOTAS where HMC_MARCA  not in (SELECT  CAT_GP_CLASIF FROM TOTAL_MARCAS )")
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			AddTitle(c.GetString("HMC_MARCA"))
			CLV1.AddTextItem("TOTAL  PREVENTA = $ 0.00","1")
			CLV1.AddTextItem("M E T A  = $" & C.GetString("HMC_TOTAL"),"1")
			CLV1.AddTextItem("CLIENTES  = 0","1")
		Next
	End If
	c.Close


End Sub

Sub AddTitle (Title As String)
	Dim p_MARCAS As B4XView = xui.CreatePanel("")
	p_MARCAS.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, TitleHeight)
	p_MARCAS.LoadLayout("CellTitle")
	lblTitle.Text = Title
	Dim td As TitleData
	td.Title = Title
	CLV1.Add(p_MARCAS, td)
End Sub

Sub B_OK_PANEL5_Click
	Panel5.Visible = False
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
	Panel4.Visible=False
	SCROLL_RESDIA.Visible = False
	Btn_Ubicar.Visible=True
	p_principal.Visible = True

End Sub

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

Private Sub p_mandaInfo_Click
	
End Sub

Private Sub iv_abordo_Click
	Starter.skmt.ExecNonQuery("delete from CUENTAA")
	Starter.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object("0"))
	B4XPages.MainPage.tipo_venta = "ABORDO"
	B4XPages.ShowPage("Productos")
End Sub

Sub checaPedido
	Starter.skmt.ExecNonQuery("Update kmt_info set gestion = 0")
	Private c As Cursor = Starter.skmt.ExecQuery("SELECT PC_CLIENTE FROM PEDIDO_CLIENTE")
	If c.RowCount > 0 Then
		Starter.skmt.ExecNonQuery("Update kmt_info set gestion = 2  WHERE CAT_CL_CODIGO IN (SELECT PC_CLIENTE FROM PEDIDO_CLIENTE)")
	End If
	Private c As Cursor = Starter.skmt.ExecQuery("SELECT NV_CLIENTE FROM NOVENTA")
	If c.RowCount > 0 Then
		Starter.skmt.ExecNonQuery("Update kmt_info set gestion = 3  WHERE CAT_CL_CODIGO IN (SELECT NV_CLIENTE FROM NOVENTA)")
	End If
	
	Private coord As Cursor = Starter.skmt.ExecQuery("SELECT * FROM COORDENADAS")
	If coord.RowCount > 0 Then
		For cor = 0 To coord.RowCount -1
			coord.Position = cor
			B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE kmt_info set  CAT_CL_LONG = ?, CAT_CL_LAT =?, CAT_CL_BCOORDENADAS = ? where CAT_CL_CODIGO = ?", Array As Object(coord.GetString("LAT"), coord.GetString("LONG"),(coord.GetInt("CANTIDAD")+1),coord.GetString("CLIENTE")))
		Next
	End If
	
	Private coord As Cursor = Starter.skmt.ExecQuery("SELECT * FROM ATIENDE")
	If coord.RowCount > 0 Then
		For cor = 0 To coord.RowCount -1
			coord.Position = cor
			B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE kmt_info set  CAT_CL_ATIENDE1 = ? where CAT_CL_CODIGO = ?", Array As Object(coord.GetString("ATIENDE"),coord.GetString("CLIENTE")))
		Next
	End If
	
	Private coord As Cursor = Starter.skmt.ExecQuery("SELECT * FROM GIROS_ACTUAL")
	If coord.RowCount > 0 Then
		For cor = 0 To coord.RowCount -1
			coord.Position = cor
			B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE kmt_info set  CAT_CL_GIRO = ? where CAT_CL_CODIGO = ?", Array As Object(coord.GetString("GIRO"), coord.GetString("CLIENTE")))
		Next
	End If
End Sub

Private Sub b_tabulador_Click
	B4XPages.ShowPage("tabulador")
End Sub

Private Sub btnCobranza_Click
	Log("Entrando al Panel de Cobranza")
    
	pnlCobranza.Width = Root.Width
	pnlCobranza.Height = Root.Height
	pnlCobranza.Left = 0
	pnlCobranza.Top = 0
	pnlCobranza.BringToFront
	pnlCobranza.Visible = True
	pnlTotal.Visible = True
	Dim ct As Cursor = B4XPages.MainPage.skmt.ExecQuery($"SELECT IFNULL(sum(IFNULL(a.a_abono,0)),0) as suma_abono FROM kmt_info2 ki LEFT JOIN ABONOSP ap ON ki.CAT_CL_CODIGO = ap.CLIENTE LEFT JOIN ABONOS a ON ki.CAT_CL_CODIGO = a.a_cliente WHERE CAST(ap.SALDO_PENDIENTE AS REAL) > 0"$)
	ct.Position = 0
	If ct.RowCount > 0 Then
		lblTotal.Text = "El total abonado es: $" & ct.getString("suma_abono")
	End If
	lblVersion.Text = Application.VersionName
	ct.Close
	CargarDatosCobranza
End Sub

Private Sub CargarDatosCobranza
	For i = pnlCobranza.NumberOfViews - 1 To 0 Step -1
		Dim v As View = pnlCobranza.GetView(i)
		If v Is Label Then
			Dim lbl As Label = v
			If lbl.Text = "No hay cuentas por cobrar" Then
				pnlCobranza.RemoveViewAt(i)
			End If
		End If
	Next
	c = B4XPages.MainPage.skmt.ExecQuery($"SELECT ROW_NUMBER() OVER (ORDER BY ki.CAT_CL_NOMBRE) AS Secuencia, ki.CAT_CL_CODIGO, ki.CAT_CL_NOMBRE, ap.SALDO_PENDIENTE, IFNULL(a.a_abono,0) as a_abono FROM kmt_info2 ki LEFT JOIN ABONOSP ap ON ki.CAT_CL_CODIGO = ap.CLIENTE LEFT JOIN ABONOS a ON ki.CAT_CL_CODIGO = a.a_cliente WHERE CAST(ap.SALDO_PENDIENTE AS REAL) > 0"$)
	Log("Número de registros: " & c.RowCount)
    
	clvCobranza.Clear
	
	For i = 0 To c.RowCount - 1
		c.Position = i
        
		Dim pItem As B4XView = xui.CreatePanel("")
		pItem.LoadLayout("C_CuentasXCobrar")
		pItem.SetLayoutAnimated(0, 0, 0, Root.Width, 100dip)
		pItem.Color = Colors.White
        
		pnlContenedorCobranza.SetLayoutAnimated(0, 0, 0, pItem.Width, pItem.Height)
		pnlContenedorCobranza.Color = xui.Color_Transparent
        
		l_Secuencia.Text = c.GetString("Secuencia")
        
		' Manejo seguro del nombre
		Dim codigo As String = c.GetString("CAT_CL_CODIGO")
		Dim nombre As String = c.GetString("CAT_CL_NOMBRE")
		If codigo = Null Then codigo = ""
		If nombre = Null Then nombre = ""
		l_Nombre.SingleLine = False
		l_Nombre.Text = codigo & " " & nombre
        
		l_CuentaXCobrar.Text = "$" & NumberFormat(c.GetDouble("SALDO_PENDIENTE"), 1, 2)
		l_Abono.Text = "$" & NumberFormat(c.GetDouble("a_abono"), 1, 2)
        
		clvCobranza.Add(pItem, "Item-" & i)
	Next
	
	c.Close
	pnlCobranza.Invalidate
    
	If c.RowCount = 0 Then
		Dim lblEmpty As Label
		lblEmpty.Initialize("")
		lblEmpty.Text = "No hay cuentas por cobrar"
		lblEmpty.TextSize = 16
		lblEmpty.TextColor = Colors.Gray
		lblEmpty.Gravity = Gravity.CENTER
		pnlCobranza.AddView(lblEmpty, 0, 100dip, Root.Width, 50dip)
	End If
End Sub

Private Sub btnRegresar_Click
	pnlCobranza.Visible = False
End Sub

Private Sub pnlCobranza_Click
	
End Sub

'Private Sub clvCobranza_ItemClick (Index As Int, Value As Object)
'	Dim CodigoCliente As Cursor = Value
'	CodigoCliente = B4XPages.MainPage.skmt.ExecQuery($"SELECT ROW_NUMBER() OVER (ORDER BY ki.CAT_CL_NOMBRE) AS Secuencia, ki.CAT_CL_NOMBRE, ap.SALDO_PENDIENTE, IFNULL(a.a_abono,0) as a_abono FROM kmt_info2 ki LEFT JOIN ABONOSP ap ON ki.CAT_CL_CODIGO = ap.CLIENTE LEFT JOIN ABONOS a ON ki.CAT_CL_CODIGO = a.a_cliente WHERE CAST(ap.SALDO_PENDIENTE AS REAL) > 0"$)
'	B4XPages.ShowPage("cliente")
'End Sub

Private Sub b_regreso_Click
	p_prod.Visible = False
End Sub

Private Sub p_prod_Click
	
End Sub

Private Sub b_productos_Click
	
	Dim label1 As Label
	label1 = lv_prod_Prin.SingleLineLayout.Label
	label1.TextSize = 14
	p_prod.Width = Root.Width
	p_prod.Height = Root.Height
	b_regreso.Left = (p_prod.Width - b_regreso.Width) / 2
	b_regreso.Top = p_prod.Height - b_regreso.Height
	
	p_prod.Visible = True
	p_prod.BringToFront

	
	Private c As Cursor = Starter.skmt.ExecQuery("select CAT_GP_NOMBRE AS HVD_PRONOMBRE, IFNULL(cat_gp_almacen, 0) AS HVD_RECHAZOCANT from CAT_GUNAPROD2 WHERE CAT_GP_TIPO <> 'PROMOS' AND CAT_GP_SUBTIPO <> 'PROMOS' order by CAT_GP_NOMBRE asc")
	
	lv_prod_Prin.SingleLineLayout.Label.TextColor = Colors.Black
	lv_prod_Prin.Clear
	If c.RowCount > 0 Then
		For i = 0 To c.RowCount - 1
			c.Position = i
			Dim itemText As String
			
			
			
			itemText = $"${c.GetString("HVD_PRONOMBRE")} ${CRLF} ${CRLF}Cantidad: ${(c.GetDouble("HVD_RECHAZOCANT"))}"$ 
				lv_prod_Prin.AddSingleLine(itemText)
			
			
		Next
	Else
		lv_prod_Prin.AddSingleLine("No hay datos disponibles.")
	End If
	c.Close
	
End Sub
