B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Mods 'Ignore
	'2023/05/04 - Se modifico el sub b_geopass_Click para que si se mete la contraseña KMTS1, se habilite la venta fuera de la geocerca.
End Sub

Sub Class_Globals
	Private Root As B4XView 'ignore
	Dim reqManager As DBRequestManager
	Private xui As XUI 'ignore
	'// Process Globals
	Dim g As GPS
	Dim ime As IME
	Dim ruta As String
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String = ""
	Dim total_cliente As String
	Dim m_lat As String
	Dim m_lon As String
	Dim cmp20 As Serial
	Dim printer As TextWriter
	Dim PairedDevices As Map
	Dim L As List
	Dim TAMANO As Int
	Dim ESPACIO As Int
	Dim BLANCO As String
	Dim cuenta As String
	Dim Printer1 As EscPosPrinter
	Dim MAC_IMPRESORA As String
	Dim LONGITUD As String = "0"
	Dim LATITUD As String = "0"
	Dim NOMBRE As String
	Dim ruta_tienda As String
	Dim id_encuesta As String
	Dim LLAMAR_FOTO As String
	Dim CURSOR_FOTO As Int
	Dim TOMAR_FOTO As String
	Dim YA_IMPRIMIO2 As String
	Dim CREDITO_DISPONIBLE As String
	'//Globals
	Dim c As Cursor
	Dim s As Cursor
	Dim c2 As Cursor
	Dim S1 As Cursor
	Dim S2 As Cursor
	Dim S3 As Cursor
	Dim C1 As Cursor
	Dim C3 As Cursor
	Dim C4 As Cursor
	Dim C5 As Cursor
	Dim C6 As Cursor
	Dim c7 As Cursor
	Dim C8 As Cursor
	Dim RMI As String
	Dim RMI_VALOR As String
	Dim ListView1 As ListView
	Dim la_cuenta As Label
	Dim La_nombre As Label
	Dim la_Calle As Label
	Dim la_numero As Label
	Dim la_nint As Label
	Dim la_edo As Label
	Dim la_pob As Label
	Dim la_col As Label
	Dim la_cp As Label
	Dim la_zona As Label
	Dim gest As Button
	Dim la_saldotot As Label
	Dim la_saldooper As Label
	Dim Tels As Button
	Dim Label10 As Label
	Dim Label11 As Label
	Dim Tar As Button
	Dim la_comm As Label
	Dim la_actdte As Label
	Dim la_usuario As Label
	Dim la_resultado As Label
	Dim l_entre1 As Label
	Dim l_entre2 As Label
	Dim l_atiende As Label
	Dim l_atiende2 As Label
	Dim DATOS As Button
	Dim Guardar As Button
	Dim NUEVO As Button
	Dim l_total As Label
	Dim c2 As Cursor
	Dim S2 As Cursor
	Private s As Cursor
	Dim res As String
	Private HIST As Button
	Private MONTO_COMPRA As String
	Private META As String
	Private META2 As String
	Private VERIFICA As String
	Private L_QR As Label
	Private BT_QR As Button
	Private qr As QRCode
	Dim sc As Zxing_scanner
	Dim CODIGO As String
	Private b_mapa As Button
	Dim CUANTOS As String
	Private B_IMP As Button
	Dim Toggla As Toggle
	Private B_VENTA As Button
	Dim PASA_IMP As String
	Dim sucursal As String
	Dim FACTURA As String
	Dim CREDITO As String
	Private b_factura As Button
	Dim perfil As String
	Private CH_TA As CheckBox
	Private CH_TC As CheckBox
	Private CH_TB As CheckBox
	Private CH_TD As CheckBox
	Private E_CUANTOS_E As EditText
	Private B_GUARDAR As Button
	Private TIPOEX As String
	Private B_EXIBI As Button
	Private Panel1 As Panel
	Dim t3 As Timer
	'--***---- BOLETA DE LIQUIDACION
	Private P_BOLETA As Panel
	'------ BILLETES
	Private LBL_TMIL As Label
	Private LBL_TQUIN As Label
	Private LBL_TDOS As Label
	Private LBL_TCIEN As Label
	Private LBL_TCIN As Label
	Private LBL_TVEIN As Label
	Private LBL_MIL As Label
	Private LBL_QUIN As Label
	Private LBL_DOSC As Label
	Private LBL_CIEN As Label
	Private LBL_CINCUEN As Label
	Private LBL_VEINTE As Label
	Private EDT_CANVEIN As EditText
	Private EDT_CANCIN As EditText
	Private EDT_CANCIEN As EditText
	Private EDT_CANDOS As EditText
	Private EDT_CANQUIN As EditText
	Private EDT_CANMIL As EditText
	Private Btn_TOTALBILLETE As Button
	Private Pnl_Billete As Panel
	Private Pnl_Moneda As Panel
	Private L_CALCULA_BILLE As Label
	'------ BOTONES MAS Y MENOS
	Private B_MENMIL As Button
	Private B_SUMIL As Button
	Private B_MENQUI As Button
	Private B_SUQUI As Button
	Private B_MENDOS As Button
	Private B_SUDOS As Button
	Private B_MENCIE As Button
	Private B_SUCIEN As Button
	Private B_MENCIN As Button
	Private B_SUCIN As Button
	Private B_MENVEI As Button
	Private B_SUVEI As Button
	'------ MONEDAS
	Private L_DIEZ As Label
	Private L_CINCO As Label
	Private L_DOS As Label
	Private L_UNO As Label
	Private L_CENTAVO As Label
	Private LBL_TDIEZ As Label
	Private LBL_TCI As Label
	Private LBL_TDO As Label
	Private LBL_TUN As Label
	Private LBL_TCEN As Label
	Private EDT_CANCEN As EditText
	Private EDT_CANUN As EditText
	Private EDT_CANDO As EditText
	Private EDT_CANCI As EditText
	Private EDT_CANDIEZ As EditText
	Private L_CALCULA_MONEDA As Label
	Private B_TOTALMONEDA As Button
	'------ BOTONES MAS Y MENOS
	Private B_MENCENT As Button
	Private B_MENUN As Button
	Private B_MENDO As Button
	Private B_MENCI As Button
	Private B_MENDIEZ As Button
	Private B_SUMDIEZ As Button
	Private B_SUMCIN As Button
	Private B_SUMDO As Button
	Private B_SUMUN As Button
	Private B_SUMCENT As Button
	'------ SUMA TOTALES
	Private Edt_FH As EditText
	Private B_AGREGAMONE As Button
	Private B_AGREGABILL As Button
	Private TOTALES As Label
	Private B_SUM_TOTAL As Button
	Private TOTALBILLETES As Button
	Private TOTALMONEDA As Button
	Private PNL_TOTALES As Panel
	Private LBL_RETURN As Label
	Private IMG_IMPRESORA As Label
	Private LBL_REGRESA As Label
	'--***---- FIN BOLETA
	Private P_INF_GENERAL As Panel
	Private B_Regresar As Button
	Private ABORDO As String
	Private a_inicial As String
	Private a_total As String
	Private a_venta As String
	Private a_final As String
	Private a_VENTA_F As String
	Private a_inicial_5 As String
	
	Private L_INVA As ListView
	Private B_IMP_INV As Button
	Private B_CERRAR_I As Button
	Private Panel_INV_A As Panel
	Private LBL_TVEINTE As Label
	Private B_SUMVEINTE As Button
	Private EDT_CANVEINTE As EditText
	Private B_MENVEINTE As Button
	Private L_VEINTE As Label
	Dim RutaBoleta As String
	Dim Id_Almacen As String
	Dim cursorBoleta As Cursor
	Private Bt_GuardarBoleta As Button
	Private CUANTOS1 As String
	Private Panel9 As Panel
	Private t_tenc As Label
	Private E_RES_E As EditText
	Private B_E_NEXT As Button
	Private Label26 As Label
	Private l_chk_e As Label
	Private Chk_1 As CheckBox
	Private chk_2 As CheckBox
	Private chk_3 As CheckBox
	Private b_chk_e As Button
	Private Panel10 As Panel
	Private chk_1_valor As String
	Private chk_2_valor As String
	Private chk_3_valor As String
	Private p_encuesta As Panel
	Private b_encuesta_1 As Button
	Private b_encuesta_2 As Button
	Private b_encuesta_3 As Button
	Private l_titEncuesta As Label
	Private l_txtEncuesta As Label
	Private encuestaRes As String
	Private botonPresionado As Int
	Private B_IMP2 As Button
	Dim impresoraConectada As Boolean = False
	Private l_categoria2 As Label
	Private l_exhibidor2 As Label
	Private p_exhibidores As Panel
	Private Button1 As Button
	Private b_exhibidor As Button
	Private l_exhibidores3 As Label
	Private l_segmento2 As Label
	Private et_encuesta As EditText
	Private b_encuesta_continuar As Button
	Dim muestraBoleta As Boolean = False
	Private Panel4 As Panel
	Private Panel6 As Panel
	Private l_ubicacion As Label
	Dim l_ubicacion2 As Label
	Dim b_ubicacion As Button
	Dim logger As Boolean = False
	Private b_whats As Button
	Private b_aceptarrpomo As Button
	Private b_rechazapromo As Button
	Private p_promowhats As Panel
	Private l_promowhats As Label
	Private L_doe As Label
	
	Private gps_boton_doe As String
	Private pgs_boton_noventa As String
	Private P_DOE As Panel
	Private LP_DOE As ListView
	Private BP_DOE_A As Button
	Private BP_DOE_R As Button
	Private p_pideGeoPass As Panel
	Private b_geopass As Button
	Private et_geopass As EditText
	Dim laDist As Float
	Private L_DOE_TOTAL As Label
	Private Panel11 As Panel
	Private BP_DOE_R1 As Button
	Private r_1 As RadioButton
	Private r_2 As RadioButton
	Private r_3 As RadioButton
	Private r_4 As RadioButton
	Private R_5 As RadioButton
	Private e_comm As EditText
	Private motivo As String
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
	reqManager.Initialize(Me, Starter.server)
	'load the layout to Root
	Root.LoadLayout("cliente")
	ruta = File.DirInternal
	Subs.panelAnchoAlto(P_INF_GENERAL, Root.Width, Root.Height)
	Panel6.Width = Root.Width
	p_promowhats.Width = Root.Width
	p_promowhats.visible = False
	If Starter.boleta = 0 Then
		c=Starter.skmt.ExecQuery("select 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_BFACTURA, CAT_CL_BCREDITO, CAT_CL_CATEGORIA, CAT_CL_SEGMENTO from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
		s=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		s.Position=0
		If c.RowCount > 0 Then
			c.Position=0
			la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
			cuenta = c.GetString("CAT_CL_CODIGO")
			La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
			NOMBRE = c.GetString("CAT_CL_NOMBRE")
			la_Calle.Text = c.GetString("CAT_CL_CALLE") & c.GetString("CAT_CL_NOEXT")
			la_col.Text = c.GetString("CAT_CL_COLONIA")
			la_edo.Text = c.GetString("CAT_CL_EDO")
			la_cp.Text = c.GetString("CAT_CL_CP")
			l_entre1.Text = c.GetString("CAT_CL_CALLE1")
			l_entre2.Text = c.GetString("CAT_CL_CALLE2")
			l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
			l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
			la_saldotot.Text = c.GetString("CAT_CL_TELEFONO")
			''' ESTO SE AGREGA PARA QUE SE VEA LOS CLIENTES DOE
			If c.GetString("CAT_CL_EMAIL") = "1" Then
				L_doe.Visible = True
			Else
				L_doe.Visible = False
			End If
			'''FIN CLIENTES DOE
			l_total.Text = s.GetString("TOTAL_CLIE")
			total_cliente = s.GetString("TOTAL_CLIE")
			MONTO_COMPRA = c.GetString("CAT_CL_MTOCOMPRA")
			FACTURA = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
			LONGITUD = 0
			If c.GetString("CAT_CL_LONG") <> Null And c.GetString("CAT_CL_LONG") <> "null" And IsNumber(c.GetString("CAT_CL_LONG")) Then  LONGITUD =  c.GetString("CAT_CL_LONG")
			LATITUD = 0
			If c.GetString("CAT_CL_LAT") <> Null And c.GetString("CAT_CL_LAT") <> "null" And IsNumber(c.GetString("CAT_CL_LAT")) Then LATITUD = c.GetString("CAT_CL_LAT")
			l_categoria2.text = c.GetString("CAT_CL_CATEGORIA")
			l_segmento2.text = c.GetString("CAT_CL_SEGMENTO")
			If logger Then Log($"Lon: ${LONGITUD}, Lat: ${LATITUD}"$)
		Else
			RutaBoleta=Starter.rutaV
		End If
	End If
	c=Starter.skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("MACIMP"))
	c.Position =0
	If c.RowCount > 0 Then
		MAC_IMPRESORA = c.GetString("CAT_VA_VALOR")
	Else
		MAC_IMPRESORA = 0
		Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MACIMP","0"))
	End If
	Starter.MAC_IMPRESORA = MAC_IMPRESORA
	Printer1.Initialize(Me, "Printer1")
	TOMAR_FOTO = 0
	c.Close
	If s.IsInitialized Then s.Close
End Sub

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

Sub B4XPage_Appear
	If Subs.traeUltimaActividadBD <> "Cliente" Then Subs.iniciaActividad(Subs.traeUltimaActividadBD)
	If Not(muestraBoleta) Then P_INF_GENERAL.Visible = True
	
	
	la_cuenta.Text = ""
	La_nombre.Text = ""
	la_Calle.Text = ""
	la_col.Text = ""
	la_edo.Text = ""
	la_cp.Text = ""
	l_entre1.Text = ""
	l_entre2.Text = ""
	l_atiende.Text = ""
	l_atiende2.Text = ""
	l_total.Text = ""
	l_exhibidor2.Text = ""
	la_saldooper.Text = ""
	l_categoria2.text = ""
	l_segmento2.text = ""
	
	p_pideGeoPass.Visible = False
