B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=11.5
@EndOfDesignText@
Sub Class_Globals
	Private Root As B4XView 'ignore
	Private xui As XUI 'ignore
	Private p_cliente As Panel

	Dim g As GPS
	Dim ruta As String
	Dim skmt As SQL
	Dim clie_id As String
	Dim sDate,sTime As String
	Dim usuario As String
	Dim total_cliente As String
	Dim m_lat, m_lon As String
	Dim btAdmin As BluetoothAdmin
	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 tipo_venta As String = "PREVENTA"
	Dim MAC_IMPRESORA As String
	
	
	Dim c As Cursor
	Dim s As Cursor
	Dim DD As Cursor
	Dim c2 As Cursor
	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 lat_gps, lon_gps As String

	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 CODIGO As String

	Private b_mapa As Button
	Dim CUANTOS As String
	Private B_IMP As Button
	Dim Toggla As Toggle
	Dim tgl As Toggle
	Private Panel1 As Panel
	Private I_COMPRA As EditText
	Private B_GUARDA_C As Button
	Private b_venta As Button
	Dim ALMACEN As String
	Dim LA_GPS As Label
	Private B_E_NEXT As Button
	Private E_RES_E As EditText
	Private t_tenc As Label
	Private Panel2 As Panel
	Private CONTADOR_E As String
	Private HR_RES1 As String
	Private HR_RES2 As String
	Private HR_RES3 As String
	Private EXISTE As String
	Private TELEFONO As String
	
	
	Private RB1 As RadioButton
	Private RB2 As RadioButton
	Private RB3 As RadioButton
	Private RB4 As RadioButton
	Private RB5 As RadioButton
	
	Private stay_hh As String
	Private stay_mi As String
	Private stay_ss As String
	
	Private LA_GEO As Label
	Dim result As Int
	Private cercavalor As String
	Private LA_RUTA As String
	
	Private b_like As Button
	Private B_GPS As Button
	Dim sc As JhsIceZxing1
	Dim CODIGO As String
	Private SV_ENCUESTA As ScrollView
	Private RB1_E1 As RadioButton
	Private RB2_E1 As RadioButton
	Private RB3_E1 As RadioButton
	Private CHB1 As CheckBox
	Private CHB2 As CheckBox
	Private CHB3 As CheckBox
	Private Panel5 As Panel
	Private B_guardaencuesta As Button
	Private RadioButton1 As RadioButton
	Private RadioButton2 As RadioButton
	Private RadioButton3 As RadioButton
	Private RadioButton4 As RadioButton
	Private RadioButton5 As RadioButton
	Private RadioButton6 As RadioButton
	Private RadioButton7 As RadioButton
	Private RadioButton8 As RadioButton
	Private RadioButton9 As RadioButton
	Private RadioButton10 As RadioButton
	Private RadioButton11 As RadioButton
	Private RadioButton12 As RadioButton
	Private RadioButton13 As RadioButton
	Private RadioButton14 As RadioButton	
	Private CheckBox1 As CheckBox
	Private CheckBox2 As CheckBox
	Private CheckBox3 As CheckBox
	Private CheckBox4 As CheckBox
	Private CheckBox5 As CheckBox
	Private CheckBox6 As CheckBox
	Private CheckBox7 As CheckBox
	Private CheckBox8 As CheckBox
	Dim encuentasmapa As Map
	Private p6 As EditText
	Private p7 As EditText
	Private p8 As EditText
	Private Panel7 As Panel
	Private RadioButton17 As RadioButton
	Private RadioButton16 As RadioButton
	Private RadioButton15 As RadioButton
	Private B_guardaencuesta_m2 As Button
	Private et_p1_m2 As EditText
	Private et_p2_m2 As EditText
	Private RB7_P6_M2 As RadioButton
	Private RB6_P6_M2 As RadioButton
	Private RB5_P6_M2 As RadioButton
	Private RB4_P6_M2 As RadioButton
	Private RB3_P6_M2 As RadioButton
	Private RB2_P6_M2 As RadioButton
	Private RB1_P6_M2 As RadioButton
	Private et_p5_m2 As EditText
	Private rd3_p4_m2 As RadioButton
	Private rd2_p4_m2 As RadioButton
	Private rd1_p4_m2 As RadioButton
	Private RB1_P3_M2 As RadioButton
	Private RB2_P3_M2 As RadioButton
	Private RB3_P3_M2 As RadioButton
	Private RB4_P3_M2 As RadioButton
	Private ET_P3_M2 As EditText
	Private Panel7_M2 As Panel
	Private P4_M2 As String
	Private P3_M2 As String
	Private P6_M2 As String
	
	Private CB1_P3_M2 As CheckBox
	Private CB2_P3_M2 As CheckBox
	Private CB3_P3_M2 As CheckBox
	Private CB4_P3_M2 As CheckBox
	Private CB5_P3_M2 As CheckBox
	Private CB6_P3_M2 As CheckBox
	Private EXISTE2 As String
	Private EXISTE3 As String
	Private EXISTE4 As String
	Private EXISTE5 As String
	Private et_p1_m3 As EditText
	Private et_p2_m3 As EditText
	Private CB1_P3_M3 As CheckBox
	Private CB2_P3_M3 As CheckBox
	Private CB3_P3_M3 As CheckBox
	Private CB4_P3_M3 As CheckBox
	Private CB5_P3_M3 As CheckBox
	Private CB1_P4_M3 As CheckBox
	Private CB2_P4_M3 As CheckBox
	Private CB3_P4_M3 As CheckBox
	Private CB4_P4_M3 As CheckBox
	Private CB5_P4_M3 As CheckBox
	Private rd1_p5_m3 As RadioButton
	Private rd2_p5_m3 As RadioButton
	Private CB1_P6_M3 As CheckBox
	Private CB2_P6_M3 As CheckBox
	Private CB3_P6_M3 As CheckBox
	Private CB4_P6_M3 As CheckBox
	Private CB5_P6_M3 As CheckBox
	Private CB6_P6_M3 As CheckBox
	Private ET_P6_M3 As EditText
	Private CB1_P7_M3 As CheckBox
	Private CB2_P7_M3 As CheckBox
	Private CB3_P7_M3 As CheckBox
	Private CB4_P7_M3 As CheckBox
	Private CB1_P8_M3 As CheckBox
	Private CB2_P8_M3 As CheckBox
	Private CB_P8_M3 As CheckBox
	Private CB4_P8_M3 As CheckBox
	Private RB1_P9_M3 As RadioButton
	Private RB2_P9_M3 As RadioButton
	Private RB3_P9_M3 As RadioButton
	Private RB4_P9_M3 As RadioButton
	Private RB5_P9_M3 As RadioButton
	Private B_guardaencuesta_m3 As Button
	Private P_gallina As Panel
	Private b_acepta_gallina As Button
	Private B_CANCELA_GALLINA As Button
	Private B_GALLINA As Button
	Private la_cuenta_gallina As Label
	Private cb_pregunta As B4XComboBox
	Dim girotienda As String
	Private p_pregunta1 As Panel
	Private b_preguntag As Button
	Private et_p1_m4 As EditText
	Private et_p2_m4 As EditText
	Private cb_p3_m4 As B4XComboBox
	Private cb_p4_1_m4 As B4XComboBox
	Private cb_p4_2_m4 As B4XComboBox
	Private cb_p4_3_m4 As B4XComboBox
	Private cb_p4_4_m4 As B4XComboBox
	Private cb_p4_5_m4 As B4XComboBox
	Dim itemselect2 As String
	Dim itemselect3 As String
	Dim itemselect4 As String
	Dim itemselect5 As String
	Dim itemselect6 As String
	Dim itemselect7 As String
	Private B_guardaencuesta_m4 As Button
	Private p_modulo5 As Panel
	Private cb_p1_m5 As B4XComboBox
	Private cb_p2_m5 As B4XComboBox
	Private cb_p3_m5 As B4XComboBox
	Private cb_p4_m5 As B4XComboBox
	Private cb_p5_m5 As B4XComboBox
	Private cb_p6_m5 As B4XComboBox
	Private cb_p7_m5 As B4XComboBox
	Private cb_p8_m5 As B4XComboBox
	Private cb_p9_m5 As B4XComboBox
	Dim itemselect8 As String
	Dim itemselect9 As String
	Dim itemselect10 As String
	Dim itemselect11 As String
	Dim itemselect12 As String
	Dim itemselect13 As String
	Dim itemselect14 As String
	Dim itemselect15 As String
	Dim itemselect16 As String
	Private B_guardaencuesta_m5 As Button
