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 c As Cursor
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 CANCELA As Button
	Dim GUARDA As Button
	Dim r_1 As RadioButton
	Dim r_2 As RadioButton
	Dim r_3 As RadioButton
	Dim e_comm As EditText
	Dim motivo As String
	Dim cuenta As String
	Dim usuario As String
    Dim sDate,sTime As String
	Dim lat_gps, lon_gps As String
	Dim tgl As Toggle
	Dim r_4 As RadioButton
	
	Private stay_hh As String
	Private stay_mi As String
	Private stay_ss As String
	
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	If(FirstTime) Then
	 g.Initialize("GPS")
	End If
    
	Activity.LoadLayout("nopago")
    
	' valido donde escribo el archivo de la base de datos de kmt
'	If File.ExternalWritable Then
'	   ruta = File.DirDefaultExternal
'	Else
'	   ruta = File.DirInternal
'	   
'	End If
'    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)
	
End Sub

Sub Activity_Resume
	e_comm.Text=""
	tgl.Initialize

'	tgl.TurnGPSOn
'    If g.GPSEnabled=False Then
'	  ToastMessageShow("Habilitar el GPS", True)
'	  StartActivity(g.LocationSettingsIntent)
'	 Else
	  g.Start(0,0)
'	 End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)
	g.Start(0,0)

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
	StartActivity(fila)
End Sub
Sub GUARDA_Click
If r_1.Checked Then
motivo = "CERRADO"
Else If r_2.Checked Then
motivo = "NO COMPRA"
Else If r_3.Checked Then
motivo = "CON PRODUCTO"
Else
motivo = "NO ESTA EL ENCARGADO"
End If
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
        c=starter.skmt.execQuery("select CUENTA from cuentaa")
        c.Position = 0
	    cuenta = c.GetString("CUENTA")
	    c=Starter.skmt.execQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
		c=Starter.skmt.execQuery("select PE_PROID,PE_CANT FROM PEDIDO where pe_cliente in (Select CUENTA from cuentaa) ")
	    If c.RowCount>0 Then
	       For i=0 To c.RowCount -1
		      c.Position=i
		      Starter.skmt.execNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_id = ?", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
	       Next
	    End If
	
	
	    Starter.skmt.execNonQuery("delete from pedido_cliente where pc_cliente in (Select CUENTA from cuentaa)")
	    Starter.skmt.execNonQuery("delete from pedido where pe_cliente in (Select CUENTA from cuentaa)")
	
     	Starter.skmt.execNonQuery2("INSERT INTO  NOVENTA (NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON) VALUES(?,?,?,?,?,?,?) ", Array As Object (cuenta,sDate & sTime, usuario, motivo,e_comm.text,lat_gps,lon_gps))
	Starter.skmt.execNonQuery("UPDATE kmt_info set gestion = 3  where CAT_CL_CODIGO In (select cuenta from cuentaa)")
	DateTime.TimeFormat = "HHmmss"
	sTime=DateTime.Time(DateTime.Now)
	starter.skmt.execNonQuery2("UPDATE HIST_STAY_STORE set HSS_OUT = ?  where HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(sTime))
	'  starter.skmt.execNonQuery("UPDATE HIST_STAY_STORE set HSS_TOT = HSS_OUT - HSS_IN where HSS_CODIGO In (select cuenta from cuentaa)")
	

	c=starter.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")
	
	starter.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))
	

	starter.skmt.execNonQuery2("UPDATE HIST_STAY_OUT set HSO_FIN = ?  ", Array As Object(sTime))
	
	DateTime.TimeFormat = "HH:mm:ss"
	
	StartActivity(seleccion)
End Sub