'	If Logger Then Log(muestraBoleta)
	CallSubDelayed(Tracker, "StartFLP2")
	b_ubicacion.Text = "SIN GPS"
	b_ubicacion.TextColor = Colors.Red
	pgs_boton_noventa = "1"
	m_lat = -99.167244
	m_lon = 19.427184
	If Not(Starter.GPS.GPSEnabled) Then
		ToastMessageShow("Debe Activar el GPS del Equipo.", True)
		StartActivity(Starter.GPS.LocationSettingsIntent)
	Else
		Starter.GPS.Start(0, 0)
		If Starter.ubicacionActual.Latitude <> 0 Then GPS_LocationChanged(Starter.ubicacionActual)
	End If
	If muestraBoleta Then LLAMA_BOLETA
	BT_QR.Enabled = False
	b_factura.Visible = False
	Panel_INV_A.Visible = False
	CREDITO_DISPONIBLE =0

	If Starter.boleta = 0 Then
		c=Starter.skmt.ExecQuery("SELECT 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 FROM CAT_ENCUESTA_PREGUNTA ORDER BY CAT_CE_DESCRIPCION, CAST(CAT_EP_ORDEN_PREGUNTA AS DECIMAL)")
		If c.RowCount > 0 Then c.Position= 1
		
		If TOMAR_FOTO = 0 Then
			c=Starter.skmt.ExecQuery("select * from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
			s=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			s.Position=0
			S1=Starter.skmt.ExecQuery("select count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			S1.Position=0
			Log("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh    "&c.RowCount)
			c.Position=0
			la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
			La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
			la_Calle.Text = c.GetString("CAT_CL_CALLE") & " " & c.GetString("CAT_CL_NOEXT")
			la_col.Text = c.GetString("CAT_CL_COLONIA")
			la_edo.Text = c.GetString("CAT_CL_EDO")
			la_cp.Text = c.GetString("CAT_CL_CP")
			l_entre1.Text = c.GetString("CAT_CL_CALLE1")
			l_entre2.Text = c.GetString("CAT_CL_CALLE2")
			l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
			l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
			l_total.Text = s.GetString("TOTAL_CLIE")
			total_cliente = s.GetString("TOTAL_CLIE")
			m_lat =c.GetString("CAT_CL_LAT")
			m_lon =c.GetString("CAT_CL_LONG")
			CREDITO_DISPONIBLE = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
			ruta_tienda = c.GetString("CAT_CL_RUTA")
			YA_IMPRIMIO2 = c.GetString("IMPRESION")
			l_categoria2.text = c.GetString("CAT_CL_CATEGORIA")
			l_segmento2.text = c.GetString("CAT_CL_SEGMENTO")
			If c.GetString("CAT_CL_EMAIL") = "1" Then
				L_doe.Visible = True
			Else
				L_doe.Visible = False
			End If
			'''FIN CLIENTES DOE
			LONGITUD = 0
			If la_cuenta.Text = "0" Then
				m_lat = Starter.lat_gps
				m_lon = Starter.lon_gps
			End If
			If c.GetString("CAT_CL_LONG") <> Null And c.GetString("CAT_CL_LONG") <> "null" And IsNumber(c.GetString("CAT_CL_LONG")) Then  LONGITUD =  c.GetString("CAT_CL_LONG")
			LATITUD = 0
			If c.GetString("CAT_CL_LAT") <> Null And c.GetString("CAT_CL_LAT") <> "null" And IsNumber(c.GetString("CAT_CL_LAT")) Then LATITUD = c.GetString("CAT_CL_LAT")
			LogColor($"${c.GetString("CAT_CL_LAT")}, ${c.GetString("CAT_CL_LONG")}"$, Colors.red)
			If logger Then Log($"Lat: ${LATITUD}, Lon: ${LONGITUD}"$)
			NOMBRE = c.GetString("CAT_CL_NOMBRE")
			If l_total.Text = Null Then
				Tels.Visible = True
			Else
				Tels.Visible = False
				pgs_boton_noventa = "0"
				If la_cuenta.Text = "0" Then
					CREDITO_DISPONIBLE  = 10000000
					CREDITO = 0
				End If
			End If
'			If S1.GetString("CUANTOS") = 0 Then
'				Tels.Visible = True
'			Else 'Si ya hay venta, ocultamos el boton de "NO VENTA"
'				Tels.Visible = False
'				pgs_boton_noventa = "0"
'			End If
			If CREDITO = "1" Then
				Msgbox("ALTO","Este cliente no se le puede vender ya que tienen adeudo en su crédito") 'ignore
				B_VENTA.Visible = False
				gest.Visible = False
			Else
				B_VENTA.Visible = True
				gest.Visible = True
			End If
			' Msgbox(c.GetString("CAT_CL_NUM_SERIEFISICO"),"AVISO")
			If c.GetString("CAT_CL_NUM_SERIEFISICO") = "0"  Then
				L_QR.Visible = True
			Else
				L_QR.Visible = False
			End If
			S2=Starter.skmt.ExecQuery("select count(*) AS CUANTOS from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
			S2.Position =0
			CUANTOS = S2.GetString("CUANTOS")
			S2.Close
			If CUANTOS > 0 Then
				c2=Starter.skmt.ExecQuery("select sum(HVD_COSTO_TOT) AS TOTAL from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
				c2.Position =0
				MONTO_COMPRA = c2.GetString("TOTAL")
				c2.Close
			Else
				MONTO_COMPRA = "0"
			End If

			la_saldotot.Text = MONTO_COMPRA
			If MONTO_COMPRA <> "0" Then
				META2 = 300 -  MONTO_COMPRA
			Else
				META2 = 300
			End If
			If META2 < 1 Then
				META2 = "CUBIERTO"
			End If
			la_saldooper.Text = META2
			c7=Starter.skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM PEDIDO  WHERE PE_CLIENTE IN (Select cuenta from cuentaa) ")
			c7.Position=0
			If c7.GetString("CUANTOS") = 0 Then
				c=Starter.skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa)")
				c.Position =0
				If c.GetString("CUANTOS")  > 0 Then
					C1=Starter.skmt.ExecQuery("SELECT HCCP_PROMO FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa) ")
					C1.Position =0
					C3=Starter.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM CAT_GUNAPROD2 WHERE CAT_GP_ID = ? ", Array As String(C1.GetString("HCCP_PROMO")))
					C3.Position = 0
					If C3.GetString("CUANTOS") > 0 Then
						c2=Starter.skmt.ExecQuery2("SELECT CAT_GP_NOMBRE FROM CAT_GUNAPROD2 WHERE CAT_GP_ID = ? ", Array As String(C1.GetString("HCCP_PROMO")))
						c2.Position = 0
						MsgboxAsync("El cliente tiene derecho a una promo especial "& c2.GetString("CAT_GP_NOMBRE"),"Aviso") 'ignore
						c2.Close
					Else
						MsgboxAsync("El cliente tiene derecho a una promo especial ","Aviso") 'ignore
					End If
					C3.Close
					C1.Close
				End If
			End If
			c7.Close
			B_VENTA.Visible = True
			Tels.Visible = True
			If CREDITO = "1" Then
				Msgbox("El cliente tiene credito excedido","Aviso") 'ignore
				B4XPages.ShowPage("Principal")
			End If
		Else
			Cuestionario
		End If
		If YA_IMPRIMIO2 = 0 Then
			Guardar.Visible = False
		Else
			Guardar.Visible = True
		End If
		If la_cuenta.text = "0" Then Guardar.Visible = True 'Abordo
		If l_total.Text = Null Or l_total.Text = "null" Or l_total.text = "0" Then Guardar.Visible = True 'Si no hay venta entonces "Guardar" es visible.

		'Promo Especial
'		If Logger Then LogColor($"Ultima actividad BD=${Subs.traeUltimaActividadBD}"$, Colors.Magenta)
		Dim mPromoEspecial As Map = revisaPromoEspecial
'		If Logger Then Log(mPromoEspecial.Get("esValida"))
		If Subs.traeUltimaActividadBD = "Productos" Then 'Venimos de "Productos"
			If logger Then Log("Venimos de Productos")
			If l_total.Text <> Null And mPromoEspecial.Get("montoPromo") <> Null And  l_total.Text > ((mPromoEspecial.Get("montoPromo") *  (100 - mPromoEspecial.Get("rangoPromo")))/100) And _
			l_total.Text <= mPromoEspecial.Get("montoPromo") Then 'El monto de la venta esta dentro del rango para la promo.
				If logger Then Log("Promo dentro del rango")
				Msgbox($"Si la venta sobrepasa los $${mPromoEspecial.Get("montoPromo")} se activa la promoción '${mPromoEspecial.Get("descrPromo")}'"$, "CASI EN RANGO DE PROMO ESPECIAL") 'ignore
			Else
				If logger Then Log("Promo fuera de rango")
			End If
			If l_total.Text <> Null And mPromoEspecial.Get("montoPromo") <> Null And l_total.text >= mPromoEspecial.Get("montoPromo") Then
				If logger Then Log("Promo Autorizada")
				res = Msgbox2("Pomocion '" & mPromoEspecial.Get("descrPromo") & "' disponible.\nSi se otorga la promoción ya NO será posible modificar la venta.", "PROMO DISPONIBLE", "Si", "", "No", Null) 'ignore
				If res = DialogResponse.POSITIVE Then
					If logger Then Log("Promocion aceptada.")
					If logger Then Log($"${mPromoEspecial.Get("idProd")}, ${mPromoEspecial.Get("idPromo")}, ${mPromoEspecial.Get("cantProd")}, ${mPromoEspecial.Get("nombreProd")}, ${mPromoEspecial.Get("descrPromo")}, ${la_cuenta.Text}, ${usuario}, ${ruta_tienda}"$)
					metePromoEspecial(mPromoEspecial.Get("idProd"), mPromoEspecial.Get("idPromo"), mPromoEspecial.Get("cantProd"), mPromoEspecial.Get("nombreProd"), mPromoEspecial.Get("descrPromo"), la_cuenta.Text, usuario, ruta_tienda)
					Subs.ponImpreso(la_cuenta.Text)
				End If
			End If
			If l_total.Text <> Null And mPromoEspecial.Get("montoPromo") <> Null Then Log($"Monto venta = ${l_total.Text}, rango para promo = ${(mPromoEspecial.Get("montoPromo") * (100 - mPromoEspecial.Get("rangoPromo"))/100)}"$)
		End If

		c=Starter.skmt.ExecQuery("select count(*) as conNoVenta FROM NOVENTA WHERE NV_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position = 0
		If c.GetString("conNoVenta") = 1 Then  Tels.Visible = False 'Si ya tiene NoVenta, ocultamos el boton.
		c.Close
	Else
		RutaBoleta=Starter.rutaV
	End If
	If c.IsInitialized Then c.Close
	If s.IsInitialized Then s.Close
	If S1.IsInitialized Then S1.Close
	If logger Then Log("=====================   Traemos EXHIBIDORES " & la_cuenta.Text & "   =================" )
	c=Starter.skmt.ExecQuery2("select * FROM HIST_EXHIBIDORES2 where hist_ex_id_cliente = ?", Array As String (la_cuenta.Text))
	Log("uuuuuuuuuuuuuuuuuuuuuuuuuuuuu    "&c.RowCount)
	If c.RowCount > 0 Then
		Private exhibs As String = ""
		Private separador As String = ""
		For i=0 To c.RowCount -1
			c.Position=i
			If i < c.RowCount And i <> 0 Then separador = " - " Else separador = ""
			exhibs = exhibs & separador & c.GetString("HIST_EX_TIPO")
		Next
'		If Logger Then LogColor(exhibs, Colors.Blue)
		c.Close
		l_exhibidor2.Text = exhibs
		l_exhibidores3.Text = exhibs
	End If
	
	'PARA LA PROMO DOE
	If Starter.boleta = 0 Then
	b_whats.Visible = False
	gps_boton_doe = "0"
	C1=Starter.skmt.ExecQuery("select IMPRESION FROM kmt_info where  CAT_CL_CODIGO In (select cuenta from cuentaa)")
	C1.Position = 0
	If C1.GetString("IMPRESION") <> "1" Then
		S=Starter.skmt.ExecQuery2("select  COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) AND PE_PROID = ?", Array As String("PROMODOE") )
		s.Position = 0
		If s.GetString("CUANTOS") = 0 Then
			c=Starter.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa) AND HCCP_PROMO = ?", Array As String("PROMODOE"))
			c.Position =0
			If c.GetString("CUANTOS")  > 0 Then
				C3=Starter.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM CAT_GUNAPROD2 WHERE CAT_GP_ID = ? ", Array As String("1008094223"))
				C3.Position = 0
				If C3.GetString("CUANTOS") > 0 Then
					c2=Starter.skmt.ExecQuery2("SELECT CAT_GP_ALMACEN FROM CAT_GUNAPROD2 WHERE CAT_GP_ID = ? ", Array As String("1008094223"))
					c2.Position = 0
					If c2.GetString("CAT_GP_ALMACEN") > 0 Then
						b_whats.Visible = False
						'	gps_boton_doe = "1"
						
					End If
					c2.Close
				End If
				C3.Close
			End If
			c.Close
		End If
		s.Close
	End If
	C1.Close
	End If

	gps_boton_doe = "0"
	muestraBoleta = False
	b_whats.Visible =False
	If l_total.Text <> Null Then Tels.Visible = False
End Sub

Sub Printer1_Connected (Success As Boolean)
'	If Logger Then Log("Printer1_Connected")
	If Success Then
		ToastMessageShow("Impresora conectada", False)
		Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("MACIMP"))
		Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MACIMP",Starter.mac_impresora))
		If logger Then LogColor("Impresora conectada", Colors.Green)
'		B_IMP2.Enabled = True
		impresoraConectada = True
	Else
'		Msgbox(Printer1.ConnectedErrorMsg, "Error connecting.") 'ignore
'		ToastMessageShow("Error conectando la impresora", False)
		If logger Then LogColor("Error conectando la impresora", Colors.Red)
	End If
End Sub

Sub GPS_LocationChanged (Location1 As Location)
	'Este codigo se corre desde Tracker/flp_LocationChanged
	b_ubicacion.TextColor = Colors.Gray
	Sleep(200)
	b_ubicacion.TextColor = Colors.White
	If logger Then Log($"${Location1.Latitude}, ${Location1.Longitude}, ${Location1.Accuracy}"$)

	If m_lat = Null Or m_lat = "" Then m_lat = 0
	If m_lon = Null Or m_lon = "" Then m_lon = 0

	Private ubicacionTienda As Location
	ubicacionTienda.Initialize
	ubicacionTienda.Latitude = m_lat
	ubicacionTienda.Longitude = m_lon
	If logger Then Log($"Tienda:${ubicacionTienda.Latitude}, ${ubicacionTienda.Longitude}"$)
	b_ubicacion.TextSize = 13
	b_ubicacion.Text = $"Precisión GPS $1.0{Location1.Accuracy} m"$
	If Location1.Accuracy > 200 Then
		b_ubicacion.TextColor = Colors.Red
		b_ubicacion.TextSize = 16
		b_ubicacion.Text = $"Mala señal $1.0{Location1.Accuracy} m"$
	End If
	laDist= Location1.DistanceTo(ubicacionTienda)
	l_ubicacion2.Text = $"Dist: $1.0{laDist} mts."$
	If laDist > 300 Then l_ubicacion2.TextColor = Colors.Red Else l_ubicacion2.TextColor = Colors.Black

	'''' GEO CERCA
	'''' esto es para la geocerca validar tambien el las variables del whats y del no venta que las borra si existe venta
	Dim l1, l2 As Location
	l1.Initialize2(Starter.lat_gps, Starter.lon_gps)
	
	
'	Log($"Coordenadas de la tienda - lat:${m_lat}, lon:${m_lon}"$)
	l2.Initialize2(m_lat, m_lon)
	
	Dim distance As Long
	distance =    l1.DistanceTo(l2)  ' resultado en metros
	gest.Visible = True
	
	gps_boton_doe ="1"
'	LogColor($"Distancia actual: ${distance}"$, Colors.Blue)
	If distance <= 5000000000000 Or usuario = "KMTSKLL1" Then
'		If pgs_boton_noventa = "1" Then Tels.Visible = True
		If gps_boton_doe ="1" Then b_whats.Visible = True
		B_VENTA.Visible = True
		Tels.Visible = True
		If l_total.Text <> Null And l_total.Text <> "null" Then
'			Log("Hide NoVenta" & "|" & l_total.Text & "|")
			Tels.Visible = False
		End If
		pedido_doe_muestra
	Else
		Tels.Visible = False
		B_VENTA.Visible = False
		b_whats.Visible = False
	End If
	''' fin de la geocerca
End Sub

Sub ListView1_ItemLongClick (Position As Int, Value As Object)
	
End Sub

Sub gest_Click
	Starter.tipov = "PREVENTA"
	Subs.iniciaActividad("Productos")
End Sub

Sub Tels_Click
	Subs.iniciaActividad("noventa")
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
	' BACK key pressed
	'Return True to close, False to cancel
	If PNL_TOTALES.Visible Then
		PNL_TOTALES.Visible = False
		P_BOLETA.Visible = False
		P_INF_GENERAL.Visible = True
		Log("Panel general="&P_INF_GENERAL.Visible)
		Subs.iniciaActividad("Principal")
	else if p_pideGeoPass.Visible Then
		p_pideGeoPass.Visible = False
	else if Panel_INV_A.Visible Then
		Panel_INV_A.Visible = False
		P_INF_GENERAL.Visible = True
		If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
	Else
		Msgbox("Presione Guardar para continuar","Aviso") 'ignore
	End If
	Return False
End Sub

Sub Tar_Click
	Subs.iniciaActividad("nota")
End Sub

Sub DATOS_Click
	Subs.iniciaActividad("telefonos")
End Sub

Sub Guardar_Click
	Log("GUARDAR")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	If Starter.lat_gps = 0 Or Starter.lat_gps = Null Then
		Private coords As List = Subs.traeCoordsDeBD
		Starter.lat_gps = coords.Get(0)
		Starter.lon_gps = coords.Get(1)
	End If
	c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	If l_total.Text <> Null And l_total.Text <> "null" Then Subs.ponImpreso(clie_id) 'Solo lo marcamos com impreso si tiene venta (total > 0).
	c=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	If c.GetString("CUANTOS") > 0 Then
		Starter.skmt.ExecNonQuery("delete from NOVENTA where NV_CLIENTE In (select cuenta from cuentaa)")
		Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
		Starter.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) VALUES (?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), Starter.lon_gps, Starter.lat_gps))
		Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
	End If
	s=Starter.skmt.ExecQuery("SELECT count(*)  AS FOLIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	s.Position = 0
	If s.GetString("FOLIO") > 0 Then
		c=Starter.skmt.ExecQuery("SELECT SUM(PE_FOLIO) AS FOLIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
		c.Position = 0
	End If
	s.Close
	Starter.skmt.ExecNonQuery("delete from pedido3")
	Starter.skmt.ExecNonQuery("INSERT INTO PEDIDO3 (PE_PRECIO2,	PE_TIPO,	PE_DESC,	PE_COSTO_SIN,	PE_RUTA,	PE_CEDIS,	 PE_COSTO_TOT,	 PE_COSTOU,	 PE_CANT,	PE_PRONOMBRE,	PE_PROID,	PE_CLIENTE,	PE_USUARIO ) SELECT PE_PRECIO2,	PE_TIPO, PE_DESC, PE_COSTO_SIN,	PE_RUTA, PE_CEDIS,	SUM(PE_COSTO_TOT) AS PE_COSTO_TOT,	 PE_COSTOU,	SUM(PE_CANT) As PE_CANT,	PE_PRONOMBRE,	PE_PROID,	PE_CLIENTE,		PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) GROUP BY PE_PRECIO2,	PE_TIPO,	PE_DESC,	PE_COSTO_SIN,	PE_RUTA,	PE_CEDIS,	PE_COSTOU, PE_PRONOMBRE,	PE_PROID, PE_CLIENTE ")
	c=Starter.skmt.ExecQuery("select PE_PRECIO2,PE_TIPO,PE_DESC,PE_COSTO_SIN,PE_RUTA,PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,	PE_FECHA,PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Starter.skmt.ExecNonQuery2("UPDATE PEDIDO3 SET PE_FECHA= ? WHERE PE_CLIENTE = ? AND PE_PRONOMBRE = ? AND PE_PROID = ?  AND PE_CEDIS = ? ", Array As Object(c.GetString("PE_FECHA"), c.GetString("PE_CLIENTE"),c.GetString("PE_PRONOMBRE"),c.GetString("PE_PROID"),c.GetString("PE_CEDIS")))
		Next
	End If
	c.Close
	Starter.skmt.ExecNonQuery2("UPDATE PEDIDO3 SET PE_FOLIO = ? WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As Object(YA_IMPRIMIO2))
	Starter.skmt.ExecNonQuery("delete from pedido WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) ")
	Starter.skmt.ExecNonQuery("INSERT INTO PEDIDO SELECT * FROM PEDIDO3")
	Starter.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_FECHA = ?  WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) and PE_FECHA IS NULL", Array As Object(sDate & sTime))
	Starter.skmt.ExecNonQuery("delete from PEDIDO where PE_CANT = 0") 'Mod por CHV para que borre los productos que esten con cantidad 0 - 211228
	Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("ULTIMOMODULO"))
	Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("ULTIMOMODULO", "seleccion"))
'	Activity.Finish
	CallSubDelayed(Tracker, "StartFLP")
	If logger Then LogColor("Cerramos Cliente, iniciamos Principal", Colors.blue)
'	B4XPages.ShowPage("Principal")
	Starter.ultima_back_productos = 0
	B4XPages.ShowPageAndRemovePreviousPages("Principal")
End Sub

Sub NUEVO_Click
	Subs.iniciaActividad("nuevocliente")
End Sub

Sub HIST_Click
	Subs.iniciaActividad("Historico")
End Sub

Sub BT_QR_Click
	Dim scan_width As Int
	Dim scan_height As Int
	scan_width = 400
	scan_height = 400
	sc.BeginScan("sc","CODIGO CLIENTE",scan_width,scan_height)
End Sub

Sub sc_result(atype As String,Values As String)
	'Log("Type : " & atype)
	'Log("Value : " & Values)
	CODIGO = Values
	Starter.skmt.ExecNonQuery2("UPDATE kmt_info set CAT_CL_NUM_SERIEFISICO = ?, CAT_CL_LONG = ?, CAT_CL_LAT =? where CAT_CL_CODIGO In (select cuenta from cuentaa)", Array As Object(CODIGO, Starter.lon_gps, Starter.lat_gps))
End Sub

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

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

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

Sub B_IMP_Click
	Starter.skmt.Close : Log("Cerramos BD") : Starter.revisaBD
	Subs.panelAnchoAlto(Panel_INV_A, Root.Width, Root.Height)
	Panel_INV_A.Visible = True
	P_INF_GENERAL.Visible = False
	If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
	L_INVA.Clear
	Dim label1 As Label
	label1 = L_INVA.TwoLinesLayout.Label
	label1.TextSize = 14
	label1.TextColor = Colors.Black
	Dim label2 As Label
	label2 = L_INVA.TwoLinesLayout.SecondLabel
	label2.TextSize = 14
	label2.TextColor = Colors.Black
'	Aqui es donde esta el pedo de julieta de los descuentos, quitar el precio2 pero meter un if para saber si es ruta especial o es normal o que show.
	s=Starter.skmt.ExecQuery2 ("select CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_ALMACEN  from cat_gunaprod2 where CAT_GP_CLASIF <> ? ORDER BY CAT_GP_NOMBRE ", Array As String("PROMOS"))
	If s.RowCount>0 Then
		For i=0 To S.RowCount -1
			s.Position=i
			S1=Starter.skmt.ExecQuery2("select CAT_GP_ALMACEN from cat_gunaprod5 where CAT_GP_ID = ?", Array As String(s.GetString("CAT_GP_ID")))
			S1.Position=0
			S3=Starter.skmt.ExecQuery2("select count(*) as CUANTOS from HIST_ABORDO where HIST_PROID = ?", Array As String(s.GetString("CAT_GP_ID")))
			S3.Position=0
			If S3.GetString("CUANTOS") > 0  Then
				S2=Starter.skmt.ExecQuery2("select HIST_CANT from HIST_ABORDO where HIST_PROID = ?", Array As String(s.GetString("CAT_GP_ID")))
				S2.Position=0
				a_inicial =  S1.GetString("CAT_GP_ALMACEN") -  S2.GetString("HIST_CANT")
			Else
				a_inicial =  S1.GetString("CAT_GP_ALMACEN")
			End If
			a_inicial_5 = S1.GetString("CAT_GP_ALMACEN")
			If S3.GetString("CUANTOS") > 0  Then
				ABORDO = S2.GetString("HIST_CANT")
			Else
				ABORDO = 0
			End If
			a_total =  S1.GetString("CAT_GP_ALMACEN")
			C4=Starter.skmt.ExecQuery2("select  count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) <> ? AND PE_PROID = ? AND PE_TIPO = ? ", Array As String("CAMBIO", s.GetString("CAT_GP_ID"), "VENTA"))
			C4.Position=0
			If C4.GetString("CUANTOS") > 0 Then
				C3=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE, sum(PE_COSTO_TOT) AS TOTAL from pedido where substr(pe_pronombre,1,6) <> ? AND PE_PROID = ? AND PE_TIPO = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO", s.GetString("CAT_GP_ID"), "VENTA"))
				C3.Position=0
				a_venta = C3.GetString("CANTIDAD")
				a_VENTA_F =  C3.GetString("TOTAL")
			Else
				a_venta = 0
				a_VENTA_F = 0
			End If
			C4.Close
			
			C4=Starter.skmt.ExecQuery2("select  count(*) as CUANTOS  from pedido where substr(pe_pronombre,1,6) = ? AND PE_PROID = ? ", Array As String("CAMBIO", s.GetString("CAT_GP_ID")))
			C4.Position=0
			If C4.GetString("CUANTOS") > 0 Then
				C1=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE from pedido where substr(pe_pronombre,1,6) = ? AND PE_PROID = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO", s.GetString("CAT_GP_ID")))
				C1.Position=0
				RMI = C1.GetString("CANTIDAD")
				C1.Close
			Else
				RMI = 0
			End If
			C4.Close
			a_final = a_inicial_5 - a_venta
			L_INVA.AddTwoLines(s.GetString("CAT_GP_NOMBRE"), "II-" & a_inicial & ".CD." & ABORDO & ".IIT." & a_total &  ".VT." & a_venta & "..$" & a_VENTA_F & ".IF." & a_final & ".RMI." & RMI)
		Next
	End If
	s.Close
End Sub

Sub B_IMP2_Click
	Log("inicia B_IMP2_Click")
	B_IMP2.Enabled = False
	If l_total.Text <> Null And l_total.Text <> "null" Then Subs.ponImpreso(la_cuenta.Text) 'Solo lo marcamos como impreso si tiene venta (total > 0).
	ProgressDialogShow("Imprimiendo, un momento ...")
	Printer1.DisConnect
	If Not(Printer1.IsConnected) Then
		If logger Then Log("conectando 1")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada)
			Sleep(1000)
			cont = cont + 1
			If cont = 7 Then Printer1.Connect 'Tratamos de reconectar
			If cont > 15 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	Else
		If logger Then Log("conectando 2")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada) Or Not(Printer1.IsConnected)
			Sleep(1000)
			cont = cont + 1
			If cont = 2 Then Printer1.Connect
			If cont > 4 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	End If
