mirror of
https://github.com/KeymonSoft/Mariana.git
synced 2026-04-17 21:06:16 +00:00
- Cambio de 50 segundos a 10 segundos en la revision de la hora para los recordatorios. - Cambio en el envio de la ruta para la contraseña de la geocerca, si no habia cliente seleccionado, no regresaba la ruta correcta.
192 lines
8.5 KiB
QBasic
192 lines
8.5 KiB
QBasic
B4A=true
|
|
Group=Default Group
|
|
ModulesStructureVersion=1
|
|
Type=Service
|
|
Version=9.85
|
|
@EndOfDesignText@
|
|
#Region Service Attributes
|
|
#StartAtBoot: False
|
|
#ExcludeFromLibrary: 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.
|
|
Public gps As GPS
|
|
Dim skmt As SQL
|
|
Dim ph As Phone
|
|
Public rp As RuntimePermissions
|
|
Dim s As C_Subs
|
|
Public FLP As FusedLocationProvider
|
|
' Private flpStarted As Boolean
|
|
Dim reqManager As DBRequestManager
|
|
' Dim DBReqServer As String = "http://11.0.0.253:1782"
|
|
Dim DBReqServer As String = "http://192.99.93.204:1781"
|
|
' Dim DBReqServer As String = "http://10.0.0.205:1782"
|
|
' Dim DBReqServer As String = "http://11.0.0.231:1782"
|
|
Dim Timer1 As Timer
|
|
Dim Interval As Int = 300
|
|
Dim ruta As String = File.DirInternal
|
|
'Para los Logs
|
|
Private logs As StringBuilder
|
|
Private logcat As LogCat
|
|
Dim dia_semana As String = ""
|
|
Dim logger As Boolean = True
|
|
Dim marcaCel As String = ph.manufacturer
|
|
Public rp As RuntimePermissions
|
|
Dim muestraProgreso As String = 0
|
|
Dim timerRecordatorio As Timer
|
|
Dim ultimoRecordatorio As String = ""
|
|
End Sub
|
|
|
|
Sub Service_Create
|
|
'This is the program entry point.
|
|
'This is a good place to load resources that are not specific to a single activity.
|
|
s.Initialize(Me, "Subs") 'Inicializamos la clase Subs
|
|
skmt = s.inicializaBD(File.DirInternal, "kmt.db")
|
|
gps.Initialize("GPS")
|
|
Timer1.Initialize("Timer1", Interval * 1000)
|
|
Timer1.Enabled = True
|
|
' 'Para los Logs
|
|
#if RELEASE
|
|
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
|
|
#end if
|
|
logs.Initialize
|
|
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para Push FirebaseMessaging
|
|
End Sub
|
|
|
|
Sub Service_Start (StartingIntent As Intent)
|
|
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
|
|
Subs.revisaBD
|
|
If s.traeDBReqServerDeBD(skmt) <> "N/A" Then DBReqServer = s.traeDBReqServerDeBD(skmt)
|
|
reqManager.Initialize(Me, DBReqServer)
|
|
' StartService(NotificationService)
|
|
timerRecordatorio.Initialize("timerRecordatorio", 10 * 1000)
|
|
timerRecordatorio.Enabled = True
|
|
End Sub
|
|
|
|
Private Sub Timer1_Tick
|
|
' Log("Next run " & DateTime.Time(DateTime.Now + Interval * 1000))
|
|
ENVIA_ULTIMA_GPS
|
|
End Sub
|
|
|
|
Sub GPS_LocationChanged (Location1 As Location)
|
|
' CallSub2(Main, "GPS_LocationChanged", Location1)
|
|
End Sub
|
|
|
|
Sub Service_TaskRemoved
|
|
'This event will be raised when the user removes the app from the recent apps list.
|
|
End Sub
|
|
|
|
Sub Service_Destroy
|
|
|
|
End Sub
|
|
|
|
Sub ENVIA_ULTIMA_GPS
|
|
If IsConnectedToInternet Or 1 = 1 Then
|
|
Dim logger As Boolean = True
|
|
If logger Then LogColor("Iniciamos ENVIA_ULTIMA_GPS", Colors.Magenta)
|
|
Dim cmd As DBCommand
|
|
' cmd.Initialize
|
|
' cmd.Name = "select_fechat"
|
|
' B4XPages.MainPage.reqManager.ExecuteQuery(cmd , 0, "fechat")
|
|
Dim cmd As DBCommand
|
|
cmd.Initialize
|
|
cmd.Name = "UPDATE_MARDS_ACTUAL2_GPS"
|
|
If B4XPages.MainPage.lat_gps.Length < 15 Then B4XPages.MainPage.lat_gps = B4XPages.MainPage.lat_gps&"0"
|
|
cmd.Parameters = Array As Object(B4XPages.MainPage.montoActual, B4XPages.MainPage.clientestotal, B4XPages.MainPage.clientesventa,B4XPages.MainPage.clientesvisitados,B4XPages.MainPage.lat_gps,B4XPages.MainPage.lon_gps,B4XPages.MainPage.batt,0, 0, 0,B4XPages.MainPage.ALMACEN,B4XPages.MainPage.rutapreventa)
|
|
If logger Then Log($"montoActual: ${B4XPages.MainPage.montoActual}, cTotal: ${B4XPages.MainPage.clientestotal}, cVenta: ${B4XPages.MainPage.clientesventa}, cVisitados: ${B4XPages.MainPage.clientesvisitados}, ${B4XPages.MainPage.lat_gps}, ${B4XPages.MainPage.lon_gps}, Batt: ${B4XPages.MainPage.batt}, 0, 0, 0, Almacen: ${B4XPages.MainPage.ALMACEN}, Ruta: ${B4XPages.MainPage.rutapreventa}"$)
|
|
reqManager.ExecuteCommand(cmd, "inst_visitas")
|
|
skmt.ExecNonQuery2("Update cat_variables set CAT_VA_VALOR = ? WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
|
|
'Reiniciamos el timer para cuando llamamos el Sub desde "seleccion"
|
|
Timer1.Enabled = False
|
|
Timer1.Interval = Interval * 1000
|
|
Timer1.Enabled = True
|
|
Else
|
|
Log("Sin conexión a internet, no se envió UTR!")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
'Para los Logs
|
|
Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
|
|
logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
|
|
If logs.Length > 4000 Then
|
|
logs.Remove(0, logs.Length - 2000) 'Obtenemos log de 2000 ~ 4000 chars
|
|
End If
|
|
End Sub
|
|
|
|
'Return true to allow the OS default exceptions handler to handle the uncaught exception. 'Para los Logs
|
|
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
|
|
'wait for 500ms to allow the logs to be updated.
|
|
Dim jo As JavaObject
|
|
Dim l As Long = 500: jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l)) 'Sleep 500ms
|
|
logcat.LogCatStop
|
|
logs.Append(StackTrace)
|
|
Subs.revisaBD
|
|
Subs.errorLog.ExecNonQuery2("INSERT INTO errores(fecha, error) VALUES (?,?)", Array As Object (Subs.fechaKMT(DateTime.now), logs))
|
|
Return True
|
|
End Sub
|
|
|
|
'Inicializa el reqServer con la dirección dada y lo guarda en CAT_VARIABLES.
|
|
Sub reinicializaReqManager(srv As String)
|
|
skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("SERVER"))
|
|
skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SERVER", srv))
|
|
DBReqServer = srv
|
|
reqManager.Initialize(Me, srv)
|
|
' LogColor(srv, Colors.red)
|
|
End Sub
|
|
|
|
Sub JobDone(Job As HttpJob)
|
|
' LogColor("starter jobdone", Colors.Red)
|
|
' Log(Job.ErrorMessage)
|
|
' Private r As DBResult = reqManager.HandleJob(Job)
|
|
If Job.Success = False Then
|
|
' LogColor("** " & Job.Tag & " Error: " & Job.ErrorMessage, Colors.Red) ' Mod by CHV - 211023
|
|
If Job.ErrorMessage.Contains("failed to connect") Or Job.ErrorMessage.Contains("Failed to connect") Then
|
|
ToastMessageShow("¡Hubo un error contactando al servidor, por favor revise su conexión!", True)
|
|
End If
|
|
'ToastMessageShow("Error: " & Job.ErrorMessage, True)
|
|
Else
|
|
' LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211023
|
|
End If
|
|
End Sub
|
|
|
|
Sub IsConnectedToInternet As Boolean 'ignore
|
|
Dim r As Reflector
|
|
r.Target = r.GetContext
|
|
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
|
|
r.Target = r.RunMethod("getActiveNetworkInfo")
|
|
If r.Target <> Null Then
|
|
Return r.RunMethod("isConnectedOrConnecting")
|
|
End If
|
|
Return False
|
|
End Sub
|
|
|
|
Private Sub timerRecordatorio_Tick
|
|
'10:30, 13:00 y 15:30
|
|
Log($"${DateTime.GetHour(DateTime.now)}:${DateTime.GetMinute(DateTime.now)}"$)
|
|
Log("Revisando la hora - UltimoRecordatorio: " & ultimoRecordatorio)
|
|
If ultimoRecordatorio <> DateTime.GetHour(DateTime.now) & DateTime.GetMinute(DateTime.now) Then
|
|
If (DateTime.GetHour(DateTime.now) = 10 And DateTime.GetMinute(DateTime.now) = 20) _ 'Recordatorio de las 10:20
|
|
Or (DateTime.GetHour(DateTime.now) = 10 And DateTime.GetMinute(DateTime.now) = 25) _ 'Recordatorio de las 10:25
|
|
Or (DateTime.GetHour(DateTime.now) = 10 And DateTime.GetMinute(DateTime.now) = 29) _ 'Recordatorio de las 10:29
|
|
Or (DateTime.GetHour(DateTime.now) = 10 And DateTime.GetMinute(DateTime.now) = 30) _ 'Recordatorio de las 10:30
|
|
Or (DateTime.GetHour(DateTime.now) = 12 And DateTime.GetMinute(DateTime.now) = 50) _ 'Recordatorio de las 12:50
|
|
Or (DateTime.GetHour(DateTime.now) = 12 And DateTime.GetMinute(DateTime.now) = 55) _ 'Recordatorio de las 12:55
|
|
Or (DateTime.GetHour(DateTime.now) = 12 And DateTime.GetMinute(DateTime.now) = 59) _ 'Recordatorio de las 12:59
|
|
Or (DateTime.GetHour(DateTime.now) = 13 And DateTime.GetMinute(DateTime.now) = 0) _ 'Recordatorio de las 13:00
|
|
Or (DateTime.GetHour(DateTime.now) = 15 And DateTime.GetMinute(DateTime.now) = 20) _ 'Recordatorio de las 15:20
|
|
Or (DateTime.GetHour(DateTime.now) = 15 And DateTime.GetMinute(DateTime.now) = 25) _ 'Recordatorio de las 15:25
|
|
Or (DateTime.GetHour(DateTime.now) = 15 And DateTime.GetMinute(DateTime.now) = 29) _ 'Recordatorio de las 15:29
|
|
Or (DateTime.GetHour(DateTime.now) = 15 And DateTime.GetMinute(DateTime.now) = 30) _ 'Recordatorio de las 15:30
|
|
Or (DateTime.GetHour(DateTime.now) = 10 And DateTime.GetMinute(DateTime.now) = 70) Then ' HORARIO DE PRUEBA
|
|
Log("¡¡MANDAMOS RECORDATORIO!!")
|
|
If Not(B4XPages.GetManager.IsForeground) Then Subs.notiHigh("¡¡ATENCION!!", "Recuerda enviar tu venta.", Main)
|
|
If B4XPages.MainPage.IsInitialized And B4XPages.MainPage.pantallaActual.IsInitialized Then
|
|
B4XPages.MainPage.recordatorio.agregaPanelRecordatorio(B4XPages.MainPage.pantallaActual)
|
|
End If
|
|
ultimoRecordatorio = DateTime.GetHour(DateTime.now) & DateTime.GetMinute(DateTime.now)
|
|
End If
|
|
End If
|
|
End Sub |