B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=6.8
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	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 As String
	Dim 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 tipov As String
	Dim Printer1 As EscPosPrinter
	Dim MAC_IMPRESORA As String


End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

    Dim c As Cursor
	Dim s As Cursor
	Dim c2 As Cursor
	Dim E1 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 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
	Private B_INV As Button
	Private B_IMP2 As Button
	
	Dim id_encuesta As String
	Dim LLAMAR_FOTO As String
	Dim CURSOR_FOTO As Int
	Dim TOMAR_FOTO As String
	Private Panel10 As Panel
	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 chk_1_valor As String
	Private chk_2_valor As String
	Private chk_3_valor As String
	Private t_tenc As Label
	Private E_RES_E As EditText
	Private B_E_NEXT As Button
	Private Panel9 As Panel
	Private Label26 As Label
	Dim impresoraConectada As Boolean = False
	Dim printer As TextWriter
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	'Activity.LoadLayout("Layout1")
	If(FirstTime) Then
	 g.Initialize("GPS")
	End If
	Activity.RemoveAllViews
    Activity.LoadLayout("info_gral")
	
	' valido donde escribo el archivo de la base de datos de kmt
	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=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  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=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

	  ' ListView1.Clear
	   
	   'If c.RowCount>0 Then
	    '  For i=0 To c.RowCount -1
		     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")
			FACTURA = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
	
			 
			' la_producto.Text = c.GetString("CDPROD")
			 'la_numero.Text = c.GetString("CDNUMEXT")
			 'la_nint.Text = c.GetString("CDNUMINT")
			 'la_pob.Text = c.GetString("CFSDOGLOBAL")
			 
			 'la_saldooper.Text = c.GetString("CAT_CL_FALTA")
			 'Label10.Text = "FECHA DE ALTA"
			 'Label11.Text = "# ENCUESTAS"
			 
			'c=skmt.ExecQuery("select MGCTA, MGACTT, MGGESTT, MGDTEACTT, COMM  from hist_gest where MGCTA In (Select cuenta from cuentaa)")
	 		'c.Position=0
			'la_comm.Text = c.GetString("COMM")
			'la_actdte.Text = C.GetString("MGDTEACTT")
			'la_usuario.Text = c.GetString("MGGESTT")
			'la_resultado.Text = c.GetString("MGACTT")
			
			 
			 'la_padre.Text = c.GetString("PR_CF_FECHA_DISP")
			 'la_no_ird.Text = c.GetString("PR_CF_SALDO_ACORT")
			 
	' se crea o no el archivo de la base de ddatos de kmt
	'NOTAS SI SE MODIFICA LA ESTRUCTURA SE QUITA EL IF Y SE VA DIRECTO A LA SENTENCIA FILE.COPY PARA QUE 
	'TOME LA NUEVA ESTRUCTURA ES MUY IMPORTANTE TENER EL IF DE LO CONTRARIO SOLO LO ESCRIBE UNA VEZ Y LO BORRA
	'SI SE REGRESA A ESTE ACTIVIDAD.
			 'ListView1.AddTwoLines(c.GetString("pr_cd_nombre"),c.GetString("pr_cd_colonia"))
	    '  Next
	   'End If
	   ' SE COMENTA IMPRESORA ANTERIOR
'	If FirstTime Then
'		btAdmin.Initialize("BlueTeeth")
'		cmp20.Initialize("Printer")
'	End If

	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("MACIMP"))
	c.Position = 0
	MAC_IMPRESORA = c.GetString("CAT_VA_VALOR")
	If MAC_IMPRESORA = "" Then MAC_IMPRESORA = "0"
	Starter.MAC_IMPRESORA = MAC_IMPRESORA
	   Log("|" & MAC_IMPRESORA & "|")
	If FirstTime Then
		Printer1.Initialize(Me, "Printer1")
		
	End If

TOMAR_FOTO = 0

End Sub

Sub Activity_Resume
	BT_QR.Enabled = False
	b_factura.Visible = False
