29/11/23 - Cambios en respaldo diario

- Se agregó´la table CAT_RMI al respaldo.
- Cuando se restaura el respaldo, se suma el abordo al inventario de CAT_GUNAPROD2.
- Se agregó códigp para el limite de abordo (No esta terminado)
This commit is contained in:
2023-11-29 00:11:47 -06:00
parent feb1433e6b
commit 128855a742
9 changed files with 308 additions and 81 deletions

View File

@@ -25,13 +25,15 @@ Sub Class_Globals
Dim btAdmin As BluetoothAdmin
Dim RD_fechaRestauracion As String = ""
Private fechaRestauracion As String = ""
Private khdb As SQL
End Sub
'Inicializa la clase "kms_helperSubs".
'Ej. kh.Initialize(Me, "kh")
Public Sub Initialize (vCallback As Object, vEventName As String) As Object
'Inicializa la clase "kms_helperSubs", el tercer parametro es la base de datos que se va a usar.
'Ej. kh.Initialize(Me, "kh", skmt)
Public Sub Initialize (vCallback As Object, vEventName As String, db As SQL) As Object
EventName = vEventName
CallBack = vCallback
khdb = db
Return Me
End Sub
@@ -60,6 +62,7 @@ Sub RD_Init
safePath = Dirp & Dir
'Si no existe el directorio "kmts" en el raiz de la tarjeta de memoria, nos cambiamos al directorio seguro (sdcard/Android/data/kelloggs...)
If Not(File.IsDirectory(Dirp, Dir)) Then safePath = rp.GetSafeDirDefaultExternal("kmts")
Log($"Hay directirio: ${Dirp} ${Dir}- ${File.IsDirectory(Dirp, Dir)}"$)
If Starter.Logger Then Log($"Safepath:${safePath}"$)
Private name() As String = Regex.split(" ", Application.LabelName) 'Obtenemos el nombre de la app para ponerselo a la BD.
rkmt.Initialize(safePath, $"${name(0)}.rkmt.km"$, True)
@@ -70,6 +73,7 @@ Sub RD_Init
If chkIfTableExists(skmt, "CAT_GUNAPROD2") Then rkmt.ExecNonQuery($"create table if not exists CAT_GUNAPROD2 (${getTableColumnList(skmt, "CAT_GUNAPROD2")}, FECHA TEXT)"$)
If chkIfTableExists(skmt, "kmt_info") Then rkmt.ExecNonQuery($"create table if not exists kmt_info (${getTableColumnList(skmt, "kmt_info")}, FECHA TEXT)"$)
If chkIfTableExists(skmt, "PROMOS_COMP") Then rkmt.ExecNonQuery($"create table if not exists PROMOS_COMP (${getTableColumnList(skmt, "PROMOS_COMP")}, FECHA TEXT)"$)
If chkIfTableExists(skmt, "CAT_RMI") Then rkmt.ExecNonQuery($"create table if not exists CAT_RMI (${getTableColumnList(skmt, "CAT_RMI")}, FECHA TEXT)"$)
DateTime.DateFormat = "yyyyMMdd"
fechaHoy = DateTime.Date(DateTime.Now)
If Starter.Logger Then Log("RKMTS: " & rkmt.IsInitialized)
@@ -124,15 +128,23 @@ End Sub
'RD - Copia la tabla PEDIDO a rkmt.db en la tarjeta del celular.
Sub RD_respalda_pedido
Private inicio As String = DateTime.Now
DateTime.DateFormat = "MM/dd/yyyy"
Private fechaHoy2 As String = DateTime.Date(DateTime.Now)
' Log("Copiando PEDIDO ...")
Private x As Cursor = skmt.ExecQuery("select * from PEDIDO")
' Log(x.RowCount)
If x.RowCount > 0 Then
Private lasCols As String = getTableColumnListName(skmt, "PEDIDO")
rkmt.BeginTransaction
' rkmt.BeginTransaction
rkmt.ExecNonQuery($"delete from PEDIDO where FECHA = '${fechaHoy}'"$)
rkmt.ExecNonQuery($"insert into PEDIDO (${lasCols}, FECHA) select ${lasCols}, '${fechaHoy}' as FECHA from skmt1.PEDIDO where substr(pe_fecha, 1, 10) = '${fechaHoy}'"$)
rkmt.TransactionSuccessful 'Si no se pone TransactionSuccessful no se escribe NADA!!
rkmt.EndTransaction
rkmt.ExecNonQuery($"insert into PEDIDO (${lasCols}, FECHA) select ${lasCols}, '${fechaHoy}' as FECHA from skmt1.PEDIDO where substr(pe_fecha, 1, 10) = '${fechaHoy2}'"$)
' Private f As Cursor = rkmt.ExecQuery($"Select ${lasCols}, '${fechaHoy}' as FECHA from skmt1.PEDIDO where substr(pe_fecha, 1, 10) = '${fechaHoy2}'"$)
' Log($">>>>>> registros pedido : ${f.RowCount} - ${fechaHoy}"$)
' Private d As Cursor = skmt1.ExecQuery($"select ${lasCols}, '${fechaHoy}' as FECHA from PEDIDO where substr(pe_fecha, 1, 10) = '${fechaHoy}'"$)
' Log(d.RowCount)
' rkmt.TransactionSuccessful 'Si no se pone TransactionSuccessful no se escribe NADA!!
' rkmt.EndTransaction
End If
x.Close
LogColor("P: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
@@ -166,10 +178,10 @@ Sub RD_restaura_cat_gunaprod
Log(fechaRestauracion)
lasCols = lasCols.Replace(", FECHA", "") 'Quitamos la imagen del respaldo.
Private c As Cursor = rkmt.ExecQuery($"select distinct fecha from CAT_GUNAPROD ${fechaRestauracion} order by fecha desc"$) 'where fecha <> '${fechaHoy}' 'Traemos la ultima fecha antes de hoy.
Log(c.RowCount)
' Log(c.RowCount)
If c.RowCount > 0 Then
c.Position = 0
Log(c.GetString("FECHA"))
' Log(c.GetString("FECHA"))
skmt.ExecNonQuery("delete from CAT_GUNAPROD")
skmt.ExecNonQuery($"insert into CAT_GUNAPROD (${lasCols}) select ${lasCols} from rkmt1.CAT_GUNAPROD where fecha = '${c.GetString("FECHA")}'"$)
Log($"insert into CAT_GUNAPROD (${lasCols}) select ${lasCols} from rkmt1.CAT_GUNAPROD where fecha = '${c.GetString("FECHA")}'"$)
@@ -215,6 +227,29 @@ Sub RD_restaura_cat_gunaprod2
Else
ToastMessageShow($"No hay respaldo GP2 para la fecha ${fechaRestauracion.SubString(fechaRestauracion.Length - 10)}"$, True)
End If
'Agregamos al inventario las cantidades del abordo
Private sqlAbordo As String = ""
Private sqlfechaAbordo As String = ""
If fechaRestauracion = "" Then
sqlAbordo = "where PE_TIPO = 'ABORDO'"
sqlfechaAbordo = $"And fecha = '${fechaHoy}'"$
Else
sqlAbordo = "and PE_TIPO = 'ABORDO'"
sqlfechaAbordo = ""
End If
Private a As Cursor = rkmt.ExecQuery($"select * from PEDIDO ${fechaRestauracion} ${sqlAbordo} ${sqlfechaAbordo} order by fecha desc"$) 'where fecha <> '${fechaHoy}' 'Traemos la ultima fecha antes de hoy.
Log($"select * from PEDIDO ${fechaRestauracion} ${sqlAbordo} ${sqlfechaAbordo} order by fecha desc"$)
' Log(">>>>>>>> PEDIDOS " & a.RowCount)
If a.RowCount > 0 Then
For i = 0 To a.RowCount - 1
a.Position = i
skmt.ExecNonQuery($"update CAT_GUNAPROD2 set CAT_GP_ALMACEN = CAT_GP_ALMACEN + ${a.GetString("PE_CANT")} where CAT_GP_ID = '${a.GetString("PE_PROID")}'"$)
Log($"update CAT_GUNAPROD2 set CAT_GP_ALMACEN = CAT_GP_ALMACEN + ${a.GetString("PE_CANT")}' where CAT_GP_ID = '${a.GetString("PE_PROID")}'"$)
Next
Else
ToastMessageShow($"No hay respaldo GP2 para la fecha ${fechaRestauracion.SubString(fechaRestauracion.Length - 10)}"$, True)
End If
Log("R-GP2: " & ((DateTime.Now - inicio)/1000) & " segs")
End Sub
@@ -332,6 +367,57 @@ Sub RD_restaura_promos_comp
Log("R-KMT: " & ((DateTime.Now - inicio)/1000) & " segs")
End Sub
'RD - Copia la tabla cat_rmi a rkmt.db en la tarjeta del celular.
Sub RD_respalda_cat_rmi
Private inicio As String = DateTime.Now
' Log("Copiando cat_rmi ...")
Private x As Cursor = skmt.ExecQuery("select * from CAT_RMI")
If x.RowCount > 0 Then
Private lasCols As String = getTableColumnListName(skmt, "CAT_RMI")
rkmt.BeginTransaction
rkmt.ExecNonQuery($"delete from CAT_RMI where fecha = '${fechaHoy}'"$)
rkmt.ExecNonQuery($"insert into CAT_RMI (${lasCols}, FECHA) select ${lasCols}, '${fechaHoy}' as FECHA from skmt1.CAT_RMI"$)
rkmt.TransactionSuccessful 'Si no se pone TransactionSuccessful no se escribe NADA!!
rkmt.EndTransaction
End If
x.Close
LogColor("RMI: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
End Sub
'RD - Copia la tabla cat_rmi de rkmt.db al celular.
Sub RD_restaura_cat_rmi
Private inicio As String = DateTime.Now
' Log("Restaurando CAT_RMI ...")
fechaRestauracion = RD_fechaRestauracionSQL(RD_fechaRestauracion)
Private lasCols As String = getTableColumnListName(rkmt, "CAT_RMI")
lasCols = lasCols.Replace(", FECHA", "") 'Quitamos la fecha del respaldo.
Private c As Cursor = rkmt.ExecQuery($"select distinct fecha from CAT_RMI ${fechaRestauracion} order by fecha desc"$) 'where fecha <> '${fechaHoy}' 'Traemos la ultima fecha antes de hoy.
' Log(c.RowCount)
If c.RowCount > 0 Then
c.Position = 0
' Log(c.GetString("FECHA"))
skmt.ExecNonQuery("delete from CAT_RMI")
skmt.ExecNonQuery($"insert into CAT_RMI (${lasCols}) select ${lasCols} from rkmt1.CAT_RMI where fecha = '${c.GetString("FECHA")}'"$)
Log($"insert into CAT_RMI (${lasCols}) select ${lasCols} from rkmt1.CAT_RMI where fecha = '${c.GetString("FECHA")}'"$)
Else
ToastMessageShow($"No hay respaldo RMI para la fecha ${fechaRestauracion.SubString(fechaRestauracion.Length - 10)}"$, True)
End If
Log("R-RMI: " & ((DateTime.Now - inicio)/1000) & " segs")
End Sub
Sub respaldoBatch 'ignore
If RD_Init_IsInitialized Then
RD_respalda_cat_detalle_paq
RD_respalda_cat_gunaprod
RD_respalda_cat_gunaprod2
RD_respalda_kmt_info
RD_respalda_pedido
RD_respalda_promos_comp
RD_respalda_cat_rmi
Else
Log("****** RD NO INICIALIZADO ********")
End If
End Sub
'RD - Realiza un "vacuum" de la base de datos "rkmt".
Sub RD_vacuum 'ignore
@@ -513,7 +599,7 @@ End Sub
Sub traeCliente(db As SQL) As String 'ignore
Private c As Cursor
Private cl As String
c = skmt.ExecQuery("Select CUENTA from cuentaa")
c = db.ExecQuery("Select CUENTA from cuentaa")
c.Position=0
cl = c.GetString("CUENTA")
c.Close
@@ -521,17 +607,45 @@ Sub traeCliente(db As SQL) As String 'ignore
End Sub
'Regresa en un mapa el total de productos y monto del pedido del cliente actual
'resultado = {"productos":"antidad_de_productos", "monto":"costo_total"}
Sub traeTotalesClienteActual(db As SQL) As Map 'ignore
'resultado = {"productos":"cantidad_de_productos", "monto":"costo_total"}
Sub traeTotalesClienteActual As Map 'ignore
Private m As Map
m.Initialize
Private c_prodsX As Cursor = skmt.ExecQuery("select ifnull(sum(PE_CANT), 0) as cantProds, ifnull(sum(PE_COSTO_TOT), 0) as costoTotal FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc")
Private c_prodsX As Cursor = khdb.ExecQuery("select ifnull(sum(PE_CANT), 0) as cantProds, ifnull(sum(PE_COSTO_TOT), 0) as costoTotal FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa) order by PE_PRONOMBRE asc")
c_prodsX.Position = 0
' LogColor($"Productos de la orden: ${c_prodsX.GetString("cantProds")}, Total: ${c_prodsX.GetString("costoTotal")}"$, Colors.red)
m = CreateMap("productos": c_prodsX.GetString("cantProds"), "monto" : c_prodsX.GetString("costoTotal"))
Return m
End Sub
'Regresa el TOTAL de la venta del cliente
Sub traeTotalCliente As Double
Private sumaTotal As Double
Private cursorprueba As Cursor = khdb.ExecQuery2("select PE_COSTO_TOT from pedido where PE_CEDIS <> PE_PROID and pe_cliente in (Select CUENTA from cuentaa) AND PE_CEDIS <> ?", Array As String("DOE"))
For i= 0 To cursorprueba.RowCount -1
cursorprueba.Position = i
' LogColor(cursorprueba.GetString("PE_COSTO_TOT"),Colors.Red)
sumaTotal = sumaTotal + cursorprueba.GetString("PE_COSTO_TOT")
sumaTotal = NumberFormat2(sumaTotal, 0, 2, 2, False)
' Log(NumberFormat2(sumaTotal, 0, 2, 2, False))
Next
cursorprueba.Close
Return sumaTotal
End Sub
'Regresa la venta de la ruta desde pedido.
Sub traeVenta As Double 'ignore
Private sumatotal As Double = 0
Private cursorprueba As Cursor = khdb.ExecQuery2("select PE_COSTO_TOT from pedido where PE_CEDIS <> PE_PROID and PE_CLIENTE <> 0 and PE_CEDIS <> ?", Array As String("DOE"))
For i = 0 To cursorprueba.RowCount - 1
cursorprueba.Position = i
sumatotal = sumatotal + cursorprueba.GetDouble("PE_COSTO_TOT")
' Log("Total venta: " & NumberFormat2(sumatotal, 0, 2, 2, False))
Next
cursorprueba.Close
Return NumberFormat2(sumatotal, 0, 2, 2, False)
End Sub
'Borra el pedido del cliente actual.
'Borra los registros de la tabla "PEDIDO" y "PEDIDO_CLIENTE"
'Actualiza las tablas "cat_gunaprod" y "kmt_info".
@@ -574,6 +688,44 @@ Sub hayPedido(db As SQL) As Boolean 'ignore
Return hay
End Sub
'Regresa el limite de abordo especificado en web.
Sub traeLimiteAbordoWeb As Double 'ignore
Private limite As Int = 0
Private c As Cursor = khdb.ExecQuery("select CAT_VA_VALOR from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'LIMITE'")
If c.RowCount > 0 Then
c.Position = 0
limite = c.GetString("CAT_VA_VALOR")
End If
c.Close
Return limite
End Sub
'Regresa el limite de abordo de acuerdo al inventario actual.
'Se calcula multiplicando el inventario por el precio del inventario
Sub traeLimiteAbordoXInventario As Double 'ignore
Private limiteInicial As Double = 0
Private c As Cursor = khdb.ExecQuery2("select sum(cat_gp_precio * cat_gp_almacen) as limiteInicial from cat_gunaprod2 where cat_gp_almacen > 0 and cat_gp_clasif <> ? ", Array As String("PROMOS"))
If c.RowCount > 0 Then
c.Position = 0
limiteInicial = c.GetDouble("limiteInicial")
End If
c.Close
Return limiteInicial
End Sub
'Regresa el total de la venta de abordo en la tabla pedido.
Sub traeVentaAbordo As Double
Log("Venta abordo")
Private va As Double = 0
Private c As Cursor = khdb.ExecQuery("select sum(PE_COSTO_TOT) as ventaAbordo from pedido where PE_TIPO = 'ABORDO'")
If c.RowCount > 0 Then
c.Position = 0
va = c.GetDouble("ventaAbordo")
End If
Log("VENTA ABORDO: " & va)
Return va
End Sub
Sub string2date(fecha As String) 'ignore
Log(fecha)
DateTime.DateFormat = "MM/dd/yyyy"
@@ -613,7 +765,7 @@ Sub ticksAformatoFecha(fecha As Long, formato As String) As String 'ignore
End Sub
'Revisa si la aplicación tiene permiso para acceder a las notificaciones.
Sub CheckNotificationAccess As Boolean
Sub CheckNotificationAccess As Boolean 'ignore
Dim ph As Phone
Dim nstr, pstr As String
Dim r As Reflector