B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	'//Process_Globas
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	Dim reqManager As DBRequestManager
	Dim t1 As Timer
	Dim t2 As Timer
	Private t3 As Timer
	Dim inicioContador As String
	
	'//Globals
	Dim trabajar As Button
	Dim Cursor_check As Cursor
	Dim c As Cursor
	Dim d As Cursor
	Dim b As Cursor
	Dim e As Cursor
	Dim f As Cursor
	Dim C_DOE As Cursor
	Dim D_DOE As Cursor
	Dim F_DOE As Cursor
	
	Dim TOTAL_DOE_BB As String
	Dim TOTAL_EFE_DOE As String
	Dim TOTAL_ENTREGA_DOE As String
	
	
	Dim DDD As Cursor
	Dim cargar As Button
	Dim foto1() As Byte
	Dim foto2() As Byte
	Dim foto3() As Byte
	Dim foto4() As Byte
	Dim usuario As String
	Dim connecta As Button
	Dim conn As String
	Dim Subir As Button
	Dim cmd As DBCommand
	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 Today 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 Int
	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 MARCASQ As String
	Private B_PROXIMA As Button
	Private l_monto_a As Label
	Private ImageView9 As ImageView
	Private L_MONTO_R As Label
	Dim PERFIL As String
	Dim NUMERO_PEDIDO As String
	Private l_cambios As Label
	Dim l_monto_ks As Label
	Dim l_monto_kp As Label
	Dim l_monto_k As Label
	Private Cuantos As String
	Dim cmp20 As Serial
	Dim printer As TextWriter
	Dim PairedDevices As Map
	Dim TAMANO As Int
	Dim ESPACIO As Int
	Dim BLANCO As String
	Dim sDate,sTime As String
	Dim PASA_IMP As String
	Dim s As Cursor
	Private B_IMP As Button
	Private l_monto_c1 As Label
	Private l_monto_c2 As Label
	Private l_monto_c3 As Label
	Private B_BOLETA As Button
	Private B_MAPA_RUTA As Button
	Private Panel5 As Panel
	Private L_CUOTA1 As Label
	Private L_CUOTA2 As Label
	Private L_CUOTA3 As Label
	Private L_CUOTA4 As Label
	Private L_CUOTA5 As Label
	Private L_CUOTA6 As Label
	Private L_META1 As Label
	Private L_META2 As Label
	Private L_META3 As Label
	Private L_META4 As Label
	Private L_META5 As Label
	Private L_META6 As Label
	Private B_CUOATA_C As Button
	Private b_cuotas As Button
	Private Panel1 As Panel
	Private Panel2 As Panel
	Dim ENVIADA As String
	Dim PORENVIAR As String
	Private Btn_CheckList As Button
	Dim Cedis_Check As String
	Private TIEMPO As String
	Private RUTA1 As Label
	Private L_ABORDO As Label
	Private bcarga1 As String
	Private bcarga2 As String
	Private bcarga3 As String
	Private contador_env As String
	Private contador_strem As String
	Private ruta_valida As String
	Private PNL_ACCESO As Panel
	Private Panel7 As Panel
	Private L_SUPLENCIA As Label
	Private E_RUTA2 As EditText
	Private Label4 As Label
	Private SEMANA As String
	Private ImageView1 As ImageView
	Dim DIA_VISITA As String
	
'	Para el PDFViewer
	Dim pdf As PdfiumCore
	Private PDFView1 As PDFView
	Private btnFirst As Button
	Private btnPrev As Button
	Private lblPages As Label
	Private btnNext As Button
	Private btnLast As Button
	Private glPages As Int
	Private p_pdfViewer As Panel
	Private pdfViewerActivo As Boolean
	Private p_controles_pdf As Panel
	Private pdfURL As String
	Private l_2 As Label
	Dim cartaPorteLista As Boolean
	Private l_downloadPDF As Label
	Private ProgressBarPDF As ProgressBar
	Private p_downloadPDF As Panel
	Private p_progress1 As Panel
	Private l_porcentaje As Label
	Private detenerLoop As Boolean = False
	Dim logger As Boolean = True
	Private L_DOE As Label
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
	Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	If Not(Starter.Logger) Then logger = False
	Root = Root1
	'load the layout to Root
	Root.LoadLayout("principal")
	EJECUTANDO=1
	Dim ruta As String
	img2.Visible =False
	ruta = File.DirInternal
	DateTime.DateFormat = "MM/dd/yyyy"
	fecha=DateTime.Date(DateTime.Now)
	c=Starter.skmt.ExecQuery2("select CAT_CO_CONFIGURACION from CAT_CODIGOS where CAT_CO_PONDERACION =1 AND CAT_CO_ACCION = ?", Array As String("SERVER"))
	c.Position =0
	Starter.server = c.GetString("CAT_CO_CONFIGURACION")
	c.Close
	b=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	d=Starter.skmt.ExecQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	D.Position=0
	b.Close
	e=Starter.skmt.ExecQuery("select count(*) as POR_VISITAR from kmt_info")
	e.Position=0
	f=Starter.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=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info")
		f.Position=0
		l_ruta.Text = f.GetString("CAT_CL_RUTA")
		RUTA1.Text = l_ruta.TEXT
		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=Starter.skmt.ExecQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente ")
		b=Starter.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")
	End If
End Sub

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

Sub B4XPage_Appear
	If Starter.ultima_back_productos = 1 Then
		Subs.iniciaActividad("productos")
	Else
	
	Starter.btAdmin.Initialize("BlueTeeth")
	If Not(Starter.btAdmin.IsEnabled) Then Starter.btAdmin.Enable
	e_ruta.Enabled = True
	Starter.rutaV = l_ruta.Text
	c=Starter.skmt.ExecQuery2("select count(*) as CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SERVER"))
	c.Position =0
	If c.GetString("CUANTOS") = 0 Then
		Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SERVER", Starter.server))
	Else
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SERVER"))
		c.Position =0
		Starter.server = c.GetString("CAT_VA_VALOR")
	End If
	c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FECHA"))
	If c.RowCount > 0 Then
		c.Position = 0
		Starter.FECHA_HOY = c.GetString("CAT_VA_VALOR")
	End If
	reqManager.Initialize(Me, Starter.server)
	c=Starter.skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA"))
	c.Position =0
	SEMANA = c.GetString("CUANTOS")
	c.Close
	If SEMANA > 0 Then
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA"))
		c.Position =0
		SEMANA = c.GetString("CAT_VA_VALOR")
		c.Close
	End If
	c.Close
	c=Starter.skmt.ExecQuery2("select  count(*) as CUANTOS from kmt_info where  CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?) and gestion = 0 and cat_cl_codigo <> 0 AND CAT_CL_TIPO_RUTA IN (?,?)  ORDER BY CAT_CL_NUM_SERIEFISICO", Array As String("DIA_VISITA",SEMANA, "SEMANAL"))
	c.Position = 0
	Starter.clientesTotal = c.GetString("CUANTOS")
	l_porvisitar.Text = Starter.clientesTotal
	PASO = 0
	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=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente where pc_cliente <> 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
'	If Starter.marcaCel <> "LGE" Then ToastMessageShow(Cuantos , True)
	d=Starter.skmt.ExecQuery2("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0 and  cat_cl_codigo <> 0 AND CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?)", Array As String("DIA_VISITA"))
	D.Position=0
	b.Close
	e=Starter.skmt.ExecQuery2("select count(*) as POR_VISITAR from kmt_info where cat_cl_codigo <> 0 and CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?) ", Array As String("DIA_VISITA"))
	e.Position=0
	f=Starter.skmt.ExecQuery("select count(*) as CAT_CL_RUTA from kmt_info where cat_cl_codigo <> 0")
	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=Starter.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info")
		f.Position=0
		l_ruta.Text = f.GetString("CAT_CL_RUTA")
		f.Close
	End If
	c=Starter.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	Starter.usuario = usuario
	c.Close
	c=Starter.skmt.ExecQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	C.Close
	Cursor_check = Starter.skmt.ExecQuery("select count(*) as CUANTOS from TMP_INSPECCION_AUTO_DIARIA where tmp_auto_kilometraje <> '' ")
	Cursor_check.Position = 0
	Cedis_Check = Cursor_check.GetString("CUANTOS")

	If Not(File.Exists(File.DirInternal,"FOTO1.jpg")) Or _
		Not(File.Exists(File.DirInternal,"FOTO2.jpg")) Or _ 
		Not(File.Exists(File.DirInternal,"FOTO3.jpg")) Or _ 
		Not(File.Exists(File.DirInternal,"FOTO4.jpg")) Then
		If Not(File.Exists(File.DirInternal,"FOTO1.jpg")) Then Log("Falta foto1")
		If Not(File.Exists(File.DirInternal,"FOTO2.jpg")) Then Log("Falta foto2")
		If Not(File.Exists(File.DirInternal,"FOTO3.jpg")) Then Log("Falta foto3")
		If Not(File.Exists(File.DirInternal,"FOTO4.jpg")) Then Log("Falta foto4")
		Cedis_Check = 0
	End If
	If Cedis_Check = 0 And l_ruta.Text <> 0 Then
		Btn_CheckList.Visible = True
		B_MAPA_RUTA.Visible = False
	Else
		'	PONER EN FALSE
		Btn_CheckList.Visible = False
		B_MAPA_RUTA.Visible = True
		If usuario = "JOSELUIS"  Then Btn_CheckList.Visible = True  'Mod por CHV - 211125
	End If
	contador_strem = 0
	contador_env = 0
	E_RUTA2.Visible = False
	L_SUPLENCIA.Visible = False
	Label4.Visible = False
	Starter.montoActual = L_MONTOD.Text
	Starter.clientesventa =  l_cuantosc.Text
	Starter.clientesvisitados = l_porvisitar.TEXT
	Starter.ALMACEN = ALMACEN
	Starter.rutapreventa =  l_ruta.text
	CallSub(Starter, "ENVIA_ULTIMA_GPS")
	c.Close
	Subs.guardaUltimaActividadBD("principal")
	Subs.ultimaActividad(Me)
	
	End If
End Sub

Sub trabajar_Click
	'CallSubDelayed(gestion,"gestion")
	'Mod por CHV para que si no se ha hecho el checklist no permita la venta - 211125
	c=Starter.skmt.ExecQuery("select 'TMP_AUTO_FECHA ' from TMP_INSPECCION_AUTO_DIARIA where tmp_auto_kilometraje <> ''")
	If c.RowCount > 0 Then
		If logger Then Log("Si hay checklist")
	Else
		If logger Then Log("NO hay checklist")
		Msgbox("No se ha realizado aún el 'Checklist' del vehículo, por favor completelo antes de realizar una venta.", "FALTA EL CHECKLIST") 'ignore
		Return
	End If
	c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("MARCAS"))
	c.Position =0
	If c.RowCount > 0 Then
		MARCASQ = c.GetString("CAT_VA_VALOR")
		c.Close
		Starter.skmt.ExecNonQuery("delete from CAT_GUNAPROD WHERE CAT_GP_CLASIF NOT IN (" & MARCASQ &")" )
		Starter.skmt.ExecNonQuery("delete from CAT_GUNAPROD WHERE CAT_GP_ID IN (SELECT CAT_DP_ID FROM CAT_DETALLES_PAQ WHERE CAT_DP_IDPROD NOT IN (SELECT CAT_GP_ID FROM CAT_GUNAPROD))")
		B4XPages.ShowPage("Clientes")
	Else
		If Starter.marcaCel <> "LGE" Then ToastMessageShow("No hay marcas en la base de datos ... ya se cargo ruta??", True)
	End If
End Sub

Sub Subir_Click
	CARGA = "SUBIR"