End Sub

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

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	'load the layout to Root
'	Activity.RemoveAllViews
	Root.LoadLayout("cliente")
	ruta = File.DirInternal
	If File.Exists(ruta, "kmt.db") = False Then
		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
	End If
	skmt.Initialize(ruta,"kmt.db", True)
	c=B4XPages.MainPage.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  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	s=B4XPages.MainPage.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")
		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")
		la_saldooper.Text = c.GetString("CAT_CL_EMAIL")
		l_total.Text = s.GetString("TOTAL_CLIE")
		total_cliente = s.GetString("TOTAL_CLIE")
		MONTO_COMPRA = c.GetString("CAT_CL_MTOCOMPRA")
	End If
	c.Close
	s.Close
	btAdmin.Initialize("BlueTeeth")
	cmp20.Initialize("Printer")
	SV_ENCUESTA.Height = Root.Height
	SV_ENCUESTA.Width = Root.Height
	p_pregunta1.Height = Root.Height
	p_pregunta1.Width = Root.Height
End Sub

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

Sub B4XPage_Appear
	B4XPages.MainPage.tipo_venta = tipo_venta
	encuentasmapa.Initialize
	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_CAMERA)
	Wait For Activity_PermissionResult (Permission As String, resultC As Boolean)
	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
	Wait For Activity_PermissionResult (Permission As String, resultC As Boolean)

	LA_GPS.TextColor = Colors.Red
	LA_GPS.Text = "SIN UBICACION GPS"
	cercavalor = 0
	If Not(Starter.gps.GPSEnabled) Then
		ToastMessageShow("Es necesario tener el GPS encendido", True)
		StartActivity(Starter.gps.LocationSettingsIntent)
	End If
	skmt.Initialize(ruta,"kmt.db", True)
	c=B4XPages.MainPage.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_NUM_SERIEFISICO  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	s=B4XPages.MainPage.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")
		la_cuenta_gallina.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")
		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")
		TELEFONO  = c.GetString("CAT_CL_TELEFONO")
		l_total.Text = s.GetString("TOTAL_CLIE")
		total_cliente = s.GetString("TOTAL_CLIE")
		m_lat = "0"
		If c.GetString("CAT_CL_LAT") <> "" Then m_lat =c.GetString("CAT_CL_LAT")
		If m_lat.Length < 5 Then m_lat = "0"
		m_lon = "0"
		If c.GetString("CAT_CL_LONG") <> "" Then m_lon =c.GetString("CAT_CL_LONG")
		If m_lon.Length < 5 Then m_lon = "0"
		LA_RUTA = c.GetString("CAT_CL_RUTA")
		' ESTO ES PARA FORZAR A PEDIR LA FOTO Y EL GPS
		If c.GetString("CAT_CL_NUM_SERIEFISICO") = "0"  Then
			L_QR.TEXT = "SIN CODIGO"
			L_QR.TextColor = Colors.Red
			gest.VISIBLE = True
			BT_QR.Visible = True
		Else
			L_QR.TEXT = c.GetString("CAT_CL_NUM_SERIEFISICO")
			L_QR.TextColor = Colors.Blue
			BT_QR.Visible = False
		End If
	End If
	c.Close
	s.Close
	
	S2=B4XPages.MainPage.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=B4XPages.MainPage.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
	c=B4XPages.MainPage.skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
	If c.RowCount>0 Then
		C.Position=0
		ALMACEN = C.GetString("ID_ALMACEN")
	End If
	c.Close
	If ALMACEN = "1" Then
		Tels.Visible = False
		gest.Visible = True
		B_GPS.Visible = False
	End If
	If ALMACEN = "4"  Then
		b_like.Visible = False
		DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_VENTAS WHERE HVD_CLIENTE IN (Select cuenta from cuentaa) AND HVD_PRONOMBRE =?", Array As String("KNORR RINDE MAS 70 GR"))
		DD.Position =0
		If DD.GetString("CUANTOS")  = 0 Then
			c=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM PEDIDO  WHERE PE_CLIENTE  IN (Select cuenta from cuentaa) AND PE_PRONOMBRE =?", Array As String("KNORR RINDE MAS 70 GR"))
			c.Position =0
			If c.GetString("CUANTOS") = 0 Then
				b_like.Visible = False
			Else
				b_like.Visible = False
			End If
			c.Close
		Else
			b_like.Visible = False
		End If
		DD.Close
	Else
		b_like.Visible = False
	End If
	If ALMACEN = "16" Or ALMACEN = "13" Then
		Tels.Visible = True
		gest.Visible = True
	End If
	CallSubDelayed(Tracker, "Track")
	CallSubDelayed(Tracker, "StartFLPSmall")
	If Tracker.FLP.GetLastKnownLocation.IsInitialized Then 'Si tenemos "UltimaUbicaccionConocida" la usamos.
		B4XPages.MainPage.lat_gps = Tracker.FLP.GetLastKnownLocation.Latitude
		B4XPages.MainPage.lon_gps = Tracker.FLP.GetLastKnownLocation.Longitude
