mirror of
https://github.com/KeymonSoft/Guna_Preventa.git
synced 2026-04-17 12:56:17 +00:00
Se agrega los colores paras que no se confundan y se corrige que si no tienen venta y entran al res dia no truene
This commit is contained in:
@@ -2848,6 +2848,7 @@ Sub resdia_Click
|
||||
' s3.Close
|
||||
|
||||
Private s3 As Cursor = B4XPages.MainPage.skmt.ExecQuery("select distinct(pe_cliente) FROM PEDIDO")
|
||||
|
||||
If s3.RowCount > 0 Then
|
||||
Private total1 As String = 0
|
||||
For i = 0 To s3.RowCount - 1
|
||||
@@ -2858,6 +2859,8 @@ Sub resdia_Click
|
||||
' LogColor($"Total despues ${total1}"$, Colors.blue)
|
||||
Next
|
||||
L_REAL.Text = total1
|
||||
Else
|
||||
L_REAL.Text = 0
|
||||
End If
|
||||
|
||||
'Prueba0
|
||||
@@ -2919,6 +2922,8 @@ Sub resdia_Click
|
||||
c.Close
|
||||
End If
|
||||
' L_REAL.Text = l_monto_ks.Text
|
||||
Log(L_NES.Text)
|
||||
Log(L_REAL.Text)
|
||||
L_ALCANCE.Text = Round2((L_NES.Text / L_REAL.Text + 1),2)
|
||||
L_VPLAN.Text = l_porvisitar.Text
|
||||
L_VREAL.Text = L_CUANTOST.text
|
||||
|
||||
@@ -116,32 +116,58 @@ Sub B4XPage_Appear
|
||||
' --- 2. Query 2: (MODIFICADO) ---
|
||||
' Este es el query de SQLite que hicimos, adaptado
|
||||
' para usar la variable 'nombreProducto'
|
||||
' Dim sql As String = $"
|
||||
' WITH FechasObjetivo (Fecha) AS (
|
||||
' SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-28 days'))
|
||||
' UNION ALL
|
||||
' SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-21 days'))
|
||||
' UNION ALL
|
||||
' SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-14 days'))
|
||||
' UNION ALL
|
||||
' SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-7 days'))
|
||||
' )
|
||||
' SELECT
|
||||
' COALESCE(SUM(H.HVD_CANT), 0) AS HVD_CANT_TOTAL
|
||||
' FROM
|
||||
' FechasObjetivo AS F
|
||||
' LEFT JOIN
|
||||
' HIST_VENTAS AS H
|
||||
' ON F.Fecha = H.HVD_FECHA
|
||||
' AND H.HVD_CLIENTE IN (SELECT CUENTA FROM cuentaa)
|
||||
' AND H.HVD_PRONOMBRE = '${nombreProducto}'
|
||||
' GROUP BY
|
||||
' F.Fecha
|
||||
' ORDER BY
|
||||
' SUBSTR(F.Fecha, 7, 4),
|
||||
' SUBSTR(F.Fecha, 4, 2),
|
||||
' SUBSTR(F.Fecha, 1, 2)
|
||||
' "$
|
||||
|
||||
|
||||
Dim sql As String = $"
|
||||
WITH FechasObjetivo (Fecha) AS (
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-28 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-21 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-14 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-7 days'))
|
||||
)
|
||||
SELECT
|
||||
COALESCE(SUM(H.HVD_CANT), 0) AS HVD_CANT_TOTAL
|
||||
FROM
|
||||
FechasObjetivo AS F
|
||||
LEFT JOIN
|
||||
HIST_VENTAS AS H
|
||||
ON F.Fecha = H.HVD_FECHA
|
||||
AND H.HVD_CLIENTE IN (SELECT CUENTA FROM cuentaa)
|
||||
AND H.HVD_PRONOMBRE = '${nombreProducto}'
|
||||
GROUP BY
|
||||
F.Fecha
|
||||
ORDER BY
|
||||
SUBSTR(F.Fecha, 7, 4),
|
||||
SUBSTR(F.Fecha, 4, 2),
|
||||
SUBSTR(F.Fecha, 1, 2)
|
||||
"$
|
||||
WITH FechasObjetivo (Fecha) AS (
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-28 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-21 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-14 days'))
|
||||
UNION ALL
|
||||
SELECT strftime('%d/%m/%Y', date('now', 'localtime', '-7 days'))
|
||||
)
|
||||
SELECT
|
||||
COALESCE(SUM(H.HVD_CANT), 0) AS HVD_CANT_TOTAL,
|
||||
-- Si el mes de la fecha es igual al mes actual, devuelve 1, si no 0
|
||||
CASE WHEN SUBSTR(F.Fecha, 4, 2) = strftime('%m', 'now', 'localtime') THEN 1 ELSE 0 END AS EsMesActual
|
||||
FROM
|
||||
FechasObjetivo AS F
|
||||
LEFT JOIN
|
||||
HIST_VENTAS AS H
|
||||
ON F.Fecha = H.HVD_FECHA
|
||||
AND H.HVD_CLIENTE IN (SELECT CUENTA FROM cuentaa)
|
||||
AND H.HVD_PRONOMBRE = '${nombreProducto}'
|
||||
GROUP BY F.Fecha
|
||||
ORDER BY SUBSTR(F.Fecha, 7, 4), SUBSTR(F.Fecha, 4, 2), SUBSTR(F.Fecha, 1, 2)
|
||||
"$
|
||||
|
||||
' Log($"Ejecutando para: ${nombreProducto}")
|
||||
' Log(sql) ' Descomenta esto si necesitas depurar el query
|
||||
@@ -151,30 +177,58 @@ Sub B4XPage_Appear
|
||||
' --- 3. Leer los 4 resultados (YA NO NECESITAMOS BUCLE) ---
|
||||
' Sabemos que el query SIEMPRE devuelve 4 filas
|
||||
' en el orden correcto (hace 28, 21, 14, 7 días)
|
||||
Log(prohit2.RowCount)
|
||||
' Log(prohit2.RowCount)
|
||||
' If prohit2.RowCount = 4 Then
|
||||
' prohit2.Position = 0
|
||||
' cant_sem4 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 1 (-28 días)
|
||||
'
|
||||
' prohit2.Position = 1
|
||||
' cant_sem3 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 2 (-21 días)
|
||||
'
|
||||
' prohit2.Position = 2
|
||||
' cant_sem2 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 3 (-14 días)
|
||||
'
|
||||
' prohit2.Position = 3
|
||||
' cant_sem1 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 4 (-7 días)
|
||||
' Else
|
||||
' Log($"Error: El query no devolvió 4 filas para '${nombreProducto}'"$)
|
||||
' End If
|
||||
'
|
||||
' prohit2.Close ' Cerramos el cursor interno
|
||||
'
|
||||
Dim promx As Double = (cant_sem4 + cant_sem3 + cant_sem2 + cant_sem1) / 4
|
||||
'
|
||||
'
|
||||
' CustomListView1.Add(CreateListItem(nombreProducto, cant_sem4, cant_sem3, cant_sem2, cant_sem1, promx ), 1)
|
||||
|
||||
|
||||
' Variables nuevas para el color (1 = Mes Actual, 0 = Otro)
|
||||
Dim c1, c2, c3, c4 As Int
|
||||
|
||||
If prohit2.RowCount = 4 Then
|
||||
prohit2.Position = 0
|
||||
cant_sem4 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 1 (-28 días)
|
||||
|
||||
prohit2.Position = 1
|
||||
cant_sem3 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 2 (-21 días)
|
||||
|
||||
prohit2.Position = 2
|
||||
cant_sem2 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 3 (-14 días)
|
||||
|
||||
prohit2.Position = 3
|
||||
cant_sem1 = prohit2.GetString("HVD_CANT_TOTAL") ' Fila 4 (-7 días)
|
||||
Else
|
||||
Log($"Error: El query no devolvió 4 filas para '${nombreProducto}'"$)
|
||||
End If
|
||||
|
||||
prohit2.Close ' Cerramos el cursor interno
|
||||
|
||||
Dim promx As Double = (cant_sem4 + cant_sem3 + cant_sem2 + cant_sem1) / 4
|
||||
|
||||
|
||||
CustomListView1.Add(CreateListItem(nombreProducto, cant_sem4, cant_sem3, cant_sem2, cant_sem1, promx ), 1)
|
||||
cant_sem4 = prohit2.GetString("HVD_CANT_TOTAL")
|
||||
c1 = prohit2.GetInt("EsMesActual")
|
||||
|
||||
prohit2.Position = 1
|
||||
cant_sem3 = prohit2.GetString("HVD_CANT_TOTAL")
|
||||
c2 = prohit2.GetInt("EsMesActual")
|
||||
|
||||
prohit2.Position = 2
|
||||
cant_sem2 = prohit2.GetString("HVD_CANT_TOTAL")
|
||||
c3 = prohit2.GetInt("EsMesActual")
|
||||
|
||||
prohit2.Position = 3
|
||||
cant_sem1 = prohit2.GetString("HVD_CANT_TOTAL")
|
||||
c4 = prohit2.GetInt("EsMesActual")
|
||||
Else
|
||||
Log("Error en filas")
|
||||
End If
|
||||
prohit2.Close
|
||||
|
||||
' Pasamos los indicadores de color al método (c1, c2, c3, c4)
|
||||
CustomListView1.Add(CreateListItem(nombreProducto, cant_sem4, cant_sem3, cant_sem2, cant_sem1, promx, c1, c2, c3, c4), 1)
|
||||
'
|
||||
Next
|
||||
|
||||
prohit.Close ' Cerramos el cursor externo
|
||||
@@ -187,16 +241,52 @@ Sub B4XPage_Appear
|
||||
End Sub
|
||||
|
||||
|
||||
Sub CreateListItem(prodhis As String, s1 As Int, s2 As Int, s3 As Int,s4 As Int, prom As Double) As Panel 'ignore
|
||||
'Sub CreateListItem(prodhis As String, s1 As Int, s2 As Int, s3 As Int,s4 As Int, prom As Double) As Panel 'ignore
|
||||
' Dim p As B4XView = xui.CreatePanel("")
|
||||
' p.SetLayoutAnimated(0, 0, 0, 288dip, 170dip)
|
||||
' p.LoadLayout("historicobat")
|
||||
' l_productohist.Text = prodhis
|
||||
' l_s1.Text = s1
|
||||
' l_s2.Text = s2
|
||||
' l_s3.Text = s3
|
||||
' l_s4.Text = s4
|
||||
' L_PROMEDIOHIST.text = "Promedio " & prom
|
||||
'
|
||||
' Return p
|
||||
'End Sub
|
||||
|
||||
|
||||
Sub CreateListItem(prodhis As String, s1 As Int, s2 As Int, s3 As Int, s4 As Int, prom As Double, m1 As Int, m2 As Int, m3 As Int, m4 As Int) As Panel
|
||||
Dim p As B4XView = xui.CreatePanel("")
|
||||
' p.SetLayoutAnimated(0, 0, 0, 100%x, 170dip) ' En B4A es mejor usar %x para el ancho
|
||||
p.SetLayoutAnimated(0, 0, 0, 288dip, 170dip)
|
||||
p.LoadLayout("historicobat")
|
||||
|
||||
l_productohist.Text = prodhis
|
||||
l_s1.Text = s1
|
||||
l_s2.Text = s2
|
||||
l_s3.Text = s3
|
||||
l_s4.Text = s4
|
||||
L_PROMEDIOHIST.text = "Promedio " & prom
|
||||
|
||||
|
||||
' Cambiar color de fondo de los labels según el mes
|
||||
' Si mX es 1 (mes actual) -> Azul, si no -> Amarillo
|
||||
l_s1.Color = IIf(m1 = 1, xui.Color_Blue, xui.Color_Yellow)
|
||||
l_s2.Color = IIf(m2 = 1, xui.Color_Blue, xui.Color_Yellow)
|
||||
l_s3.Color = IIf(m3 = 1, xui.Color_Blue, xui.Color_Yellow)
|
||||
l_s4.Color = IIf(m4 = 1, xui.Color_Blue, xui.Color_Yellow)
|
||||
|
||||
' Opcional: Cambiar el color del texto para que contraste
|
||||
l_s1.TextColor = IIf(m1 = 1, xui.Color_White, xui.Color_Black)
|
||||
l_s2.TextColor = IIf(m2 = 1, xui.Color_White, xui.Color_Black)
|
||||
l_s3.TextColor = IIf(m3 = 1, xui.Color_White, xui.Color_Black)
|
||||
l_s4.TextColor = IIf(m4 = 1, xui.Color_White, xui.Color_Black)
|
||||
|
||||
L_PROMEDIOHIST.Text = "Promedio " & NumberFormat(prom, 1, 2)
|
||||
|
||||
Return p
|
||||
End Sub
|
||||
|
||||
' Función auxiliar por si no tienes activado el IIf de B4A (disponible en versiones recientes)
|
||||
'Sub IIf(Condition As Boolean, TrueValue As Object, FalseValue As Object) As Object
|
||||
' If Condition Then Return TrueValue Else Return FalseValue
|
||||
'End Sub
|
||||
Binary file not shown.
@@ -88,6 +88,6 @@ ModuleClosedNodes6=
|
||||
ModuleClosedNodes7=6,8,9,10,11
|
||||
ModuleClosedNodes8=
|
||||
ModuleClosedNodes9=
|
||||
NavigationStack=B4XMainPage,Class_Globals,30,0,C_Cliente,recalculoXcant,1300,0,C_Cliente,B4XPage_Appear,542,0,C_Cliente,LA_GPS_Click,1353,0,Tracker,StartFLP2,403,0,Tracker,StartFLPSmall,421,0,Tracker,CreateLocationRequest2,462,1,Tracker,CreateLocationRequestSmallD,453,1,C_Cliente,MejorarPrecisionGPS,1283,4,Tracker,CreateLocationRequest,440,0
|
||||
NavigationStack=Tracker,StartFLPSmall,417,0,C_Principal,resdia_Click,2747,3,C_Cliente,Class_Globals,126,0,C_Cliente,InicializarLocalizacionMejorada,1391,0,Diseñador Visual,cliente.bal,-100,2,C_Cliente,HIST_Click,2829,0,C_historicobat,B4XPage_Created,52,0,C_historicobat,Class_Globals,0,0,C_historicobat,B4XPage_Appear,223,0,C_historicobat,CreateListItem,255,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=27,2,16,28,5,13,17,29,19,4,12,22
|
||||
VisibleModules=27,2,16,28,5,13,17,29,19,4,10
|
||||
|
||||
Reference in New Issue
Block a user