'	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.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
	contador_env = 0
	contador_strem = 0
	e_ruta.Text = ruta_valida
	PASO = 1
	'End If
	If PASO = 1 Then
		c=Starter.skmt.ExecQuery("select  CAT_CL_CODIGO, CAT_CL_RUTA from kmt_info")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				Starter.skmt.ExecNonQuery2("update PEDIDO set PE_RUTA  =  ? where PE_CLIENTE = ? ", Array As Object(c.GetString("CAT_CL_RUTA"),c.GetString("CAT_CL_CODIGO")))
			Next
		End If
		c=Starter.skmt.ExecQuery2("SELECT  HE_CUANTOS, HE_FECHA FROM HIST_ENVIOS WHERE HE_TIPO = ?", Array As String("PEDIDO"))
		c.Position = 0
		''' FALTA PONER EL IF DE CUANTAS VECES MANDO Y SI MANDO PREGUNTAR ENVIAR BOLETA O PEDIDO
		If c.GetString("HE_CUANTOS") = 0 Then
			SUBIR_INFO_PEDIDO
		Else
			Dim result As Int
			result = Msgbox2("QUE VA A ENVIAR?", "ENVIO DE INFO.", "BOLETA", "VALIDAR", "VTA/PED", LoadBitmap(File.DirAssets, "alert2.png")) 'ignore
			If result = DialogResponse.Positive Then
				SUBIR_INFO_BOLETA
			ELSE IF result = DialogResponse.NEGATIVE Then
				SUBIR_INFO_PEDIDO
			ELSE IF result = DialogResponse.CANCEL Then
				VALIDAR_INFO
			End If
		End If
	End If
End Sub

Sub cargar_Click
	'Para descargar el PDF de la carta porte  /////////////////////////////////////////////////////////////////////////
	DateTime.DateFormat = "yyyyMMdd"
	Dim hoy As String = DateTime.Date(DateTime.Now)
	If logger Then Log(DateTime.Date(File.LastModified(File.DirInternal,"cartaPorte.pdf")) & " - " & hoy )
'	If Not(File.Exists(File.DirInternal,"cartaPorte.pdf")) Then 'Si no existe la descargamos ...
'		If logger Then LogColor("No hay carta porte.", Colors.Red)
'		descargaCartaPorte ' la descargamos.
'		Do While Not(cartaPorteLista) 'Mientras no se termine de descargar la carta porte, esperamos ...
'			Sleep(1000)
'			If logger Then Log("Descargando Carta Porte (Loop cargar_Click)")
'		Loop
'	Else If (DateTime.Date(File.LastModified(File.DirInternal,"cartaPorte.pdf")) < hoy And Starter.rutaTipo <> "FORANEA") Then  ' si la fecha del pdf NO es de hoy y la ruta NO es foranea entonces ...
'		LogColor("La carta porte es vieja.", Colors.Red)
'		If logger Then Log(Starter.rutaTipo)
'		descargaCartaPorte ' la descargamos.
'		Do While Not(cartaPorteLista) 'Mientras no se termine de descargar la carta porte, esperamos ...
'			Sleep(1000)
'			If logger Then Log("Descargando Carta Porte (Loop cargar_Click)")
'			If detenerLoop Then Exit
'			detenerLoop = False
'		Loop
'	Else
		cartaPorteLista = True
		If logger Then LogColor("Ya hay carta porte con fecha de hoy", Colors.Green)
		Private MB As Int
		MB = Msgbox2("¿Quiere descargarla nuevamente?", "YA SE DESCARGO LA CARTA PORTE", "Si", "", "No", Null) 'ignore
		If MB = DialogResponse.Positive Then
			descargaCartaPorte
			Do While Not(cartaPorteLista)  'Mientras no se termine de descargar la carta porte esperamos ...
				Sleep(1000)
				If logger Then Log("Descargando Carta Porte (Loop cargar_Click)")
				If detenerLoop Then Exit
				detenerLoop = False
			Loop
		ELSE IF MB = DialogResponse.NEGATIVE Then
'			descargaCartaPorte
		ELSE IF MB = DialogResponse.CANCEL Then
'			VALIDAR_INFO
		End If
'	End If
	'Termina descargar el PDF de la carta porte  ///////////////////////////////////////////////////////////////////////////////
	If cartaPorteLista Then
		CARGA = "CARGAR"
		img2.Visible =True
		L_P_1.Visible = True
		S_CC.Visible = True
		Btn_CheckList.Visible=False
'		P1.Visible = True
'		P1.BringToFront
		P1.Width = GetDeviceLayoutValues.Width
		P1.Height = GetDeviceLayoutValues.Height
		Subs.panelVisible(P1, 0,  0)
		trabajar.Visible = False
		B_PROXIMA.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
		E_RUTA2.Visible = False
		L_SUPLENCIA.Visible = False
		Label4.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
		bcarga1 = 0
		bcarga2 = 0
		bcarga3 = 0
		e_ruta.Text = ruta_valida
		' NUEVOS CLIENTE
	
		Starter.skmt.ExecNonQuery2("delete from kmt_info where substr(CAT_CL_CODIGO,1,1) <> ?", Array As Object ("N"))
		Starter.skmt.ExecNonQuery("delete from cod_result")
		Starter.skmt.ExecNonQuery("delete from hist_gest")
		Starter.skmt.ExecNonQuery("delete from cat_gunaprod")
		Starter.skmt.ExecNonQuery("delete from cat_gunaprod2")
	
		Starter.skmt.ExecNonQuery("delete from cat_gunaprod_doe")
		Starter.skmt.ExecNonQuery("delete from pedido_doe")
		
		Starter.skmt.ExecNonQuery("DELETE FROM CAT_GUNAPROD5")
		Starter.skmt.ExecNonQuery("DELETE FROM HIST_ENCUESTA2")
		Starter.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
		Starter.skmt.ExecNonQuery("delete from telefonos")
		Starter.skmt.ExecNonQuery("delete from HIST_VENTAS")
		Starter.skmt.ExecNonQuery("delete from HIST_PROMOS")
		Starter.skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
		Starter.skmt.ExecNonQuery("delete from PROMOS_COMP")
		Starter.skmt.ExecNonQuery("delete from CAT_VERIFICACION")
		Starter.skmt.ExecNonQuery("delete from LISTA_PRECIOS")
		Starter.skmt.ExecNonQuery("delete from CAT_PRECIOS")
		Starter.skmt.ExecNonQuery("delete from HIST_RMI")
		Starter.skmt.ExecNonQuery("delete from HIST_CUOTAS")
		Starter.skmt.ExecNonQuery("delete from HIST_EXHIBIDORES2")
		Starter.skmt.ExecNonQuery("delete from CAT_DESCUENTOS_SKU")
		Starter.skmt.ExecNonQuery("delete from HIST_ABORDO")
		Starter.skmt.ExecNonQuery("delete from DESC_CLIENTES")
		Starter.skmt.ExecNonQuery("delete from CAT_ENCUESTA_PREGUNTA")
		Starter.skmt.ExecNonQuery("delete from CAT_PROMO_MONTO")
		Starter.skmt.ExecNonQuery("delete from CAT_RMI")
		Starter.skmt.ExecNonQuery("delete from CAT_DEV")
		
	
		Starter.skmt.ExecNonQuery("delete from CLIENTE_CARGA_DIA")
		Starter.skmt.ExecNonQuery("INSERT INTO CLIENTE_CARGA_DIA (CCD_CUENTA) SELECT DISTINCT PE_CLIENTE FROM PEDIDO")
	
		
	''' PEDIDO DOE
		Starter.skmt.ExecNonQuery("delete from CAT_GUNAPROD_DOE")
		Starter.skmt.ExecNonQuery("delete from PEDIDO_DOE")
	''' FIN DOE

		Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
		Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",0))

		c=Starter.skmt.ExecQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
	
		DateTime.TimeFormat = "HHmmss"
		inicioContador = DateTime.Now
	
		cmd.Initialize
		cmd.Name = "SELECT_HIST_ENCUESTA_KELL"
		cmd.Parameters = Array As Object( e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "HIST_ENCUESTA2")
	
		cmd.Initialize
		cmd.Name = "SELECT_EXHIBIDOR_RUTA_KELL"
		cmd.Parameters = Array As Object( e_ruta.text )
		If logger Then Log(e_ruta.TEXT)
		reqManager.ExecuteQuery(cmd , 0, "exhibidores")

		cmd.Initialize 'Para traer la contraseña del candado de "FIN DIA"
		cmd.Name = "SELECT_PASS_FIN_DIA"
		reqManager.ExecuteQuery(cmd , 0, "pass_fin_dia")

		cmd.Initialize
		cmd.Name = "select_cat_gunaprod_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprod")
		
		cmd.Initialize
		cmd.Name = "select_cat_devoluciones_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "devoluciones")

		cmd.Initialize
		cmd.Name = "select_cat_gunaprod2_KELL"
		cmd.Parameters = Array As Object(ALMACEN, e_ruta.Text)
		reqManager.ExecuteQuery(cmd , 0, "gunaprod2")

		cmd.Initialize
		cmd.Name = "select_cat_encuesta_p_KELL"
		cmd.Parameters = Array As Object(ALMACEN, e_ruta.Text)
		reqManager.ExecuteQuery(cmd , 0, "encuesta_p")

		cmd.Initialize
		cmd.Name = "select_cat_paquetes_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
		cmd.Initialize
		cmd.Name = "select_cat_paquetess_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "gunaprodps")
	
		cmd.Initialize
		cmd.Name = "select_cat_detallepa_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "detallepaq")

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

		cmd.Initialize
		cmd.Name = "select_hist_datos_KELL"
		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_datos_KELL2"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_datos")

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

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

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

		cmd.Initialize
		cmd.Name = "select_promo_monto_KELL"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "promo_monto")
		
		
	
		If E_RUTA2.Text <> "" Then
			cmd.Initialize
			cmd.Name = "select_cat_clientes_guna_KELL2"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "kmt_datos")
	
			cmd.Initialize
			cmd.Name = "select_hist_datos_KELL"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN,e_ruta.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_datos")
	
			cmd.Initialize
			cmd.Name = "select_hist_promos_KELL"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_promos")
	
			cmd.Initialize
			cmd.Name = "select_hist_cliente_promos_KELL"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
	
			cmd.Initialize
			cmd.Name = "select_promo_comp_KELL"
			cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
			reqManager.ExecuteQuery(cmd , 0, "hist_comp_promos")

			cmd.Initialize
			cmd.Name = "select_DESC_CLIENTE_KELL"
			cmd.Parameters = Array As Object( ALMACEN,E_RUTA2.text)
			reqManager.ExecuteQuery(cmd , 0, "DESCUENTOS_CLIENTE")
	
			cmd.Initialize
			cmd.Name = "select_DESC_CLIE_SKU_KELL"
			cmd.Parameters = Array As Object( ALMACEN,E_RUTA2.text)
			reqManager.ExecuteQuery(cmd , 0, "DESCUENTOS_CLIENTE_SKU")
		End If
	
		cmd.Initialize
		cmd.Name = "select_DESC_CLIENTE_KELL"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text)
		reqManager.ExecuteQuery(cmd , 0, "DESCUENTOS_CLIENTE")
		
		cmd.Initialize
		cmd.Name = "select_cat_RMI_KELL"
		cmd.Parameters = Array As Object(ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "RMI")
	
		cmd.Initialize
		cmd.Name = "select_DESC_CLIE_SKU_KELL"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text)
		reqManager.ExecuteQuery(cmd , 0, "DESCUENTOS_CLIENTE_SKU")

		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_KELL"
		cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "folio")

		' esto es para sacar el perfil y marcas del usuario
		cmd.Initialize
		cmd.Name = "select_perfil_KELL"
		cmd.Parameters = Array As Object(usuario)
		reqManager.ExecuteQuery(cmd , 0, "perfil")

		cmd.Initialize
		cmd.Name = "select_marcas_KELL"
		cmd.Parameters = Array As Object(usuario)
		reqManager.ExecuteQuery(cmd , 0, "marcas")
	
		cmd.Initialize
		cmd.Name = "select_CAMBIOS_KELL"
		'cmd.Parameters = Array As Object( ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "cat_cambios")

		cmd.Initialize
		cmd.Name = "select_SUCURSAL_KELL"
		cmd.Parameters = Array As Object( ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "sucursal")
	
		cmd.Initialize
		cmd.Name = "select_dia_visita_KELL"
		cmd.Parameters = Array As Object( ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "dia_visita")
	
		cmd.Initialize
		cmd.Name = "select_HIST_CUOTAS"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
		reqManager.ExecuteQuery(cmd , 0, "CUOTAS")
	
		cmd.Initialize
		cmd.Name = "select_hist_ventas_abordo_KELL"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
		reqManager.ExecuteQuery(cmd , 0, "hist_abordo")

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

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

		cmd.Initialize
		cmd.Name = "select_cat_variables_semana_tipo_KELL"
		reqManager.ExecuteQuery(cmd , 0, "SEMANA")

		cmd.Initialize
		cmd.Name ="insert_drop_KELL"
		cmd.Parameters = Array As Object(usuario,e_ruta.Text,fecha, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text,"CARGA", ALMACEN)
		reqManager.ExecuteCommand(cmd , "inst_noventa_ins_drop_kell")

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

		cmd.Initialize
		cmd.Name = "select_limite_abordo"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
		reqManager.ExecuteQuery(cmd , 0, "limite_abordo")
		
''' PARA LO DE DOE
		cmd.Initialize
		cmd.Name = "select_pedido_doe"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
		reqManager.ExecuteQuery(cmd , 0, "pedido_doe")
		
		cmd.Initialize
		cmd.Name = "select_cat_gunaprod_doe"
		cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
		reqManager.ExecuteQuery(cmd , 0, "cat_gunaprod_doe")