'		Log($"Tenemos UUC: ${Tracker.FLP.GetLastKnownLocation.Latitude},${Tracker.FLP.GetLastKnownLocation.Longitude}"$)
		GPS_LocationChanged(Tracker.FLP.GetLastKnownLocation)
	End If
	If ALMACEN = "1" Or ALMACEN = "2" Or ALMACEN = "4" Or ALMACEN = "5" Or ALMACEN = "25" Then
	DD=skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_VENTAS WHERE HVD_CLIENTE IN (Select cuenta from cuentaa) AND HVD_PRONOMBRE =?", Array As String("KNORR SUIZA GALLINA"))
	DD.Position =0
	If DD.GetString("CUANTOS")  = 0 Then
		c=skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM PEDIDO  WHERE PE_CLIENTE  IN (Select cuenta from cuentaa) AND PE_PRONOMBRE =?", Array As String("KNORR SUIZA GALLINA"))
		c.Position =0
		If c.GetString("CUANTOS") = 0 Then
			B_GALLINA.Visible = True
		Else
			B_GALLINA.Visible = False
		End If
		c.Close
	Else
		B_GALLINA.Visible = False
	End If
	DD.Close
	Else
		B_GALLINA.Visible = False
	End If
	P_gallina.Visible = False
End Sub

Sub GPS_LocationChanged (Location1 As Location)
'	LogColor($"Entrando a Cliente.GPS_LocationChanged"$, Colors.red)
	If Tracker.FLP.GetLastKnownLocation.IsInitialized And Tracker.FLP.GetLastKnownLocation.Latitude <> 0 Then
		B4XPages.MainPage.lat_gps = Tracker.FLP.GetLastKnownLocation.Latitude
		B4XPages.MainPage.lon_gps = Tracker.FLP.GetLastKnownLocation.Longitude
'		Log("Coords set to: " & B4XPages.MainPage.lat_gps & " and " & B4XPages.MainPage.lon_gps)
	End If
	
	Dim l1, l2 As Location
	l1.Initialize2(B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps)
'	Log($"Coordenadas de la tienda - lat:${m_lat}, lon:${m_lon}"$)
	l2.Initialize2(m_lat, m_lon)
	
	BT_QR.Enabled = True
	LA_GPS.TextColor = Colors.Blue
	LA_GPS.Text = "CON UBICACION GPS"
	B_GPS.Enabled = True
	'now we need the distance between our location and the target location
	Dim distance As Long
	distance =    l1.DistanceTo(l2)  'the result is in meter
	gest.Visible = True
	If distance < 100 Then
		LA_GEO.TextColor = Colors.Blue
		Tels.Visible = True
		gest.Visible = True
	Else
		LA_GEO.TextColor = Colors.Red
		If ALMACEN = "1" Then
			Tels.Visible = False
			gest.Visible = True
		End If
	End If
	LA_GEO.Text= $"$1.2{distance/1000} kms"$
	B4XPages.MainPage.skmt.ExecNonQuery("DELETE FROM HIST_GPS")
	B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO  HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
	CallSubDelayed(Tracker, "CreateLocationRequest")
End Sub

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

Sub gest_Click
'	Log(Subs.traeAlmacen)
	Dim Items As List
	Items.Initialize
	Items.Add("Selecciona una opción")
	Items.Add("Tienda de Abarrotes (Abarrotes, Misceláneas, Minisupers, Particulares con Venta y Cremerías)")
	Items.Add("Recaudería (Frutas y Verduras)")
	Items.Add("Vinos y Licores")
	Items.Add("Carnicería o Pollería")
	Items.Add("Farmacia")
	Items.Add("Jarciería (Productos de Limpieza)")
	Items.Add("Papelería y Regalos")
	Items.Add("Tortillería")
	Items.Add("Escuelas")
	Items.Add("Estanquillos (Puestos Semifijos)")
	Items.Add("Fonda, Cocina Económica, Cafetería)")
	Items.Add("Tlapalería, Ferretería")
	Items.Add("Dulcería, Materias Primas")
	Items.Add("Semillas y Chiles Secos")
	Items.Add("Cybercafé")
	Items.Add("Hotel")
	Items.Add("Veterinaria")
	Items.Add("Tienda de Mascotas")
	Items.Add("Otros")
	cb_pregunta.SetItems(Items)

	girotienda = "Selecciona una opcion"
	
'	Log(Subs.traeAlmacen)
	c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM ENCUESTA_MODULO1 WHERE CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	EXISTE  = c.GetString("CUANTOS")
	c.Close
	
	c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM ENCUESTA_MODULO2 WHERE CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	EXISTE2  = c.GetString("CUANTOS")
	c.Close
	
	c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM ENCUESTA_MODULO3 WHERE CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	EXISTE3  = c.GetString("CUANTOS")
	c.Close
	
	c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM ENCUESTA_MODULO4 WHERE CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	EXISTE4  = c.GetString("CUANTOS")
	c.Close
	
	c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM ENCUESTA_MODULO5 WHERE CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	EXISTE5  = c.GetString("CUANTOS")
	c.Close
	
'' esto para la primera encuesta m1	
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ENCUESTA")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60
'	Panel7.Visible = False

	'' para la m2
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ESNCUESTA_m2")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60
'	Panel7_M2.Visible = False
'	
	'' para la m3
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ENCUESSTA_M3")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60

	If Subs.traeAlmacen = 4 Or Subs.traeAlmacen = 36 Or Subs.traeAlmacen = 56 Then
		p_pregunta1.Visible = True
	Else
		B4XPages.ShowPage("productos")
	End If

End Sub

Private Sub cb_pregunta_SelectedIndexChanged (Index As Int)
	girotienda = Sender.As(B4XComboBox).SelectedItem
	Log(girotienda)
	Log(Index)
End Sub

Private Sub b_preguntag_Click
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE kmt_info SET CAT_CL_GIRO = ? WHERE CAT_CL_CODIGO = ? And CAT_CL_NOMBRE = ?", Array As Object (girotienda, la_cuenta.text,La_nombre.Text))
'' esto para la primera encuesta m1
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ENCUESTA")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60
'	Panel7.Visible = False

	'' para la m2
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ESNCUESTA_m2")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60
'	Panel7_M2.Visible = False
'	
	'' para la m3
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	SV_ENCUESTA.Panel.LoadLayout("ENCUESSTA_M3")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60

	'' para la m3