'	If Logger Then Log($"Impresora Conectada: ${Printer1.IsConnected}"$)
	If la_cuenta.Text <> "0" And la_cuenta.Text <> "null" Then
		Starter.skmt.ExecNonQuery2("UPDATE PEDIDO SET PE_TIPO = ?   WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) ", Array As Object("VENTA"))
		Starter.skmt.ExecNonQuery("UPDATE kmt_info set IMPRESION = 1  where CAT_CL_CODIGO In (select cuenta from cuentaa)")''
		Guardar.Visible = True
	End If
	Starter.skmt.ExecNonQuery("delete from pedido3")
	Starter.skmt.ExecNonQuery("INSERT INTO PEDIDO3 (PE_PRECIO2,	PE_TIPO,	PE_DESC,	PE_COSTO_SIN,	PE_RUTA,	PE_CEDIS,	 PE_COSTO_TOT,	 PE_COSTOU,	 PE_CANT,	PE_PRONOMBRE,	PE_PROID,	PE_CLIENTE,	PE_USUARIO ) SELECT PE_PRECIO2,	PE_TIPO, PE_DESC, PE_COSTO_SIN,	PE_RUTA, PE_CEDIS,	SUM(PE_COSTO_TOT) AS PE_COSTO_TOT,	 PE_COSTOU,	SUM(PE_CANT) As PE_CANT,	PE_PRONOMBRE,	PE_PROID,	PE_CLIENTE,		PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) GROUP BY PE_PRECIO2,	PE_TIPO,	PE_DESC,	PE_COSTO_SIN,	PE_RUTA,	PE_CEDIS,	PE_COSTOU, PE_PRONOMBRE,	PE_PROID, PE_CLIENTE ")
	c=Starter.skmt.ExecQuery("select PE_PRECIO2,PE_TIPO,PE_FOLIO,PE_DESC,PE_COSTO_SIN,PE_RUTA,PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,	PE_FECHA,PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			Starter.skmt.ExecNonQuery2("UPDATE PEDIDO3 SET PE_FECHA= ? WHERE PE_CLIENTE = ? AND PE_PRONOMBRE = ? AND PE_PROID = ?  AND PE_CEDIS = ? AND PE_FOLIO = ?", Array As Object(c.GetString("PE_FECHA"), c.GetString("PE_CLIENTE"),c.GetString("PE_PRONOMBRE"),c.GetString("PE_PROID"),c.GetString("PE_CEDIS"), c.GetString("PE_FOLIO")))
		Next
	End If
	Starter.skmt.ExecNonQuery("delete from pedido WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) ")
	Starter.skmt.ExecNonQuery("INSERT INTO PEDIDO SELECT * FROM PEDIDO3")
	
	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.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	c=Starter.skmt.ExecQuery2("SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION =?", Array As String ("SUCURSAL"))
	c.Position = 0
	sucursal = c.GetString("CAT_VA_VALOR")
	c.Close
	TAMANO = 0
	ESPACIO = 14
	BLANCO = " "
	'esto para las impresoras nuevas
	'printer.Initialize(cmp20.OutputStream)
	Printer1.Reset
	Dim bmp As Bitmap
	bmp.InitializeResize(File.DirAssets, "kelloggs.png", 376, 129, True) 'ignore
	Dim myimage As AnImage = Printer1.ImageToBWIMage(bmp)
	myimage = Printer1.DitherImage2D(myimage, 128)
	myimage= Printer1.PackImage(myimage)
	
	Printer1.WriteString(CRLF) ' nudge the printer to show the user something is happening
	Printer1.WriteString(Printer1.REVERSE)
	Printer1.PrintImage(myimage)
	Printer1.WriteString(Printer1.UNREVERSE)
	''	Printer1.Justify = 1
	If la_cuenta.Text = "0" Then
		Try
			Printer1.WriteString("KELLOGG COMPANY MEXICO"  & CRLF)
			Printer1.WriteString(sDate &" " & sTime  &  CRLF)
			Printer1.WriteString("Vendedor:" & usuario  &  CRLF)
			Printer1.WriteString("Ruta:" & ruta_tienda  &  CRLF)
			Printer1.WriteString("Tienda: " & La_nombre.Text  & CRLF)
			Printer1.WriteString("ID.Cliente: " &  la_cuenta.Text  & CRLF)
			Printer1.WriteString("Calle: " & la_Calle.Text  & CRLF)
			Printer1.WriteString("Colonia: " & la_col.Text  & CRLF)
			Printer1.WriteString("C.P.: " & la_cp.Text  & CRLF)
			Printer1.WriteString("Entre calle1: " & l_entre1.Text  & CRLF)
			Printer1.WriteString("Entre Calle2: " & l_entre2.Text  & CRLF)
			Printer1.WriteString(" " & CRLF)
			Printer1.WriteString("------------------------------"  & CRLF)
			Printer1.WriteString("PEDIDO" & CRLF)
			Printer1.WriteString("------------------------------"  & CRLF)
			s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and substr(pe_pronombre,1,6) <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE", Array As String("ABORDO","CAMBIO"))
			If S.RowCount>0 Then
				For i=0 To S.RowCount -1
					S.Position=i
					If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
						Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
					Else
						Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
						Private strT As String = ""
						strT = s.GetString("L_CANT")&s.GetString("L_COSTOU")&s.GetString("L_COSTO_TOT")
						TAMANO = strT.Length
						ESPACIO = ESPACIO - TAMANO
						For E=0 To ESPACIO -1
							BLANCO = " " & BLANCO
						Next
'						If Logger Then Log($"|${ESPACIO}|, |${TAMANO}|, |${BLANCO}|"$)
						Private pecostou As String = 0
						If s.GETSTRING("PE_COSTOU") <> Null And IsNumber(s.GETSTRING("PE_COSTOU")) Then pecostou = s.GETSTRING("PE_COSTOU")
						Private pecostotot As String = 0
						If s.GETSTRING("PE_COSTO_TOT") <> Null And IsNumber(s.GETSTRING("PE_COSTO_TOT")) Then pecostotot = s.GETSTRING("PE_COSTO_TOT")
						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & NumberFormat2(pecostou, 1, 2, 2, False) & "   $" & NumberFormat2(pecostotot, 1, 2, 2, False) & CRLF)
'						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
						TAMANO = 0
						ESPACIO = 14
						BLANCO = " "
					End If
				Next
			End If
			s.Close
			Printer1.WriteString(CRLF)
			Printer1.WriteString("------------RMI---------------"  & CRLF)
			s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and substr(pe_pronombre,1,6) = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE", Array As String("ABORDO","CAMBIO"))
			If S.RowCount>0 Then
				For i=0 To S.RowCount -1
					TAMANO = 0
					ESPACIO = 14
					BLANCO = " "
					S.Position=i
					If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
						Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
					Else
						Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
						Private strT As String = ""
						strT = s.GetString("L_CANT")&s.GetString("L_COSTOU")&s.GetString("L_COSTO_TOT")
						TAMANO = strT.Length
						ESPACIO = ESPACIO - TAMANO
						For E=0 To ESPACIO -1
							BLANCO = " " & BLANCO
						Next
						Private pecostou As String = 0
						If s.GETSTRING("PE_COSTOU") <> Null And IsNumber(s.GETSTRING("PE_COSTOU")) Then pecostou = s.GETSTRING("PE_COSTOU")
						Private pecostotot As String = 0
						If s.GETSTRING("PE_COSTO_TOT") <> Null And IsNumber(s.GETSTRING("PE_COSTO_TOT")) Then pecostotot = s.GETSTRING("PE_COSTO_TOT")
						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & NumberFormat2(pecostou, 1, 2, 2, False) & "   $" & NumberFormat2(pecostotot, 1, 2, 2, False) & CRLF)