FACTURA =0
If g.GPSEnabled=False Then
	  ToastMessageShow("Habilitar el GPS", True)
	  StartActivity(g.LocationSettingsIntent)
	 Else
	  g.Start(0,0)
	 End If
	
			skmt.Initialize(ruta,"kmt.db", True)
	c=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,CAT_CL_BFACTURA,CAT_CL_BCREDITO  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=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

	  ' ListView1.Clear
	   
	   'If c.RowCount>0 Then
	    '  For i=0 To c.RowCount -1
		     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")
			 '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")
			 m_lat =c.GetString("CAT_CL_LAT")
			 m_lon =c.GetString("CAT_CL_LONG")
			FACTURA = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
			
			If l_total.Text <> Null Then

			If la_cuenta.Text.Contains("N") = True Then
			FACTURA  = 0
			End If
				
			If FACTURA = "1" Then
			b_factura.Visible = True
			
			End If
			End If
			
			If CREDITO = "1" Then
			Msgbox("ALTO","Este cliente no se le puede vender ya que tienen adeudo en su crédito")
			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=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=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
			   
			' la_producto.Text = c.GetString("CDPROD")
			 'la_numero.Text = c.GetString("CDNUMEXT")
			 'la_nint.Text = c.GetString("CDNUMINT")
			 'la_pob.Text = c.GetString("CFSDOGLOBAL")
			 
			 'la_saldooper.Text = c.GetString("CAT_CL_FALTA")
			 'Label10.Text = "FECHA DE ALTA"
			 'Label11.Text = "# ENCUESTAS"
			 
	
			 'c=skmt.ExecQuery("select MGCTA, MGACTT, MGGESTT, MGDTEACTT, COMM  from hist_gest where MGCTA In (Select cuenta from cuentaa)")
	 		'c.Position=0
			'la_comm.Text = c.GetString("COMM")
			'la_actdte.Text = C.GetString("MGDTEACTT")
			'la_usuario.Text = c.GetString("MGGESTT")
			'la_resultado.Text = c.GetString("MGACTT")
'
'
'
''''''''''''''''''esto es para los pup de validacion 
'	
'	
'	s=skmt.ExecQuery("select count(*) as CUANTOS from HIST_VERIFICACION where HVE_CLIENTE IN (Select cuenta from cuentaa)")	
'	s.Position=0
'	If s.GetString("CUANTOS") = 0 Then
'		
'			If MONTO_COMPRA > 300 Then
'				META = "FELICIDADES ESTE CLIENTE YA ALCANZO LA META DE VENTA"
'			Else
'				META2 = 300 -  MONTO_COMPRA 
'		
'				META = "FALTA POR ALCANZAR META, LA VENTA MINIMA PARA HOY ES DE : " & META2
'			   
'			End If
'		c=skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'		If c.GetString("CUANTOS") <> 0 Then
'			
'		c2=skmt.ExecQuery("select CAT_VE_IDPROD, CAT_VE_NOMBRE, CAT_VE_ORDEN FROM CAT_VERIFICACION ORDER BY CAT_VE_ORDEN ")
 '        If c2.RowCount>0 Then
'	      For i=0 To c2.RowCount -1
''		  	c2.Position =i
'			VERIFICA = VERIFICA & "-------VALIDAR-------   " & c2.GetString("CAT_VE_NOMBRE")
'			
'	      	
'		  Next
'		End If
'	End If		
'		c.Close
'		c2.Close
'			
'		Msgbox(" Instrucciones:     " & META &" para este clinete el adicional " & VERIFICA &" y el cliente cuenta con 6 promos.","Indicaciones")

'	c=skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'	If c.GetString("CUANTOS") <> 0 Then
'		c2=skmt.ExecQuery("select CAT_VE_IDPROD, CAT_VE_NOMBRE, CAT_VE_ORDEN FROM CAT_VERIFICACION ORDER BY CAT_VE_ORDEN ")
 '        If c2.RowCount>0 Then
''	      For i=0 To c2.RowCount -1
'		  	c2.Position =i
'			'ToastMessageShow(c2.GetString("CAT_GP_NOMBRE"), True)
'
'		  	res =  Msgbox2("Tiene el cliente  " & c2.GetString("CAT_VE_NOMBRE"),"Verificacion", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'	      	If res = DialogResponse.POSITIVE Then
 '         	  skmt.ExecNonQuery2("INSERT INTO HIST_VERIFICACION VALUES (?,?,?)", Array As Object(la_cuenta.Text,c2.GetString("CAT_VE_IDPROD"), 1))
'	
'			Else
'		  	skmt.ExecNonQuery2("INSERT INTO HIST_VERIFICACION VALUES (?,?,?)", Array As Object(la_cuenta.Text,c2.GetString("CAT_VE_IDPROD"), 0))
'	
'			End If
'		  Next
'		End If
'	End If
'	c.Close
'	End If
'	s.Close

