Files
Kelloggs_v4/B4A/C_Subs.bas
Jose Alberto Guerra Ugalde ea1bb8d292 9/11/23 - Código para Respaldo Diario en Android 10.
- En Android 10, el código para ManageExternalStorage no funciona, asi que si se detecta que el directorio (skmt) no se creo, se manda la BD al directorio seguro en la sdcard (sdcard/Android/data/kelloggs ...)
2023-11-09 20:56:55 -06:00

580 lines
22 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=12.2
@EndOfDesignText@
Sub Class_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
' Public GZip As GZipStrings 'Usa la libreria CompressStrings
' Private su As StringUtils 'Usa la libreria StringUtils
Private EventName As String 'ignore
Private CallBack As Object 'ignore
Dim phn As Phone
Dim devModel As String
Dim db, kmt, errorLog As SQL 'Requiere la libreria "SQL" 'ignore
' Dim wifi As MLwifi
Dim ssid As String 'ignore
Private subsLogs As Boolean = False
End Sub
'You can add more parameters here.
Public Sub Initialize (vCallback As Object, vEventName As String) As Object
EventName = vEventName
CallBack = vCallback
Return Me
End Sub
'Inicializa la BD con "kmt.db" en File.DirInternal, si el archivo no existe, lo copia desde File.DirAssets.
'Dispara el evento "dbOk" cuando termina.
Sub dbInit As SQL
If File.Exists(File.DirInternal, "kmt.db") = False Then File.Copy(File.DirAssets, "kmt.db", File.DirInternal, "kmt.db")
db.Initialize(File.DirInternal,"kmt.db", True)
dbOk(True)
Return db
End Sub
Sub dbOk(Success As Boolean)
If SubExists(CallBack, EventName & "_dbOk") Then
CallSub2(CallBack, EventName & "_dbOk", Success)
End If
End Sub
'Pone el valor de phn.Model en la variable global "devModel"
Sub getPhnId As String 'ignore
'Requiere la libreria "Phone"
devModel = phn.Model
If devModel.Length <= 3 Then 'Si phn.Model esta en blanco ...
Dim t As String = phn.GetSettings("android_id") 'Intentamos con "android_id"
devModel = t
End If
If devModel.Length >= 3 Then 'Si tenemos valor para phn.Model
File.WriteString(File.DirInternal, "phnId.txt", devModel) 'Sobreescribimos archivo phnId.txt with deviceId
' Log("Tenemos phnId: "&devModel&" "&File.DirInternal&"/phn.txt sobreescrito")
Else If devModel.Length < 3 Then ' Si no tenemos valor, lo leemos de phnId.txt
Dim s As String = File.ReadString(File.DirInternal, "phnId.txt")
devModel = s
' Log("Leemos id de "&File.DirInternal&"/phnId.txt")
' Log(devModel)
End If
Return devModel
End Sub
'Convierte una fecha al formato yyMMddHHmmss
Sub fechaKMT(fecha As String) As String 'ignore
' Log(fecha)
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
DateTime.DateFormat = "yyMMddHHmmss"
Dim nuevaFecha As String=DateTime.Date(fecha)
DateTime.DateFormat = OrigFormat 'return to orig date format
' Log(nuevaFecha)
Return nuevaFecha
End Sub
'Escribimos las coordenadas y fecha a un archivo de texto
Sub guardaInfoEnArchivo(coords As String) 'ignore
' Cambiamos el formato de la hora
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
DateTime.DateFormat="MMM-dd HH:mm:ss"
Dim lastUpdate As String=DateTime.Date(DateTime.Now)
DateTime.DateFormat = OrigFormat 'return to orig date format
Dim ubic As String = coords&","&lastUpdate
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "gps.txt", True)
Dim s As String = ubic & CRLF
Dim t() As Byte = s.GetBytes("UTF-8")
out.WriteBytes(t, 0, t.Length)
out.Close
End Sub
'Escribimos las coordenadas (latitud, longitud, fecha) y fecha a una BD
Sub guardaInfoEnBD(coords As String) 'ignore
Log("Guardamos ubicacion en BD - "&coords)
Try
Dim latlon() As String = Regex.Split("\|", coords)
If latlon.Length < 2 Then latlon = Regex.Split(",", coords) 'Si son menos de 2, entonces estan separadas por comas y no por "|"
If subsLogs Then Log("LatLon="&latlon)
kmt.ExecNonQuery2("INSERT INTO RUTA_GPS(FECHA, LAT, LON) VALUES (?,?,?)", Array As Object (latlon(2),latlon(0),latlon(1)))
Catch
LogColor(LastException, Colors.red)
End Try
End Sub
'Limpiamos la tabla RUTA_GPS de la BD
Sub deleteGPS_DB 'ignore
kmt.ExecNonQuery("delete from RUTA_GPS")
kmt.ExecNonQuery("vacuum;")
ToastMessageShow("Borramos BD Coords GPS", False)
End Sub
'Limpiamos la tabla errorLog de la BD
Sub deleteErrorLog_DB 'ignore
errorLog.ExecNonQuery("delete from errores")
errorLog.ExecNonQuery("vacuum;")
ToastMessageShow("BD Errores Borrada", False)
End Sub
'Mandamos "coords" en un mensaje a "Sprvsr"
'Sub mandamosLoc(coords As String) 'ignore
'' Log("Iniciamos mandamosLoc "&coords)
'' Log("locRequest="&Tracker.locRequest)
' guardaInfoEnBD(coords)'Escribimos coordenadas y fecha a una bd
' Dim t As String
' If Tracker.locRequest="Activa" Then
' If PushService.au = 1 Then
' t = "au" ' es una actualizacion
' Else
' t = "u" ' es una peticion
' End If
' Dim params As Map = CreateMap("topic":"Sprvsr", "coords":coords, "t":t, "b":PushService.battery, "mt":Main.montoActual)
' CallSub2(PushService, "mandaMensaje",params)
' Tracker.locRequest="Enviada"
' CallSubDelayed(Tracker,"CreateLocationRequest")
' End If
'End Sub
'Regresa la fecha y hora de hoy a las 00:00 en el formato "yyMMddHHMMSS"
Sub fechaInicioHoy As String 'ignore
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
DateTime.DateFormat = "yyMMdd"
Private h As String = DateTime.Date(DateTime.Now)&"000000"
DateTime.DateFormat = OrigFormat 'return to orig date format
Log("Hoy="&h)
Return h
End Sub
'Guardamos "texto" a la bitacora
Sub log2DB(texto As String) 'ignore
LogColor(fechaKMT(DateTime.Now)&" - log2BD: '"&texto&"'", Colors.LightGray)
kmt.ExecNonQuery2("INSERT INTO bitacora(fecha, texto) VALUES (?,?)", Array As Object (fechaKMT(DateTime.now), texto))
End Sub
'Regresa verdadero si ya pasaron XX minutos de la fecha dada
Sub masDeXXMins(hora As Int, mins As Int) As Boolean 'ignore
If (hora + mins * DateTime.TicksPerMinute) < DateTime.Now Then
Return True
Else
Return False
End If
End Sub
'Regresa verdadero si ya pasaron XX minutos de la fechaKMT dada
Sub masDeXXMinsKMT(hora As String, mins As Int) As Boolean 'ignore
Try
' LogColor($"Hora=${fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute)}, Mins=${mins}, Actual=${fechaKMT(DateTime.Now)}"$,Colors.red)
If fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute < DateTime.Now Then
' Log("+++ +++ "&fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute) & " < " & fechaKMT(DateTime.Now))
Return True
Else
' Log("+++ +++ "&fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute) & " > " & fechaKMT(DateTime.Now))
Return False
End If
Catch
Log(LastException)
End Try
End Sub
'Limpiamos la tabla "bitacora" de la BD
Sub borraLogDB 'ignore
LogColor("Borramos BD de log", Colors.Magenta)
kmt.ExecNonQuery("delete from bitacora")
kmt.ExecNonQuery("vacuum;")
End Sub
'Monitoreamos los servicios para ver si estan activos (No pausados), y si no, los reniciamos
'Sub Monitor 'ignore
' Private monitorStatus As Boolean = True
' LogColor("Corriendo Subs.Monitor", Colors.RGB(161,150,0))
' If IsPaused(Tracker) Then
' log2DB("Reiniciando 'Tracker Pausado' desde Subs.Monitor")
' StartService(Tracker)
' monitorStatus = False
' Else
' CallSubDelayed(Tracker, "revisaFLP")
' End If
' If IsPaused(PushService) Then
' log2DB("Reiniciando 'PushService Pausado' desde Subs.Monitor")
' StartService(PushService)
' monitorStatus = False
' Else
' revisaPushService
' End If
' If monitorStatus Then LogColor(" +++ +++ Servicios Activos", Colors.Green)
'End Sub
'Convierte una fecha en formato YYMMDDHHMMSS a Ticks
Sub fechaKMT2Ticks(fKMT As String) As Long 'ignore
Try
If fKMT.Length = 12 Then
Private parteFecha As String = fKMT.SubString2(0,6)
Private parteHora As String = fKMT.SubString(6)
Private OrigFormat As String = DateTime.DateFormat 'save original date format
DateTime.DateFormat = "yymmdd"
DateTime.TimeFormat = "HHmmss"
Private ticks As Long = DateTime.DateTimeParse(parteFecha,parteHora)
DateTime.DateFormat = OrigFormat 'return to original date format
Return ticks
Else
Log("Formato de fecha incorrecto, debe de ser 'YYMMDDHHMMSS', no '"&fKMT&"' largo="&fKMT.Length)
Return 0
End If
Catch
Log(LastException)
LogColor($"Fecha dada: ${fKMT}, Parte Fecha: ${parteFecha}, Parte Hora: ${parteHora}"$, Colors.Red)
Return 0
End Try
End Sub
Sub InstallAPK(dir As String, apk As String) 'ignore
If File.Exists(dir, apk) Then
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(dir, apk))
i.SetType("application/vnd.android.package-archive")
StartActivity(i)
End If
End Sub
'Copia la base de datos del almacenamiento interno al externo en el directorio kmts.
Sub copiaDB(result As Boolean) 'ignore
ToastMessageShow("copiaDB", False)
If result Then
Dim p As String
If File.ExternalWritable Then
p = File.DirRootExternal
' Log("Externo")
Else
p = File.DirInternal
' Log("Interno")
End If
Dim theDir As String
Try
File.MakeDir(File.DirRootExternal,"kmts")
theDir = "/kmts"
Catch
theDir = ""
End Try
Try
File.Copy(File.DirInternal,"kmt.db",File.DirRootExternal&theDir,"cedex_kmt.db")
File.Copy(File.DirInternal,"errorLog.db",File.DirRootExternal&theDir,"cedex_errorLog.db")
ToastMessageShow("BD copiada!", False)
Catch
ToastMessageShow("No se pudo hacer la copia: "&LastException, True)
End Try
Log("rootExternal="&p)
Log("File.DirInternal="&File.DirInternal)
Log("File.DirRootExternal="&File.DirRootExternal)
Else
ToastMessageShow("Sin permisos", False)
End If
End Sub
'Hace visible y trae al frente el panel con los parametros "Top" y "Left" dados.
Sub panelVisible(panel As Panel, top As Int, left As Int) 'ignore
panel.BringToFront
panel.Visible = True
panel.Top = top
panel.Left = left
End Sub
'Oculta el panel especificado y lo manda al fondo
Sub panelOculto(panel As Panel) 'ignore
panel.SendToBack
panel.Visible = False
End Sub
'Modifica el ancho y alto de un panel dado con el ancho y alto proporcionados y los pone en top 0 y left 0.
Sub panelAnchoAlto(p As Panel, w As Int, h As Int) 'ignore
' If Starter.logger Then Log($"panel:${p}, alncho=${w}, alto=${h}"$)
p.Top = 0
p.Left = 0
p.Width = w
p.Height = h
End Sub
'Centra una etiqueta dentro de un elemento superior.
Sub centraEtiqueta(elemento As Label, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Centra un panel horizontalmente dentro de un elemento superior.
Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Centra un panel verticalmente dentro de un elemento superior.
Sub centraPanelV(elemento As Panel, altoElementoSuperior As Int) 'ignore
elemento.Top = Round(altoElementoSuperior/2)-(elemento.Height/2)
End Sub
'Centra una barra de progreso dentro de un elemento superior.
Sub centraProgressBar(elemento As ProgressBar, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Centra un editText dentro de un elemento superior.
Sub centraEditText(elemento As EditText, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Regresa el usuario de la tabla USUARIOA si es que existe, si no existe, regresa "SinUsuario".
Sub buscaDBUsuario As String 'ignore
Private c As Cursor
Private usuario As String = "SinUsuario"
c=kmt.ExecQuery("select USUARIO from usuarioa")
c.Position=0
If c.RowCount > 0 Then usuario = c.GetString("USUARIO")
Return usuario
End Sub
'Regresa la fecha en el formato "MM/dd/yyyy"
Sub traeFecha As String 'ignore
DateTime.DateFormat = "MM/dd/yyyy"
Private sDate As String = DateTime.Date(DateTime.Now)
Private sTime As String = DateTime.Time(DateTime.Now)
Return sDate & sTime
End Sub
'Guarda el nombre y version de la app en CAT_VARIABLES.
Sub guardaAppInfo(skmt As SQL) 'ignore
skmt.ExecNonQuery("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'EMPRESA' or CAT_VA_DESCRIPCION = 'APP_NAME' or CAT_VA_DESCRIPCION = 'APP_VERSION'")
skmt.ExecNonQuery($"insert into CAT_VARIABLES (CAT_VA_DESCRIPCION, CAT_VA_VALOR) values ('APP_NAME', '${Application.LabelName}')"$)
skmt.ExecNonQuery($"insert into CAT_VARIABLES (CAT_VA_DESCRIPCION, CAT_VA_VALOR) values ('APP_VERSION', '${Application.VersionName}')"$)
End Sub
'Muestra en el Log los campos y valores que regresan en el JobDone.
Sub logJobDoneResultados(resultado As DBResult) 'ignore
For Each records() As Object In resultado.Rows
LogColor($"====== ${resultado.Tag} - REGISTROS = ${resultado.Rows.Size}"$, Colors.RGB(215,37,0))
For Each k As String In resultado.Columns.Keys
LogColor(k & " = " & records(resultado.Columns.Get(k)), Colors.RGB(215,37,0))
Next
Next
End Sub
'Regresa la base de datos especificada ya inicializada.
Sub inicializaBD(ruta As String, BDName As String) As SQL 'ignore
Dim skmt As SQL
If File.Exists(ruta, BDName) = False Then
File.Copy(File.DirAssets, BDName, ruta, BDName)
LogColor($"Copiamos ${BDName} de ${File.DirAssets} a ${ruta}"$,Colors.Green)
End If
skmt.Initialize(ruta, BDName, True)
Return skmt
End Sub
'Agrega una columna a la tabla especificada.
'Hay que indicar el "tipo" de la columna (TEXT, INTEGER, ETC)
'Ej. agregaColumna("TABLA", "COLUMNA", "TIPO")
Sub agregaColumna(tabla As String, columna As String, tipo As String) 'ignore
Try 'Intentamos usar "pragma_table_info" para revisar si existe la columna en la tabla
Private c As Cursor = Starter.skmt.ExecQuery($"SELECT COUNT(*) AS fCol FROM pragma_table_info('${tabla}') WHERE name='${columna}'"$)
c.Position = 0
If c.GetString("fCol") = 0 Then 'Si no esta la columna la agregamos
Starter.skmt.ExecNonQuery($"ALTER TABLE ${tabla} ADD COLUMN ${columna} ${tipo}"$)
Log($"Columna "${columna} ${tipo}", agregada a "${tabla}"."$)
End If
Catch 'Si no funciona "pragma_table_info" lo hacemos con try/catch
Try
Starter.skmt.ExecNonQuery($"ALTER TABLE ${tabla} ADD COLUMN ${columna} ${tipo}"$)
Log($"Columna "${columna} ${tipo}", agregada a "${tabla}".."$)
Catch
Log(LastException)
End Try
End Try
End Sub
'Regresa el DBReqServer desde CAT_VARIABLES o "N/A" si no existe.
Sub traeDBReqServerDeBD As String 'ignore
Dim srvr As String = "N/A"
Dim rs As ResultSet = Starter.skmt.ExecQuery("select valor from cat_variables where nombre = 'servidor'")
If rs.RowCount > 0 Then
rs.NextRow
srvr = rs.GetString("valor")
End If
Return srvr
End Sub
'Regresa el valor de intervalo desde CAT_VARIABLES o "30" si no existe.
Sub traeIntervaloDeBD As String 'ignore
Dim intrvl As String = "30"
Dim rs As ResultSet = Starter.skmt.ExecQuery("select valor from cat_variables where nombre = 'intervalo'")
If rs.RowCount > 0 Then
rs.NextRow
intrvl = rs.GetString("valor")
End If
Return intrvl
End Sub
'Regresa el valor timeout desde CAT_VARIABLES o "9000" si no existe.
Sub traeTimeoutDeBD As String 'ignore
Dim tmout As String = "9000"
Dim rs As ResultSet = Starter.skmt.ExecQuery("select valor from cat_variables where nombre = 'timeout'")
If rs.RowCount > 0 Then
rs.NextRow
tmout = rs.GetString("valor")
End If
Return tmout
End Sub
'Crea una notificación con el "body" dado y regresa el objeto.
Sub CreateNotification (Body As String) As Notification 'ignore
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.SetInfo("Tester", Body, Main)
Return notification
End Sub
'Genera una notificacion con importancia alta
Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
activity = Main
Private notif As Notification
notif.Initialize2(notif.IMPORTANCE_HIGH)
notif.Icon = "icon"
notif.Vibrate = False
notif.Sound = False
notif.AutoCancel = True
' If logger Then Log("notiHigh: "&title)
notif.SetInfo(title, body, activity)
' Log("notiHigh SetInfo")
notif.Notify(id)
End Sub
'Regresa el objeto de una notificacion con importancia baja
Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'ignore
Private notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
' Log("notiLowReturn: "&title)
notification.Icon = "icon"
notification.Sound = False
notification.Vibrate = False
notification.SetInfo(title, Body, Main)
notification.Notify(id)
' Log("notiLowReturn SetInfo")
Return notification
End Sub
'Guarda el nombre de la pagina en base de datos la muestra.
Sub iniciaActividad(ia As String) 'ignore
If ia <> "" And ia <> Null Then
' If Starter.logger Then LogColor($"Guardamos en BD '${ia}'"$, Colors.Yellow)
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("ULTIMOMODULO"))
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("ULTIMOMODULO", ia))
B4XPages.ShowPage(ia)
' If Starter.logger Then LogColor("Iniciamos --> " & ia, Colors.Blue)
End If
End Sub
'Guarda el nombre de la actividad en base de datos e inicia la actividad.
Sub iniciaActividad2(ia As String) 'ignore
' if starter.logger then LogColor($"Guardamos en BD '${ia}'"$, Colors.Yellow)
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("ULTIMOMODULO"))
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("ULTIMOMODULO", ia))
StartActivity(ia)
' B4XPages.ShowPage(ia)
' if starter.logger then LogColor("Iniciamos --> " & ia, Colors.Blue)
End Sub
'Cierra todas las actividades y sale de la aplicacion (Android 4.1+ - API 16+)
Sub cierraActividades 'ignore
If Starter.logger Then Log("closing activities")
Dim jo As JavaObject
jo.InitializeContext
jo.RunMethod("finishAffinity", Null)
End Sub
'Revisa que exista la BD y si es necesario crea algunas tablas dentro de ella
Sub revisaBD 'ignore
' if starter.logger then Log("subs.revisaBD")
Starter.ruta = File.DirInternal
If Not(File.Exists(Starter.ruta, "kmt.db")) Then File.Copy(File.DirAssets, "kmt.db", Starter.ruta, "kmt.db")
If Not(Starter.skmt.IsInitialized) Then Starter.skmt.Initialize(Starter.ruta, "kmt.db", True)
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(fecha INTEGER, lat TEXT, lon TEXT)")
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS HIST_ENCUESTA2(HE_CLIENTE TEXT)")
' Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS UUC(fecha INTEGER, lat TEXT, lon TEXT)") 'LastKnownLocation
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS bitacora(fecha INTEGER, texto TEXT)") 'Bitacora
Try 'Si no existe la columna CAT_CL_CATEGORIA la agregamos.
Starter.skmt.ExecQuery("select count(CAT_CL_CATEGORIA) from kmt_info")
Catch
Try
Starter.skmt.ExecNonQuery("ALTER TABLE kmt_info ADD COLUMN CAT_CL_CATEGORIA TEXT")
Catch
If Starter.logger Then LogColor("No pudimos agregar la columna CAT_CL_CATEGORIA.", Colors.Red)
If Starter.logger Then LogColor(LastException, Colors.Red)
End Try
End Try
Try 'Si no existe la columna CAT_CL_SEGMENTO la agregamos.
Starter.skmt.ExecQuery("select count(CAT_CL_SEGMENTO) from kmt_info")
Catch
Try
Starter.skmt.ExecNonQuery("ALTER TABLE kmt_info ADD COLUMN CAT_CL_SEGMENTO TEXT")
Catch
If Starter.logger Then LogColor("No pudimos agregar la columna CAT_CL_SEGMENTO.", Colors.Red)
If Starter.logger Then LogColor(LastException, Colors.Red)
End Try
End Try
'Tabla para la bitacora de errores
If Not(Starter.errorLog.IsInitialized) Then Starter.errorLog.Initialize(File.DirInternal, "errorLog.db", True)
Starter.errorLog.ExecNonQuery("CREATE TABLE IF NOT EXISTS errores(fecha TEXT, error TEXT)")
End Sub
'Regresa el dia de HOY como string, en español y mayusculas.
Sub dameDiaSemana As String 'ignore
Private ds As String = DateTime.GetDayOfWeek(DateTime.Now)
If ds = "1" Then
ds = "DOMINGO"
else if ds = "2" Then
ds = "LUNES"
else if ds = "3" Then
ds = "MARTES"
else if ds = "4" Then
ds = "MIERCOLES"
else if ds = "5" Then
ds = "JUEVES"
else if ds = "6" Then
ds = "VIERNES"
Else
ds = "SABADO"
End If
Return ds
End Sub
'Regresa cuentos clientes fuera de frecuencia hay con venta.
Sub dameClientesFueraDeFrecuencia As String 'ignore
Private dia_visita As String = dameDiaSemana
Private f As Cursor = Starter.skmt.ExecQuery("SELECT CAT_VA_VALOR as dia_visita FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = 'DIA_VISITA'")
If f.RowCount > 0 Then
f.Position=0
dia_visita = f.GetString("dia_visita")
End If
' Log("-> "&dia_visita)
f = Starter.skmt.ExecQuery("Select count(distinct PE_CLIENTE) as cff FROM kmt_info INNER JOIN PEDIDO ON kmt_info.CAT_CL_CODIGO = PEDIDO.PE_CLIENTE WHERE kmt_info.CAT_CL_DIAS_VISITA <> '"&dia_visita&"'")
f.Position=0
' Log(f.GetString("cff"))
Private cff As String = f.GetString("cff")
f.Close
Return cff
End Sub
'Regresa la ultima actividad guardada en base de datos.
Sub traeUltimaActividadBD As String 'ignore
' If Starter.logger Then LogColor("Buscamos ultima actividad en BD", Colors.Magenta)
Private c As Cursor
Private x As String
c = Starter.skmt.ExecQuery("select CAT_VA_VALOR from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'ULTIMOMODULO'")
If c.RowCount > 0 Then
c.Position = 0
x = c.GetString("CAT_VA_VALOR")
' If Starter.logger Then Log("Encontramos: " & x)
End If
c.Close
Return x
End Sub
'En geocerca si mete la contraseña poner 0 en precision gps y si esta dentro de los 50 mts poner 1 y 2 para eventos que no lo ocupen
'Mandar fecha de sync(sysdate)
Sub bitacora(fechab As String, usuariob As String, almacenb As String, rutab As String, eventob As String, clienteb As String, iniciob As String, finb As String, latitudb As String, longitudb As String, precision As String, motivonoventa As String, motivonovisita As String) 'ignore
Log("bitacora")
Starter.skmt.ExecNonQuery($"INSERT INTO BITACORAGPS (fechab, usuariob , almacenb , rutab , eventob , clienteb , iniciob , finb , latitudb , longitudb , precision , motivonoventa , motivonovisita) VALUES ('${fechab}' ,'${usuariob}' , '${almacenb}' , '${rutab}' , '${eventob}' , '${clienteb}' , '${iniciob}' , '${finb}' , '${latitudb}' , '${longitudb}' , '${precision}' , '${motivonoventa}' , '${motivonovisita}')"$)
End Sub