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
	'//Process Globals
	Dim g As GPS
	Dim ruta As String
	Dim c As Cursor
	Dim C2 As Cursor
	'//Globals
	Dim CANCELA As Button
	Dim GUARDA As Button
	Dim cuenta As String
	Dim usuario As String
	Dim sDate,sTime As String
	Dim lat_gps, lon_gps As String
	Dim no_cliente As String
	Dim no_ruta As String
	Dim r_4 As RadioButton
	Dim E_NOMBRE As EditText
	Dim ALMACEN As String
	Dim DIA_VISITA As String
End Sub

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

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
	Root = Root1
	'load the layout to Root
	Root.LoadLayout("nuevocliente")
	ruta = File.DirInternal
End Sub

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

Sub B4XPage_Appear
	E_NOMBRE.Text =  ""
End Sub

Sub GPS_LocationChanged (Location1 As Location)
'	lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
'	lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
End Sub

Sub CANCELA_Click
	B4XPages.ShowPage("Principal")
End Sub

Sub GUARDA_Click
	If E_NOMBRE.Text =  "" Then
		ToastMessageShow("Se tiene que nombrar la tienda para continuar" , True)
	Else
		DateTime.DateFormat = "MM/dd/yyyy"
		DateTime.Timeformat = "HHmmss"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
		c=Starter.skmt.ExecQuery("select CAT_CL_RUTA ,CAT_CL_DIAS_VISITA FROM kmt_info ") ' WHERE  CAT_CL_DIAS_VISITA = (SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = 'DIA_VISITA')")
		c.Position=0
		no_ruta= c.GetString("CAT_CL_RUTA")
		DIA_VISITA=c.GetString("CAT_CL_DIAS_VISITA")
		
		'Aqui creamos manualmete la hora con el separador de los 2 puntos porque en algunas versiones de android no respeta el formato "Timeformat = 'HH:mm:ss'"
		Private hora As String = sTime.SubString2(0,2)
		Private mins As String = sTime.SubString2(2,4)
		Private segs As String = sTime.SubString(4)
		Private sTime2 As String = hora&":"&mins&":"&segs
		Log("////////////// sTime: "&sTime&" ////////////////")
		If Starter.lat_gps = 0 Or Starter.lat_gps = Null Then 'Si latitud es CERO o NULL traemos las ultimas coordenadas de la base de datos.
			Private coords As List = Subs.traeCoordsDeBD
			Starter.lat_gps = coords.Get(0)
			Starter.lon_gps = coords.Get(1)
		End If
		no_cliente= "N" & sTime2 & no_ruta
		c.Close
		C2=Starter.skmt.ExecQuery("SELECT ID_ALMACEN FROM CAT_ALMACEN")
		C2.Position=0
		ALMACEN= C2.GetString("ID_ALMACEN")
		C2.Close
		'Msgbox("coordenadas "&Starter.lon_gps & Starter.lat_gps,"aviso")
		Starter.skmt.ExecNonQuery2("INSERT INTO kmt_info(CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_DIAS_VISITA,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO,CAT_CL_BCREDITO, gestion,CAT_CL_BFACTURA,IMPRESION) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,0,0,1000000,0) ",Array As Object (no_cliente,no_ruta, E_NOMBRE.Text,DIA_VISITA,"new","null","null","null","null","null","null","null","null","NULL","NULL","null","0",Starter.lon_gps,Starter.lat_gps))
		Starter.skmt.ExecNonQuery("delete from CUENTAA")
		Starter.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(no_cliente))
		Subs.iniciaActividad("Cliente")
	End If
End Sub