''''''''''''''''''''''''''' hasta aqui es todo para los pups de validacion.
' para imprimir			  	
'	Toggla.TurnBluetoothOn
'	btAdmin.Initialize("BlueTeeth")
'	cmp20.Initialize("Printer")
	If Printer1.IsConnected = False Then
		
		Printer1.Connect
		
	Else
		Printer1.DisConnect
		Printer1.Connect
		
	End If


'	StartPrinter
	If PASA_IMP = "1" Then
		B_IMP.Enabled = True
	End If
	
	'''''''''Agregar la parte de si tiene credito o no tiene credito
	If la_cuenta.Text="0" Then
		B_VENTA.Visible = False
		gest.Visible = False
	Else
		B_VENTA.Visible = True
		gest.Visible = True
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub GPS_LocationChanged (Location1 As Location)
'lat_gps=Location1.Latitude
'lon_gps=Location1.Longitude
'	BT_QR.Enabled = True
	Dim sDate,sTime As String
	
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
		   
	skmt.ExecNonQuery("DELETE FROM HIST_GPS")
	
	skmt.ExecNonQuery2("INSERT INTO  HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, Main.lat_gps, Main.lon_gps))
End Sub


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

Sub gest_Click
    'StartActivity(telefonos)
	
	'   skmt.ExecNonQuery("delete from PRODUCTOA")
	'  skmt.ExecNonQuery2("INSERT INTO PRODUCTOA VALUES (?)", Array As Object(la_producto.Text))
	'  Dim cuantos As String
  	'c=skmt.ExecQuery("select count(*) as cuantos from HIST_VISITAS WHERE HIST_VI_CREDITO IN (SELECT CUENTA FROM CUENTAA) ")
    '    c.Position = 0
	'    cuantos = c.GetString("cuantos")
	'	ToastMessageShow(cuantos,True)
	'If cuantos > 0 Then
	'StartActivity(gestion)
	'Else If cuantos = 0 Then

''''' ESTE CODIGO SIRVE PARA MANDAR EN PUPUP LA PROMOCIONES E IR PREGUNTANDO UNO A UNO.
''' DESDE EL CURSOR Y TODO EL IF DE ABAJO SON 20 LINEAS.
'	c=skmt.ExecQuery("select count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
'	    c.Position=0
'	If c.GetString("CUANTOS") = 0 Then
'		c2=skmt.ExecQuery2("select  CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG from cat_gunaprod where CAT_GP_ALMACEN > 0 and CAT_GP_CLASIF = ? AND CAT_GP_TIPO = ? AND CAT_GP_SUBTIPO = ?  AND CAT_GP_ID IN (SELECT HP_CODIGO_PROMOCION FROM HIST_PROMOS WHERE HP_CLIENTE IN (Select cuenta from cuentaa) )", Array As String("PROMOS", "PROMOS", "PROMOS"))
 '        If c2.RowCount>0 Then
'	      For i=0 To c2.RowCount -1
'		  	c2.Position =i
'			'ToastMessageShow(c2.GetString("CAT_GP_NOMBRE"), True)
'
'		  	res =  Msgbox2(" " & c2.GetString("CAT_GP_NOMBRE"),"IR......", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'	      	If res = DialogResponse.POSITIVE Then
 '         		skmt.ExecNonQuery("delete from PROID")
'	  			skmt.ExecNonQuery2("INSERT INTO PROID VALUES (?)", Array As Object(c2.GetString("CAT_GP_NOMBRE")))
'	  			StartActivity(pedidos)
'		  		i = c2.RowCount
'		  	else if i = c2.RowCount -1 Then
'		  			StartActivity(colonia2)
'		  	End If
'		  Next
'		Else
'			StartActivity(colonia2)
'		End If
'	Else
'		StartActivity(colonia2)
'	End If
'	c.Close
	''''' HASTA AQUI TERMINA LO DE LOS PUPUPS
Main.tipov = "PREVENTA"
' StartActivity(colonia2)
cuestionario
End Sub

Sub Tels_Click
     ' skmt.ExecNonQuery("delete from PEDIDO")
	  StartActivity(nopago)
End Sub
Sub Activity_KeyPress (key As Int) As Boolean
    ' BACK key pressed
    If key=KeyCodes.KEYCODE_BACK Then
            ' I want to capture the key here so I return True
			StartActivity(colonia)
            'Return True
    End If
    ' Returning False signals the system to handle the key
    Return False
End Sub

Sub Tar_Click
	 StartActivity(tarjeta)
End Sub
Sub DATOS_Click
	 StartActivity(telefonos)
End Sub
Sub Guardar_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=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	
	c=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
	skmt.ExecNonQuery("delete from NOVENTA where NV_CLIENTE In (select cuenta from cuentaa)")
	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) VALUES (?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), Main.lon_gps, Main.lat_gps))
	skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")		
	End If
	c.Close
	
	skmt.ExecNonQuery("delete from pedido3")
	skmt.ExecNonQuery("INSERT INTO PEDIDO3 SELECT 	PE_PRECIO2,	PE_TIPO,	PE_FOLIO,	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,	1 As PE_FECHA,	PE_USUARIO FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) GROUP BY PE_PRECIO2,	PE_TIPO,	PE_FOLIO,	PE_DESC,	PE_COSTO_SIN,	PE_RUTA,	PE_CEDIS,	PE_COSTOU, PE_PRONOMBRE,	PE_PROID, PE_CLIENTE ")
	c=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
			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
	skmt.ExecNonQuery("delete from pedido WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) ")
	skmt.ExecNonQuery("INSERT INTO PEDIDO SELECT * FROM PEDIDO3")
	
	
	StartActivity(seleccion)
End Sub
Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub
Sub HIST_Click
	StartActivity(Historico)
End Sub

Sub BT_QR_Click
	

    'StartActivity(QR_MODULE)
	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

	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, Main.lon_gps, Main.lat_gps))
	  
End Sub
Sub sc_noScan
    Log("nothing returned from the scan !!!!!")
End Sub
Sub calc_ean_checksum(number As String) As String           'this has now become redundant as I am only interested in QR Codes
    Dim i As Int
    Dim cO As Char
    Dim soma As Int
    Dim n As Int
    Dim digit As Float
   
    soma = 0
    For i=0 To number.Length - 1
        digit = number.SubString2(i,i+1)
        n= digit * ((i Mod 2) * 2 + 1)   
        soma=soma+n
    Next
    Return number & ( ( 10 - ( soma Mod 10 )) Mod 10 )
End Sub

Sub b_mapa_Click
	StartActivity(mapas)
End Sub

Sub B_IMP_Click
	
	c=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=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=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=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
	ProgressDialogShow("Imprimiendo, un momento ...")
	Printer1.DisConnect
	If Not(Printer1.IsConnected) Then
		Log("Conectando a impresora ...")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada)
			Sleep(1000)
			Log("++++++  " & cont)
			cont = cont + 1
			If cont = 7 Then Printer1.Connect 'Tratamos de reconectar
			If cont > 15 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	Else
		Log("conectando 2")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada) Or Not(Printer1.IsConnected)
			Sleep(1000)
			Log("******  " & cont)
			cont = cont + 1
			If cont = 2 Then Printer1.Connect
			If cont > 4 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	End If
	
	TAMANO = 0
	ESPACIO = 21
	BLANCO = " "
	Dim bmp As Bitmap
	bmp.InitializeResize(File.DirAssets, "durakelo1.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
	'printer.Initialize(cmp20.OutputStream)
	Printer1.WriteString("DURAKELO S.A. de C.V." &  CRLF)
	Printer1.WriteString("RFC: DUR-011025-T12" &  CRLF)
	Printer1.WriteString(sucursal &  CRLF)
	Printer1.WriteString(sDate &  CRLF)
	Printer1.WriteString(sTime &  CRLF)
	Printer1.WriteString("Vendedor:" & usuario &  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)
	
	If perfil = "V-ESPECIAL" Then 'Or perfil = "V-SUPER"
		Printer1.WriteString("-----------PREVENTA-----------" &  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=skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_PRECIO2 as PE_COSTOU, length(PE_PRECIO2) as L_COSTOU,PE_CANT * PE_PRECIO2 AS  PE_COSTO_TOT, length(PE_CANT * PE_PRECIO2) as L_COSTO_TOT,PE_PROID, PE_CEDIS  FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)  order by PE_PROID ", Array As String("PREVENTA"))
		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)
					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
					Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") &  CRLF )
					TAMANO = 0
					ESPACIO = 21
					BLANCO = " "
				End If
			Next
		End If
		s.Close
		s=skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL, SUM(PE_PRECIO2 * PE_CANT) AS TOTAL2 FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
		s.Position =0
		If s.GetString("TOTAL") - s.GetString("TOTAL2") <> 0 Then
			Printer1.WriteString("Descuento:     $" & 	 (s.GetString("TOTAL2") -  s.GetString("TOTAL")) &  CRLF)
		End If
		Printer1.WriteString("Total Preventa:   $" & s.GetString("TOTAL") &  CRLF)
		s.Close
	
	Else
		Printer1.WriteString("-----------PREVENTA-----------" &  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=skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU,PE_CANT * PE_COSTOU AS  PE_COSTO_TOT, length(PE_CANT * PE_COSTOU) as L_COSTO_TOT,PE_PROID, PE_CEDIS  FROM PEDIDO WHERE PE_TIPO = ? AND LENGTH(PE_CEDIS) < 4 AND PE_CLIENTE IN (Select CUENTA from cuentaa)  order by  PE_PROID", Array As String("PREVENTA"))
		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)
					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
					Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") &  CRLF )
					TAMANO = 0
					ESPACIO = 21
					BLANCO = " "
				End If
			Next
		End If
		s.Close
		s=skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU,PE_CANT * PE_COSTOU AS  PE_COSTO_TOT, length(PE_CANT * PE_COSTOU) as L_COSTO_TOT,PE_PROID, PE_CEDIS  FROM PEDIDO WHERE PE_TIPO = ? and LENGTH(PE_CEDIS) > 3  AND PE_CLIENTE IN (Select CUENTA from cuentaa)  order by  PE_CEDIS, PE_COSTOU", Array As String("PREVENTA"))
		If S.RowCount>0 Then
			Printer1.WriteString("----PROMOS----" &  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
				
					Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") &  CRLF)
					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
					Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") &  CRLF )
					TAMANO = 0
					ESPACIO = 21
					BLANCO = " "
				End If
			Next
			Printer1.WriteString("--FIN PROMOS----" &  CRLF)
		End If
		s.Close
		
		s=skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL, SUM(PE_PRECIO2 * PE_CANT) AS TOTAL2 FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
		s.Position =0
	'	If s.GetString("TOTAL") - s.GetString("TOTAL2") <> 0 Then
	'		Printer1.WriteString("Descuento:     $" & 	 (s.GetString("TOTAL2") -  s.GetString("TOTAL")))
	'	End If
		Printer1.WriteString("Total Preventa:   $" & s.GetString("TOTAL") &  CRLF)
		s.Close
	
	End If
	Printer1.WriteString(" " &  CRLF)
	Printer1.WriteString("------------------------------" &  CRLF)
	Printer1.WriteString("ENTREGA EN :" &  CRLF)
	Printer1.WriteString(la_Calle.Text &  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)
	
	Sleep(1000)
	Printer1.DisConnect
	
	ProgressDialogHide
'	printer.Flush
	'	printer.Close
	
End Sub


Sub B_IMP2_Click
	c=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=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=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=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
	
	ProgressDialogShow("Imprimiendo, un momento ...")
'	Printer1.DisConnect
	If Not(Printer1.IsConnected) Then
		Log("conectando 1")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada)
'			Log("conectando ...")
			Sleep(1000)
			cont = cont + 1
			If cont = 3 Then Printer1.Connect 'Tratamos de reconectar
			If cont > 15 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	Else
		Log("conectando 2")
		Printer1.Connect
		Private cont As Int = 0
		Do While Not(impresoraConectada) Or Not(Printer1.IsConnected)
'			Log("conectando ...")
			Sleep(1000)
			cont = cont + 1
			If cont = 2 Then Printer1.Connect
			If cont > 4 Then impresoraConectada = True
		Loop
		Sleep(500)
		impresoraConectada = False
	End If
	Log("Iniciamos ...")
	TAMANO = 0
	ESPACIO = 21
	BLANCO = " "
	Dim bmp As Bitmap
	bmp.InitializeResize(File.DirAssets, "durakelo1.png", 376, 129, True) 'ignore
	Dim myimage As AnImage = Printer1.ImageToBWIMage(bmp)
	
	myimage = Printer1.DitherImage2D(myimage, 128)
	
	myimage= Printer1.PackImage(myimage)
	Log("Iniciamos 2 ...")
	Printer1.WriteString(CRLF) ' nudge the printer to show the user something is happening
	Printer1.WriteString(Printer1.REVERSE)
	
	Printer1.PrintImage(myimage)
	Printer1.WriteString(Printer1.UNREVERSE)

'	printer.Initialize(cmp20.OutputStream)
	Printer1.WriteString("DURAKELO S.A. de C.V." &  CRLF)
	Printer1.WriteString("RFC: DUR-011025-T12" &  CRLF)
	Printer1.WriteString(sucursal &  CRLF)
	Printer1.WriteString(sDate &  CRLF)
	Printer1.WriteString(sTime &  CRLF)
	Printer1.WriteString("Vendedor:" & usuario &  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("-----------ENTREGA------------" &  CRLF)
	
	s=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 LENGTH(PE_CEDIS) < 4 AND PE_CLIENTE IN (Select CUENTA from cuentaa)  order by  PE_PRONOMBRE", Array As String("VENTA"))
	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)
				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
				Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") &  CRLF )
				TAMANO = 0
				ESPACIO = 21
				BLANCO = " "
			End If
		Next
	End If
	s.Close
	
	s=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 LENGTH(PE_CEDIS) > 3 AND PE_CLIENTE IN (Select CUENTA from cuentaa)  order by  PE_CEDIS, PE_COSTOU", Array As String("VENTA"))
	If S.RowCount>0 Then
		Printer1.WriteString("----PROMOS----" &  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
				
				Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") &  CRLF)
				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
				Printer1.WriteString(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") &  CRLF )
				TAMANO = 0
				ESPACIO = 21
				BLANCO = " "
			End If

		Next
		Printer1.WriteString("--FIN PROMOS----" &  CRLF)

	End If
	s.Close
	
	Printer1.WriteString(" " &  CRLF)
	s=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("Total entrega:   $" & s.GetString("TOTAL") &  CRLF)
	s.Close
'	Printer1.WriteString("------------VENTA-------------")
'	Printer1.WriteString("TOTAL COMPRA: $:" & total_cliente)
	Printer1.WriteString(" " &  CRLF)
	Printer1.WriteString("------------------------------" &  CRLF)
	Printer1.WriteString("ENTREGA EN :" &  CRLF)
	Printer1.WriteString(la_Calle.Text &  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)
	
	Sleep(1000)
	Printer1.DisConnect
	ProgressDialogHide
	'printer.Flush
'	printer.Close
	
End Sub


Sub B_INV_Click

	c=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 = 21
	BLANCO = " "
'	printer.Initialize(cmp20.OutputStream)
	Printer1.WriteString("DURAKELO S.A. de C.V." &  CRLF)
	Printer1.WriteString("RESUMEN DIA A LA HORA" &  CRLF)
	Printer1.WriteString(sDate & " " &  sTime &  CRLF)
	Printer1.WriteString("Vendedor:" & usuario  & CRLF )
	Printer1.WriteString("-------------VENTA-------------"  & CRLF)
	
	
	E1=skmt.ExecQuery2("Select count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("VENTA"))
	E1.Position = 0
	If E1.GetString("CUANTOS") > 0 Then
		
		c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("VENTA"))
		c.Position = 0
		Printer1.WriteString("VENTA: " &  c.GetString("MONTO_DIA") &  CRLF)
		c.Close
	Else
		Printer1.WriteString("VENTA: " & "0" &  CRLF)
	End If
	E1.Close
		
		
	E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("PREVENTA"))
	E1.Position = 0
	If E1.GetString("CUANTOS") > 0 Then
		
		c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("PREVENTA"))
		c.Position = 0
		Printer1.WriteString("PREVENTA: " & c.GetString("MONTO_DIA") &  CRLF)
		c.Close
	Else
		Printer1.WriteString("PREVENTA: " & "0" &  CRLF)
	End If
	E1.Close
		
		
	E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("ABORDO"))
	E1.Position = 0
	If E1.GetString("CUANTOS") > 0 Then
		
		c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("ABORDO"))
		c.Position = 0
		Printer1.WriteString("ABORDO: " & c.GetString("MONTO_DIA") &  CRLF)
		c.Close
	Else
		Printer1.WriteString("ABORDO: " & "0" &  CRLF)
	End If
	E1.Close

		
	
	
	Printer1.WriteString("-----------INVENTARIO-----------"  & 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=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
	
			Printer1.WriteString(s.GetString("CAT_GP_NOMBRE") &  CRLF)
			
			Printer1.WriteString("CANTIDAD: " &  s.GetString("CAT_GP_ALMACEN")  & 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
	's=skmt.ExecQuery("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO")
	's.Position =0
	'If s.GetString("TOTAL") - s.GetString("TOTAL2") <> 0 Then
'		Printer1.WriteString("Descuento:     $" & 	 (s.GetString("TOTAL2") -  s.GetString("TOTAL")))
'	End If
'	Printer1.WriteString("Total Preventa:   $" & s.GetString("TOTAL"))
'	s.Close
	
	 
	
	

	Printer1.WriteString(" " &  CRLF)
	Printer1.WriteString("-----------RMI----------------"  &  CRLF)
	Printer1.WriteString(" " &  CRLF)
	'c=skmt.ExecQuery2("select  count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO"))
	'c.Position =0
	'Cuantos = c.GETSTRING("CUANTOS")
	'c.Close
	'If Cuantos >0 Then
	c=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"))
	
	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
	'End If
	
	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)
	Printer1.WriteString("------------------------------" &  CRLF)
	Printer1.WriteString(" " &  CRLF)
	
'	printer.Flush
		
	
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
'			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")
'	'	printer.Close
'		cmp20.Disconnect
'	End Try
'
'	If PairedDevices.Size = 0 Then
'		Msgbox("Error Connecting to Printer - Printer Not Found","")
'		Return
'	End If
'
'	If PairedDevices.Size = 1 Then
'		Try
'		'FLEOS	
'		'cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
'			cmp20.Connect(PairedDevices.Get(PairedDevices.GetKeyAt(0)))
'			
'		Catch
'			Msgbox("Connecting","Printer Error")
'			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)
'
'		If resimp <> DialogResponse.CANCEL Then
'			cmp20.Connect(PairedDevices.Get(L.Get(resimp)))
'			
'		End If
'	End If
'End Sub


Sub B_VENTA_Click
	Main.tipov = "VENTA"
	'StartActivity(colonia2)
	cuestionario
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 CH_TA.Checked = True Then
		TIPOEX = CH_TA.Text
	ELSE If CH_TB.Checked = True Then
		TIPOEX = CH_TB.Text
	ELSE If CH_TC.Checked = True Then
		TIPOEX = CH_TC.Text
	ELSE If CH_TD.Checked = True Then
		TIPOEX = CH_TD.Text
	End If
	
	Panel1.Visible = False
	B_EXIBI.Visible = True
	b_factura.Visible = True
	HIST.Visible = True
	Tar.VISIBLE = True
	B_IMP.Visible = True
	Tels.Visible = True
	B_VENTA.Visible = True
	B_IMP2.Visible = True
	gest.Visible = True
	Guardar.Visible = True
	B_INV.Visible = True
	
	c=skmt.ExecQuery("select CUENTA from cuentaa")
	c.Position = 0
	cuenta = c.GetString("CUENTA")
	
	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
	
	s=skmt.ExecQuery("select CAT_EX_ID, CAT_EX_TIPO, CAT_EX_VALOR FROM CAT_EXHIBIDORES")
	
	If s.RowCount>0 Then
		For i=0 To s.RowCount -1
			s.Position=i
			If s.GetString("CAT_EX_ID") = "1" Then
				CH_TA.Text = s.GetString("CAT_EX_VALOR")
			End If
			If s.GetString("CAT_EX_ID") = "2" Then
				CH_TB.Text = s.GetString("CAT_EX_VALOR")
			End If
			If s.GetString("CAT_EX_ID") = "3" Then
				CH_TC.Text = s.GetString("CAT_EX_VALOR")
			End If
			If s.GetString("CAT_EX_ID") = "4" Then
				CH_TD.Text = s.GetString("CAT_EX_VALOR")
			End If
		
		Next
	End If

	E_CUANTOS_E.Text = ""
	CH_TA.Checked = False
	CH_TB.Checked = False
	CH_TC.Checked = False
	CH_TD.Checked = False
	Panel1.Visible = True
	B_EXIBI.Visible = False
	b_factura.Visible = False
	HIST.Visible = False
	Tar.VISIBLE = False
	B_IMP.Visible = False
	Tels.Visible = False
	B_VENTA.Visible = False
	B_IMP2.Visible = False
	gest.Visible = False
	Guardar.Visible = False
	B_INV.Visible = False
	
End Sub


Sub Printer1_Connected (Success As Boolean)
	Log("Impresora conectada.")
	If Success Then
		ToastMessageShow("Connected successfully", False)
		skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("MACIMP"))
		skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MACIMP",Main.mac_impresora))
		B_IMP.Enabled = True
		impresoraConectada = True
	Else
'		Msgbox(Printer1.ConnectedErrorMsg, "Error connecting.")
'		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 cuestionario
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	
	If TOMAR_FOTO = 0 Then
		s=skmt.ExecQuery("select COUNT(*) AS CUANTOS from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
		s.Position= 0
		CUANTOS = s.GetString("CUANTOS")
	Else
		CUANTOS = 0
	End If
	If CUANTOS = 0 Then
		c=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
				'		Msgbox("paso1","a")
				If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 5 Then
					id_encuesta = c.GetString("CAT_EP_ID")
					TOMAR_FOTO = 1
					CURSOR_FOTO = i
					StartActivity(foto)
					'		Msgbox("paso2","a")
					Exit
				ELSE IF c.GetString("CAT_EP_IDTIPOPREGUNTA") = 3 Then
					res =  Msgbox2(c.GetString("CAT_EP_PREGUNTA"),c.GetString("CAT_CE_DESCRIPCION"), "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
					If res = DialogResponse.POSITIVE Then
						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
						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")))
					Else IF res = DialogResponse.CANCEL Then
						i = i -1
					End If
				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"))
					If res = DialogResponse.POSITIVE Then
						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")))
						'i = c.GetString("CAT_EP_RES1_PRED") -1
					Else IF res = DialogResponse.NEGATIVE Then
						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
					res =  Msgbox2(c.GetString("CAT_EP_PREGUNTA"),c.GetString("CAT_CE_DESCRIPCION"), c.GetString("CAT_EP_RES1_PRED"), c.GetString("CAT_EP_RES2_PRED"),c.GetString("CAT_EP_RES3_PRED"),LoadBitmap(File.DirAssets,"alert2.png"))
					If res = DialogResponse.POSITIVE Then
						skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, c.GetString("CAT_EP_RES1_PRED"),sDate & sTime,c.GetString("CAT_EP_ID")))
					Else IF res = DialogResponse.NEGATIVE Then
						skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, c.GetString("CAT_EP_RES3_PRED"),sDate & sTime,c.GetString("CAT_EP_ID")))
					Else IF res = DialogResponse.CANCEL Then
						skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, c.GetString("CAT_EP_RES2_PRED"),sDate & sTime,c.GetString("CAT_EP_ID")))
					End If
					'		Msgbox("paso4","a")
				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")
					TOMAR_FOTO = 1
					CURSOR_FOTO = i
					'			Msgbox("paso5","a")
					Exit
				ELSE If c.GetString("CAT_EP_IDTIPOPREGUNTA") = 1 Then
					Panel9.Visible = True
					t_tenc.Text = c.GetString("CAT_EP_PREGUNTA")
					Label26.Text = c.GetString("CAT_CE_DESCRIPCION")
					E_RES_E.Text = ""
					TOMAR_FOTO = 1
					CURSOR_FOTO = i
					Exit
				Else
				'	Main.tipov = "VENTA"
					StartActivity(colonia2)
				End If
			Next
		Else
		'	Main.tipov = "VENTA"
			StartActivity(colonia2)
		End If
	Else
	'	Main.tipov = "VENTA"
		StartActivity(colonia2)
	End If
End Sub


Sub B_E_NEXT_Click
	Panel9.Visible = False
	
	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")))
	Main.tipov = "VENTA"
	'TOMAR_FOTO = 1
	cuestionario
	'StartActivity(colonia2)

End Sub


Sub b_chk_e_Click
	Panel10.Visible = False
	
	If Chk_1.Checked = True Then
		skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, chk_1_valor,sDate & sTime,c.GetString("CAT_EP_ID")))
	else if chk_2.Checked = True Then
		skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, chk_2_valor,sDate & sTime,c.GetString("CAT_EP_ID")))
	else if chk_3.Checked = True Then
		skmt.ExecNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, chk_3_valor,sDate & sTime,c.GetString("CAT_EP_ID")))
	End If
	Main.tipov = "VENTA"
	'TOMAR_FOTO = 1
	cuestionario
	
End Sub