'	p_cliente.Visible = False
'	SV_ENCUESTA.Visible = True
'	p_pregunta1.Visible = False
'	SV_ENCUESTA.Panel.LoadLayout("ENCUESTA_M4")
'	Panel5.Width = Root.Width * 0.94
'	SV_ENCUESTA.Panel.Height = Panel5.Height + 60
'			
'	Dim Items2 As List
'	Items2.Initialize
'	Items2.Add("Selecciona una opcion")
'	Items2.Add("Propio")
'	Items2.Add("Rentado")
'	cb_p3_m4.SetItems(Items2)
'	itemselect2 = "Selecciona una opcion"
'	
'	Dim Items3 As List
'	Items3.Initialize
'	Items3.Add("Selecciona una opcion")
'	Items3.Add("Completamente Surtido")
'	Items3.Add("Bien Surtido")
'	Items3.Add("Poco Surtido")
'	Items3.Add("Muy Poco Surtido")
'	Items3.Add("Sin Existencias")
'	cb_p4_1_m4.SetItems(Items3)
'	itemselect3 = "Selecciona una opcion"
'	cb_p4_2_m4.SetItems(Items3)
'	itemselect4 = "Selecciona una opcion"
'	cb_p4_3_m4.SetItems(Items3)
'	itemselect5 = "Selecciona una opcion"
'	cb_p4_4_m4.SetItems(Items3)
'	itemselect6 = "Selecciona una opcion"
'	cb_p4_5_m4.SetItems(Items3)
'	itemselect7 = "Selecciona una opcion"
'	
	If girotienda = "Tienda de Abarrotes (Abarrotes, Misceláneas, Minisupers, Particulares con Venta y Cremerías)"  Then
		If  Subs.traeAlmacen = 36  And EXISTE4 = 0 Then
			p_cliente.Visible = False
			SV_ENCUESTA.Visible = True
			p_pregunta1.Visible = False
			SV_ENCUESTA.Panel.LoadLayout("ENCUESTA_M4")
			Panel5.Width = Root.Width * 0.94
			SV_ENCUESTA.Panel.Height = Panel5.Height + 60
			
			Dim Items2 As List
			Items2.Initialize
			Items2.Add("Selecciona una opcion")
			Items2.Add("Propio")
			Items2.Add("Rentado")
			cb_p3_m4.SetItems(Items2)
			itemselect2 = "Selecciona una opcion"
	
			Dim Items3 As List
			Items3.Initialize
			Items3.Add("Selecciona una opcion")
			Items3.Add("Completamente Surtido")
			Items3.Add("Bien Surtido")
			Items3.Add("Poco Surtido")
			Items3.Add("Muy Poco Surtido")
			Items3.Add("Sin Existencias")
			cb_p4_1_m4.SetItems(Items3)
			itemselect3 = "Selecciona una opcion"
			cb_p4_2_m4.SetItems(Items3)
			itemselect4 = "Selecciona una opcion"
			cb_p4_3_m4.SetItems(Items3)
			itemselect5 = "Selecciona una opcion"
			cb_p4_4_m4.SetItems(Items3)
			itemselect6 = "Selecciona una opcion"
			cb_p4_5_m4.SetItems(Items3)
			itemselect7 = "Selecciona una opcion"
			
		ELSE IF Subs.traeAlmacen = 56 And EXISTE4 = 0 Then
			p_cliente.Visible = False
			SV_ENCUESTA.Visible = True
			p_pregunta1.Visible = False
			SV_ENCUESTA.Panel.LoadLayout("ENCUESTA_M4")
			Panel5.Width = Root.Width * 0.94
			SV_ENCUESTA.Panel.Height = Panel5.Height + 60
			
			Dim Items2 As List
			Items2.Initialize
			Items2.Add("Selecciona una opcion")
			Items2.Add("Propio")
			Items2.Add("Rentado")
			cb_p3_m4.SetItems(Items2)
			itemselect2 = "Selecciona una opcion"
	
			Dim Items3 As List
			Items3.Initialize
			Items3.Add("Selecciona una opcion")
			Items3.Add("Completamente Surtido")
			Items3.Add("Bien Surtido")
			Items3.Add("Poco Surtido")
			Items3.Add("Muy Poco Surtido")
			Items3.Add("Sin Existencias")
			cb_p4_1_m4.SetItems(Items3)
			itemselect3 = "Selecciona una opcion"
			cb_p4_2_m4.SetItems(Items3)
			itemselect4 = "Selecciona una opcion"
			cb_p4_3_m4.SetItems(Items3)
			itemselect5 = "Selecciona una opcion"
			cb_p4_4_m4.SetItems(Items3)
			itemselect6 = "Selecciona una opcion"
			cb_p4_5_m4.SetItems(Items3)
			itemselect7 = "Selecciona una opcion"
			
		Else If Subs.traeAlmacen = 4  And EXISTE5 = 0 Then
			p_cliente.Visible = False
			SV_ENCUESTA.Visible = True
			p_pregunta1.Visible = False
			SV_ENCUESTA.Panel.LoadLayout("ENCUESTA_M5")
			p_modulo5.Width = Root.Width * 0.94
			SV_ENCUESTA.Panel.Height = p_modulo5.Height + 60
	
			Dim Items8 As List
			Items8.Initialize
			Items8.Add("Selecciona una opcion")
			Items8.Add("Completamente Surtido")
			Items8.Add("Bien Surtido")
			Items8.Add("Poco Surtido")
			Items8.Add("Muy Poco Surtido")
			Items8.Add("Sin Existencias")
			cb_p1_m5.SetItems(Items8)
			itemselect8 = "Selecciona una opcion"
			cb_p2_m5.SetItems(Items8)
			itemselect9 = "Selecciona una opcion"
			cb_p3_m5.SetItems(Items8)
			itemselect10 = "Selecciona una opcion"
			cb_p4_m5.SetItems(Items8)
			itemselect11 = "Selecciona una opcion"
			cb_p5_m5.SetItems(Items8)
			itemselect12 = "Selecciona una opcion"
			cb_p6_m5.SetItems(Items8)
			itemselect13 = "Selecciona una opcion"
			cb_p7_m5.SetItems(Items8)
			itemselect14 = "Selecciona una opcion"
			cb_p8_m5.SetItems(Items8)
			itemselect15 = "Selecciona una opcion"
			cb_p9_m5.SetItems(Items8)
			itemselect16 = "Selecciona una opcion"
		End If
	Else
		B4XPages.ShowPage("productos")
	End If
End Sub

Private Sub cb_p3_m4_SelectedIndexChanged (Index As Int)
	itemselect2 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect2)
	Log(Index)
End Sub

Private Sub cb_p4_1_m4_SelectedIndexChanged (Index As Int)
	itemselect3 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect3)
	Log(Index)
End Sub

Private Sub cb_p4_2_m4_SelectedIndexChanged (Index As Int)
	itemselect4 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect4)
	Log(Index)
End Sub

Private Sub cb_p4_3_m4_SelectedIndexChanged (Index As Int)
	itemselect5 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect5)
	Log(Index)
End Sub

