23/9/23 - Commit inicial.
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
**/Objects
|
||||
**/AutoBackups
|
||||
24
B4A/B4XUpdateAvailable.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
125
B4A/BatteryUtilities.bas
Normal file
@@ -0,0 +1,125 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=9.95
|
||||
@EndOfDesignText@
|
||||
'Class module
|
||||
Sub Class_Globals
|
||||
Private nativeMe As JavaObject
|
||||
End Sub
|
||||
|
||||
'Initializes the object.
|
||||
Public Sub Initialize
|
||||
nativeMe = Me
|
||||
End Sub
|
||||
'Return information about the battery status. It returns the following 11 values in an integer Array:
|
||||
'0 - EXTRA_LEVEL = current battery level, from 0 To EXTRA_SCALE.
|
||||
'1 - EXTRA_SCALE = the maximum battery level possible.
|
||||
'2 - EXTRA_HEALTH = the current health constant.
|
||||
'3 - EXTRA_ICON_SMALL = the resource ID of a small status bar icon indicating the current battery state.
|
||||
'4 - EXTRA_PLUGGED = whether the device is plugged into a Power source; 0 means it is on battery, other constants are different types of Power sources.
|
||||
'5 - EXTRA_STATUS = the current status constant.
|
||||
'6 - EXTRA_TEMPERATURE = the current battery temperature.
|
||||
'7 - EXTRA_VOLTAGE = the current battery voltage level.
|
||||
'8 - A value indicating if the battery is being charged or fully charged (If neither it returns 0 Else it returns 1)
|
||||
'9 - A value indicating if it is charging via USB (0 = Not USB, 2 = USB)
|
||||
'10 - A value indicating if it is charging via AC (0 = Not AC, 1 = AC)
|
||||
Public Sub getBatteryInformation () As Int()
|
||||
|
||||
Dim batteryInfo(11) As Int
|
||||
batteryInfo = nativeMe.RunMethod("getBatteryInformation",Null)
|
||||
Return batteryInfo
|
||||
End Sub
|
||||
|
||||
Public Sub getBatteryTechnolgy() As String
|
||||
|
||||
Dim batterytech As String
|
||||
batterytech = nativeMe.RunMethod("getBatteryTechnology",Null)
|
||||
Return batterytech
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
#If Java
|
||||
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
public int[] getBatteryInformation() {
|
||||
|
||||
int[] mybat = new int[11];
|
||||
|
||||
Intent batteryIntent = ba.context.getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
|
||||
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||
mybat[0] = level;
|
||||
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||
mybat[1] = scale;
|
||||
int health = batteryIntent.getIntExtra(BatteryManager.EXTRA_HEALTH,-1);
|
||||
mybat[2] = health;
|
||||
int icon_small = batteryIntent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL,-1);
|
||||
mybat[3] = icon_small;
|
||||
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED,-1);
|
||||
mybat[4] = plugged;
|
||||
// boolean present = batteryIntent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
|
||||
int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS,-1);
|
||||
mybat[5] = status;
|
||||
// String technology = batteryIntent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
|
||||
// BA.Log("Technology = " + technology);
|
||||
int temperature = batteryIntent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE,-1);
|
||||
mybat[6] = temperature;
|
||||
int voltage = batteryIntent.getIntExtra(BatteryManager.EXTRA_VOLTAGE,-1);
|
||||
mybat[7] = voltage;
|
||||
// int ac = batteryIntent.getIntExtra("plugged",BatteryManager.BATTERY_PLUGGED_AC);
|
||||
// mybat[8] = ac;
|
||||
// int usb = batteryIntent.getIntExtra("plugged",BatteryManager.BATTERY_PLUGGED_USB);
|
||||
// mybat[9] = usb;
|
||||
|
||||
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||||
status == BatteryManager.BATTERY_STATUS_FULL;
|
||||
mybat[8] = 0;
|
||||
if (isCharging == true) {
|
||||
mybat[8] = 1;
|
||||
}
|
||||
|
||||
// How are we charging?
|
||||
mybat[9] = 0;
|
||||
mybat[10] = 0;
|
||||
int chargePlug = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
|
||||
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
|
||||
if (usbCharge == true) {
|
||||
mybat[9] = 2;
|
||||
}
|
||||
|
||||
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
|
||||
if (acCharge == true) {
|
||||
mybat[10] = 1;
|
||||
}
|
||||
|
||||
return mybat;
|
||||
}
|
||||
|
||||
|
||||
public String getBatteryTechnology() {
|
||||
|
||||
Intent batteryIntent = ba.context.getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
|
||||
String technology = batteryIntent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
|
||||
|
||||
return technology;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#End If
|
||||
109
B4A/C_Buscar.bas
Normal file
@@ -0,0 +1,109 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim c As Cursor
|
||||
Dim ListView1 As ListView
|
||||
Dim b_noventa As Button
|
||||
Private p_principal As Panel
|
||||
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("buscar")
|
||||
c=Starter.skmt.ExecQuery("select REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT FROM REPARTO")
|
||||
ListView1.Clear
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 10
|
||||
label1.TextColor = Colors.Black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 10
|
||||
label2.TextColor = Colors.Blue
|
||||
ListView1.AddTwoLines(c.GetString("REP_CLIENTE"),c.GetString("REP_PRONOMBRE") &" Cantidad #"& c.GetString("REP_CANT")& " SubTotal $"& c.GetString("REP_COSTO_TOT"))
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
p_principal.Width = Root.Width
|
||||
p_principal.Height = Root.Height
|
||||
Subs.centraPanel(p_principal, Root.Width)
|
||||
|
||||
c=Starter.skmt.ExecQuery("select REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT FROM REPARTO")
|
||||
ListView1.Clear
|
||||
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 10
|
||||
label1.TextColor = Colors.Black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 10
|
||||
label2.TextColor = Colors.Blue
|
||||
ListView1.AddTwoLines(c.GetString("REP_CLIENTE"),c.GetString("REP_PRONOMBRE") &" Cantidad #"& c.GetString("REP_CANT")& " SubTotal $"& c.GetString("REP_COSTO_TOT"))
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
End Sub
|
||||
|
||||
Sub Regresar_Click
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' BACK key pressed
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Principal")
|
||||
'Return True
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
Sub ListView1_ItemLongClick (Position As Int, Value As Object)
|
||||
Starter.skmt.ExecNonQuery("delete from CUENTAA")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(Value))
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Sub b_noventa_Click
|
||||
c=Starter.skmt.ExecQuery("select NV_CLIENTE,NV_MOTIVO,NV_COMM FROM NOVENTA ORDER BY NV_CLIENTE asc")
|
||||
ListView1.Clear
|
||||
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 10
|
||||
label1.TextColor = Colors.Black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 10
|
||||
label2.TextColor = Colors.Blue
|
||||
ListView1.AddTwoLines(c.GetString("NV_CLIENTE"),"Motivo #"& c.GetString("NV_MOTIVO")& " Comentario $"& c.GetString("NV_COMM"))
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
428
B4A/C_Cliente.bas
Normal file
@@ -0,0 +1,428 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim g As GPS
|
||||
Dim clie_id As String
|
||||
Dim sDate,sTime As String
|
||||
Dim usuario As String
|
||||
Dim cuenta As String
|
||||
Dim btAdmin As BluetoothAdmin
|
||||
Dim cmp20 As Serial
|
||||
Dim printer As TextWriter
|
||||
Dim PairedDevices As Map
|
||||
Dim L As List
|
||||
Dim TAMANO As Int
|
||||
Dim ESPACIO As Int
|
||||
Dim BLANCO As String
|
||||
|
||||
Dim LONGITUD As String
|
||||
Dim LATITUD As String
|
||||
Dim NOMBRE As String
|
||||
Dim c As Cursor
|
||||
Dim s As Cursor
|
||||
Dim ListView1 As ListView
|
||||
Dim la_cuenta As Label
|
||||
Dim La_nombre As Label
|
||||
Dim la_Calle As Label
|
||||
Dim la_numero As Label
|
||||
Dim la_nint As Label
|
||||
Dim la_edo As Label
|
||||
Dim la_pob As Label
|
||||
Dim la_col As Label
|
||||
Dim la_cp As Label
|
||||
Dim la_zona As Label
|
||||
Dim gest As Button
|
||||
Dim la_saldotot As Label
|
||||
Dim la_saldooper As Label
|
||||
|
||||
Dim b_noEntrega As Button
|
||||
Dim Label10 As Label
|
||||
Dim Label11 As Label
|
||||
|
||||
Dim Tar As Button
|
||||
Private L_QR As Label
|
||||
Private BT_QR As Button
|
||||
|
||||
Dim la_comm As Label
|
||||
Dim la_actdte As Label
|
||||
Dim la_usuario As Label
|
||||
Dim la_resultado As Label
|
||||
Dim l_entre1 As Label
|
||||
Dim l_entre2 As Label
|
||||
Dim l_atiende As Label
|
||||
Dim l_atiende2 As Label
|
||||
Dim DATOS As Button
|
||||
Dim Guardar As Button
|
||||
Dim NUEVO As Button
|
||||
Private l_total As Label
|
||||
Private HIST As Button
|
||||
Dim PASA_IMP As String
|
||||
Private B_IMP As Button
|
||||
Dim total_cliente As String
|
||||
Dim CREDITO As String
|
||||
Private p_principal As Panel
|
||||
Private B_PASO2 As Button
|
||||
Private L_CANT As Label
|
||||
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
|
||||
g.Initialize("GPS")
|
||||
' Activity.LoadLayout("info_gral")
|
||||
Root.LoadLayout("cliente")
|
||||
c=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_RUTA, CAT_CL_NOMBRE, 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 from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
|
||||
s=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
s.Position=0
|
||||
c.Position=0
|
||||
la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
|
||||
La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
|
||||
la_Calle.Text = c.GetString("CAT_CL_CALLE") & c.GetString("CAT_CL_NOEXT")
|
||||
la_col.Text = c.GetString("CAT_CL_COLONIA")
|
||||
la_edo.Text = c.GetString("CAT_CL_EDO")
|
||||
la_cp.Text = c.GetString("CAT_CL_CP")
|
||||
l_entre1.Text = c.GetString("CAT_CL_CALLE1")
|
||||
l_entre2.Text = c.GetString("CAT_CL_CALLE2")
|
||||
If c.GetString("CAT_CL_ATIENDE1") <> Null And c.GetString("CAT_CL_ATIENDE1") <> "null" Then
|
||||
l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
|
||||
Else
|
||||
l_atiende.Text = " "
|
||||
End If
|
||||
If c.GetString("CAT_CL_ATIENTE2") <> Null And c.GetString("CAT_CL_ATIENTE2") <> "NULL" Then
|
||||
l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
|
||||
Log("|"&c.GetString("CAT_CL_ATIENTE2")&"|")
|
||||
Else
|
||||
l_atiende2.Text = " "
|
||||
End If
|
||||
la_saldotot.Text = c.GetString("CAT_CL_TELEFONO")
|
||||
la_saldooper.Text = c.GetString("CAT_CL_EMAIL")
|
||||
' l_total.Text = s.GetString("TOTAL_CLIE")
|
||||
btAdmin.Initialize("BlueTeeth")
|
||||
cmp20.Initialize("Printer")
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
Subs.centraPanel(p_principal, Root.Width)
|
||||
Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
|
||||
c=Starter.skmt.ExecQuery("select CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,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_BCREDITO from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
|
||||
s=Starter.skmt.ExecQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
s.Position=0
|
||||
c.Position=0
|
||||
la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
|
||||
La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
|
||||
NOMBRE = c.GetString("CAT_CL_NOMBRE")
|
||||
LONGITUD = c.GetString("CAT_CL_LONG")
|
||||
LATITUD = c.GetString("CAT_CL_LAT")
|
||||
la_Calle.Text = c.GetString("CAT_CL_CALLE") & c.GetString("CAT_CL_NOEXT")
|
||||
la_col.Text = c.GetString("CAT_CL_COLONIA")
|
||||
la_edo.Text = c.GetString("CAT_CL_EDO")
|
||||
la_cp.Text = c.GetString("CAT_CL_CP")
|
||||
l_entre1.Text = c.GetString("CAT_CL_CALLE1")
|
||||
l_entre2.Text = c.GetString("CAT_CL_CALLE2")
|
||||
If c.GetString("CAT_CL_ATIENDE1") <> Null And c.GetString("CAT_CL_ATIENDE1") <> "null" Then
|
||||
l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
|
||||
Else
|
||||
l_atiende.Text = " "
|
||||
End If
|
||||
If c.GetString("CAT_CL_ATIENTE2") <> Null And c.GetString("CAT_CL_ATIENTE2") <> "NULL" Then
|
||||
l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
|
||||
Else
|
||||
l_atiende2.Text = " "
|
||||
End If
|
||||
la_saldotot.Text = c.GetString("CAT_CL_TELEFONO")
|
||||
la_saldooper.Text = c.GetString("CAT_CL_EMAIL")
|
||||
' l_total.Text = s.GetString("TOTAL_CLIE")
|
||||
CREDITO = C.GetString("CAT_CL_BCREDITO")
|
||||
|
||||
|
||||
Private cym As Map = Subs.traeCantYMonto2(Subs.traeCliente)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
l_total.Text = Round2(cym.Get("monto"), 2)
|
||||
|
||||
If CREDITO = "1" Then
|
||||
Msgbox("AVISO","SE TIENE QUE IMPRIMIR PAGARÉ") 'ignore
|
||||
End If
|
||||
' Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
' L_CANT.Text = cym.Get("cantidad")
|
||||
' l_total.Text = cym.Get("monto")
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Location1 As Location)
|
||||
' lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
|
||||
' lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
|
||||
Dim sDate,sTime As String
|
||||
DateTime.DateFormat = "MM/dd/yyyy"
|
||||
sDate=DateTime.Date(DateTime.Now)
|
||||
sTime=DateTime.Time(DateTime.Now)
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM HIST_GPS")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
|
||||
End Sub
|
||||
|
||||
Sub ListView1_ItemLongClick (Position As Int, Value As Object)
|
||||
|
||||
End Sub
|
||||
|
||||
Sub gest_Click
|
||||
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.Close
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM NOVENTA WHERE NV_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, "ENTREGA","ENTREGA COMPLETA", B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
|
||||
Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2 where CAT_CL_CODIGO In (select cuenta from cuentaa) ")
|
||||
Starter.skmt.ExecNonQuery("update HIST_VENTAS SET HVD_ESTATUS = 1 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
|
||||
B4XPages.ShowPage("Principal")
|
||||
End Sub
|
||||
|
||||
Sub b_noEntrega_Click
|
||||
' skmt.ExecNonQuery("delete from PEDIDO")
|
||||
B4XPages.ShowPage("noVenta")
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' BACK key pressed
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Clientes")
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
Sub Tar_Click
|
||||
' StartActivity(colonia2)
|
||||
B4XPages.ShowPage("Productos")
|
||||
End Sub
|
||||
|
||||
Sub DATOS_Click
|
||||
' StartActivity(telefonos)
|
||||
End Sub
|
||||
|
||||
Sub Guardar_Click
|
||||
B4XPages.ShowPage("Principal")
|
||||
End Sub
|
||||
|
||||
Sub NUEVO_Click
|
||||
StartActivity(MAPA_CLIENTE)
|
||||
End Sub
|
||||
|
||||
Sub HIST_Click
|
||||
' B4XPages.MainPage.historico.prodsMap.Initialize
|
||||
'' B4XPages.MainPage.historico.clv_pedido.Clear
|
||||
' B4XPages.ShowPage("Historico")
|
||||
B4XPages.MainPage.detalleVenta.prodsMap.Initialize
|
||||
' B4XPages.MainPage.historico.clv_pedido.Clear
|
||||
B4XPages.ShowPage("DetalleVenta")
|
||||
End Sub
|
||||
|
||||
Sub B_IMP_Click
|
||||
c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
c.Position=0
|
||||
usuario = c.GetString("USUARIO")
|
||||
DateTime.DateFormat = "MM/dd/yyyy"
|
||||
sDate=DateTime.Date(DateTime.Now)
|
||||
sTime=DateTime.Time(DateTime.Now)
|
||||
TAMANO = 0
|
||||
ESPACIO = 21
|
||||
BLANCO = " "
|
||||
CREDITO ="1"
|
||||
If CREDITO = "1" Then
|
||||
DateTime.DateFormat = "MM/dd/yyyy"
|
||||
sDate=DateTime.Date(DateTime.Now)
|
||||
sTime=DateTime.Time(DateTime.Now)
|
||||
printer.Initialize(cmp20.OutputStream)
|
||||
printer.WriteLine("DBC.")
|
||||
printer.WriteLine("RFC: ")
|
||||
printer.WriteLine(sDate)
|
||||
printer.WriteLine(sTime)
|
||||
printer.WriteLine("Tienda: " & La_nombre.Text)
|
||||
s=Starter.skmt.ExecQuery("select SUM(HVD_CANT) AS PC_NOART, SUM(HVD_COSTO_TOT) AS PC_MONTO from HIST_VENTAS where HVD_CLIENTE in (Select CUENTA from cuentaa)")
|
||||
s.Position=0
|
||||
printer.WriteLine("Debo (emos) y pagare (mos) incondicionamelte a la orden de DBC a la cantidad de $" & s.GetString("PC_MONTO") & " PESOS _______________________________________________________________________________________________________________ ")
|
||||
printer.WriteLine("en esta ciudad o en cualquier otra que se requiera de pago, valor recibido a mi entera satisfaccion y que me obligo a cumplir el dia______________________.")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine("Si este pagare no fuera cubiertoa su vencimiento Me (nos) obligo (amos) a pagar intereses moratorios a razon de 3 % mensual")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine(" ")
|
||||
printer.WriteLine("------------------------------")
|
||||
printer.WriteLine(" NOMBRE Y FIRMA ")
|
||||
printer.WriteLine("------------------------------")
|
||||
printer.WriteLine(" ")
|
||||
printer.Flush
|
||||
End If
|
||||
|
||||
printer.Initialize(cmp20.OutputStream)
|
||||
printer.WriteLine("PROFINA")
|
||||
printer.WriteLine("RFC: ")
|
||||
printer.WriteLine("Tel.:")
|
||||
printer.WriteLine(sDate)
|
||||
printer.WriteLine(sTime)
|
||||
printer.WriteLine("Vendedor:" & usuario)
|
||||
printer.WriteLine("Tienda: " & La_nombre.Text)
|
||||
s=Starter.skmt.ExecQuery("select SUM(HVD_CANT) AS PC_NOART, SUM(HVD_COSTO_TOT) AS PC_MONTO from HIST_VENTAS where HVD_CLIENTE in (Select CUENTA from cuentaa)")
|
||||
s.Position=0
|
||||
c=Starter.skmt.ExecQuery("select SUM(PE_CANT) AS PE_CANT, SUM(PE_COSTO_TOT) AS PE_COSTO_TOT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
C.Position=0
|
||||
|
||||
printer.WriteLine("Total : $" & (s.GetString("PC_MONTO") + c.GetString("PE_COSTO_TOT")))
|
||||
s.Close
|
||||
printer.WriteLine("-----------ENTREGA------------")
|
||||
S=Starter.skmt.ExecQuery("select HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,length(HVD_cant) as L_CANT,HVD_COSTO_TOT,length(HVD_COSTO_TOT) as L_COSTO_TOT from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) ")
|
||||
|
||||
's=skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA"))
|
||||
If S.RowCount>0 Then
|
||||
For i=0 To S.RowCount -1
|
||||
S.Position=i
|
||||
'If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
|
||||
' printer.WriteLine(s.GetString("PE_PRONOMBRE"))
|
||||
|
||||
'Else
|
||||
|
||||
printer.WriteLine(s.GetString("HVD_CANT") & " " & s.GetString("HVD_PRONOMBRE"))
|
||||
TAMANO = s.GetLong("L_CANT") + TAMANO
|
||||
'TAMANO = s.GetLong("L_COSTOU") + TAMANO
|
||||
TAMANO = s.GetLong("L_COSTO_TOT") + TAMANO
|
||||
|
||||
ESPACIO = ESPACIO - TAMANO
|
||||
|
||||
For E=0 To ESPACIO -1
|
||||
BLANCO = " " & BLANCO
|
||||
Next
|
||||
printer.WriteLine("$" & s.GETSTRING("HVD_COSTO_TOT") )
|
||||
TAMANO = 0
|
||||
ESPACIO = 21
|
||||
BLANCO = " "
|
||||
'End If
|
||||
Next
|
||||
End If
|
||||
s.Close
|
||||
|
||||
s=Starter.skmt.ExecQuery2("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("VENTA"))
|
||||
If S.RowCount>0 Then
|
||||
For i=0 To S.RowCount -1
|
||||
S.Position=i
|
||||
'If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
|
||||
' printer.WriteLine(s.GetString("PE_PRONOMBRE"))
|
||||
|
||||
'Else
|
||||
|
||||
printer.WriteLine(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE"))
|
||||
TAMANO = s.GetLong("L_CANT") + TAMANO
|
||||
'TAMANO = s.GetLong("L_COSTOU") + TAMANO
|
||||
TAMANO = s.GetLong("L_COSTO_TOT") + TAMANO
|
||||
|
||||
ESPACIO = ESPACIO - TAMANO
|
||||
|
||||
For E=0 To ESPACIO -1
|
||||
BLANCO = " " & BLANCO
|
||||
Next
|
||||
printer.WriteLine("$" & s.GETSTRING("PE_COSTO_TOT") )
|
||||
TAMANO = 0
|
||||
ESPACIO = 21
|
||||
BLANCO = " "
|
||||
'End If
|
||||
Next
|
||||
End If
|
||||
s.Close
|
||||
printer.WriteLine("------------------------------")
|
||||
printer.WriteLine("---NO ES UN COMPROBANTE ------")
|
||||
printer.WriteLine("---------FISCAL---------------")
|
||||
printer.WriteLine("---COMPROBANTE DE ENTREGA-----")
|
||||
printer.WriteLine("------------------------------")
|
||||
|
||||
printer.Flush
|
||||
' printer.Close
|
||||
End Sub
|
||||
|
||||
Sub Printer_Connected (Success As Boolean)
|
||||
If Success Then
|
||||
B_IMP.Enabled = True
|
||||
PASA_IMP = "1"
|
||||
Else
|
||||
B_IMP.Enabled = False
|
||||
If Msgbox2("", "Printer Error","Reprint","Cancel","",Null) = DialogResponse.POSITIVE Then 'ignore
|
||||
StartPrinter
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub StartPrinter
|
||||
Dim PairedDevices As Map
|
||||
Dim L As List
|
||||
Dim resimp As Int
|
||||
ToastMessageShow("Printing.....",True)
|
||||
PairedDevices.Initialize
|
||||
Try
|
||||
PairedDevices = cmp20.GetPairedDevices
|
||||
Catch
|
||||
Msgbox("Getting Paired Devices","Printer Error") 'ignore
|
||||
printer.Close
|
||||
cmp20.Disconnect
|
||||
End Try
|
||||
If PairedDevices.Size = 0 Then
|
||||
Msgbox("Error Connecting to Printer - Printer Not Found","") 'ignore
|
||||
Return
|
||||
End If
|
||||
If PairedDevices.Size = 1 Then
|
||||
Try
|
||||
'FLEOS
|
||||
cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
|
||||
'cmp20.Connect(PairedDevices.Get(PairedDevices.GetKeyAt(0)))
|
||||
Catch
|
||||
Msgbox("Connecting","Printer Error") 'ignore
|
||||
printer.Close
|
||||
cmp20.Disconnect
|
||||
End Try
|
||||
Else
|
||||
L.Initialize
|
||||
For i = 0 To PairedDevices.Size - 1
|
||||
L.Add(PairedDevices.GetKeyAt(i))
|
||||
Next
|
||||
resimp = InputList(L, "Choose device", -1) 'ignore
|
||||
If resimp <> DialogResponse.CANCEL Then
|
||||
cmp20.Connect(PairedDevices.Get(L.Get(resimp)))
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub B_PASO2_Click
|
||||
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.Close
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM NOVENTA WHERE NV_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, "PASO","PASO ESPERA", B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
|
||||
B4XPages.ShowPage("Principal")
|
||||
End Sub
|
||||
563
B4A/C_Clientes.bas
Normal file
@@ -0,0 +1,563 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Mods
|
||||
'Los clientes con rechazo se estan mostrando en la lista ... se DEBEN de mostrar???
|
||||
End Sub
|
||||
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim q_buscar As String
|
||||
' Dim skmt As SQL
|
||||
Dim entro As String
|
||||
Dim c As Cursor
|
||||
Dim c2 As Cursor
|
||||
Dim ListView1 As ListView
|
||||
' Dim gest As Button
|
||||
Dim lfila As Label
|
||||
Dim busca As EditText
|
||||
Private p_colonia As Panel
|
||||
' Dim distList As List
|
||||
' Dim distMap As Map
|
||||
Dim laRuta As String
|
||||
Private b_GetDirs As Button
|
||||
Private distOrderedMap, clientesMapaO As B4XOrderedMap
|
||||
Private img_getDirs As ImageView
|
||||
Private l_rutaInfo As Label
|
||||
Private b_getRutaInfo As Button
|
||||
Private conMapa As Boolean = False
|
||||
Dim listaWayPoints As List
|
||||
Dim lv1Top As String
|
||||
Private b_limpiarRuta As Button
|
||||
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("clientes")
|
||||
entro ="2"
|
||||
lv1Top = ListView1.Top
|
||||
clientesMapaO.Initialize
|
||||
Starter.skmt.ExecNonQuery("delete from waypoints")
|
||||
Log("Coordenadas del almacen: " & Starter.cedisLocation.Longitude & "," & Starter.cedisLocation.Latitude)
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
busca.Text = ""
|
||||
b_GetDirs.Visible = False
|
||||
' skmt.Initialize(Starter.ruta,"kmt.db", True)
|
||||
entro ="2"
|
||||
' esto es para rutas se quito por colonia
|
||||
'SE COMENTA EL SIGUIENTE CODIGO PARA QUE TODAS LAS TIENDAS APAREZCAN.
|
||||
'c=skmt.ExecQuery("select CAT_CL_COLONIA, count(*) as cuantos from kmt_info where gestion = 0 group by CAT_CL_COLONIA order by CAT_CL_COLONIA asc")
|
||||
p_colonia.Width = Root.Width
|
||||
p_colonia.Height = Root.Height
|
||||
p_colonia.Top = 0
|
||||
p_colonia.Left = 0
|
||||
Subs.centraListView(ListView1, p_colonia.Width)
|
||||
ListView1.Height = p_colonia.Height * 0.75
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
If Not(l_rutaInfo.Visible) Then
|
||||
ListView1.Top = lv1Top
|
||||
Else
|
||||
ListView1.Top = lv1Top + 100
|
||||
End If
|
||||
c=Starter.skmt.ExecQuery("select codigo, indice, CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_NOEXT from waypoints inner join kmt_info on waypoints.codigo = kmt_info.CAT_CL_CODIGO where gestion = 0 order by indice")
|
||||
If c.RowCount > 0 Then 'Ya hay waypoints en la base de datos
|
||||
c.Position = 0
|
||||
' Log("Ya hay waypoints.")
|
||||
conMapa = True
|
||||
' Private t1 As Map
|
||||
ListView1.Clear
|
||||
Dim cs, cs2 As CSBuilder
|
||||
entro = 3
|
||||
' Log("Generamos ListView1 en Activity_Resume")
|
||||
For i=0 To c.RowCount -1 'Generamos el listView con la lista ordenada.
|
||||
c.Position=i
|
||||
cs.Initialize
|
||||
cs2.Initialize
|
||||
' t1 = Starter.waypointsOrdered.Get(k)
|
||||
' c.GetString("codigo")
|
||||
ListView1.AddTwoLines(cs.Color(Colors.RGB(100,149,237)).Append(c.GetString("codigo")).PopAll, cs2.append(c.GetString("CAT_CL_NOMBRE")).Color(Colors.RGB(100,149,237)).Append(" Calle: ").Pop.Append(c.GetString("CAT_CL_CALLE").Trim & " " & c.GetString("CAT_CL_NOEXT")).PopAll )
|
||||
Next
|
||||
Else
|
||||
generaListViewRutas
|
||||
End If
|
||||
c.Close
|
||||
p_colonia.Width = Root.Width
|
||||
p_colonia.Height = Root.Height
|
||||
Subs.centraEtiqueta(l_rutaInfo, Root.Width)
|
||||
Subs.centraListView(ListView1, p_colonia.Width)
|
||||
ListView1.Height = p_colonia.Height * 0.70
|
||||
Subs.centraEtiqueta(lfila, Root.Width)
|
||||
b_getRutaInfo.Visible = True
|
||||
b_getRutaInfo.BringToFront
|
||||
End Sub
|
||||
|
||||
|
||||
Sub ListView1_ItemClick (Position As Int, Value As Object)
|
||||
' Log($"Entro= ${entro}"$)
|
||||
ListView1.Clear
|
||||
Sleep(50)
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
If Not(l_rutaInfo.Visible) Then
|
||||
ListView1.Top = lv1Top
|
||||
Else
|
||||
ListView1.Top = lv1Top + 100
|
||||
End If
|
||||
l_rutaInfo.Visible = False
|
||||
b_GetDirs.Visible = False
|
||||
If entro = "2" Then
|
||||
b_GetDirs.Visible = True
|
||||
img_getDirs.Visible = True
|
||||
b_getRutaInfo.Visible = False
|
||||
Private lrt As String
|
||||
lrt = Value
|
||||
laRuta = lrt.SubString(6) 'Quitamos el texto "Ruta: " para obtener el numero de la ruta.
|
||||
' Log($"Original: ${Value} - Mod: |${lrt.SubString(6)}| - laRuta: ${laRuta}"$)
|
||||
c2=Starter.skmt.ExecQuery2("select CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO, CAT_CL_LAT, CAT_CL_LONG from kmt_info where CAT_CL_RUTA = ? and gestion = 0 order by CAT_CL_NOMBRE ", Array As String(laRuta))
|
||||
Private thisLoc As Location
|
||||
Private label1 As Label
|
||||
Private label2 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 15
|
||||
label1.TextColor = Colors.black
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 15
|
||||
label2.TextColor = Colors.black
|
||||
label2.Height = 38dip
|
||||
thisLoc.Initialize
|
||||
If entro = 2 Then ListView1.TwoLinesLayout.ItemHeight = 75dip
|
||||
lfila.text = "Nombre y Calle"
|
||||
distOrderedMap.Initialize
|
||||
If c2.RowCount>0 Then
|
||||
For i=0 To c2.RowCount -1 'Generamos mapa de clientes
|
||||
c2.Position=i
|
||||
thisLoc.Latitude = c2.GetString("CAT_CL_LAT")
|
||||
thisLoc.Longitude = c2.GetString("CAT_CL_LONG")
|
||||
' Log(Tracker.UUGCoords)
|
||||
Private distancia As Int = Tracker.UUGCoords.DistanceTo(thisLoc) 'Calculamos la distancia de la posicion ACTUAL a la tienda.
|
||||
Private esteCliente As Map = CreateMap("distancia": distancia, "ubicacion": thisLoc.Longitude&","&thisLoc.Latitude, "codigo": c2.GetString("CAT_CL_CODIGO"), "nomDirDist": $"${c2.GetString("CAT_CL_NOMBRE")} CALLE: ${c2.GetString("CAT_CL_CALLE")} ${CRLF}Distancia: $1.1{(distancia/1000)} kms"$)
|
||||
distOrderedMap.Put(distancia, esteCliente)
|
||||
Next
|
||||
distOrderedMap.Keys.Sort(True) 'Ordenamos la mapa de clientes por distancia.
|
||||
ListView1.Clear
|
||||
Private m1 As Map
|
||||
For Each k As Object In distOrderedMap.Keys 'Generamos el listView con el mapa ordenada.
|
||||
m1 = distOrderedMap.Get(k)
|
||||
m1.Get("codigo")
|
||||
ListView1.AddTwoLines(m1.Get("codigo"), m1.Get("nomDirDist"))
|
||||
Next
|
||||
End If
|
||||
c2.Close
|
||||
entro = "3"
|
||||
Else If entro = "3" Then
|
||||
Starter.skmt.ExecNonQuery("delete from CUENTAA")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object(Value))
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Genera el listview que muestra las rutas y clientes a visitar por ruta.
|
||||
Sub generaListViewRutas
|
||||
ListView1.Clear
|
||||
Sleep(110)
|
||||
lfila.Text = "RUTA PREVENTA"
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 15
|
||||
label1.TextColor = Colors.Black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 15
|
||||
label2.TextColor = Colors.Black
|
||||
ListView1.TwoLinesLayout.ItemHeight = 60dip
|
||||
c=Starter.skmt.ExecQuery("select CAT_CL_RUTA, count(*) as cuantos from kmt_info where gestion = 0 group by CAT_CL_RUTA order by CAT_CL_RUTA asc")
|
||||
If c.RowCount>0 Then
|
||||
ListView1.Clear
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
ListView1.AddTwoLines("Ruta: " & c.GetString("CAT_CL_RUTA"), "Por visitar: " & c.GetString("cuantos"))
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
End Sub
|
||||
|
||||
Sub Activity_KeyPress (key As Int) As Boolean 'ignore
|
||||
' BACK key pressed
|
||||
If key=KeyCodes.KEYCODE_BACK Then
|
||||
If entro = 3 And Not(conMapa) Then
|
||||
b_GetDirs.Visible = False
|
||||
' StartActivity(Activity_Create(False))
|
||||
B4XPage_Created(Root)
|
||||
Return True
|
||||
End If
|
||||
B4XPages.ShowPage("Principal")
|
||||
Return False
|
||||
'End If
|
||||
End If
|
||||
' Returning False signals the system to handle the key
|
||||
End Sub
|
||||
|
||||
Sub BUSCA_TextChanged (Old As String, New As String)
|
||||
q_buscar = "%" & busca.Text & "%"
|
||||
c2=Starter.skmt.ExecQuery2("select CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO from kmt_info where CAT_CL_NOMBRE like ? and gestion = 0 order by CAT_CL_CODIGO ", Array As String(q_buscar))
|
||||
ListView1.Clear
|
||||
lfila.text = "Nombre y Calle"
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
If c2.RowCount>0 Then
|
||||
For i=0 To c2.RowCount -1
|
||||
c2.Position=i
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 15
|
||||
label1.TextColor = Colors.Black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 15
|
||||
label2.TextColor = Colors.Black
|
||||
ListView1.AddTwoLines(c2.GetString("CAT_CL_CODIGO"), c2.GetString("CAT_CL_NOMBRE") &" CALLE: "& c2.GetString("CAT_CL_CALLE"))
|
||||
Next
|
||||
End If
|
||||
entro = "3"
|
||||
c2.Close
|
||||
End Sub
|
||||
|
||||
'Regresa la distancia y tiempo de la ruta entre dos puntos, usa el API del projecto OSRM. (Parte de la funcionalidad OSRM)
|
||||
'Para mas información ir a esta liga:
|
||||
'http://project-osrm.org/docs/v5.24.0/api/?language=cURL#route-service
|
||||
Sub distanciaEntreCoords(id As String, coords1 As String, coords2 As String) As ResumableSub 'ignore
|
||||
Sleep(1050)
|
||||
Private distanciaTotal As String = "0"
|
||||
Private tiempo As String = "0"
|
||||
Dim j As HttpJob
|
||||
j.Initialize("", Me)
|
||||
j.Download("https://router.project-osrm.org/route/v1/driving/"&coords1&";"&coords2&"?overview=false")
|
||||
Wait For (j) JobDone(j As HttpJob)
|
||||
If j.Success Then
|
||||
Dim jp As JSONParser
|
||||
jp.Initialize(j.GetString)
|
||||
Dim m As Map = jp.NextObject
|
||||
Log($"Respuesta: ${m.Get("code")}"$)
|
||||
If m.Get("code") = "Ok" Then
|
||||
' Log(m)
|
||||
Dim rutas As List = m.Get("routes")
|
||||
Dim rutas2 As Map = rutas.Get(0)
|
||||
' Log(rutas2)
|
||||
' Dim legs As List = rutas2.Get("legs")
|
||||
' Log(legs)
|
||||
distanciaTotal = rutas2.Get("distance")
|
||||
tiempo = rutas2.Get("duration")
|
||||
Log($"Distancia total: ${distanciaTotal}, Tiempo: ${tiempo}"$ )
|
||||
End If
|
||||
Else
|
||||
Log("Error!")
|
||||
End If
|
||||
j.Release
|
||||
Private r As List
|
||||
r.Initialize
|
||||
r.Add(id)
|
||||
r.Add(distanciaTotal)
|
||||
r.Add(tiempo)
|
||||
Return r
|
||||
End Sub
|
||||
|
||||
'Regresa la distancia y tiempo estimado de la ruta del repartidor, utiliza el API del projecto OSRM
|
||||
'para calcular la distancia y tiempo de la ruta de un mapa de coordenadas a visitar dado. (Parte de la funcionalidad OSRM)
|
||||
Sub traeRutaDia(aVisitar As B4XOrderedMap)
|
||||
Private coordsInicio As String = $"${Starter.cedisLocation.Longitude},${Starter.cedisLocation.Latitude}"$
|
||||
Log($"Coordenadas de inicio: ${Starter.cedisLocation.Longitude},${Starter.cedisLocation.Latitude}"$)
|
||||
Private rutaCompleta As String = coordsInicio
|
||||
Private preRuta As String = coordsInicio
|
||||
Private distanciaTotal, distanciaTotal0, tiempo0, tiempo As Double
|
||||
Private masDe100 As Boolean
|
||||
Private m4 As Map
|
||||
Private visitaActual As Int = 0
|
||||
Private cuantosAntes As Int = 0
|
||||
listaWayPoints.Initialize
|
||||
If aVisitar.Keys.Size > 98 Then 'Si los clientes a visitar son mas de 100 entonces hacemos 2 rutas, una inicial con pocas visitas (las que pasen de 100) y la final con el resto ...
|
||||
cuantosAntes = aVisitar.Keys.Size - 98 'Definimos de cuantos clientes va a ser la ruta inicial.
|
||||
preRuta = coordsInicio 'Ponemos las coordenadas de inicio (Las del CEDIS).
|
||||
rutaCompleta = ""
|
||||
masDe100 = True
|
||||
End If
|
||||
Log($"a visitar: ${aVisitar.Keys.Size}"$)
|
||||
For Each k As Object In aVisitar.Keys
|
||||
visitaActual = visitaActual + 1
|
||||
m4 = aVisitar.Get(k)
|
||||
' Log($"visitaActual: ${visitaActual} - cuantosAntes: ${cuantosAntes}"$)
|
||||
If visitaActual < cuantosAntes + 2 Then 'Si estas coordenadas son de la ruta inicial las agregamos ...
|
||||
preRuta = preRuta & ";" & m4.Get("coords")
|
||||
' LogColor($"PreRuta - visitaActual: ${visitaActual} - coords: ${m4.Get("coords")}"$, Colors.Magenta)
|
||||
End If
|
||||
If visitaActual >= cuantosAntes + 2 Then 'Si estas coordenadas son de la ruta final las agregamos ...
|
||||
rutaCompleta = rutaCompleta & ";" & m4.Get("coords")
|
||||
' LogColor($"RutaCompleta - visitaActual: ${visitaActual} - coords: ${m4.Get("coords")} - testRuta Size: ${testRutaCompleta.size}"$, Colors.Green)
|
||||
End If
|
||||
Next
|
||||
rutaCompleta = rutaCompleta & ";" & coordsInicio 'Agregamos las coordenadas del CEDIS al final para que sea viaje ida y vuelta.
|
||||
' rutaCompleta = rutaCompleta & ";" & coordsInicio
|
||||
If rutaCompleta.StartsWith(";") Then rutaCompleta = rutaCompleta.SubString(1) 'Si las cooredenadas tienen ";" al principio se lo quitamos.
|
||||
' LogColor(preRuta, Colors.magenta)
|
||||
' LogColor(rutaCompleta, Colors.Green)
|
||||
ProgressDialogShow2("Calculando distancia y tiempo, un momento por favor.", False)
|
||||
Private tiempoVisitas As Double 'TIMEPO DE 4 MINUTOS PROMEDIO POR TIENDA ESTO SE CAMBIA SEGUN EL CLIENTE
|
||||
tiempoVisitas = aVisitar.Keys.Size * 4 * 60 'Aqui se calcula el tiempo que duran las visitas x 4 mins cada una en segundos.
|
||||
tiempo0 = 0
|
||||
distanciaTotal0 = 0
|
||||
If masDe100 Then 'Si son mas de 100, entonces primero calculamos la ruta inicial.
|
||||
Dim j0 As HttpJob
|
||||
j0.Initialize("trip0", Me)
|
||||
j0.Download("https://router.project-osrm.org/trip/v1/driving/"&preRuta&"?source=first&destination=last&roundtrip=false&geometries=geojson")
|
||||
' LogColor("https://router.project-osrm.org/trip/v1/driving/"&preRuta&"?source=first&destination=last&roundtrip=false&geometries=geojson", Colors.Magenta)
|
||||
Wait For (j0) JobDone(j0 As HttpJob)
|
||||
If j0.Success Then
|
||||
Dim jp0 As JSONParser
|
||||
jp0.Initialize(j0.GetString)
|
||||
Dim m0 As Map = jp0.NextObject
|
||||
If m0.Get("code") = "Ok" Then
|
||||
Dim puntos0 As List = m0.Get("waypoints")
|
||||
Private esteWayPoint0 As Map
|
||||
For p = 0 To puntos0.Size -1
|
||||
esteWayPoint0 = puntos0.Get(p)
|
||||
' LogColor("WP:" & esteWayPoint0, Colors.magenta)
|
||||
' LogColor("WP: " & esteWayPoint0.Get("waypoint_index") & ", loc: " & esteWayPoint0.Get("location") & ", name: " & esteWayPoint0.Get("name"), Colors.Magenta)
|
||||
esteWayPoint0.Remove("hint")
|
||||
esteWayPoint0.Remove("distance")
|
||||
esteWayPoint0.Remove("trips_index")
|
||||
listaWayPoints.Add(esteWayPoint0)
|
||||
' LogColor("estewaypoint: "&esteWayPoint0, Colors.Magenta)
|
||||
Next
|
||||
Dim rutas0 As List = m0.Get("trips")
|
||||
Dim rutas20 As Map = rutas0.Get(0)
|
||||
' Dim geometry0 As Map = rutas20.Get("geometry")
|
||||
' Private coords0 As List = geometry0.Get("coordinates")
|
||||
distanciaTotal0 = rutas20.Get("distance")
|
||||
tiempo0 = rutas20.Get("duration")
|
||||
tiempo0 = ((tiempo0 * 2) ) 'Tiempo X 2 (es muy corto porque no toma encuenta el trafico).
|
||||
Log($"Distancia total ruta inicial: $1.1{distanciaTotal0/1000} kms, tiempo aprox: $1.1{tiempo0/60} mins. ($1.1{tiempo0/60/60} hrs)"$)
|
||||
' l_rutaInfo.Text = $"Distancia total: $1.1{distanciaTotal0/1000} kms, tiempo aprox: $1.1{tiempo0/60/60} hrs"$
|
||||
End If
|
||||
Else
|
||||
Log("Error!")
|
||||
End If
|
||||
j0.Release
|
||||
End If
|
||||
|
||||
Dim j As HttpJob
|
||||
j.Initialize("trip", Me) 'Calculamos el resto de la ruta.
|
||||
j.Download("https://router.project-osrm.org/trip/v1/driving/"&rutaCompleta&"?source=first&destination=last&roundtrip=false&geometries=geojson")
|
||||
' LogColor("https://router.project-osrm.org/trip/v1/driving/"&rutaCompleta&"?source=first&destination=last&roundtrip=false&geometries=geojson", Colors.Green)
|
||||
Wait For (j) JobDone(j As HttpJob)
|
||||
If j.Success Then
|
||||
Dim jp As JSONParser
|
||||
jp.Initialize(j.GetString)
|
||||
Dim m As Map = jp.NextObject
|
||||
If m.Get("code") = "Ok" Then
|
||||
Dim puntos As List = m.Get("waypoints")
|
||||
Private esteWayPoint As Map
|
||||
Dim twpi As Int
|
||||
For p = 0 To puntos.Size -1
|
||||
esteWayPoint = puntos.Get(p)
|
||||
' LogColor("WP:" & esteWayPoint, Colors.green)
|
||||
' LogColor("WP: " & esteWayPoint.Get("waypoint_index") & ", loc: " & esteWayPoint.Get("location") & ", name: " & esteWayPoint.Get("name"), Colors.Green)
|
||||
esteWayPoint.Remove("hint")
|
||||
esteWayPoint.Remove("distance")
|
||||
esteWayPoint.Remove("trips_index")
|
||||
twpi = esteWayPoint.Get("waypoint_index")
|
||||
esteWayPoint.Remove("waypoint_index")
|
||||
esteWayPoint.Put("waypoint_index", (twpi + cuantosAntes + 2))
|
||||
listaWayPoints.Add(esteWayPoint)
|
||||
' LogColor("estewaypoint: "&esteWayPoint, Colors.Green)
|
||||
Next
|
||||
Dim rutas As List = m.Get("trips")
|
||||
Dim rutas2 As Map = rutas.Get(0)
|
||||
distanciaTotal = rutas2.Get("distance")
|
||||
Log("distancia ruta 2:" & (distanciaTotal) & "|" & rutas2.Get("distance"))
|
||||
distanciaTotal = distanciaTotal + distanciaTotal0
|
||||
tiempo = rutas2.Get("duration")
|
||||
tiempo = (((tiempo + tiempo0) * 2) + tiempoVisitas) 'Tiempo X 2 (es muy corto porque no toma encuenta el trafico) + tiempoVisitas.
|
||||
Log($"Distancia total: $1.1{distanciaTotal/1000} kms, tiempo aprox: $1.1{tiempo/60} mins. ($1.1{tiempo/60/60} hrs)"$)
|
||||
l_rutaInfo.Text = $"Distancia: $1.1{distanciaTotal/1000} kms, tiempo aprox: $1.1{tiempo/60/60} hrs${CRLF}Visitas restantes: ${aVisitar.Keys.Size}"$
|
||||
l_rutaInfo.Width = Root.Width * 0.9
|
||||
Subs.centraEtiqueta(l_rutaInfo, Root.Width)
|
||||
l_rutaInfo.Visible = True
|
||||
l_rutaInfo.BringToFront
|
||||
ListView1.Top = lv1Top + 100
|
||||
End If
|
||||
Else
|
||||
LogColor("**************** Error! ******************", Colors.red)
|
||||
End If
|
||||
j.Release
|
||||
ProgressDialogHide
|
||||
' LogColor("clientesMapaO size: " & clientesMapaO.Size & "|" & listaWayPoints.Size, Colors.Blue)
|
||||
Private r As Int = 1
|
||||
Private r1, wps As Map
|
||||
Starter.skmt.ExecNonQuery("delete from waypoints")
|
||||
For Each k As Object In clientesMapaO.Keys 'Guardamos en la BD el orden de los waypoints para luego generar el listview.
|
||||
r1 = clientesMapaO.Get(k)
|
||||
r1.Get("codigo")
|
||||
' Log(listaWayPoints.Get(r) & "|" & r1.Get("coords") & "|" & r1.Get("calle"))
|
||||
wps = listaWayPoints.Get(r)
|
||||
Starter.skmt.ExecNonQuery2("insert into waypoints values (?,?)", Array As Object(r1.Get("codigo"), wps.get("waypoint_index")))
|
||||
r = r + 1
|
||||
Next
|
||||
ListView1.Clear
|
||||
Sleep(100)
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 15
|
||||
label2.Height = 100dip
|
||||
ListView1.TwoLinesLayout.ItemHeight = 70dip
|
||||
Dim cs, cs2 As CSBuilder
|
||||
entro = 3
|
||||
Log("Generamos ListView1 en traeRutaDia")
|
||||
'Traemos las visitas restantes ordenadas por el indice de waypoints (este indice nos indica el orden en la ruta calculada).
|
||||
c=Starter.skmt.ExecQuery("select codigo, indice, CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_NOEXT from waypoints inner join kmt_info on waypoints.codigo = kmt_info.CAT_CL_CODIGO where gestion = 0 order by indice")
|
||||
If c.RowCount > 0 Then
|
||||
For i=0 To c.RowCount -1 'Generamos el listView con la lista ordenada.
|
||||
c.Position=i
|
||||
cs.Initialize
|
||||
cs2.Initialize
|
||||
ListView1.AddTwoLines(cs.Color(Colors.RGB(100,149,237)).Append(c.GetString("codigo")).PopAll, cs2.append(c.GetString("CAT_CL_NOMBRE")).Color(Colors.RGB(100,149,237)).Append(" Calle: ").Pop.Append(c.GetString("CAT_CL_CALLE").Trim & " " & c.GetString("CAT_CL_NOEXT")).PopAll )
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
End Sub
|
||||
|
||||
'Calcula distancia y tiempo de la ubicacion ACTUAL a las 8 primeras tiendas de la lista usando el API de OSRM. (Parte de la funcionalidad OSRM)
|
||||
Private Sub b_GetDirs_Click
|
||||
ProgressDialogShow("Calculando distancias y tiempos ...")
|
||||
Private m2 As Map
|
||||
Private f As Int = 0
|
||||
For Each k As Object In distOrderedMap.Keys 'Traemos la distancia y tiempo desde OSRM (2 puntos)
|
||||
m2 = distOrderedMap.Get(k)
|
||||
Private distancia2 As String = m2.Get("distancia")
|
||||
Private thisLoc1 As String = m2.Get("ubicacion")
|
||||
Private locActual As String = Tracker.UUGCoords.Longitude&","&Tracker.UUGCoords.Latitude
|
||||
If locActual = "0,0" Then 'Si no tenemos ubicacion actual de GPS, buscamos la ultima guardada en la base de datos.
|
||||
c = Starter.skmt.ExecQuery("select * from hist_gps")
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
locActual = c.GetString("hglon") & "," & c.GetString("hglat")
|
||||
End If
|
||||
c.Close
|
||||
End If
|
||||
f = f+1
|
||||
If f < 8 Then
|
||||
If locActual = "0,0" Then 'Si todavia no tenemos ubicacion actual, entonces avisamos.
|
||||
ToastMessageShow("No se pudo obtener la ubicacion actual!!", True)
|
||||
f = 8
|
||||
End If
|
||||
Log($"locActual: ${locActual}, thisLoc1: ${thisLoc1}"$)
|
||||
Wait For(distanciaEntreCoords(distancia2, locActual, thisLoc1)) Complete (r As List)
|
||||
LogColor($"R: ${r.Get(0)} - ${r.Get(1)} - ${r.Get(2)}"$, Colors.Green)
|
||||
Private tId As Int = r.Get(0)
|
||||
Private tMap As Map = distOrderedMap.Get(tId)
|
||||
LogColor("|" & tId & "| - " &distOrderedMap.Get(tId), Colors.Blue)
|
||||
Private tempNDD As String = tMap.Get("nomDirDist")
|
||||
Private indexD As Int = tempNDD.IndexOf("Distancia:")
|
||||
If indexD > -1 Then tempNDD = tempNDD.SubString2(0, indexD)
|
||||
Log(tempNDD)
|
||||
tempNDD = tempNDD & $"Dist: $1.1{(r.Get(1)/1000)} kms, Tiempo aprox: $1.0{((r.Get(2)*2)/60)} min."$ 'Multiplicamos el tiempo X 2 porque el tiempo estimado siempre es muy corto, X2 es mucho mas real con trafico.
|
||||
Private esteCliente As Map = CreateMap("distancia": distancia2, "ubicacion": tMap.Get("ubicacion"), "codigo": tMap.Get("codigo"), "nomDirDist": tempNDD)
|
||||
distOrderedMap.Put(tId, esteCliente)
|
||||
ListView1.Clear
|
||||
Private m3 As Map
|
||||
For Each k As Object In distOrderedMap.Keys 'Generamos el listView con la lista ordenada.
|
||||
m3 = distOrderedMap.Get(k)
|
||||
m3.Get("codigo")
|
||||
ListView1.AddTwoLines(m3.Get("codigo"), m3.Get("nomDirDist"))
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
ProgressDialogHide
|
||||
End Sub
|
||||
|
||||
'Regresa un mapa (B4XOrderedMap) con todos los clientes que tiene que visitar el repartidor. (Parte de la funcionalidad OSRM)
|
||||
Sub traeTodosAVisitar As B4XOrderedMap 'ignore
|
||||
Log("Iniciamos traeTodosAVisitar")
|
||||
' If Starter.waypointsOrdered.isInitialized Then Log(Starter.waypointsOrdered.Size)
|
||||
' Private rutaCompleta As String = ""
|
||||
Private thisLoc, ubicacionInicial As Location
|
||||
ubicacionInicial = Starter.cedisLocation
|
||||
LogColor(ubicacionInicial, Colors.Gray)
|
||||
c=Starter.skmt.ExecQuery("select sum(gestion) as hayVisitados from kmt_info")
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
' Log(c.GetString("hayVisitados"))
|
||||
If c.GetString("hayVisitados") > 0 Then ubicacionInicial = Tracker.UUGCoords 'Si ya hay clientes visitados, entonces ya no estamos en el CEDIS y la ubicacion inicial debe de ser la ACTUAL.
|
||||
End If
|
||||
c.Close
|
||||
LogColor(ubicacionInicial, Colors.Red)
|
||||
thisLoc.Initialize
|
||||
clientesMapaO.Clear
|
||||
'Traemos las rutas asignadas al repartidor.
|
||||
c=Starter.skmt.ExecQuery("select CAT_CL_RUTA, count(*) as cuantos from kmt_info where gestion = 0 group by CAT_CL_RUTA order by CAT_CL_RUTA asc")
|
||||
If c.RowCount>0 Then
|
||||
'Traemos los clientes de cada ruta.
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
' Log($"Renglones ruta: ${c.RowCount} - i=${i} - Ruta: ${c.GetString("CAT_CL_RUTA")}"$)
|
||||
c2=Starter.skmt.ExecQuery2("select CAT_CL_NOMBRE, CAT_CL_CALLE, CAT_CL_CODIGO, CAT_CL_LAT, CAT_CL_LONG from kmt_info where CAT_CL_RUTA = ? and gestion = 0 order by CAT_CL_NOMBRE ", Array As String(c.GetString("CAT_CL_RUTA")))
|
||||
If c2.RowCount>0 Then
|
||||
For j=0 To c2.RowCount -1 'Generamos lista de clientes
|
||||
c2.Position=j
|
||||
' Log($"Renglones clientes: ${c2.RowCount} - j=${j} - Ruta: ${c2.GetString("CAT_CL_CODIGO")}"$)
|
||||
thisLoc.Latitude = c2.GetString("CAT_CL_LAT")
|
||||
thisLoc.Longitude = c2.GetString("CAT_CL_LONG")
|
||||
If Not(thisLoc.Latitude = 0.0) And Not(thisLoc.Latitude = 0) Then 'Este IF es para que si las coordenadas no son válidas, entonces no las agregue al mapeo, porque el API de OSRM nos manda error.
|
||||
Private distancia As Int = ubicacionInicial.DistanceTo(thisLoc) 'Calculamos la distancia del cedis a la tienda.
|
||||
If clientesMapaO.ContainsKey(distancia) Then distancia = distancia + 1 'Si por alguna extraña razon hay dos tiendas a la misma distancia del CEDIS, le sumamos 1 para que sea diferente.
|
||||
Private esteCliente As Map = CreateMap("distancia": distancia, "ordenDist": j, "coords": c2.GetString("CAT_CL_LONG")&","&c2.GetString("CAT_CL_LAT"), "codigo": c2.GetString("CAT_CL_CODIGO"), "nombre": c2.GetString("CAT_CL_NOMBRE"), "calle": c2.GetString("CAT_CL_CALLE"))
|
||||
clientesMapaO.Put(distancia, esteCliente)
|
||||
Else
|
||||
ToastMessageShow("Hay tiendas SIN coordenadas, fueron excluidas!!", False)
|
||||
End If
|
||||
' Log($"${thisLoc}"$)
|
||||
' rutaCompleta = rutaCompleta & ";" & c2.GetString("CAT_CL_LONG")&","&c2.GetString("CAT_CL_LAT")
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
clientesMapaO.Keys.Sort(True) 'Ordenamos la lista de clientes por distancia.
|
||||
c.Close
|
||||
c2.Close
|
||||
Log(c.RowCount & " rutas, " & clientesMapaO.Size & " clientes")
|
||||
' LogColor(rutaCompleta, Colors.Magenta)
|
||||
' Log(clientesMapaO)
|
||||
Return clientesMapaO
|
||||
End Sub
|
||||
|
||||
'Traemos la ruta de visitas via el API de OSRM usando el sub "traeRutaDia(traeTodosAVisitar)".
|
||||
Private Sub b_getRutaInfo_Click
|
||||
traeRutaDia(traeTodosAVisitar)
|
||||
End Sub
|
||||
|
||||
'Mostramos u ocultamos el boton para borrar los waypoints de la ruta.
|
||||
Private Sub b_getRutaInfo_LongClick
|
||||
If b_limpiarRuta.Visible Then
|
||||
b_limpiarRuta.Visible = False
|
||||
Else
|
||||
b_limpiarRuta.Visible = True
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Borramos los waypoints de la ruta.
|
||||
Private Sub b_limpiarRuta_Click
|
||||
Starter.skmt.ExecNonQuery("delete from waypoints")
|
||||
b_limpiarRuta.Visible = False
|
||||
B4XPage_Appear
|
||||
End Sub
|
||||
611
B4A/C_DetalleVenta.bas
Normal file
@@ -0,0 +1,611 @@
|
||||
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
|
||||
Dim g As GPS
|
||||
Dim clie_id As String
|
||||
Dim sDate,sTime As String
|
||||
Dim usuario As String
|
||||
Dim c As Cursor
|
||||
' Dim ruta As String
|
||||
Dim b_regresar As Button
|
||||
Dim ListView1 As ListView
|
||||
Dim L_CANT As Label
|
||||
Dim L_TOTAL As Label
|
||||
Dim b_borra As Button
|
||||
Dim Existe As String
|
||||
Dim result As String
|
||||
' Dim lat_gps, lon_gps As String
|
||||
Dim cuantos As String
|
||||
Dim nombre_prod As String
|
||||
Dim cuantos_pedido As String
|
||||
Private Titulo As Label
|
||||
Private P1 As Panel
|
||||
Private lv2 As ListView
|
||||
Private p_principal As Panel
|
||||
Dim clv_pedido As CustomListView
|
||||
Private p_prods As Panel
|
||||
Private l_prodX As Label
|
||||
Private l_pCant As Label
|
||||
Private et_pCant As EditText
|
||||
Dim bmp As Bitmap
|
||||
Dim etCantHasFocus As Boolean = False
|
||||
Dim totalProds As Int = 0
|
||||
Dim totalCompra As Int = 0
|
||||
Dim prodsMap As Map
|
||||
Dim reconstruirPedido As Boolean = False
|
||||
Dim promoABorrar As String
|
||||
Private b_guardar As Button
|
||||
Private b_prodMas As Button
|
||||
Private b_prodMenos As Button
|
||||
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
|
||||
B4XPages.SetTitle(Me, "Detalle de venta")
|
||||
'load the layout to Root
|
||||
g.Initialize("GPS")
|
||||
Root.LoadLayout("detalleVenta")
|
||||
b_borra.Visible = False
|
||||
Titulo.Text = "Pedido"
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
Subs.centraPanel(p_principal, Root.Width)
|
||||
' b_guardar.Visible = False
|
||||
|
||||
' Titulo.Left = Round(p_principal.Width/2)-(Titulo.Width/2)
|
||||
L_CANT.Text =""
|
||||
L_TOTAL.Text=""
|
||||
c=Starter.skmt.ExecQuery("select count(*) as EXISTE from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ")
|
||||
C.Position=0
|
||||
Existe = C.GetString("EXISTE")
|
||||
C.Close
|
||||
' c=Starter.skmt.ExecQuery("select distinct hist_ventas.hvd_num_registro, HIST_VENTAS.HVD_CLIENTE, HIST_VENTAS.HVD_PRONOMBRE, HIST_VENTAS.HVD_PROID, HIST_VENTAS.HVD_CANT, HIST_VENTAS2.HVD_CANT as HVD_CANT2, HIST_VENTAS.HVD_COSTO_TOT, HIST_VENTAS.HVD_CODPROMO from HIST_VENTAS inner join HIST_VENTAS2 on HIST_VENTAS.HVD_PROID = HIST_VENTAS2.HVD_PROID and HIST_VENTAS.HVD_CLIENTE = HIST_VENTAS2.HVD_CLIENTE WHERE HIST_VENTAS.HVD_CLIENTE IN (Select CUENTA from cuentaa) and HIST_VENTAS.HVD_RECHAZO = 0 order by HIST_VENTAS.HVD_CODPROMO desc, HIST_VENTAS.HVD_PRONOMBRE asc")
|
||||
c=Starter.skmt.ExecQuery("select hvd_num_registro, HVD_CLIENTE, HVD_PRONOMBRE, HVD_PROID, HVD_CANT, HVD_COSTO_TOT, HVD_CODPROMO from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 and hvd_cant > 0 order by HVD_CODPROMO desc, HVD_PRONOMBRE asc")
|
||||
ListView1.Clear
|
||||
clv_pedido.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
clv_pedido.GetBase.SetLayoutAnimated(100, 0dip, 60dip, Root.Width - 50, Root.Height * 0.62) 'Cambiamos el tamaño y posición de la lista de productos
|
||||
clv_pedido.Base_Resize(clv_pedido.GetBase.Width, clv_pedido.GetBase.Height) 'Cambiamos el tamaño del panel interno de la lista para que ajuste al nuevo tamaño.
|
||||
' Log("RC1:"&c.RowCount)
|
||||
If c.RowCount>0 Then
|
||||
' Log("Usamos HV")
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
'Traemos cantidad de hvd2
|
||||
Private oc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT from HIST_VENTAS2 WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and hvd_proid = '${c.GetString("HVD_PROID")}' and HVD_NUM_REGISTRO = '${c.GetString("HVD_NUM_REGISTRO")}'"$)
|
||||
Private cant2 As Int = 0
|
||||
If oc.RowCount > 0 Then
|
||||
oc.Position = 0
|
||||
cant2 = oc.GetString("HVD_CANT")
|
||||
End If
|
||||
oc.Close
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 12
|
||||
label1.TextColor = Colors.black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 12
|
||||
label2.TextColor = Colors.black
|
||||
Private bgColor, textColor As Int
|
||||
bgColor = Colors.RGB(177, 200, 249)'azul
|
||||
textColor = Colors.black
|
||||
If c.GetString("HVD_CODPROMO") <> "1" Then
|
||||
' bgColor = Colors.RGB(255, 212, 163) 'naranja
|
||||
bgColor = Colors.White
|
||||
End If
|
||||
' Log($"Agregamos prod a lista1 | ${c.GetString("HVD_CANT")} - ${c.GetString("HVD_CANT2")}"$) 'HVD_CANT2 es la original de la orden.
|
||||
' ListView1.AddTwoLines(c.GetString("HVD_PRONOMBRE"),"Cantidad #"& c.GetString("HVD_CANT")& " SubTotal $"& c.GetString("HVD_COSTO_TOT"))
|
||||
clv_pedido.Add(CreateListItem(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), c.GetString("HVD_CANT"), 0, clv_pedido.AsView.Width, 50dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),Subs.traeCliente), c.GetString("HVD_PRONOMBRE"))
|
||||
Next
|
||||
' cuentaProds("")
|
||||
End If
|
||||
'Traemos lo vendido
|
||||
Private vc As Cursor = Starter.skmt.ExecQuery("select * from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE")
|
||||
' Log($"VENTA: ${vc.RowCount}"$)
|
||||
If vc.RowCount > 0 Then
|
||||
' Log("Usamos REPARTO")
|
||||
' bgColor = Colors.RGB(248,113,113)
|
||||
textColor = Colors.RGB(0,87,142)
|
||||
For i=0 To vc.RowCount -1
|
||||
vc.Position = i
|
||||
Private cantCO As Int = 0
|
||||
'Traemos la cantidad disponible del cliente original
|
||||
Private cco As Cursor = Starter.skmt.ExecQuery($"select * from REPARTO where REP_CLIENTE = '${vc.GetString("REP_CLI_ORIG")}' and REP_CLI_ORIG = '${vc.GetString("REP_CLI_ORIG")}' and REP_PRODID='${vc.GetString("REP_PRODID")}' and REP_RECHAZO = '1' and REP_CANT > 0"$)
|
||||
|
||||
If cco.RowCount > 0 Then
|
||||
cco.Position = 0
|
||||
cantCO = cco.GetString("REP_CANT") + vc.GetString("REP_CANT")
|
||||
End If
|
||||
cantCO = Subs.traeCantidadRechazada(vc.GetString("REP_CLI_ORIG"), vc.GetString("REP_PRODID"))
|
||||
|
||||
' Log($"${vc.GetString("REP_CLI_ORIG")}, ${vc.GetString("REP_CLIENTE")}, ${vc.GetString("REP_PRODID")}, ${vc.GetString("REP_PRONOMBRE")}, ${vc.GetString("REP_RECHAZO")}, ${vc.GetString("REP_CANT")}, ${vc.GetString("REP_PRECIO")}, ${cantCO}, ${cco.GetString("REP_CANT")}, ${vc.GetString("REP_CANT")}"$)
|
||||
clv_pedido.Add(CreateListItem(vc.GetString("REP_PRONOMBRE"), Subs.traePrecio(vc.GetString("REP_PRODID"), 1), vc.GetString("REP_CANT"), cantCO, clv_pedido.AsView.Width, 50dip, bmp, vc.GetString("REP_PRODID"), bgColor, textColor, 1, vc.GetString("REP_CLI_ORIG")), vc.GetString("REP_PRONOMBRE"))
|
||||
Next
|
||||
cco.Close
|
||||
vc.Close
|
||||
End If
|
||||
|
||||
If Existe <> 0 Then
|
||||
c = Starter.skmt.ExecQuery("select SUM(HVD_CANT) AS PC_NOART, SUM(HVD_COSTO_TOT) AS PC_MONTO from HIST_VENTAS where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ")
|
||||
C.Position=0
|
||||
L_CANT.Text = c.GetString("PC_NOART")
|
||||
L_TOTAL.Text = Round2(c.GetString("PC_MONTO"), 2)
|
||||
End If
|
||||
c=Starter.skmt.ExecQuery("select count(*) as EXISTE from PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
c.Position=0
|
||||
Existe = C.GetString("EXISTE")
|
||||
c.Close
|
||||
' c=Starter.skmt.ExecQuery("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc")
|
||||
'ListView1.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
' Log("RC2:" & c.RowCount)
|
||||
' If c.RowCount > 0 Then
|
||||
' For i=0 To c.RowCount -1
|
||||
' c.Position=i
|
||||
' Dim label1 As Label
|
||||
' label1 = ListView1.TwoLinesLayout.Label
|
||||
' label1.TextSize = 12
|
||||
' label1.TextColor = Colors.White
|
||||
' Dim label2 As Label
|
||||
' label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
' label2.TextSize = 12
|
||||
' label2.TextColor = Colors.White
|
||||
' Log("Agegamos prod a lista 2")
|
||||
' ListView1.AddTwoLines("VENTA" & c.GetString("PE_PRONOMBRE"),"Cantidad #"& c.GetString("PE_CANT")& " SubTotal $"& c.GetString("PE_COSTO_TOT"))
|
||||
' 'folio = c.GetString("PE_FOLIO")
|
||||
' Next
|
||||
' End If
|
||||
If Existe <> 0 Then
|
||||
c=Starter.skmt.ExecQuery("select SUM(PE_CANT) AS PE_CANT, SUM(PE_COSTO_TOT) AS PE_COSTO_TOT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
C.Position=0
|
||||
L_CANT.Text = L_CANT.Text + c.GetString("PE_CANT")
|
||||
L_TOTAL.Text = Round2(L_TOTAL.Text + c.GetString("PE_COSTO_TOT"), 2)
|
||||
End If
|
||||
'la_no_ird.Text = c.GetString("PR_CF_SALDO_ACORT")
|
||||
' cuentaProds("")
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Location1 As Location)
|
||||
' lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
|
||||
' lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
|
||||
End Sub
|
||||
|
||||
Sub b_regresar_Click
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' BACK key pressed
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Cliente")
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
Sub ListView1_ItemLongClick (Position As Int, Value As Object) 'BORRAR
|
||||
' nombre_prod = Value
|
||||
' result = Msgbox2("Seguro que desa borrar este articulo?","Borrar Articulo", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
|
||||
' If result = DialogResponse.POSITIVE Then
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' c.Position=0
|
||||
' If c.GetString("HVD_CANT") > 1 Then
|
||||
' b_regresar.Visible =False
|
||||
' b_borra.Visible=False
|
||||
' P1.Visible =True
|
||||
' cuantos_pedido = c.GetString("HVD_CANT")
|
||||
' lv2.Clear
|
||||
' lv2.SingleLineLayout.Label.TextColor = Colors.Black
|
||||
' For i=1 To c.GetString("HVD_CANT")
|
||||
' lv2.AddSingleLine(i)
|
||||
' Next
|
||||
' Else
|
||||
' ' skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
|
||||
' c.Close
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT,REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' c.Position=0
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
|
||||
' c.Close
|
||||
'
|
||||
' 'skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' ' se cambia por update para no borrarlo y tener todos los registros.
|
||||
' Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
'
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' 'quitar esta mamada no es ahi
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' B4XPage_Appear
|
||||
' End If
|
||||
'
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub lv2_ItemClick (Position As Int, Value As Object) 'BORRAR
|
||||
' ' If Value = "Todos" Then
|
||||
' ' cuantos = c.GetString("HVD_CANT")
|
||||
' 'Else
|
||||
' cuantos = Value
|
||||
' ' End If
|
||||
' If cuantos = cuantos_pedido Then
|
||||
' 'Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
|
||||
' c.Close
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(nombre_prod))
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(nombre_prod))
|
||||
' c.Position=0
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
|
||||
' c.Close
|
||||
' 'Starter.skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' ' se cambia por update para no borrarlo y tener todos los registros.
|
||||
' Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' 'quitar esta m*m*d* no es ahi
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_RECHAZO = 1, HVD_PARCIAL = 0, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos, nombre_prod))
|
||||
' b_regresar.Visible =True
|
||||
' b_borra.Visible=True
|
||||
' P1.Visible =False
|
||||
' B4XPage_Appear
|
||||
' Else
|
||||
' ' skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
|
||||
' c.Close
|
||||
'
|
||||
' 'modificar tambien esto
|
||||
' 'Modificaciones para que solo quite una parte.
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, ?, ? * (HVD_COSTO_TOT/?), HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos,cuantos,cuantos_pedido, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("insert into hist_ventas(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, HVD_RECHAZO, HVD_ESTATUS, HVD_PARCIAL) select HVD_CLIENTE,HVD_PRONOMBRE,?,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, 1, HVD_ESTATUS, 1 from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_RECHAZO = 0, HVD_PARCIAL = 1, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_COSTO_TOT = HVD_CANT * (HVD_COSTO_TOT/?) where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos_pedido, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
|
||||
' 'crear nueva tabla para que guarde el resto.
|
||||
'' skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' B4XPage_Appear
|
||||
' b_regresar.Visible =True
|
||||
' b_borra.Visible=True
|
||||
' P1.Visible =False
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
'****************************************************************************
|
||||
'***************** PARA EL MAS/MENOS *************************************
|
||||
'****************************************************************************
|
||||
|
||||
Sub CreateListItem(Text As String, precioU As String, inv As Int, inv2 As Int, Width As Int, Height As Int, img As Bitmap, prodId As String, bc As Int, tc As Int, promo As String, cliente_original As String) As Panel
|
||||
Dim p As B4XView = xui.CreatePanel("")
|
||||
Private cs As CSBuilder
|
||||
cs.Initialize
|
||||
p.SetLayoutAnimated(0, 0, 0, Width, Height)
|
||||
p.LoadLayout("prodItem")
|
||||
p_prods.Color = bc
|
||||
l_prodX.TextColor = tc
|
||||
precioU = $"$1.2{precioU}"$
|
||||
l_prodX.Text = Text&CRLF&"Cant: " & inv2 & " $" & precioU
|
||||
If promo <> "1" And precioU = 0 Then
|
||||
l_prodX.Text = cs.Color(Colors.RGB(123,0,0)).append(Text&CRLF&"Cant: " & inv2 & " $" & precioU).PopAll
|
||||
End If
|
||||
l_prodX.Tag = $"ID: ${prodId}${CRLF}${Text}${CRLF}Precio: $$1.2{precioU}${CRLF}Inv: ${inv} pzs"$
|
||||
' l_pCant.Text = 0
|
||||
l_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
|
||||
et_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
|
||||
p_prods.Tag = l_pCant.tag
|
||||
' Log($"Ponemos la cant en ${inv}"$)
|
||||
l_pCant.Text = inv
|
||||
' et_pCant.Text = inv
|
||||
' et_pCant.BringToFront
|
||||
|
||||
l_pCant.BringToFront
|
||||
et_pCant.SendToBack
|
||||
|
||||
' i_prod.Bitmap = img
|
||||
Return p
|
||||
End Sub
|
||||
|
||||
Sub b_prodMenos_Click
|
||||
etCantHasFocus = False
|
||||
Log("etCantHasFocus=" & etCantHasFocus)
|
||||
LogColor("b_prodMenos_Click", Colors.Magenta)
|
||||
Dim index As Int = clv_pedido.GetItemFromView(Sender)
|
||||
Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
|
||||
Dim pnl As B4XView = pnl0.GetView(0)
|
||||
Dim laCant As B4XView = pnl.GetView(2).GetView(3)
|
||||
' Log(pnl.GetView(2).GetView(0) & "|" & pnl.GetView(2).GetView(1) & "|" & pnl.GetView(2).GetView(2))
|
||||
Dim esteTag As List = Regex.Split("\|", laCant.Tag)
|
||||
Log("LC_TEXT:"&laCant.Text&"|PROMO:"&esteTag.Get(3)&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
|
||||
If esteTag.Get(3) <> "1" Then 'Si es PROMO entonces ...
|
||||
Log("ES PROMO")
|
||||
result = Msgbox2("Si se modifica una promoción, la promoción se rompe y solo quedarán los productos sueltos, ¿seguro que desea continuar?","Modificar Promoción", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
|
||||
If result = DialogResponse.POSITIVE Then 'Quitamos esta promo
|
||||
prodsMap.Remove(esteTag.Get(3))
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PROID = '${esteTag.Get(3)}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_CODPROMO = 1 WHERE HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
LogColor(prodsMap, Colors.red)
|
||||
reconstruirPedido = True
|
||||
promoABorrar = esteTag.Get(3)
|
||||
B4XPage_Appear
|
||||
End If
|
||||
Else
|
||||
If laCant.Text = "" Then laCant.Text = 0
|
||||
laCant.Text = $"$1.0{laCant.Text-1}"$
|
||||
If laCant.Text < 0 Then laCant.Text = 0
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
|
||||
End If
|
||||
Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
|
||||
Log("PU: " & preciou)
|
||||
' LogColor("estamos aqui mmenos " & laCant.Text& " , " & (preciou * laCant.Text),Colors.Green )
|
||||
' If L_CANT.Text - 1 >= 0 Then
|
||||
' L_CANT.Text = L_CANT.Text - 1
|
||||
' End If
|
||||
' b_guardar.Visible = True
|
||||
Subs.prodRechazo(esteTag.Get(5), esteTag.Get(2))
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
' cuentaProds("-")
|
||||
End Sub
|
||||
|
||||
Sub b_prodMas_Click
|
||||
etCantHasFocus = False
|
||||
' Log("etCantHasFocus=" & etCantHasFocus)
|
||||
LogColor("b_prodMas_Click", Colors.Magenta)
|
||||
Dim index As Int = clv_pedido.GetItemFromView(Sender)
|
||||
Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
|
||||
Dim pnl As B4XView = pnl0.GetView(0)
|
||||
Dim laCant As B4XView = pnl.GetView(2).GetView(3)
|
||||
' Log(pnl.GetView(2).GetView(1).text&"|"&pnl.GetView(2).GetView(2)&"|"&pnl.GetView(2).GetView(4).text)
|
||||
' Log($"precio|stock:${laCant.tag}"$)
|
||||
' Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
|
||||
Dim esteTag As List = Regex.Split("\|", laCant.Tag)
|
||||
Log("LC_TEXT:"&laCant.Text&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
|
||||
If laCant.Text = "" Then laCant.Text = 0
|
||||
|
||||
Private maxProds = esteTag.Get(1) + esteTag.Get(4) 'Prods disponibles + prods comprados
|
||||
|
||||
LogColor($"++++++++++++++++++++++++++ ${esteTag}"$, Colors.Green)
|
||||
' Log(esteTag.get(4))
|
||||
If laCant.Text + 1 <= maxProds Then
|
||||
Log($"NuevaCant = ${laCant.Text + 1}"$)
|
||||
laCant.Text = $"$1.0{laCant.Text + 1}"$
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen - 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
|
||||
|
||||
Subs.prodVenta(esteTag.Get(5), esteTag.Get(2))
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
' cuentaProds("+")
|
||||
End If
|
||||
' Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
|
||||
' Log(preciou)
|
||||
' LogColor("estamos aquii mas " & laCant.Text& " , " & (preciou * laCant.Text) ,Colors.Green )
|
||||
' b_guardar.Visible = True
|
||||
' Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
|
||||
' c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS2 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID = '${esteTag.Get(2)}' "$)
|
||||
' c.Position = 0
|
||||
' Dim cantoriginal As String = 0
|
||||
' If c.RowCount > 0 Then
|
||||
' cantoriginal = c.GetString("HVD_CANT")
|
||||
' End If
|
||||
' If cantoriginal <= esteTag.Get(1) Then
|
||||
' L_CANT.Text = L_CANT.Text + 1
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub cuentaProds(accion As String)
|
||||
' Log("Entramos a cuentaProds")
|
||||
Log("*******************************************************")
|
||||
Private cantRechazada As Int = 0
|
||||
If Not(reconstruirPedido) Then
|
||||
Log("*********** CUENTAPRODS - NO RECONSTRUIR")
|
||||
prodsMap.Initialize
|
||||
For i = 0 To clv_pedido.GetSize - 1
|
||||
Private p0 As B4XView = clv_pedido.GetPanel(i)
|
||||
Private p As B4XView = p0.GetView(0)
|
||||
Private cant1 As B4XView = p.GetView(2).GetView(3)
|
||||
If cant1.Text = "" Then cant1.Text = 0
|
||||
' totalProds = totalProds + cant1.Text
|
||||
Private esteTag As List = Regex.Split("\|", cant1.Tag)
|
||||
Log("-------------------------------------")
|
||||
Log($"ET: ${esteTag}"$)
|
||||
Private esteProd As String = esteTag.Get(2)
|
||||
Private estaCant As Int = cant1.Text
|
||||
Private estaCantOriginal As Int = esteTag.Get(1)
|
||||
Private esteCliente = Subs.traeCliente
|
||||
Private esteProdNombre = Subs.traeNombre(esteProd)
|
||||
Private esteClienteOriginal As Int = esteTag.Get(5)
|
||||
Private fechaReparto As String = Subs.traeFechaReparto
|
||||
Private maxProds = Subs.traeMaxCantidad(esteTag.Get(5), esteTag.Get(2))
|
||||
|
||||
If cant1.Text > maxProds Then cant1.Text = maxProds
|
||||
|
||||
cantRechazada = esteTag.Get(4) - cant1.Text
|
||||
' If accion = "-" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) + 1
|
||||
' If accion = "+" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) - 1
|
||||
Log($"${Subs.traeCantidadRechazada(esteClienteOriginal, esteProd)}, ${Subs.traeCantidadVendida(esteClienteOriginal, esteProd)}"$)
|
||||
|
||||
' LogColor($"cantRechazada = ${esteTag.Get(4)} - ${cant1.Text}"$, Colors.Magenta)
|
||||
LogColor($"cantRechazada = ${cantRechazada}"$, Colors.Magenta)
|
||||
Private estePrecio As String = 0
|
||||
If Subs.traePrecio(esteProd, 1) <> Null Then estePrecio = Subs.traePrecio(esteProd, 1) * cantRechazada
|
||||
|
||||
' LogColor(esteProd & "|" & cant1.Text & "|" & estaCantOriginal & "|" & cantRechazada & "|" & estePrecio, Colors.red)
|
||||
' LogColor($"cantRechazada=${cantRechazada} | ${esteProdNombre}"$, Colors.Blue)
|
||||
' Log($"Ponemos HVD_CANT ${esteProd} en ${cant1.text}"$)
|
||||
Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = ? WHERE HVD_PROID = ? and HVD_CLIENTE in (Select CUENTA from cuentaa)", Array As String(cant1.Text ,esteProd))
|
||||
Private rr As Cursor = Starter.skmt.ExecQuery($"select count(REP_CLIENTE) as hayRechazo from REPARTO where rep_prodid = '${esteProd}' and REP_CLIENTE in (Select CUENTA from cuentaa)"$)
|
||||
rr.Position = 0
|
||||
' Log($"HayRechazo=${rr.GetString("hayRechazo")}"$)
|
||||
If rr.GetString("hayRechazo") = 0 Then
|
||||
Log("INSERTAMOS EN REPARTO")
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?) ", Array As String(esteCliente, esteProdNombre, 0, estePrecio, fechaReparto, esteProd, estePrecio, esteCliente))
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?) ", Array As String(esteCliente, esteProdNombre, cantRechazada, 0, fechaReparto, esteProd, estePrecio, esteCliente))
|
||||
Else if esteClienteOriginal = "0" Then 'Actualizamos el rechazo en el cliente actual.
|
||||
' Log($"Actualizamos REP_CANT=${cantRechazada}"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cantRechazada}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
|
||||
Else 'Cliente original <> 0 entonces actualizamos el rechazo en el cliente original y NO en el actual.
|
||||
Log($"Actualizamos REP_CANT RECHAZO = ${cantRechazada}"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = ${cantRechazada}, REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE = '${esteClienteOriginal}' and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cant1.Text}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${esteProd}'"$)
|
||||
End If
|
||||
|
||||
If cant1.Text > 0 Then
|
||||
' totalCompra = totalCompra + (esteTag.get(0) * cant1.text)
|
||||
' Log($"Cant: ${cant1.Text}, Suma: ${totalCompra}"$)
|
||||
Private m As Map
|
||||
m=CreateMap("cant":cant1.Text, "cant2":esteTag.get(4), "precio":esteTag.get(0), "promo":esteTag.get(3), "nombre":Subs.traeNombre(esteTag.Get(2)), "cli_orig":esteTag.get(5))
|
||||
' LogColor("PUT:" & esteTag.Get(2), Colors.Red)
|
||||
prodsMap.Put(esteTag.Get(2), m)
|
||||
End If
|
||||
Log("-------------------------------------")
|
||||
Next
|
||||
End If
|
||||
Private bgColor, textColor As Int
|
||||
|
||||
If reconstruirPedido Then
|
||||
Log("*********** CUENTAPRODS - SI RECONSTRUIR")
|
||||
Private newPromo, newPrecio As String
|
||||
clv_pedido.Clear
|
||||
Log("Usamos PRODSMAP")
|
||||
For Each pr As String In prodsMap.Keys
|
||||
Private pr1 As Map = prodsMap.Get(pr)
|
||||
Log("PPP: " & pr & "|PromoABorrar=" & promoABorrar & "|" & pr1)
|
||||
bgColor = Colors.RGB(177, 200, 249)'azul
|
||||
textColor = Colors.black
|
||||
newPromo = pr1.Get("promo")
|
||||
newPrecio = pr1.Get("precio")
|
||||
Log("AAA: " & newPromo & "|" & promoABorrar)
|
||||
If newPromo = promoABorrar Then
|
||||
newPromo = 1
|
||||
newPrecio = Subs.traePrecio(pr, False) * pr1.Get("cant")
|
||||
'Ponemos precio SIN promo y sacamos el producto de la promo.
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_COSTO_TOT = ${newPrecio}, HVD_CODPROMO = 1 WHERE HVD_PRONOMBRE = '${pr1.Get("nombre")}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
LogColor("CAMBIAMOS PROMO: " & newPromo, Colors.Magenta)
|
||||
End If
|
||||
If newPromo <> "1" Then
|
||||
' bgColor = Colors.RGB(255, 212, 163) 'naranja
|
||||
bgColor = Colors.White
|
||||
End If
|
||||
Log($"CLI: ${pr1.Get("nombre")}, ${newPrecio}, ${pr1.Get("cant")}, ${pr1.Get("cant2")}"$)
|
||||
clv_pedido.Add(CreateListItem(pr1.Get("nombre"), newPrecio, pr1.Get("cant"), pr1.Get("cant2"), clv_pedido.AsView.Width, 50dip, bmp, pr, bgColor, textColor, newPromo, pr1.Get("cli_orig")), pr1.Get("nombre"))
|
||||
reconstruirPedido = False
|
||||
Next
|
||||
promoABorrar = ""
|
||||
End If
|
||||
Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
|
||||
LogColor("prodsMap=" & prodsMap, Colors.Green)
|
||||
|
||||
|
||||
LogColor(prodsMap, Colors.Blue)
|
||||
c = Starter.skmt.ExecQuery($"SELECT sum(HVD_CANT) as CANTIDAD FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)"$)
|
||||
Dim cantidad1 As String = 0
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
cantidad1 = c.GetString("CANTIDAD")
|
||||
L_CANT.Text = Round(cantidad1)
|
||||
End If
|
||||
c.Close
|
||||
|
||||
Dim totalfinal As String = 0
|
||||
For Each pr As String In prodsMap.Keys
|
||||
Private pr1 As Map = prodsMap.Get(pr)
|
||||
' LogColor(pr,Colors.Red)
|
||||
Dim x As Cursor = Starter.skmt.ExecQuery($"SELECT CAT_GP_PRECIO FROM CAT_GUNAPROD WHERE CAT_GP_ID = '${pr}'"$)
|
||||
c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID ='${pr}' "$)
|
||||
Dim cantidady As String = 0
|
||||
If c.RowCount >0 Then
|
||||
c.Position = 0
|
||||
cantidady = c.GetString("HVD_CANT")
|
||||
End If
|
||||
' Log(x.RowCount)
|
||||
If x.RowCount > 0 Then
|
||||
x.Position = 0
|
||||
' Log(x.GetString("CAT_GP_PRECIO"))
|
||||
Dim preciou As String = x.GetString("CAT_GP_PRECIO")
|
||||
Dim costototalhist As String = preciou * cantidady
|
||||
' Log("Total ==== "&costototalhist)
|
||||
End If
|
||||
totalfinal = totalfinal + costototalhist
|
||||
x.Close
|
||||
Next
|
||||
L_TOTAL.Text = Round2(totalfinal, 2)
|
||||
c.Close
|
||||
|
||||
c = Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE")
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
If c.GetString("CUANTOS") > 0 Then
|
||||
|
||||
Dim z As Cursor = Starter.skmt.ExecQuery($"select SUM(REP_CANT) AS CANTIDAD , SUM(REP_PRECIO) AS PRECIO from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE"$)
|
||||
Dim cantidad2 As String = 0
|
||||
' Log(z.RowCount)
|
||||
If z.RowCount > 0 Then
|
||||
z.Position = 0
|
||||
cantidad2= z.GetString("CANTIDAD")
|
||||
' LogColor(z.GetString("PRECIO")&" , " & z.GetString("CANTIDAD"), Colors.Magenta)
|
||||
' Log(cantidad1 &" , "& cantidad2)
|
||||
L_CANT.Text = Round((cantidad1 + cantidad2))
|
||||
End If
|
||||
z.Close
|
||||
|
||||
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub b_guardar_Click
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub l_pCant_Click
|
||||
|
||||
End Sub
|
||||
|
||||
Sub p_prods_Click
|
||||
Log(Sender.As(Panel).tag)
|
||||
End Sub
|
||||
112
B4A/C_Detalle_Promo.bas
Normal file
@@ -0,0 +1,112 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim c As Cursor
|
||||
' Dim ruta As String
|
||||
Dim Regresar As Button
|
||||
Dim b As Cursor
|
||||
Dim regalo As String
|
||||
Dim ListView1 As ListView
|
||||
Dim L_CANT As Label
|
||||
Dim L_TOTAL As Label
|
||||
Dim borra As Button
|
||||
Dim Existe 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("detalle_promo")
|
||||
c=Starter.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS, CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID)")
|
||||
ListView1.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
b=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from cat_gunaprod where CAT_GP_ID = ?", Array As String(C.GetString("CAT_DP_IDPROD")))
|
||||
B.Position =0
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 10
|
||||
label1.TextColor = Colors.White
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 10
|
||||
label2.TextColor = Colors.White
|
||||
If c.GetString("CAT_DP_PRECIO") = 0 Then
|
||||
regalo = "SI"
|
||||
Else
|
||||
regalo = "NO"
|
||||
End If
|
||||
ListView1.AddTwoLines(B.GetString("CAT_GP_NOMBRE"),"Cantidad # "& c.GetString("CAT_DP_PZAS")& " REGALO "& regalo)
|
||||
b.Close
|
||||
Next
|
||||
c.Close
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
Starter.skmt.Initialize(Starter.ruta,"kmt.db", True)
|
||||
c=Starter.skmt.ExecQuery("select CAT_DP_IDPROD, CAT_DP_PZAS, CAT_DP_PRECIO FROM CAT_DETALLES_PAQ WHERE CAT_DP_ID IN (Select PROIDID from PROIDID)")
|
||||
ListView1.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
b=Starter.skmt.ExecQuery2("select CAT_GP_NOMBRE from cat_gunaprod where CAT_GP_ID = ?", Array As String(C.GetString("CAT_DP_IDPROD")))
|
||||
B.Position =0
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 10
|
||||
label1.TextColor = Colors.White
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 10
|
||||
label2.TextColor = Colors.White
|
||||
If c.GetString("CAT_DP_PRECIO") = 0 Then
|
||||
regalo = "SI"
|
||||
Else
|
||||
regalo = "NO"
|
||||
End If
|
||||
ListView1.AddTwoLines(B.GetString("CAT_GP_NOMBRE"),"Cantidad # "& c.GetString("CAT_DP_PZAS")& " REGALO "& regalo)
|
||||
b.Close
|
||||
Next
|
||||
c.Close
|
||||
End If
|
||||
'la_no_ird.Text = c.GetString("PR_CF_SALDO_ACORT")
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Regresar_Click
|
||||
' StartActivity(pedidos)
|
||||
B4XPages.ShowPage("")
|
||||
End Sub
|
||||
|
||||
Sub Activity_KeyPress (key As Int) As Boolean
|
||||
' BACK key pressed
|
||||
If key=KeyCodes.KEYCODE_BACK Then
|
||||
' I want to capture the key here so I return True
|
||||
' StartActivity(pedidos)
|
||||
B4XPages.ShowPage("")
|
||||
'Return True
|
||||
End If
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
167
B4A/C_Foto.bas
Normal file
@@ -0,0 +1,167 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Private frontCamera As Boolean = False
|
||||
Dim g As GPS
|
||||
Private p_camara As Panel
|
||||
Private camEx As CameraExClass
|
||||
Dim btnTakePicture As Button
|
||||
Dim c As Cursor
|
||||
Dim cuenta As String
|
||||
Dim lat_gps As String
|
||||
Dim USUARIO As String
|
||||
Dim MOTIVO 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
|
||||
g.Initialize("GPS")
|
||||
Root.LoadLayout("foto")
|
||||
c=Starter.skmt.ExecQuery("select cuenta from cuentaa")
|
||||
c.Position = 0
|
||||
cuenta = c.GetString("CUENTA")
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Private Sub InitializeCamera
|
||||
camEx.Initialize(p_camara, frontCamera, Me, "Camera1")
|
||||
frontCamera = camEx.Front
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
' camEx.Release
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Location1 As Location)
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Camera1_Ready (Success As Boolean)
|
||||
If Success Then
|
||||
camEx.SetJpegQuality(90)
|
||||
camEx.CommitParameters
|
||||
camEx.StartPreview
|
||||
Log(camEx.GetPreviewSize)
|
||||
Else
|
||||
ToastMessageShow("Cannot open camera.", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub btnTakePicture_Click
|
||||
Dim ps As CameraSize
|
||||
ps.Width =640
|
||||
ps.Height =480
|
||||
camEx.SetPictureSize(ps.Width, ps.Height)
|
||||
'ToastMessageShow(ps.Width & "x" & ps.Height, False)
|
||||
camEx.CommitParameters
|
||||
camEx.TakePicture
|
||||
End Sub
|
||||
|
||||
Sub btnFocus_Click
|
||||
camEx.FocusAndTakePicture
|
||||
End Sub
|
||||
|
||||
Sub Camera1_PictureTaken (Data() As Byte)
|
||||
Dim filename As String = "1.jpg"
|
||||
Dim dir As String = File.DirRootExternal
|
||||
|
||||
camEx.SavePictureToFile(Data, dir, filename)
|
||||
camEx.StartPreview 'restart preview
|
||||
'Dim out As OutputStream
|
||||
Dim sDate,sTime As String
|
||||
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.Close
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM NOVENTA WHERE NV_CLIENTE IN (select cuenta from cuentaa)")
|
||||
c=Starter.skmt.ExecQuery("select HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) order by HVD_PRONOMBRE asc")
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(c.GetString("HVD_PRONOMBRE")))
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),c.GetString("HVD_PRONOMBRE")))
|
||||
' ANTES DE MODIFCAR
|
||||
Next
|
||||
End If
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO NOVENTA (NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON, NV_FOTO) VALUES(?,?,?,?,?,?,?,?) ", Array As Object (cuenta,sDate & sTime, USUARIO, "CERRADO", B4XPages.MainPage.noVenta.COMENTARIO, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps, Data))
|
||||
Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
Starter.skmt.ExecNonQuery("update HIST_VENTAS SET HVD_RECHAZO = 1 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Sub ChangeCamera_Click
|
||||
camEx.Release
|
||||
frontCamera = Not(frontCamera)
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Sub btnEffect_Click
|
||||
Dim effects As List = camEx.GetSupportedColorEffects
|
||||
If effects.IsInitialized = False Then
|
||||
ToastMessageShow("Effects not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
|
||||
camEx.SetColorEffect(effect)
|
||||
ToastMessageShow(effect, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
Sub btnFlash_Click
|
||||
Dim f() As Float = camEx.GetFocusDistances
|
||||
Log(f(0) & ", " & f(1) & ", " & f(2))
|
||||
Dim flashModes As List = camEx.GetSupportedFlashModes
|
||||
If flashModes.IsInitialized = False Then
|
||||
ToastMessageShow("Flash not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
|
||||
camEx.SetFlashMode(flash)
|
||||
ToastMessageShow(flash, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
Sub btnPictureSize_Click
|
||||
Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
|
||||
Dim current As CameraSize = camEx.GetPictureSize
|
||||
For i = 0 To pictureSizes.Length - 1
|
||||
If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
|
||||
Next
|
||||
Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
|
||||
camEx.SetPictureSize(ps.Width, ps.Height)
|
||||
ToastMessageShow(ps.Width & "x" & ps.Height & i, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' BACK key pressed
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Cliente")
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
609
B4A/C_Historico.bas
Normal file
@@ -0,0 +1,609 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim g As GPS
|
||||
Dim clie_id As String
|
||||
Dim sDate,sTime As String
|
||||
Dim usuario As String
|
||||
Dim c As Cursor
|
||||
' Dim ruta As String
|
||||
Dim b_regresar As Button
|
||||
Dim ListView1 As ListView
|
||||
Dim L_CANT As Label
|
||||
Dim L_TOTAL As Label
|
||||
Dim b_borra As Button
|
||||
Dim Existe As String
|
||||
Dim result As String
|
||||
' Dim lat_gps, lon_gps As String
|
||||
Dim cuantos As String
|
||||
Dim nombre_prod As String
|
||||
Dim cuantos_pedido As String
|
||||
Private Titulo As Label
|
||||
Private P1 As Panel
|
||||
Private lv2 As ListView
|
||||
Private p_principal As Panel
|
||||
Dim clv_pedido As CustomListView
|
||||
Private p_prods As Panel
|
||||
Private l_prodX As Label
|
||||
Private l_pCant As Label
|
||||
Private et_pCant As EditText
|
||||
Dim bmp As Bitmap
|
||||
Dim etCantHasFocus As Boolean = False
|
||||
Dim totalProds As Int = 0
|
||||
Dim totalCompra As Int = 0
|
||||
Dim prodsMap As Map
|
||||
Dim reconstruirPedido As Boolean = False
|
||||
Dim promoABorrar As String
|
||||
Private b_guardar As Button
|
||||
Private b_prodMas As Button
|
||||
Private b_prodMenos As Button
|
||||
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
|
||||
g.Initialize("GPS")
|
||||
Root.LoadLayout("historico")
|
||||
b_borra.Visible = False
|
||||
Titulo.Text = "Pedido"
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
Subs.centraPanel(p_principal, Root.Width)
|
||||
' b_guardar.Visible = False
|
||||
|
||||
' Titulo.Left = Round(p_principal.Width/2)-(Titulo.Width/2)
|
||||
L_CANT.Text =""
|
||||
L_TOTAL.Text=""
|
||||
c=Starter.skmt.ExecQuery("select count(*) as EXISTE from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ")
|
||||
C.Position=0
|
||||
Existe = C.GetString("EXISTE")
|
||||
C.Close
|
||||
' c=Starter.skmt.ExecQuery("select distinct hist_ventas.hvd_num_registro, HIST_VENTAS.HVD_CLIENTE, HIST_VENTAS.HVD_PRONOMBRE, HIST_VENTAS.HVD_PROID, HIST_VENTAS.HVD_CANT, HIST_VENTAS2.HVD_CANT as HVD_CANT2, HIST_VENTAS.HVD_COSTO_TOT, HIST_VENTAS.HVD_CODPROMO from HIST_VENTAS inner join HIST_VENTAS2 on HIST_VENTAS.HVD_PROID = HIST_VENTAS2.HVD_PROID and HIST_VENTAS.HVD_CLIENTE = HIST_VENTAS2.HVD_CLIENTE WHERE HIST_VENTAS.HVD_CLIENTE IN (Select CUENTA from cuentaa) and HIST_VENTAS.HVD_RECHAZO = 0 order by HIST_VENTAS.HVD_CODPROMO desc, HIST_VENTAS.HVD_PRONOMBRE asc")
|
||||
c=Starter.skmt.ExecQuery("select hvd_num_registro, HVD_CLIENTE, HVD_PRONOMBRE, HVD_PROID, HVD_CANT, HVD_COSTO_TOT, HVD_CODPROMO from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 and hvd_cant > 0 order by HVD_CODPROMO desc, HVD_PRONOMBRE asc")
|
||||
ListView1.Clear
|
||||
clv_pedido.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
clv_pedido.GetBase.SetLayoutAnimated(100, 0dip, 60dip, Root.Width - 50, Root.Height * 0.62) 'Cambiamos el tamaño y posición de la lista de productos
|
||||
clv_pedido.Base_Resize(clv_pedido.GetBase.Width, clv_pedido.GetBase.Height) 'Cambiamos el tamaño del panel interno de la lista para que ajuste al nuevo tamaño.
|
||||
' Log("RC1:"&c.RowCount)
|
||||
If c.RowCount>0 Then
|
||||
' Log("Usamos HV")
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
'Traemos cantidad de hvd2
|
||||
Private oc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT from HIST_VENTAS2 WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) and hvd_proid = '${c.GetString("HVD_PROID")}' and HVD_NUM_REGISTRO = '${c.GetString("HVD_NUM_REGISTRO")}'"$)
|
||||
Private cant2 As Int = 0
|
||||
If oc.RowCount > 0 Then
|
||||
oc.Position = 0
|
||||
cant2 = oc.GetString("HVD_CANT")
|
||||
End If
|
||||
oc.Close
|
||||
Dim label1 As Label
|
||||
label1 = ListView1.TwoLinesLayout.Label
|
||||
label1.TextSize = 12
|
||||
label1.TextColor = Colors.black
|
||||
Dim label2 As Label
|
||||
label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
label2.TextSize = 12
|
||||
label2.TextColor = Colors.black
|
||||
Private bgColor, textColor As Int
|
||||
bgColor = Colors.RGB(177, 200, 249)'azul
|
||||
textColor = Colors.black
|
||||
If c.GetString("HVD_CODPROMO") <> "1" Then
|
||||
' bgColor = Colors.RGB(255, 212, 163) 'naranja
|
||||
bgColor = Colors.White
|
||||
End If
|
||||
' Log($"Agregamos prod a lista1 | ${c.GetString("HVD_CANT")} - ${c.GetString("HVD_CANT2")}"$) 'HVD_CANT2 es la original de la orden.
|
||||
' ListView1.AddTwoLines(c.GetString("HVD_PRONOMBRE"),"Cantidad #"& c.GetString("HVD_CANT")& " SubTotal $"& c.GetString("HVD_COSTO_TOT"))
|
||||
clv_pedido.Add(CreateListItem(c.GetString("HVD_PRONOMBRE"), Subs.traePrecio(c.GetString("HVD_PROID"), c.GetString("HVD_CODPROMO")), c.GetString("HVD_CANT"), 0, clv_pedido.AsView.Width, 50dip, bmp, c.GetString("HVD_PROID"), bgColor, textColor, c.GetString("HVD_CODPROMO"),Subs.traeCliente), c.GetString("HVD_PRONOMBRE"))
|
||||
Next
|
||||
' cuentaProds("")
|
||||
End If
|
||||
'Traemos lo vendido
|
||||
Private vc As Cursor = Starter.skmt.ExecQuery("select * from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE")
|
||||
Log($"VENTA: ${vc.RowCount}"$)
|
||||
If vc.RowCount > 0 Then
|
||||
' Log("Usamos REPARTO")
|
||||
' bgColor = Colors.RGB(248,113,113)
|
||||
textColor = Colors.RGB(0,87,142)
|
||||
For i=0 To vc.RowCount -1
|
||||
vc.Position = i
|
||||
Private cantCO As Int = 0
|
||||
'Traemos la cantidad disponible del cliente original
|
||||
Private cco As Cursor = Starter.skmt.ExecQuery($"select * from REPARTO where REP_CLIENTE = '${vc.GetString("REP_CLI_ORIG")}' and REP_CLI_ORIG = '${vc.GetString("REP_CLI_ORIG")}' and REP_PRODID='${vc.GetString("REP_PRODID")}' and REP_RECHAZO = '1' and REP_CANT > 0"$)
|
||||
|
||||
If cco.RowCount > 0 Then
|
||||
cco.Position = 0
|
||||
cantCO = cco.GetString("REP_CANT") + vc.GetString("REP_CANT")
|
||||
End If
|
||||
cantCO = Subs.traeCantidadRechazada(vc.GetString("REP_CLI_ORIG"), vc.GetString("REP_PRODID"))
|
||||
|
||||
' Log($"${vc.GetString("REP_CLI_ORIG")}, ${vc.GetString("REP_CLIENTE")}, ${vc.GetString("REP_PRODID")}, ${vc.GetString("REP_PRONOMBRE")}, ${vc.GetString("REP_RECHAZO")}, ${vc.GetString("REP_CANT")}, ${vc.GetString("REP_PRECIO")}, ${cantCO}, ${cco.GetString("REP_CANT")}, ${vc.GetString("REP_CANT")}"$)
|
||||
clv_pedido.Add(CreateListItem(vc.GetString("REP_PRONOMBRE"), Subs.traePrecio(vc.GetString("REP_PRODID"), 1), vc.GetString("REP_CANT"), cantCO, clv_pedido.AsView.Width, 50dip, bmp, vc.GetString("REP_PRODID"), bgColor, textColor, 1, vc.GetString("REP_CLI_ORIG")), vc.GetString("REP_PRONOMBRE"))
|
||||
Next
|
||||
cco.Close
|
||||
vc.Close
|
||||
End If
|
||||
|
||||
If Existe <> 0 Then
|
||||
c = Starter.skmt.ExecQuery("select SUM(HVD_CANT) AS PC_NOART, SUM(HVD_COSTO_TOT) AS PC_MONTO from HIST_VENTAS where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ")
|
||||
C.Position=0
|
||||
L_CANT.Text = c.GetString("PC_NOART")
|
||||
L_TOTAL.Text = Round2(c.GetString("PC_MONTO"), 2)
|
||||
End If
|
||||
c=Starter.skmt.ExecQuery("select count(*) as EXISTE from PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
c.Position=0
|
||||
Existe = C.GetString("EXISTE")
|
||||
c.Close
|
||||
' c=Starter.skmt.ExecQuery("select PE_PRONOMBRE,PE_COSTO_TOT, PE_CANT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc")
|
||||
'ListView1.Clear
|
||||
Subs.SetDivider(ListView1, Colors.LightGray, 2)
|
||||
' Log("RC2:" & c.RowCount)
|
||||
' If c.RowCount > 0 Then
|
||||
' For i=0 To c.RowCount -1
|
||||
' c.Position=i
|
||||
' Dim label1 As Label
|
||||
' label1 = ListView1.TwoLinesLayout.Label
|
||||
' label1.TextSize = 12
|
||||
' label1.TextColor = Colors.White
|
||||
' Dim label2 As Label
|
||||
' label2 = ListView1.TwoLinesLayout.SecondLabel
|
||||
' label2.TextSize = 12
|
||||
' label2.TextColor = Colors.White
|
||||
' Log("Agegamos prod a lista 2")
|
||||
' ListView1.AddTwoLines("VENTA" & c.GetString("PE_PRONOMBRE"),"Cantidad #"& c.GetString("PE_CANT")& " SubTotal $"& c.GetString("PE_COSTO_TOT"))
|
||||
' 'folio = c.GetString("PE_FOLIO")
|
||||
' Next
|
||||
' End If
|
||||
If Existe <> 0 Then
|
||||
c=Starter.skmt.ExecQuery("select SUM(PE_CANT) AS PE_CANT, SUM(PE_COSTO_TOT) AS PE_COSTO_TOT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
C.Position=0
|
||||
L_CANT.Text = L_CANT.Text + c.GetString("PE_CANT")
|
||||
L_TOTAL.Text = Round2(L_TOTAL.Text + c.GetString("PE_COSTO_TOT"), 2)
|
||||
End If
|
||||
'la_no_ird.Text = c.GetString("PR_CF_SALDO_ACORT")
|
||||
' cuentaProds("")
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Location1 As Location)
|
||||
' lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
|
||||
' lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
|
||||
End Sub
|
||||
|
||||
Sub b_regresar_Click
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' BACK key pressed
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Cliente")
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
Sub ListView1_ItemLongClick (Position As Int, Value As Object) 'BORRAR
|
||||
' nombre_prod = Value
|
||||
' result = Msgbox2("Seguro que desa borrar este articulo?","Borrar Articulo", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
|
||||
' If result = DialogResponse.POSITIVE Then
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' c.Position=0
|
||||
' If c.GetString("HVD_CANT") > 1 Then
|
||||
' b_regresar.Visible =False
|
||||
' b_borra.Visible=False
|
||||
' P1.Visible =True
|
||||
' cuantos_pedido = c.GetString("HVD_CANT")
|
||||
' lv2.Clear
|
||||
' lv2.SingleLineLayout.Label.TextColor = Colors.Black
|
||||
' For i=1 To c.GetString("HVD_CANT")
|
||||
' lv2.AddSingleLine(i)
|
||||
' Next
|
||||
' Else
|
||||
' ' skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
|
||||
' c.Close
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT,REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' c.Position=0
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),Value))
|
||||
' c.Close
|
||||
'
|
||||
' 'skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' ' se cambia por update para no borrarlo y tener todos los registros.
|
||||
' Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
'
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' 'quitar esta mamada no es ahi
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' B4XPage_Appear
|
||||
' End If
|
||||
'
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub lv2_ItemClick (Position As Int, Value As Object) 'BORRAR
|
||||
' ' If Value = "Todos" Then
|
||||
' ' cuantos = c.GetString("HVD_CANT")
|
||||
' 'Else
|
||||
' cuantos = Value
|
||||
' ' End If
|
||||
' If cuantos = cuantos_pedido Then
|
||||
' 'Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
|
||||
' c.Close
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(nombre_prod))
|
||||
' c=Starter.skmt.ExecQuery2("select HVD_CANT FROM hist_ventas where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(nombre_prod))
|
||||
' c.Position=0
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),nombre_prod))
|
||||
' c.Close
|
||||
' 'Starter.skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' ' se cambia por update para no borrarlo y tener todos los registros.
|
||||
' Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As String(Value))
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' 'quitar esta m*m*d* no es ahi
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_RECHAZO = 1, HVD_PARCIAL = 0, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos, nombre_prod))
|
||||
' b_regresar.Visible =True
|
||||
' b_borra.Visible=True
|
||||
' P1.Visible =False
|
||||
' B4XPage_Appear
|
||||
' Else
|
||||
' ' skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
|
||||
' c.Close
|
||||
'
|
||||
' 'modificar tambien esto
|
||||
' 'Modificaciones para que solo quite una parte.
|
||||
' Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_CLI_ORIG) select HVD_CLIENTE, HVD_PRONOMBRE, ?, ? * (HVD_COSTO_TOT/?), HVD_FECHA, HVD_CLIENTE from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos,cuantos,cuantos_pedido, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("insert into hist_ventas(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, HVD_RECHAZO, HVD_ESTATUS, HVD_PARCIAL) select HVD_CLIENTE,HVD_PRONOMBRE,?,HVD_COSTO_TOT, HVD_FECHA, HVD_CODPROMO, HVD_PROID,HVD_NUM_TICKET, HVD_NUM_REGISTRO, 1, HVD_ESTATUS, 1 from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As Object(cuantos, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_RECHAZO = 0, HVD_PARCIAL = 1, HVD_CANT = HVD_CANT - ? where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update hist_Ventas set HVD_COSTO_TOT = HVD_CANT * (HVD_COSTO_TOT/?) where HVD_pronombre = ? and HVD_cliente in (Select CUENTA from cuentaa) and HVD_RECHAZO = 0 ", Array As Object(cuantos_pedido, nombre_prod))
|
||||
' Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(cuantos,nombre_prod))
|
||||
' 'crear nueva tabla para que guarde el resto.
|
||||
'' skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(Value))
|
||||
' 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
|
||||
' clie_id = c.GetString("CUENTA")
|
||||
' c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
' c.Position=0
|
||||
' usuario = c.GetString("USUARIO")
|
||||
' Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
' B4XPage_Appear
|
||||
' b_regresar.Visible =True
|
||||
' b_borra.Visible=True
|
||||
' P1.Visible =False
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
'****************************************************************************
|
||||
'***************** PARA EL MAS/MENOS *************************************
|
||||
'****************************************************************************
|
||||
|
||||
Sub CreateListItem(Text As String, precioU As String, inv As Int, inv2 As Int, Width As Int, Height As Int, img As Bitmap, prodId As String, bc As Int, tc As Int, promo As String, cliente_original As String) As Panel
|
||||
Dim p As B4XView = xui.CreatePanel("")
|
||||
Private cs As CSBuilder
|
||||
cs.Initialize
|
||||
p.SetLayoutAnimated(0, 0, 0, Width, Height)
|
||||
p.LoadLayout("prodItem")
|
||||
p_prods.Color = bc
|
||||
l_prodX.TextColor = tc
|
||||
precioU = $"$1.2{precioU}"$
|
||||
l_prodX.Text = Text&CRLF&"Cant: " & inv2 & " $" & precioU
|
||||
If promo <> "1" And precioU = 0 Then
|
||||
l_prodX.Text = cs.Color(Colors.RGB(123,0,0)).append(Text&CRLF&"Cant: " & inv2 & " $" & precioU).PopAll
|
||||
End If
|
||||
l_prodX.Tag = $"ID: ${prodId}${CRLF}${Text}${CRLF}Precio: $$1.2{precioU}${CRLF}Inv: ${inv} pzs"$
|
||||
' l_pCant.Text = 0
|
||||
l_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
|
||||
et_pCant.Tag = Round2(precioU,2)&"|"&inv&"|"&prodId&"|"&promo&"|"&inv2&"|"&cliente_original
|
||||
p_prods.Tag = l_pCant.tag
|
||||
' Log($"Ponemos la cant en ${inv}"$)
|
||||
l_pCant.Text = inv
|
||||
' et_pCant.Text = inv
|
||||
' et_pCant.BringToFront
|
||||
|
||||
l_pCant.BringToFront
|
||||
et_pCant.SendToBack
|
||||
|
||||
' i_prod.Bitmap = img
|
||||
Return p
|
||||
End Sub
|
||||
|
||||
Sub b_prodMenos_Click
|
||||
etCantHasFocus = False
|
||||
Log("etCantHasFocus=" & etCantHasFocus)
|
||||
LogColor("b_prodMenos_Click", Colors.Magenta)
|
||||
Dim index As Int = clv_pedido.GetItemFromView(Sender)
|
||||
Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
|
||||
Dim pnl As B4XView = pnl0.GetView(0)
|
||||
Dim laCant As B4XView = pnl.GetView(2).GetView(3)
|
||||
' Log(pnl.GetView(2).GetView(0) & "|" & pnl.GetView(2).GetView(1) & "|" & pnl.GetView(2).GetView(2))
|
||||
Dim esteTag As List = Regex.Split("\|", laCant.Tag)
|
||||
Log("LC_TEXT:"&laCant.Text&"|PROMO:"&esteTag.Get(3)&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
|
||||
If esteTag.Get(3) <> "1" Then 'Si es PROMO entonces ...
|
||||
Log("ES PROMO")
|
||||
result = Msgbox2("Si se modifica una promoción, la promoción se rompe y solo quedarán los productos sueltos, ¿seguro que desea continuar?","Modificar Promoción", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png")) 'ignore
|
||||
If result = DialogResponse.POSITIVE Then 'Quitamos esta promo
|
||||
prodsMap.Remove(esteTag.Get(3))
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_RECHAZO = 1 WHERE HVD_PROID = '${esteTag.Get(3)}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_CODPROMO = 1 WHERE HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
LogColor(prodsMap, Colors.red)
|
||||
reconstruirPedido = True
|
||||
promoABorrar = esteTag.Get(3)
|
||||
B4XPage_Appear
|
||||
End If
|
||||
Else
|
||||
If laCant.Text = "" Then laCant.Text = 0
|
||||
laCant.Text = $"$1.0{laCant.Text-1}"$
|
||||
If laCant.Text < 0 Then laCant.Text = 0
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
|
||||
End If
|
||||
Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
|
||||
Log("PU: " & preciou)
|
||||
' LogColor("estamos aqui mmenos " & laCant.Text& " , " & (preciou * laCant.Text),Colors.Green )
|
||||
' If L_CANT.Text - 1 >= 0 Then
|
||||
' L_CANT.Text = L_CANT.Text - 1
|
||||
' End If
|
||||
' b_guardar.Visible = True
|
||||
Subs.prodRechazo(esteTag.Get(5), esteTag.Get(2))
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
' cuentaProds("-")
|
||||
End Sub
|
||||
|
||||
Sub b_prodMas_Click
|
||||
etCantHasFocus = False
|
||||
' Log("etCantHasFocus=" & etCantHasFocus)
|
||||
LogColor("b_prodMas_Click", Colors.Magenta)
|
||||
Dim index As Int = clv_pedido.GetItemFromView(Sender)
|
||||
Dim pnl0 As B4XView = clv_pedido.GetPanel(index)
|
||||
Dim pnl As B4XView = pnl0.GetView(0)
|
||||
Dim laCant As B4XView = pnl.GetView(2).GetView(3)
|
||||
' Log(pnl.GetView(2).GetView(1).text&"|"&pnl.GetView(2).GetView(2)&"|"&pnl.GetView(2).GetView(4).text)
|
||||
' Log($"precio|stock:${laCant.tag}"$)
|
||||
' Log($"Indice: ${index}, cant:${laCant.Text+1}, precioU: ${laCant.tag}"$)
|
||||
Dim esteTag As List = Regex.Split("\|", laCant.Tag)
|
||||
Log("LC_TEXT:"&laCant.Text&"|LC_TAG:"&laCant.Tag&"|ET:"&esteTag)
|
||||
If laCant.Text = "" Then laCant.Text = 0
|
||||
|
||||
Private maxProds as string = esteTag.Get(1) + esteTag.Get(4) 'Prods disponibles + prods comprados
|
||||
|
||||
LogColor($"++++++++++++++++++++++++++ ${esteTag}"$, Colors.Green)
|
||||
' Log(esteTag.get(4))
|
||||
If laCant.Text + 1 <= maxProds Then
|
||||
Log($"NuevaCant = ${laCant.Text + 1}"$)
|
||||
laCant.Text = $"$1.0{laCant.Text + 1}"$
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen - 1 where cat_gp_id = ?", Array As Object(esteTag.Get(2)))
|
||||
Subs.prodVenta(esteTag.Get(5), esteTag.Get(2))
|
||||
Private cym As Map = Subs.traemosCantYMonto(clv_pedido)
|
||||
L_CANT.Text = cym.Get("cantidad")
|
||||
L_TOTAL.Text = Round2(cym.Get("monto"), 2)
|
||||
' cuentaProds("+")
|
||||
End If
|
||||
' Dim preciou As Float = esteTag.Get(0)/esteTag.Get(1)
|
||||
' Log(preciou)
|
||||
' LogColor("estamos aquii mas " & laCant.Text& " , " & (preciou * laCant.Text) ,Colors.Green )
|
||||
' b_guardar.Visible = True
|
||||
' Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
|
||||
' c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS2 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID = '${esteTag.Get(2)}' "$)
|
||||
' c.Position = 0
|
||||
' Dim cantoriginal As String = 0
|
||||
' If c.RowCount > 0 Then
|
||||
' cantoriginal = c.GetString("HVD_CANT")
|
||||
' End If
|
||||
' If cantoriginal <= esteTag.Get(1) Then
|
||||
' L_CANT.Text = L_CANT.Text + 1
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub cuentaProds(accion As String)
|
||||
' Log("Entramos a cuentaProds")
|
||||
Log("*******************************************************")
|
||||
Private cantRechazada As Int = 0
|
||||
If Not(reconstruirPedido) Then
|
||||
Log("*********** CUENTAPRODS - NO RECONSTRUIR")
|
||||
prodsMap.Initialize
|
||||
For i = 0 To clv_pedido.GetSize - 1
|
||||
Private p0 As B4XView = clv_pedido.GetPanel(i)
|
||||
Private p As B4XView = p0.GetView(0)
|
||||
Private cant1 As B4XView = p.GetView(2).GetView(3)
|
||||
If cant1.Text = "" Then cant1.Text = 0
|
||||
' totalProds = totalProds + cant1.Text
|
||||
Private esteTag As List = Regex.Split("\|", cant1.Tag)
|
||||
Log("-------------------------------------")
|
||||
Log($"ET: ${esteTag}"$)
|
||||
Private esteProd As String = esteTag.Get(2)
|
||||
Private estaCant As Int = cant1.Text
|
||||
Private estaCantOriginal As Int = esteTag.Get(1)
|
||||
Private esteCliente = Subs.traeCliente
|
||||
Private esteProdNombre = Subs.traeNombre(esteProd)
|
||||
Private esteClienteOriginal As Int = esteTag.Get(5)
|
||||
Private fechaReparto As String = Subs.traeFechaReparto
|
||||
Private maxProds = Subs.traeMaxCantidad(esteTag.Get(5), esteTag.Get(2))
|
||||
|
||||
If cant1.Text > maxProds Then cant1.Text = maxProds
|
||||
|
||||
cantRechazada = esteTag.Get(4) - cant1.Text
|
||||
' If accion = "-" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) + 1
|
||||
' If accion = "+" Then cantRechazada = Subs.traeCantidadRechazada(esteClienteOriginal, esteProd) - 1
|
||||
Log($"${Subs.traeCantidadRechazada(esteClienteOriginal, esteProd)}, ${Subs.traeCantidadVendida(esteClienteOriginal, esteProd)}"$)
|
||||
|
||||
' LogColor($"cantRechazada = ${esteTag.Get(4)} - ${cant1.Text}"$, Colors.Magenta)
|
||||
LogColor($"cantRechazada = ${cantRechazada}"$, Colors.Magenta)
|
||||
Private estePrecio As String = 0
|
||||
If Subs.traePrecio(esteProd, 1) <> Null Then estePrecio = Subs.traePrecio(esteProd, 1) * cantRechazada
|
||||
|
||||
' LogColor(esteProd & "|" & cant1.Text & "|" & estaCantOriginal & "|" & cantRechazada & "|" & estePrecio, Colors.red)
|
||||
' LogColor($"cantRechazada=${cantRechazada} | ${esteProdNombre}"$, Colors.Blue)
|
||||
' Log($"Ponemos HVD_CANT ${esteProd} en ${cant1.text}"$)
|
||||
Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = ? WHERE HVD_PROID = ? and HVD_CLIENTE in (Select CUENTA from cuentaa)", Array As String(cant1.Text ,esteProd))
|
||||
Private rr As Cursor = Starter.skmt.ExecQuery($"select count(REP_CLIENTE) as hayRechazo from REPARTO where rep_prodid = '${esteProd}' and REP_CLIENTE in (Select CUENTA from cuentaa)"$)
|
||||
rr.Position = 0
|
||||
' Log($"HayRechazo=${rr.GetString("hayRechazo")}"$)
|
||||
If rr.GetString("hayRechazo") = 0 Then
|
||||
Log("INSERTAMOS EN REPARTO")
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?) ", Array As String(esteCliente, esteProdNombre, 0, estePrecio, fechaReparto, esteProd, estePrecio, esteCliente))
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?) ", Array As String(esteCliente, esteProdNombre, cantRechazada, 0, fechaReparto, esteProd, estePrecio, esteCliente))
|
||||
Else if esteClienteOriginal = "0" Then 'Actualizamos el rechazo en el cliente actual.
|
||||
' Log($"Actualizamos REP_CANT=${cantRechazada}"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cantRechazada}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
|
||||
Else 'Cliente original <> 0 entonces actualizamos el rechazo en el cliente original y NO en el actual.
|
||||
Log($"Actualizamos REP_CANT RECHAZO = ${cantRechazada}"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = ${cantRechazada}, REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE = '${esteClienteOriginal}' and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${esteProd}'"$)
|
||||
' Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = '${cant1.Text}', REP_PRECIO = '${estePrecio}', REP_COSTO_TOT = '${estePrecio * cantRechazada}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${esteClienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${esteProd}'"$)
|
||||
End If
|
||||
|
||||
If cant1.Text > 0 Then
|
||||
' totalCompra = totalCompra + (esteTag.get(0) * cant1.text)
|
||||
' Log($"Cant: ${cant1.Text}, Suma: ${totalCompra}"$)
|
||||
Private m As Map
|
||||
m=CreateMap("cant":cant1.Text, "cant2":esteTag.get(4), "precio":esteTag.get(0), "promo":esteTag.get(3), "nombre":Subs.traeNombre(esteTag.Get(2)), "cli_orig":esteTag.get(5))
|
||||
' LogColor("PUT:" & esteTag.Get(2), Colors.Red)
|
||||
prodsMap.Put(esteTag.Get(2), m)
|
||||
End If
|
||||
Log("-------------------------------------")
|
||||
Next
|
||||
End If
|
||||
Private bgColor, textColor As Int
|
||||
|
||||
If reconstruirPedido Then
|
||||
Log("*********** CUENTAPRODS - SI RECONSTRUIR")
|
||||
Private newPromo, newPrecio As String
|
||||
clv_pedido.Clear
|
||||
Log("Usamos PRODSMAP")
|
||||
For Each pr As String In prodsMap.Keys
|
||||
Private pr1 As Map = prodsMap.Get(pr)
|
||||
Log("PPP: " & pr & "|PromoABorrar=" & promoABorrar & "|" & pr1)
|
||||
bgColor = Colors.RGB(177, 200, 249)'azul
|
||||
textColor = Colors.black
|
||||
newPromo = pr1.Get("promo")
|
||||
newPrecio = pr1.Get("precio")
|
||||
Log("AAA: " & newPromo & "|" & promoABorrar)
|
||||
If newPromo = promoABorrar Then
|
||||
newPromo = 1
|
||||
newPrecio = Subs.traePrecio(pr, False) * pr1.Get("cant")
|
||||
'Ponemos precio SIN promo y sacamos el producto de la promo.
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_COSTO_TOT = ${newPrecio}, HVD_CODPROMO = 1 WHERE HVD_PRONOMBRE = '${pr1.Get("nombre")}' and HVD_cliente in (Select CUENTA from cuentaa)"$)
|
||||
LogColor("CAMBIAMOS PROMO: " & newPromo, Colors.Magenta)
|
||||
End If
|
||||
If newPromo <> "1" Then
|
||||
' bgColor = Colors.RGB(255, 212, 163) 'naranja
|
||||
bgColor = Colors.White
|
||||
End If
|
||||
Log($"CLI: ${pr1.Get("nombre")}, ${newPrecio}, ${pr1.Get("cant")}, ${pr1.Get("cant2")}"$)
|
||||
clv_pedido.Add(CreateListItem(pr1.Get("nombre"), newPrecio, pr1.Get("cant"), pr1.Get("cant2"), clv_pedido.AsView.Width, 50dip, bmp, pr, bgColor, textColor, newPromo, pr1.Get("cli_orig")), pr1.Get("nombre"))
|
||||
reconstruirPedido = False
|
||||
Next
|
||||
promoABorrar = ""
|
||||
End If
|
||||
Log($"Total Prods: ${totalProds}, Total Compra: $$1.2{totalCompra}"$)
|
||||
LogColor("prodsMap=" & prodsMap, Colors.Green)
|
||||
|
||||
|
||||
LogColor(prodsMap, Colors.Blue)
|
||||
c = Starter.skmt.ExecQuery($"SELECT sum(HVD_CANT) as CANTIDAD FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)"$)
|
||||
Dim cantidad1 As String = 0
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
cantidad1 = c.GetString("CANTIDAD")
|
||||
L_CANT.Text = Round(cantidad1)
|
||||
End If
|
||||
c.Close
|
||||
|
||||
Dim totalfinal As String = 0
|
||||
For Each pr As String In prodsMap.Keys
|
||||
Private pr1 As Map = prodsMap.Get(pr)
|
||||
' LogColor(pr,Colors.Red)
|
||||
Dim x As Cursor = Starter.skmt.ExecQuery($"SELECT CAT_GP_PRECIO FROM CAT_GUNAPROD WHERE CAT_GP_ID = '${pr}'"$)
|
||||
c = Starter.skmt.ExecQuery($"SELECT HVD_CANT FROM HIST_VENTAS WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA) AND HVD_PROID ='${pr}' "$)
|
||||
Dim cantidady As String = 0
|
||||
If c.RowCount >0 Then
|
||||
c.Position = 0
|
||||
cantidady = c.GetString("HVD_CANT")
|
||||
End If
|
||||
' Log(x.RowCount)
|
||||
If x.RowCount > 0 Then
|
||||
x.Position = 0
|
||||
' Log(x.GetString("CAT_GP_PRECIO"))
|
||||
Dim preciou As String = x.GetString("CAT_GP_PRECIO")
|
||||
Dim costototalhist As String = preciou * cantidady
|
||||
' Log("Total ==== "&costototalhist)
|
||||
End If
|
||||
totalfinal = totalfinal + costototalhist
|
||||
x.Close
|
||||
Next
|
||||
L_TOTAL.Text = Round2(totalfinal, 2)
|
||||
c.Close
|
||||
|
||||
c = Starter.skmt.ExecQuery("select COUNT(*) AS CUANTOS from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE")
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
If c.GetString("CUANTOS") > 0 Then
|
||||
|
||||
Dim z As Cursor = Starter.skmt.ExecQuery($"select SUM(REP_CANT) AS CANTIDAD , SUM(REP_PRECIO) AS PRECIO from REPARTO where REP_CLIENTE in (select cuenta from cuentaa) and REP_RECHAZO = '0' and REP_CANT > 0 order by REP_PRONOMBRE"$)
|
||||
Dim cantidad2 As String = 0
|
||||
' Log(z.RowCount)
|
||||
If z.RowCount > 0 Then
|
||||
z.Position = 0
|
||||
cantidad2= z.GetString("CANTIDAD")
|
||||
' LogColor(z.GetString("PRECIO")&" , " & z.GetString("CANTIDAD"), Colors.Magenta)
|
||||
' Log(cantidad1 &" , "& cantidad2)
|
||||
L_CANT.Text = Round((cantidad1 + cantidad2))
|
||||
End If
|
||||
z.Close
|
||||
|
||||
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub b_guardar_Click
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub l_pCant_Click
|
||||
|
||||
End Sub
|
||||
|
||||
Sub p_prods_Click
|
||||
Log(Sender.As(Panel).tag)
|
||||
End Sub
|
||||
24
B4A/C_Mapas.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
110
B4A/C_NoVenta.bas
Normal file
@@ -0,0 +1,110 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Dim g As GPS
|
||||
Dim c As Cursor
|
||||
Dim COMENTARIO As String
|
||||
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 r_4 As RadioButton
|
||||
Private p_principal As Panel
|
||||
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("no_venta")
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub B4XPage_Appear
|
||||
e_comm.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("Cliente")
|
||||
End Sub
|
||||
|
||||
Sub GUARDA_Click
|
||||
If r_1.Checked Then
|
||||
motivo = "CERRADO"
|
||||
Else If r_2.Checked Then
|
||||
motivo = "NO PIDIO"
|
||||
Else If r_3.Checked Then
|
||||
motivo = "CANCELA"
|
||||
Else
|
||||
motivo = "NO ESTA EL ENCARGADO"
|
||||
End If
|
||||
If motivo <> "CERRADO" Then
|
||||
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.Close
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM NOVENTA WHERE NV_CLIENTE IN (select cuenta from cuentaa)")
|
||||
'Traemos los productos del pedido.
|
||||
c=Starter.skmt.ExecQuery("select HVD_NUM_REGISTRO, HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT, HVD_FECHA, HVD_PROID, CAT_GP_PRECIO from HIST_VENTAS2 join CAT_GUNAPROD on CAT_GP_ID = HVD_PROID WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) order by HVD_PRONOMBRE asc")
|
||||
If c.RowCount > 0 Then 'Si hay pedido en HIST_VENTAS ...
|
||||
|
||||
'Revisamos si se le ha agregado venta al pedido.
|
||||
Private esteCliente As String = Subs.traeCliente
|
||||
Private rv As Cursor = Starter.skmt.ExecQuery($"select * from REPARTO where REP_CLIENTE = '${esteCliente}' and REP_CLI_ORIG <> '${esteCliente}' and REP_RECHAZO = 0"$)
|
||||
If rv.RowCount > 0 Then 'Si tenemos venta en el pedido ...
|
||||
For i2=0 To rv.RowCount - 1
|
||||
rv.Position = i2
|
||||
Log($"Actualizamos REPARTO - cliente=${rv.GetString("REP_CLIENTE")}, cliente orignal=${rv.GetString("REP_CLI_ORIG")}, le agregamos ${rv.GetString("REP_CANT")}"$)
|
||||
Starter.skmt.ExecNonQuery($"update REPARTO set REP_CANT = REP_CANT + ${rv.GetString("REP_CANT")} where REP_RECHAZO = '1' and REP_CLIENTE = '${rv.GetString("REP_CLI_ORIG")}' and REP_CLI_ORIG = '${rv.GetString("REP_CLI_ORIG")}'"$)
|
||||
Next
|
||||
End If
|
||||
|
||||
Starter.skmt.ExecNonQuery("delete from reparto where REP_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
For i=0 To c.RowCount - 1 'Insertamos los productos en REPARTO.
|
||||
c.Position=i
|
||||
Log($"REGISTRO= ${c.GetString("HVD_NUM_REGISTRO")}"$)
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?,?) ", Array As String(c.GetString("HVD_CLIENTE"),c.GetString("HVD_PRONOMBRE"),c.GetString("HVD_CANT"),c.GetString("HVD_COSTO_TOT"),c.GetString("HVD_FECHA"), c.GetString("HVD_PROID"), c.GetString("CAT_GP_PRECIO"), c.GetString("HVD_NUM_REGISTRO"), c.GetString("HVD_CLIENTE")))
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_PRODREGISTRO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?,?) ", Array As String(c.GetString("HVD_CLIENTE"),c.GetString("HVD_PRONOMBRE"),0,c.GetString("HVD_COSTO_TOT"),c.GetString("HVD_FECHA"), c.GetString("HVD_PROID"), c.GetString("CAT_GP_PRECIO"), c.GetString("HVD_NUM_REGISTRO"), c.GetString("HVD_CLIENTE")))
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),c.GetString("HVD_PRONOMBRE")))
|
||||
Next
|
||||
End If
|
||||
|
||||
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, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
|
||||
Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
Starter.skmt.ExecNonQuery("update HIST_VENTAS SET HVD_RECHAZO = 1 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
|
||||
B4XPages.ShowPage("Principal")
|
||||
Else
|
||||
COMENTARIO = e_comm.Text
|
||||
' B4XPages.ShowPage("Foto")
|
||||
StartActivity(foto)
|
||||
End If
|
||||
End Sub
|
||||
24
B4A/C_NuevoCliente.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
24
B4A/C_Pedidos.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
1318
B4A/C_Principal.bas
Normal file
1140
B4A/C_Productos.bas
Normal file
24
B4A/C_TicketsDia.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
74
B4A/C_UpdateAvailable.bas
Normal file
@@ -0,0 +1,74 @@
|
||||
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
|
||||
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.Color = Colors.Transparent
|
||||
End Sub
|
||||
|
||||
Sub B4XPage_Appear
|
||||
Try
|
||||
Do While Not(CanRequestPackageInstalls)
|
||||
MsgboxAsync($"Por favor permita que ${Application.PackageName} instale actualizaciones"$, "Instalar actualización")
|
||||
Wait For Msgbox_Result(Result As Int)
|
||||
Dim in As Intent
|
||||
in.Initialize("android.settings.MANAGE_UNKNOWN_APP_SOURCES", "package:" & Application.PackageName)
|
||||
StartActivity(in)
|
||||
Loop
|
||||
Catch
|
||||
Log("updateAvailable() Error - " & LastException.Message)
|
||||
End Try
|
||||
If appUpdater.newApp.update Then
|
||||
ofreceActualizacion
|
||||
Else
|
||||
sinActualizacion
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'////////////////////////////////////////////////////////////////////////////////////////////
|
||||
'//// Esta es una actividad usada por el servicio appUpdater para mostrar notificaciones
|
||||
'//// cuando hay alguna actualizacion de apk.
|
||||
'////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public Sub CanRequestPackageInstalls As Boolean
|
||||
' // https://www.b4x.com/android/forum/threads/version-safe-apk-installation.87667/#content
|
||||
Dim ctxt As JavaObject
|
||||
ctxt.InitializeContext
|
||||
Dim PackageManager As JavaObject = ctxt.RunMethod("getPackageManager", Null)
|
||||
Return PackageManager.RunMethod("canRequestPackageInstalls", Null)
|
||||
End Sub
|
||||
|
||||
Sub ofreceActualizacion
|
||||
If Msgbox2(appUpdater.newApp.newMsg,"Actualización disponible","Si","","No",Null) = DialogResponse.Positive Then 'ignore
|
||||
' StartService(DownloadService)
|
||||
CallSubDelayed(appUpdater, "download_newApk")
|
||||
' ToastMessageShow("Descargando actualización", True)
|
||||
End If
|
||||
B4XPages.MainPage.ocultaProgreso
|
||||
StartActivity(Main)
|
||||
' Activity.Finish
|
||||
B4XPages.ShowPage("Login")
|
||||
End Sub
|
||||
|
||||
Sub sinActualizacion
|
||||
Msgbox(appUpdater.newApp.okMsg, "Aplicación al corriente") 'ignore
|
||||
' StartActivity(Main)
|
||||
B4XPages.MainPage.ocultaProgreso
|
||||
B4XPages.ShowPage("Login")
|
||||
End Sub
|
||||
134
B4A/C_tabulador.bas
Normal file
@@ -0,0 +1,134 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
Private et_mil As EditText
|
||||
Private et_quinientos As EditText
|
||||
Private et_docientos As EditText
|
||||
Private et_cien As EditText
|
||||
Private et_cincuenta As EditText
|
||||
Private et_veinte As EditText
|
||||
Private et_m_veinte As EditText
|
||||
Private et_m_diez As EditText
|
||||
Private et_m_cinco As EditText
|
||||
Private et_m_dos As EditText
|
||||
Private et_m_peso As EditText
|
||||
Private et_m_centavo As EditText
|
||||
Private b_calcular As Button
|
||||
Private b_guardar As Button
|
||||
Private l_total As Label
|
||||
Dim sum_billetes As Int
|
||||
Dim sum_monedas As Float
|
||||
Dim total As Float
|
||||
Dim c As Cursor
|
||||
Dim d As Cursor
|
||||
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("tabulador")
|
||||
End Sub
|
||||
|
||||
Sub B4XPage_Appear
|
||||
d = Starter.skmt.ExecQuery("SELECT VEINTE, DIEZ, CINCO, DOS, PESO, CENTAVO, TOTAL FROM TABULADOR_MONEDAS")
|
||||
c = Starter.skmt.ExecQuery("SELECT MIL, QUINIENTOS, DOCIENTOS, CIEN, CINCUENTA, VEINTE FROM TABULADOR_BILLETES")
|
||||
c.Position = 0
|
||||
d.Position = 0
|
||||
If c.RowCount > 0 And d.RowCount > 0 Then
|
||||
Log("TABULADR CON RESUKTADO")
|
||||
et_mil.Text = c.GetString("MIL")
|
||||
et_quinientos.Text = c.GetString("QUINIENTOS")
|
||||
et_docientos.Text = c.GetString("DOCIENTOS")
|
||||
et_cien.Text = c.GetString("CIEN")
|
||||
et_cincuenta.Text = c.GetString("CINCUENTA")
|
||||
et_veinte.Text = c.GetString("VEINTE")
|
||||
et_m_veinte.Text = d.GetString("VEINTE")
|
||||
et_m_diez.Text = d.GetString("DIEZ")
|
||||
et_m_cinco.Text = d.GetString("CINCO")
|
||||
et_m_dos.Text = d.GetString("DOS")
|
||||
et_m_peso.Text = d.GetString("PESO")
|
||||
et_m_centavo.Text = d.GetString("CENTAVO")
|
||||
l_total.Text = d.GetString("TOTAL")
|
||||
else If c.RowCount = 0 And d.RowCount = 0 Then
|
||||
Log("TABULADR SIN RESUKTADO")
|
||||
et_mil.Text = ""
|
||||
et_quinientos.Text = ""
|
||||
et_docientos.Text = ""
|
||||
et_cien.Text = ""
|
||||
et_cincuenta.Text = ""
|
||||
et_veinte.Text = ""
|
||||
et_m_veinte.Text = ""
|
||||
et_m_diez.Text = ""
|
||||
et_m_cinco.Text = ""
|
||||
et_m_dos.Text = ""
|
||||
et_m_peso.Text = ""
|
||||
et_m_centavo.Text = ""
|
||||
l_total.Text = ""
|
||||
End If
|
||||
c.Close
|
||||
d.Close
|
||||
End Sub
|
||||
|
||||
Private Sub b_guardar_Click
|
||||
b_calcular_Click
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM TABULADOR_MONEDAS")
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM TABULADOR_BILLETES")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO TABULADOR_BILLETES (MIL, QUINIENTOS, DOCIENTOS, CIEN, CINCUENTA, VEINTE) VALUES (?,?,?,?,?,?)", Array As Object(et_mil.Text,et_quinientos.Text,et_docientos.Text,et_cien.Text,et_cincuenta.Text,et_veinte.Text))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO TABULADOR_MONEDAS (VEINTE, DIEZ, CINCO, DOS, PESO, CENTAVO, TOTAL) VALUES (?,?,?,?,?,?,?)", Array As Object(et_m_veinte.Text,et_m_diez.Text,et_m_cinco.Text,et_m_dos.Text,et_m_peso.Text,et_m_centavo.Text,l_total.Text))
|
||||
B4XPages.ShowPage("Principal")
|
||||
End Sub
|
||||
|
||||
Private Sub b_calcular_Click
|
||||
If et_mil.Text = "" Then
|
||||
et_mil.Text = 0
|
||||
End If
|
||||
If et_quinientos.Text = "" Then
|
||||
et_quinientos.Text = 0
|
||||
End If
|
||||
If et_docientos.Text = "" Then
|
||||
et_docientos.Text = 0
|
||||
End If
|
||||
If et_cien.Text = "" Then
|
||||
et_cien.Text = 0
|
||||
End If
|
||||
If et_cincuenta.Text = "" Then
|
||||
et_cincuenta.Text = 0
|
||||
End If
|
||||
If et_veinte.Text = "" Then
|
||||
et_veinte.Text = 0
|
||||
End If
|
||||
If et_m_veinte.Text = "" Then
|
||||
et_m_veinte.Text = 0
|
||||
End If
|
||||
If et_m_diez.Text = "" Then
|
||||
et_m_diez.Text = 0
|
||||
End If
|
||||
If et_m_cinco.Text = "" Then
|
||||
et_m_cinco.Text = 0
|
||||
End If
|
||||
If et_m_dos.Text = "" Then
|
||||
et_m_dos.Text = 0
|
||||
End If
|
||||
If et_m_peso.Text = "" Then
|
||||
et_m_peso.Text = 0
|
||||
End If
|
||||
If et_m_centavo.Text = "" Then
|
||||
et_m_centavo.Text = 0
|
||||
End If
|
||||
sum_billetes = (et_mil.Text * 1000) + (et_quinientos.Text * 500) + (et_docientos.Text * 200) + ( et_cien.Text * 100 ) + ( et_cincuenta.Text * 50 ) + ( et_veinte.Text * 20 )
|
||||
sum_monedas = (et_m_veinte.Text * 20) + ( et_m_diez.Text * 10 ) + ( et_m_cinco.Text * 5 ) + ( et_m_dos.Text * 2 ) + ( et_m_peso.Text * 1 ) + ( et_m_centavo.Text * 0.50 )
|
||||
total = sum_billetes + sum_monedas
|
||||
l_total.Text = Round2(total, 2)
|
||||
End Sub
|
||||
290
B4A/CameraExClass.bas
Normal file
@@ -0,0 +1,290 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=7.01
|
||||
@EndOfDesignText@
|
||||
|
||||
'Class module
|
||||
'version 1.20
|
||||
'See this page for the list of constants:
|
||||
'http://developer.android.com/intl/fr/reference/android/hardware/Camera.Parameters.html
|
||||
'Note that you should use the constant values instead of the names.
|
||||
Sub Class_Globals
|
||||
Private nativeCam As Object
|
||||
Private cam As Camera
|
||||
Private r As Reflector
|
||||
Private target As Object
|
||||
Private event As String
|
||||
Public Front As Boolean
|
||||
Type CameraInfoAndId (CameraInfo As Object, Id As Int)
|
||||
Type CameraSize (Width As Int, Height As Int)
|
||||
Private parameters As Object
|
||||
End Sub
|
||||
|
||||
Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String)
|
||||
target = TargetModule
|
||||
event = EventName
|
||||
Front = FrontCamera
|
||||
Dim id As Int
|
||||
id = FindCamera(Front).id
|
||||
If id = -1 Then
|
||||
Front = Not(Front) 'try different camera
|
||||
id = FindCamera(Front).id
|
||||
If id = -1 Then
|
||||
ToastMessageShow("No camera found.", True)
|
||||
Return
|
||||
End If
|
||||
End If
|
||||
cam.Initialize2(Panel1, "camera", id)
|
||||
End Sub
|
||||
|
||||
Private Sub FindCamera (frontCamera As Boolean) As CameraInfoAndId
|
||||
Dim ci As CameraInfoAndId
|
||||
Dim cameraInfo As Object
|
||||
Dim cameraValue As Int
|
||||
If frontCamera Then cameraValue = 1 Else cameraValue = 0
|
||||
cameraInfo = r.CreateObject("android.hardware.Camera$CameraInfo")
|
||||
Dim numberOfCameras As Int = r.RunStaticMethod("android.hardware.Camera", "getNumberOfCameras", Null, Null)
|
||||
For i = 0 To numberOfCameras - 1
|
||||
r.RunStaticMethod("android.hardware.Camera", "getCameraInfo", Array As Object(i, cameraInfo), _
|
||||
Array As String("java.lang.int", "android.hardware.Camera$CameraInfo"))
|
||||
r.target = cameraInfo
|
||||
If r.GetField("facing") = cameraValue Then
|
||||
ci.cameraInfo = r.target
|
||||
ci.Id = i
|
||||
Return ci
|
||||
End If
|
||||
Next
|
||||
ci.id = -1
|
||||
Return ci
|
||||
End Sub
|
||||
|
||||
Private Sub SetDisplayOrientation
|
||||
r.target = r.GetActivity
|
||||
r.target = r.RunMethod("getWindowManager")
|
||||
r.target = r.RunMethod("getDefaultDisplay")
|
||||
r.target = r.RunMethod("getRotation")
|
||||
Dim previewResult, result, degrees As Int = r.target * 90
|
||||
Dim ci As CameraInfoAndId = FindCamera(Front)
|
||||
r.target = ci.CameraInfo
|
||||
Dim orientation As Int = r.GetField("orientation")
|
||||
If Front Then
|
||||
previewResult = (orientation + degrees) Mod 360
|
||||
result = previewResult
|
||||
previewResult = (360 - previewResult) Mod 360
|
||||
Else
|
||||
previewResult = (orientation - degrees + 360) Mod 360
|
||||
result = previewResult
|
||||
Log(previewResult)
|
||||
End If
|
||||
r.target = nativeCam
|
||||
r.RunMethod2("setDisplayOrientation", previewResult, "java.lang.int")
|
||||
r.target = parameters
|
||||
r.RunMethod2("setRotation", result, "java.lang.int")
|
||||
CommitParameters
|
||||
End Sub
|
||||
|
||||
Private Sub Camera_Ready (Success As Boolean)
|
||||
If Success Then
|
||||
r.target = cam
|
||||
nativeCam = r.GetField("camera")
|
||||
r.target = nativeCam
|
||||
parameters = r.RunMethod("getParameters")
|
||||
SetDisplayOrientation
|
||||
Else
|
||||
Log("success = false, " & LastException)
|
||||
End If
|
||||
CallSub2(target, event & "_ready", Success)
|
||||
End Sub
|
||||
|
||||
Sub Camera_Preview (Data() As Byte)
|
||||
If SubExists(target, event & "_preview") Then
|
||||
CallSub2(target, event & "_preview", Data)
|
||||
End If
|
||||
End Sub
|
||||
Public Sub TakePicture
|
||||
cam.TakePicture
|
||||
End Sub
|
||||
|
||||
Private Sub Camera_PictureTaken (Data() As Byte)
|
||||
CallSub2(target, event & "_PictureTaken", Data)
|
||||
End Sub
|
||||
|
||||
Public Sub StartPreview
|
||||
cam.StartPreview
|
||||
End Sub
|
||||
|
||||
Public Sub StopPreview
|
||||
cam.StopPreview
|
||||
End Sub
|
||||
|
||||
Public Sub Release
|
||||
cam.Release
|
||||
End Sub
|
||||
|
||||
'Saves the data received from PictureTaken event
|
||||
Public Sub SavePictureToFile(Data() As Byte, Dir As String, FileName As String)
|
||||
Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
|
||||
out.WriteBytes(Data, 0, Data.Length)
|
||||
out.Close
|
||||
End Sub
|
||||
|
||||
Public Sub SetParameter(Key As String, Value As String)
|
||||
r.target = parameters
|
||||
r.RunMethod3("set", Key, "java.lang.String", Value, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetParameter(Key As String) As String
|
||||
r.target = parameters
|
||||
Return r.RunMethod2("get", Key, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub CommitParameters
|
||||
Try
|
||||
r.target = nativeCam
|
||||
r.RunMethod4("setParameters", Array As Object(parameters), Array As String("android.hardware.Camera$Parameters"))
|
||||
Catch
|
||||
ToastMessageShow("Error setting parameters.", True)
|
||||
Log(LastException)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub GetColorEffect As String
|
||||
Return GetParameter("effect")
|
||||
End Sub
|
||||
|
||||
Public Sub SetColorEffect(Effect As String)
|
||||
SetParameter("effect", Effect)
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedPicturesSizes As CameraSize()
|
||||
r.target = parameters
|
||||
Dim list1 As List = r.RunMethod("getSupportedPictureSizes")
|
||||
Dim cs(list1.Size) As CameraSize
|
||||
For i = 0 To list1.Size - 1
|
||||
r.target = list1.Get(i)
|
||||
cs(i).Width = r.GetField("width")
|
||||
cs(i).Height = r.GetField("height")
|
||||
Next
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
Public Sub SetPictureSize(Width As Int, Height As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod3("setPictureSize", Width, "java.lang.int", Height, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub SetJpegQuality(Quality As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setJpegQuality", Quality, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub SetFlashMode(Mode As String)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setFlashMode", Mode, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetFlashMode As String
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getFlashMode")
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedFlashModes As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedFlashModes")
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedColorEffects As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedColorEffects")
|
||||
End Sub
|
||||
|
||||
Public Sub GetPreviewSize As CameraSize
|
||||
r.target = parameters
|
||||
r.target = r.RunMethod("getPreviewSize")
|
||||
Dim cs As CameraSize
|
||||
cs.Width = r.GetField("width")
|
||||
cs.Height = r.GetField("height")
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
Public Sub GetPictureSize As CameraSize
|
||||
r.target = parameters
|
||||
r.target = r.RunMethod("getPictureSize")
|
||||
Dim cs As CameraSize
|
||||
cs.Width = r.GetField("width")
|
||||
cs.Height = r.GetField("height")
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
'Converts a preview image formatted in YUV format to JPEG.
|
||||
'Note that you should not save every preview image as it will slow down the whole process.
|
||||
Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
|
||||
Dim size, previewFormat As Object
|
||||
r.target = parameters
|
||||
size = r.RunMethod("getPreviewSize")
|
||||
previewFormat = r.RunMethod("getPreviewFormat")
|
||||
r.target = size
|
||||
Dim width = r.GetField("width"), height = r.GetField("height") As Int
|
||||
Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
|
||||
Array As Object(data, previewFormat, width, height, Null), _
|
||||
Array As String("[B", "java.lang.int", "java.lang.int", "java.lang.int", "[I"))
|
||||
r.target = yuvImage
|
||||
Dim rect1 As Rect
|
||||
rect1.Initialize(0, 0, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
|
||||
Dim out As OutputStream
|
||||
out.InitializeToBytesArray(100)
|
||||
r.RunMethod4("compressToJpeg", Array As Object(rect1, quality, out), _
|
||||
Array As String("android.graphics.Rect", "java.lang.int", "java.io.OutputStream"))
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedFocusModes As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedFocusModes")
|
||||
End Sub
|
||||
|
||||
Public Sub SetContinuousAutoFocus
|
||||
Dim modes As List = GetSupportedFocusModes
|
||||
If modes.IndexOf("continuous-picture") > -1 Then
|
||||
SetFocusMode("continuous-picture")
|
||||
Else If modes.IndexOf("continuous-video") > -1 Then
|
||||
SetFocusMode("continuous-video")
|
||||
Else
|
||||
Log("Continuous focus mode is not available")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub SetFocusMode(Mode As String)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setFocusMode", Mode, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetFocusDistances As Float()
|
||||
Dim F(3) As Float
|
||||
r.target = parameters
|
||||
r.RunMethod4("getFocusDistances", Array As Object(F), Array As String("[F"))
|
||||
Return F
|
||||
End Sub
|
||||
'This method should only be called if you need to immediately release the camera.
|
||||
'For example if you need to start another application that depends on the camera.
|
||||
Public Sub CloseNow
|
||||
cam.Release
|
||||
r.target = cam
|
||||
r.RunMethod2("releaseCameras", True, "java.lang.boolean")
|
||||
End Sub
|
||||
'Calls AutoFocus and then takes the picture if focus was successfull.
|
||||
Public Sub FocusAndTakePicture
|
||||
cam.AutoFocus
|
||||
End Sub
|
||||
Private Sub Camera_FocusDone (Success As Boolean)
|
||||
If Success Then
|
||||
TakePicture
|
||||
Else
|
||||
Log("AutoFocus error.")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
272
B4A/DBRequestManager.bas
Normal file
@@ -0,0 +1,272 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=7.01
|
||||
@EndOfDesignText@
|
||||
'Class module
|
||||
Sub Class_Globals
|
||||
Private mTarget As Object
|
||||
Type DBResult (Tag As Object, Columns As Map, Rows As List)
|
||||
Type DBCommand (Name As String, Parameters() As Object)
|
||||
Private link As String
|
||||
Private bc As ByteConverter
|
||||
Private T_NULL = 0, T_STRING = 1, T_SHORT = 2, T_INT = 3, T_LONG = 4, T_FLOAT = 5 _
|
||||
,T_DOUBLE = 6, T_BOOLEAN = 7, T_BLOB = 8 As Byte
|
||||
Private VERSION As Float = 0.9
|
||||
Private tempArray(1) As Object
|
||||
Dim jobTagAnterior As String = "" 'Mod por CHV - 211023
|
||||
End Sub
|
||||
|
||||
'Target - The module that handles JobDone (usually Me).
|
||||
'ConnectorLink - URL of the Java server.
|
||||
Public Sub Initialize (Target As Object, ConnectorLink As String)
|
||||
mTarget = Target
|
||||
link = ConnectorLink
|
||||
End Sub
|
||||
|
||||
'Sends a query request.
|
||||
'Command - Query name and parameters.
|
||||
'Limit - Maximum rows to return or 0 for no limit.
|
||||
'Tag - An object that will be returned in the result.
|
||||
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object)
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
|
||||
WriteObject(Command.Name, out2)
|
||||
WriteInt(Limit, out2)
|
||||
WriteList(Command.Parameters, out2)
|
||||
out2.Close
|
||||
j.PostBytes(link & "?method=query", ms.ToBytesArray)
|
||||
End Sub
|
||||
|
||||
'Executes a batch of (non-select) commands.
|
||||
'ListOfCommands - List of the commands that will be executes.
|
||||
'Tag - An object that will be returned in the result.
|
||||
Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object)
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
WriteInt(ListOfCommands.Size, out2)
|
||||
For Each Command As DBCommand In ListOfCommands
|
||||
WriteObject(Command.Name, out2)
|
||||
WriteList(Command.Parameters, out2)
|
||||
Next
|
||||
out2.Close
|
||||
j.PostBytes(link & "?method=batch", ms.ToBytesArray)
|
||||
End Sub
|
||||
|
||||
'Similar to ExecuteBatch. Sends a single command.
|
||||
Public Sub ExecuteCommand(Command As DBCommand, Tag As Object)
|
||||
ExecuteBatch(Array As DBCommand(Command), Tag)
|
||||
End Sub
|
||||
|
||||
Private Sub StartJob(j As HttpJob, MemoryStream As OutputStream, Tag As Object) As OutputStream
|
||||
j.Initialize("DBRequest", mTarget)
|
||||
j.Tag = Tag
|
||||
MemoryStream.InitializeToBytesArray(0)
|
||||
Dim compress As CompressedStreams
|
||||
Dim out As OutputStream = compress.WrapOutputStream(MemoryStream, "gzip")
|
||||
WriteObject(VERSION, out)
|
||||
Return out
|
||||
End Sub
|
||||
|
||||
Private Sub WriteList(Parameters As List, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
If Parameters = Null Or Parameters.IsInitialized = False Then
|
||||
Dim Parameters As List
|
||||
Parameters.Initialize
|
||||
End If
|
||||
data = bc.IntsToBytes(Array As Int(Parameters.Size))
|
||||
out.WriteBytes(data, 0, data.Length)
|
||||
For Each o As Object In Parameters
|
||||
WriteObject(o, out)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub WriteObject(o As Object, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
tempArray(0) = o
|
||||
If tempArray(0) = Null Then
|
||||
out.WriteBytes(Array As Byte(T_NULL), 0, 1)
|
||||
Else If tempArray(0) Is Short Then
|
||||
out.WriteBytes(Array As Byte(T_SHORT), 0, 1)
|
||||
data = bc.ShortsToBytes(Array As Short(o))
|
||||
Else If tempArray(0) Is Int Then
|
||||
out.WriteBytes(Array As Byte(T_INT), 0, 1)
|
||||
data = bc.IntsToBytes(Array As Int(o))
|
||||
Else If tempArray(0) Is Float Then
|
||||
out.WriteBytes(Array As Byte(T_FLOAT), 0, 1)
|
||||
data = bc.FloatsToBytes(Array As Float(o))
|
||||
Else If tempArray(0) Is Double Then
|
||||
out.WriteBytes(Array As Byte(T_DOUBLE), 0, 1)
|
||||
data = bc.DoublesToBytes(Array As Double(o))
|
||||
Else If tempArray(0) Is Long Then
|
||||
out.WriteBytes(Array As Byte(T_LONG), 0, 1)
|
||||
data = bc.LongsToBytes(Array As Long(o))
|
||||
Else If tempArray(0) Is Boolean Then
|
||||
out.WriteBytes(Array As Byte(T_BOOLEAN), 0, 1)
|
||||
Dim b As Boolean = 0
|
||||
Dim data(1) As Byte
|
||||
If b Then data(0) = 1 Else data(0) = 0
|
||||
Else If GetType(tempArray(0)) = "[B" Then
|
||||
data = o
|
||||
out.WriteBytes(Array As Byte(T_BLOB), 0, 1)
|
||||
WriteInt(data.Length, out)
|
||||
Else 'If o Is String Then (treat all other values as string)
|
||||
out.WriteBytes(Array As Byte(T_STRING), 0, 1)
|
||||
data = bc.StringToBytes(o, "UTF8")
|
||||
WriteInt(data.Length, out)
|
||||
End If
|
||||
If data.Length > 0 Then out.WriteBytes(data, 0, data.Length)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadObject(In As InputStream) As Object
|
||||
Dim data(1) As Byte
|
||||
In.ReadBytes(data, 0, 1)
|
||||
Select data(0)
|
||||
Case T_NULL
|
||||
Return Null
|
||||
Case T_SHORT
|
||||
Dim data(2) As Byte
|
||||
Return bc.ShortsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_INT
|
||||
Dim data(4) As Byte
|
||||
Return bc.IntsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_LONG
|
||||
Dim data(8) As Byte
|
||||
Return bc.LongsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_FLOAT
|
||||
Dim data(4) As Byte
|
||||
Return bc.FloatsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_DOUBLE
|
||||
Dim data(8) As Byte
|
||||
Return bc.DoublesFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_BOOLEAN
|
||||
Dim b As Byte = ReadByte(In)
|
||||
Return b = 1
|
||||
Case T_BLOB
|
||||
Dim len As Int = ReadInt(In)
|
||||
Dim data(len) As Byte
|
||||
Return ReadBytesFully(In, data, data.Length)
|
||||
Case Else
|
||||
Dim len As Int = ReadInt(In)
|
||||
Dim data(len) As Byte
|
||||
ReadBytesFully(In, data, data.Length)
|
||||
Return BytesToString(data, 0, data.Length, "UTF8")
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub ReadBytesFully(In As InputStream, Data() As Byte, Len As Int) As Byte()
|
||||
Dim count = 0, read As Int
|
||||
Do While count < Len And read > -1
|
||||
read = In.ReadBytes(Data, count, Len - count)
|
||||
count = count + read
|
||||
Loop
|
||||
Return Data
|
||||
End Sub
|
||||
|
||||
Private Sub WriteInt(i As Int, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
data = bc.IntsToBytes(Array As Int(i))
|
||||
out.WriteBytes(data, 0, data.Length)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadInt(In As InputStream) As Int
|
||||
Dim data(4) As Byte
|
||||
Return bc.IntsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadByte(In As InputStream) As Byte
|
||||
Dim data(1) As Byte
|
||||
In.ReadBytes(data, 0, 1)
|
||||
Return data(0)
|
||||
End Sub
|
||||
|
||||
'Handles the Job result and returns a DBResult.
|
||||
Public Sub HandleJob(Job As HttpJob) As DBResult
|
||||
' Dim start As Long = DateTime.Now
|
||||
Dim In As InputStream = Job.GetInputStream
|
||||
Dim cs As CompressedStreams
|
||||
In = cs.WrapInputStream(In, "gzip")
|
||||
Dim serverVersion As Float = ReadObject(In) 'ignore
|
||||
Dim method As String = ReadObject(In)
|
||||
Dim table As DBResult
|
||||
table.Initialize
|
||||
table.Columns.Initialize
|
||||
table.rows.Initialize
|
||||
table.Tag = Job.Tag
|
||||
If jobTagAnterior <> Job.Tag Then LogColor("HandleJob: '"&Job.Tag&"'", Colors.Blue) 'Mod por CHV - 211023
|
||||
jobTagAnterior = Job.Tag 'Mod por CHV - 211023
|
||||
If method = "query" Then
|
||||
Dim numberOfColumns As Int = ReadInt(In)
|
||||
For i = 0 To numberOfColumns - 1
|
||||
table.Columns.Put(ReadObject(In), i)
|
||||
Next
|
||||
Do While ReadByte(In) = 1
|
||||
Dim rowObjects(numberOfColumns) As Object
|
||||
table.rows.Add(rowObjects)
|
||||
For col = 0 To numberOfColumns - 1
|
||||
Dim o As Object = ReadObject(In)
|
||||
rowObjects(col) = o
|
||||
Next
|
||||
Loop
|
||||
Else If method = "batch" Then
|
||||
table.Columns.Put("AffectedRows", 0)
|
||||
Dim rows As Int = ReadInt(In)
|
||||
For i = 0 To rows - 1
|
||||
table.rows.Add(Array As Object(ReadInt(In)))
|
||||
Next
|
||||
End If
|
||||
In.Close
|
||||
Return table
|
||||
End Sub
|
||||
|
||||
'Reads a file and returns the file as a bytes array.
|
||||
Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
|
||||
Dim out As OutputStream
|
||||
out.InitializeToBytesArray(0)
|
||||
Dim In As InputStream = File.OpenInput(Dir, FileName)
|
||||
File.Copy2(In, out)
|
||||
out.Close
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
|
||||
'Converts an image to a bytes array (for BLOB fields).
|
||||
Public Sub ImageToBytes(Image As Bitmap) As Byte()
|
||||
Dim out As OutputStream
|
||||
out.InitializeToBytesArray(0)
|
||||
Image.WriteToStream(out, 100, "JPEG")
|
||||
out.Close
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
'Converts a bytes array to an image (for BLOB fields).
|
||||
Public Sub BytesToImage(bytes() As Byte) As Bitmap
|
||||
Dim In As InputStream
|
||||
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
|
||||
Dim bmp As Bitmap
|
||||
bmp.Initialize2(In)
|
||||
Return bmp
|
||||
End Sub
|
||||
|
||||
'Prints the table to the logs.
|
||||
Public Sub PrintTable(Table As DBResult)
|
||||
Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
|
||||
Dim sb As StringBuilder
|
||||
sb.Initialize
|
||||
For Each col In Table.Columns.Keys
|
||||
sb.Append(col).Append(TAB)
|
||||
Next
|
||||
Log(sb.ToString)
|
||||
For Each row() As Object In Table.Rows
|
||||
Dim sb As StringBuilder
|
||||
sb.Initialize
|
||||
For Each record As Object In row
|
||||
sb.Append(record).Append(TAB)
|
||||
Next
|
||||
ToastMessageShow(sb.ToString, True)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
BIN
B4A/Files/alert2.png
Normal file
|
After Width: | Height: | Size: 632 B |
BIN
B4A/Files/alerta.jpg
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
B4A/Files/buscar.bal
Normal file
BIN
B4A/Files/cliente.bal
Normal file
BIN
B4A/Files/clientes.bal
Normal file
BIN
B4A/Files/dbc.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
B4A/Files/detalle_promo.bal
Normal file
BIN
B4A/Files/detalleventa.bal
Normal file
BIN
B4A/Files/durakelo1.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
B4A/Files/engrane.jpg
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
B4A/Files/fondo_kmt.jpg
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
B4A/Files/foto.bal
Normal file
BIN
B4A/Files/guardagestion.bal
Normal file
BIN
B4A/Files/guna_viejo.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
B4A/Files/guna_viejo2.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
B4A/Files/historico.bal
Normal file
BIN
B4A/Files/infonavit1.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
B4A/Files/itembuttonblue.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
B4A/Files/kelloggs.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
B4A/Files/keymon_logo.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
B4A/Files/kmt.db
Normal file
BIN
B4A/Files/login.bal
Normal file
BIN
B4A/Files/logo sanfer.jpg
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
B4A/Files/logo_exitus1.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
B4A/Files/logo_mariana.jpg
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
B4A/Files/logomedi.jpg
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
B4A/Files/mainpage.bal
Normal file
BIN
B4A/Files/malo.jpg
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
B4A/Files/mapa.bal
Normal file
BIN
B4A/Files/mapa_cliente.bal
Normal file
BIN
B4A/Files/mapa_rutas.bal
Normal file
BIN
B4A/Files/mariana_logo_192x192.jpg
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
B4A/Files/no_venta.bal
Normal file
BIN
B4A/Files/nuevocliente.bal
Normal file
BIN
B4A/Files/pedido.bal
Normal file
BIN
B4A/Files/planfia_logo.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
B4A/Files/planfia_logo_old.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
B4A/Files/planfia_logo_old2.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
B4A/Files/principal.bal
Normal file
BIN
B4A/Files/proditem.bal
Normal file
BIN
B4A/Files/productos.bal
Normal file
BIN
B4A/Files/profina.jpg
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
B4A/Files/profina.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
B4A/Files/sync.png
Normal file
|
After Width: | Height: | Size: 763 B |
BIN
B4A/Files/tabulador.bal
Normal file
BIN
B4A/Files/telefonos.bal
Normal file
115
B4A/MAPA_CLIENTE.bas
Normal file
@@ -0,0 +1,115 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Activity
|
||||
Version=9.95
|
||||
@EndOfDesignText@
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: FALSE
|
||||
|
||||
#End Region
|
||||
|
||||
Sub Process_Globals
|
||||
Dim GPS As GPS
|
||||
Dim rp As RuntimePermissions
|
||||
Dim ruta As String
|
||||
Dim skmt As SQL
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
Private gmap As GoogleMap
|
||||
Private MapFragment1 As MapFragment
|
||||
Dim Latitud As Double = 0
|
||||
Dim Longitud As Double = 0
|
||||
Dim Lat2 As Double = 0
|
||||
Dim Lon2 As Double = 0
|
||||
Dim p1, p2 As Location
|
||||
Dim Distance As Float
|
||||
Dim boton1 As Button
|
||||
Dim c As Cursor
|
||||
Dim latmarker As String
|
||||
Dim longmarker As String
|
||||
Private l_long As Label
|
||||
Private l_lat As Label
|
||||
Private NOMBRE_TIENDA As String
|
||||
Private p_principal As Panel
|
||||
Private b_regresar As Button
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
Activity.LoadLayout("mapa_cliente")
|
||||
If MapFragment1.IsGooglePlayServicesAvailable = False Then
|
||||
ToastMessageShow("Please install Google Play Services.", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub MapFragment1_Ready
|
||||
gmap = MapFragment1.GetMap
|
||||
'permisos
|
||||
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
|
||||
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
gmap.MyLocationEnabled = Result
|
||||
'fin de permisos
|
||||
Dim JavaMapsObject As JavaObject
|
||||
JavaMapsObject = gmap.GetUiSettings
|
||||
JavaMapsObject.RunMethod("setMapToolbarEnabled", Array As Object(True))
|
||||
Dim marcador1 As Marker = gmap.AddMarker (latmarker,longmarker, "TIENDA")
|
||||
marcador1.Snippet = B4XPages.MainPage.cliente.NOMBRE
|
||||
'posicion inicial
|
||||
Dim aa As CameraPosition
|
||||
aa.Initialize(latmarker,longmarker,15)''' RECOMENDABLE CAMBIAR A 10 SI ES MAS DE 1 MARCADOR
|
||||
gmap.AnimateCamera(aa)
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Parametro As Location)
|
||||
' GPS.Start(0, 0)
|
||||
' Dim sp As Int
|
||||
' sp = Ceil(Parametro.Speed * 3.6)
|
||||
' boton1.Text = sp &" "&"km/h"
|
||||
' Latitud = Parametro.Latitude
|
||||
' Longitud = Parametro.Longitude
|
||||
' p2.Initialize2(Latitud,Longitud)
|
||||
' p1.Initialize2(Lat2, Lon2)
|
||||
' Distance = p1.DistanceTo(p2)
|
||||
' If Latitud <> 0 And Longitud <> 0 Then
|
||||
' If Distance > 10 Then
|
||||
' Lat2 = Latitud
|
||||
' Lon2 = Longitud
|
||||
' Dim cp As CameraPosition
|
||||
' cp.Initialize2(Parametro.Latitude, Parametro.Longitude, gmap.CameraPosition.Zoom, Parametro.Bearing, 0)
|
||||
' gmap.AnimateCamera(cp)
|
||||
' End If
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
Subs.centraBoton(b_regresar, Activity.Width)
|
||||
GPS.Initialize("GPS")
|
||||
If GPS.GPSEnabled = False Then
|
||||
ToastMessageShow("Debe Activar el GPS del Equipo.", True)
|
||||
StartActivity(GPS.LocationSettingsIntent)
|
||||
Else
|
||||
GPS.Start(0, 0)
|
||||
End If
|
||||
Subs.centraPanel(p_principal, Activity.Width)
|
||||
p_principal.Height = Activity.Height * 0.95
|
||||
latmarker = B4XPages.MainPage.cliente.LATITUD
|
||||
longmarker = B4XPages.MainPage.cliente.LONGITUD
|
||||
NOMBRE_TIENDA = B4XPages.MainPage.cliente.NOMBRE
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
GPS.Stop
|
||||
End Sub
|
||||
|
||||
Sub reg_Click
|
||||
' StartActivity(fila)
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Private Sub b_regresar_Click
|
||||
Log("Pressed")
|
||||
Activity.Finish
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
327
B4A/MAPA_RUTAS.bas
Normal file
@@ -0,0 +1,327 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Activity
|
||||
Version=9.3
|
||||
@EndOfDesignText@
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: False
|
||||
#End Region
|
||||
|
||||
'Activity module
|
||||
Sub Process_Globals
|
||||
Dim GPS As GPS
|
||||
Dim rp As RuntimePermissions
|
||||
' Dim skmt As SQL
|
||||
Dim c As Cursor
|
||||
Dim c2 As Cursor
|
||||
Dim c22 As Cursor
|
||||
Dim c3 As Cursor
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
Private gmap As GoogleMap
|
||||
Private MapFragment1 As MapFragment
|
||||
Dim Latitud As Double = 0
|
||||
Dim Longitud As Double = 0
|
||||
Dim Lat2 As Double = 0
|
||||
Dim Lon2 As Double = 0
|
||||
Dim p1, p2 As Location
|
||||
Dim Distance As Float
|
||||
Dim boton1 As Button
|
||||
Dim HUE_BLUE As Float
|
||||
Dim HUE_RED As Float
|
||||
Dim HUE_GREEN As Float
|
||||
Private B_AZUL As Button
|
||||
Private B_ROJO As Button
|
||||
Private B_VERDE As Button
|
||||
Private B_TODOS As Button
|
||||
Dim Tienda As String
|
||||
Dim ruta, rutaAnt As String
|
||||
Dim LatitudRu As Double
|
||||
Dim LongitudRU As Double
|
||||
Dim LIST_AZUL As List
|
||||
Dim LIST_ROJO As List
|
||||
Dim LIST_VERDE As List
|
||||
Dim MARK_AZUL As Marker
|
||||
Dim MARK_ROJO As Marker
|
||||
Dim MARK_VERDE As Marker
|
||||
Dim MARK_CEDIS As Marker
|
||||
Dim rojo As String
|
||||
Dim azul As String
|
||||
Dim verde As String
|
||||
Dim todos As String
|
||||
Dim NumSerie As Int
|
||||
Dim OnInfoWindowClickListener1 As OnInfoWindowClickListener
|
||||
Dim GoogleMapEXTRA As GoogleMapsExtras
|
||||
Dim CODIGO As String
|
||||
Private SEMANA As String
|
||||
' Dim ruta As String
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
' Msgbox("0","AVISO")
|
||||
Activity.LoadLayout("MAPA_RUTAS")
|
||||
' ruta = Main.ruta
|
||||
' If File.Exists(RUTA, "kmt.db") = False Then
|
||||
' File.Copy(File.DirAssets, "kmt.db", RUTA, "kmt.db")
|
||||
' End If
|
||||
' skmt.Initialize(Starter.ruta,"kmt.db", True)
|
||||
'GPS
|
||||
' If(FirstTime) Then
|
||||
' GPS.Initialize("GPS")
|
||||
' End If
|
||||
' Msgbox("0.0","AVISO")
|
||||
If MapFragment1.IsGooglePlayServicesAvailable = False Then
|
||||
ToastMessageShow("Please install Google Play Services.", True)
|
||||
End If
|
||||
' Msgbox("0.1","AVISO")
|
||||
'Boton velocidad'
|
||||
' boton1.Initialize(0)
|
||||
' boton1.Text = 0 &" "&"km/h"
|
||||
' boton1.TextColor = Colors.Red
|
||||
' boton1.TextSize = 15
|
||||
' Activity.AddView(boton1, 40%x, 5dip, 25%x, 40dip)
|
||||
'Fin Boton velocidad'
|
||||
'MARK_CEDIS.IsInitialized
|
||||
MARK_AZUL.IsInitialized
|
||||
MARK_ROJO.IsInitialized
|
||||
MARK_VERDE.IsInitialized
|
||||
|
||||
LIST_AZUL.Initialize
|
||||
LIST_ROJO.Initialize
|
||||
LIST_VERDE.Initialize
|
||||
|
||||
verde = 0
|
||||
azul = 0
|
||||
rojo = 0
|
||||
todos = 1
|
||||
' c=skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA"))
|
||||
' c.Position =0
|
||||
' SEMANA = c.GetString("CUANTOS")
|
||||
' c.Close
|
||||
'
|
||||
' If SEMANA > 0 Then
|
||||
' c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SEMANA"))
|
||||
' c.Position =0
|
||||
' SEMANA = c.GetString("CAT_VA_VALOR")
|
||||
' c.Close
|
||||
' End If
|
||||
|
||||
' Msgbox("0.2","AVISO")
|
||||
End Sub
|
||||
|
||||
Sub MapFragment1_Ready
|
||||
' Msgbox("111","AVISO")
|
||||
gmap = MapFragment1.GetMap
|
||||
gmap.IsInitialized
|
||||
|
||||
'todos= 1
|
||||
'permisos
|
||||
' Msgbox("11","AVISO")
|
||||
|
||||
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
|
||||
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
gmap.MyLocationEnabled = Result
|
||||
|
||||
Dim JavaMapsObject As JavaObject
|
||||
JavaMapsObject = gmap.GetUiSettings
|
||||
JavaMapsObject.RunMethod("setMapToolbarEnabled", Array As Object(True))
|
||||
|
||||
' Msgbox("12","AVISO")
|
||||
|
||||
'''''''----------------------------MARKER AZUL - POR ENTREGAR
|
||||
Private esteAzul As Int = 0
|
||||
Private esteAzul2 As Float
|
||||
If azul = 1 Or todos = 1 Then
|
||||
c.IsInitialized
|
||||
c=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE, CAT_CL_LAT, CAT_CL_LONG, CAT_CL_RUTA from kmt_info where gestion = 0 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 order by CAT_CL_RUTA")
|
||||
' Msgbox("2","AVISO")
|
||||
rutaAnt = ""
|
||||
For i = 0 To c.RowCount -1
|
||||
c.Position = i
|
||||
LatitudRu = c.GetString("CAT_CL_LAT")
|
||||
LongitudRU = c.GetString("CAT_CL_LONG")
|
||||
CODIGO=c.GetString("CAT_CL_CODIGO")
|
||||
Tienda= c.GetString("CAT_CL_NOMBRE")
|
||||
ruta = c.GetString("CAT_CL_RUTA")
|
||||
If rutaAnt <> ruta Then esteAzul = esteAzul + 1
|
||||
If esteAzul = 1 Then esteAzul2=gmap.HUE_AZURE-25
|
||||
If esteAzul = 2 Then esteAzul2=gmap.HUE_AZURE
|
||||
If esteAzul = 3 Then esteAzul2=gmap.HUE_AZURE+25
|
||||
If esteAzul = 4 Then esteAzul2=gmap.HUE_AZURE+50
|
||||
If esteAzul = 5 Then esteAzul2=gmap.HUE_AZURE+75
|
||||
' Log(ruta & "|" & esteAzul & "|" & esteAzul2)
|
||||
MARK_AZUL = gmap.AddMarker2(LatitudRu,LongitudRU, CODIGO, esteAzul2)
|
||||
MARK_AZUL.Snippet = "R: " & ruta & " - " & Tienda
|
||||
rutaAnt = ruta
|
||||
Next
|
||||
c .Close
|
||||
If MARK_AZUL.IsInitialized Then LIST_AZUL.Add(MARK_AZUL)
|
||||
End If
|
||||
' Msgbox("3","AVISO")
|
||||
'''''''----------------------------MARKER VERDE- ENTREGADO
|
||||
If verde = 1 Or todos = 1 Then
|
||||
rutaAnt = ""
|
||||
c2.IsInitialized
|
||||
c2=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE, CAT_CL_LONG, CAT_CL_LAT, CAT_CL_RUTA from kmt_info where gestion = 2 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 order by CAT_CL_RUTA")
|
||||
For i = 0 To c2.RowCount -1
|
||||
c2.Position = i
|
||||
LongitudRU = c2.GetString("CAT_CL_LONG")
|
||||
LatitudRu = c2.GetString("CAT_CL_LAT")
|
||||
CODIGO=c2.GetString("CAT_CL_CODIGO")
|
||||
Tienda= c2.GetString("CAT_CL_NOMBRE")
|
||||
ruta = c2.GetString("CAT_CL_RUTA")
|
||||
MARK_VERDE = gmap.AddMarker2(LatitudRu,LongitudRU, CODIGO,gmap.HUE_GREEN)
|
||||
MARK_VERDE.Snippet = "R:" & ruta & ", " & Tienda
|
||||
Next
|
||||
Else
|
||||
If verde = 1 Or todos = 1 Then
|
||||
rutaAnt = ""
|
||||
c2.IsInitialized
|
||||
c2=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE, CAT_CL_LONG, CAT_CL_LAT, CAT_CL_RUTA from kmt_info where gestion = 2 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 order by CAT_CL_RUTA")
|
||||
For i = 0 To c2.RowCount -1
|
||||
c2.Position = i
|
||||
LongitudRU = c2.GetString("CAT_CL_LONG")
|
||||
LatitudRu = c2.GetString("CAT_CL_LAT")
|
||||
CODIGO=c2.GetString("CAT_CL_CODIGO")
|
||||
Tienda= c2.GetString("CAT_CL_NOMBRE")
|
||||
ruta = c2.GetString("CAT_CL_RUTA")
|
||||
MARK_VERDE = gmap.AddMarker2(LatitudRu,LongitudRU, CODIGO,gmap.HUE_GREEN)
|
||||
MARK_VERDE.Snippet = "R:" & ruta & ", " & Tienda
|
||||
Next
|
||||
c2 .Close
|
||||
If MARK_VERDE.IsInitialized Then LIST_VERDE.Add(MARK_VERDE)
|
||||
End If
|
||||
End If
|
||||
|
||||
' '''''''----------------------------MARKER ROJO - NO ENTREGADO
|
||||
|
||||
If rojo = 1 Or todos = 1 Then
|
||||
rutaAnt = ""
|
||||
c3.IsInitialized
|
||||
c3=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE, CAT_CL_LONG, CAT_CL_LAT, CAT_CL_RUTA from kmt_info where gestion = 3 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 order by CAT_CL_RUTA")
|
||||
For i = 0 To c3.RowCount -1
|
||||
c3.Position = i
|
||||
LongitudRU = c3.GetDouble("CAT_CL_LONG")
|
||||
LatitudRu = c3.GetDouble("CAT_CL_LAT")
|
||||
Tienda= c3.GetString("CAT_CL_NOMBRE")
|
||||
ruta = c3.GetString("CAT_CL_RUTA")
|
||||
CODIGO=c3.GetString("CAT_CL_CODIGO")
|
||||
MARK_ROJO = gmap.AddMarker2(LatitudRu,LongitudRU, CODIGO,gmap.HUE_RED)
|
||||
MARK_ROJO.Snippet= "R:" & ruta & ", " & Tienda
|
||||
Next
|
||||
Else
|
||||
If rojo = 1 Or todos = 1 Then
|
||||
rutaAnt = ""
|
||||
c3.IsInitialized
|
||||
c3=Starter.skmt.ExecQuery("select CAT_CL_CODIGO, CAT_CL_NOMBRE, CAT_CL_LONG, CAT_CL_LAT, CAT_CL_RUTA from kmt_info where gestion = 3 and CAT_CL_LAT is not null and CAT_CL_LONG is not null and CAT_CL_LAT <> 0 and CAT_CL_LONG <> 0 order by CAT_CL_RUTA")
|
||||
For i = 0 To c3.RowCount -1
|
||||
c3.Position = i
|
||||
LongitudRU = c3.GetDouble("CAT_CL_LONG")
|
||||
LatitudRu = c3.GetDouble("CAT_CL_LAT")
|
||||
Tienda= c3.GetString("CAT_CL_NOMBRE")
|
||||
ruta = c2.GetString("CAT_CL_RUTA")
|
||||
CODIGO=c3.GetString("CAT_CL_CODIGO")
|
||||
MARK_ROJO = gmap.AddMarker2(LatitudRu,LongitudRU, CODIGO,gmap.HUE_RED)
|
||||
MARK_ROJO.Snippet= "R:" & ruta & ", " & Tienda
|
||||
Next
|
||||
If MARK_ROJO.IsInitialized Then LIST_ROJO.Add(MARK_ROJO)
|
||||
c3.Close
|
||||
End If
|
||||
End If
|
||||
''------------------------------
|
||||
' MARK_CEDIS = gmap.AddMarker3("19.3961802","-99.0784293","CEDIS", LoadBitmap(File.DirAssets, "marker-azul-0.png"))
|
||||
' If MARK_VERDE.Visible Or MARK_ROJO.Visible Then
|
||||
' MARK_CEDIS.Remove
|
||||
' End If
|
||||
Dim aa As CameraPosition
|
||||
aa.Initialize(LatitudRu,LongitudRU,15)''' RECOMENDABLE CAMBIAR A 10 PARA QUE SE VEAN MAS MARCADORES
|
||||
gmap.AnimateCamera(aa)
|
||||
|
||||
'''''---------------------- ESTO ES PARA LOS CLICK EN LAS VENTANAS D INFORMACION-----------
|
||||
Dim OnInfoWindowClickListener1 As OnInfoWindowClickListener
|
||||
OnInfoWindowClickListener1.Initialize("OnInfoWindowClickListener1")
|
||||
GoogleMapEXTRA.SetOnInfoWindowClickListener(gmap, OnInfoWindowClickListener1)
|
||||
End Sub
|
||||
|
||||
''''-------------------------- PRUEBA CON MARKER _CLICK
|
||||
|
||||
Sub OnInfoWindowClickListener1_click(Marker1 As Marker)
|
||||
Starter.skmt.ExecNonQuery("delete from CUENTAA")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?) ", Array As Object(Marker1.Title))
|
||||
Activity.Finish
|
||||
B4XPages.ShowPage("Cliente")
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Parametro As Location)
|
||||
'MARK_CEDIS.IsInitialized
|
||||
' Dim sp As Int
|
||||
' sp = Ceil(Parametro.Speed * 3.6)
|
||||
' boton1.Text = sp &" "&"km/h"
|
||||
' Latitud = Parametro.Latitude
|
||||
' Longitud = Parametro.Longitude
|
||||
' p2.Initialize2(Latitud,Longitud)
|
||||
' p1.Initialize2(Lat2, Lon2)
|
||||
' Distance = p1.DistanceTo(p2)
|
||||
' If Latitud <> 0 And Longitud <> 0 Then
|
||||
' If Distance > 10 Then
|
||||
' Lat2 = Latitud
|
||||
' Lon2 = Longitud
|
||||
' Dim cp As CameraPosition
|
||||
' cp.Initialize2(Parametro.Latitude, Parametro.Longitude, gmap.CameraPosition.Zoom, Parametro.Bearing, 0)
|
||||
' gmap.AnimateCamera(cp)
|
||||
' End If
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
' If GPS.GPSEnabled = False Then
|
||||
' ToastMessageShow("Debe Activar el GPS del Equipo.", True)
|
||||
' StartActivity(GPS.LocationSettingsIntent)
|
||||
' Else
|
||||
' GPS.Start(0, 0)
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
GPS.Stop
|
||||
End Sub
|
||||
|
||||
Sub B_TODOS_Click
|
||||
todos =1
|
||||
verde = 0
|
||||
azul = 0
|
||||
rojo = 0
|
||||
MapFragment1_Ready
|
||||
End Sub
|
||||
|
||||
Sub B_VERDE_Click
|
||||
verde = 1
|
||||
azul = 0
|
||||
rojo = 0
|
||||
todos = 0
|
||||
gmap.Clear
|
||||
MapFragment1_Ready
|
||||
End Sub
|
||||
|
||||
Sub B_ROJO_Click
|
||||
rojo = 1
|
||||
verde = 0
|
||||
azul = 0
|
||||
todos = 0
|
||||
gmap.Clear
|
||||
MapFragment1_Ready
|
||||
End Sub
|
||||
|
||||
Sub B_AZUL_Click
|
||||
azul = 1
|
||||
verde = 0
|
||||
rojo = 0
|
||||
todos = 0
|
||||
gmap.Clear
|
||||
MapFragment1_Ready
|
||||
End Sub
|
||||
|
||||
|
||||
87
B4A/Mariana_Reparto.b4a.meta
Normal file
@@ -0,0 +1,87 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks10=
|
||||
ModuleBookmarks11=
|
||||
ModuleBookmarks12=
|
||||
ModuleBookmarks13=
|
||||
ModuleBookmarks14=
|
||||
ModuleBookmarks15=
|
||||
ModuleBookmarks16=
|
||||
ModuleBookmarks17=
|
||||
ModuleBookmarks18=
|
||||
ModuleBookmarks19=
|
||||
ModuleBookmarks2=
|
||||
ModuleBookmarks20=
|
||||
ModuleBookmarks21=
|
||||
ModuleBookmarks22=
|
||||
ModuleBookmarks23=
|
||||
ModuleBookmarks24=
|
||||
ModuleBookmarks25=
|
||||
ModuleBookmarks26=
|
||||
ModuleBookmarks27=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks4=
|
||||
ModuleBookmarks5=
|
||||
ModuleBookmarks6=
|
||||
ModuleBookmarks7=
|
||||
ModuleBookmarks8=
|
||||
ModuleBookmarks9=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints10=
|
||||
ModuleBreakpoints11=
|
||||
ModuleBreakpoints12=
|
||||
ModuleBreakpoints13=
|
||||
ModuleBreakpoints14=
|
||||
ModuleBreakpoints15=
|
||||
ModuleBreakpoints16=
|
||||
ModuleBreakpoints17=
|
||||
ModuleBreakpoints18=
|
||||
ModuleBreakpoints19=
|
||||
ModuleBreakpoints2=
|
||||
ModuleBreakpoints20=
|
||||
ModuleBreakpoints21=
|
||||
ModuleBreakpoints22=
|
||||
ModuleBreakpoints23=
|
||||
ModuleBreakpoints24=
|
||||
ModuleBreakpoints25=
|
||||
ModuleBreakpoints26=
|
||||
ModuleBreakpoints27=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleBreakpoints6=
|
||||
ModuleBreakpoints7=
|
||||
ModuleBreakpoints8=
|
||||
ModuleBreakpoints9=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes10=5,6,7,8,9
|
||||
ModuleClosedNodes11=
|
||||
ModuleClosedNodes12=1
|
||||
ModuleClosedNodes13=
|
||||
ModuleClosedNodes14=
|
||||
ModuleClosedNodes15=
|
||||
ModuleClosedNodes16=5,6,7,8,10,12,13,14,15,16,17,19,23,24
|
||||
ModuleClosedNodes17=4
|
||||
ModuleClosedNodes18=
|
||||
ModuleClosedNodes19=
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes20=
|
||||
ModuleClosedNodes21=
|
||||
ModuleClosedNodes22=4
|
||||
ModuleClosedNodes23=
|
||||
ModuleClosedNodes24=
|
||||
ModuleClosedNodes25=
|
||||
ModuleClosedNodes26=45,46,47,48,49,50,53,54
|
||||
ModuleClosedNodes27=2
|
||||
ModuleClosedNodes3=
|
||||
ModuleClosedNodes4=3,4,5,7,8
|
||||
ModuleClosedNodes5=
|
||||
ModuleClosedNodes6=2
|
||||
ModuleClosedNodes7=1,3
|
||||
ModuleClosedNodes8=12,13
|
||||
ModuleClosedNodes9=1,3,7,12,13,14,15
|
||||
NavigationStack=C_Principal,b_mapa_Click,1151,0,C_Principal,e_ruta_EnterPressed,1167,0,C_Principal,Subir_Click,521,0,B4XMainPage,B4XPage_CloseRequest,298,0,B4XMainPage,Class_Globals,67,0,B4XMainPage,b_envioBD_Click,317,0,appUpdater,fileProvider_init,236,6,appUpdater,Service_Destroy,235,0,B4XMainPage,B4XPage_Created,139,6,B4XMainPage,B4XPage_Appear,160,4,Main,Process_Globals,17,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=2,25,15,5,26,1,19,17
|
||||
188
B4A/Medicomed_Reparto.b4a
Normal file
@@ -0,0 +1,188 @@
|
||||
Build1=Default,reparto_medicomed.keymon.lat,HU2_PUBLIC
|
||||
File1=alert2.png
|
||||
File10=guna_viejo.png
|
||||
File11=guna_viejo2.png
|
||||
File12=historico.bal
|
||||
File13=intmex_logo_192x192.jpg
|
||||
File14=itembuttonblue.png
|
||||
File15=kelloggs.png
|
||||
File16=login.bal
|
||||
File17=logo_mariana.jpeg
|
||||
File18=logo_mariana.jpg
|
||||
File19=logomedi.jpg
|
||||
File2=cliente.bal
|
||||
File20=MainPage.bal
|
||||
File21=mapa_cliente.bal
|
||||
File22=mariana_logo_192x192.jpg
|
||||
File23=no_venta.bal
|
||||
File24=planfia_logo.png
|
||||
File25=principal.bal
|
||||
File26=proditem.bal
|
||||
File27=productos.bal
|
||||
File28=profina.jpg
|
||||
File29=PROFINA.png
|
||||
File3=clientes.bal
|
||||
File30=sync.png
|
||||
File4=dbc.png
|
||||
File5=detalleVenta.bal
|
||||
File6=durakelo1.png
|
||||
File7=engrane.jpg
|
||||
File8=fondo_kmt.jpg
|
||||
File9=foto.bal
|
||||
FileGroup1=Default Group
|
||||
FileGroup10=Default Group
|
||||
FileGroup11=Default Group
|
||||
FileGroup12=Default Group
|
||||
FileGroup13=Default Group
|
||||
FileGroup14=Default Group
|
||||
FileGroup15=Default Group
|
||||
FileGroup16=Default Group
|
||||
FileGroup17=Default Group
|
||||
FileGroup18=Default Group
|
||||
FileGroup19=Default Group
|
||||
FileGroup2=Default Group
|
||||
FileGroup20=Default Group
|
||||
FileGroup21=Default Group
|
||||
FileGroup22=Default Group
|
||||
FileGroup23=Default Group
|
||||
FileGroup24=Default Group
|
||||
FileGroup25=Default Group
|
||||
FileGroup26=Default Group
|
||||
FileGroup27=Default Group
|
||||
FileGroup28=Default Group
|
||||
FileGroup29=Default Group
|
||||
FileGroup3=Default Group
|
||||
FileGroup30=Default Group
|
||||
FileGroup4=Default Group
|
||||
FileGroup5=Default Group
|
||||
FileGroup6=Default Group
|
||||
FileGroup7=Default Group
|
||||
FileGroup8=Default Group
|
||||
FileGroup9=Default Group
|
||||
Group=Default Group
|
||||
Library1=appupdating
|
||||
Library10=googlemapsextras
|
||||
Library11=gps
|
||||
Library12=ime
|
||||
Library13=javaobject
|
||||
Library14=json
|
||||
Library15=okhttputils2
|
||||
Library16=phone
|
||||
Library17=randomaccessfile
|
||||
Library18=reflection
|
||||
Library19=runtimepermissions
|
||||
Library2=b4xpages
|
||||
Library20=serial
|
||||
Library21=sql
|
||||
Library22=togglelibrary
|
||||
Library23=xcustomlistview
|
||||
Library24=zxing_scanner
|
||||
Library25=fileprovider
|
||||
Library3=baqrcode
|
||||
Library4=byteconverter
|
||||
Library5=camera
|
||||
Library6=compressstrings
|
||||
Library7=core
|
||||
Library8=fusedlocationprovider
|
||||
Library9=googlemaps
|
||||
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.LightTheme)~\n~'End of default text.~\n~~\n~''''' CAMBIA LA CLAVE API~\n~AddApplicationText(~\n~<meta-data~\n~ android:name="com.google.android.geo.API_KEY"~\n~ android:value="AIzaSyBlBnx3O-DncOSv3oFIp-12wgujOYYcl-U"/>~\n~ <meta-data android:name="com.google.android.gms.version"~\n~ android:value="@integer/google_play_services_version" />~\n~)~\n~~\n~CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)~\n~SetApplicationAttribute(android:usesCleartextTraffic, "true")~\n~AddManifestText(<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="33" />)~\n~AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)~\n~'AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="23" />)~\n~'AddManifestText(<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="19" />)~\n~'AddManifestText(<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" android:maxSdkVersion="19" />) 'in order to access the device non-resettable identifiers such as IMEI and serial number.~\n~AddManifestText(<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />)~\n~'/////////////// FLP y FBMessageing MOD Inicia /////////////////////~\n~'CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)~\n~'CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)~\n~'CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)~\n~'CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)~\n~SetServiceAttribute(Tracker, android:foregroundServiceType, "location")~\n~'/////////////// FLP y FBMessageing MOD Termina /////////////////////~\n~~\n~'Si al cargar un mapa de google mande este error "java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion". agregar la siguiente linea:~\n~AddApplicationText(<uses-library android:name="org.apache.http.legacy" android:required="false"/>)~\n~~\n~'/////////////////////// App Updating ////////////////~\n~ AddManifestText(<uses-permission~\n~ android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="33" />~\n~ )~\n~ AddApplicationText(~\n~ <provider~\n~ android:name="android.support.v4.content.FileProvider"~\n~ android:authorities="$PACKAGE$.provider"~\n~ android:exported="false"~\n~ android:grantUriPermissions="true">~\n~ <meta-data~\n~ android:name="android.support.FILE_PROVIDER_PATHS"~\n~ android:resource="@xml/provider_paths"/>~\n~ </provider>~\n~ )~\n~ CreateResource(xml, provider_paths,~\n~ <paths>~\n~ <external-files-path name="name" path="" />~\n~ <files-path name="name" path="" />~\n~ <files-path name="name" path="shared" />~\n~ </paths>~\n~ )~\n~AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)~\n~AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)~\n~AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)~\n~AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)~\n~~\n~AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)~\n~AddPermission(android.permission.INTERNET)~\n~AddPermission(android.permission.INSTALL_PACKAGES)~\n~AddPermission(android.permission.READ_EXTERNAL_STORAGE)~\n~AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)~\n~AddPermission(android.permission.READ_PHONE_STATE)~\n~AddPermission(android.permission.WAKE_LOCK)~\n~CreateResourceFromFile(Macro, JhsIceZxing1.CaturePortrait)~\n~ ~\n~SetApplicationAttribute(android:largeHeap, "true")~\n~~\n~
|
||||
Module1=appUpdater
|
||||
Module10=C_Historico
|
||||
Module11=C_Mapas
|
||||
Module12=C_NoVenta
|
||||
Module13=C_NuevoCliente
|
||||
Module14=C_Pedidos
|
||||
Module15=C_Principal
|
||||
Module16=C_Productos
|
||||
Module17=C_tabulador
|
||||
Module18=C_TicketsDia
|
||||
Module19=C_UpdateAvailable
|
||||
Module2=|relative|..\B4XMainPage
|
||||
Module20=CameraExClass
|
||||
Module21=DBRequestManager
|
||||
Module22=foto
|
||||
Module23=MAPA_CLIENTE
|
||||
Module24=MAPA_RUTAS
|
||||
Module25=Starter
|
||||
Module26=Subs
|
||||
Module27=Tracker
|
||||
Module3=BatteryUtilities
|
||||
Module4=C_Buscar
|
||||
Module5=C_Cliente
|
||||
Module6=C_Clientes
|
||||
Module7=C_Detalle_Promo
|
||||
Module8=C_DetalleVenta
|
||||
Module9=C_Foto
|
||||
NumberOfFiles=30
|
||||
NumberOfLibraries=25
|
||||
NumberOfModules=27
|
||||
Version=12.2
|
||||
@EndOfDesignText@
|
||||
#Region Project Attributes
|
||||
#ApplicationLabel: Medicomed Reparto
|
||||
#VersionCode: 1
|
||||
#VersionName: 3.06.15
|
||||
'SupportedOrientations possible values: unspecified, landscape or portrait.
|
||||
#SupportedOrientations: portrait
|
||||
#CanInstallToExternalStorage: False
|
||||
#AdditionalJar: com.android.support:support-v4
|
||||
#AdditionalJar: com.google.android.gms:play-services-location
|
||||
#BridgeLogger: True
|
||||
#End Region
|
||||
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: True
|
||||
#End Region
|
||||
|
||||
Sub Process_Globals
|
||||
Public ActionBarHomeClicked As Boolean
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
Dim pm As B4XPagesManager
|
||||
pm.Initialize(Activity)
|
||||
End Sub
|
||||
|
||||
'Template version: B4A-1.01
|
||||
#Region Delegates
|
||||
|
||||
Sub Activity_ActionBarHomeClick
|
||||
ActionBarHomeClicked = True
|
||||
B4XPages.Delegate.Activity_ActionBarHomeClick
|
||||
ActionBarHomeClicked = False
|
||||
End Sub
|
||||
|
||||
Sub Activity_KeyPress (KeyCode As Int) As Boolean
|
||||
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
B4XPages.Delegate.Activity_Resume
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
B4XPages.Delegate.Activity_Pause
|
||||
End Sub
|
||||
|
||||
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
|
||||
End Sub
|
||||
|
||||
Sub Create_Menu (Menu As Object)
|
||||
B4XPages.Delegate.Create_Menu(Menu)
|
||||
End Sub
|
||||
|
||||
#if Java
|
||||
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
|
||||
processBA.raiseEvent(null, "create_menu", menu);
|
||||
return true;
|
||||
}
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
'Program code should go into B4XMainPage and other pages.
|
||||
87
B4A/Medicomed_Reparto.b4a.meta
Normal file
@@ -0,0 +1,87 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks10=
|
||||
ModuleBookmarks11=
|
||||
ModuleBookmarks12=
|
||||
ModuleBookmarks13=
|
||||
ModuleBookmarks14=
|
||||
ModuleBookmarks15=
|
||||
ModuleBookmarks16=
|
||||
ModuleBookmarks17=
|
||||
ModuleBookmarks18=
|
||||
ModuleBookmarks19=
|
||||
ModuleBookmarks2=
|
||||
ModuleBookmarks20=
|
||||
ModuleBookmarks21=
|
||||
ModuleBookmarks22=
|
||||
ModuleBookmarks23=
|
||||
ModuleBookmarks24=
|
||||
ModuleBookmarks25=
|
||||
ModuleBookmarks26=
|
||||
ModuleBookmarks27=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks4=
|
||||
ModuleBookmarks5=
|
||||
ModuleBookmarks6=
|
||||
ModuleBookmarks7=
|
||||
ModuleBookmarks8=
|
||||
ModuleBookmarks9=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints10=
|
||||
ModuleBreakpoints11=
|
||||
ModuleBreakpoints12=
|
||||
ModuleBreakpoints13=
|
||||
ModuleBreakpoints14=
|
||||
ModuleBreakpoints15=
|
||||
ModuleBreakpoints16=
|
||||
ModuleBreakpoints17=
|
||||
ModuleBreakpoints18=
|
||||
ModuleBreakpoints19=
|
||||
ModuleBreakpoints2=
|
||||
ModuleBreakpoints20=
|
||||
ModuleBreakpoints21=
|
||||
ModuleBreakpoints22=
|
||||
ModuleBreakpoints23=
|
||||
ModuleBreakpoints24=
|
||||
ModuleBreakpoints25=
|
||||
ModuleBreakpoints26=
|
||||
ModuleBreakpoints27=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleBreakpoints6=
|
||||
ModuleBreakpoints7=
|
||||
ModuleBreakpoints8=
|
||||
ModuleBreakpoints9=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes10=
|
||||
ModuleClosedNodes11=
|
||||
ModuleClosedNodes12=
|
||||
ModuleClosedNodes13=
|
||||
ModuleClosedNodes14=
|
||||
ModuleClosedNodes15=
|
||||
ModuleClosedNodes16=
|
||||
ModuleClosedNodes17=
|
||||
ModuleClosedNodes18=
|
||||
ModuleClosedNodes19=
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes20=
|
||||
ModuleClosedNodes21=
|
||||
ModuleClosedNodes22=
|
||||
ModuleClosedNodes23=
|
||||
ModuleClosedNodes24=
|
||||
ModuleClosedNodes25=
|
||||
ModuleClosedNodes26=
|
||||
ModuleClosedNodes27=
|
||||
ModuleClosedNodes3=
|
||||
ModuleClosedNodes4=
|
||||
ModuleClosedNodes5=
|
||||
ModuleClosedNodes6=
|
||||
ModuleClosedNodes7=
|
||||
ModuleClosedNodes8=
|
||||
ModuleClosedNodes9=
|
||||
NavigationStack=appUpdater,Process_Globals,74,0,B4XMainPage,B4XPage_Created,80,1,Diseñador Visual,principal.bal,-100,1,B4XMainPage,Entrar_Click,182,0,C_tabulador,Class_Globals,0,0,C_tabulador,b_guardar_Click,82,1,C_Clientes,Mods,0,0,C_Cliente,Class_Globals,0,0,C_Principal,Class_Globals,0,0,C_Principal,cargar_Click,656,0,MAPA_RUTAS,MapFragment1_Ready,147,2
|
||||
SelectedBuild=0
|
||||
VisibleModules=1,2,3,4,5,6,7,8,9,10,15,23,24
|
||||
154
B4A/Starter.bas
Normal file
@@ -0,0 +1,154 @@
|
||||
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 rp As RuntimePermissions
|
||||
Public FLP As FusedLocationProvider
|
||||
Private flpStarted As Boolean
|
||||
Dim skmt As SQL
|
||||
Dim ruta As String
|
||||
Private BTAdmin As BluetoothAdmin
|
||||
Public BluetoothState As Boolean
|
||||
Dim Timer1 As Timer
|
||||
Dim Interval As Int = 300
|
||||
'Para WebSockets
|
||||
' Dim monitor As Timer 'Lo usamos para monitorear los servicios Tracker y PushService
|
||||
' Dim monitorTicks As Int = 0
|
||||
Dim trackerActividad As String = "501231235959"
|
||||
Dim pushServiceActividad As String = "501231235959"
|
||||
'Para los Logs
|
||||
Private logs As StringBuilder
|
||||
Private logcat As LogCat
|
||||
Public SharedFolder As String 'Para actualizar apk
|
||||
Dim cedisLocation As Location
|
||||
Dim reqManager As DBRequestManager
|
||||
Dim server As String = "http://187.189.244.154:1783"
|
||||
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.
|
||||
ruta = File.DirInternal 'Ruta de la base de datos por defecto.
|
||||
' If File.ExternalWritable Then ruta = rp.GetSafeDirDefaultExternal("") 'Si podemos escribir a la tarjeta, cambiamos la ruta.
|
||||
If Not(File.Exists(ruta, "kmt.db")) Then File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db") 'Si no existe el archivo de la base de datos, lo copiamos.
|
||||
Log(ruta)
|
||||
skmt.Initialize(ruta,"kmt.db", True)
|
||||
' CallSubDelayed(PushService, "SubscribeToTopics")
|
||||
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
|
||||
' BTAdmin.Initialize("admin")
|
||||
' If BTAdmin.IsEnabled = False Then
|
||||
' If BTAdmin.Enable = False Then
|
||||
' ToastMessageShow("Error enabling Bluetooth adapter.", True)
|
||||
' Else
|
||||
' ToastMessageShow("Enabling Bluetooth adapter...", False)
|
||||
' End If
|
||||
' Else
|
||||
' BluetoothState = True
|
||||
' End If
|
||||
' reqManager.Initialize(Me, Main.server)
|
||||
Timer1.Initialize("Timer1", Interval * 1000)
|
||||
Timer1.Enabled = True
|
||||
SharedFolder = rp.GetSafeDirDefaultExternal("")
|
||||
cedisLocation.Initialize
|
||||
cedisLocation.Latitude = "19.48118148992086"
|
||||
cedisLocation.Longitude = "-99.15295579261536"
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
|
||||
' StartService(PushService)
|
||||
' monitor.Initialize("monitor", 30000)
|
||||
' monitor.Enabled = True
|
||||
End Sub
|
||||
|
||||
Sub Service_TaskRemoved
|
||||
'This event will be raised when the user removes the app from the recent apps list.
|
||||
End Sub
|
||||
|
||||
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
|
||||
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
|
||||
Return True
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub Timer1_Tick
|
||||
' ToastMessageShow("Timer",False)
|
||||
' LogColor("Siguiente actualizacion " & DateTime.Time(DateTime.Now + Interval * 1000),Colors.Blue)
|
||||
ENVIA_ULTIMA_GPS
|
||||
End Sub
|
||||
|
||||
Sub ENVIA_ULTIMA_GPS
|
||||
If IsConnectedToInternet Then
|
||||
Log("Con internet, enviamos UTR!")
|
||||
Dim skmt As SQL
|
||||
Dim cmd As DBCommand
|
||||
Dim reqManager As DBRequestManager
|
||||
reqManager.Initialize(Me, server)
|
||||
' LogColor($"ReqServer = ${server}"$, Colors.red)
|
||||
skmt.Initialize(ruta,"kmt.db", True)
|
||||
' Log("server: "&Main.server)
|
||||
skmt.Initialize(ruta,"kmt.db", True)
|
||||
If B4XPages.MainPage.logger Then LogColor("Iniciamos ENVIA_ULTIMA_GPS", Colors.red)
|
||||
DateTime.TimeFormat = "HHmmss"
|
||||
B4XPages.MainPage.ultimaActualizacionGPS = DateTime.Time(DateTime.Now)
|
||||
cmd.Initialize
|
||||
cmd.Name = "select_fechat_medi"
|
||||
reqManager.ExecuteQuery(cmd , 0, "fechat")
|
||||
|
||||
Dim cmd As DBCommand
|
||||
cmd.Initialize
|
||||
cmd.Name = "UPDATE_MEDI_ACTUALR3_GPS"
|
||||
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, B4XPages.MainPage.montoRechazado, B4XPages.MainPage.montoEntregado, B4XPages.MainPage.clientestotal, B4XPages.MainPage.porVisitar, B4XPages.MainPage.entregas, B4XPages.MainPage.rechazos, Application.VersionName, B4XPages.MainPage.ALMACEN, B4XPages.MainPage.rutapreventa )
|
||||
If B4XPages.MainPage.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}, montoRechazado: ${B4XPages.MainPage.montoRechazado}, montoEntregado: ${B4XPages.MainPage.montoEntregado}, porVisitar: ${B4XPages.MainPage.porVisitar}, entregas: ${B4XPages.MainPage.entregas}, rechazos: ${B4XPages.MainPage.rechazos}, 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 otra actividad
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
871
B4A/Subs.bas
Normal file
@@ -0,0 +1,871 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=StaticCode
|
||||
Version=11
|
||||
@EndOfDesignText@
|
||||
'Code module
|
||||
'Subs in this code module will be accessible from all modules.
|
||||
Sub Process_Globals
|
||||
'These global variables will be declared once when the application starts.
|
||||
'These variables can be accessed from all modules.
|
||||
Public GZip As GZipStrings
|
||||
Private su As StringUtils
|
||||
Dim phn As Phone
|
||||
Dim devModel As String
|
||||
Dim kmt, errorLog As SQL 'Requiere la libreria "SQL"
|
||||
' Dim wifi As MLwifi
|
||||
Dim ssid As String 'ignore
|
||||
Dim rutaMaxPoints As Int = 3000
|
||||
Dim rutaHrsAtras As Int = 48
|
||||
' Dim rutaInicioHoy As String = ""
|
||||
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
|
||||
|
||||
'Comprime y regresa un texto (str) en base64
|
||||
Sub compress(str As String) As String 'ignore
|
||||
'Requiere la libreria "CompressStrings"
|
||||
Dim compressed() As Byte = GZip.compress(str)
|
||||
' Log($"UncompressedBytesLength: ${str.Length}"$)
|
||||
' Log($"CompressedBytesLength: ${compressed.Length}"$)
|
||||
Dim base64 As String = su.EncodeBase64(compressed)
|
||||
Log($"Comprimido: ${base64.Length}"$)
|
||||
' Log($"CompressedBytes converted to base64: ${base64}"$)
|
||||
Return base64
|
||||
End Sub
|
||||
|
||||
'Descomprime y regresa un texto en base64
|
||||
Sub decompress(base64 As String) As String 'ignore
|
||||
Dim decompressedbytes() As Byte = su.DecodeBase64(base64)
|
||||
' Log($"decompressedbytesLength: ${decompressedbytes.Length}"$)
|
||||
Dim bc As ByteConverter
|
||||
Dim uncompressed As String = bc.StringFromBytes(decompressedbytes,"UTF8")
|
||||
Log($"Descomprimido: ${uncompressed.Length}"$)
|
||||
' Log($"Decompressed String = ${uncompressed}"$)
|
||||
Return uncompressed
|
||||
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
|
||||
|
||||
'Trae un string con hora, minutos y segundos - HHmmss
|
||||
Sub hmsKMT As String 'ignore
|
||||
' Log(fecha)
|
||||
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||
DateTime.DateFormat="HHmmss"
|
||||
Private nuevaHora As String=DateTime.Date(DateTime.Now)
|
||||
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||
' Log(nuevaFecha)
|
||||
Return nuevaHora
|
||||
End Sub
|
||||
|
||||
'Genera una notificacion con importancia alta
|
||||
Sub notiHigh(title As String, body As String, activity As Object) 'ignore
|
||||
Private notif As Notification
|
||||
notif.Initialize2(notif.IMPORTANCE_HIGH)
|
||||
notif.Icon = "icon"
|
||||
notif.Vibrate = False
|
||||
notif.Sound = False
|
||||
notif.AutoCancel = True
|
||||
Log("notiHigh: "&title)
|
||||
notif.SetInfo(title, body, activity)
|
||||
' Log("notiHigh SetInfo")
|
||||
notif.Notify(777)
|
||||
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
|
||||
|
||||
'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
|
||||
If B4XPages.MainPage.logger Then 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 Main.Logger Then Log("LatLon="&latlon)
|
||||
If Not(kmt.IsInitialized) Then revisaBD
|
||||
kmt.ExecNonQuery2("INSERT INTO RUTA_GPS(fecha, lat, lon) VALUES (?,?,?)", Array As Object (latlon(2),latlon(0),latlon(1)))
|
||||
Catch
|
||||
Log(LastException)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'Regresa la ruta solicitada comprimida y en base64
|
||||
Sub dameRuta(inicioRuta As String, origenRuta As String) As String 'ignore
|
||||
'Requiere la libreria "SQL"
|
||||
Dim fechaInicio As String
|
||||
Try 'incioRuta es numero
|
||||
inicioRuta = inicioRuta * 1
|
||||
' Log("fechaInicio numerica="&fechaInicio)
|
||||
fechaInicio = fechaKMT(DateTime.Now - (DateTime.TicksPerHour * inicioRuta))
|
||||
Catch 'inicioRuta es string
|
||||
fechaInicio = fechaInicioHoy
|
||||
' Log("fechaInicio string="&fechaInicio)
|
||||
End Try
|
||||
If B4XPages.MainPage.logger Then Log("fechaInicio: "&fechaInicio&" | rutaHrsAtras="&rutaHrsAtras) 'fechaKMT(DateTime.Now)
|
||||
Dim c As Cursor
|
||||
If kmt.IsInitialized = False Then kmt.Initialize(Starter.ruta, "kmt.db", True)
|
||||
If B4XPages.MainPage.logger Then Log("select FECHA, LAT, LON from "& origenRuta &" where FECHA > " & fechaInicio & " order by FECHA desc limit " & rutaMaxPoints)
|
||||
c = kmt.ExecQuery("select FECHA, LAT, LON from "& origenRuta &" where FECHA > " & fechaInicio & " order by FECHA desc limit " & rutaMaxPoints)
|
||||
c.Position = 0
|
||||
Dim ruta2 As String = ""
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
ruta2=ruta2&CRLF&c.GetString("LAT")&","&c.GetString("LON")&","&c.GetString("FECHA")
|
||||
B4XPages.MainPage.fechaRuta = c.GetString("FECHA")
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
Return compress(ruta2)
|
||||
End Sub
|
||||
|
||||
'Limpiamos la tabla RUTA_GPS de la BD
|
||||
Sub deleteGPS_DB 'ignore
|
||||
kmt.ExecNonQuery("delete from RUTA_GPS")
|
||||
kmt.ExecNonQuery("vacuum;")
|
||||
End Sub
|
||||
|
||||
'Limpiamos la tabla errorLog de la BD
|
||||
Sub deleteErrorLog_DB 'ignore
|
||||
If Not(errorLog.IsInitialized) Then revisaBD
|
||||
errorLog.ExecNonQuery("delete from errores")
|
||||
errorLog.ExecNonQuery("vacuum;")
|
||||
ToastMessageShow("Borrada", False)
|
||||
End Sub
|
||||
|
||||
'Borramos el archio "gps.txt"
|
||||
Sub borramosArchivoGPS 'ignore
|
||||
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "gps.txt", False)
|
||||
Dim s As String = ""
|
||||
Dim t() As Byte = s.GetBytes("UTF-8")
|
||||
out.WriteBytes(t, 0, t.Length)
|
||||
out.Close
|
||||
End Sub
|
||||
|
||||
'Revisa que exista la BD y si es necesario crea algunas tablas dentro de ella
|
||||
Sub revisaBD 'ignore
|
||||
If Not(File.Exists(Starter.ruta, "kmt.db")) Then File.Copy(File.DirAssets, "kmt.db", Starter.ruta, "kmt.db")
|
||||
If Not(kmt.IsInitialized) Then kmt.Initialize(Starter.ruta, "kmt.db", True)
|
||||
kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(FECHA INTEGER, LAT TEXT, LON TEXT)")
|
||||
' kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS UUC(fecha INTEGER, lat TEXT, lon TEXT)") 'LastKnownLocation
|
||||
kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS bitacora(fecha INTEGER, texto TEXT)") 'Bitacora
|
||||
'Tabla para la bitacora de errores
|
||||
If Not(errorLog.IsInitialized) Then errorLog.Initialize(Starter.ruta, "errorLog.db", True)
|
||||
errorLog.ExecNonQuery("CREATE TABLE IF NOT EXISTS errores(fecha INTEGER, error TEXT)")
|
||||
End Sub
|
||||
|
||||
'Obtiene el ssid al que esta conectado el telefono
|
||||
Sub getSSID 'ignore
|
||||
' 'Requiere la libreria "MLWifi400"
|
||||
' If wifi.isWifiConnected Then
|
||||
' ssid = wifi.WifiSSID
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
'Convierte un texto en formato JSON a un objeto "Map"
|
||||
Sub JSON2Map(theJson As String) As Map 'ignore
|
||||
'Requiere la libreria "JSON"
|
||||
Try
|
||||
Private json As JSONParser
|
||||
json.Initialize(theJson)
|
||||
Return json.NextObject
|
||||
Catch
|
||||
Log(LastException)
|
||||
log2DB("JSON2Map: "&LastException)
|
||||
Private m As Map = CreateMap("title":"Error generating JSON", "t":"Error", "Message":LastException, "text" : LastException)
|
||||
Return m
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'Convierte un mapa a formato JSON
|
||||
Sub map2JSON(m As Map) As String 'ignore
|
||||
'Requiere la libreria "JSON"
|
||||
'Convierte un objecto "Map" a JSON
|
||||
Dim jg As JSONGenerator
|
||||
jg.Initialize(m)
|
||||
Dim t As String = jg.ToString
|
||||
Return t
|
||||
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)
|
||||
' 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.Magenta)
|
||||
If kmt.IsInitialized Then 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
|
||||
' 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
|
||||
|
||||
'Compara la UUG (Ultima Ubicacion Guardada) con FLP.LastKnowLocation y si
|
||||
'cumple con los requisitos de distancia y precision la guardamos en la BD.
|
||||
Sub revisaUUG 'ignore
|
||||
revisaFLP
|
||||
If Tracker.FLP.GetLastKnownLocation.IsInitialized Then
|
||||
Dim daa As Int = Tracker.UUGCoords.DistanceTo(Tracker.FLP.GetLastKnownLocation) 'Distancia de la UUG a la actual de Tracker.FLP.GetLastKnownLocation
|
||||
If B4XPages.MainPage.Logger Then LogColor($"**** UUC "${fechaKMT(Tracker.FLP.GetLastKnownLocation.Time)}|$0.2{Tracker.FLP.GetLastKnownLocation.Accuracy}|$0.8{Tracker.FLP.GetLastKnownLocation.Latitude}|$0.8{Tracker.FLP.GetLastKnownLocation.Longitude}|$0.2{Tracker.FLP.GetLastKnownLocation.Speed}|"$, Colors.RGB(255,112,35))
|
||||
If daa > 40 And Tracker.FLP.GetLastKnownLocation.Accuracy < 35 Then 'Si la distancia de la ubicacion anterior es mayor de XX y la precision es menor de XX, la guardamos ...
|
||||
kmt.ExecNonQuery2("INSERT INTO RUTA_GPS(fecha, lat, lon) VALUES (?,?,?)", Array As Object (fechaKMT(Tracker.FLP.GetLastKnownLocation.Time),Tracker.FLP.GetLastKnownLocation.Latitude,Tracker.FLP.GetLastKnownLocation.Longitude))
|
||||
If B4XPages.MainPage.Logger Then Log("++++ Distancia a anterior="&daa&"|"&"Precision="&Tracker.FLP.GetLastKnownLocation.Accuracy)
|
||||
End If
|
||||
Tracker.UUGCoords = Tracker.FLP.GetLastKnownLocation
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Revisamos que el FLP (FusedLocationProvider) este inicializado y activo
|
||||
Sub revisaFLP 'ignore
|
||||
LogColor($"**** **** Revisamos FLP - ${fechaKMT(DateTime.Now)}**** ****"$, Colors.RGB(78,0,227))
|
||||
Private todoBienFLP As Boolean = True
|
||||
If Not(Tracker.FLP.IsInitialized) Then
|
||||
log2DB("revisaFLP: No esta inicializado ... 'Reinicializando FLP'")
|
||||
Tracker.FLP.Initialize("flp")
|
||||
todoBienFLP = False
|
||||
End If
|
||||
If Tracker.FLP.IsInitialized Then
|
||||
If Not(Tracker.FLP.IsConnected) Then
|
||||
log2DB("revisaFLP: No esta conectado ... 'Reconectando FLP'")
|
||||
' Tracker.FLP.Connect
|
||||
CallSubDelayed(Tracker,"StartFLP")
|
||||
todoBienFLP = False
|
||||
End If
|
||||
If Tracker.FLP.IsConnected And _
|
||||
Tracker.FLP.GetLastKnownLocation.IsInitialized And _
|
||||
Tracker.FLP.GetLastKnownLocation.DistanceTo(Tracker.UUGCoords) > 500 Then
|
||||
log2DB("revisaFLP: 'No se esta actualizando, lo reiniciamos ...'")
|
||||
StartService(Tracker)
|
||||
todoBienFLP = False
|
||||
End If
|
||||
End If
|
||||
If todoBienFLP Then LogColor(" +++ +++ Sin errores en FLP", Colors.Green)
|
||||
' revisar hora de lastKnownlocation y si es mayor de 10 minutos llamar StartFLP
|
||||
End Sub
|
||||
|
||||
'Revisamos que el servicio "PushService" este inicializado y activo
|
||||
Sub revisaPushService 'ignore
|
||||
' Private todoBienPS As Boolean = True
|
||||
'' LogColor("**** **** Revisamos PushService **** ****", Colors.RGB(78,0,227))
|
||||
' Try
|
||||
' If Not(PushService.wsh.IsInitialized) Then 'Si no esta inicializado ...
|
||||
' log2DB("revisaPushService: No esta inicializado ... 'Reinicializando PushService'")
|
||||
' CallSubDelayed(PushService, "Connect")
|
||||
' todoBienPS = False
|
||||
' End If
|
||||
' Catch
|
||||
' Log(LastException)
|
||||
' insertaEnErrores("Subs.revisaPushService: Reiniciando - "&LastException)
|
||||
' End Try
|
||||
' Try
|
||||
' If Not(PushService.wsh.ws.Connected) Then 'Si no esta conectado ...
|
||||
' log2DB("revisaPushService: No esta conectado ... 'Reconectando PushService'")
|
||||
' CallSubDelayed(PushService, "Connect")
|
||||
' todoBienPS = False
|
||||
' End If
|
||||
' Catch
|
||||
' Log(LastException)
|
||||
' insertaEnErrores("Subs.revisaPushService: Reconectando - "&LastException)
|
||||
' End Try
|
||||
' Try
|
||||
' If masDeXXMinsKMT(Starter.pushServiceActividad, 5) Then 'Si mas de xx minutos de la ultima actividad entonces ...
|
||||
' PushService.wsh.Close
|
||||
' CallSubDelayed(PushService, "Connect")
|
||||
' ' StartService(PushService)
|
||||
' ' If Main.Logger Then Log("Ultima act: "&Starter.pushServiceActividad)
|
||||
' log2DB("revisaPushService: 'Reconectamos 'PushService' por inactividad")
|
||||
' Starter.pushServiceActividad = fechaKMT(DateTime.Now)
|
||||
' todoBienPS = False
|
||||
' End If
|
||||
' Catch
|
||||
' Log(LastException)
|
||||
' insertaEnErrores("Subs.revisaPushService: Reconectando por inactividad - "&LastException)
|
||||
' End Try
|
||||
' If todoBienPS Then LogColor(" +++ +++ Sin errores en PushService", Colors.Green)
|
||||
End Sub
|
||||
|
||||
'Borramos renglones extra de la tabla de errores
|
||||
Sub borraArribaDe100Errores 'ignore
|
||||
If Not(errorLog.IsInitialized) Then revisaBD
|
||||
LogColor("Recortamos la tabla de Errores, limite de 100", Colors.Magenta)
|
||||
errorLog.ExecNonQuery("DELETE FROM errores WHERE fecha NOT in (SELECT fecha FROM errores ORDER BY fecha desc LIMIT 99 )")
|
||||
errorLog.ExecNonQuery("vacuum;")
|
||||
' Log("Borramos mas de 100 de errorLog")
|
||||
End Sub
|
||||
|
||||
'Borramos renglones extra de la tabla de bitacora
|
||||
Sub borraArribaDe600RenglonesBitacora 'ignore
|
||||
revisaBD
|
||||
LogColor("Recortamos la tabla de la Bitacora, limite de 600", Colors.Magenta)
|
||||
Private c As Cursor
|
||||
c = kmt.ExecQuery("select fecha from bitacora")
|
||||
c.Position = 0
|
||||
If c.RowCount > 650 Then
|
||||
kmt.ExecNonQuery("DELETE FROM bitacora WHERE fecha NOT in (SELECT fecha FROM bitacora ORDER BY fecha desc LIMIT 599 )")
|
||||
kmt.ExecNonQuery("vacuum;")
|
||||
' Log("Borramos mas de 600 de bitacora")
|
||||
End If
|
||||
c.Close
|
||||
End Sub
|
||||
|
||||
'Inserta 50 renglones de prueba a la tabla "errores"
|
||||
Sub insertaRenglonesPruebaEnErrorLog 'ignore
|
||||
If Not(errorLog.IsInitialized) Then revisaBD
|
||||
Log("insertamos 50 renglones a errorLog")
|
||||
For x = 1 To 50
|
||||
errorLog.ExecNonQuery2("INSERT INTO errores(fecha, error) VALUES (?,?)", Array As Object (fechaKMT(DateTime.now), "abc"))
|
||||
Log(x)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'Regresa la tabla "errores" en una lista de mapas convertida a JSON
|
||||
Sub dameErroresJSON(SQL As SQL, maxErrores As Int, comprimido As Boolean) As String 'ignore
|
||||
Log("dameErroresJSON")
|
||||
Private j As JSONGenerator
|
||||
Private lim As String
|
||||
Private cur As ResultSet
|
||||
Private l As List
|
||||
Private i As Int = 0
|
||||
l.Initialize
|
||||
Dim m, m2 As Map
|
||||
m2.Initialize
|
||||
If maxErrores = 0 Then lim = "" Else lim = "limit "&maxErrores
|
||||
cur = SQL.ExecQuery("select * from errores order by fecha desc "&lim)
|
||||
Do While cur.NextRow
|
||||
m.Initialize
|
||||
m.Put("fecha", cur.GetString("fecha"))
|
||||
m.Put("error", cur.GetString("error"))
|
||||
m2.Put(i,m)
|
||||
i = i + 1
|
||||
Loop
|
||||
cur.Close
|
||||
j.Initialize(m2)
|
||||
Log(j.ToString)
|
||||
If comprimido Then
|
||||
Return compress(j.ToString)
|
||||
Else
|
||||
Return j.ToString
|
||||
End If
|
||||
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)
|
||||
' Log(" +++ +++ pFecha:"&parteFecha&" | pHora:"&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
|
||||
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,"guna_rep_kmt.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 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
|
||||
|
||||
Sub insertaEnErrores(error As String) 'ignore
|
||||
If Not(errorLog.IsInitialized) Then revisaBD
|
||||
errorLog.ExecNonQuery2("INSERT INTO errores(fecha, error) VALUES (?,?)", Array As Object (fechaKMT(DateTime.now), error))
|
||||
End Sub
|
||||
|
||||
'Saca el usuario de la tabla USUARIOA
|
||||
Sub dameUsuarioDeDB As String 'ignore
|
||||
Private c As Cursor
|
||||
Private u As String = "SinUsuario"
|
||||
If Not(kmt.IsInitialized) Then revisaBD
|
||||
c=kmt.ExecQuery("select USUARIO from usuarioa")
|
||||
c.Position=0
|
||||
If c.RowCount > 0 Then u = c.GetString("USUARIO")
|
||||
c.Close
|
||||
Return u
|
||||
End Sub
|
||||
|
||||
Sub SetDivider(lv As ListView, Color As Int, Height As Int) 'ignore
|
||||
Dim r As Reflector
|
||||
r.Target = lv
|
||||
Dim CD As ColorDrawable
|
||||
CD.Initialize(Color, 0)
|
||||
r.RunMethod4("setDivider", Array As Object(CD), Array As String("android.graphics.drawable.Drawable"))
|
||||
r.RunMethod2("setDividerHeight", Height, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
'Centra un listview dentro de un elemento superior
|
||||
Sub centraListView(elemento As ListView, anchoElementoSuperior As Int) 'ignore
|
||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||
End Sub
|
||||
|
||||
'Centra un panel 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 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 boton dentro de un elemento superior
|
||||
Sub centraBoton(elemento As Button, anchoElementoSuperior As Int) 'ignore
|
||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||
End Sub
|
||||
|
||||
'Trae el nombre del producto con ID dado, desde HIST_VENTAS.
|
||||
Sub traeNombre(id As String) As String
|
||||
Private nombre As String
|
||||
Private idc As Cursor = kmt.ExecQuery($"select HVD_PRONOMBRE from HIST_VENTAS where HVD_PROID = '${id}'"$)
|
||||
idc.Position=0
|
||||
If idc.RowCount > 0 Then nombre = idc.GetString("HVD_PRONOMBRE")
|
||||
idc.Close
|
||||
' Log("NOMBRE=" & nombre)
|
||||
Return nombre
|
||||
End Sub
|
||||
|
||||
'Trae el precio del ID dado, desde CAT_GUNAPROD o HIST_VENTAS, dependiendo de si es promoción o no.
|
||||
Sub traePrecio(id As String, quePromo As String) As String
|
||||
Private pu As String = "0"
|
||||
If quePromo = "1" Then
|
||||
Private idc As Cursor = kmt.ExecQuery($"select CAT_GP_PRECIO from CAT_GUNAPROD where CAT_GP_ID = '${id}'"$)
|
||||
If idc.RowCount > 0 Then
|
||||
idc.Position=0
|
||||
If idc.RowCount > 0 And IsNumber(idc.GetString("CAT_GP_PRECIO")) Then pu = idc.GetString("CAT_GP_PRECIO")
|
||||
' Log("id=" & id & "|p=" & x & "|" & idc.GetString("CAT_GP_PRECIO"))
|
||||
End If
|
||||
idc.Close
|
||||
Else 'Si es una promo, entonces sacamos el costo total del producto en la promo de HIST_VENTAS2 y lo dividimos entre la cantidad.
|
||||
Private pc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT, HVD_COSTO_TOT from HIST_VENTAS2 where HVD_CLIENTE in (select cuenta from cuentaa) and HVD_PROID = '${id}' and HVD_CODPROMO = '${quePromo}'"$)
|
||||
If pc.RowCount > 0 Then
|
||||
pc.Position = 0
|
||||
If pc.GetString("HVD_COSTO_TOT")<> Null And pc.GetString("HVD_CANT") <> Null Then
|
||||
pu = pc.GetString("HVD_COSTO_TOT") / pc.GetString("HVD_CANT")
|
||||
End If
|
||||
End If
|
||||
pc.Close
|
||||
End If
|
||||
Return pu
|
||||
End Sub
|
||||
|
||||
'Trae el cliente desde la BD.
|
||||
Sub traeCliente As String 'ignore
|
||||
Private cli As Cursor = Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
|
||||
cli.Position = 0
|
||||
Private cl As String = cli.GetString("CUENTA")
|
||||
cli.Close
|
||||
Return cl
|
||||
End Sub
|
||||
|
||||
Sub traeFechaReparto As String
|
||||
Private fe As Cursor = Starter.skmt.ExecQuery("select HVD_FECHA from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
|
||||
Private f As String = "-"
|
||||
If fe.RowCount > 0 Then
|
||||
fe.Position = 0
|
||||
f = fe.GetString("HVD_FECHA")
|
||||
End If
|
||||
fe.Close
|
||||
Return f
|
||||
End Sub
|
||||
|
||||
'Trae de la tabla Reparto,la cantidad rechazada de un producto dado de un cliente dado.
|
||||
Sub traeCantidadRechazada(cliente As String, prodId As String) As Int
|
||||
Private cant As Int = 0
|
||||
Private cr As Cursor = Starter.skmt.ExecQuery($"Select rep_cliente, rep_prodid, REP_CANT, REP_RECHAZO from reparto where rep_cliente = '${cliente}' and rep_prodid = '${prodId}' and REP_RECHAZO = 1"$)
|
||||
If cr.RowCount > 0 Then
|
||||
cr.Position = 0
|
||||
cant = cr.GetString("REP_CANT")
|
||||
End If
|
||||
Log($"${cliente}, ${prodId}, rowcont:${cr.RowCount}, cant: ${cant}"$)
|
||||
Return cant
|
||||
End Sub
|
||||
|
||||
'Trae de la tabla Reparto,la cantidad vendida de un producto dado de un cliente dado.
|
||||
Sub traeCantidadVendida(cliente As String, prodId As String) As Int
|
||||
Private cant As Int = 0
|
||||
Private cr As Cursor = Starter.skmt.ExecQuery($"Select rep_cliente, rep_prodid, REP_CANT, REP_RECHAZO from reparto where rep_cli_orig = '${cliente}' and rep_prodid = '${prodId}' and REP_RECHAZO = 0 and REP_CANT > 0"$)
|
||||
' Log($"${cliente}, ${prodId}, rowcont:${cr.RowCount}"$)
|
||||
If cr.RowCount > 0 Then
|
||||
cr.Position = 0
|
||||
cant = cr.GetString("REP_CANT")
|
||||
End If
|
||||
Return cant
|
||||
End Sub
|
||||
|
||||
'Trae la cantidad desde la tabla hist_ventas2, del producto dado, del cliente dado.
|
||||
Sub traeMaxCantidad(cliente As String, prodId As String) As Int
|
||||
Private cant As Int = 0
|
||||
Private cr As Cursor = Starter.skmt.ExecQuery($"Select hvd_cant from hist_ventas2 where hvd_cliente = '${cliente}' and hvd_proid = '${prodId}'"$)
|
||||
' Log($"${cliente}, ${prodId}, rowcont:${cr.RowCount}"$)
|
||||
If cr.RowCount > 0 Then
|
||||
cr.Position = 0
|
||||
cant = cr.GetString("HVD_CANT")
|
||||
End If
|
||||
Return cant
|
||||
End Sub
|
||||
|
||||
'Ponemos venta de producto en la tabla de Reparto.
|
||||
Sub prodVenta(clienteOriginal As String, prodId As String)
|
||||
' Log("RECHAZO VENTA")
|
||||
Private precio As String = traePrecio(prodId, 1)
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
|
||||
Log($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
|
||||
Log($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_COSTO_TOT = REP_CANT * ${precio}, REP_PRECIO = '${precio}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
|
||||
|
||||
' Private pu As String = 0
|
||||
' Private cant As Int = 0
|
||||
' Private pc As Cursor = Starter.skmt.ExecQuery($"select (HVD_COSTO_TOT / HVD_CANT) as PU, HVD_CANT from HIST_VENTAS2 where HVD_CLIENTE = '${clienteOriginal}' and HVD_PROID = '${prodId}'"$)
|
||||
' Log($"PU ROWCOUNT = ${pc.RowCount}"$)
|
||||
' If pc.RowCount > 0 Then
|
||||
' pc.Position = 0
|
||||
' pu = pc.GetString("PU")
|
||||
' End If
|
||||
' pc.Close
|
||||
' Private pc As Cursor = Starter.skmt.ExecQuery($"select HVD_CANT from HIST_VENTAS where HVD_CLIENTE = '${clienteOriginal}' and HVD_PROID = '${prodId}'"$)
|
||||
' If pc.RowCount > 0 Then
|
||||
' pc.Position = 0
|
||||
' cant = pc.GetString("HVD_CANT")
|
||||
' End If
|
||||
' pc.Close
|
||||
'' Starter.skmt.ExecNonQuery($"update hist_ventas set HVD_CANT = '${cant - 1}' where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_PROID = '${prodId}'"$)
|
||||
' Starter.skmt.ExecNonQuery($"update hist_ventas set HVD_COSTO_TOT = '${cant * pu}' where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_PROID = '${prodId}'"$)
|
||||
'' Log($"update hist_ventas set HVD_CANT = '${cant - 1}' where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_PROID = '${prodId}'"$)
|
||||
' Log($"update hist_ventas set HVD_COSTO_TOT = '${cant * pu}' where HVD_CLIENTE in (Select CUENTA from cuentaa) and HVD_PROID = '${prodId}'"$)
|
||||
End Sub
|
||||
|
||||
'Ponemos rechazo de producto en la tabla de Reparto.
|
||||
Sub prodRechazo(clienteOriginal As String, prodId As String)
|
||||
Log("RECHAZO DEVOLUCION")
|
||||
Private rr As Cursor = Starter.skmt.ExecQuery($"select count(REP_CLIENTE) as hayRechazo from REPARTO where rep_prodid = '${prodId}' and REP_CLIENTE in (Select CUENTA from cuentaa)"$)
|
||||
rr.Position = 0
|
||||
If rr.GetString("hayRechazo") = 0 Then
|
||||
Log("INSERTAMOS EN REPARTO")
|
||||
' Log($"select * from hist_ventas where hvd_cliente in (select cuenta from cuentaa) and hvd_proid = '${prodId}'"$)
|
||||
Private chv As Cursor = Starter.skmt.ExecQuery($"select * from hist_ventas where hvd_cliente in (select cuenta from cuentaa) and hvd_proid = '${prodId}'"$)
|
||||
' Log(chv.RowCount)
|
||||
If chv.RowCount > 0 Then
|
||||
chv.Position = 0
|
||||
' Log($"CANT=${chv.GetString("HVD_CANT")}"$)
|
||||
Private precio As String = traePrecio(prodId, 1)
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,1,?,?,?) ", Array As String(traeCliente, chv.GetString("HVD_PRONOMBRE"), 1, precio, chv.GetString("HVD_FECHA"), prodId, precio, traeCliente))
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT, REP_FECHA, REP_RECHAZO, REP_PRODID, REP_PRECIO, REP_CLI_ORIG) VALUES (?,?,?,?,?,0,?,?,?) ", Array As String(traeCliente, chv.GetString("HVD_PRONOMBRE"), chv.GetString("HVD_CANT") - 1, (chv.GetString("HVD_CANT") - 1) * precio, chv.GetString("HVD_FECHA"), prodId, precio, traeCliente))
|
||||
Starter.skmt.ExecNonQuery($"update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = 0, HVD_COSTO_TOT = '0' where HVD_PROID = '${prodId}' and HVD_CLIENTE in (Select CUENTA from cuentaa)"$)
|
||||
End If
|
||||
Else
|
||||
Log($"ACTUALIZAMOS REPARTO"$)
|
||||
Private precio As String = traePrecio(prodId, 1)
|
||||
Starter.skmt.ExecNonQuery2("update HIST_VENTAS set HVD_PARCIAL = 1, HVD_CANT = 0, HVD_COSTO_TOT = '0' WHERE HVD_PROID = ? and HVD_CLIENTE in (Select CUENTA from cuentaa)", Array As String(prodId))
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
|
||||
' Log($"update reparto set REP_CANT = REP_CANT + 1 where REP_CLIENTE = '${clienteOriginal}' and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 1 and REP_PRODID = '${prodId}'"$)
|
||||
' Log($"update reparto set REP_CANT = REP_CANT - 1 where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_RECHAZO = 0 and REP_PRODID = '${prodId}'"$)
|
||||
Starter.skmt.ExecNonQuery($"update reparto set REP_COSTO_TOT = REP_CANT * ${precio}, REP_PRECIO = '${precio}' where REP_CLIENTE in (Select CUENTA from cuentaa) and REP_CLI_ORIG = '${clienteOriginal}' and REP_PRODID = '${prodId}'"$)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub traemosCantYMonto(clv As CustomListView) As Map
|
||||
' Log("TRAEMOS CANT Y MONTO")
|
||||
Private cant As Int = 0
|
||||
Private monto As Float = 0
|
||||
For i = 0 To clv.GetSize - 1
|
||||
Private p0 As B4XView = clv.GetPanel(i)
|
||||
Private p As B4XView = p0.GetView(0)
|
||||
Private cant1 As B4XView = p.GetView(2).GetView(3)
|
||||
If cant1.Text = "" Then cant1.Text = 0
|
||||
Private esteTag As List = Regex.Split("\|", cant1.Tag)
|
||||
' Log($"CANT:${cant1.text}, esteTag=${esteTag}"$)
|
||||
If esteTag.Get(2) <> esteTag.Get(3) Then cant = cant + cant1.Text 'Si el ID es diferente de la promo, lo sumamos, si no, no lo sumamos porque es el encabezado de la promo en 0.
|
||||
monto = monto + (esteTag.Get(0) * cant1.Text)
|
||||
Next
|
||||
' Log($"CANT=${cant}, MONTO=${monto}"$)
|
||||
Return CreateMap("cantidad":cant, "monto":monto)
|
||||
End Sub
|
||||
|
||||
Sub traeCantYMonto2(cliente As String) As Map
|
||||
' Log("TRAE CANT Y MONTO2")
|
||||
Private cant As Int = 0
|
||||
Private monto As Float = 0
|
||||
Private ccym As Cursor = Starter.skmt.ExecQuery($"Select hvd_codpromo, hvd_proid, HVD_CANT, (Select CAT_GP_PRECIO from cat_gunaprod where cat_gp_id = hvd_proid) As precio from HIST_VENTAS where HVD_CLIENTE = '${cliente}'"$)
|
||||
If ccym.RowCount > 0 Then
|
||||
For i=0 To ccym.RowCount -1
|
||||
ccym.Position = i
|
||||
If ccym.GetString("HVD_CODPROMO") <> ccym.GetString("HVD_PROID") And ccym.GetString("precio") <> Null Then 'Si no es el header de una promo...
|
||||
cant = cant + ccym.GetString("HVD_CANT")
|
||||
' Log($"${ccym.GetString("HVD_CANT")} * ${ccym.GetString("precio")}"$)
|
||||
monto = monto + (ccym.GetString("HVD_CANT") * traePrecio(ccym.GetString("HVD_PROID"), ccym.GetString("HVD_CODPROMO")))
|
||||
End If
|
||||
Next
|
||||
' Log($"CANT=${cant}, MONTO=${monto}"$)
|
||||
End If
|
||||
|
||||
ccym = Starter.skmt.ExecQuery($"Select rep_prodid, rep_cant, (Select CAT_GP_PRECIO from cat_gunaprod where cat_gp_id = rep_prodid) As precio from REPARTO where REP_CLIENTE in (Select cuenta from cuentaa) And REP_RECHAZO = '0' and REP_CANT > 0"$)
|
||||
If ccym.RowCount > 0 Then
|
||||
For i=0 To ccym.RowCount -1
|
||||
ccym.Position = i
|
||||
If ccym.GetString("REP_CANT") <> Null Then cant = cant + ccym.GetString("REP_CANT")
|
||||
monto = monto + (ccym.GetString("REP_CANT") * ccym.GetString("precio"))
|
||||
Next
|
||||
Log($"CANT=${cant}, MONTO=${monto}"$)
|
||||
End If
|
||||
|
||||
ccym.Close
|
||||
Return CreateMap("cantidad":cant, "monto":monto)
|
||||
End Sub
|
||||
|
||||
'Regresa la cantidad entregada desde HIST_VENTAS.
|
||||
Sub traeEntregados As Map
|
||||
Private m As Map
|
||||
Private cant As Int = 0
|
||||
Private monto As String = 0
|
||||
Private rc As Cursor = Starter.skmt.ExecQuery($"select sum(HVD_CANT) as CUANTOS, sum(HVD_COSTO_TOT) as CUANTO from HIST_VENTAS where HVD_ESTATUS = '1' and HVD_COSTO_TOT <> '0'"$)
|
||||
If rc.RowCount > 0 Then
|
||||
rc.Position = 0
|
||||
If rc.GetString("CUANTOS") <> Null Then
|
||||
cant = cant + rc.GetString("CUANTOS")
|
||||
monto = monto + rc.GetString("CUANTO")
|
||||
End If
|
||||
End If
|
||||
' LogColor($"CANTIDAD ENTREGADA = ${cant}"$, Colors.red)
|
||||
Return CreateMap("cantidad": cant, "monto": monto)
|
||||
End Sub
|
||||
|
||||
'Regresa la cantidad rechazada desde REPARTO.
|
||||
Sub traeRechazados As Map
|
||||
Private m As Map
|
||||
Private cant As Int = 0
|
||||
Private monto As String = 0
|
||||
Private rc As Cursor = Starter.skmt.ExecQuery($"select sum(REP_CANT) as CUANTOS, sum(REP_CANT * REP_PRECIO) as CUANTO from REPARTO where REP_RECHAZO = '1' and REP_CANT <> '0'"$)
|
||||
If rc.RowCount > 0 Then
|
||||
rc.Position = 0
|
||||
If rc.GetString("CUANTOS") <> Null Then
|
||||
cant = cant + rc.GetString("CUANTOS")
|
||||
monto = monto + rc.GetString("CUANTO")
|
||||
End If
|
||||
End If
|
||||
' LogColor($"CANTIDAD RECHAZADA = ${cant}"$, Colors.red)
|
||||
Return CreateMap("cantidad": cant, "monto": monto)
|
||||
End Sub
|
||||
|
||||
'Regresa la cantidad vendida desde REPARTO.
|
||||
Sub traeVendidos As Map
|
||||
Private m As Map
|
||||
Private cant As Int = 0
|
||||
Private monto As String = 0
|
||||
Private rc As Cursor = Starter.skmt.ExecQuery($"select sum(REP_CANT) as CUANTOS, sum(REP_CANT * REP_PRECIO) as CUANTO from REPARTO where REP_RECHAZO = '0' and REP_CANT <> '0'"$)
|
||||
If rc.RowCount > 0 Then
|
||||
rc.Position = 0
|
||||
If rc.GetString("CUANTOS") <> Null Then
|
||||
cant = cant + rc.GetString("CUANTOS")
|
||||
monto = monto + rc.GetString("CUANTO")
|
||||
End If
|
||||
End If
|
||||
' LogColor($"CANTIDAD VENDIDA = ${cant}"$, Colors.red)
|
||||
Return CreateMap("cantidad": cant, "monto": monto)
|
||||
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)
|
||||
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
|
||||
236
B4A/Tracker.bas
Normal file
@@ -0,0 +1,236 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Service
|
||||
Version=10.2
|
||||
@EndOfDesignText@
|
||||
#Region Service Attributes
|
||||
#StartAtBoot: True
|
||||
#End Region
|
||||
'******************************************************************************
|
||||
'No olvidar agregar esta linea al editor de manifiesto:
|
||||
' SetServiceAttribute(Tracker, android:foregroundServiceType, "location")
|
||||
'
|
||||
'En Starter agregar estas lineas en Process_Globals
|
||||
' Public rp As RuntimePermissions
|
||||
' Public FLP As FusedLocationProvider
|
||||
' Private flpStarted As Boolean
|
||||
'
|
||||
'En Main agregar estas lineas a Activity_Resume
|
||||
' Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
|
||||
' Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
' If Result Then
|
||||
' StartService(Tracker)
|
||||
' Log("Start Tracker")
|
||||
' Else
|
||||
' ToastMessageShow("No permission", True)
|
||||
' End If
|
||||
'
|
||||
'Se necesitan las librerias FusedLocationProvider, GPS, Phone y RunTimePermissions
|
||||
'
|
||||
'Y en Main agregar estas dos lineas:
|
||||
'#AdditionalJar: com.android.support:support-v4
|
||||
'#AdditionalJar: com.google.android.gms:play-services-location
|
||||
|
||||
Sub Process_Globals
|
||||
Private nid As Int = 1
|
||||
Private Tracking As Boolean
|
||||
Private lock As PhoneWakeState
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
Public FLP As FusedLocationProvider
|
||||
Dim actualLR As LocationRequest
|
||||
Private flpStarted As Boolean
|
||||
Dim locRequest As String
|
||||
Dim UUGCoords As Location 'Ultima Ubicacion Guardada
|
||||
Dim trackerActividad, pushServiceActividad As String
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
|
||||
UUGCoords.Initialize
|
||||
UUGCoords.Latitude = 0
|
||||
UUGCoords.Longitude = 0
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
FLP.Initialize("flp")
|
||||
FLP.Connect
|
||||
lock.PartialLock
|
||||
StartFLP
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionSuccess
|
||||
' If B4XPages.MainPage.logger Then Log("Connected to location provider")
|
||||
'FLP.GetLastKnownLocation
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionFailed(ConnectionResult1 As Int)
|
||||
If B4XPages.MainPage.logger Then Log("Failed to connect to location provider")
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionSuspended(ConnectionResult1 As Int)
|
||||
If B4XPages.MainPage.logger Then Log("FLP conection suspended")
|
||||
StartFLP
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
LogColor("Iniciando Tracker ...", Colors.Green)
|
||||
Service.StopAutomaticForeground
|
||||
' Service.StartForeground(51042, Subs.notiLowReturn("THIS (T)", PushService.wsStatus, 51042))
|
||||
StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerMinute, True)
|
||||
Track
|
||||
Starter.trackerActividad = Subs.fechaKMT(DateTime.Now)
|
||||
' Log("trackerActividad="&Starter.trackerActividad&"|"& Subs.fechaKMT(DateTime.Now))
|
||||
End Sub
|
||||
|
||||
Public Sub Track
|
||||
If B4XPages.MainPage.logger Then Log("Inicia Track - Tracking : "&Tracking)
|
||||
If Tracking Then
|
||||
' Log(actualLR.GetSmallestDisplacement)
|
||||
Return 'Si ya estamos "rastreando" no hacemos nada (return)
|
||||
End If
|
||||
If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
|
||||
If B4XPages.MainPage.logger Then Log("No permission")
|
||||
Return
|
||||
End If
|
||||
StartFLP 'Iniciamos FusedLocationProvider
|
||||
Tracking = True
|
||||
End Sub
|
||||
|
||||
Public Sub StartFLP
|
||||
' If B4XPages.MainPage.logger Then Log("StartFLP - flpStarted="&flpStarted)
|
||||
Do While FLP.IsConnected = False
|
||||
Sleep(500)
|
||||
' If Main.logger Then Log("sleeping")
|
||||
Loop
|
||||
' If flpStarted = False Then
|
||||
' If Main.logger Then Log("RequestLocationUpdates")
|
||||
FLP.RequestLocationUpdates(CreateLocationRequest) 'Buscamos ubicacion
|
||||
' If Main.logger Then Log("Buscamos ubicacion")
|
||||
' If Main.logger Then Log(actualLR.GetSmallestDisplacement)
|
||||
flpStarted = True
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Public Sub StartFLP2Reqs
|
||||
If B4XPages.MainPage.logger Then Log("StartFLP - flpStarted="&flpStarted)
|
||||
Do While FLP.IsConnected = False
|
||||
Sleep(500)
|
||||
If B4XPages.MainPage.logger Then Log("sleeping GR")
|
||||
Loop
|
||||
dameUltimaUbicacionConocida 'Regresamos ultima ubicacion conocida
|
||||
FLP.RequestLocationUpdates(CreateLocationRequest2times) 'Buscamos ubicacion 2 peticiones
|
||||
If B4XPages.MainPage.logger Then Log("Buscamos ubicacion 2 peticiones")
|
||||
If B4XPages.MainPage.logger Then Log(actualLR.GetSmallestDisplacement)
|
||||
End Sub
|
||||
|
||||
Private Sub CreateLocationRequest As LocationRequest
|
||||
If B4XPages.MainPage.logger Then Log("CreateLocationRequest")
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(10000) 'Intervalo deseado para actualizaciones de ubicacion
|
||||
lr.SetFastestInterval(lr.GetInterval / 2) 'Intervalo minimo para actualizaciones de ubicacion
|
||||
lr.SetSmallestDisplacement(75) 'Solo registra cambio de ubicacion si es mayor a XX mts
|
||||
lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
|
||||
actualLR=lr
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Private Sub CreateLocationRequest2times As LocationRequest
|
||||
If B4XPages.MainPage.logger Then Log("Iniciamos CreateLocationRequest2times")
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(2000) 'Intervalo deseado para actualizaciones de ubicacion
|
||||
lr.SetFastestInterval(lr.GetInterval / 2) 'Intervalo minimo para actualizaciones de ubicacion
|
||||
lr.setNumUpdates(2) 'Solicitamos solo 2 actualizaciones con estos parametros
|
||||
lr.SetSmallestDisplacement(10) 'Solo registra cambio de ubicacion si es mayor a XX mts
|
||||
lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
|
||||
actualLR=lr
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Sub dameUltimaUbicacionConocida
|
||||
If FLP.GetLastKnownLocation.IsInitialized Then 'Mandamos ultima ubicacion guardada
|
||||
' If Main.logger Then Log("Mandamos UUC : "&formatoFecha(FLP.GetLastKnownLocation.Time))
|
||||
If B4XPages.MainPage.Logger Then LogColor($"Mandamos UUC "${Subs.fechaKMT(FLP.GetLastKnownLocation.Time)}|Acc:$0.2{FLP.GetLastKnownLocation.Accuracy}|$0.8{FLP.GetLastKnownLocation.Latitude}|$0.8{FLP.GetLastKnownLocation.Longitude}|Spd:$0.2{FLP.GetLastKnownLocation.Speed}|"$, Colors.RGB(255,112,35))
|
||||
Dim coords As String = FLP.GetLastKnownLocation.Latitude&","&FLP.GetLastKnownLocation.Longitude&","&formatoFecha(FLP.GetLastKnownLocation.Time)
|
||||
' CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
Subs.mandamosLoc(coords)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub StopFLP
|
||||
'Log("StopFLP")
|
||||
If flpStarted Then
|
||||
FLP.RemoveLocationUpdates 'Eliminamos todas las solicitudes de ubicacion
|
||||
flpStarted = False
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub flp_LocationChanged (Location1 As Location)
|
||||
Starter.trackerActividad = Subs.fechaKMT(DateTime.Now)
|
||||
UUGCoords = Location1
|
||||
' If Main.logger Then Log("SmallestDisplacement="&actualLR.GetSmallestDisplacement)
|
||||
CallSub2(Starter, "GPS_LocationChanged", Location1)
|
||||
' CallSub2(gestion, "GPS_LocationChanged", Location1)
|
||||
' CallSubDelayed2(gestion, "GPS_LocationChanged", Location1)
|
||||
B4XPages.MainPage.lat_gps = Location1.Latitude
|
||||
B4XPages.MainPage.lon_gps = Location1.Longitude
|
||||
'/////// para la ultima ubicacion FL
|
||||
Dim sDate,sTime As String
|
||||
DateTime.DateFormat = "MM/dd/yyyy"
|
||||
sDate=DateTime.Date(DateTime.Now)
|
||||
sTime=DateTime.Time(DateTime.Now)
|
||||
Try
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM HIST_GPS")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps))
|
||||
Catch
|
||||
If B4XPages.MainPage.logger Then Log("Error al borrar o insertar nuevas coordendas en HIST_GPS")
|
||||
End Try
|
||||
'///////
|
||||
Dim coords As String = Location1.Latitude&","&Location1.Longitude&","&formatoFecha(Location1.Time)
|
||||
Log("Loc changed : "&Location1.Latitude&","&Location1.Longitude)
|
||||
If B4XPages.MainPage.logger Then Log("Mandamos Ubicacion")
|
||||
If B4XPages.MainPage.logger Then Log(locRequest)
|
||||
' Solo mandamos la ubicacion si la precision es menor a XX mts
|
||||
If Location1.Accuracy < 100 Then
|
||||
Subs.guardaInfoEnBD(coords)'Escribimos coordenadas y fecha en BD
|
||||
' CallSubDelayed2(FirebaseMessaging,"mandamosLoc",coords)
|
||||
Subs.mandamosLoc(coords)
|
||||
End If
|
||||
Dim origFormat As String = DateTime.TimeFormat 'Guardamos formato de fecha
|
||||
DateTime.TimeFormat = "HHmmss" ' Modificamos formato de fecha
|
||||
Dim minsDif As Int = DateTime.Time(DateTime.Now) - B4XPages.MainPage.ultimaActualizacionGPS
|
||||
' If Main.logger Then Log("UltimaAct="&Main.ultimaActualizacionGPS&" MinsDif="&minsDif)
|
||||
If Location1.Accuracy < 100 And minsDif > 240 Then 'Si precision de 100 y 4 min transcurridos manda a web
|
||||
If B4XPages.MainPage.logger Then Log("actualizamos Ubicacion Web")
|
||||
CallSubDelayed(Starter, "ENVIA_ULTIMA_GPS")
|
||||
End If
|
||||
DateTime.TimeFormat = origFormat 'Regresamos formato de fecha original
|
||||
'Revisamos servicios
|
||||
Subs.monitor
|
||||
End Sub
|
||||
|
||||
Sub CreateNotification (Body As String) As Notification 'ignore
|
||||
Dim notification As Notification
|
||||
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
notification.Icon = "icon"
|
||||
notification.SetInfo("MEDICOMED", Body, Main)
|
||||
Return notification
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
If Tracking Then
|
||||
StopFLP
|
||||
End If
|
||||
Tracking = False
|
||||
lock.ReleasePartialLock
|
||||
End Sub
|
||||
|
||||
Sub formatoFecha(fecha As String) As String 'Convierte una fecha al formato yyMMddHHmmss
|
||||
' Log(fecha)
|
||||
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||
DateTime.DateFormat="yyMMddHHmmss"
|
||||
Dim lastUpdate As String=DateTime.Date(fecha)
|
||||
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||
' Log(lastUpdate)
|
||||
Return lastUpdate
|
||||
End Sub
|
||||
284
B4A/appUpdater.bas
Normal file
@@ -0,0 +1,284 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Service
|
||||
Version=10.2
|
||||
@EndOfDesignText@
|
||||
#Region Service Attributes
|
||||
#StartAtBoot: False
|
||||
#End Region
|
||||
|
||||
'////////////////////////////////////////////////////////////////////////////////////////////
|
||||
'//// Servicio para revisar si hay actualizacion de aplicación, usa la
|
||||
'//// actividad "updateAvailable" para mostrar mensajes.
|
||||
'////
|
||||
'//// https://www.b4x.com/android/forum/threads/update-your-app-without-using-the-gplaystore.109720/#content
|
||||
'////
|
||||
'//// En la actividad del la cual se va a llamar la revision de actualizacion
|
||||
'//// hay que agregar los siguientes Subs:
|
||||
'////
|
||||
' Sub boton_que_llama_revision_Click
|
||||
' StartService(appUpdater)
|
||||
' End Sub
|
||||
'
|
||||
' appUpdater - Mostramos el anuncio de que se esta descargando el nuevo apk
|
||||
' Sub muestraProgreso
|
||||
' ProgressDialogShow("Descargando actualización")
|
||||
' End Sub
|
||||
'
|
||||
' appUpdater - Ocultamos el anuncio de que se esta descargando el nuevo apk
|
||||
' Sub ocultaProgreso
|
||||
' ProgressDialogHide
|
||||
' End Sub
|
||||
'////
|
||||
'//// Requiere las siguientes librerias:
|
||||
'////
|
||||
'//// * appUpdating
|
||||
'//// * JavaObject
|
||||
'//// * OkHttpUtils2
|
||||
'//// * Phone
|
||||
'//// * RuntimePermissions
|
||||
'////
|
||||
'//// Requiere las siguientes lineas en el manifiesto:
|
||||
'////
|
||||
' AddManifestText(<uses-permission
|
||||
' android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
' android:maxSdkVersion="18" />
|
||||
' )
|
||||
' AddApplicationText(
|
||||
' <provider
|
||||
' android:name="android.support.v4.content.FileProvider"
|
||||
' android:authorities="$PACKAGE$.provider"
|
||||
' android:exported="false"
|
||||
' android:grantUriPermissions="true">
|
||||
' <meta-data
|
||||
' android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
' android:resource="@xml/provider_paths"/>
|
||||
' </provider>
|
||||
' )
|
||||
' CreateResource(xml, provider_paths,
|
||||
' <paths>
|
||||
' <external-files-path name="name" path="" />
|
||||
' <files-path name="name" path="" />
|
||||
' <files-path name="name" path="shared" />
|
||||
' </paths>
|
||||
' )
|
||||
' AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)
|
||||
' AddPermission(android.permission.INTERNET)
|
||||
' AddPermission(android.permission.INSTALL_PACKAGES)
|
||||
' AddPermission(android.permission.READ_EXTERNAL_STORAGE)
|
||||
' AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
|
||||
' AddPermission(android.permission.READ_PHONE_STATE)
|
||||
' AddPermission(android.permission.WAKE_LOCK)
|
||||
'////
|
||||
'////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Sub Process_Globals
|
||||
'These global variables will be declared once when the application starts.
|
||||
'These variables can be accessed from all modules.
|
||||
|
||||
'Aqui va la liga al archivo .ver en el servidor que contiene la información de la aplicacion
|
||||
Public lnk As String = "https://keymon.lat/movil/medicomed/medicomed_reparto.ver"
|
||||
|
||||
'/// En el servidor se necesita un archivo de texto (.ver) que tenga los siguientes
|
||||
'/// datos separados por un tabulador
|
||||
'/// contents of ver file, each field is seperated by a tab
|
||||
' Field 0 = 2.226.19.09.19.01a <-- Esta es la version de la aplicación disponible
|
||||
' Field 1 = A new version of the MyAPP is available, Download and update now ? <-- Mensaje para cuando hay actualización
|
||||
' Field 2 = MyApp is up to date <--- Mensaje para cuando no hay actualización
|
||||
' Field 3 = http://www.mydomain.com/Public/myapp.apk <--- Liga al apk de la actualización
|
||||
|
||||
Public nNewApp As Notification
|
||||
Public nNewAppnID As Int = 16
|
||||
'Para Download
|
||||
Dim nativeMe As JavaObject
|
||||
Dim n2 As Notification
|
||||
Dim n2ID As Int = 16
|
||||
'Para fileProvider
|
||||
Public SharedFolder As String
|
||||
Public UseFileProvider As Boolean
|
||||
Private rp As RuntimePermissions
|
||||
|
||||
Type mNewVersion(update As Boolean, nonewAPP As Boolean, notifyUser As Boolean, _
|
||||
version As String, newMsg As String, okMsg As String, appLink As String)
|
||||
Public newApp As mNewVersion
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
Log("appUpdater(), Service_Create")
|
||||
newApp.Initialize
|
||||
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
|
||||
n2.Initialize
|
||||
nativeMe.InitializeContext
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
Log("appUpdater(), Service_Start")
|
||||
' CallSubDelayed2(Main, "muestraProgreso", "Buscando actualización")
|
||||
B4XPages.MainPage.muestraProgreso("Buscando actualización")
|
||||
Log("Buscando actualización")
|
||||
fileProvider_init
|
||||
Wait For (Download(Me, lnk)) JobDone (j As HttpJob)
|
||||
If j.Success Then
|
||||
Try
|
||||
Dim app() As String = Regex.Split(Chr(9),j.GetString)
|
||||
' // Set the data
|
||||
newApp.appLink = app(3) 'Liga a nueva app
|
||||
newApp.newMsg = app(1) 'Texto de que hay actualizacion
|
||||
newApp.okMsg = app(2) 'Texto de app al corriente
|
||||
newApp.version = app(0) 'Version actual
|
||||
|
||||
Log($"Application.VersionName=${Application.VersionName}, newApp=${newApp}"$)
|
||||
|
||||
' // App version check
|
||||
If newApp.version = Application.VersionName Then
|
||||
newApp.update = False
|
||||
Log("No new app")
|
||||
B4XPages.ShowPage("updateAvailable")
|
||||
'Se puede mandar tambien una notificacion avisando que NO hay actualizaciones
|
||||
CreateNotification2("Aplicacion al corriente","No hay actualizaciones disponibles","ic_file_download_white_24dp",Main,True,True,nNewApp,nNewAppnID)
|
||||
End If
|
||||
If newApp.version <> Application.VersionName Then
|
||||
newApp.update = True
|
||||
Log("New app true")
|
||||
B4XPages.ShowPage("updateAvailable")
|
||||
'Se puede mandar tambien una notificacion avisando que hay actualizacion disponible
|
||||
' CreateNotification2("Nueva aplicación disponible","Haga clic para descargar.","ic_file_download_white_24dp",C_UpdateAvailable,True,True,nNewApp,nNewAppnID)
|
||||
End If
|
||||
Catch
|
||||
Log("appUpdater(), Job Failed, error " & LastException.Message)
|
||||
End Try
|
||||
Else
|
||||
Log("appUpdater(), Job Failed " & lnk)
|
||||
End If
|
||||
j.Release
|
||||
' StopService(Me)
|
||||
End Sub
|
||||
|
||||
Sub download_Start (StartingIntent As Intent)
|
||||
download_newApk
|
||||
End Sub
|
||||
|
||||
Sub download_newApk
|
||||
' CreateNotification("Descargando actualización", "Descargando apk", "ic_file_download_white_24dp", Main, False, True)
|
||||
' CallSubDelayed2(Main, "muestraProgreso", "Descargando actualización")
|
||||
Log("Descargando actualización")
|
||||
B4XPages.ShowPage("login")
|
||||
B4XPages.MainPage.muestraProgreso("Descargando actualización")
|
||||
Starter.muestraProgreso = 1
|
||||
Dim job_newAPP As HttpJob
|
||||
job_newAPP.Initialize("job_newAPP",Me)
|
||||
job_newAPP.Download(newApp.appLink)
|
||||
Wait for (job_newAPP) JobDone (job_newAPP As HttpJob)
|
||||
If job_newAPP.Success = True Then
|
||||
' // Delete existing file
|
||||
If File.Exists(SharedFolder,"newapp.apk") Then
|
||||
File.Delete(SharedFolder,"newapp.apk")
|
||||
End If
|
||||
' // Save new file
|
||||
Dim outNewAPK As OutputStream = File.OpenOutput(SharedFolder,"newapp.apk", False)
|
||||
File.Copy2(job_newAPP.GetInputStream, outNewAPK)
|
||||
outNewAPK.Close
|
||||
' If Starter.Logger Then Log("APK dir: "&SharedFolder)
|
||||
B4XPages.MainPage.ocultaProgreso
|
||||
Log("ocultamos prigreso DOWNLOAD APK")
|
||||
End If
|
||||
job_newAPP.Release
|
||||
' // Install the app
|
||||
Dim in As Intent
|
||||
in.Initialize(in.ACTION_VIEW,"" )
|
||||
SetFileUriAsIntentData(in, "newapp.apk")
|
||||
' // Type must be set after calling SetFileUriAsIntentData
|
||||
in.SetType("application/vnd.android.package-archive")
|
||||
StartActivity(in)
|
||||
n2.Cancel(nNewAppnID)
|
||||
' Service.StopForeground(nNewAppnID)
|
||||
StopService(Me)
|
||||
' CallSubDelayed(Main,"ocultaProgreso")
|
||||
End Sub
|
||||
|
||||
Sub download_Destroy
|
||||
n2.Cancel(n2ID)
|
||||
Service.StopForeground(n2ID)
|
||||
End Sub
|
||||
|
||||
Sub Download (Callback As Object, link As String) As HttpJob
|
||||
Dim j As HttpJob
|
||||
j.Initialize("", Callback)
|
||||
j.Download(link)
|
||||
Return j
|
||||
End Sub
|
||||
|
||||
Private Sub CreateNotification2(Title As String, Content As String, _ 'ignore
|
||||
Icon As String, TargetActivity As Object, Sound As Boolean, _
|
||||
Vibrate As Boolean, pN As Notification,pNID As Int) As Notification
|
||||
pN.Initialize2(pN.IMPORTANCE_HIGH)
|
||||
' pN.Number = pNID
|
||||
' pN.Light = False
|
||||
pN.Vibrate = Vibrate
|
||||
pN.Sound = Sound
|
||||
' pN.OnGoingEvent = False
|
||||
pN.Icon = Icon
|
||||
pN.AutoCancel = True
|
||||
pN.SetInfo(Title, Content, TargetActivity)
|
||||
pN.Notify(pNID)
|
||||
Return pN
|
||||
End Sub
|
||||
|
||||
Private Sub CreateNotification(Title As String, Content As String, Icon As String, TargetActivity As Object, Sound As Boolean, Vibrate As Boolean) As Notification 'ignore
|
||||
n2.Initialize
|
||||
n2.Light = False
|
||||
n2.Vibrate = Vibrate
|
||||
n2.Sound = Sound
|
||||
n2.OnGoingEvent = True
|
||||
n2.Icon = Icon
|
||||
n2.SetInfo(Title, Content, TargetActivity)
|
||||
n2.Notify(nNewAppnID)
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
Log("appUpdater(), Service_Destroy")
|
||||
End Sub
|
||||
|
||||
Sub fileProvider_init
|
||||
Dim p As Phone
|
||||
If p.SdkVersion >= 24 Or File.ExternalWritable = False Then
|
||||
UseFileProvider = True
|
||||
SharedFolder = File.Combine(File.DirInternal, "shared")
|
||||
If Not(File.IsDirectory(File.DirInternal,"shared")) Then
|
||||
File.MakeDir("", SharedFolder)
|
||||
End If
|
||||
Else
|
||||
UseFileProvider = False
|
||||
SharedFolder = rp.GetSafeDirDefaultExternal("shared")
|
||||
End If
|
||||
Log($"Using FileProvider? - ${UseFileProvider}"$)
|
||||
End Sub
|
||||
|
||||
'Returns the file uri.
|
||||
Sub GetFileUri (FileName As String) As Object
|
||||
Try
|
||||
If Not(UseFileProvider) Then
|
||||
Dim uri As JavaObject
|
||||
Return uri.InitializeStatic("android.net.Uri").RunMethod("parse", Array("file://" & File.Combine(SharedFolder, FileName)))
|
||||
End If
|
||||
Dim f As JavaObject
|
||||
f.InitializeNewInstance("java.io.File", Array(SharedFolder, FileName))
|
||||
Dim fp As JavaObject
|
||||
Dim context As JavaObject
|
||||
context.InitializeContext
|
||||
fp.InitializeStatic("android.support.v4.content.FileProvider")
|
||||
Return fp.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
|
||||
Catch
|
||||
Log("FileProvider::GetFileUri - error - " & LastException.Message)
|
||||
Return ""
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'Replaces the intent Data field with the file uri.
|
||||
'Resets the type field. Make sure to call Intent.SetType after calling this method
|
||||
Sub SetFileUriAsIntentData (Intent As Intent, FileName As String)
|
||||
Dim jo As JavaObject = Intent
|
||||
jo.RunMethod("setData", Array(GetFileUri(FileName)))
|
||||
Intent.Flags = Bit.Or(Intent.Flags, 1) 'FLAG_GRANT_READ_URI_PERMISSION
|
||||
End Sub
|
||||
190
B4A/foto.bas
Normal file
@@ -0,0 +1,190 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Activity
|
||||
Version=7.01
|
||||
@EndOfDesignText@
|
||||
#Region Activity Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: True
|
||||
|
||||
#End Region
|
||||
|
||||
Sub Process_Globals
|
||||
Private frontCamera As Boolean = False
|
||||
' Dim ruta As String
|
||||
Dim g As GPS
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
Private p_camara As Panel
|
||||
Private camEx As CameraExClass
|
||||
Dim btnTakePicture As Button
|
||||
' Dim skmt As SQL
|
||||
Dim c As Cursor
|
||||
Dim cuenta As String
|
||||
Dim lat_gps As String
|
||||
' Dim lon_gps As String
|
||||
Dim USUARIO As String
|
||||
Dim MOTIVO As String
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
If(FirstTime) Then
|
||||
g.Initialize("GPS")
|
||||
End If
|
||||
Activity.LoadLayout("foto")
|
||||
c=Starter.skmt.ExecQuery("select cuenta from cuentaa")
|
||||
c.Position = 0
|
||||
cuenta = c.GetString("CUENTA")
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Private Sub InitializeCamera
|
||||
camEx.Initialize(p_camara, frontCamera, Me, "Camera1")
|
||||
frontCamera = camEx.Front
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
camEx.Release
|
||||
End Sub
|
||||
|
||||
Sub GPS_LocationChanged (Location1 As Location)
|
||||
' lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
|
||||
' lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
|
||||
'btnTakePicture.Enabled = True
|
||||
's.ExecNonQuery2("INSERT INTO HIST_GPS (HGDATE,HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, lat_gps, lon_gps))
|
||||
End Sub
|
||||
|
||||
Sub Camera1_Ready (Success As Boolean)
|
||||
If Success Then
|
||||
camEx.SetJpegQuality(90)
|
||||
camEx.CommitParameters
|
||||
camEx.StartPreview
|
||||
Log(camEx.GetPreviewSize)
|
||||
Else
|
||||
ToastMessageShow("Cannot open camera.", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub btnTakePicture_Click
|
||||
Dim ps As CameraSize
|
||||
ps.Width =640
|
||||
ps.Height =480
|
||||
camEx.SetPictureSize(ps.Width, ps.Height)
|
||||
'ToastMessageShow(ps.Width & "x" & ps.Height, False)
|
||||
camEx.CommitParameters
|
||||
camEx.TakePicture
|
||||
End Sub
|
||||
|
||||
Sub btnFocus_Click
|
||||
camEx.FocusAndTakePicture
|
||||
End Sub
|
||||
|
||||
Sub Camera1_PictureTaken (Data() As Byte)
|
||||
Dim filename As String = "1.jpg"
|
||||
Dim dir As String = File.DirRootExternal
|
||||
|
||||
camEx.SavePictureToFile(Data, dir, filename)
|
||||
camEx.StartPreview 'restart preview
|
||||
|
||||
'Dim out As OutputStream
|
||||
|
||||
Dim sDate,sTime As String
|
||||
|
||||
|
||||
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.Close
|
||||
Starter.skmt.ExecNonQuery("DELETE FROM NOVENTA WHERE NV_CLIENTE IN (select cuenta from cuentaa)")
|
||||
|
||||
c=Starter.skmt.ExecQuery("select HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa) order by HVD_PRONOMBRE asc")
|
||||
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
Starter.skmt.ExecNonQuery2("insert into reparto(REP_CLIENTE, REP_PRONOMBRE, REP_CANT, REP_COSTO_TOT) select HVD_CLIENTE, HVD_PRONOMBRE, HVD_CANT, HVD_COSTO_TOT from hist_ventas where HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(c.GetString("HVD_PRONOMBRE")))
|
||||
|
||||
Starter.skmt.ExecNonQuery2("update cat_gunaprod set cat_gp_almacen = cat_gp_almacen + ? where cat_gp_nombre = ?", Array As Object(c.GetString("HVD_CANT"),c.GetString("HVD_PRONOMBRE")))
|
||||
' ANTES DE MODIFCAR
|
||||
'skmt.ExecNonQuery2("delete FROM HIST_VENTAS WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(c.GetString("HVD_PRONOMBRE")))
|
||||
'skmt.ExecNonQuery2("update HIST_VENTAS set HVD_EXISTE = ? WHERE HVD_PRONOMBRE = ? and HVD_cliente in (Select CUENTA from cuentaa) ", Array As String(motivo, c.GetString("HVD_PRONOMBRE")))
|
||||
|
||||
Next
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO NOVENTA (NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON, NV_FOTO) VALUES(?,?,?,?,?,?,?,?) ", Array As Object (cuenta,sDate & sTime, USUARIO, "CERRADO", B4XPages.MainPage.noVenta.COMENTARIO, B4XPages.MainPage.lat_gps, B4XPages.MainPage.lon_gps, Data))
|
||||
Starter.skmt.ExecNonQuery("UPDATE kmt_info set gestion = 3 where CAT_CL_CODIGO In (select cuenta from cuentaa)")
|
||||
Starter.skmt.ExecNonQuery("update HIST_VENTAS SET HVD_RECHAZO = 1 WHERE HVD_CLIENTE IN (SELECT CUENTA FROM CUENTAA)")
|
||||
B4XPages.ShowPage("Principal")
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Sub ChangeCamera_Click
|
||||
camEx.Release
|
||||
frontCamera = Not(frontCamera)
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Sub btnEffect_Click
|
||||
Dim effects As List = camEx.GetSupportedColorEffects
|
||||
If effects.IsInitialized = False Then
|
||||
ToastMessageShow("Effects not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
|
||||
camEx.SetColorEffect(effect)
|
||||
ToastMessageShow(effect, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
Sub btnFlash_Click
|
||||
Dim f() As Float = camEx.GetFocusDistances
|
||||
Log(f(0) & ", " & f(1) & ", " & f(2))
|
||||
Dim flashModes As List = camEx.GetSupportedFlashModes
|
||||
If flashModes.IsInitialized = False Then
|
||||
ToastMessageShow("Flash not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
|
||||
camEx.SetFlashMode(flash)
|
||||
ToastMessageShow(flash, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
Sub btnPictureSize_Click
|
||||
Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
|
||||
Dim current As CameraSize = camEx.GetPictureSize
|
||||
For i = 0 To pictureSizes.Length - 1
|
||||
If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
|
||||
Next
|
||||
Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
|
||||
camEx.SetPictureSize(ps.Width, ps.Height)
|
||||
ToastMessageShow(ps.Width & "x" & ps.Height & i, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
Sub Activity_KeyPress (key As Int) As Boolean
|
||||
' BACK key pressed
|
||||
If key=KeyCodes.KEYCODE_BACK Then
|
||||
' I want to capture the key here so I return True
|
||||
B4XPages.ShowPage("Principal")
|
||||
'Return True
|
||||
End If
|
||||
' Returning False signals the system to handle the key
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
375
B4XMainPage.bas
Normal file
@@ -0,0 +1,375 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=9.85
|
||||
@EndOfDesignText@
|
||||
#Region Shared Files
|
||||
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
|
||||
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
|
||||
#End Region
|
||||
|
||||
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
|
||||
|
||||
Sub Class_Globals
|
||||
Dim rp As RuntimePermissions
|
||||
Private Root As B4XView
|
||||
Private xui As XUI
|
||||
Private Root As B4XView
|
||||
Public rp As RuntimePermissions
|
||||
Public login As B4XMainPage
|
||||
Public principal As C_Principal
|
||||
Public clientes As C_Clientes
|
||||
Public cliente As C_Cliente
|
||||
' Public foto As C_Foto
|
||||
Public productos As C_Productos
|
||||
Public updateAvailable As C_UpdateAvailable
|
||||
Public mapas As C_Mapas
|
||||
Public nuevoCliente As C_NuevoCliente
|
||||
Public ticketsDia As C_TicketsDia
|
||||
Public noVenta As C_NoVenta
|
||||
Public pedidos As C_Pedidos
|
||||
Public buscar As C_Buscar
|
||||
' Public historico As C_Historico
|
||||
Public detalleVenta As C_DetalleVenta
|
||||
Public detalle_promo As C_Detalle_Promo
|
||||
Dim reqManager As DBRequestManager
|
||||
' Dim ruta As String
|
||||
Dim usuario As String
|
||||
Dim logger As Boolean = true
|
||||
Dim lat_gps, lon_gps As String
|
||||
' Dim skmt As SQL
|
||||
Dim usuario As String
|
||||
Dim server As String
|
||||
Dim montoActual, clientesTotal, clientesVenta, clientesRechazo, clientesVisitados, almacen, rutaPreventa, CANTIDADPROD As String
|
||||
Dim ultimaActualizacionGPS As String = 235959
|
||||
Dim fechaRuta As String
|
||||
' Public wsServerLink As String = "ws://187.189.244.154:51042/push/b4a_ws2"
|
||||
' Public wsServerLink As String = "ws://10.0.0.214:51042/push/b4a_ws2"
|
||||
Dim srvIp As String
|
||||
Dim phn As Phone
|
||||
Dim user As EditText
|
||||
Dim pass As EditText
|
||||
Dim c As Cursor
|
||||
Dim existe As String
|
||||
Dim paso1 As String
|
||||
Private IMEN As Label
|
||||
Dim IMEI As String
|
||||
Private Label1 As Label
|
||||
Dim server As String
|
||||
Private p_principal As Panel
|
||||
Private Entrar As Button
|
||||
Public tabulador As C_tabulador
|
||||
Dim batt As Int
|
||||
Dim porVisitar, entregas, rechazos, montoEntregado, montoRechazado As String
|
||||
Private p_appUpdate As Panel
|
||||
Private i_engrane As ImageView
|
||||
Private b_server As Button
|
||||
Private b_apk As Button
|
||||
Private b_envioBD As Button
|
||||
Private b_regesar As Button
|
||||
Private et_server As EditText
|
||||
Private p_serverList As Panel
|
||||
Private lv_server As ListView
|
||||
Public Provider As FileProvider
|
||||
Public rutaBDBackup As String = ""
|
||||
End Sub
|
||||
|
||||
Public Sub Initialize
|
||||
' B4XPages.GetManager.LogEvents = True
|
||||
End Sub
|
||||
|
||||
'This event will be called once, before the page becomes visible.
|
||||
Private Sub B4XPage_Created (Root1 As B4XView)
|
||||
Root = Root1
|
||||
B4XPages.GetManager.LogEvents = True
|
||||
Root.LoadLayout("login")
|
||||
B4XPages.SetTitle(Me, "Medicomed Reparto")
|
||||
login.Initialize
|
||||
B4XPages.AddPage("Login", login)
|
||||
principal.Initialize
|
||||
B4XPages.AddPage("Principal", principal)
|
||||
clientes.Initialize
|
||||
B4XPages.AddPage("Clientes", clientes)
|
||||
cliente.Initialize
|
||||
B4XPages.AddPage("Cliente", cliente)
|
||||
' foto.Initialize
|
||||
' B4XPages.AddPage("Foto", foto)
|
||||
productos.Initialize
|
||||
B4XPages.AddPage("Productos", productos)
|
||||
updateAvailable.Initialize
|
||||
B4XPages.AddPage("updateAvailable", updateAvailable)
|
||||
mapas.Initialize
|
||||
B4XPages.AddPage("Mapas", mapas)
|
||||
nuevoCliente.Initialize
|
||||
B4XPages.AddPage("NuevoCliente", nuevoCliente)
|
||||
ticketsDia.Initialize
|
||||
B4XPages.AddPage("TicketsDia", ticketsDia)
|
||||
noVenta.Initialize
|
||||
B4XPages.AddPage("NoVenta", noVenta)
|
||||
pedidos.Initialize
|
||||
B4XPages.AddPage("Pedidos", pedidos)
|
||||
buscar.Initialize
|
||||
B4XPages.AddPage("Buscar", buscar)
|
||||
' historico.Initialize
|
||||
' B4XPages.AddPage("Historico", historico)
|
||||
detalleVenta.Initialize
|
||||
B4XPages.AddPage("DetalleVenta", detalleVenta)
|
||||
detalle_promo.Initialize
|
||||
B4XPages.AddPage("Detalle_Promo", detalle_promo)
|
||||
tabulador.Initialize
|
||||
B4XPages.AddPage("tabulador", tabulador)
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS TABULADOR_MONEDAS(VEINTE TEXT, DIEZ TEXT, CINCO TEXT, DOS TEXT, PESO TEXT, CENTAVO TEXT, TOTAL TEXT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS TABULADOR_BILLETES(MIL TEXT, QUINIENTOS TEXT, DOCIENTOS TEXT, CIEN TEXT, CINCUENTA TEXT, VEINTE TEXT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS HIST_VENTAS2 (HVD_PARCIAL TEXT, HVD_RECHAZO TEXT, HVD_NUM_REGISTRO TEXT, HVD_NUM_TICKET TEXT, HVD_PROID TEXT, HVD_CODPROMO TEXT, HVD_FECHA TEXT, HVD_ESTATUS TEXT, HVD_CLIENTE TEXT, HVD_PRONOMBRE TEXT, HVD_CANT TEXT, HVD_COSTO_TOT TEXT)")
|
||||
' Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS VENTAS (V_FECHA TEXT, V_CLIENTE TEXT, V_CLIENTE_ORIG TEXT, V_PRODNOMBRE TEXT, V_PRODID TEXT, V_CANTIDAD TEXT, V_PRECIO TEXT, V_TOTAL TEXT, V_PRODREGISTRO TEXT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RECHAZOS (R_FECHA TEXT, R_CLIENTE TEXT, R_CLI_ORIG TEXT, R_PRODID TEXT, R_CANT TEXT, R_RECHAZO INT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS VENTAS (V_FECHA TEXT, V_CLIENTE TEXT, V_CLI_ORIG TEXT, V_PRODID TEXT, V_CANT TEXT, V_RECHAZO INT)")
|
||||
Subs.agregaColumna("REPARTO", "REP_PRODREGISTRO", "TEXT")
|
||||
Subs.agregaColumna("REPARTO", "REP_PRODID", "TEXT")
|
||||
Subs.agregaColumna("REPARTO", "REP_CLI_ORIG", "TEXT")
|
||||
Subs.agregaColumna("REPARTO", "REP_PRECIO", "TEXT")
|
||||
Subs.agregaColumna("REPARTO", "REP_RECHAZO", "INTEGER")
|
||||
Subs.agregaColumna("RECHAZOS", "R_PRECIO", "TEXT")
|
||||
Subs.agregaColumna("VENTAS", "V_PRECIO", "TEXT")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTAA (RUTAA TEXT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS wayPoints (codigo TEXT, indice INT)")
|
||||
Dim server As String = "http://187.189.244.154:1783"
|
||||
' server = "http://10.0.0.205:1782"
|
||||
' server = "http://11.0.0.44:1782"
|
||||
reqManager.Initialize(Me, B4XPages.MainPage.server)
|
||||
LogColor($"ReqServer = ${B4XPages.MainPage.server}"$, Colors.red)
|
||||
Label1.Text = Application.VersionName
|
||||
' Dim P As PhoneId
|
||||
Log("provider")
|
||||
Provider.Initialize
|
||||
|
||||
' Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
|
||||
' Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
||||
' If Result Then
|
||||
' IMEN.Text = "" 'P.GetDeviceId
|
||||
' IMEI = "" 'P.GetDeviceId
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Sub B4XPage_Appear
|
||||
If Starter.muestraProgreso = 1 Then
|
||||
muestraProgreso("Descargando actualización")
|
||||
Starter.muestraProgreso = 0
|
||||
End If
|
||||
Subs.centraPanel(p_principal, Root.Width)
|
||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
|
||||
' LogColor("Start Tracker1", Colors.red)
|
||||
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then
|
||||
StartService(Tracker)
|
||||
' LogColor("Start Tracker", Colors.red)
|
||||
Else
|
||||
ToastMessageShow("No permission", True)
|
||||
Log("Sin permisos")
|
||||
End If
|
||||
' LogColor("Start Tracker3", Colors.red)
|
||||
c=Starter.skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
If c.RowCount > 0 Then
|
||||
' c.Position=0
|
||||
' c=skmt.ExecQuery("select USUARIO from usuarioa")
|
||||
c.Position=0
|
||||
usuario = c.GetString("USUARIO")
|
||||
End If
|
||||
c.Close
|
||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
||||
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then
|
||||
Log("Con permisos de escritura externa")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
|
||||
Sub Entrar_Click
|
||||
If pass.Text = "YA" Then
|
||||
Starter.skmt.ExecNonQuery("delete from usuarioa")
|
||||
Starter.skmt.ExecNonQuery("delete from VERSION")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO USUARIOA VALUES (?,?)", Array As Object("ROOT", "ROOT"))
|
||||
Starter.skmt.ExecNonQuery("delete from cat_almacen")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_ALMACEN(ID_ALMACEN) VALUES (?)", Array As Object (user.Text))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO VERSION(NOVERSION) VALUES (?)", Array As Object ("2.1"))
|
||||
' principal.B_REGRESA_Click
|
||||
' B4XPages.MainPage.principal.Subir.Visible = True
|
||||
B4XPages.ShowPage("Principal")
|
||||
Else
|
||||
c=Starter.skmt.ExecQuery2("select count(*) as EXISTE1 from usuarioa where usuario = ?", Array As String(user.Text))
|
||||
c.Position=0
|
||||
existe = c.GetString("EXISTE1")
|
||||
c.Close
|
||||
'existe = 1
|
||||
If existe = 0 Then
|
||||
'skmt.ExecNonQuery("delete from usuarioa")
|
||||
Dim cmd As DBCommand
|
||||
cmd.Initialize
|
||||
cmd.Name = "select_usuario_medi_REPG"
|
||||
cmd.Parameters = Array As Object(user.Text, pass.Text)
|
||||
reqManager.ExecuteQuery(cmd , 0, "usuario")
|
||||
|
||||
' Dim cmd As DBCommand
|
||||
' cmd.Initialize
|
||||
' cmd.Name = "select_version_MARDS"
|
||||
' reqManager.ExecuteQuery(cmd , 0, "version")
|
||||
Else
|
||||
' principal.B_REGRESA_Click
|
||||
B4XPages.ShowPage("Principal")
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub JobDone(Job As HttpJob)
|
||||
If Job.Success = False Then
|
||||
ToastMessageShow("Error: " & Job.ErrorMessage, True)
|
||||
Else
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim result As DBResult = reqManager.HandleJob(Job)
|
||||
If result.Tag = "version" Then 'query tag
|
||||
For Each records() As Object In result.Rows
|
||||
Starter.skmt.ExecNonQuery("delete from VERSION")
|
||||
Dim CAT_VE_VERSION As String = records(result.Columns.Get("CAT_VE_VERSION"))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO VERSION(NOVERSION) VALUES (?)", Array As Object (CAT_VE_VERSION))
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim result As DBResult = reqManager.HandleJob(Job)
|
||||
If result.Tag = "agencia" Then 'query tag
|
||||
For Each records() As Object In result.Rows
|
||||
|
||||
Dim ID_ALMACEN As String = records(result.Columns.Get("ID_ALMACEN"))
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim result As DBResult = reqManager.HandleJob(Job)
|
||||
If result.Tag = "usuario" Then 'query tag
|
||||
For Each records() As Object In result.Rows
|
||||
Dim name As String = records(result.Columns.Get("USUARIO"))
|
||||
Dim ID_ALMACEN As String = records(result.Columns.Get("CAT_LO_AGENCIA"))
|
||||
Dim IMEI_BASE As String = records(result.Columns.Get("CAT_LO_IDTELEFONO"))
|
||||
Next
|
||||
paso1 = 1
|
||||
End If
|
||||
End If
|
||||
Job.Release
|
||||
End If
|
||||
|
||||
If paso1 = 1 Then
|
||||
If name = "OKActivo" Then
|
||||
Starter.skmt.ExecNonQuery("delete from usuarioa")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO USUARIOA VALUES (?,?)", Array As Object(user.Text, pass.Text))
|
||||
Starter.skmt.ExecNonQuery("delete from cat_almacen")
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_ALMACEN(ID_ALMACEN) VALUES (?)", Array As Object (ID_ALMACEN))
|
||||
B4XPages.ShowPage("Principal")
|
||||
Else If name = "OKExpirado"& IMEI Then
|
||||
Msgbox("Usuario Expirado llamar al administrador","") 'ignore
|
||||
Else If name = "OKCancelado"& IMEI Then
|
||||
Msgbox("Usuario Cancelado llamar al administrador","") 'ignore
|
||||
Else
|
||||
Msgbox("Usuario o password No validos","") 'ignore
|
||||
End If
|
||||
paso1 = 0
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub i_engrane_Click
|
||||
p_appUpdate.Width = Root.Width
|
||||
p_appUpdate.Height = Root.Height
|
||||
Subs.centraPanel(p_serverList, Root.Width)
|
||||
Subs.centraBoton(b_server, Root.Width)
|
||||
Subs.centraBoton(b_apk, Root.Width)
|
||||
Subs.centraBoton(b_envioBD, Root.Width)
|
||||
Subs.centraBoton(b_regesar, Root.Width)
|
||||
Subs.centraBoton(b_server, p_serverList.Width)
|
||||
lv_server.Clear
|
||||
lv_server.AddSingleLine("http://keymon.lat:1783")
|
||||
If user.Text = "KMTS1" Then lv_server.AddSingleLine("http://10.0.0.205:1783")
|
||||
' l_server.Text = Starter.server
|
||||
et_server.Text = server
|
||||
Subs.panelVisible(p_appUpdate, 0, 0)
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
' Log("closreq")
|
||||
If p_appUpdate.Visible Then
|
||||
p_appUpdate.Visible = False
|
||||
Else
|
||||
Sleep(0)
|
||||
ExitApplication
|
||||
End If
|
||||
Return False
|
||||
End Sub
|
||||
|
||||
Private Sub b_regesar_Click
|
||||
p_principal.Visible = True
|
||||
p_appUpdate.Visible = False
|
||||
End Sub
|
||||
|
||||
'Enviamos la base de datos por correo o Whatsapp
|
||||
Private Sub b_envioBD_Click
|
||||
' copiaDB
|
||||
' Sleep(1000)
|
||||
Dim FileName As String = "kmt.db"
|
||||
'copy the shared file to the shared folder
|
||||
Log("xxxxxx:"&Provider.SharedFolder)
|
||||
Sleep(1000)
|
||||
File.Copy(File.DirInternal, FileName, Provider.SharedFolder, FileName)
|
||||
Dim email As Email
|
||||
email.To.Add("soporte@keymonsoft.com")
|
||||
email.Subject = "Base de datos para revisión"
|
||||
email.Attachments.Add(Provider.GetFileUri(FileName))
|
||||
' email.Attachments.Add(Provider.GetFileUri(FileName)) 'second attachment
|
||||
Dim in As Intent = email.GetIntent
|
||||
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
|
||||
StartActivity(in)
|
||||
End Sub
|
||||
|
||||
Private Sub b_apk_Click
|
||||
StartService(appUpdater)
|
||||
End Sub
|
||||
|
||||
Private Sub b_server_Click
|
||||
Log("Guardar servidor")
|
||||
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("SERVER"))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SERVER",et_server.text))
|
||||
B4XPages.MainPage.server = et_server.text
|
||||
Starter.server = B4XPages.MainPage.server
|
||||
If logger Then Log("Inicializamos reqManager con " & B4XPages.MainPage.server)
|
||||
reqManager.Initialize(Me, B4XPages.MainPage.server)
|
||||
LogColor($"ReqServer = ${B4XPages.MainPage.server}"$, Colors.red)
|
||||
reinicializaReqManager
|
||||
p_appUpdate.Visible = False
|
||||
' Entrar.Visible = True
|
||||
End Sub
|
||||
|
||||
Private Sub lv_server_ItemClick (Position As Int, Value As Object)
|
||||
server = Value
|
||||
' l_server.Text = Value
|
||||
et_server.Text = Value
|
||||
reqManager.Initialize(Me, Value)
|
||||
LogColor($"ReqServer = ${Value}"$, Colors.red)
|
||||
ToastMessageShow("Servidor modificado", False)
|
||||
End Sub
|
||||
|
||||
Sub reinicializaReqManager
|
||||
reqManager.Initialize(Me, B4XPages.MainPage.server)
|
||||
If logger Then Log(B4XPages.MainPage.server)
|
||||
LogColor($"ReqServer = ${B4XPages.MainPage.server}"$, Colors.red)
|
||||
End Sub
|
||||
|
||||
'appUpdater - Mostramos el anuncio de que se esta descargando el nuevo apk
|
||||
Sub muestraProgreso(mensaje As String)
|
||||
ProgressDialogShow(mensaje)
|
||||
End Sub
|
||||
|
||||
'appUpdater - Ocultamos el anuncio de que se esta descargando el nuevo apk
|
||||
Sub ocultaProgreso
|
||||
ProgressDialogHide
|
||||
End Sub
|
||||
1
gitpull.bat
Normal file
@@ -0,0 +1 @@
|
||||
git pull
|
||||