'						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
						TAMANO = 0
						ESPACIO = 14
						BLANCO = " "
					End If
					If logger Then Log($"|${ESPACIO}|, |${TAMANO}|, |${BLANCO}|"$)
				Next
			End If
			s.Close
			Printer1.WriteString(CRLF)
			
			s=Starter.skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("ABORDO"))
			s.Position =0
			Private sTotal1 As Double
			If s.GetString("TOTAL") <> Null And IsNumber(s.GETSTRING("TOTAL")) Then
				sTotal1 = s.GetString("TOTAL")
			Else
				sTotal1 = 0
			End If
			Printer1.WriteString( "Total entrega:   $"  & NumberFormat2(sTotal1, 1, 2, 2, False) & CRLF)
			
			Printer1.WriteString("==============================="  & CRLF)
			''bold para las nuevas impresoras
			Private total3 As String = 0
			If s.GETSTRING("TOTAL") <> Null And IsNumber(s.GETSTRING("TOTAL")) Then total3 = s.GETSTRING("TOTAL")
			Printer1.WriteString(  Printer1.BOLD &  "Total pedido:   $" & NumberFormat2(total3, 1, 2, 2, False) & CRLF)

			s.Close
			s=Starter.skmt.ExecQuery2("select SUM(PE_CANT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("ABORDO"))
			s.Position =0
			Private total4 As String = "0"
			If s.GetString("TOTAL") <> Null And IsNumber(s.GetString("TOTAL")) Then total4 = s.GetString("TOTAL")
			Printer1.WriteString( Printer1.BOLD &   "No. Productos: " & total4 & CRLF)
			Printer1.WriteString("==============================="  & CRLF)
			s.Close
			Printer1.WriteString(Printer1.DEFAULTS)

'			printer.WriteLine("------------VENTA-------------")
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
	
			Printer1.WriteString(  "Nombre y Firma del cliente" & CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString("______________________________" & CRLF)
			Printer1.WriteString("------------------------------" & CRLF)
			Printer1.WriteString("----ESTE TICKET NO ES UN -----" & CRLF)
			Printer1.WriteString("--COMPROBANTE FISCAL, SOLO ES-" & CRLF)
			Printer1.WriteString("--------INFORMATIVO-----------" & CRLF)
			Printer1.WriteString("------------------------------" & CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			'printer.Close
			Sleep(1000)
			Printer1.DisConnect
		Catch
			ToastMessageShow("Error en la impresion 1.", True)
			Printer1.Disconnect
			B4XPages.ShowPage("Principal")
		End Try
	Else
		Try
			DateTime.DateFormat = "yyyymmdd"
			sDate=DateTime.Date(DateTime.Now)
			Printer1.WriteString("KELLOGG COMPANY MEXICO" & CRLF)
			Printer1.WriteString("No. Ticket: " & sDate &  la_cuenta.Text & CRLF)
		
			DateTime.DateFormat = "MM/dd/yyyy"
			sDate=DateTime.Date(DateTime.Now)
		
			Printer1.WriteString(sDate &" " & sTime & CRLF)
			Printer1.WriteString("Vendedor:" & usuario & CRLF)
			Printer1.WriteString("Ruta:" & ruta_tienda & CRLF)
			Printer1.WriteString("Tienda: " & La_nombre.Text & CRLF)
			Printer1.WriteString("ID.Cliente: " &  la_cuenta.Text & CRLF)
			Printer1.WriteString("Calle: " & la_Calle.Text & CRLF)
			Printer1.WriteString("Colonia: " & la_col.Text & CRLF)
			Printer1.WriteString("C.P.: " & la_cp.Text & CRLF)
			Printer1.WriteString("Entre calle1: " & l_entre1.Text & CRLF)
			Printer1.WriteString("Entre Calle2: " & l_entre2.Text & CRLF)
			Printer1.WriteString(" " & CRLF)
			
			''''''' PEDIDOS DOE
			
			s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_CEDIS = ?  AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_CEDIS,PE_PRONOMBRE", Array As String("DOE"))
			
			''		s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and pe_codpromo = ? and substr(pe_pronombre,1,6) <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_CEDIS,PE_PRONOMBRE", Array As String("VENTA", "DOE", "CAMBIO"))
			If S.RowCount>0 Then
				Printer1.WriteString("------------------------------"  & CRLF)
				Printer1.WriteString("PEDIDO DON TOÑO" & CRLF)
				Printer1.WriteString("------------------------------"  & CRLF)
				For i=0 To S.RowCount -1
					S.Position=i
					
					If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
						Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
					Else
						Private strT As String = ""
						Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
						Private strT As String = ""
						strT = s.GetString("L_CANT")&s.GetString("L_COSTOU")&s.GetString("L_COSTO_TOT")
						TAMANO = strT.Length
						ESPACIO = ESPACIO - TAMANO
						For E=0 To ESPACIO -1
							BLANCO = " " & BLANCO
						Next
						Private pecostou As String = 0
						If s.GETSTRING("PE_COSTOU") <> Null And IsNumber(s.GETSTRING("PE_COSTOU")) Then pecostou = s.GETSTRING("PE_COSTOU")
						Private pecostotot As String = 0
						If s.GETSTRING("PE_COSTO_TOT") <> Null And IsNumber(s.GETSTRING("PE_COSTO_TOT")) Then pecostotot = s.GETSTRING("PE_COSTO_TOT")
						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & NumberFormat2(pecostou, 1, 2, 2, False) & "   $" & NumberFormat2(pecostotot, 1, 2, 2, False) & CRLF)
'						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
'						If Logger Then Log($"|${ESPACIO}|, |${TAMANO}|, |${BLANCO}|"$)
						TAMANO = 0
						ESPACIO = 14
						BLANCO = " "
					End If
				Next
			End If
			s.Close
			
			s=Starter.skmt.ExecQuery2("select sum(PE_CANT) as CANTIDAD, SUM(PE_COSTO_TOT) AS TOTAL  FROM PEDIDO WHERE PE_CEDIS <> PE_PROID AND PE_CEDIS = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("DOE"))
			s.Position = 0
			Private sTotal2 As Double
			If s.GetString("TOTAL") <> Null And IsNumber(s.GETSTRING("TOTAL")) Then
				sTotal2 = s.GetString("TOTAL")
				Printer1.WriteString(  $"Sub Total :   $${NumberFormat2(sTotal2, 1, 2, 2, False)}"$ & CRLF)
			
			Else
				sTotal2 = 0
			End If
			Private cantidad1 As String = "0"
			If s.GetString("CANTIDAD") <> Null And IsNumber(s.GetString("CANTIDAD")) Then
				cantidad1 = s.GetString("CANTIDAD")
			
				Printer1.WriteString(  "No. Productos: " & cantidad1 & CRLF)
				Printer1.WriteString("------------------------------"  & CRLF)
				Printer1.WriteString("FIN PEDIDO DON TOÑO" & CRLF)
				Printer1.WriteString("------------------------------"  & CRLF)
			End If
			
			'	Printer1.WriteString(CRLF)
			s.Close
			''''SE MODIFCA EL QUERY POR LOS PEDIDOS DOE
			S=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and substr(pe_pronombre,1,6) <> ? AND PE_CEDIS <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_CEDIS,PE_PRONOMBRE", Array As String("VENTA","CAMBIO","DOE"))
			
			Printer1.WriteString("------------------------------"  & CRLF)
			Printer1.WriteString("VENTA" & CRLF)
			Printer1.WriteString("------------------------------"  & CRLF)
			''s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and pe_codpromo <> ? and substr(pe_pronombre,1,6) <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_CEDIS,PE_PRONOMBRE", Array As String("VENTA", "DOE", "CAMBIO"))
			If S.RowCount>0 Then
				For i=0 To S.RowCount -1
					S.Position=i
					If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
						Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
					Else
						Private strT As String = ""
						Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
						Private strT As String = ""
						strT = s.GetString("L_CANT")&s.GetString("L_COSTOU")&s.GetString("L_COSTO_TOT")
						TAMANO = strT.Length
						ESPACIO = ESPACIO - TAMANO
						For E=0 To ESPACIO -1
							BLANCO = " " & BLANCO
						Next
						Private pecostou As String = 0
						If s.GETSTRING("PE_COSTOU") <> Null And IsNumber(s.GETSTRING("PE_COSTOU")) Then pecostou = s.GETSTRING("PE_COSTOU")
						Private pecostotot As String = 0
						If s.GETSTRING("PE_COSTO_TOT") <> Null And IsNumber(s.GETSTRING("PE_COSTO_TOT")) Then pecostotot = s.GETSTRING("PE_COSTO_TOT")
						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & NumberFormat2(pecostou, 1, 2, 2, False) & "   $" & NumberFormat2(pecostotot, 1, 2, 2, False) & CRLF)
'						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
'						If Logger Then Log($"|${ESPACIO}|, |${TAMANO}|, |${BLANCO}|"$)
						TAMANO = 0
						ESPACIO = 14
						BLANCO = " "
					End If
				Next
			End If
			s.Close
			s=Starter.skmt.ExecQuery2("select sum(PE_CANT) as CANTIDAD, SUM(PE_COSTO_TOT) AS TOTAL  FROM PEDIDO WHERE PE_CEDIS <> PE_PROID AND PE_TIPO = ? and substr(pe_pronombre,1,6) <> ? AND PE_CEDIS <> ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA","CAMBIO","DOE"))
			s.Position = 0
			Private sTotal2 As Double
			If s.GetString("TOTAL") <> Null And IsNumber(s.GETSTRING("TOTAL")) Then
				sTotal2 = s.GetString("TOTAL")
			Else
				sTotal2 = 0
			End If
			Printer1.WriteString(Printer1.REVERSE & "==============================="  & CRLF)
			Printer1.WriteString( Printer1.UNREVERSE & Printer1.BOLD & $"Sub Total Venta:   $${NumberFormat2(sTotal2, 1, 2, 2, False)}"$ & CRLF)
			Private cantidad1 As String = "0"
			If s.GetString("CANTIDAD") <> Null And IsNumber(s.GetString("CANTIDAD")) Then cantidad1 = s.GetString("CANTIDAD")
			Printer1.WriteString( Printer1.UNREVERSE & Printer1.BOLD & "No. Productos: " & cantidad1 & CRLF)
			Printer1.WriteString(CRLF)
			s.Close
			Printer1.WriteString("------------RMI---------------"  & CRLF)
			s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? and substr(pe_pronombre,1,6) = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA","CAMBIO"))
			If S.RowCount>0 Then
				For i=0 To S.RowCount -1
					S.Position=i
					If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
						Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
					
					Else
						Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
						Private strT As String = ""
						strT = s.GetString("L_CANT")&s.GetString("L_COSTOU")&s.GetString("L_COSTO_TOT")
						TAMANO = strT.Length
						ESPACIO = ESPACIO - TAMANO
						For E=0 To ESPACIO -1
							BLANCO = " " & BLANCO
						Next
						Private pecostou As String = 0
						If s.GETSTRING("PE_COSTOU") <> Null And IsNumber(s.GETSTRING("PE_COSTOU")) Then pecostou = s.GETSTRING("PE_COSTOU")
						Private pecostotot As String = 0
						If s.GETSTRING("PE_COSTO_TOT") <> Null And IsNumber(s.GETSTRING("PE_COSTO_TOT")) Then pecostotot = s.GETSTRING("PE_COSTO_TOT")
						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & NumberFormat2(pecostou, 1, 2, 2, False) & "   $" & NumberFormat2(pecostotot, 1, 2, 2, False) & CRLF)
'						Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
						If logger Then Log($"|${ESPACIO}|, |${TAMANO}|, |${BLANCO}|"$)
						TAMANO = 0
						ESPACIO = 14
						BLANCO = " "
					End If
				Next
			End If
			s.Close
		
			s=Starter.skmt.ExecQuery2("select sum(PE_CANT) as CANTIDAD, SUM(PE_COSTO_TOT) AS TOTAL  FROM PEDIDO WHERE  PE_CEDIS <> PE_PROID AND  PE_TIPO = ? and substr(pe_pronombre,1,6) = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA","CAMBIO"))
			s.Position = 0
			Private sTotal3 As Double
			If s.GetString("TOTAL") <> Null And IsNumber(s.GetString("TOTAL")) Then
				sTotal3 = s.GetString("TOTAL")
			Else
				sTotal3 = 0
			End If
			Printer1.WriteString(Printer1.REVERSE & "==============================="  & CRLF)
			Printer1.WriteString(Printer1.UNREVERSE & Printer1.BOLD &  "Sub Total CAMBIOS:   $" & NumberFormat2(sTotal3, 1, 2, 2, False) & CRLF)
			Private cantidad2 As String = "0"
			If s.GetString("CANTIDAD") <> Null And IsNumber(s.GetString("CANTIDAD")) Then cantidad2 = s.GetString("CANTIDAD")
			Printer1.WriteString( Printer1.UNREVERSE & Printer1.BOLD & "No. Productos: " & cantidad2 & CRLF)
			Printer1.WriteString(CRLF)
			s.Close
			Printer1.WriteString(CRLF)
			s=Starter.skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA"))
			s.Position =0
			Printer1.WriteString(Printer1.REVERSE & "==============================="  & CRLF)
			Private total2 As String = 0
			If s.GETSTRING("TOTAL") <> Null And IsNumber(s.GETSTRING("TOTAL")) Then total2 = s.GETSTRING("TOTAL")
			Printer1.WriteString(Printer1.UNREVERSE & Printer1.BOLD & "Total venta:   $" & NumberFormat2(total2, 1, 2, 2, False) & CRLF)
'			Printer1.WriteString(Printer1.UNREVERSE & Printer1.BOLD & "Total venta:   $" & s.GetString("TOTAL") & CRLF)
'			Printer1.WriteString("==============================="  & CRLF)
'		
'			Printer1.WriteString( "Total venta:   $" & s.GetString("TOTAL") & CRLF)
			s.Close
			s=Starter.skmt.ExecQuery2("select SUM(PE_CANT) AS TOTAL FROM PEDIDO WHERE  PE_CEDIS <> PE_PROID AND PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA"))
			s.Position =0
			Private total5 As String = "0"
			If s.GetString("TOTAL") <> Null And IsNumber(s.GetString("TOTAL")) Then total5 = s.GetString("TOTAL")
			Printer1.WriteString(Printer1.BOLD & "No. Productos vendidos: " & (total5 - cantidad2) & CRLF)
			Printer1.WriteString(Printer1.BOLD & "Producto devuelto : " & cantidad2 & CRLF)
			Printer1.WriteString(Printer1.REVERSE & "==============================="  & CRLF)
'			Printer1.WriteString( "No. Productos: " & s.GetString("TOTAL") & CRLF)
'			Printer1.WriteString( "==============================="  & CRLF)
			s.Close
			Printer1.WriteString(Printer1.UNREVERSE)
			Printer1.WriteString(Printer1.NOBOLD)
'			printer.WriteLine("------------VENTA-------------")
'			printer.WriteLine("TOTAL COMPRA: $:" & total_cliente)
'			Printer1.WriteString(Printer1.DEFAULTS & CRLF)
			Printer1.WriteString(CRLF)
			'	Printer1.WriteString(Printer1.SINGLE)
			'Printer1.WriteString("------------------------------")
			'	Printer1.WriteString(Printer1.HIGH)
			'	Printer1.Justify = 1
			Printer1.WriteString( "Nombre y Firma del cliente" & CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			'	Printer1.WriteString(Printer1.DEFAULTS)
			'	Printer1.WriteString(Printer1.SINGLE)
			Printer1.WriteString("______________________________" & CRLF)
			Printer1.WriteString("------------------------------" & CRLF)
			Printer1.WriteString("----ESTE TICKET NO ES UN -----" & CRLF)
			Printer1.WriteString("--COMPROBANTE FISCAL, SOLO ES-" & CRLF)
			Printer1.WriteString("--------INFORMATIVO-----------" & CRLF)
			Printer1.WriteString("------------------------------" & CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Printer1.WriteString(CRLF)
			Sleep(1000)
			Printer1.DisConnect
		Catch
			ToastMessageShow("Error en la impresion 2.", True)
			Printer1.Disconnect
			B4XPages.ShowPage("Principal")
		End Try
	End If
	Sleep(1000)
	B_IMP2.Enabled = True
	ProgressDialogHide
'	If Logger Then Log("Habilitamos boton")
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.Connect(PairedDevices.Get(PairedDevices.GetKeyAt(0)))
		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


Sub B_VENTA_Click
	If la_cuenta.Text = "0" Then
		Starter.tipov = "ABORDO"
		Subs.iniciaActividad("Productos")
	Else
		Cuestionario
	End If
End Sub

'Muestra un boton con las dimensiones, posicion y texto especificados.
Sub muestraBoton (thisButton As Button, theText As String, Left As Int, Top As Int, width As Int, height As Int)
	thisButton.Text = theText
	thisButton.Tag = theText
	thisButton.Left = Left
	thisButton.Top = Top
	thisButton.Width = width
	thisButton.Height = height
	thisButton.Visible = True
End Sub

'Muestra un boton con las dimensiones, posicion y texto especificados.
Sub muestraBotonCentrado (thisButton As Button, theText As String, Top As Int, width As Int, height As Int) 'ignore
	Private anchoPantalla As Int
	thisButton.Text = theText
	thisButton.Tag = theText
	anchoPantalla = GetDeviceLayoutValues.Width
	thisButton.Left = (anchoPantalla/2) - (width/2)
	thisButton.Top = Top
	thisButton.Width = width
	thisButton.Height = height
	thisButton.Visible = True
End Sub

'Esta subrutina muestra las encuestas.
Sub Cuestionario
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	CUANTOS = 0
	If TOMAR_FOTO = 0 Then
		s=Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
		s.Position= 0
		CUANTOS = s.GetString("CUANTOS")
		Private CUANTOS2 As Int = 0
		s=Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS2 from HIST_ENCUESTA2 where HE_CLIENTE In (Select cuenta from cuentaa)")
		s.Position = 0
		CUANTOS2 = s.GetString("CUANTOS2")
		If logger Then LogColor($"Hist:encuesta=${CUANTOS}, hist_encuesta2 = ${CUANTOS2}"$, Colors.Magenta)
	End If
	If CUANTOS = 0 And CUANTOS2 = 0 Then
		c=Starter.skmt.ExecQuery("SELECT 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 FROM CAT_ENCUESTA_PREGUNTA ORDER BY CAT_CE_DESCRIPCION, CAST(CAT_EP_ORDEN_PREGUNTA AS DECIMAL)")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				If TOMAR_FOTO = 1 Then
					If CURSOR_FOTO + 1 > c.RowCount -1 Then
						TOMAR_FOTO = 0
						Exit
					Else
						i = CURSOR_FOTO +1
					End If
					'Msgbox(i,"a")
					TOMAR_FOTO = 0
				End If
				c.Position=i
				Dim tipoPregunta As String = c.GetString("CAT_EP_IDTIPOPREGUNTA")
'				If Logger Then Log("=================== "&tipoPregunta)
'				If Logger Then Log($"Pregunta tipo: ${tipoPregunta}"$)
				'		Msgbox("paso1","a")
				If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 5 Then
					id_encuesta = c.GetString("CAT_EP_ID")
					TOMAR_FOTO = 1
					CURSOR_FOTO = i
					Subs.iniciaActividad("foto")
					'		Msgbox("paso2","a")
					Exit
				ELSE IF c.GetString("CAT_EP_IDTIPOPREGUNTA") = 3 Then  ' Tipo SI/NO
					botonPresionado = 0 ' Bandera para que espere a que se conteste la pregunta
					l_titEncuesta.Text = c.GetString("CAT_CE_DESCRIPCION")
					l_txtEncuesta.Text = c.GetString("CAT_EP_PREGUNTA")
					Subs.centraEtiqueta(l_txtEncuesta, Root.Width)
					muestraBoton(b_encuesta_1,"SI", centroPantalla-350, 580, 300, 160)
					muestraBoton(b_encuesta_2, "NO", centroPantalla+50, 580, 300, 160)
					muestraEncuesta
					Do Until botonPresionado = 1 'Esperamos que respondan la pregunta
						Sleep(0)
					Loop
					Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, encuestaRes,sDate & sTime,c.GetString("CAT_EP_ID")))
					ocultaPanelEncuesta
				ELSE IF c.GetString("CAT_EP_IDTIPOPREGUNTA") = 4 Then
					res =  Msgbox2(c.GetString("CAT_EP_PREGUNTA"),c.GetString("CAT_CE_DESCRIPCION"), "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
					If res = DialogResponse.POSITIVE Then
						Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,c.GetString("CAT_EP_ID")))
					Else IF res = DialogResponse.NEGATIVE Then
						Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,c.GetString("CAT_EP_ID")))
						i = c.GetInt("CAT_EP_RES2_PRED") -2
					Else IF res = DialogResponse.CANCEL Then
						i = i -1
					End If
					'			Msgbox("paso3","a")
				ELSE If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 2 Then ' Tipo 3 opciones.
					botonPresionado = 0 ' Bandera para que espere a que se conteste la pregunta.
					l_titEncuesta.Text = c.GetString("CAT_CE_DESCRIPCION")
					l_txtEncuesta.Text = c.GetString("CAT_EP_PREGUNTA")
					muestraBoton(b_encuesta_1, c.GetString("CAT_EP_RES2_PRED"), centroPantalla-250, 580, 500, 160)
					muestraBoton(b_encuesta_2, c.GetString("CAT_EP_RES3_PRED"), centroPantalla-250, 740, 500, 160)
					muestraBoton(b_encuesta_3, c.GetString("CAT_EP_RES1_PRED"), centroPantalla-250, 900, 500, 160)
					muestraEncuesta
					Do Until botonPresionado = 1 'Esperamos que respondan la pregunta.
						Sleep(0)
					Loop
					Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, encuestaRes,sDate & sTime,c.GetString("CAT_EP_ID")))
					ocultaPanelEncuesta
				ELSE If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 6 Then
					Panel10.Visible = True
					l_chk_e.Text =  c.GetString("CAT_EP_PREGUNTA")
					Chk_1.Checked = False
					chk_2.Checked = False
					chk_3.Checked = False
					Chk_1.Text = c.GetString("CAT_EP_RES1_PRED")
					chk_2.Text =  c.GetString("CAT_EP_RES2_PRED")
					chk_3.Text =  c.GetString("CAT_EP_RES3_PRED")
					chk_1_valor =  c.GetString("CAT_EP_RES1_PRED")
					chk_2_valor =  c.GetString("CAT_EP_RES2_PRED")
					chk_3_valor =  c.GetString("CAT_EP_RES3_PRED")
					Chk_1.Tag = c.GetString("CAT_EP_ID")
					chk_2.Tag = c.GetString("CAT_EP_ID")
					chk_3.Tag = c.GetString("CAT_EP_ID")
					TOMAR_FOTO = 1
					CURSOR_FOTO = i
					Exit
				ELSE If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 1 Then
					botonPresionado = 0 ' Bandera para que espere a que se conteste la pregunta
					l_titEncuesta.Text = c.GetString("CAT_CE_DESCRIPCION")
					l_txtEncuesta.Text = c.GetString("CAT_EP_PREGUNTA")
					Subs.centraEditText(et_encuesta, Root.Width)
					et_encuesta.Visible = True
					b_encuesta_continuar.Enabled = False
					muestraBoton(b_encuesta_continuar,"Continuar", centroPantalla-250, 680, 500, 160)
					muestraEncuesta
					Do Until botonPresionado = 1 'Esperamos que respondan la pregunta
						Sleep(0)
					Loop
					Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, encuestaRes,sDate & sTime,c.GetString("CAT_EP_ID")))
					ocultaPanelEncuesta
				Else
					Starter.tipov = "VENTA"
					Subs.iniciaActividad("Productos")
				End If
			Next
		Else
			Starter.tipov = "VENTA"
			Subs.iniciaActividad("Productos")
		End If
	Else
		Starter.tipov = "VENTA"
		Subs.iniciaActividad("Productos")
	End If
End Sub

Sub b1_Click
	Log("B1 clicked")
End Sub

Sub b2_Click
	If logger Then Log("B2 clicked")
End Sub

Sub b_factura_Click
	
End Sub

Sub CH_TA_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TC_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TB_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TD_CheckedChange(Checked As Boolean)
	
End Sub

Sub B_GUARDAR_Click
	If logger Then Log("Guardar clic")
	If CH_TA.Checked = True Then
		TIPOEX = "TIPO A"
	ELSE If CH_TB.Checked = True Then
		TIPOEX = "TIPO B"
	ELSE If CH_TC.Checked = True Then
		TIPOEX = "TIPO C"
	ELSE If CH_TD.Checked = True Then
		TIPOEX = "TIPO D"
	End If
	Panel1.Visible = False
	B_EXIBI.Visible = True
	b_factura.Visible = True
	HIST.Visible = True
	c=Starter.skmt.ExecQuery("select CUENTA from cuentaa")
	c.Position = 0
	cuenta = c.GetString("CUENTA")
	Starter.skmt.ExecNonQuery2("INSERT INTO HIST_EXIBIDORES(CAT_CL_CLIENTE,CAT_CL_EXHIBIDOR,CAT_CL_BEXHIBIDOR) VALUES(?,?,?)", Array As Object(cuenta,TIPOEX,E_CUANTOS_E.Text))
End Sub

Sub B_EXIBI_Click
	Panel1.Visible = True
	B_EXIBI.Visible = False
	b_factura.Visible = False
	HIST.Visible = False
End Sub

'''''''''''''''''''''''''''''''''''''' BOLETA DE LIQUIDACION
Sub LLAMA_BOLETA
	'' FECHA DE TELEFONO
	If Subs.clienteActual = "" Then Starter.skmt.ExecNonQuery("insert into cuentaa (cuenta) values (0)")
	DateTime.DateFormat="dd/MM/yyyy"
	Edt_FH.Text=DateTime.Date(DateTime.Now)
	Subs.panelAnchoAlto(PNL_TOTALES, Root.Width, Root.Height)
	PNL_TOTALES.Visible=True
	Pnl_Billete.Visible=True
	Pnl_Moneda.visible=True
	LBL_RETURN.Visible=False
	LBL_REGRESA.Visible=False
	Subs.panelAnchoAlto(P_BOLETA, Root.Width, Root.Height)
	P_BOLETA.Visible=True
	P_INF_GENERAL.Visible=False
	If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
	LBL_REGRESA.Visible=True
	Private c As Cursor = Starter.skmt.ExecQuery("select * from TMP_CAT_BILLETE join TMP_CAT_MONEDAS")
	If c.RowCount > 0 Then
		c.Position = 0
		If logger Then Log("==================== CALCULADORA "&c.ColumnCount)
'		Traemos billetes
		EDT_CANMIL.Text = "0"
		If IsNumber(c.GetString("TMP_BILLE_MIL")) Then EDT_CANMIL.Text = c.GetString("TMP_BILLE_MIL")
		EDT_CANQUIN.Text = "0"
		If c.GetString("TMP_BILLE_QUINIENTOS")<> Null Then EDT_CANQUIN.Text = c.GetString("TMP_BILLE_QUINIENTOS")
		EDT_CANDOS.Text = "0"
		If c.GetString("TMP_BILLE_DOSCIENTOS") <>Null Then EDT_CANDOS.Text = c.GetString("TMP_BILLE_DOSCIENTOS")
		EDT_CANCIEN.Text = "0"
		If c.GetString("TMP_BILLE_CIEN")<> Null Then EDT_CANCIEN.Text = c.GetString("TMP_BILLE_CIEN")
		EDT_CANCIN.Text = "0"
		If c.GetString("TMP_BILLE_CINCUENTA")<> Null Then EDT_CANCIN.Text = c.GetString("TMP_BILLE_CINCUENTA")
		EDT_CANVEIN.Text = "0"
		If c.GetString("TMP_BILLE_VEINTE")<> Null Then EDT_CANVEIN.Text = c.GetString("TMP_BILLE_VEINTE")
'		Traemos monedas
		EDT_CANVEINTE.Text = "0"
		If c.GetString("TMP_MON_VEINTE")<> Null Then EDT_CANVEINTE.Text = c.GetString("TMP_MON_VEINTE")
		EDT_CANDIEZ.Text = "0"
		If c.GetString("TMP_MON_DIEZ")<> Null Then EDT_CANDIEZ.Text = c.GetString("TMP_MON_DIEZ")
		EDT_CANCI.Text = "0"
		If c.GetString("TMP_MON_CINCO")<> Null Then EDT_CANCI.Text = c.GetString("TMP_MON_CINCO")
		EDT_CANDO.Text = "0"
		If c.GetString("TMP_MON_DOS")<> Null Then EDT_CANDO.Text = c.GetString("TMP_MON_DOS")
		EDT_CANUN.Text = "0"
		If c.GetString("TMP_MON_UN")<> Null Then EDT_CANUN.Text = c.GetString("TMP_MON_UN")
		EDT_CANCEN.Text = "0"
		If c.GetString("TMP_MON_CENTAVOS")<> Null Then EDT_CANCEN.Text = c.GetString("TMP_MON_CENTAVOS")
		L_CALCULA_BILLE_CLICK
		L_CALCULA_MONEDA_Click
		B_SUM_TOTAL.Text = TOTALBILLETES.Text + TOTALMONEDA.text
	End If
	'Starter.boleta = 0
	c.Close
End Sub

'''BILLETES
Sub L_CALCULA_BILLE_CLICK
	If EDT_CANMIL.Text="" Or  EDT_CANQUIN.Text="" Or EDT_CANDOS.Text="" Or EDT_CANCIEN.Text="" Or EDT_CANCIN.Text="" Or EDT_CANVEIN.Text="" Then
		Pnl_Billete.RequestFocus
		Msgbox("Por favor llena todas las cantidades","") 'ignore
	Else
		LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
		LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
		LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
		LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
		LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
		LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

'20
Private Sub EDT_CANVEIN_FocusChanged (HasFocus As Boolean)
	If EDT_CANVEIN.Text = "" Then EDT_CANVEIN.Text = "0"
	EDT_CANVEIN.Text = Round (EDT_CANVEIN.Text)
	LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUVEI_Click
	If EDT_CANVEIN.Text = "" Then
		EDT_CANVEIN.Text=0
		LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
	Else
		EDT_CANVEIN.Text = Round (EDT_CANVEIN.Text + 1)
		LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENVEI_Click
	If EDT_CANVEIN.Text = "" Then
		EDT_CANVEIN.Text=0
		LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
	Else IF EDT_CANVEIN.Text > 0 Then
		EDT_CANVEIN.Text = Round(EDT_CANVEIN.Text -1)
		LBL_TVEIN.Text=LBL_VEINTE.Tag * EDT_CANVEIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub
'50
Private Sub EDT_CANCIN_FocusChanged (HasFocus As Boolean)
	If EDT_CANCIN.Text = "" Then EDT_CANCIN.Text = "0"
	EDT_CANCIN.Text = Round (EDT_CANCIN.Text)
	LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUCIN_Click
	If EDT_CANCIN.Text = "" Then
		EDT_CANCIN.Text =0
		LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
	Else
		EDT_CANCIN.Text = Round (EDT_CANCIN.Text + 1)
		LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENCIN_Click
	If EDT_CANCIN.Text = "" Then
		EDT_CANCIN.Text =0
		LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
	Else IF EDT_CANCIN.Text > 0 Then
		EDT_CANCIN.Text = Round(EDT_CANCIN.Text -1)
		LBL_TCIN.Text=LBL_CINCUEN.Tag * EDT_CANCIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

'100
Private Sub EDT_CANCIEN_FocusChanged (HasFocus As Boolean)
	If EDT_CANCIEN.Text = "" Then EDT_CANCIEN.Text = "0"
	EDT_CANCIEN.Text = Round (EDT_CANCIEN.Text)
	LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUCIEN_Click
	If EDT_CANCIEN.Text = "" Then
		EDT_CANCIEN.Text = 0
		LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
	Else
		EDT_CANCIEN.Text = Round (EDT_CANCIEN.Text + 1)
		LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENCIE_Click
	If EDT_CANCIEN.Text = "" Then
		EDT_CANCIEN.Text = 0
		LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
	Else IF EDT_CANCIEN.Text > 0 Then
		EDT_CANCIEN.Text = Round(EDT_CANCIEN.Text -1)
		LBL_TCIEN.Text=LBL_CIEN.Tag * EDT_CANCIEN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

'200
Private Sub EDT_CANDOS_FocusChanged (HasFocus As Boolean)
	If EDT_CANDOS.Text = "" Then EDT_CANDOS.Text = "0"
	EDT_CANDOS.Text = Round (EDT_CANDOS.Text)
	LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUDOS_Click
	If EDT_CANDOS.Text = "" Then
		EDT_CANDOS.Text = 0
		LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
	Else
		EDT_CANDOS.Text = Round (EDT_CANDOS.Text + 1)
		LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENDOS_Click
	If EDT_CANDOS.Text = "" Then
		EDT_CANDOS.Text = 0
		LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
	Else IF EDT_CANDOS.Text > 0 Then
		EDT_CANDOS.Text = Round(EDT_CANDOS.Text -1)
		LBL_TDOS.Text=LBL_DOSC.Tag * EDT_CANDOS.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

'500
Private Sub EDT_CANQUIN_FocusChanged (HasFocus As Boolean)
	If EDT_CANQUIN.Text = "" Then EDT_CANQUIN.Text = "0"
	EDT_CANQUIN.Text = Round (EDT_CANQUIN.Text)
	LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUQUI_Click
	If EDT_CANQUIN.Text = "" Then
		EDT_CANQUIN.Text =0
		LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
	Else
		EDT_CANQUIN.Text = Round (EDT_CANQUIN.Text + 1)
		LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENQUI_Click
	If EDT_CANQUIN.Text = "" Then
		EDT_CANQUIN.Text =0
		LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
	Else IF EDT_CANQUIN.Text > 0 Then
		EDT_CANQUIN.Text = Round(EDT_CANQUIN.Text -1)
		LBL_TQUIN.Text=LBL_QUIN.Tag * EDT_CANQUIN.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub
'1000
Private Sub EDT_CANMIL_FocusChanged (HasFocus As Boolean)
	If EDT_CANMIL.Text = "" Then EDT_CANMIL.Text = "0"
	EDT_CANMIL.Text = Round (EDT_CANMIL.Text )
	LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
	Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
	TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
End Sub

Sub B_SUMIL_Click
	If EDT_CANMIL.Text = "" Then
		EDT_CANMIL.Text = 0
		LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
	Else
		EDT_CANMIL.Text = Round (EDT_CANMIL.Text + 1)
		LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

Sub B_MENMIL_Click
	If EDT_CANMIL.Text = "" Then
		EDT_CANMIL.Text = 1
		LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
	Else IF EDT_CANMIL.Text > 0 Then
		EDT_CANMIL.Text = Round(EDT_CANMIL.Text -1)
		LBL_TMIL.Text= LBL_MIL.Tag * EDT_CANMIL.Text
		Btn_TOTALBILLETE.Text= ( LBL_TMIL.Text + LBL_TQUIN.Text + LBL_TDOS.Text + LBL_TCIEN.Text + LBL_TCIN.Text + LBL_TVEIN.Text)
		TOTALBILLETES.Text=Btn_TOTALBILLETE.Text
	End If
End Sub

'''' MONEDAS
Sub L_CALCULA_MONEDA_Click
	If EDT_CANDIEZ.Text="" Or  EDT_CANCI.Text="" Or EDT_CANDO.Text="" Or EDT_CANUN.Text="" Or EDT_CANCEN.Text=""   Or EDT_CANVEINTE.Text="" Then
		Msgbox("Por favor llena todas las cantidades","") 'ignore
		Pnl_Billete.RequestFocus
	Else
		LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
		LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
		LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
		LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
		LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
		LBL_TVEINTE.Text=L_VEINTE.Tag * EDT_CANVEINTE.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

'0.50
Private Sub EDT_CANCEN_FocusChanged (HasFocus As Boolean)
	If EDT_CANCEN.Text = "" Then EDT_CANCEN.Text = "0"
	EDT_CANCEN.Text = Round (EDT_CANCEN.Text)
	LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_SUMCENT_Click
	If EDT_CANCEN.Text = "" Then
		EDT_CANCEN.Text = 0
		LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
	Else
		EDT_CANCEN.Text = Round (EDT_CANCEN.Text + 1)
		LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_MENCENT_Click
	If EDT_CANCEN.Text = "" Then
		EDT_CANCEN.Text =0
		LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
	Else IF EDT_CANCEN.Text > 0 Then
		EDT_CANCEN.Text = Round(EDT_CANCEN.Text -1)
		LBL_TCEN.Text=L_CENTAVO.Tag * EDT_CANCEN.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

'1
Private Sub EDT_CANUN_FocusChanged (HasFocus As Boolean)
	If EDT_CANUN.Text = "" Then EDT_CANUN.Text = "0"
	EDT_CANUN.Text = Round (EDT_CANUN.Text)
	LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_SUMUN_Click
	If EDT_CANUN.Text = "" Then
		
		LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
	Else
		EDT_CANUN.Text = Round (EDT_CANUN.Text + 1)
		LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_MENUN_Click
	If EDT_CANUN.Text = "" Then
		EDT_CANUN.Text = 0
		LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
	Else IF EDT_CANUN.Text > 0 Then
		EDT_CANUN.Text = Round(EDT_CANUN.Text -1)
		LBL_TUN.Text=L_UNO.Tag * EDT_CANUN.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

'2
Private Sub EDT_CANDO_FocusChanged (HasFocus As Boolean)
	If EDT_CANDO.Text = "" Then EDT_CANDO.Text = "0"
	EDT_CANDO.Text = Round (EDT_CANDO.Text)
	LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_SUMDO_Click
	If EDT_CANDO.Text = "" Then
		EDT_CANDO.Text =0
		LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
	Else
		EDT_CANDO.Text = Round (EDT_CANDO.Text + 1)
		LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_MENDO_Click
	If EDT_CANDO.Text = "" Then
		EDT_CANDO.Text=0
		LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
	Else IF EDT_CANDO.Text > 0 Then
		EDT_CANDO.Text = Round(EDT_CANDO.Text -1)
		LBL_TDO.Text=L_DOS.Tag * EDT_CANDO.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

'5
Private Sub EDT_CANCI_FocusChanged (HasFocus As Boolean)
	If EDT_CANCI.Text = "" Then EDT_CANCI.Text = "0"
	EDT_CANCI.Text = Round (EDT_CANCI.Text)
	LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text )
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_SUMCIN_Click
	If EDT_CANCI.Text = "" Then
		EDT_CANCI.Text =0
		LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
	Else
		EDT_CANCI.Text = Round (EDT_CANCI.Text + 1)
		LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text )
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_MENCI_Click
	If EDT_CANCI.Text = "" Then
		EDT_CANCI.Text =0
		LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
	Else IF EDT_CANCI.Text > 0 Then
		EDT_CANCI.Text = Round(EDT_CANCI.Text -1)
		LBL_TCI.Text= L_CINCO.Tag * EDT_CANCI.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub
'10
Private Sub EDT_CANDIEZ_FocusChanged (HasFocus As Boolean)
	If EDT_CANDIEZ.Text = "" Then EDT_CANDIEZ.Text = "0"
	EDT_CANDIEZ.Text = Round (EDT_CANDIEZ.Text)
	LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_SUMDIEZ_Click
	If EDT_CANDIEZ.Text = "" Then
		EDT_CANDIEZ.Text =0
		LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
	Else
		EDT_CANDIEZ.Text = Round (EDT_CANDIEZ.Text + 1)
		LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_MENDIEZ_Click
	If EDT_CANDIEZ.Text = "" Then
		EDT_CANDIEZ.Text = 0
		LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
	Else IF EDT_CANDIEZ.Text > 0 Then
		EDT_CANDIEZ.Text = Round(EDT_CANDIEZ.Text -1)
		LBL_TDIEZ.Text= L_DIEZ.Tag * EDT_CANDIEZ.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

'20
Private Sub EDT_CANVEINTE_FocusChanged (HasFocus As Boolean)
	If EDT_CANVEINTE.Text = "" Then EDT_CANVEINTE.Text = "0"
	EDT_CANVEINTE.Text = Round(EDT_CANVEINTE.Text)
	LBL_TVEINTE.Text= L_VEINTE.Tag * EDT_CANVEINTE.Text
	B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text +  LBL_TVEINTE.Text )
	TOTALMONEDA.Text=B_TOTALMONEDA.Text
End Sub

Sub B_MENVEINTE_Click
	If EDT_CANVEINTE.Text = "" Then
		EDT_CANVEINTE.Text = 0
		LBL_TVEINTE.Text= L_VEINTE.Tag * EDT_CANVEINTE.Text
	Else IF EDT_CANVEINTE.Text > 0 Then
		EDT_CANVEINTE.Text = Round(EDT_CANVEINTE.Text -1)
		LBL_TVEINTE.Text= L_VEINTE.Tag * EDT_CANVEINTE.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text +  LBL_TVEINTE.Text )
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

Sub B_SUMVEINTE_Click
	If EDT_CANVEINTE.Text = "" Then
		EDT_CANVEINTE.Text =0
		LBL_TVEINTE.Text= L_VEINTE.Tag * EDT_CANVEINTE.Text
	Else
		EDT_CANVEINTE.Text = Round (EDT_CANVEINTE.Text + 1)
		LBL_TVEINTE.Text= L_VEINTE.Tag * EDT_CANVEINTE.Text
		B_TOTALMONEDA.Text=( LBL_TDIEZ.Text + LBL_TCI.Text + LBL_TDO.Text + LBL_TUN.Text + LBL_TCEN.Text + LBL_TVEINTE.Text)
		TOTALMONEDA.Text=B_TOTALMONEDA.Text
	End If
End Sub

''''''TOTALES
Sub TOTALES_Click
	If TOTALMONEDA.Text="" Or  TOTALBILLETES.Text=""  Then
		TOTALMONEDA.Text=0
		TOTALBILLETES.Text=0
		B_SUM_TOTAL.Text="$"& (TOTALMONEDA.Text + TOTALBILLETES.Text)
	Else
		B_SUM_TOTAL.Text= "$"&(TOTALMONEDA.Text + TOTALBILLETES.Text)
	End If
End Sub

Sub B_AGREGABILL_Click
	Pnl_Billete.Visible=True
	Pnl_Moneda.Visible=False
	PNL_TOTALES.Visible=False
	LBL_RETURN.Visible=True
	LBL_REGRESA.Visible=True
End Sub

Sub B_AGREGAMONE_Click
	Pnl_Billete.Visible=False
	Pnl_Moneda.Visible=True
	PNL_TOTALES.Visible=False
	LBL_RETURN.Visible=True
	LBL_REGRESA.Visible=True
End Sub

Sub LBL_RETURN_Click
	Pnl_Billete.Visible=False
	Pnl_Moneda.Visible=False
	PNL_TOTALES.Visible=True
	LBL_RETURN.Visible=False
	LBL_REGRESA.Visible=False
	''' CALCULO FINAL
	If TOTALMONEDA.Text="" Or  TOTALBILLETES.Text=""  Then
		TOTALMONEDA.Text=0
		TOTALBILLETES.Text=0
		B_SUM_TOTAL.Text="$"& (TOTALMONEDA.Text + TOTALBILLETES.Text)
	Else
		B_SUM_TOTAL.Text="$"& (TOTALMONEDA.Text + TOTALBILLETES.Text)
	End If
End Sub

Sub LBL_REGRESA_Click
	Pnl_Billete.Visible=False
	Pnl_Moneda.Visible=False
	LBL_RETURN.Visible=False
	LBL_REGRESA.Visible=False
	PNL_TOTALES.Visible=True
	LBL_REGRESA.Visible=True
End Sub

Sub B_Regresar_Click
'	StartActivity("SELECCION")
	Subs.iniciaActividad("principal")
'	B4XPages.ShowPage("Principal")
'	Activity.Finish
	PNL_TOTALES.Visible=False
	Pnl_Billete.Visible=False
	Pnl_Moneda.visible=False
	PNL_TOTALES.Visible=False
	LBL_RETURN.Visible=False
	LBL_REGRESA.Visible=False
	P_BOLETA.Visible=False
	P_INF_GENERAL.Visible=True
	If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
	LBL_REGRESA.Visible=False
	
End Sub

Sub IMG_IMPRESORA_Click
'	Printer1.DisConnect : Log("Desconectando impresora")
'	impresoraConectada = False
'	Private cont As Int = 0
'	ToastMessageShow("Conectando impresora", False)
'	Do While Not(impresoraConectada) And cont < 9
'		Printer1.Connect
'		If Logger Then Log("Conectando impresora")
'		Sleep(1000)
'		If Logger Then Log(impresoraConectada)
'		cont = cont + 1
'	Loop
'	If Logger Then Log("connected")
	ProgressDialogShow("Imprimiendo, un momento ...")
	Printer1.DisConnect
	If Not(Printer1.IsConnected) Then
		If logger Then 	Log("conectando 1")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada)
			Sleep(1000)
			cont = cont + 1
			If cont = 7 Then Printer1.Connect 'Tratamos de reconectar
			If cont > 15 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	Else
		If logger Then Log("conectando 2")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada) Or Not(Printer1.IsConnected)
			Sleep(1000)
			cont = cont + 1
			If cont = 2 Then Printer1.Connect
			If cont > 4 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	End If


	c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	Printer1.WriteString("KELLOGG COMPANY MEXICO" & CRLF)
	Printer1.WriteString(sDate &" " & sTime & CRLF)
	Printer1.WriteString("Vendedor:" & usuario & CRLF)
	Printer1.WriteString(" " & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("BILLETES" &  CRLF)
	Printer1.WriteString("$1,000 X " & EDT_CANMIL.TEXT & " =      " & LBL_TMIL.TEXT & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$500 X   " & EDT_CANQUIN.TEXT & " =     " & LBL_TQUIN.TEXT &CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$200 X   " & EDT_CANDOS.TEXT & " =      " & LBL_TDOS.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$100 X   " & EDT_CANCIEN.TEXT & " =     " & LBL_TCIEN.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$50 X    " & EDT_CANCIN.TEXT & " =      " & LBL_TCIN.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$20 X    " & EDT_CANVEIN.TEXT & " =     " & LBL_TVEIN.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("TOTAL BILLETES...... " & Btn_TOTALBILLETE.TEXT  & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("MONEDAS" &  CRLF)
	Printer1.WriteString("$20 X    " & EDT_CANVEINTE.TEXT & " =     " & LBL_TVEINTE.TEXT &CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$10 X    " & EDT_CANDIEZ.TEXT & " =     " & LBL_TDIEZ.TEXT &CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$5 X     " & EDT_CANCI.TEXT & " =       " & LBL_TCI.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$2 X     " & EDT_CANDO.TEXT & " =       " & LBL_TDO.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$1 X     " & EDT_CANUN.TEXT & " =       " & LBL_TUN.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("$.50 X   " & EDT_CANCEN.TEXT & " =      " & LBL_TCEN.Text & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString("TOTAL MONEDAS....... " & B_TOTALMONEDA.TEXT  & CRLF)
	Printer1.WriteString(" " & CRLF)
	Printer1.WriteString("TOTAL .........." & B_SUM_TOTAL.TEXT  & CRLF)
	Printer1.WriteString(" " & CRLF)
	Printer1.WriteString("------------------------------"  & CRLF)
	Printer1.WriteString(" " & CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString("Nombre y Firma"  & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString("______________________________" & CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	ProgressDialogHide
End Sub

Sub B_IMP_INV_Click
	ProgressDialogShow("Imprimiendo, un momento ...")
	Printer1.DisConnect
	If Not(Printer1.IsConnected) Then
		If logger Then Log("conectando 1")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada)
			Sleep(1000)
			cont = cont + 1
			If cont = 7 Then Printer1.Connect 'Tratamos de reconectar
			If cont > 15 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	Else
		If logger Then Log("conectando 2")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada) Or Not(Printer1.IsConnected)
			Sleep(1000)
			cont = cont + 1
			If cont = 2 Then Printer1.Connect
			If cont > 4 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	End If
	c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	TAMANO = 5
	ESPACIO = 14
	BLANCO = " "
	Printer1.WriteString("KELLOG COMPANY MEXICO"  & CRLF)
	Printer1.WriteString("RESUMEN DIA"  & CRLF)
	Printer1.WriteString(sDate & " " &  sTime  & CRLF)
	Printer1.WriteString("Vendedor:" & usuario  & CRLF)
	Printer1.WriteString("-------INVENTARIO A BORDO----------"  & CRLF)
''' se cambia este 	Printer1.WriteString("---II---CD---IIT---VT---RMI---IF---"  & CRLF) ------- sin RMI
	Printer1.WriteString("---II---CD---IIT---VT---------IF---"  & CRLF)

	' aqui es donde esta el pedo de julieta de los descuentos quitar el precio2 pero meter un if para saber si es ruta especial o es normal o que show.
	s=Starter.skmt.ExecQuery2 ("select CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_ALMACEN  from cat_gunaprod2 where CAT_GP_CLASIF <> ? ORDER BY CAT_GP_NOMBRE ", Array As String("PROMOS"))
	Log($"Reglones: ${s.RowCount}"$)
	If s.RowCount>0 Then
		For i=0 To S.RowCount -1
			Log(i)
			Try
				s.Position=i
				Printer1.WriteString(s.GetString("CAT_GP_NOMBRE")  & CRLF)
				Log("p"&i)
			Catch
				Log(LastException)
				If logger Then Log("Saliendo con Try/Catch")
				Exit
			End Try
			S1=Starter.skmt.ExecQuery2("select CAT_GP_ALMACEN from cat_gunaprod5 where CAT_GP_ID = ?", Array As String(s.GetString("CAT_GP_ID")))
			S1.Position=0
			S3=Starter.skmt.ExecQuery2("select count(*) as CUANTOS from HIST_ABORDO where HIST_PROID = ?", Array As String(s.GetString("CAT_GP_ID")))
			S3.Position=0
			If S3.GetString("CUANTOS") > 0  Then
				S2=Starter.skmt.ExecQuery2("select HIST_CANT from HIST_ABORDO where HIST_PROID = ?", Array As String(s.GetString("CAT_GP_ID")))
				S2.Position=0
				a_inicial =  S1.GetString("CAT_GP_ALMACEN") -  S2.GetString("HIST_CANT")
			Else
				a_inicial =  S1.GetString("CAT_GP_ALMACEN")
			End If
			a_inicial_5 = S1.GetString("CAT_GP_ALMACEN")
			'Printer1.WriteString("INICIAL: " & ABORDO & CRLF)
			If S3.GetString("CUANTOS") > 0  Then
				'Printer1.WriteString("CARGA DIA : " &  S2.GetString("HIST_CANT") & CRLF)
				ABORDO = S2.GetString("HIST_CANT")
			Else
				'Printer1.WriteString("CARGA DIA : 0"  & CRLF)
				ABORDO = 0
			End If
			'Printer1.WriteString("CARGA TOTAL : " &  S1.GetString("CAT_GP_ALMACEN") & CRLF)
			a_total =  S1.GetString("CAT_GP_ALMACEN")

			C4=Starter.skmt.ExecQuery2("select  count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) <> ? AND PE_TIPO = ? and  PE_PROID = ? ", Array As String("CAMBIO","VENTA", s.GetString("CAT_GP_ID")))
			C4.Position=0
			If C4.GetString("CUANTOS") > 0 Then
				C3=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE from pedido where substr(pe_pronombre,1,6) <> ? AND PE_TIPO = ? AND PE_PROID = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO","VENTA", s.GetString("CAT_GP_ID")))
				C3.Position=0
				'Printer1.WriteString("VENTA: " & C3.GetString("CANTIDAD") &  CRLF)
				a_venta = C3.GetString("CANTIDAD")
			Else
				'Printer1.WriteString("VENTA: 0" &   CRLF)
				a_venta = 0
			End If
			C4.Close
			''' se conenta esto para el cambio de RMI
			C4=Starter.skmt.ExecQuery2("select  count(*) as CUANTOS  from pedido where substr(pe_pronombre,1,6) = ? AND PE_PROID = ? ", Array As String("CAMBIO", s.GetString("CAT_GP_ID")))
			C4.Position=0
			If C4.GetString("CUANTOS") > 0 Then
				C1=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE from pedido where substr(pe_pronombre,1,6) = ? AND PE_PROID = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO", s.GetString("CAT_GP_ID")))
				C1.Position=0
				RMI = C1.GetString("CANTIDAD")
			Else
				RMI = 0
			End If

			'Printer1.WriteString("INV. ACT.: " &  s.GetString("CAT_GP_ALMACEN")  & CRLF)
			'a_final =s.GetString("CAT_GP_ALMACEN")
			''' se cammbi a este a_final = a_inicial_5 - a_venta - RMI por el sin RMI cambiuo de rmi
			a_final = a_inicial_5 - a_venta 
			
			'Printer1.WriteString("RMI: " & RMI &   CRLF)
			Private sep1 As String
			Private sep2 As String
			Private sep3 As String
			Private sep4 As String
			Private sep5 As String
			Private sep6 As String

			sep1 = a_inicial.Length
			If sep1 = 1 Then
				a_inicial = "----" & a_inicial
			else if sep1 = 2 Then
				a_inicial = "---" & a_inicial
			else if sep1 = 3 Then
				a_inicial = "--" & a_inicial
			else if sep1 = 4 Then
				a_inicial = "-" & a_inicial
			else if sep1 = 5 Then
				a_inicial =  a_inicial
			End If
			sep2 = ABORDO.Length
			If sep2 = 1 Then
				ABORDO = "----" & ABORDO
			else if sep2 = 2 Then
				ABORDO = "---" & ABORDO
			else if sep2 = 3 Then
				ABORDO = "--" & ABORDO
			else if sep2 = 4 Then
				ABORDO = "-" & ABORDO
			else if sep2 = 5 Then
				ABORDO =  ABORDO
			End If

			sep3 = a_total.Length
			If sep3 = 1 Then
				a_total = "----" & a_total
			else if sep3 = 2 Then
				a_total = "---" & a_total
			else if sep3 = 3 Then
				a_total = "--" & a_total
			else if sep3 = 4 Then
				a_total = "-" & a_total
			else if sep3 = 5 Then
				a_total =  a_total
			End If

			sep4 = a_venta.Length
			If sep4 = 1 Then
				a_venta = "----" & a_venta
			else if sep4 = 2 Then
				a_venta = "---" & a_venta
			else if sep4 = 3 Then
				a_venta = "--" & a_venta
			else if sep4 = 4 Then
				a_venta = "-" & a_venta
			else if sep4 = 5 Then
				a_venta =  a_venta
			End If

			sep5 = a_final.Length
			If sep5 = 1 Then
				a_final = "----" & a_final
			else if sep5 = 2 Then
				a_final = "---" & a_final
			else if sep5 = 3 Then
				a_final = "--" & a_final
			else if sep5 = 4 Then
				a_final = "-" & a_final
			else if sep5 = 5 Then
				a_final =  a_final
			End If
''''se cambia por lo de RMI
''			sep6 = RMI.Length
''			If sep6 = 1 Then
''				RMI = "----" & RMI
''			else if sep6 = 2 Then
''				RMI = "---" & RMI
''			else if sep6 = 3 Then
''				RMI = "--" & RMI
''			else if sep6 = 4 Then
''				RMI = "-" & RMI
''			else if sep6 = 5 Then
''				RMI =  RMI
''			End If
''  se cambia este 			Printer1.WriteString( a_inicial &  ABORDO &  a_total &  a_venta &   RMI & a_final &   CRLF) --- por este sin RMI

			Printer1.WriteString( a_inicial &  ABORDO &  a_total &  a_venta &    a_final &   CRLF)

			TAMANO = TAMANO + 1
			If TAMANO > 40 Then
				
				t3.Initialize("T3", 4000) ' 1000 = 1 second
				t3.Enabled = True
				Wait For  t3_tick
				TAMANO = 0
			End If
		Next
	End If
	s.Close
	If S3.IsInitialized Then S3.Close
	Try
		c=Starter.skmt.ExecQuery("select count(*) as CUANTOS from pedido")
		c.Position =0
		CUANTOS = c.GetString("CUANTOS")
		c.Close
	Catch
		CUANTOS = 0
	End Try
	''' se quita por el RMI
	Try
		c=Starter.skmt.ExecQuery2("select count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO"))
		If c.RowCount > 0 Then
			c.Position =0
			CUANTOS1 = c.GetString("CUANTOS")
		Else
			CUANTOS1 = 0
		End If
		c.Close
	Catch
		CUANTOS1 = 0
	End Try
	If CUANTOS <> CUANTOS1 Then
		Try
			c=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE from pedido where substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO"))
			Printer1.WriteString(CRLF)
			Printer1.WriteString("-----------RMI----------------"  & CRLF)
			Printer1.WriteString(CRLF)
			If C.RowCount>0 Then
				For i=0 To C.RowCount -1
					C.Position=i
					Printer1.WriteString(C.GetString("CANTIDAD") & " " & C.GetString("PE_PRONOMBRE")  & CRLF)
				Next
			End If
			c.Close
		Catch
			Printer1.WriteString(CRLF)
		End Try
	End If
		
	' TOTALES DE LOS ARCHIVOS
			
	s.Close
	S=Starter.skmt.ExecQuery2("select SUM(CAT_GP_ALMACEN) AS CAT_GP_ALMACEN from cat_gunaprod2 WHERE CAT_GP_CLASIF <> ? ", Array As String("PROMOS"))
	S.Position=0
	a_final =s.GetString("CAT_GP_ALMACEN")
			
	S1.Close
	S1=Starter.skmt.ExecQuery("select SUM(CAT_GP_ALMACEN) AS CAT_GP_ALMACEN from cat_gunaprod5 ")
	S1.Position=0
	a_total =  S1.GetString("CAT_GP_ALMACEN")
	a_inicial =  S1.GetString("CAT_GP_ALMACEN")
	S1.Close
	ABORDO =0
	C3=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD, SUM(PE_COSTO_TOT) AS PE_TOTAL from pedido where pe_proid <> pe_cedis and substr(pe_pronombre,1,6) <> ? AND PE_CLIENTE <> ?", Array As String("CAMBIO", "0"))
	C8=Starter.skmt.ExecQuery2("select  SUM(PE_COSTO_TOT) AS PE_TOTAL from pedido where pe_proid <> pe_cedis AND PE_CLIENTE <> ?", Array As String( "0"))
	C8.Position=0
	If C3.RowCount > 0 Then
		C3.Position=0
		a_venta = C3.GetString("CANTIDAD")
	Else
		a_venta = 0
	End If
	
	If a_venta = Null Then a_venta = 0
	If  CUANTOS <> CUANTOS1 Then
		C1=Starter.skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD, SUM(PE_COSTO_TOT) AS TOTAL from pedido where substr(pe_pronombre,1,6) = ? ", Array As String("CAMBIO"))
		C1.Position=0
		RMI = C1.GetString("CANTIDAD")
		RMI_VALOR = C1.GetString("TOTAL")
		C1.Close
	Else
		RMI = 0
	End If
	If RMI = Null Then RMI = 0
	If logger Then Log($"a_total=${a_total}, a_venta=${a_venta}, rmi=${RMI}"$)
	a_final = a_total - a_venta 
	Printer1.WriteString(Printer1.BOLD & "Piezas en RMI : " & RMI &   CRLF)
	Printer1.WriteString(Printer1.BOLD & "TOTAL  RMI : " & RMI_VALOR &   CRLF)
	
	Printer1.WriteString(Printer1.BOLD & "----RESUMEN TOTAL---- " &   CRLF)
	'' se cambia por lo del rmi	Printer1.WriteString("---" & a_inicial & "..." & ABORDO & "..." & a_total &  "..." & a_venta & "..." & a_final & "..." & RMI &   CRLF)
	Printer1.WriteString("---" & a_inicial & "..." & ABORDO & "..." & a_total &  "..." & a_venta & "..." & a_final & "..." &   CRLF)

	Printer1.WriteString(Printer1.BOLD & "TOTAL VENTA " & C8.GetString("PE_TOTAL")  &   CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString("Nombre y Firma"  & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString("______________________________" & CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	If C3.IsInitialized Then C3.Close
	ProgressDialogHide
End Sub

Sub B_CERRAR_I_Click
	Panel_INV_A.Visible = False
	P_INF_GENERAL.Visible = True
	If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
End Sub

Sub Bt_GuardarBoleta_Click
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	cursorBoleta=Starter.skmt.ExecQuery("select ID_ALMACEN FROM CAT_ALMACEN")
	cursorBoleta.Position=0
	Id_Almacen=cursorBoleta.GetString("ID_ALMACEN")
	Starter.skmt.ExecNonQuery("delete from TMP_CAT_BILLETE")
	Starter.skmt.ExecNonQuery("delete from TMP_CAT_MONEDAS")
	Starter.skmt.ExecNonQuery2("INSERT INTO TMP_CAT_BILLETE (TMP_BILLE_RUTA, TMP_BILLE_IDALMACEN, TMP_BILLE_FECHA, TMP_BILLE_MIL, TMP_BILLE_QUINIENTOS, TMP_BILLE_DOSCIENTOS, TMP_BILLE_CIEN, TMP_BILLE_CINCUENTA, TMP_BILLE_VEINTE) values (?,?,?,?,?,?,?,?,?)", Array As Object (RutaBoleta,Id_Almacen,sDate & sTime,EDT_CANMIL.Text,EDT_CANQUIN.Text,EDT_CANDOS.Text,EDT_CANCIEN.Text,EDT_CANCIN.Text,EDT_CANVEIN.Text))
	Starter.skmt.ExecNonQuery2("INSERT INTO TMP_CAT_MONEDAS (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) values (?,?,?,?,?,?,?,?,?)", Array As Object (RutaBoleta,Id_Almacen,sDate & sTime,EDT_CANVEINTE.Text,EDT_CANDIEZ.Text,EDT_CANCI.Text,EDT_CANDO.Text,EDT_CANUN.Text,EDT_CANCEN.Text))
'	If Logger Then Log($"${RutaBoleta},${Id_Almacen},${EDT_CANMIL.Text},${EDT_CANQUIN.Text},${EDT_CANDOS.Text},${EDT_CANCIEN.Text},${EDT_CANCIN.Text},${EDT_CANVEIN.Text}"$)
'	If Logger Then Log($"${RutaBoleta},${Id_Almacen},${EDT_CANVEINTE.Text},${EDT_CANDIEZ.Text},${EDT_CANCI.Text},${EDT_CANDO.Text},${EDT_CANUN.Text},${EDT_CANCEN.Text}"$)
	Msgbox("Datos Guardados ","Listo") 'ignore
End Sub

Sub B_E_NEXT_Click
	Panel9.Visible = False
	Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, E_RES_E.Text ,sDate & sTime,c.GetString("CAT_EP_ID")))
	Starter.tipov = "VENTA"
	Cuestionario
End Sub

Sub b_chk_e_Click
	Panel10.Visible = False
	Private resp As String = ""
	If Chk_1.Checked = True Then resp = chk_1_valor
	If chk_2.Checked = True Then resp = resp & " / " & chk_2_valor
	If chk_3.Checked = True Then resp = resp & " / " & chk_3_valor
	If resp.StartsWith(",") Then resp = resp.SubString(2) 'Quitamos la coma si existe al principio.
	Starter.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, resp, sDate & sTime, Chk_1.Tag))
	Starter.tipov = "VENTA"
	Cuestionario
End Sub

'Muestra el panel de la encuesta, le da el alto y ancho de la pantalla y la pone en 0,0
Sub muestraEncuesta
'	If Logger Then Log("Muestra Encuesta")
	p_encuesta.Top = 0
	p_encuesta.left = 0
	p_encuesta.Height = GetDeviceLayoutValues.Height
	p_encuesta.Width = GetDeviceLayoutValues.Width
	p_encuesta.SetVisibleAnimated(200, True)
	p_encuesta.Elevation = 90 'ignore
	p_encuesta.BringToFront
	P_INF_GENERAL.Visible = False
	Log("Panel general="&P_INF_GENERAL.Visible)
End Sub

' Oculta el panel de la encuesta y los botones de la misma.
Sub ocultaPanelEncuesta
'	Log("Oculta Encuesta")
	b_encuesta_1.Visible = False
	b_encuesta_2.Visible = False
	b_encuesta_3.Visible = False
	p_encuesta.Visible = False
	P_INF_GENERAL.Visible = True
	If logger Then Log("Panel general="&P_INF_GENERAL.Visible)
End Sub

'Regresa el valor de "left" para el centro de la pantalla
Sub centroPantalla As Int
	Private anchoPantalla As Int = GetDeviceLayoutValues.Width
	Private anchoPantalla As Int = Root.Width
	Return anchoPantalla/2
End Sub

Private Sub b_encuesta_1_Click
	Dim btn As Button = Sender
	Log(btn.Tag & " clicked - " & btn.Text)
	encuestaRes = btn.Text
	ocultaPanelEncuesta
	botonPresionado = 1
End Sub

Private Sub b_encuesta_2_Click
	Dim btn As Button = Sender
	Log(btn.Tag & " clicked - " & btn.Text)
	encuestaRes = btn.Text
	ocultaPanelEncuesta
	botonPresionado = 1
End Sub

Private Sub b_encuesta_3_Click
	Dim btn As Button = Sender
	If logger Then Log(btn.Tag & " clicked - " & btn.Text)
	encuestaRes = btn.Text
	ocultaPanelEncuesta
	botonPresionado = 1
End Sub

Private Sub b_encuesta_continuar_Click
	encuestaRes = et_encuesta.Text
	et_encuesta.Text = ""
	et_encuesta.Visible = False
	b_encuesta_continuar.Visible = False
	ocultaPanelEncuesta
	botonPresionado = 1
End Sub

Private Sub et_encuesta_TextChanged (Old As String, New As String)
'	Log($"|${Old}|,|${New}|"$)
	If New.Length > 0 Then b_encuesta_continuar.Enabled = True
	If New.Length < 1 Then b_encuesta_continuar.Enabled = False
End Sub

'Revisa si el cliente actual es candidato a la promo especial que da regalo según el monto de la compra.
'Se revisa que el cliente tenga asignada la promoción, que no tenga venta impresa y que el producto de regalo tenga existencia.
'Si cumple las 3 condiciones regresa esValida=True, si no, esValida=False.
Sub revisaPromoEspecial As Map
'	Necesitamos cliente autorizado, producto promocional con existencia y cliente no impreso.
	Private hayInventario As String = ""
	Private clienteConPromo As String = ""
	Private clienteImpreso As String = ""
	Dim promoInfo As Map
	promoInfo.Initialize
	Private x As Cursor
	'Revisamos si ya tiene venta impresa.
	x=Starter.skmt.ExecQuery("select count(*) as CUANTOS from CLIENTE_IMPRESO where CI_CUENTA in (Select CUENTA from cuentaa)")
	x.Position = 0
	clienteImpreso = x.GetString("CUANTOS")
'	Log(clienteImpreso)
'	If clienteImpreso = "0" Then Log("El cliente no tiene venta impresa.")
	x.Close
	'Revisamos que tenga asignada la promo.
	x=Starter.skmt.ExecQuery("select count(*) as clienteConPromo, CPM_PROID, CPM_CANT, CPM_RANGO, CPM_DESC, CPM_IDPROMO, CPM_MONTO from CAT_PROMO_MONTO where CPM_CLIENTE in (Select CUENTA from cuentaa)")
	If x.RowCount > 0 Then
		x.Position = 0
		If x.GetString("clienteConPromo") = 1 Then 'Cliente autorizado para promo.
			clienteConPromo = "1"
			Private y As Cursor
			Private nombreProd As String = ""
			y=Starter.skmt.ExecQuery("select cat_gp_nombre as nombreProd from cat_gunaprod where cat_gp_id = '" & x.GetString("CPM_PROID") & "'")
			If y.RowCount > 0 Then
				y.Position = 0
				nombreProd = y.GetString("nombreProd")
			End If
			Log("El cliente tiene asignada la promo especial.")
			Private p As Cursor
			p=Starter.skmt.ExecQuery("select count(*) as hayInventario from CAT_GUNAPROD where CAT_GP_ALMACEN > 0 and CAT_GP_ID = " & x.GetString("CPM_PROID"))
			p.Position = 0
			hayInventario = p.GetString("hayInventario")
			If hayInventario = "1" Then Log("El producto de la promo tiene existencia.")
			p.Close
			promoInfo = CreateMap("idProd":x.GetString("CPM_PROID"), "cantProd":x.GetString("CPM_CANT"), "rangoPromo":x.GetString("CPM_RANGO"), "descrPromo":x.GetString("CPM_DESC"), "idPromo":x.GetString("CPM_IDPROMO"), "montoPromo":x.GetString("CPM_MONTO"), "nombreProd":nombreProd)
		End If
	End If
	x.Close
	If clienteImpreso = "0" And clienteConPromo = "1" And hayInventario = "1" Then
		Log("Cumple con TODAS las condiciones de la promo.")
		promoInfo.Put("esValida", True)
		Return promoInfo
	Else
'		Log("NO cumple con las condiciones de la promo.")
		promoInfo.Put("esValida", False)
		Return promoInfo
	End If
End Sub

'Mete la promoción especial de regalo por monto vendido.
Sub metePromoEspecial(idProd As String, idPromo As String, cantProd As Int, nombreProd As String, promoDescr As String, idCliente As String, idUsuario As String, idRuta As String) 'ignore
	Dim query As String
	query = "cat_gunaprod"
	If Starter.tipov = "VENTA" Then query = "cat_gunaprod2"
'	Falta nombre de producto en el insert
	Starter.skmt.ExecNonQuery2("DELETE from PEDIDO where PE_CEDIS = ?", Array As String (idPromo))
	'Metemos encabezado de la promo.
	Starter.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (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(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (idPromo, 0, 0, cantProd, promoDescr, idPromo, idCliente, sDate & sTime, idUsuario, idRuta, Starter.tipov, 0))
	'Metemos el producto de regalo.
	Starter.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (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(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (idPromo, 0.01, 0.01, cantProd, nombreProd, idProd, idCliente, sDate & sTime, idUsuario, idRuta, Starter.tipov, 0.01))
	'Actualizamos existencia en CAT_GUNAPROD.
	Starter.skmt.ExecNonQuery2("update " & query & " set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object(cantProd, idProd))
End Sub

Sub revisaImpresora (mode As String) 'ignore
	''	Log("Revisamos impresora " & Starter.intentosImpresora)
	''	Log("RevisandoImpresora= " & Starter.revisandoImpresora)
'	If Not(Starter.btAdmin.IsEnabled) Then Starter.btAdmin.Enable 'Si no esta prendido el BT lo prendemos.
'	If Not(Printer1.IsInitialized) Then Printer1.Initialize(Me, "Printer1") 'Si no esta inicializada la inicializamos.
'	If Not(Starter.revisandoImpresora) Then Return
'	Starter.revisandoImpresora = True
'	If mode = "BT" Then
	''		Try
	''		LogColor("reiniciamos BT", Colors.Blue)
	''		Starter.btAdmin.Disable
	''		Sleep(500)
	''		Starter.btAdmin.Enable
	''		Sleep(1000)
	''		If Starter.btAdmin.IsEnabled Then revisaImpresora("")
	''		Catch
	''			Log(LastException)
	''		End Try
'	Else
	''		ToastMessageShow("Conectando impresora.", False)
'		If Not(Printer1.IsConnected) Then 'Si no estamos conectados, nos conectamos.
'			Log("Connect")
'			Printer1.Connect
'		Else 'Si ya estamos conectados 
'			Log("Disc-Conn")
'			Printer1.DisConnect
'			Sleep(1000)
'			Printer1.Connect
'		End If
'	End If
End Sub

Private Sub l_exhibidor2_Click
	p_exhibidores.Left = (Root.Width/2) - (p_exhibidores.Width/2)
	p_exhibidores.Top = Root.Height/4
	p_exhibidores.Visible = True
	p_exhibidores.Elevation = 90dip
End Sub

Private Sub b_exhibidor_Click
	p_exhibidores.Visible = False
End Sub

Private Sub Panel9_Click
	'Esta vacio porque solo esta capturado los clics.
End Sub

Private Sub PNL_TOTALES_Click
	'Esta vacio porque solo esta capturado los clics.
End Sub

Private Sub b_ubicacion_Click
	CallSubDelayed(Tracker, "StartFLP2")
End Sub

Private Sub P_BOLETA_Click
	'Esta vacio porque solo esta capturado los clics.
End Sub

Private Sub b_whats_Click
	P_INF_GENERAL.Visible = False
	p_promowhats.visible = True
	
	c=Starter.skmt.ExecQuery("select CAT_CL_CODIGO from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	If c.RowCount > 0 Then
		c.Position=0
		l_promowhats.Text = c.GetString("CAT_CL_CODIGO")
	End If
	c.Close
End Sub

Private Sub b_aceptarrpomo_Click
'	c=Starter.skmt.ExecQuery("select CAT_CL_NOMBRE from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
'	If c.RowCount > 0 Then
'		c.Position=0
'		l_promowhats.Text = c.GetString("CAT_CL_NOMBRE")
'	End If
'	c.Close
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c.Close
	c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	c.Close
	c=Starter.skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
	If c.RowCount>0 Then
		C.Position=0
		Id_Almacen = C.GetString("ID_ALMACEN")
	End If
	c.Close
	
	Starter.skmt.ExecNonQuery2("INSERT INTO HIST_PROMO_WHATS VALUES (?,?)", Array As Object(l_promowhats.Text, "PROMO ACEPTADA"))

	Starter.skmt.ExecNonQuery2("INSERT INTO  PEDIDO (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(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object ("PROMODOE",0 , 0, 1, "KIT DE BIENVENIDA DON TOÑO", "PROMODOE",la_cuenta.TEXT, sDate & sTime, usuario,Starter.rutaV,Starter.tipov,0))
	Starter. skmt.ExecNonQuery2("INSERT INTO  PEDIDO (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(?,?,?,?,?,?,?,?,?,?,?,?) ", Array As Object ("PROMODOE",0.01 , 0.01, 1, "CAJA CHOCO ZUCARITAS 260 GR", "1008094223",la_cuenta.TEXT, sDate & sTime, usuario,Starter.rutaV,Starter.tipov,0))
	Starter.skmt.ExecNonQuery2("update cat_gunaprod2 set cat_gp_almacen = cat_gp_almacen - ? where cat_gp_id = ? ", Array As Object("1", "1008094223"))
	c=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
	If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
	Starter.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), Starter.lon_gps, Starter.lat_gps,Id_Almacen,Starter.rutaV,c.GetString("TOTAL_CLIE_SIN")))
	
	Starter.skmt.ExecNonQuery("delete from pedido3")
	Starter.skmt.ExecNonQuery("UPDATE PEDIDO SET PE_FOLIO = 0 where PE_FOLIO IS NULL")
	Starter.skmt.ExecNonQuery("INSERT INTO PEDIDO3 (PE_PRECIO2, PE_TIPO, PE_FECHA, PE_DESC, PE_COSTO_SIN, PE_RUTA, PE_CEDIS, PE_COSTO_TOT, PE_COSTOU, PE_CANT, PE_PRONOMBRE, PE_PROID, PE_CLIENTE, PE_USUARIO ) SELECT PE_PRECIO2, PE_TIPO, PE_FECHA, PE_DESC, PE_COSTO_SIN, PE_RUTA, PE_CEDIS, SUM(PE_COSTO_TOT) AS PE_COSTO_TOT, PE_COSTOU, SUM(PE_CANT) As PE_CANT, PE_PRONOMBRE, PE_PROID, PE_CLIENTE, PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) GROUP BY PE_PRECIO2, PE_TIPO, PE_DESC, PE_COSTO_SIN,	PE_RUTA, PE_CEDIS, PE_COSTOU, PE_PRONOMBRE,	PE_PROID, PE_CLIENTE ") 'Mod por CHV - 220302 - Agregué PE_FECHA al select/insert

'	starter.skmt.ExecNonQuery2("INSERT INTO")
	p_promowhats.Visible = False
	P_INF_GENERAL.Visible = True
	c.Close
	b_whats.Visible = False
	Starter.skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS where HCCP_CLIENTE IN (Select cuenta from cuentaa)")
End Sub

Private Sub b_rechazapromo_Click
	Starter.skmt.ExecNonQuery2("INSERT INTO HIST_PROMO_WHATS VALUES (?,?)", Array As Object(l_promowhats.Text, "PROMO RECHAZADA"))
	p_promowhats.Visible = False
	P_INF_GENERAL.Visible = True
	b_whats.Visible = False
End Sub

Private Sub BP_DOE_A_Click
	c=Starter.skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
	If c.RowCount>0 Then
		C.Position=0
		Id_Almacen = C.GetString("ID_ALMACEN")
	End If
	c.Close
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c=Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	c.Close
	Starter.skmt.ExecNonQuery("INSERT INTO  PEDIDO (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) SELECT 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 FROM PEDIDO_DOE WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	Starter.skmt.ExecNonQuery2("UPDATE  PEDIDO SET PE_CEDIS = ?, PE_TIPO = ? WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As Object("DOE","DOE"))
	
	c=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, SUM(PE_COSTO_SIN) AS TOTAL_CLIE_SIN FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	Starter.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
	If logger Then LogColor($"Insertamos coordenadas en pedido: ${Starter.lon_gps}, ${Starter.lat_gps}"$, Colors.Magenta)
	Starter.skmt.ExecNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT,PC_ALMACEN,PC_RUTA,PC_COSTO_SIN) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), Starter.lon_gps, Starter.lat_gps,Id_Almacen,Starter.rutaV,c.GetString("TOTAL_CLIE_SIN")))
	Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
	c.Close
	Starter.skmt.ExecNonQuery("delete from PEDIDOS_DOE_ENTREGA  where PC_CLIENTE in (Select CUENTA from cuentaa)")
	Starter.skmt.ExecNonQuery2("insert into PEDIDOS_DOE_ENTREGA (PC_CLIENTE, PC_ENTREGA) VALUES (?,?) ", Array As Object(clie_id,"ENTREGADO"))
	
	Starter.skmt.ExecNonQuery("delete from pedido_DOE where pe_cliente in (Select CUENTA from cuentaa)")
	
	P_DOE.Visible = False
End Sub

Private Sub BP_DOE_R_Click
	
	Dim result As Int
	result = Msgbox2("El cliente perderá el descuento si cancela el pedio, se cancela el pedido ?", "Pedido Cancela", "SI", "", "NO", LoadBitmap(File.DirAssets, "alert2.png"))
	If result = DialogResponse.Positive Then
	
		Panel11.Visible = True
		BP_DOE_A.Visible = False
		BP_DOE_R.Visible = False
	Else
		P_DOE.Visible = False
	End If
	
End Sub

Private Sub l_ubicacion2_LongClick
	If laDist > 49 Then
		p_pideGeoPass.BringToFront
		p_pideGeoPass.Visible = True
	End If
End Sub

Private Sub p_pideGeoPass_Click
End Sub

Private Sub b_geopass_Click
	ime.HideKeyboard
	If et_geopass.Text = "KMTS1" Then
		m_lat = Starter.lat_gps
		m_lon = Starter.lon_gps
		GPS_LocationChanged(Starter.ubicacionActual)
		Starter.skmt.ExecNonQuery($"update kmt_info set CAT_CL_LAT = '${Starter.lat_gps}', CAT_CL_LONG = '${Starter.lon_gps}' where CAT_CL_CODIGO = '${Subs.traeCliente}'"$)
		B_VENTA.Visible = True
		Tels.Visible = True
		et_geopass.Text = ""
		p_pideGeoPass.Visible = False
	Else
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name = "select_geoPass"
		cmd.Parameters = Array As Object(et_geopass.Text, Subs.traeAlmacen, Subs.traeRuta)
		reqManager.ExecuteQuery(cmd , 0, "traeGeoPass")
		Log($"${Starter.server}, ${et_geopass.Text}, ${Subs.traeAlmacen}, ${Subs.traeRuta}"$)
		p_pideGeoPass.Visible = False
		ime.HideKeyboard
		'	Log("Guardamos coords")
		'	LATITUD = Starter.lat_gps
		'	LONGITUD = Starter.lon_gps
		'	GPS_LocationChanged(Starter.ubicacionActual)
		'	Starter.skmt.ExecNonQuery($"update kmt_info set CAT_CL_LAT = '${Starter.lat_gps}', CAT_CL_LONG = '${Starter.lon_gps}' where CAT_CL_CODIGO = '${Subs.traeCliente}'"$)
	End If
End Sub

Sub P_INF_GENERAL_Click
	If p_pideGeoPass.Visible Then p_pideGeoPass.Visible = False
End Sub

Sub JobDone(Job As HttpJob)
	If Job.Success = False Then
'		ToastMessageShow("Error: " & Job.ErrorMessage, True)
		LogColor("Error: " & Job.ErrorMessage, Colors.red)
	Else
		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 = "traeGeoPass" Then 'query tag
				Log("SIN REGISTROS " & result.Rows.Size)
				If result.Rows.Size = 0 Then MsgboxAsync("Contraseña equivocada, por favor intente de nuevo.", "ATENCION")
				For Each records() As Object In result.Rows
'					For Each k As String In result.Columns.Keys
'						Log(k & ": " & records(result.Columns.Get(k)))
'					Next
					Private permiso_geoPass As String = records(result.Columns.Get("'OK'"))
					If permiso_geoPass = "OK" Then
						m_lat = Starter.lat_gps
						m_lon = Starter.lon_gps
						GPS_LocationChanged(Starter.ubicacionActual)
						Starter.skmt.ExecNonQuery($"update kmt_info set CAT_CL_LAT = '${Starter.lat_gps}', CAT_CL_LONG = '${Starter.lon_gps}' where CAT_CL_CODIGO = '${Subs.traeCliente}'"$)
						Dim cmd As DBCommand
						cmd.Initialize
						cmd.Name = "delete_geoPass"
						cmd.Parameters = Array As Object( Subs.traeAlmacen, Subs.traeRuta)
						reqManager.ExecuteQuery(cmd , 0, "traeGeoPass")

					End If
				Next
			End If
		End If
	End If
	Job.Release
End Sub

Private Sub BP_DOE_R1_Click
	If r_1.Checked Then
		motivo = "CERRADO"
	Else If r_2.Checked Then
		motivo = "NO LO PIDIO"
	Else If r_3.Checked Then
		motivo = "FUERA DE TIEMPO"
	Else if r_4.Checked Then
		motivo = "NO ESTA EL ENCARGADO"
	Else if R_5.Checked Then
		motivo = "FALTA DE DINERO"
	End If
	motivo = motivo & " " & e_comm.Text
	
	BP_DOE_A.Visible = True
	BP_DOE_R.Visible = True
	
	Panel11.Visible = False
	P_DOE.Visible = False
	c=Starter.skmt.ExecQuery("select PE_PROID,PE_CANT, PE_TIPO FROM PEDIDO_DOE where pe_cliente in (Select CUENTA from cuentaa) ")
	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
'	Starter.skmt.ExecNonQuery("delete from pedido_cliente where pc_cliente in (Select CUENTA from cuentaa)")
	Starter.skmt.ExecNonQuery("delete from PEDIDOS_DOE_ENTREGA  where PC_CLIENTE in (Select CUENTA from cuentaa)")
	Starter.skmt.ExecNonQuery2("insert into PEDIDOS_DOE_ENTREGA (PC_CLIENTE, PC_ENTREGA) VALUES (?,?) ", Array As Object(clie_id,motivo))
	
	Starter.skmt.ExecNonQuery("delete from pedido_DOE where pe_cliente in (Select CUENTA from cuentaa)")
	P_DOE.Visible = False
End Sub

private Sub pedido_doe_muestra
	''' ESTO SE AGREGA PARA QUE SE VEA LOS CLIENTES DOE
	Dim YA_TIENE_PEDIDO_DOE As String
	
	C5=Starter.skmt.ExecQuery2("select COUNT(*) AS CLIENTE_DOE from PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) AND PE_CEDIS = ? ", Array As String("DOE"))
	C5.Position = 0
	If C5.GetString("CLIENTE_DOE") > 0 Then
		YA_TIENE_PEDIDO_DOE = 1
	Else
		YA_TIENE_PEDIDO_DOE = 0
	End If
	C5.Close
	If YA_TIENE_PEDIDO_DOE = 0 Then
		C5=Starter.skmt.ExecQuery("select COUNT(*) AS CLIENTE_DOE from PEDIDO_DOE WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) ")
		C5.Position = 0
		If C5.GetString("CLIENTE_DOE") >0 Then
			P_DOE.VISIBLE = True
			C6=Starter.skmt.ExecQuery("select PE_PROID, PE_PRONOMBRE, PE_CANT, PE_COSTO_TOT from PEDIDO_DOE where  PE_CLIENTE IN (Select CUENTA from cuentaa)")
			LP_DOE.Clear
			If C6.RowCount>0 Then
				For i=0 To C6.RowCount -1
					C6.Position=i
					Dim label1 As Label
					label1 = LP_DOE.TwoLinesLayout.Label
					label1.TextSize = 14
					label1.TextColor = Colors.Black
					Dim label2 As Label
					label2 = LP_DOE.TwoLinesLayout.SecondLabel
					label2.TextSize = 14
					label2.TextColor = Colors.Black
					LP_DOE.AddTwoLines(C6.GetString("PE_PRONOMBRE"), " # " & C6.GetString("PE_CANT") & " TOTAL " & C6.GetString("PE_COSTO_TOT")  )
				Next
			End If
			C6.Close
			C6=Starter.skmt.ExecQuery("select SUM(PE_CANT) AS CANT, SUM(PE_COSTO_TOT) AS TOTAL from PEDIDO_DOE where  PE_CLIENTE IN (Select CUENTA from cuentaa)")
			C6.Position= 0
			L_DOE_TOTAL.Text = "TOTAL PEDIDO DOE :"& C6.GetString("TOTAL") & " No. PIEZAS: " & C6.GetString("CANT")
			C6.Close
			''' FALTAN LOS BOTONES DE ACEPTAR Y RECHAZAR, INVENTAIRO ABORDO MODIFICAR PARA IMPRIMIR
		End If
		C5.Close
	End If
End Sub