Private Sub cb_p4_4_m4_SelectedIndexChanged (Index As Int)
	itemselect6 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect6)
	Log(Index)
End Sub

Private Sub cb_p4_5_m4_SelectedIndexChanged (Index As Int)
	itemselect7 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect7)
	Log(Index)
End Sub

Private Sub cb_p1_m5_SelectedIndexChanged (Index As Int)
	itemselect8 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect8)
	Log(Index)
End Sub

Private Sub cb_p2_m5_SelectedIndexChanged (Index As Int)
	itemselect9 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect9)
	Log(Index)
End Sub

Private Sub cb_p3_m5_SelectedIndexChanged (Index As Int)
	itemselect10 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect10)
	Log(Index)
End Sub

Private Sub cb_p4_m5_SelectedIndexChanged (Index As Int)
	itemselect11 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect11)
	Log(Index)
End Sub

Private Sub cb_p5_m5_SelectedIndexChanged (Index As Int)
	itemselect12 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect12)
	Log(Index)
End Sub

Private Sub cb_p6_m5_SelectedIndexChanged (Index As Int)
	itemselect13 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect13)
	Log(Index)
End Sub

Private Sub cb_p7_m5_SelectedIndexChanged (Index As Int)
	itemselect14 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect14)
	Log(Index)
End Sub

Private Sub cb_p8_m5_SelectedIndexChanged (Index As Int)
	itemselect15 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect15)
	Log(Index)
End Sub

Private Sub cb_p9_m5_SelectedIndexChanged (Index As Int)
	itemselect16 = Sender.As(B4XComboBox).SelectedItem
	Log(itemselect16)
	Log(Index)
End Sub


Sub B_guardaencuesta_Click
	skmt.ExecNonQuery2("INSERT INTO ENCUESTA_MODULO1 (CLIENTE, ALMACEN,P1, P2, P3, P4, P5, P6, P7, P8, P9) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object(Subs.traeCliente, ALMACEN, encuentasmapa.Get("P1"),encuentasmapa.Get("P2"),encuentasmapa.Get("P3"),encuentasmapa.Get("P4"),encuentasmapa.Get("P5"),p6.Text,p7.Text,p8.Text,encuentasmapa.Get("P9")))
	SV_ENCUESTA.Visible = False
	p_cliente.Visible = True
	B4XPages.MainPage.tipo_venta = "PREVENTA"
	B4XPages.ShowPage("productos")
	MsgboxAsync("Encuesta guardada","")
	RB1_E1.Checked = False
	RB2_E1.Checked = False
	RB3_E1.Checked = False
	RadioButton15.Checked = False
	RadioButton16.Checked = False
	RadioButton17.Checked = False
	RadioButton1.Checked = False
	RadioButton2.Checked = False
	RadioButton3.Checked = False
	RadioButton4.Checked = False
	RadioButton5.Checked = False
	RadioButton6.Checked = False
	RadioButton7.Checked = False
	RadioButton8.Checked = False
	RadioButton9.Checked = False
	RadioButton10.Checked = False
	RadioButton11.Checked = False
	RadioButton12.Checked = False
	RadioButton13.Checked = False
	RadioButton14.Checked = False
	p6.Text = ""
	p7.Text = ""
	p8.Text = ""
	CheckBox1.Checked = False
	CheckBox2.Checked = False
	CheckBox3.Checked = False
	CheckBox4.Checked = False
	CheckBox5.Checked = False
	CheckBox6.Checked = False
	CheckBox7.Checked = False
	CheckBox8.Checked = False
End Sub

Sub Tels_Click
	B4XPages.ShowPage("NoVenta")
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
'	BACK key pressed
'	Return True To close, False To cancel
	If p_pregunta1.Visible Then
		p_pregunta1.Visible = False
	Else if SV_ENCUESTA.Visible Then
		SV_ENCUESTA.visible = False
		p_cliente.Visible = True
	Else
	B4XPages.ShowPage("Clientes")
	End If
'	Return True
	Return False
End Sub

Sub Tar_Click
	B4XPages.ShowPage("Nota")
End Sub

Sub DATOS_Click
	B4XPages.ShowPage("telefonos")
End Sub

Sub Guardar_Click
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	c.Close
	c=B4XPages.MainPage.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
		B4XPages.MainPage.skmt.ExecNonQuery("delete from NOVENTA where NV_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
		B4XPages.MainPage.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"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps))
		B4XPages.MainPage.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
	End If
	c.Close
	DateTime.TimeFormat = "HHmmss"
	sTime=DateTime.Time(DateTime.Now)
	B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_STORE set HSS_OUT = ?  where HSS_OUT = 0 AND  HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(sTime))
	'  B4XPages.MainPage.skmt.ExecNonQuery("UPDATE HIST_STAY_STORE set HSS_TOT = HSS_OUT - HSS_IN where HSS_CODIGO In (select cuenta from cuentaa)")
	Try
		c=B4XPages.MainPage.skmt.ExecQuery(" Select (substr(HSS_OUT,1,2) - substr(HSS_IN,1,2)) - Case when  (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) < 0 Then 1 Else 0 end HORAS_TOTALES, " & _
	"Case when  (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) < 0 Then (substr(HSS_OUT,3,2) + 60 - substr(HSS_IN,3,2)) " & _
	"	Else (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) End - Case when  (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) < 0 Then 1 Else 0 end  MINUTOS_TOTALES, " & _
	"Case when  (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) < 0 Then (substr(HSS_OUT,5,2) + 60 - substr(HSS_IN,5,2)) " & _
	"	Else (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) end SEGUNDOS_TOTALES " & _
	"	from HIST_STAY_STORE where HSS_CODIGO In (Select cuenta from cuentaa) ")
		c.Position = 0
		stay_hh = c.GetString("HORAS_TOTALES") * 60 * 60
		stay_mi = c.GetString("MINUTOS_TOTALES") * 60
		stay_ss = c.GetString("SEGUNDOS_TOTALES")
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_STORE set HSS_TOT = ?  where HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(stay_hh + stay_mi + stay_ss))
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE HIST_STAY_OUT set HSO_FIN = ?  ", Array As Object(sTime))
		c.Close
	Catch
		ToastMessageShow(".",True)
	End Try
	DateTime.TimeFormat = "HH:mm:ss"
	B4XPages.ShowPage("Principal")
End Sub

Sub NUEVO_Click
	B4XPages.ShowPage("NuevoCliente")
End Sub

Sub HIST_Click
	B4XPages.ShowPage("Historico")
End Sub

Sub BT_QR_Click
	sc.isportrait = True
	sc.timeoutDuration = 45
	sc.theViewFinderXfactor = 0.7
	sc.theViewFinderYfactor = 0.5
	sc.theResultColor = Colors.Green
	sc.mustVibrate = True
	sc.BeginScan("sc")
End Sub