''' FIN DOE
		cargar.Visible = False
		Subir.Visible = False
		trabajar.Visible=False
		inv.Visible = False
		If Starter.marcaCel <> "LGE" Then ToastMessageShow("Se Actualizarán los datos. Este proceso podria tardar hasta un minuto, gracias" , True)
	End If
End Sub

Sub JobDone(Job As HttpJob)
'	LogColor("JobDone: "&Job.Tag & " Success:" & Job.Success , Colors.Magenta) ' Mod by CHV - 211116
	If inicioContador = "" Then inicioContador = 0
	If Job.Success = False Then
		If logger Then LogColor("** " & Job.Tag & " Error: " & Job.ErrorMessage, Colors.Red) ' Mod by CHV - 211116
		If Job.ErrorMessage = "STREAM" Then
			contador_strem = contador_strem +1
			If CARGA = "SUBIR" Then
				PB1.Progress = PB1.Progress + 1
				If PB1.Progress > 100 Then
					PB1.Progress = 1
				End If
				If contador_env = contador_strem And  S_CP.Text <> "INFO OK" Then
					PB1.Progress = 100
					S_CP.Text = "VALIDANDO"
				End If
			End If
		End If
	Else
		If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green)  'Mod por CHV - 211110
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "kmt_datos" Then 'query tag
				If logger Then Log("TIEMPO kmt_datos : " & ((DateTime.Now-inicioContador)/1000))
				S_CC.TEXT = "CARGANDO"
				Starter.skmt.BeginTransaction
				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_BFACTURA As String = records(RESULT.Columns.Get("CAT_CL_BFACTURA"))
					Dim CAT_CL_BCREDITO As String = records(RESULT.Columns.Get("CAT_CL_BBLOQUEOCRED"))
					Dim CAT_CL_DIAS_VISITA As String = records(RESULT.Columns.Get("CAT_CL_DIAS_VISITA"))
					Dim CAT_CL_TIPO_RUTA As String = records(RESULT.Columns.Get("CAT_CL_TIPO_RUTA"))
					Dim CAT_CL_CATEGORIA As String = records(RESULT.Columns.Get("CAT_CL_CATEGORIA"))
					Dim CAT_CL_SEGMENTO As String = records(RESULT.Columns.Get("CAT_CL_SEGMENTO"))
					Dim CAT_CL_LIMITECREDITO As String = records(RESULT.Columns.Get("CAT_CL_LIMITECREDITO"))
					
					If CAT_CL_LIMITECREDITO = "0" Then CAT_CL_BFACTURA = "100000000"
					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,CAT_CL_BFACTURA,CAT_CL_BCREDITO,CAT_CL_DIAS_VISITA,CAT_CL_TIPO_RUTA, gestion, IMPRESION, CAT_CL_CATEGORIA, CAT_CL_SEGMENTO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,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_LAT,CAT_CL_LONG,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO,CAT_CL_BFACTURA,CAT_CL_BCREDITO,CAT_CL_DIAS_VISITA,CAT_CL_TIPO_RUTA,CAT_CL_CATEGORIA, CAT_CL_SEGMENTO))
				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_BFACTURA,CAT_CL_BCREDITO,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO,CAT_CL_DIAS_VISITA, gestion, IMPRESION) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,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","NULL","NULL"))
				Starter.skmt.TransactionSuccessful 'Si no se pone TransactionSuccessful no se escribe NADA!!
				Starter.skmt.EndTransaction
				Listo1 = 1
				S_CC.Text = "LISTO"
'				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
			bcarga1 = 20
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_promos" Then 'query tag
				If logger Then Log("TIEMPO hist_promos : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_PROMOS(HP_CLIENTE, HP_CODIGO_PROMOCION) VALUES (?,?)", Array As Object (HP_CLIENTE, HP_CODIGO_PROMOCION))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				'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 = 70
				ELSE IF PB1.Progress = 70 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
				If logger Then Log("TIEMPO hist_cliente_promos : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
					Starter.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
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				' 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 = "hist_comp_promos" Then 'query tag
				If logger Then Log("TIEMPO hist_comp_promos : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
					Starter.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
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 70
				ELSE IF PB1.Progress = 70 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 = "promo_monto" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CPM_CLIENTE As String = records(RESULT.Columns.Get("CPM_CLIENTE"))
					Dim CPM_IDPROMO As String = records(RESULT.Columns.Get("CPM_IDPROMO"))
					Dim CPM_MONTO As String = records(RESULT.Columns.Get("CPM_MONTO"))
					Dim CPM_PROID As String = records(RESULT.Columns.Get("CPM_PROID"))
					Dim CPM_CANT As String = records(RESULT.Columns.Get("CPM_CANT"))
					Dim CPM_RANGO As String = records(RESULT.Columns.Get("CPM_RANGO"))
					Dim CPM_DESC As String = records(RESULT.Columns.Get("CPM_DESC"))
					
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_PROMO_MONTO(CPM_CLIENTE, CPM_IDPROMO, CPM_MONTO, CPM_PROID, CPM_CANT, CPM_RANGO, CPM_DESC) VALUES (?,?,?,?,?,?,?)", Array As Object (CPM_CLIENTE, CPM_IDPROMO, CPM_MONTO, CPM_PROID, CPM_CANT, CPM_RANGO, CPM_DESC))
				
				Next
			End If
		End If
		
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "RMI" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAT_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
					Dim CAT_DESCRIPCION As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
					Dim CAT_MONTO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_RMI(CAT_ID, CAT_DESCRIPCION, CAT_MONTO) VALUES (?,?,?)", Array As Object (CAT_ID,CAT_DESCRIPCION,CAT_MONTO))
				
				Next
			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"))
					Starter.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 = "DESCUENTOS_CLIENTE" Then 'query tag
				If logger Then Log("TIEMPO DESCUENTOS_CIENTE : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim DC_CL_CLIENTE As String = records(RESULT.Columns.Get("CAT_CL_CLIENTE"))
					Dim CAT_CL_DESCUENTO_SS As String = records(RESULT.Columns.Get("CAT_CL_DESCUENTO_SS"))
					Dim CAT_CL_DESCUENTO_RTEC As String = records(RESULT.Columns.Get("CAT_CL_DESCUENTO_RTEC"))
					Dim CAT_CL_DESCUENTO_PING As String = records(RESULT.Columns.Get("CAT_CL_DESCUENTO_PING"))
					Dim CAT_CL_TIPOCLIENTE As String = records(RESULT.Columns.Get("CAT_CL_TIPOCLIENTE"))
					Starter.skmt.ExecNonQuery2("INSERT INTO DESC_CLIENTES(DC_CL_CLIENTE , CAT_CL_DESCUENTO_SS , CAT_CL_DESCUENTO_RTEC , CAT_CL_DESCUENTO_PING, CAT_CL_TIPOCLIENTE ) VALUES (?,?,?,?,?)", Array As Object (DC_CL_CLIENTE , CAT_CL_DESCUENTO_SS , CAT_CL_DESCUENTO_RTEC , CAT_CL_DESCUENTO_PING,CAT_CL_TIPOCLIENTE))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
			End If
		End If

		'DESCUENTOS SKU
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "DESCUENTOS_CLIENTE_SKU" Then 'query tag
				If logger Then Log("TIEMPO DESCUENTOS_CLIENTE_SKU : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim CAT_DS_CLIENTE As String = records(RESULT.Columns.Get("CAT_DS_CLIENTE"))
					Dim CAT_DS_PRODID As String = records(RESULT.Columns.Get("CAT_DS_PRODID"))
					Dim CAT_DS_PORCENTAJE As String = records(RESULT.Columns.Get("CAT_DS_PORCENTAJE"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_DESCUENTOS_SKU (CAT_DS_CLIENTE, CAT_DS_PRODID, CAT_DS_PORCENTAJE ) VALUES (?,?,?)", Array As Object (CAT_DS_CLIENTE, CAT_DS_PRODID, CAT_DS_PORCENTAJE))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "hist_abordo" Then 'query tag
				If logger Then Log("TIEMPO hist_abordo : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim HVD_PROID As String = records(RESULT.Columns.Get("HVD_PROID"))
					Dim HVD_CANT As String = records(RESULT.Columns.Get("HVD_CANT"))
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_ABORDO(HIST_PROID, HIST_CANT) VALUES (?,?)", Array As Object (HVD_PROID, HVD_CANT))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod" Then 'query tag
				If logger Then Log("TIEMPO gunaprod : " & ((DateTime.Now-inicioContador)/1000))
				S_CP.Text = "CARGANDO"
				Starter.skmt.BeginTransaction
				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_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_GP_INICIATIVA"))
					'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))
					Starter.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_TIPOPROD,CAT_GP_INICIATIVA,CAT_GP_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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_GP_DEV))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
				'			c.Position=0
				'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD")
				'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
				'			c.Close
				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 = 80
				ELSE IF PB2.Progress = 80 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				' 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
		''' CARGAS DOE PEDIDO
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "cat_gunaprod_doe" Then 'query tag
				If logger Then Log("TIEMPO gunaprod_DOE : " & ((DateTime.Now-inicioContador)/1000))
				S_CP.Text = "CARGANDO"
				Starter.skmt.BeginTransaction
				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_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_GP_INICIATIVA"))
					'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))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD_DOE(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_GP_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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_GP_DEV))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
				'			c.Position=0
				'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD")
				'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
				'			c.Close
				'Listo2=1
				
				' ToastMessageShow("Productos Actualizados." , True)
				
			End If
		End If
	 
	 ''' FIN CARGA CATALOGO DOE
	 ''' INICIO CARGA PEDIDO DOE
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "pedido_doe" Then 'query tag
				If logger Then Log("TIEMPO PEDIDO_DOE : " & ((DateTime.Now-inicioContador)/1000))
				S_CP.Text = "CARGANDO"
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim HVD_ALMACEN As String = records(RESULT.Columns.Get("HVD_ALMACEN"))
					Dim HVD_COSTO_TOT As String = records(RESULT.Columns.Get("HVD_COSTO_TOT"))
					Dim HVD_COSTOU As String = records(RESULT.Columns.Get("HVD_COSTOU"))
					Dim HVD_CANT As String = records(RESULT.Columns.Get("HVD_CANT"))
					Dim HVD_PRONOMBRE As String = records(RESULT.Columns.Get("HVD_PRONOMBRE"))
					Dim HVD_PROID As String = records(RESULT.Columns.Get("HVD_PROID"))
					Dim HVD_CLIENTE As String = records(RESULT.Columns.Get("HVD_CLIENTE"))
					Dim HVD_FECHA As String = records(RESULT.Columns.Get("HVD_FECHA"))
					Dim HVD_USUARIO As String = records(RESULT.Columns.Get("HVD_USUARIO"))
					Dim HVD_RUTA As String = records(RESULT.Columns.Get("HVD_RUTA"))
					
					'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))
					Starter.skmt.ExecNonQuery2("INSERT INTO PEDIDO_DOE(PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_TIPO,PE_PRECIO2) VALUES (?,?,?,?,?,?,?,?,?,?,?,0)", Array As Object (HVD_ALMACEN, HVD_COSTO_TOT, HVD_COSTOU,HVD_CANT, HVD_PRONOMBRE, HVD_PROID, HVD_CLIENTE, HVD_FECHA, HVD_USUARIO,HVD_RUTA, "DOE"))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				
				
				
				'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
				'			c.Position=0
				'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD")
				'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
				'			c.Close
				'Listo2=1
				
				' ToastMessageShow("Productos Actualizados." , True)
				
			End If
		End If
	 ''' FIN CARGA PEDIDO DOE
		'CARGA DEL CATALOGO ABORDO
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod2" Then 'query tag
				If logger Then Log("TIEMPO gunaprod2 : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
					Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
					Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_GP_INICIATIVA"))
					Dim CAT_GP_CODPROMO As String = records(RESULT.Columns.Get("CAT_GP_CODPROMO"))
					'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))
					Starter.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,CAT_GP_INICIATIVA,CAT_GP_DEV,CAT_GP_CODPROMO) 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_GP_DEV,CAT_GP_CODPROMO))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD5(CAT_GP_ID,CAT_GP_ALMACEN) VALUES (?,?)", Array As Object (CAT_GP_ID,CAT_GP_ALMACEN))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				c=Starter.skmt.ExecQUERY("SELECT COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE <> 0")
				c.Position = 0
				cuantos_pedidosc = c.GetString("CUANTOS")
				c.Close
				If cuantos_pedidosc > 0 Then
					c=Starter.skmt.ExecQUERY("SELECT PE_PROID, SUM(PE_CANT) AS PE_CANT FROM PEDIDO WHERE PE_CLIENTE <> 0 GROUP BY PE_PROID")
					If c.RowCount>0 Then
						For i=0 To c.RowCount -1
							c.Position=i
							Starter.skmt.ExecNonQuery2("update CAT_GUNAPROD2 set CAT_GP_ALMACEN = CAT_GP_ALMACEN - ? where CAT_GP_ID = ? ", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
						Next
					End If
				End If
				'	skmt.ExecNonQuery("DELETE FROM CAT_GUNAPROD5")
				'	skmt.ExecNonQuery("INSERT INTO CAT_GUNAPROD5(CAT_GP_ID, CAT_GP_ALMACEN) SELECT CAT_GP_ID, CAT_GP_ALMACEN FROM CAT_GUNAPROD2")
				
				'
				'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD2 GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
				'			c.Position=0
				'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD2")
				'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD2(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
				'			c.Close
			End If
		End If
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "devoluciones" Then 'query tag
				If logger Then Log("TIEMPO devoluciones : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_DEV(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_PRECIO) VALUES (?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_PRECIO))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				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 = 80
				ELSE IF PB2.Progress = 80 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				' 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 = "gunaprodp" Then 'query tag
				If logger Then Log("TIEMPO gunaprodp : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
'					Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
					Starter.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,CAT_GP_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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,"0"))
					'	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,CAT_GP_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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,"0"))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				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 = 80
				ELSE IF PB2.Progress = 80 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				' 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
				Starter.skmt.BeginTransaction
				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"))
					Starter.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))
					'	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))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				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 = 80
				ELSE IF PB2.Progress = 80 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
				'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
				If logger Then Log("TIEMPO detallepaq : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
					Starter.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
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				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 = 80
				ELSE IF PB2.Progress = 80 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
				If logger Then Log("TIEMPO hist_datos : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				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"))
					Dim HVD_FECHA As String = records(RESULT.Columns.Get("HVD_FECHA"))
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_VENTAS(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT, HVD_FECHA) VALUES (?,?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT,HVD_FECHA))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
				Listo3 =1
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 70
				ELSE IF PB1.Progress = 70 Then
					PB1.Progress = 100
					S_CH.Text = "LISTO"
				End If
'				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 = "hist_rmi" Then 'query tag
				If logger Then Log("TIEMPO hist_rmi : " & ((DateTime.Now-inicioContador)/1000))
				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_PROID As String = records(RESULT.Columns.Get("HVD_PROID"))
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_RMI(HR_CLIENTE,HR_PRONOMBRE,HR_PROID, HR_CANT) VALUES (?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_PROID, HVD_CANT))
				Next
				Listo3 =1
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 50
				ELSE IF PB1.Progress = 50 Then
					PB1.Progress = 80
				ELSE If PB1.Progress = 80 Then
					PB1.Progress = 100
					S_CH.Text = "LISTO"
				End If
'				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"))
					Starter.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 = "limite_abordo" Then 'query tag
				If logger Then Log("TIEMPO limite_abordo : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_LA_LIMITE_ABORDO"))
					Dim CAT_LA_ESTATUS_AUTORIZA As String = records(RESULT.Columns.Get("CAT_LA_ESTATUS_AUTORIZA"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("LIMITE"))
					If CAT_LA_ESTATUS_AUTORIZA  = 1 Then
						Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("LIMITE", "100000"))
					Else
						Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("LIMITE", Cat_Va_Valor))
					End If
				Next
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "carga_encuesta" Then 'query tag
				If logger Then Log("TIEMPO carga_encuesta : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim CAT_EP_ID  As String = records(RESULT.COLUMNS.GET("CAT_EP_ID"))
					Dim CAT_EP_IDTIPOPREGUNTA  As String = records(RESULT.COLUMNS.GET("CAT_EP_IDTIPOPREGUNTA"))
					Dim CAT_CE_DESCRIPCION  As String = records(RESULT.COLUMNS.GET("CAT_CE_DESCRIPCION"))
					Dim CAT_EP_PREGUNTA  As String = records(RESULT.COLUMNS.GET("CAT_EP_PREGUNTA"))
					Dim CAT_EP_RES1_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES1_PRED"))
					Dim CAT_EP_RES2_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES2_PRED"))
					Dim CAT_EP_RES3_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES3_PRED"))
					Dim CAT_EP_ORDEN_PREGUNTA As String = records(RESULT.COLUMNS.GET("CAT_EP_ORDEN_PREGUNTA"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_ENCUESTA_PREGUNTA (CAT_EP_ID ,CAT_EP_IDTIPOPREGUNTA ,CAT_CE_DESCRIPCION ,CAT_EP_PREGUNTA ,CAT_EP_RES1_PRED ,CAT_EP_RES2_PRED ,CAT_EP_RES3_PRED ,CAT_EP_ORDEN_PREGUNTA ) VALUES (?,?,?,?,?,?,?,?)", Array As Object (CAT_EP_ID ,CAT_EP_IDTIPOPREGUNTA ,CAT_CE_DESCRIPCION ,CAT_EP_PREGUNTA ,CAT_EP_RES1_PRED ,CAT_EP_RES2_PRED ,CAT_EP_RES3_PRED ,CAT_EP_ORDEN_PREGUNTA))
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "carga_encuesta_cliente" Then 'query tag
				If logger Then Log("TIEMPO carga_encuesta_cliente : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim HIST_ECD_IDGRUPO  As String = records(RESULT.COLUMNS.GET("HIST_ECD_IDGRUPO"))
					Dim HIST_ECD_CLIENTE  As String = records(RESULT.COLUMNS.GET("HIST_ECD_CLIENTE"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_ENCUESTA_CLIENTE(HIST_ECD_IDGRUPO ,HIST_ECD_CLIENTE) VALUES (?,?)", Array As Object (HIST_ECD_IDGRUPO ,HIST_ECD_CLIENTE))
				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
				If logger Then Log("TIEMPO valida_pedido : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim CUANTOSP As Int = records(RESULT.Columns.Get("CUANTOSP"))
					If cuantos_pedido < = CUANTOSP Then
						datos_iguales = "ok"
						S_CP.Text = "INFO OK"
					Else
						If Starter.marcaCel <> "LGE" 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_pedido1" 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
						Msgbox("ENVIO EXITOSO","AVISO") 'ignore
						cargar.Visible = True
						Subir.Visible = True
						trabajar.Visible = True
					Else
						Msgbox("NO ESTA COMPLETA LA INFO", "AVISO") 'ignore
						connecta.Visible = True
						Resumen.Visible = True
						BUSCA.Visible = True
						NUEVO.Visible = True
						trabajar.Visible = True
						B_PROXIMA.Visible = True
					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
						datos_iguales = "ok"
						S_CP.Text = "INFO OK"
					Else
						If Starter.marcaCel <> "LGE" 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
						datos_iguales = "ok"
						S_CP.Text = "INFO OK"
					Else
						If Starter.marcaCel <> "LGE" 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 = "LISTO"
			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
					Starter.skmt.ExecNonQuery("delete from VERSION")
					Dim CAT_VE_VERSION As String = records(RESULT.Columns.Get("CAT_VE_VERSION"))
					Starter.skmt.ExecNonQuery("delete from VERSION")
					Starter.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
				e_ruta.Enabled = True
'				Log(RESULT)
'				Log(RESULT.Columns.Get("VALIDO"))
				If RESULT.Columns.Get("VALIDO") = "0" Then ToastMessageShow("Ruta incorrecta", True)
				If RESULT.Rows.Size = 0 Then ToastMessageShow("No hay ruta para ese usuario", True)
				For Each records() As Object In RESULT.Rows
					Dim VALIDO As String = records(RESULT.Columns.Get("VALIDO"))
					Log("|"&VALIDO&"|")
'					If Logger Then Log(records(RESULT.Columns.Get("CAT_RU_CATEGORIA")))
					Starter.rutaTipo = records(RESULT.Columns.Get("CAT_RU_CATEGORIA")) 'Traemos el tipo de ruta para que cuando sean foraneas no carguen la carta oprte todos los dias.
					If VALIDO = "OK" Then
						cargar.Visible = True
						Subir.Visible = True
						inv.Visible = True
						connecta.Visible = False
						Starter.rutapreventa = e_ruta.text
						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
					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
			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
					Starter.FECHA_HOY = records(RESULT.Columns.Get("FECHA"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FECHA"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FECHA",Starter.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
				If logger Then Log("TIEMPO folio : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim FOLIO As String = records(RESULT.Columns.Get("FOLIO"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FOLIO"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FOLIO",FOLIO))
				Next
			End If
		End If

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

		'Marcas
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "marcas" Then 'query tag
				If logger Then Log("TIEMPO marcas : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim MARCAS As String = records(RESULT.Columns.Get("MARCAS"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("MARCAS"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MARCAS",MARCAS))
				Next
			End If
		End If

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

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

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "SEMANA" Then 'query tag
				If logger Then Log("TIEMPO SEMANA : " & ((DateTime.Now-inicioContador)/1000))
				For Each records() As Object In RESULT.Rows
					Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_VA_VALOR"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("SEMANA"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SEMANA",Cat_Va_Valor))
				Next
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "dia_visita" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim DIA_VISITA As String = records(RESULT.Columns.Get("DIA_VISITA"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("DIA_VISITA"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("DIA_VISITA",DIA_VISITA))
					'Msgbox(DIA_VISITA, "") 'ignore
				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"))
					Starter.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
		
		
		'Cambios
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "cat_cambios" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim CAMBIOS As String = records(RESULT.Columns.Get("CAT_VA_VALOR"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("CAMBIOS"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("CAMBIOS",CAMBIOS))
				Next
			End If
		End If

		'Precios
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "precios" Then 'query tag
				If logger Then Log("TIEMPO precios : " & ((DateTime.Now-inicioContador)/1000))
'				Subs.cronoX("Precios", 1)
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
					Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					Dim CAT_GP_PRECIO1 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO1"))
					Dim CAT_GP_PRECIO2 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO2"))
					Dim CAT_GP_PRECIO3 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO3"))
					Dim CAT_GP_PRECIO4 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO4"))
					Dim CAT_GP_PRECIO5 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO5"))
					Dim CAT_GP_PRECIO6 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO6"))
					Dim CAT_GP_PRECIO7 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO7"))
					Dim CAT_GP_PRECIO8 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO8"))
					Dim CAT_GP_PRECIO9 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO10"))
					Dim CAT_GP_PRECIO10 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO10")) 'ignore
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_PRECIOS(CAT_GP_ID,CAT_GP_PRECIO, 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) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_PRECIO, 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))
				Next
				Starter.skmt.ExecNonQuery("delete from LISTA_PRECIOS")
				Starter.skmt.ExecNonQuery(" insert into LISTA_PRECIOS(PRECIO, CAT_GP_ID, NLISTA)  select cat_gp_precio as precio, cat_gp_id, '1' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO1 As precio, CAT_GP_ID, '2' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO2 As precio, CAT_GP_ID, '3' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO3 As precio, CAT_GP_ID, '4' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO4 As precio, CAT_GP_ID, '5' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO5 As precio, CAT_GP_ID, '6' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO6 As precio, CAT_GP_ID, '7' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO7 As precio, CAT_GP_ID, '8' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO8 As precio, CAT_GP_ID, '9' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO9 As precio, CAT_GP_ID, '10' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO10 As precio, CAT_GP_ID, '11' as NLISTA from CAT_PRECIOS")
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
'				If Logger Then LogColor($"///////////////// ${Subs.cronoX("Precios", 2)} ///////////////////////////"$, Colors.red)
				'	ToastMessageShow("LISTA DE PRECIOS OK LISTA DE PRECIOS OK", True)
			End If
		End If
	
		'Candado Fin Dia
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "pass_fin_dia" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim nuevaContrasena As String = records(RESULT.Columns.Get("CAR_VA_VALOR3"))
					Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FINDIA_PASS"))
					Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FINDIA_PASS", nuevaContrasena))
				Next
			End If
		End If
		
		'Exhibidores
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "exhibidores" Then 'query tag
				If logger Then Log("TIEMPO exhibidores : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim HIST_EX_ID_CLIENTE As String = records(RESULT.Columns.Get("HIST_EX_ID_CLIENTE"))
					Dim HIST_EX_TIPO As String = records(RESULT.Columns.Get("HIST_EX_TIPO"))
					Dim HIST_EX_CANT As String = records(RESULT.Columns.Get("HIST_EX_CANT")) 'ignore
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_EXHIBIDORES2(HIST_EX_ID_CLIENTE,HIST_EX_TIPO, HIST_EX_CANT) VALUES (?,?,?)", Array As Object (HIST_EX_ID_CLIENTE,HIST_EX_TIPO, HIST_EX_CANT))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
			End If
		End If
		
		'HIST_ENCUESTA2
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "HIST_ENCUESTA2" Then 'query tag
				If logger Then Log("TIEMPO HIST_ENCUESTA2 : " & ((DateTime.Now-inicioContador)/1000))
				Starter.skmt.BeginTransaction
				For Each records() As Object In RESULT.Rows
					Dim HE_CLIENTE As String = records(RESULT.Columns.Get("HE_CLIENTE"))
					Starter.skmt.ExecNonQuery2("INSERT INTO HIST_ENCUESTA2(HE_CLIENTE) VALUES (?)", Array As Object (HE_CLIENTE))
				Next
				Starter.skmt.TransactionSuccessful
				Starter.skmt.EndTransaction
			End If
		End If
	End If
	Job.Release
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
	' BACK key pressed
	'Return True to close, False to cancel
	If pdfViewerActivo Then
		pdfViewerActivo = False
		PNL_ACCESO.Visible = True
		Panel7.Visible = True
		PNL_ACCESO.BringToFront
		p_pdfViewer.Visible = False
	Else if P_RESUMEN.Visible Then
		B_OK_RES_Click
	Else
		Subs.iniciaActividad("Login")
	End If
	Return False
End Sub

Sub Activity_KeyPress (key As Int) As Boolean
'	' BACK key pressed
'	If key=KeyCodes.KEYCODE_BACK Then
'		If pdfViewerActivo Then
'			pdfViewerActivo = False
'			PNL_ACCESO.Visible = True
'			Panel7.Visible = True
'			PNL_ACCESO.BringToFront
'			p_pdfViewer.Visible = False
'		Else if P_RESUMEN.Visible Then
'			B_OK_RES_Click
'		Else
'			Subs.iniciaActividad("Main")
'		End If
'		' I want to capture the key here so I return True
'		Return True
'	End If
'	' Returning False signals the system to handle the key
'	Return False
End Sub

Sub connecta_Click
'	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("RUTA"))
'	c.Position =0
'	If c.GetString("CAT_VA_VALOR") = l_ruta.Text Then
	If e_ruta.Text = "KMTSKLL1" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If
'	Aqui el codigo para que solo acepte numeros en la ruta, sin caracteres especiales  ' Mod por CHV - 211130
	Dim m As Matcher = Regex.Matcher("\d+", e_ruta.Text) 'Buscamos numeros en el campo de la ruta
	If m.Find Then e_ruta.Text = m.Match  ' Si tiene numeros, solo nos quedamos con ellos.
	If e_ruta.Text.Length > 6 Then e_ruta.Text = e_ruta.Text.SubString2(0,6) ' Si tiene mas de 6 numeros solo tomamos los primeros 6
	If logger Then Log(e_ruta.Text)
	c=Starter.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
	connecta1 = connecta1 + 1
'	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
'	Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
'	If Result Then
'		imei = p.GetDeviceId
'	End If
	imei = ""
	conn = "1"
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_version_KELL"
	reqManager.ExecuteQuery(cmd , 0, "version")
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_ruta3_KELL"
	cmd.Parameters = Array As Object(ALMACEN, e_ruta.text, usuario)
	reqManager.ExecuteQuery(cmd , 0, "ruta")
	e_ruta.Enabled = False
	If e_ruta.Text = "KMTSKLL1" Then 	e_ruta.Enabled = True
	ToastMessageShow("Validando Conexión." , False)
	ruta_valida = e_ruta.Text
'	Else
'		Msgbox("LA RUTA NO ES CORRECTA","") 'ignore
'	End If
End Sub

Sub BUSCA_Click
	Subs.iniciaActividad("TicketsDia")
End Sub

Sub b_mapa_Click
	Subs.iniciaActividad("mapas")
End Sub

Sub e_ruta_EnterPressed
	Private adelanteFinDia As Boolean = True
	c=Starter.skmt.ExecQuery("select CAT_VA_VALOR from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'FINDIA_FECHA'") 'Buscamos "FIN DIA" anterior
	If c.RowCount > 0 Then
		c.Position = 0
		If Not(c.GetString("CAT_VA_VALOR") < Starter.FECHA_HOY) Then 'Si el "FIN DIA" guardado NO es de ayer o anterior ...
			adelanteFinDia = False
		End If
		c.Close
	End If
'	If e_ruta.Text = "VALIDA" Then
'		c=Starter.skmt.ExecQuery("SELECT  PC_CLIENTE, PC_ENTREGA FROM PEDIDOS_DOE_ENTREGA")
'		Msgbox("PASA","1")
'		If c.RowCount>0 Then
'			Msgbox("PASA 2","1")
'			For i=0 To c.RowCount -1
'				c.Position=i
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "UPDATE_PEDIDOS_DOE_ENTREGA"
'				cmd.Parameters = Array As Object(C.GetString("PC_CLIENTE"),C.GetString("PC_ENTREGA"), ALMACEN, l_ruta.Text)
'				Log("ALO " & C.GetString("PC_CLIENTE")& "|" & C.GetString("PC_ENTREGA") & "|" &  ALMACEN & "|" &  l_ruta.Text )
'				
'				reqManager.ExecuteCommand(cmd , "INSERT_PEDIDOS_DOE_ENTREGA")
'				PB2.Progress = PB2.Progress + 1
'				contador_env = contador_env + 1
'			Next
'			c.Close
'		End If
'	End If
	
	If e_ruta.Text = "FIN DIA" And adelanteFinDia 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 pedido_cliente")
			Starter.skmt.ExecNonQuery("delete from pedido")
			Starter.skmt.ExecNonQuery("delete from noventa")
			Starter.skmt.ExecNonQuery("delete from clie_act")
			Starter.skmt.ExecNonQuery("delete from kmt_info")
			Starter.skmt.ExecNonQuery("delete from cat_gunaprod")
			Starter.skmt.ExecNonQuery("delete from cat_gunaprod2")
			Starter.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
			Starter.skmt.ExecNonQuery("delete from HIST_VENTAS")
			Starter.skmt.ExecNonQuery("delete from HIST_VERIFICACION")
			Starter.skmt.ExecNonQuery("delete from TMP_INSPECCION_AUTO_DIARIA")
			Starter.skmt.ExecNonQuery("delete from CAT_FOTOS")
			Starter.skmt.ExecNonQuery("delete from HIST_GPS")
			Starter.skmt.ExecNonQuery("DELETE FROM HIST_ENCUESTA")
			Starter.skmt.ExecNonQuery("DELETE FROM HIST_ENVIOS")
			Starter.skmt.ExecNonQuery("DELETE FROM CLIENTE_IMPRESO")
			Starter.skmt.ExecNonQuery("delete from CAT_PROMO_MONTO")
			Starter.skmt.ExecNonQuery("delete from TMP_CAT_BILLETE")
			Starter.skmt.ExecNonQuery("delete from TMP_CAT_MONEDAS")
			Starter.skmt.ExecNonQuery("delete from CAT_RMI")
			Starter.skmt.ExecNonQuery("delete from CAT_DEV")

			Starter.skmt.ExecNonQuery2("INSERT INTO HIST_ENVIOS VALUES (?,0,?)", Array As Object(sTime, "PEDIDO"))
			Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
			Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",0))
			Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FINDIA_FECHA"))
			Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES (CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object("FINDIA_FECHA", Starter.FECHA_HOY))
			If File.Exists(File.DirInternal,"FOTO1.jpg") Then File.Delete(File.DirInternal,"FOTO1.jpg")
			If File.Exists(File.DirInternal,"FOTO2.jpg") Then File.Delete(File.DirInternal,"FOTO2.jpg")
			If File.Exists(File.DirInternal,"FOTO3.jpg") Then File.Delete(File.DirInternal,"FOTO3.jpg")
			If File.Exists(File.DirInternal,"FOTO4.jpg") Then File.Delete(File.DirInternal,"FOTO4.jpg")
			B4XPage_Appear
		End If
	Else if e_ruta.Text = "FIN DIA" Then
		Msgbox("Ya se hizo FIN DIA hoy, solo se puede hacer un FIN DIA cada día, por favor comuniquese con un supervisor.", "LIMITE DIARIO SUPERADO") 'ignore
	End If
	If e_ruta.Text = "SUPLENCIA" Then
		E_RUTA2.Visible = True
		E_RUTA2.Text = ""
		L_SUPLENCIA.Visible = True
		Label4.Visible = True
		'	ImageView9.Visible = True
	End If
End Sub

Sub inv_Click
	img2.Visible =True
	EJECUTANDO = 1
	inve = 1
	Starter.skmt.ExecNonQuery("delete from cat_gunaprod")
	Starter.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
	c=Starter.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_KELL"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_KELL"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_KELL"
	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_KELL"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedido")
	
	t3.Initialize("T3", 5000) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
'	
'	cmd.Initialize
'	cmd.Name = "select_cuantos_noventa_KELL"
'	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
'	reqManager.ExecuteQuery(cmd , 0, "valida_noventa")
'	
'	cmd.Initialize
'	cmd.Name = "select_cuantos_pedidoc_KELL"
'	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
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
		PERFIL = "0"
		If c.RowCount > 0 Then
			c.Position =0
			PERFIL = c.GetString("CAT_VA_VALOR")
		End If
		c.Close
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
		NUMERO_PEDIDO = "0"
		If c.RowCount > 0 Then
			c.Position =0
			NUMERO_PEDIDO = c.GetString("CAT_VA_VALOR")
		End If
		c.Close
		If PERFIL = "V-ESPECIAL" Then
			Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
			Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",NUMERO_PEDIDO + 1))
		End If
		P1.Visible = False
		trabajar.Visible = True
		B_PROXIMA.Visible =True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		P1.SendToBack
	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
		trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		P1.SendToBack
	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
			B_PROXIMA.Visible =True
			NUEVO.Visible =True
			BUSCA.Visible=True
			connecta.Visible=True
			Resumen.Visible= True
			img2.Visible=False
'			ExitApplication
			P1.SendToBack
		End If
	End If
	
	If CARGA = "CARGAR" And S_CP.Text = "LISTO" And S_CC.Text = "LISTO" And S_CH.Text = "LISTO" Then
		c=Starter.skmt.ExecQUERY("SELECT COUNT(*) AS CUANTOS FROM PEDIDO_DOE WHERE PE_CLIENTE <> 0")
		c.Position = 0
		cuantos_pedidosc = c.GetString("CUANTOS")
		c.Close
		If cuantos_pedidosc > 0 Then
			c=Starter.skmt.ExecQUERY("SELECT PE_PROID, SUM(PE_CANT) AS PE_CANT FROM PEDIDO_DOE WHERE PE_CLIENTE <> 0 GROUP BY PE_PROID")
			If c.RowCount>0 Then
				For i=0 To c.RowCount -1
					c.Position=i
					Starter.skmt.ExecNonQuery2("update CAT_GUNAPROD2 set CAT_GP_ALMACEN = CAT_GP_ALMACEN - ? where CAT_GP_ID = ? ", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
				Next
			End If
		End If
		c=Starter.skmt.ExecQuery("select COUNT(DISTINCT(PE_CLIENTE)) AS CLIENTES from PEDIDO_DOE ")
		c.Position = 0
		If c.GetString("CLIENTES") >0 Then Msgbox("AVISO TIENES "& c.GetString("CLIENTES") & " PEDIDOS DON TOÑO PARA ENTREGAR"," PEDIDOS DON TOÑO")
		c.Close		
		P1.Visible = False
		trabajar.Visible = True
		B_PROXIMA.Visible =True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		P1.SendToBack
	ELSE IF CARGA = "CARGAR" Then
		S_CP.Text = "LISTO" 
		S_CC.Text = "LISTO" 
		S_CH.Text = "LISTO"
		
	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
			trabajar.Visible = True
			B_PROXIMA.Visible =True
			NUEVO.Visible =True
			BUSCA.Visible=True
			connecta.Visible=True
			Resumen.Visible= True
			img2.Visible=False
			Starter.skmt.ExecNonQuery("delete from kmt_info")
			If logger Then Log("Borramos KMT_INFO")
			Starter.skmt.ExecNonQuery("delete from cod_result")
			Starter.skmt.ExecNonQuery("delete from hist_gest")
			Starter.skmt.ExecNonQuery("delete from cat_gunaprod")
			Starter.skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
			Starter.skmt.ExecNonQuery("delete from telefonos")
			Starter.skmt.ExecNonQuery("delete from HIST_VENTAS")
			Starter.skmt.ExecNonQuery("delete from HIST_PROMOS")
			Starter.skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
			Starter.skmt.ExecNonQuery("delete from PROMOS_COMP")
			Starter.skmt.ExecNonQuery("delete from CAT_VERIFICACION")
			Starter.skmt.ExecNonQuery("delete from HIST_CUOTAS")
			P1.SendToBack
			ExitApplication
		End If
	End If
'	P1.SendToBack 'Mod por CHV - 211213 - Se movio el sendToBack a los diferentes if/then porque no en todos los casos hay que ocultar el panel (Por ejemplo cuando se selecciona "No Abortar")
End Sub

Sub NUEVO_Click
	If l_ruta.Text = 0 Then
		Msgbox("No se ha cargado ruta","Alerta") 'ignore
	Else
		 
		c=Starter.skmt.ExecQuery2("select count(*) AS COUNT from kmt_info where CAT_CL_CODIGO like ?", Array As String ("N%"))
		c.Position = 0
		If c.GetString("COUNT") > 2000 Then 
			MsgboxAsync("YA NO SE PUEDEN CREAR MAS CLIENTES","AVISO")
		Else
			Subs.iniciaActividad("nuevocliente")
				
		End If
		
		
	End If
End Sub

Sub B_OK_RES_Click
	trabajar.Visible = True
	B_PROXIMA.Visible =True
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
End Sub

Sub Resumen_Click
	P_RESUMEN.Visible = True
	P_RESUMEN.BringToFront
	trabajar.Visible = False
	B_PROXIMA.Visible =False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False
	DateTime.DateFormat = "MM/dd/yyyy"
	fecha=DateTime.Date(DateTime.Now)
	Starter.skmt.ExecNonQuery2("update PEDIDO set PE_TIPO = ? where  PE_CLIENTE =?", Array As Object("ABORDO", "0"))
	b=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente where pc_cliente <> 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
'	ToastMessageShow(Cuantos , True)
	d=Starter.skmt.ExecQuery2("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0 and  cat_cl_codigo <> 0 AND CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?)", Array As String("DIA_VISITA"))
	D.Position=0
	b.Close
	e=Starter.skmt.ExecQuery2("select count(*) as POR_VISITAR from kmt_info where cat_cl_codigo <> 0 and CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?) ", Array As String("DIA_VISITA"))
	e.Position=0
	f=Starter.skmt.ExecQuery("select count(*) as CAT_CL_RUTA from kmt_info where cat_cl_codigo <> 0")
	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=Starter.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")
		d.Close
		e.Close
		l_monto_kp.Text = "0"
		l_monto_k.Text = "0"
		l_monto_ks.Text = "0"
	Else
		' aqui poner lo de efectividad de doe y la cantidad de doe para enviar a tiempo real
		Dim TOTAL_DOE_BB As String
		Dim TOTAL_EFE_DOE As String
		Dim TOTAL_ENTREGA_DOE As String
	
		
		C_DOE = Starter.skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM PEDIDO_DOE")
		C_DOE.Position = 0
		If C_DOE.GetString("CUANTOS") > 0 Then
		F_DOE = Starter.skmt.ExecQuery("SELECT SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO_DOE")
		F_DOE.Position = 0
			TOTAL_DOE_BB = F_DOE.GetString("TOTAL")
		F_DOE.Close
		D_DOE=Starter.skmt.ExecQuery2("select  sum(PE_COSTO_TOT) as DOE from pedido where PE_CEDIS  = ? ", Array As String("PROMODOE"))
		D_DOE.Position = 0
			TOTAL_ENTREGA_DOE = D_DOE.GetString("DOE")
		D_DOE.Close
		
		
		End If
		
		'' fin de esto modificar lo anterior
		c=Starter.skmt.ExecQuery2("select  sum(pe_cant) as CAMBIOS from pedido where substr(pe_pronombre,1,6) = ?", Array As String("CAMBIO"))
		c.Position = 0
		l_cambios.Text = c.GetString("CAMBIOS")
		c.Close
		c=Starter.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_gunaprod2 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=Starter.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_gunaprod2 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=Starter.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_gunaprod2 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
		DDD=Starter.skmt.ExecQuery("Select  COUNT(*) AS CUANTOS from HIST_CUOTAS ")
		DDD.Position = 0
		If DDD.GetString("CUANTOS") > 0 Then
			c=Starter.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 = 2000
			l_monto_c2.Text = 2000
			l_monto_c3.Text = 2000
		End If
		DDD.Close
		c=Starter.skmt.ExecQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente where pc_cliente <> 0")
		b=Starter.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")
		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")
		L_CUANTOST.Text = l_cuantosc.Text + l_cuantosn.Text
		
		drop = (c.GetString("CLIENTES_DIA") + b.GetString("CUANTOS"))/ Starter.clientesTotal 'd.GetString("TOTAL_VISITAR")
		
		l_drop.Text = Round(drop * 100)
		If l_drop.Text  + l_efectiva.Text < 100 Then
			ImageView3.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
		Else If l_drop.Text  + l_efectiva.Text > =  100  And l_drop.Text  + l_efectiva.Text < 130 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") < 2500 Then
			ImageView5.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
		Else if c.GetString("MONTO_DIA") > =  2500  And c.GetString("MONTO_DIA") < 4000 Then
			ImageView5.bitmap = LoadBitmap(File.DirAssets, "alerta_amarilla.png")
		Else
			ImageView5.Bitmap = LoadBitmap(File.DirAssets, "palomita_verde.png")
		End If
		c.Close
		b.Close
	End If
	b=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido where pe_cliente = 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	If Cuantos > 0 Then
		c=Starter.skmt.ExecQuery("Select sum(PE_COSTO_TOT) AS TOTAL from pedido where pe_cliente = 0")
		c.Position = 0
		L_ABORDO.Text = c.GetString("TOTAL")
		c.Close
	End If
End Sub

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

Sub Printer_Connected (Success As Boolean)
	If Success Then
		B_IMP.Enabled = True
		PASA_IMP = "1"
	Else
		B_IMP.Enabled = False
		If Msgbox2("", "Printer Error","Reprint","Cancel","",Null) = DialogResponse.POSITIVE Then 'ignore
			StartPrinter
		End If
	End If
End Sub

Sub StartPrinter
	Dim PairedDevices As Map
	Dim L As List
	Dim resimp As Int
	ToastMessageShow("Printing.....",True)
	PairedDevices.Initialize
	Try
		PairedDevices = cmp20.GetPairedDevices
	Catch
		Msgbox("Getting Paired Devices","Printer Error") 'ignore
		printer.Close
		cmp20.Disconnect
	End Try
	If PairedDevices.Size = 0 Then
		Msgbox("Error Connecting to Printer - Printer Not Found","") 'ignore
		Return
	End If
	If PairedDevices.Size = 1 Then
		Try
			cmp20.ConnectInsecure(Starter.btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
		Catch
			Msgbox("Connecting","Printer Error") 'ignore
			printer.Close
			cmp20.Disconnect
		End Try
	Else
		L.Initialize
		For i = 0 To PairedDevices.Size - 1
			L.Add(PairedDevices.GetKeyAt(i))
		Next
		resimp = InputList(L, "Choose device", -1)  'ignore
		If resimp <> DialogResponse.CANCEL Then
			cmp20.Connect(PairedDevices.Get(L.Get(resimp)))
		End If
	End If
End Sub

' BOLETA
Sub B_BOLETA_Click
	GetResult
End Sub

Sub GetResult
	Starter.boleta = 1
	B4XPages.MainPage.cliente.muestraBoleta = True
	B4XPages.MainPage.cliente.LLAMA_BOLETA
	Subs.iniciaActividad("cliente")
'	CallSubDelayed(B4XPages.GetPage("Cliente"), "LLAMA_BOLETA")
End Sub

Sub B_MAPA_RUTA_Click
	Subs.iniciaActividad2("MAPA_RUTAS")
End Sub

Sub b_cuotas_Click
	DDD=Starter.skmt.ExecQuery("Select  COUNT(*) AS CUANTOS from HIST_CUOTAS ")
	DDD.Position = 0
	If DDD.GetString("CUANTOS") > 0 Then
		c=Starter.skmt.ExecQuery("Select  HC_CUOTA1,HC_CUOTA2,HC_CUOTA3,HC_CUOTA4,HC_CUOTA5,HC_CUOTA6,HC_META1,HC_META2,HC_META3,HC_META4,HC_META5,HC_META6 from HIST_CUOTAS ")
		c.Position= 0
		L_CUOTA1.TEXT = c.GetString("HC_CUOTA1")
		L_CUOTA2.TEXT = c.GetString("HC_CUOTA2")
		L_CUOTA3.TEXT = c.GetString("HC_CUOTA3")
		L_CUOTA4.TEXT = c.GetString("HC_CUOTA4")
		L_CUOTA5.TEXT = c.GetString("HC_CUOTA5")
		L_CUOTA6.TEXT = c.GetString("HC_CUOTA6")
		L_META1.Text = c.GetString("HC_META1")
		L_META2.Text = c.GetString("HC_META2")
		L_META3.Text = c.GetString("HC_META3")
		L_META4.Text = c.GetString("HC_META4")
		L_META5.Text = c.GetString("HC_META5")
		L_META6.Text = c.GetString("HC_META6")
		If L_MONTOD.Text > 0 Then
			L_META1.Text= $"$1.2{(l_monto_k.Text + L_META1.Text)}"$ 'l_monto_k.Text + L_META1.Text
			L_META2.Text= $"$1.2{(l_monto_kp.Text + L_META2.Text)}"$
			L_META3.Text= $"$1.2{(l_monto_ks.Text + L_META3.Text)}"$ 'l_monto_ks.Text + L_META3.Text
			L_META4.Text= $"$1.2{(l_monto_k.Text + L_META4.Text)}"$   '  l_monto_k.Text + L_META4.Text
			L_META5.Text= $"$1.2{(l_monto_kp.Text + L_META5.Text)}"$ 'l_monto_kp.Text + L_META5.Text
			L_META6.Text= $"$1.2{(l_monto_ks.Text + L_META6.Text)}"$ 'l_monto_ks.Text + L_META6.Text
		End If
	Else
		L_CUOTA1.TEXT = 0
		L_CUOTA2.TEXT = 0
		L_CUOTA3.TEXT = 0
		L_CUOTA4.TEXT = 0
		L_CUOTA5.TEXT = 0
		L_CUOTA6.TEXT = 0
		L_META1.Text = 0
		L_META2.Text = 0
		L_META3.Text = 0
		L_META4.Text = 0
		L_META5.Text = 0
		L_META6.Text = 0
	End If
	DDD.Close
	Panel5.BringToFront
	Panel5.Visible = True
	Panel2.Visible = False
	Panel1.Visible = False
End Sub

Sub B_CUOATA_C_Click
	Panel5.Visible = False
	Panel2.Visible = True
	Panel1.Visible = True
End Sub

Sub Btn_CheckList_Click
	If logger Then Log("Cambiamos a CHECKLIST_AUTO")
	B4XPages.ShowPage("CheckList")
'	Activity.Finish
End Sub

Sub Btn_CheckList_LongClick
'	Dim x As Int = "a"
'	StartActivity(errorManager)
End Sub

Sub SUBIR_INFO_PEDIDO
	P1.Width = GetDeviceLayoutValues.Width
	P1.Height = GetDeviceLayoutValues.Height
	Subs.panelVisible(P1, 0,  0)
	c=Starter.skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
	c.Position =0
	PERFIL = c.GetString("CUANTOS")
	c.Close
	If PERFIL > 0 Then
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
		c.Position =0
		PERFIL = c.GetString("CAT_VA_VALOR")
		c.Close
	End If
	c=Starter.skmt.ExecQuery2("select  count(*) AS CUANTOS  from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
	c.Position =0
	Cuantos =  c.GetString("CUANTOS")
	c.Close
	If Cuantos > 0 Then
		c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
		c.Position =0
		NUMERO_PEDIDO = c.GetString("CAT_VA_VALOR")
		c.Close
	End If
	Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE not In (select PE_CLIENTE from pedido)")
	c=Starter.skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
	' DROP
	b=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido where pe_cliente = 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	If Cuantos > 0 Then
		c=Starter.skmt.ExecQuery("Select sum(PE_COSTO_TOT) AS TOTAL from pedido where pe_cliente = 0")
		c.Position = 0
		L_ABORDO.Text = c.GetDouble("TOTAL")
		c.Close
	End If
	Dim PEDIDO_TOT As String
	b=Starter.skmt.ExecQuery("Select count(*) as CUANTOS from pedido where pe_cliente <> 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	If Cuantos > 0 Then
		c=Starter.skmt.ExecQuery("Select sum(PE_COSTO_TOT) AS TOTAL from pedido where pe_cliente <> 0")
		c.Position = 0
		PEDIDO_TOT = c.GetDouble("TOTAL")
		c.Close
	End If
	d=Starter.skmt.ExecQuery("SELECT SUM(PE_COSTO_TOT) as MONTO FROM PEDIDO")
	d.Position = 0
	Private monto1 As String = d.GetString("MONTO")
	Private abordo1 As String = L_ABORDO.Text
	If abordo1 = "" Then abordo1 = "0"
	monto1 = monto1 - abordo1
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name ="insert_drop2_KELL"
	cmd.Parameters = Array As Object(usuario, l_ruta.Text, fecha, l_porvisitar.Text, l_drop.Text, l_efectiva.Text, l_cuantosc.Text, l_cuantosn.Text, monto1, "ENVIO", ALMACEN, abordo1)
	reqManager.ExecuteCommand(cmd , "inst_noventa_ins_drop_kell")
	img2.Visible =True
	contador_env = contador_env + 1
	S_CP.Text = "Envio Cabecera"
	PB2.Progress = 100
	t3.Initialize("T3", 500) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name ="UPDATE_INFO_E_KELL"
	cmd.Parameters = Array As Object(PEDIDO_TOT, L_ABORDO.Text, d.GetDouble("MONTO"),l_ruta.TEXT, ALMACEN)
	reqManager.ExecuteCommand(cmd , "inst_noventa_Upd_Info_e_Kell")
	contador_env = contador_env + 1

'	ENCUESTA
	c=Starter.skmt.ExecQuery("SELECT  HE_CLIE, HE_RES, HE_FECHA, HE_TIPO FROM HIST_ENCUESTA")
	S_CP.Text = "Envio Encuesta"
	PB2.Progress = 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_encuesta_KELL"
			cmd.Parameters = Array As Object(C.GetString("HE_CLIE"),C.GetString("HE_RES"),C.GetString("HE_FECHA"), c.GetString("HE_TIPO"),l_ruta.Text )
			If logger Then Log($"${C.GetString("HE_CLIE")},${C.GetString("HE_RES")},${C.GetString("HE_FECHA")}, ${c.GetString("HE_TIPO")},${l_ruta.Text}"$)
			reqManager.ExecuteCommand(cmd , "inst_noventa_ins_enc_kell_"&i)
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
		PB2.Progress = 100
	End If
	c.Close
	c=Starter.skmt.ExecQuery("Select HF_FOTO, HF_CUENTA, HF_IDENCUESTA from HIST_FOTOS")
	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_foto_KELLS"
			cmd.Parameters = Array As Object(C.GetBLOB("HF_FOTO"),C.GetString("HF_CUENTA"),C.GetString("HF_IDENCUESTA"),l_ruta.Text, ALMACEN, usuario )
			reqManager.ExecuteCommand(cmd , "inst_noventa_ins_enc_foto_kell")
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
	End If
	c.Close
	t3.Initialize("T3", 500) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
	'clientes nuevos
	c=Starter.skmt.ExecQuery2("SELECT CAT_CL_CODIGO, CAT_CL_NOMBRE  FROM kmt_info where CAT_CL_ATIENDE1 = ?", Array As String("new"))
	S_CP.Text = "Envio C/Nuevos"
	PB2.Progress = 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_clie_new_KELL"
			cmd.Parameters = Array As Object(C.GetString("CAT_CL_CODIGO"),C.GetString("CAT_CL_NOMBRE"),l_ruta.Text,ALMACEN )
			reqManager.ExecuteCommand(cmd , "inst_noventa_ins_clie_new_kell")
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
	End If
	c.Close
	t3.Initialize("T3", 500) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
	S_CP.Text = "Envio C/Pedidos"
	PB2.Progress = 1
	' PEDIO_CLIENTE
	c=Starter.skmt.ExecQuery("SELECT PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT, PC_COSTO_SIN, PC_RUTA, PC_ALMACEN FROM PEDIDO_CLIENTE ")
	d=Starter.skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDOSC FROM PEDIDO_CLIENTE ")
	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_KELL"
			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,l_ruta.text,C.GetString("PC_COSTO_SIN") )
			reqManager.ExecuteCommand(cmd , "ins_pedidos")
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
		c.Close
	End If
	d.Position=0
	cuantos_pedidosc = D.GetString("CUANTOS_PEDIDOSC")
	PB2.Progress = 100
	d.Close
	ENVIADA = 0
	PORENVIAR = 0
'	Msgbox(ENVIADA & " " & PORENVIAR, "A") 'ignore
	c=Starter.skmt.ExecQuery2("SELECT COUNT(*) as CANTIDAD   FROM HIST_ENVIOS WHERE HE_TIPO = ?",Array As String("ABORDO") )
	c.Position = 0
	If c.GetString("CANTIDAD") > 0 Then
		Log($"pe_cedis_0"$)
		Starter.skmt.ExecNonQuery2("update PEDIDO set PE_CEDIS = ? where  PE_CLIENTE =? AND PE_FOLIO IS NULL ", Array As Object("RECARGA", "0"))
	End If
	Starter.skmt.ExecNonQuery("UPDATE PEDIDO SET PE_FOLIO = rowid where PE_FOLIO = 0 or PE_FOLIO = 1")
	If PERFIL = "V-ESPECIAL" Then
		Log($"pe_cedis_1"$)
		c=Starter.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_TIPO FROM PEDIDO ORDER BY PE_CLIENTE")
		d=Starter.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_pedido_esp_KELL"
				Log($"pe_cedis_2"$)
				cmd.Parameters = Array As Object(c.GetString("PE_CEDIS"),ALMACEN,C.GetString("PE_COSTO_TOT"),C.GetString("PE_COSTOU"),C.GetString("PE_CANT"),C.GetString("PE_PRONOMBRE"),C.GetString("PE_PROID"),C.GetString("PE_CLIENTE"),C.GetString("PE_FECHA"),C.GetString("PE_USUARIO"),C.GetString("PE_RUTA"), C.GetString("PE_COSTO_SIN"),C.GetString("PE_DESC"),c.GetString("PE_FOLIO"), c.GetString("PE_TIPO"),NUMERO_PEDIDO )
				reqManager.ExecuteCommand(cmd , "ins_pedido")
				contador_env = contador_env + 1
			Next
			c.Close
		End If
	Else
		Log($"pe_cedis_3"$)
		c=Starter.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_TIPO FROM PEDIDO")
		d=Starter.skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
		TIEMPO = 0
		t3.Initialize("T3", 500) ' 1000 = 1 second
		t3.Enabled = True
		Wait For  t3_tick
		S_CP.Text = "Envio de Pedidos"
		PB2.Progress = 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_pedido_KELL"
				If logger Then Log($"pe_cedis_4"$)
				cmd.Parameters = Array As Object(c.GetString("PE_CEDIS"),ALMACEN,C.GetString("PE_COSTO_TOT"),C.GetString("PE_COSTOU"),C.GetString("PE_CANT"),C.GetString("PE_PRONOMBRE"),C.GetString("PE_PROID"),C.GetString("PE_CLIENTE"),C.GetString("PE_FECHA"),C.GetString("PE_USUARIO"),C.GetString("PE_RUTA"), C.GetString("PE_COSTO_SIN"),C.GetString("PE_DESC"),c.GetString("PE_FOLIO"), c.GetString("PE_TIPO"))
				reqManager.ExecuteCommand(cmd , "ins_pedido")
				contador_env = contador_env + 1
				TIEMPO =  TIEMPO + 1
				PB2.Progress = PB2.Progress + 1
				If TIEMPO  > 20 Then
					'	Msgbox("M","A") 'ignore
					If L_P_2.Text = "Envio de Pedidos" Then
						L_P_2.Text = "Envio de Pedidos --"
					else if  L_P_2.Text = "Envio de Pedidos --" Then
						L_P_2.Text = "Envio de Pedidos \"
					else if L_P_2.Text = "Envio de Pedidos \" Then
						L_P_2.Text = "Envio de Pedidos |"
					else if L_P_2.Text = "Envio de Pedidos |" Then
						L_P_2.Text = "Envio de Pedidos /"
					else if L_P_2.Text = "Envio de Pedidos /" Then
						L_P_2.Text = "Envio de Pedidos --"
					End If
					t3.Initialize("T3", 2000) ' 1000 = 1 second
					t3.Enabled = True
					Wait For  t3_tick
					TIEMPO = 0
				End If
			Next
			c.Close
		End If
	End If
	d.Position=0
	cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
	PB2.Progress = 100
	d.Close
	
	' NOVENTA
	c=Starter.skmt.ExecQuery("SELECT  NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON FROM NOVENTA")
	D=Starter.skmt.ExecQuery("SELECT  COUNT(*) AS CUANTOS_NOVENTA FROM NOVENTA")
	t3.Initialize("T3", 500) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
	S_CP.Text = "Envio No Venta"
	PB2.Progress = 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_noventa_KELL"
			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, l_ruta.Text)
			reqManager.ExecuteCommand(cmd , "inst_noventa_ins_noventa_kell")
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
		c.Close
	End If
	d.Position=0
	cuantos_noventa = D.GetString("CUANTOS_NOVENTA")
	PB2.Progress = 100
	d.Close
	
	' ENTREGA DOE PEDIDOS_DOE_ENTREGA (PC_CLIENTE, PC_ENTREGA)
	c=Starter.skmt.ExecQuery("SELECT  PC_CLIENTE, PC_ENTREGA FROM PEDIDOS_DOE_ENTREGA")
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Dim cmd As DBCommand
			cmd.Initialize
			cmd.Name = "UPDATE_PEDIDOS_DOE_ENTREGA"
			cmd.Parameters = Array As Object(C.GetString("PC_CLIENTE"),C.GetString("PC_ENTREGA"), ALMACEN, l_ruta.Text)
			reqManager.ExecuteCommand(cmd , "UPDATE_PEDIDOS_DOE_ENTREGA")
			PB2.Progress = PB2.Progress + 1
			contador_env = contador_env + 1
		Next
		c.Close
	End If
	
	' CHECK LIST VALIDAR
	'Msgbox("antesde de mandar","") 'ignore
	c=Starter.skmt.ExecQuery("SELECT  " & Chr(34) & "TMP_AUTO_RUTA " & Chr(34) & " as TMP_AUTO_RUTA," & Chr(34) & "TMP_AUTO_PLACA" & Chr(34) & " as TMP_AUTO_PLACA," & Chr(34) & "TMP_AUTO_CEDIS " & Chr(34) & " as TMP_AUTO_CEDIS," & Chr(34) & "TMP_AUTO_IDALMACEN" & Chr(34) & " as TMP_AUTO_IDALMACEN," & Chr(34) & "TMP_AUTO_FECHA " & Chr(34) & " as TMP_AUTO_FECHA," & Chr(34) & "TMP_AUTO_KILOMETRAJE" & Chr(34) & " as TMP_AUTO_KILOMETRAJE," & Chr(34) & "TMP_AUTO_COMBUSTIBLE" & Chr(34) & " as TMP_AUTO_COMBUSTIBLE," & Chr(34) & "TMP_AUTO_TABLERO  " & Chr(34) & " as TMP_AUTO_TABLERO," & Chr(34) & "TMP_AUTO_CLAXON " & Chr(34) & " as TMP_AUTO_CLAXON," & Chr(34) & "TMP_AUTO_PARABRISAS " & Chr(34) & " as TMP_AUTO_PARABRISAS," & Chr(34) & "TMP_AUTO_CINTURON " & Chr(34) & " as TMP_AUTO_CINTURON," & Chr(34) & "TMP_AUTO_ESPEJOS " & Chr(34) & " as TMP_AUTO_ESPEJOS," & Chr(34) & "TMP_AUTO_LICENCIA " & Chr(34) & " as TMP_AUTO_LICENCIA," & Chr(34) & "TMP_AUTO_LIB_OBJETOSINE " & Chr(34) & " as TMP_AUTO_LIB_OBJETOSINE," & Chr(34) & "TMP_AUTO_LIB_OBJETOTMPERVI " & Chr(34) & " as TMP_AUTO_LIB_OBJETOTMPERVI," & Chr(34) & "TMP_AUTO_ORDEN_HERRA " & Chr(34) & " as TMP_AUTO_ORDEN_HERRA," & Chr(34) & "TMP_AUTO_UNILIMPIA " & Chr(34) & " as TMP_AUTO_UNILIMPIA," & Chr(34) & "TMP_AUTO_LIMPIO " & Chr(34) & " as TMP_AUTO_LIMPIO," & Chr(34) & "TMP_AUTO_BASURA " & Chr(34) & " as TMP_AUTO_BASURA," & Chr(34) & "TMP_AUTO_RESPONSABILIDAD " & Chr(34) & " as TMP_AUTO_RESPONSABILIDAD," & Chr(34) & "TMP_AUTO_AUDITORIA " & Chr(34) & " as TMP_AUTO_AUDITORIA," & Chr(34) & "TMP_AUTO_HABITUAL " & Chr(34) & " as TMP_AUTO_HABITUAL," & Chr(34) & "TMP_AUTO_HERRAMIENTAS " & Chr(34) & " as TMP_AUTO_HERRAMIENTAS," & Chr(34) & "TMP_AUTO_CONOS " & Chr(34) & " as TMP_AUTO_CONOS," & Chr(34) & "TMP_AUTO_EDO_CARROCERIA " & Chr(34) & " as TMP_AUTO_EDO_CARROCERIA," & Chr(34) & "TMP_AUTO_FUN_LUCES " & Chr(34) & " as TMP_AUTO_FUN_LUCES," & Chr(34) & "TMP_AUTO_PLACAS_CIRCU " & Chr(34) & " as TMP_AUTO_PLACAS_CIRCU," & Chr(34) & "TMP_AUTO_COND_LLANTAS " & Chr(34) & " as TMP_AUTO_COND_LLANTAS," & Chr(34) & "TMP_AUTO_ACEITEMOTOR " & Chr(34) & " as TMP_AUTO_ACEITEMOTOR," & Chr(34) & "TMP_AUTO_ACEITEDIREC " & Chr(34) & " as TMP_AUTO_ACEITEDIREC," & Chr(34) & "TMP_AUTO_NVL_REFRIGERANTE " & Chr(34) & " as TMP_AUTO_NVL_REFRIGERANTE," & Chr(34) & "TMP_AUTO_NVL_LIQUIDBRISAS " & Chr(34) & " as TMP_AUTO_NVL_LIQUIDBRISAS," & Chr(34) & "TMP_AUTO_COND_BANMOTOR " & Chr(34) & " as TMP_AUTO_COND_BANMOTOR," & Chr(34) & "TMP_AUTO_FUGASGRAL " & Chr(34) & " as TMP_AUTO_FUGASGRAL," & Chr(34) & "TMP_AUTO_FRENOS " & Chr(34) & " as TMP_AUTO_FRENOS," & Chr(34) & "TMP_AUTO_COMENTARIOS " & Chr(34) & " as TMP_AUTO_COMENTARIOS FROM TMP_INSPECCION_AUTO_DIARIA")
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			If File.Exists(File.DirInternal,"FOTO1.jpg") And File.Exists(File.DirInternal,"FOTO2.jpg") And _
				File.Exists(File.DirInternal,"FOTO3.jpg") And File.Exists(File.DirInternal,"FOTO4.jpg") Then
				foto1 = Bit.InputStreamToBytes(File.OpenInput(File.DirInternal,"FOTO1.jpg"))
				foto2 = Bit.InputStreamToBytes(File.OpenInput(File.DirInternal,"FOTO2.jpg"))
				foto3 = Bit.InputStreamToBytes(File.OpenInput(File.DirInternal,"FOTO3.jpg"))
				foto4 = Bit.InputStreamToBytes(File.OpenInput(File.DirInternal,"FOTO4.jpg"))
			Else
'				Msgbox("No estan completas las fotos.", "FOTOS INCOMPLETAS") 'ignore
				ToastMessageShow("FOTOS INCOMPLETAS!!", True)
			End If
			Dim cmd As DBCommand
			cmd.Initialize
			cmd.Name = "INSERT_TMP_INSPECCION_AUTO_DIARIA"
			cmd.Parameters = Array As Object(C.GetString("TMP_AUTO_RUTA"),C.GetString("TMP_AUTO_PLACA"),C.GetString("TMP_AUTO_CEDIS"),C.GetString("TMP_AUTO_IDALMACEN"),C.GetString("TMP_AUTO_FECHA"),C.GetString("TMP_AUTO_KILOMETRAJE"),C.GetString("TMP_AUTO_COMBUSTIBLE"),C.GetString("TMP_AUTO_TABLERO"),C.GetString("TMP_AUTO_CLAXON"),C.GetString("TMP_AUTO_PARABRISAS"),C.GetString("TMP_AUTO_CINTURON"),C.GetString("TMP_AUTO_ESPEJOS"),C.GetString("TMP_AUTO_LICENCIA"),C.GetString("TMP_AUTO_LIB_OBJETOSINE"),C.GetString("TMP_AUTO_LIB_OBJETOTMPERVI"),C.GetString("TMP_AUTO_ORDEN_HERRA"),C.GetString("TMP_AUTO_UNILIMPIA"),C.GetString("TMP_AUTO_LIMPIO"),C.GetString("TMP_AUTO_BASURA"),C.GetString("TMP_AUTO_RESPONSABILIDAD"),C.GetString("TMP_AUTO_AUDITORIA"),C.GetString("TMP_AUTO_HABITUAL"),C.GetString("TMP_AUTO_HERRAMIENTAS"),C.GetString("TMP_AUTO_CONOS"),C.GetString("TMP_AUTO_EDO_CARROCERIA"),C.GetString("TMP_AUTO_FUN_LUCES"),C.GetString("TMP_AUTO_PLACAS_CIRCU"),C.GetString("TMP_AUTO_COND_LLANTAS"),C.GetString("TMP_AUTO_ACEITEMOTOR"),C.GetString("TMP_AUTO_ACEITEDIREC"),C.GetString("TMP_AUTO_NVL_REFRIGERANTE"),C.GetString("TMP_AUTO_NVL_LIQUIDBRISAS"),C.GetString("TMP_AUTO_COND_BANMOTOR"),C.GetString("TMP_AUTO_FUGASGRAL"),C.GetString("TMP_AUTO_FRENOS"),C.GetString("TMP_AUTO_COMENTARIOS"), foto1, foto2, foto3, foto4)
			reqManager.ExecuteCommand(cmd , "inst_noventa_ins_tmp_insp_auto")
			contador_env = contador_env + 1
		Next
		c.Close
	End If
	t1.Initialize("T1", 20000) ' 1000 = 1 second
	t1.Enabled = True
	PORCENTAJE = Round(100/ (cuantos_noventa + cuantos_pedido + cuantos_pedidosc + 1))
	PORCENTAJE = 1

	DateTime.TimeFormat = "HHmm"
	sTime=DateTime.Time(DateTime.Now)
	c=Starter.skmt.ExecQuery2("SELECT  HE_CUANTOS, HE_FECHA FROM HIST_ENVIOS WHERE HE_TIPO = ?", Array As String("PEDIDO"))
	c.Position = 0
	Starter.skmt.ExecNonQuery2("UPDATE HIST_ENVIOS SET HE_FECHA = ?, HE_CUANTOS = ? WHERE HE_TIPO = ?", Array As Object(sTime,c.GetString("HE_CUANTOS") + 1, "PEDIDO"))
	c.Close
	c=Starter.skmt.ExecQuery("SELECT COUNT(*) as CANTIDAD   FROM PEDIDO WHERE PE_CLIENTE = 0 ")
	c.Position = 0
	PORENVIAR = c.GetString("CANTIDAD")
	If PORENVIAR > 0 Then
		Starter.skmt.ExecNonQuery2("delete from HIST_ENVIOS where HE_TIPO = ?", Array As Object ("ABORDO"))
		Starter.skmt.ExecNonQuery2("INSERT INTO HIST_ENVIOS VALUES (?,1,?)", Array As Object(sTime, "ABORDO"))
	End If
'	ToastMessageShow("Se Actualizaran los datos. Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)
	S_CP.Text = "SUBIENDO"
	DateTime.TimeFormat = "HH:mm:ss"
End Sub

Sub SUBIR_INFO_BOLETA
	P1.Width = GetDeviceLayoutValues.Width
	P1.Height = GetDeviceLayoutValues.Height
	Subs.panelVisible(P1, 0,  0)
	Try
		c=Starter.skmt.ExecQuery("SELECT TMP_BILLE_IDALMACEN,TMP_BILLE_RUTA, TMP_BILLE_FECHA,TMP_BILLE_MIL,TMP_BILLE_QUINIENTOS,TMP_BILLE_DOSCIENTOS,TMP_BILLE_CIEN,TMP_BILLE_CINCUENTA,TMP_BILLE_VEINTE FROM TMP_CAT_BILLETE")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_boletab_KELL"
				cmd.Parameters = Array As Object(C.GetString("TMP_BILLE_IDALMACEN"),l_ruta.Text,C.GetString("TMP_BILLE_FECHA"),C.GetString("TMP_BILLE_MIL"),C.GetString("TMP_BILLE_QUINIENTOS"),C.GetString("TMP_BILLE_DOSCIENTOS"),C.GetString("TMP_BILLE_CIEN"),C.GetString("TMP_BILLE_CINCUENTA"),C.GetString("TMP_BILLE_VEINTE"))
				reqManager.ExecuteCommand(cmd , "ins_boletab")
			Next
			c.Close
		End If
	
		c=Starter.skmt.ExecQuery("SELECT  TMP_MON_RUTA,TMP_MON_IDALMACEN,TMP_MON_FECHA,TMP_MON_VEINTE,TMP_MON_DIEZ,TMP_MON_CINCO,TMP_MON_DOS,TMP_MON_UN,TMP_MON_CENTAVOS FROM TMP_CAT_MONEDAS")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_boletam_KELL"
				cmd.Parameters = Array As Object(l_ruta.Text,C.GetString("TMP_MON_IDALMACEN"),C.GetString("TMP_MON_FECHA"),C.GetString("TMP_MON_VEINTE"),C.GetString("TMP_MON_DIEZ"),C.GetString("TMP_MON_CINCO"),C.GetString("TMP_MON_DOS"),C.GetString("TMP_MON_UN"),C.GetString("TMP_MON_CENTAVOS"))
				reqManager.ExecuteCommand(cmd , "ins_boletam")
			Next
			c.Close
		End If
		
		S_CP.Text = "Envio Boleta"
		PB2.Progress = 1
		contador_env = 2
		PB2.Progress = 100
		t3.Initialize("T3", 5000) ' 1000 = 1 second
		Wait For  t3_tick
		t3.Enabled = True
		S_CP.Text = "INFO OK"
	Catch
'		ToastMessageShow("ACTUALIZAR APK BOLETA",0)
		Log(LastException)
	End Try
End Sub

Sub VALIDAR_INFO
	d=Starter.skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
	d.Position = 0
	cuantos_pedido = d.GetString("CUANTOS_PEDIDO")
	d.Close
	cmd.Initialize
	cmd.Name = "select_cuantos_pedido_KELL"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedido1")
	t3.Initialize("T3", 8000) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
End Sub

' ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
' ///////////////////////////////////////////////  PDF CARTA PORTE  ///////////////////////////////////////
' ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Private Sub ImageView1_LongClick 'Mostramos la carta porte al hacer clic largo en el logo de Kelloggs
	Log("Logo clicked")
	pdf.Initialize("PDFium")
	PNL_ACCESO.Visible = False
	Panel7.Visible = False
	p_pdfViewer.Width = GetDeviceLayoutValues.Width
	p_pdfViewer.Height = GetDeviceLayoutValues.Height
	PDFView1.Width = GetDeviceLayoutValues.Width-20
	p_controles_pdf.Width = GetDeviceLayoutValues.Width-20
'	If Logger Then Log($"pantalla: ${GetDeviceLayoutValues.Width}x${GetDeviceLayoutValues.Height} -  panel: ${p_pdfViewer.Width}x${p_pdfViewer.Height}"$)
	Subs.panelVisible(p_pdfViewer, 0, 0)
	pdfViewerActivo = True
'	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
	Dim cfg As Configurator = PDFView1.fromUri(File.DirInternal,"/cartaPorte.pdf")
	cfg.SetEventname("PDFium")
	cfg.pageFitPolicy("BOTH").autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.load
End Sub

'Descarga del servidor el PDF de la carta porte del dia de hoy y la
'guarda en el almacenamiento externo con el nombre "cartaPorte.pdf"
Sub descargaCartaPorte
	Log("Inicia descargaCartaPorte")
	cartaPorteLista = False
	'Generamos el nombre del PDF de la carta porte
	DateTime.DateFormat = "ddMMyyyy"
	Private almacenX As String = Starter.almacen
	Private rutaX As String = Starter.rutapreventa
	Private cartaPortePDF As String = $"CPORTE${almacenX}_${rutaX}.pdf"$
'	cartaPortePDF = "CPORTE2_100_Prueba.pdf"  'Para pruebas
'	Log(cartaPortePDF)
	'Para el servidor
	Private pdfServer As String = "keymon.lat"
	If Starter.server.IndexOf("10.0.0.205") > -1 Then pdfServer = "10.0.0.205"
'	Log(pdfServer)
	pdfURL = $"https://${pdfServer}/CartaPorteKelloggs/CartaPorteMovil${DateTime.Date(DateTime.now)}/${cartaPortePDF}"$
	LogColor(pdfURL,Colors.Red)
'	Log("Iniciamos wait for descargaCartaPorteyProgreso")
	Wait For (descargaCartaPorteyProgreso(pdfURL)) Complete (Success As Boolean)
'	Log("Terminamos wait for descargaCartaPorteyProgreso")
	l_porcentaje.Text = "0%"
	ProgressBarPDF.Progress = 0
'	Log("Ocultamos panel descarga")
	Subs.panelOculto(p_downloadPDF)
End Sub

'Muestra el panel de descarga de la carta porte con barra de progreso
Sub descargaCartaPorteyProgreso (urlx As String) As ResumableSub
	Log("Iniciamos descargaCartaPorteyProgreso")
	If logger Then Log("Mostramos panel descarga")
	Subs.panelVisible(p_downloadPDF, 0, 0)
	Subs.centraPanel(p_progress1, Root.Width)
	Subs.centraEtiqueta(l_downloadPDF, p_progress1.Width)
	Subs.centraEtiqueta(l_porcentaje, p_progress1.Width)
	Subs.centraProgressBar(ProgressBarPDF, p_progress1.Width)
	Dim job_PDF As HttpJob
	job_PDF.Initialize("job_PDF",Me)
'	job_PDF.GetRequest.Timeout = 120000 ' Timeout a 2 minutos
	job_PDF.Download(urlx)

	'Para la barra de progreso
	' == TaskIdToJob == necesita que se agregue "HU2_PUBLIC" a "Conditional Symbols" (Project/Build Configurations) (Ctrl+B)
	Dim TaskToJob As Map = HttpUtils2Service.TaskIdToJob
	Do While HttpUtils2Service.TaskIdToJob.IsInitialized = False
		Log("Waiting for HttpUtils2Service to be ready.")
		Sleep(20)
	Loop
	Dim TaskId As Int
	Do While TaskId = 0
		For Each id As Int In TaskToJob.Keys
			If TaskToJob.Get(id) = job_PDF Then
				TaskId = id
				Exit
			End If
		Next
		Sleep(10)
	Loop
	Dim bx() As Boolean = Array As Boolean(False)
	Log("Llamamos TrackProgress")
	TrackProgress(job_PDF, bx, TaskId)
	'**** Termina barra de progreso

	Log("Iniciamos Wait for JobDone Descarga")
	Log("Mostramos panel descarga")
	Subs.panelVisible(p_downloadPDF, 0, 0)
	Wait for (job_PDF) JobDone (job_PDF As HttpJob)
'	Log("Terminamos Wait for JobDone Descarga ")
	If job_PDF.Success = False Then Log("Error PDF")
	If job_PDF.Success = True Then
		Log("Carta descargada con exito")
		cartaPorteLista = True
		' // Delete existing file
'		Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
'		Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
		If File.Exists(File.DirInternal,"cartaPorte.pdf") Then
'			Log("Borramos carta anterior")
			File.Delete(File.DirInternal,"cartaPorte.pdf")
		End If
		' // Save new file
		Dim outNewAPK As OutputStream = File.OpenOutput(File.DirInternal,"cartaPorte.pdf", False)
		File.Copy2(job_PDF.GetInputStream, outNewAPK)
'		Log("Guardamos nueva carta")
		outNewAPK.Close
		Log("APK dir: "&File.DirInternal)
		Log("Carta porte lista")
		ToastMessageShow("Carta Porte descargada exitosamente!!", False)
	Else
		Log("Hubo un error, intente de nuevo")
		job_PDF.Release
		Subs.panelOculto(p_downloadPDF)
		Log("Ruta tipo " & Starter.rutaTipo)
		If File.Exists(File.DirInternal,"cartaPorte.pdf") And Starter.rutaTipo <> "FORANEA" Then 'Existe, NO es de hoy y NO ES es FORANEA
			Private mb1 As Int
			mb1 = Msgbox2("No se pudo descargar la carta porte, por favor intente de nuevo o comuniquese con un supervisor", "Error Carta Porte", "Aceptar", "", "Reintentar", Null) 'ignore
			If mb1 = DialogResponse.Positive Then
'				Activity.Finish
'				ExitApplication
				detenerLoop = True
				B4XPages.ShowPage("Login")
			ELSE IF mb1 = DialogResponse.NEGATIVE Then
				descargaCartaPorte
			ELSE IF mb1 = DialogResponse.CANCEL Then
				'			VALIDAR_INFO
			End If
		Else
			LogColor("Hay carta porte vieja PERO la ruta es Foranea", Colors.RGB(255,131,0))
			ToastMessageShow("Hay carta porte de dias anteriores y la ruta es foranea.", True)
			cartaPorteLista = True
		End If
	End If
	bx(0) = True
	job_PDF.Release
'	Log("Termina descargaCartaPorteyProgreso")
	Return job_PDF.Success
End Sub

'Para visualizar el progreso de la descarga
Private Sub TrackProgress (j As HttpJob, Stop() As Boolean, TaskId As Int)
	Do While Stop(0) = False
		If j.Out.IsInitialized Then
			Dim TotalLength As Long = j.Response.ContentLength
			Dim size As Long = File.Size(HttpUtils2Service.TempFolder, TaskId)
'			Log(size & ", " & TotalLength & " | " & ((size/TotalLength)*100))
			ProgressBarPDF.Progress = (size/TotalLength)*100
			l_porcentaje.Text = $"$1.0{((size/TotalLength)*100)} %"$
		End If
		Sleep(100)
	Loop
'	Log("TrackProgress - "&size & ", " & TotalLength)
End Sub

Sub PDFium_loadComplete(pages As Int)
'	Log($"PDFium_loadComplete(${pages})"$)
	glPages = pages
	lblPages.Text = $"${glPages}"$
End Sub

Sub PDFium_onInitiallyRendered(page As Int)
	Log($"PDFium_onInitiallyRendered(${page})"$)
End Sub

Sub PDFium_onPageChanged(page As Int, TotalPages As Int)
'	Log($"PDFium_onPageChanged(${page},${TotalPages})"$)
	lblPages.Text = $"${page+1}/${glPages}"$
End Sub

Sub PDFium_PageNum(page As Int)
	Log($"PDFium_PageNum(${page})"$)
End Sub

Sub PDFium_Show()
	Log($"PDFium_Show()"$)
End Sub

Sub btnFirst_Click
	PDFView1.jumpTo2(0,False)
End Sub

Sub btnPrev_Click
	PDFView1.jumpTo2(PDFView1.CurrentPage-1,False)
End Sub

Sub btnNext_Click
	PDFView1.jumpTo2(PDFView1.CurrentPage+1,False)
End Sub

Sub btnLast_Click
	PDFView1.jumpTo2(glPages-1,False)
End Sub

Private Sub B_PROXIMA_LongClick
	''	StartActivity(Starter.ultimaActividad)
'	If Starter.sesion.Get("actividad") <> "" Then
	''		StartActivity(Starter.sesion.Get("actividad"))
'		Log(Starter.sesion)
'		If Starter.sesion.Size = 1 Then
'			CallSubDelayed(Starter.sesion.Get("actividad"), "activity_resume")
'		else if Starter.sesion.ContainsKey("sub") Then
'			Private esteSub As Map = Starter.sesion.Get("sub")
	''			If Logger Then Log(esteSub)
'			If esteSub.Size = 1 Then CallSubDelayed(Starter.sesion.Get("actividad"), esteSub.Get("nombre"))
'			If esteSub.Size = 2 Then CallSubDelayed2(Starter.sesion.Get("actividad"), esteSub.Get("nombre"), esteSub.get("param1"))
'			If esteSub.Size = 3 Then CallSubDelayed3(Starter.sesion.Get("actividad"), esteSub.Get("nombre"), esteSub.get("param1"), esteSub.get("param2"))
'		End If
'	End If
End Sub

Private Sub P1_Click
	'Vacio, solo está aquib para capturar el evento de clic y que no se pase hacia el fondo.
End Sub

Private Sub Resumen_LongClick
	ToastMessageShow("Enviamos UTR", True)
	CallSubDelayed(Starter, "ENVIA_ULTIMA_GPS")
End Sub