mirror of
https://github.com/KeymonSoft/Medicomed_Preventa.git
synced 2026-04-17 21:16:08 +00:00
Se hicieron invisibles normales de la venta, se agregaron 2 botones mas, uno indica que tieene venta y el otro que no tiene, tambien al boton que indica que tiene venta se le agrega una pequeña ventana para agregar la venta que se le indique.
158 lines
5.8 KiB
QBasic
158 lines
5.8 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 ph As Phone
|
|
Public rp As RuntimePermissions
|
|
Public FLP As FusedLocationProvider
|
|
Dim reqManager As DBRequestManager
|
|
Dim enVenta As Boolean = False
|
|
' Private flpStarted As Boolean
|
|
Dim reqManager As DBRequestManager
|
|
Dim server As String = "http://187.189.244.154:1781"
|
|
' Dim server As String = "http://187.189.244.154:1783"
|
|
' Dim server As String = "http://11.0.0.105:1782"
|
|
' Dim server As String = "http://11.0.0.220: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 = 0
|
|
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.
|
|
gps.Initialize("GPS")
|
|
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para Push FirebaseMessaging
|
|
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
|
|
' Log(marcaCel)
|
|
reqManager.Initialize(Me, server)
|
|
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 skmt As SQL
|
|
Dim cmd As DBCommand
|
|
skmt.Initialize(ruta,"kmt.db", False)
|
|
' cmd.Initialize
|
|
' cmd.Name = "select_fechat"
|
|
' B4XPages.MainPage.reqManager.ExecuteQuery(cmd , 0, "fechat")
|
|
Dim cmd As DBCommand
|
|
cmd.Initialize
|
|
cmd.Name = "UPDATE_MEDI_ACTUAL2_GPS"
|
|
If B4XPages.MainPage.lat_gps.Length < 15 Then B4XPages.MainPage.lat_gps = B4XPages.MainPage.lat_gps&"0"
|
|
'isaacPrueba
|
|
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
|
|
|
|
Sub reinicializaReqManager
|
|
reqManager.Initialize(Me, server)
|
|
' B4XPages.MainPage.reqManager.Initialize(Me, server)
|
|
If logger Then Log(server)
|
|
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 |