Sub sc_result(atype As String,Values As String, image As Bitmap)
	'Log("Type : " & atype)
	'Log("Value : " & Values)
	CODIGO = Values
	DD=B4XPages.MainPage.skmt.ExecQuery2("SELECT COUNT(*) AS CUANTOS FROM kmt_info WHERE CAT_CL_NUM_SERIEFISICO = ?", Array As String(CODIGO))
	DD.Position =0
	If DD.GetString("CUANTOS") > 0 Then
		MsgboxAsync("Código ya asignado", "AVISO")
	Else
		If CODIGO.Length = 7 Then
			Msgbox2Async("El código "& CODIGO & " es correcto?" , "Title", "Yes", "Cancel", "No", Null, False)
			Wait For Msgbox_Result (resultado As Int)
			If resultado = DialogResponse.POSITIVE Then
				B4XPages.MainPage.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, B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps))
				L_QR.TEXT =CODIGO
				L_QR.TextColor = Colors.Blue
				B4XPages.MainPage.skmt.ExecNonQuery2("insert into HIST_CODIGO_BARRAS(CODIGOKMTS, CODIGOB, LAT, LON) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text,CODIGO, B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps))
			End If
		Else
			MsgboxAsync("Código No Valido", "AVISO")
		End If
	End If
	DD.Close
End Sub

Sub sc_timedout(timedOut As Boolean)
	Log("timedOut " & timedOut)
End Sub

Sub sc_usercancelled(userCancelled As Boolean)
	Log("userCancelled " & userCancelled)
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
	B4XPages.ShowPage("mapas")
End Sub

Sub B_IMP_Click
	TAMANO = 0
	ESPACIO = 21
	BLANCO = " "
	printer.Initialize(cmp20.OutputStream)
	printer.WriteLine("DURAKELO S.A. de C.V.")
	printer.WriteLine("RFC: DUR-011025-T12")
	printer.WriteLine("Tel.: 618-826-0104")
	printer.WriteLine("Vendedor: KMTS ")
	printer.WriteLine("Tienda: " & La_nombre.Text)
	printer.WriteLine("-----------PREVENTA-----------")
	s=B4XPages.MainPage.skmt.ExecQuery("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 FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	If S.RowCount>0 Then
		For i=0 To S.RowCount -1
			S.Position=i
			printer.WriteLine(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE"))
			TAMANO = s.GetLong("L_CANT") + TAMANO
			TAMANO = s.GetLong("L_COSTOU") + TAMANO
			TAMANO = s.GetLong("L_COSTO_TOT") + TAMANO
			ESPACIO = ESPACIO - TAMANO
			For E=0 To ESPACIO -1
				BLANCO = " " & BLANCO
			Next
			printer.WriteLine(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") )
			TAMANO = 0
			ESPACIO = 21
			BLANCO = " "
		Next
	End If
	s.Close
	printer.WriteLine("Total Preventa:   $" & total_cliente)
	printer.WriteLine("------------VENTA-------------")
	printer.WriteLine(" ")
	printer.WriteLine("TOTAL:   $" & total_cliente)
	printer.WriteLine(" ")
	printer.WriteLine("----ESTE TICKET NO ES UN -----")
	printer.WriteLine("--COMPROBANTE FISCAL, SOLO ES-")
	printer.WriteLine("--------INFORMATIVO-----------")
	printer.WriteLine("------------------------------")
	printer.WriteLine(" ")
	printer.Flush
'	printer.Close
End Sub

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

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

Sub B_GUARDA_C_Click
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c=B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c.Close
	c=B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	c.Close
	B4XPages.MainPage.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) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object ("4",.01 , .01, 2, "KNORR RINDE MAS 70 GR", "GUNA2",la_cuenta.TEXT, sDate & sTime, usuario,LA_RUTA))
	B4XPages.MainPage.skmt.ExecNonQuery2("INSERT INTO HIST_FACE(HFCLIENTE, HFALIAS,HFRUTA,HFALMACEN) VALUES (?,?,?,?) ", Array As Object(la_cuenta.Text, I_COMPRA.Text,LA_RUTA,ALMACEN))
	Panel1.Visible = False
	b_like.Visible = True
	Tar.Visible = True
	Tels.Visible = True
	gest.Visible = True
	b_like.Visible = False
	Guardar.Visible = True
End Sub

Sub b_venta_Click
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
'	s=B4XPages.MainPage.skmt.ExecQuery("select COUNT(*) AS CUANTOS from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
'	s.Position= 0
'	If s.GetString("CUANTOS") = 0 Then
'		c=B4XPages.MainPage.skmt.ExecQuery2("SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String("CUESTIONARIO"))
'		c.Position =0
'		If c.GetString("CAT_VA_VALOR") = "2" Then
'			res =  Msgbox2("El cliente maneja CAZARES ?","CAZARES", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'Ignore
'			If res = DialogResponse.POSITIVE Then
'				B4XPages.MainPage.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,"TIENE"))
'				Panel1.Visible =True
'				I_COMPRA.Text = ""
'				BT_QR.Visible= False
'			Else
'				B4XPages.MainPage.skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,"TIENE"))
'				B4XPages.MainPage.tipo_venta = "VENTA"
'				B4XPages.ShowPage("Productos")
'			End If
'		Else
'			B4XPages.MainPage.tipo_venta = "VENTA"
'			B4XPages.ShowPage("Productos")
'		End If
'		c.Close
'	Else
'		B4XPages.MainPage.tipo_venta = "VENTA"
'		B4XPages.ShowPage("Productos")
'	End If
'	s.Close
End Sub

Sub B_E_NEXT_Click
	If E_RES_E.Text <> "" Then
		B4XPages.MainPage.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,"DONDE"))
		Panel2.Visible = False
		B4XPages.ShowPage("Productos")
	Else
		Msgbox("SIN RESPUESTA","AVISO") 'Ignore
	End If
End Sub

Sub RB1_CheckedChange(Checked As Boolean)
	If RB1.Checked = True Then
		E_RES_E.Text = "CENTRAL DE ABASTOS"
	End If
End Sub

Sub RB2_CheckedChange(Checked As Boolean)
	If RB2.Checked = True Then
		E_RES_E.Text = "AUTOSERVICIO"
	End If
End Sub

Sub RB3_CheckedChange(Checked As Boolean)
	If RB3.Checked = True Then
		E_RES_E.Text = "CLUB DE PRECIO"
	End If
End Sub

Sub RB4_CheckedChange(Checked As Boolean)
	If RB4.Checked = True Then
		E_RES_E.Text = "DIRECTO PEDEGREE"
	End If
End Sub

Sub b_like_Click
	Panel1.Visible = True
	b_like.Visible = False
	Tar.Visible = False
	Tels.Visible = False
	gest.Visible = False
	b_venta.Visible = False
	Guardar.Visible = False
End Sub

Sub B_GPS_Click
	Dim result As Int
	result = Msgbox2("Esta seguro de cambiar las coordenadas de este cliente", "Aviso GPS", "SI", "", "NO", LoadBitmap(File.DirAssets, "alerta.jpg")) 'Ignore
	If result = DialogResponse.Positive Then
		B4XPages.MainPage.skmt.ExecNonQuery2("UPDATE  kmt_info SET CAT_CL_LAT = ?, CAT_CL_LONG = ? where CAT_CL_CODIGO In (Select cuenta from cuentaa)", Array As Object(B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
		B4XPage_Appear
	End If
End Sub

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


Private Sub Panel5_Click
	
End Sub

Private Sub RB1_E1_CheckedChange(Checked As Boolean)
	Log($"RB1 Clicked - chk:${Sender.As(RadioButton).Checked}"$)
	encuentasmapa.Put("P1", Sender.As(RadioButton).text)
	encuentasmapa.Remove("P2")
	Panel7.Visible = False
	RadioButton17.Checked = False
	RadioButton16.Checked = False
	RadioButton15.Checked = False
	encuentasmapa.Remove("P2")
	Log(encuentasmapa)
End Sub

Private Sub RB2_E1_CheckedChange(Checked As Boolean)
	Log($"RB2 Clicked - chk:${Sender.As(RadioButton).Checked}"$)
	encuentasmapa.Put("P1", Sender.As(RadioButton).text)
	RadioButton17.Checked = False
	encuentasmapa.Remove("P2")
	RadioButton17.Checked = False
	RadioButton16.Checked = False
	RadioButton15.Checked = False
	Panel7.Visible = False
	encuentasmapa.Remove("P2")
	Log(encuentasmapa)
End Sub

Private Sub RB3_E1_CheckedChange(Checked As Boolean)
	Log($"RB3 Clicked - chk:${Sender.As(RadioButton).Checked}"$)
	encuentasmapa.Put("P1", Sender.As(RadioButton).text)

	Panel7.Visible = True
	Log(encuentasmapa)
End Sub

Private Sub RadioButton17_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P2", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton18_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P2", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton19_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P2", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton1_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P3", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton2_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P3", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton3_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P3", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton4_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P3", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton5_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P4", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton6_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P4", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton7_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P4", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton8_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P4", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton9_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P4", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton10_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P5", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton11_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P5", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton12_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P5", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton13_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P5", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub RadioButton14_CheckedChange(Checked As Boolean)
	encuentasmapa.Put("P5", Sender.As(RadioButton).text)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox1_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox2_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox2.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox3_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox3.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox4_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox4.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox5_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox5.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox6_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox6.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox7_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox7.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox8.Checked Then textemp = textemp & " " & CheckBox8.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub CheckBox8_CheckedChange(Checked As Boolean)
	Dim textemp As String =""
	textemp = CheckBox8.Text
	If CheckBox1.Checked Then textemp = textemp & " " & CheckBox1.Text
	If CheckBox2.Checked Then textemp = textemp & " " & CheckBox2.Text
	If CheckBox3.Checked Then textemp = textemp & " " & CheckBox3.Text
	If CheckBox4.Checked Then textemp = textemp & " " & CheckBox4.Text
	If CheckBox5.Checked Then textemp = textemp & " " & CheckBox5.Text
	If CheckBox6.Checked Then textemp = textemp & " " & CheckBox6.Text
	If CheckBox7.Checked Then textemp = textemp & " " & CheckBox7.Text
	encuentasmapa.Put("P9", textemp)
	Log(encuentasmapa)
End Sub

Private Sub B_guardaencuesta_m2_Click
	If rd1_p4_m2.Checked Then P4_M2 = "ALTO" 
	If rd2_p4_m2.Checked Then P4_M2 = "MEDIO"
	If rd3_p4_m2.Checked Then P4_M2 = "BAJO"
	
	If RB1_P6_M2.Checked Then P6_M2 = "LUNES"
	If RB2_P6_M2.Checked Then P6_M2 = "MARTES"
	If RB3_P6_M2.Checked Then P6_M2 = "MIERCOLES"
	If RB4_P6_M2.Checked Then P6_M2 = "JUEVES"
	If RB5_P6_M2.Checked Then P6_M2 = "VIERNES"
	If RB6_P6_M2.Checked Then P6_M2 = "SABADO"
	If RB7_P6_M2.Checked Then P6_M2 = "DOMINGO"
	
	P3_M2 = CB1_P3_M2.Checked & "," & CB2_P3_M2.Checked & "," & CB3_P3_M2.Checked & "," & CB4_P3_M2.Checked & "," & CB5_P3_M2.Checked & "," & CB6_P3_M2.Checked & "," & RB1_P3_M2.Checked & "," & RB2_P3_M2.Checked & "," & RB3_P3_M2.Checked& "," & ET_P3_M2.TEXT
	
	
	skmt.ExecNonQuery2("INSERT INTO ENCUESTA_MODULO2 (CLIENTE, ALMACEN,P1, P2, P3, P4, P5, P6) VALUES (?,?,?,?,?,?,?,?)", Array As Object(Subs.traeCliente, ALMACEN,et_p1_m2.Text,et_p2_m2.Text,P3_M2,P4_M2,et_p5_m2.Text,P6_M2 ))
	SV_ENCUESTA.Visible = False
	p_cliente.Visible = True
	et_p1_m2.Text = ""
	et_p2_m2.TEXT = ""
	RB7_P6_M2.Checked = False
	RB6_P6_M2.Checked = False
	RB5_P6_M2.Checked = False
	RB4_P6_M2.Checked = False
	RB3_P6_M2.Checked = False
	RB2_P6_M2.Checked = False
	RB1_P6_M2.Checked = False
	et_p5_m2.Text = ""
	rd3_p4_m2.Checked = False
	rd2_p4_m2.Checked = False
	rd1_p4_m2.Checked = False
	RB1_P3_M2.Checked = False
	RB2_P3_M2.Checked = False
	RB3_P3_M2.Checked = False
	RB4_P3_M2.Checked = False
	
	CB1_P3_M2.Checked = False
	CB2_P3_M2.Checked = False
	CB3_P3_M2.Checked = False
	CB4_P3_M2.Checked = False
	CB5_P3_M2.Checked = False
	CB6_P3_M2.Checked = False
	
	ET_P3_M2.Text = ""
	P3_M2 = ""
	P4_M2 = ""
	P6_M2 = ""
	
	Panel7_M2.Visible = False
	
	B4XPages.MainPage.tipo_venta = "PREVENTA"
	B4XPages.ShowPage("productos")
	MsgboxAsync("Encuesta guardada","")
	
End Sub

Private Sub CB6_P3_M2_CheckedChange(Checked As Boolean)
	If CB6_P3_M2.Checked = True Then 
		Panel7_M2.Visible = True
	Else
		Panel7_M2.Visible = False
	End If
	
	
End Sub

Private Sub B_guardaencuesta_m3_Click
	Private P3_M3 As String
	Private P4_M3 As String
	Private P5_M3 As String
	Private P6_M3 As String
	Private P7_M3 As String
	Private P8_M3 As String
	Private P9_M3 As String
	
	If rd1_p5_m3.Checked Then P5_M3 = "SI"
	If rd2_p5_m3.Checked Then P5_M3 = "NO"
	
	If RB1_P9_M3.Checked Then P5_M3 = "DIARIO"
	If RB2_P9_M3.Checked Then P5_M3 = "BISEMANAL"
	If RB3_P9_M3.Checked Then P5_M3 = "SEMANAL"
	If RB4_P9_M3.Checked Then P5_M3 = "QUINCENAL"
	If RB5_P9_M3.Checked Then P5_M3 = "MENSUAL"

	P3_M3 = CB1_P3_M3.Checked & "," & CB2_P3_M3.Checked & "," & CB3_P3_M3.Checked & "," & CB4_P3_M3.Checked & "," & CB5_P3_M3.Checked 
	P4_M3 = CB1_P4_M3.Checked & "," & CB2_P4_M3.Checked & "," & CB3_P4_M3.Checked & "," & CB4_P4_M3.Checked & "," & CB5_P4_M3.Checked
	P6_M3 = CB1_P6_M3.Checked & "," & CB2_P6_M3.Checked & "," & CB3_P6_M3.Checked & "," & CB4_P6_M3.Checked & "," & CB5_P6_M3.Checked & "," & CB6_P6_M3.Checked  & "," & ET_P6_M3.TEXT
	P7_M3 = CB1_P7_M3.Checked & "," & CB2_P7_M3.Checked & "," & CB3_P7_M3.Checked & "," & CB4_P7_M3.Checked
	P8_M3 = CB1_P8_M3.Checked & "," & CB2_P8_M3.Checked & "," & CB_P8_M3.Checked & "," & CB4_P8_M3.Checked

	skmt.ExecNonQuery2("INSERT INTO ENCUESTA_MODULO3 (CLIENTE, ALMACEN,P1, P2, P3, P4, P5, P6,P7,P8,P9) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object(Subs.traeCliente, ALMACEN,et_p1_m3.Text,et_p2_m3.Text,P3_M3,P4_M3,P5_M3,P6_M3,P7_M3,P8_M3,P9_M3 ))
	SV_ENCUESTA.Visible = False
	p_cliente.Visible = True
	B4XPages.MainPage.tipo_venta = "PREVENTA"
	B4XPages.ShowPage("productos")
	MsgboxAsync("Encuesta guardada","")
End Sub

Private Sub B_guardaencuesta_m4_Click
	skmt.ExecNonQuery2("INSERT INTO ENCUESTA_MODULO4 (CLIENTE, ALMACEN,P1, P2, P3, P4, P5, P6, P7, P8) VALUES (?,?,?,?,?,?,?,?,?,?)", Array As Object(Subs.traeCliente, ALMACEN,et_p1_m4.Text,et_p2_m4.Text,itemselect2,itemselect3,itemselect4,itemselect5,itemselect6,itemselect7))
	SV_ENCUESTA.Visible = False
	p_cliente.Visible = True
	B4XPages.MainPage.tipo_venta = "PREVENTA"
	B4XPages.ShowPage("productos")
	MsgboxAsync("Encuesta guardada","")
End Sub

Private Sub B_guardaencuesta_m5_Click
	skmt.ExecNonQuery2("INSERT INTO ENCUESTA_MODULO5 (CLIENTE, ALMACEN,P1, P2, P3, P4, P5, P6, P7, P8, P9) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object(Subs.traeCliente, ALMACEN,itemselect8,itemselect9,itemselect10,itemselect11,itemselect12,itemselect13,itemselect14,itemselect15,itemselect16))
	SV_ENCUESTA.Visible = False
	p_cliente.Visible = True
	B4XPages.MainPage.tipo_venta = "PREVENTA"
	B4XPages.ShowPage("productos")
	MsgboxAsync("Encuesta guardada","")
End Sub


Private Sub B_ACEPTA_GALLINA_Click
	
	
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c=skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c.Close
	c=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	c.Close
	c=skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
	If c.RowCount>0 Then
		C.Position=0
		ALMACEN = C.GetString("ID_ALMACEN")
	End If
	c.Close
	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) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object ("PRO1771",0 , 0, 1, "1 KNORR SUIZA EXH C/50/22 GR +1 KNORR SUIZA GALLINA $279.00", "PRO1771",la_cuenta.TEXT, sDate & sTime, usuario,LA_RUTA))
	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) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object ("PRO1771",139.5 , 139.5, 1, "KNORR SUIZA EXH C/50/22 GR", "UNI047",la_cuenta.TEXT, sDate & sTime, usuario,LA_RUTA))
	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) VALUES(?,?,?,?,?,?,?,?,?,?) ", Array As Object ("PRO1771",139.5 , 139.5, 1, "KNORR SUIZA GALLINA", "UNI860",la_cuenta.TEXT, sDate & sTime, usuario,LA_RUTA))
	
	c=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
	skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
	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"), B4XPages.MainPage.lon_gps, B4XPages.MainPage.lat_gps,ALMACEN,LA_RUTA,c.GetString("TOTAL_CLIE_SIN")))
	skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")

	
	'Panel5.Visible = False
	B_GALLINA.Visible = False
	b_like.Visible = True
	Tar.Visible = True
	Tels.Visible = True
	gest.Visible = True
	'b_venta.Visible = True
	b_like.Visible = False
	Guardar.Visible = True
	P_gallina.Visible = False
End Sub

Private Sub B_CANCELA_GALLINA_Click
	P_gallina.Visible = False
	'Panel5.Visible = False
	B_GALLINA.Visible = False
	b_like.Visible = True
	Tar.Visible = True
	Tels.Visible = True
	gest.Visible = True
	'b_venta.Visible = True
	b_like.Visible = False
	Guardar.Visible = True
'	tipo_venta = "PREVENTA"
'	StartActivity(colonia2)
End Sub

Private Sub B_GALLINA_Click
	P_gallina.Visible = True
	
	B_GALLINA.Visible = False
	b_like.Visible = False
	BT_QR.Visible = False
	'Panel5.Visible = True
	b_like.Visible = False
	Tar.Visible = False
	Tels.Visible = False
	gest.Visible = False
	b_venta.Visible = False
	Guardar.Visible = False
	HIST.Visible = False
End Sub


