B4A=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=12.8 @EndOfDesignText@ ' Clase para las funciones de Trend Spending. ' Trend spending son 3 presupuestos que tiene Kelloggs, que son bonificaciones, descuentos y RMIs, estos se calculan semanalmente ' y se descargan de la tabla HIST_TRADE_SPENDING_SEMANAL, de ahi obtenemos el presupuesto de la semana y el acumulado hasta ayer ' en la noche, a cada presupuesto le vamos sumando cada que agregamos a pedido un DESCUENTO (Precios diferentes al original que ' NO están en PROMOS), una BONIFICACION (precios con descuento que estan en promociones) o un RMI (de estos sumamos al presupuesto ' el precio del RMI seleccionado), de acuerdo al presupuesto disponible de cada tipo, se limitan los productos, es decir que si ' el presupuesto de bonificaciones ya se agoto, ya no aparecen promociones, o si el de descuentos se agoto, ya no se pueden agregar ' mas productos con descuento. ' Descuento es TODO lo que tenga un precio diferente al precio de lista y NO esta en promo. ' Bonificacion es lo que tiene precio diferente al orginal y esta en promo y NO es regalo o exhibidor. Sub Class_Globals Private EventName As String 'ignore Private CallBack As Object 'ignore Dim tsMaximas As Int = 0 Private tsdb As SQL Dim TS_RMI() As String Dim TS_DESCUENTOS() As String Dim TS_BONIFICACIONES() As String End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize (vCallback As Object, vEventName As String, db As SQL) As Object EventName = vEventName CallBack = vCallback tsdb = db Private mx As Map = traeInfoTrendSpending LogColor(mx, Colors.red) TS_RMI = Regex.Split(",", mx.Get("RMI")) TS_DESCUENTOS = Regex.Split(",", mx.Get("DESCUENTOS")) TS_BONIFICACIONES = Regex.Split(",", mx.Get("BONIFICACIONES")) LogColor(">>>>>>>>>>>>> TRENDSPENDING: " & mx, Colors.red) LogColor("RMI: " & TS_RMI(0) & "|" & TS_RMI(1), Colors.red) LogColor("DESCUENTOS: " & TS_DESCUENTOS(0) & "|" & TS_DESCUENTOS(1), Colors.red) LogColor("BONIFICACIONES: " & TS_BONIFICACIONES(0) & "|" & TS_BONIFICACIONES(1), Colors.red) Return Me End Sub 'Regresa la tabla de productos (cat_gunaprod o cat_gunaprod2) dependiendo del tipo de venta. Sub traeTablaProds(tipoventa As String) As String Private tablaProds As String = "cat_gunaprod2" If tipoventa = "ABORDO" Or tipoventa = "PREVENTA" Then tablaProds = "cat_gunaprod" ' LogColor($"Tipo= ${tipoventa}, tabla=${tablaProds}"$, Colors.RGB(200,136,0)) Return tablaProds End Sub 'Regresa el descuento de condiciones comerciales por SKU. Sub traeDescXSku(clienteId As String, prodId As String) As String 'ignore Private desc As String = "0" Private c As Cursor = tsdb.ExecQuery($"Select * from CAT_DESCUENTOS_SKU where CAT_DS_CLIENTE = '${clienteId}' and CAT_DS_PRODID = '${prodId}'"$) If c.RowCount > 0 Then c.Position = 0 desc = c.GetString("CAT_DS_PORCENTAJE") End If Return desc End Sub ' Regresa un mapa con el tipo, monto permitido semanal y el acumulado hasta el día anterior: ' ej: ' - RMI=1500,0 ' - DESCUENTOS=1500,0 ' - BONIFICACIONES=1500,480 Sub traeInfoTrendSpending As Map Private semana As Int = 0 Private HIST_TSS_SEMANA As String = 0 Private HIST_TSS_SEMANA_ACUM As String = 0 Private m As Map = CreateMap("RMI": 10000000 & "," & 0, "DESCUENTOS": 10000000 & "," & 0, "BONIFICACIONES": 10000000 & "," & 0) ' El 100,000 es el default del presupuesto, por si NO HAY datos de trend spending. ' m.Initialize Private c As Cursor = tsdb.ExecQuery($"select cat_va_valor from cat_variables where cat_va_descripcion = 'SEM_CAL_LABORAL'"$) If c.RowCount > 0 Then c.Position = 0 semana = c.GetInt("CAT_VA_VALOR") End If If semana > 0 Then c = tsdb.ExecQuery($"select HIST_TSS_TIPO, HIST_TSS_SEMANA${semana}, ifnull(HIST_TSS_SEMANA${semana}_ACUM,0) as HIST_TSS_SEMANA${semana}_ACUM from HIST_TREND_SPENDING_SEMANAL"$) Log($"select HIST_TSS_TIPO, HIST_TSS_SEMANA${semana}, ifnull(HIST_TSS_SEMANA${semana}_ACUM,0) as HIST_TSS_SEMANA${semana}_ACUM from HIST_TREND_SPENDING_SEMANAL"$) If c.RowCount > 0 Then For i = 0 To c.RowCount - 1 c.Position = i HIST_TSS_SEMANA = c.GetString($"HIST_TSS_SEMANA${semana}"$) If Not(IsNumber(HIST_TSS_SEMANA)) Then HIST_TSS_SEMANA = 0 Private xx As String = c.GetString($"HIST_TSS_SEMANA${semana}_ACUM"$) If xx = "null" Then xx = 0 HIST_TSS_SEMANA_ACUM = xx If c.GetString("HIST_TSS_TIPO") = "RMI" Then m.Put("RMI", HIST_TSS_SEMANA & "," & HIST_TSS_SEMANA_ACUM) else if c.GetString("HIST_TSS_TIPO") = "DESCUENTOS" Then m.Put("DESCUENTOS", HIST_TSS_SEMANA & "," & HIST_TSS_SEMANA_ACUM) else if c.GetString("HIST_TSS_TIPO") = "BONIFICACIONES" Then m.Put("BONIFICACIONES", HIST_TSS_SEMANA & "," & HIST_TSS_SEMANA_ACUM) End If Next End If End If Return m End Sub ' Modifica el acumulado del Trend Speding, le "suma" o "resta" al presupuesto especificado (RMI, BONIFICACIONES o DESCUENTOS) Sub modTrendSpending(accion As String, tipo As String, monto As String) LogColor($"#### ACCION: ${accion}, Tipo: ${tipo}, Monto: ${monto}"$, Colors.Blue) Private HIST_TSS_SEMANA As String Private HIST_TSS_SEMANA_ACUM As String Private acumulado As String = "0" If Starter.semana = 0 Then Private c As Cursor = tsdb.ExecQuery($"select cat_va_valor from cat_variables where cat_va_descripcion = 'SEM_CAL_LABORAL'"$) If c.RowCount > 0 Then c.Position = 0 Starter.semana = c.GetInt("CAT_VA_VALOR") End If End If HIST_TSS_SEMANA = $"HIST_TSS_SEMANA${Starter.semana}"$ HIST_TSS_SEMANA_ACUM = $"HIST_TSS_SEMANA${Starter.semana}_ACUM"$ Private d As Cursor = tsdb.ExecQuery($"select ifnull(acumulado, 0) as ACUMULADO from TREND_SPENDING where tipo = '${tipo.ToUpperCase}'"$) If d.RowCount > 0 Then d.Position = 0 acumulado = d.GetString("ACUMULADO") End If Log("acumulado:" & acumulado & " | monto: " & monto) Private c As Cursor = tsdb.ExecQuery($"select HIST_TSS_TIPO, ifnull(${HIST_TSS_SEMANA},0) as disponible, ifnull(${HIST_TSS_SEMANA_ACUM},0) as acumulado from HIST_TREND_SPENDING_SEMANAL where HIST_TSS_TIPO = '${tipo.ToUpperCase}'"$) ' Log(($"select HIST_TSS_TIPO, ${HIST_TSS_SEMANA} as disponible, ${HIST_TSS_SEMANA_ACUM} as acumulado from HIST_TREND_SPENDING_SEMANAL where HIST_TSS_TIPO = '${tipo.ToUpperCase}'"$)) Log("---- " & c.RowCount) If accion.ToUpperCase = "RESTA" Then If c.RowCount > 0 Then c.Position = 0 If tipo.ToUpperCase = "DESCUENTOS" Or tipo.ToUpperCase = "RMI" Or tipo.ToUpperCase = "BONIFICACIONES" Then Private nuevaBonificacion As String = NumberFormat2((acumulado + monto), 1, 2, 2, False) LogColor($"Nuevo acumulado ${tipo} = ${nuevaBonificacion}"$, Colors.Magenta) tsdb.ExecNonQuery($"delete from TREND_SPENDING where tipo = '${tipo.ToUpperCase}' "$) tsdb.ExecNonQuery($"insert into TREND_SPENDING (tipo, acumulado) values ('${tipo.ToUpperCase}', '${nuevaBonificacion}')"$) Log($"Insertamos en TRADE_SPENDING: ${nuevaBonificacion}"$) ' else if tipo.ToUpperCase = "RMI" Then End If End If else if accion.ToUpperCase = "SUMA" Then If c.RowCount > 0 Then c.Position = 0 If tipo.ToUpperCase = "DESCUENTOS" Or tipo.ToUpperCase = "RMI" Or tipo.ToUpperCase = "BONIFICACIONES" Then Private nuevaBonificacion As String = NumberFormat2((acumulado - monto), 1, 2, 2, False) LogColor($"Nueva bonificacion = ${nuevaBonificacion}"$, Colors.Magenta) tsdb.ExecNonQuery($"delete from TREND_SPENDING where tipo = '${tipo.ToUpperCase}' "$) tsdb.ExecNonQuery($"insert into TREND_SPENDING (tipo, acumulado) values ('${tipo.ToUpperCase}', '${nuevaBonificacion}')"$) End If End If End If End Sub Sub traeAcumuladoHoyTS(tipo As String) As String ' Private HIST_TSS_SEMANA As String ' Private HIST_TSS_SEMANA_ACUM As String Private acumulado As String = "0" If Starter.semana = 0 Then Private c As Cursor = tsdb.ExecQuery($"select cat_va_valor from cat_variables where cat_va_descripcion = 'SEM_CAL_LABORAL'"$) If c.RowCount > 0 Then c.Position = 0 Starter.semana = c.GetInt("CAT_VA_VALOR") End If End If ' HIST_TSS_SEMANA = $"HIST_TSS_SEMANA${Starter.semana}"$ ' HIST_TSS_SEMANA_ACUM = $"HIST_TSS_SEMANA${Starter.semana}_ACUM"$ Private d As Cursor = tsdb.ExecQuery($"select acumulado from TREND_SPENDING where tipo = '${tipo.ToUpperCase}'"$) If d.RowCount > 0 Then d.Position = 0 acumulado = d.GetString("ACUMULADO") End If ' LogColor($"Acumulado hoy de ${tipo}: "$ & acumulado, Colors.Blue) Return NumberFormat2(acumulado, 1, 2, 2, False) End Sub 'Trae el cliente de CUENTAA Sub traeCliente As String 'ignore Private c As Cursor Private cl As String c = Starter.skmt.ExecQuery("Select CUENTA from cuentaa") c.Position = 0 cl = c.GetString("CUENTA") c.Close Return cl End Sub Sub traePrecio(id As String) As String Private precio As String = "0" Private c As Cursor = tsdb.ExecQuery($"select cat_gp_precio from ${traeTablaProds(Starter.tipov)} where cat_gp_id = '${id}'"$) If c.RowCount > 0 Then c.Position = 0 precio = c.GetString("CAT_GP_PRECIO") End If Return precio End Sub Sub trendSpending(accion As String, tipo As String, clienteId As String, id As String, laCant As String, inv As Int) As String Private logger As Boolean = True LogColor("-------- > TRADE SPENDING < ---------", Colors.red) ' Log("DescxSku: " & traeDescXSku(clienteId, id)) Dim TS_RMI() As String Dim TS_DESCUENTOS() As String Dim TS_BONIFICACIONES() As String Private mx As Map = traeInfoTrendSpending TS_RMI = Regex.Split(",", mx.Get("RMI")) TS_DESCUENTOS = Regex.Split(",", mx.Get("DESCUENTOS")) TS_BONIFICACIONES = Regex.Split(",", mx.Get("BONIFICACIONES")) If tipo.ToUpperCase = "RMI" Then Private lasMaximas As Int = 0 Log($"Acumulado de RMIs: ${traeAcumuladoHoyTS("rmi")}"$) Private elMonto As String = NumberFormat2(traePrecioRMI(id), 1, 2, 2, False) If logger Then Log($"elMonto: ${elMonto}"$) ' If logger Then Log($"TS_RMI(0): ${TS_RMI(0)}"$) ' If logger Then Log($"TS_RMI(1): ${TS_RMI(1)}"$) If logger Then Log($"LaCant: ${laCant}"$) Private tsRestantes As String = (TS_RMI(0) - TS_RMI(1) - traeAcumuladoHoyTS("rmi")) Log($"tsRestantes: ${tsRestantes}"$) If accion.ToUpperCase = "PRODMAS" Then 'Regresa lasMaximas y elMonto separadas por un "|" If elMonto > 0 Then lasMaximas = ((laCant * elMonto) + tsRestantes) / elMonto If logger Then Log("lasMaximas: " & lasMaximas) If logger Then Log("traeAcumuladoHoyTS: " & traeAcumuladoHoyTS("rmi")) End If ' If laCant + 1 = lasMaximas Then ' ToastMessageShow("El presupuesto de RMI no permite agregar mas productos!!", False) ' End If If logger Then Log("EL RMI: " & elMonto) If logger Then Log($"lacant=${laCant} < lasMaximas=${lasMaximas} = ${laCant 0 Then lasMaximas = ((laCant * elMonto) + tsRestantes) / elMonto If logger Then Log("lasMaximas: " & lasMaximas) ' If logger Then Log("lasMaximas2: " & traeMaximas("descuentos", clienteId, id, laCant, "")) If logger Then Log("Acumulado hoy: " & traeAcumuladoHoyTS("descuentos")) End If If laCant = lasMaximas Then ToastMessageShow("El presupuesto de DESCUENTOS no permite agregar mas productos!!", False) End If If logger Then Log("EL MONTO: " & elMonto) If inv > 0 And laCant < lasMaximas Then modTrendSpending("resta", "descuentos", elMonto) ' Restamos al presupuesto de hoy (agregamos al acumulado). End If If logger Then Log(">>>> MONTO RESTANTE PRESUPUESTO: " & (TS_DESCUENTOS(0) - TS_DESCUENTOS(1) - traeAcumuladoHoyTS("descuentos"))) Return lasMaximas & "|" & elMonto else if accion.ToUpperCase = "PRODMENOS" Then 'Regresa descuentosMaximas y elMonto separadas por un "|" If logger Then Log("LaCANT= " & laCant & ", elMonto= " & elMonto) If laCant >= 0 Then modTrendSpending("suma", "descuentos", elMonto) ' Agregamos al presupuesto de hoy (restamos del acumulado). End If Return lasMaximas & "|" & elMonto else if accion.ToUpperCase = "TEXTCHANGED" Then If logger Then Log("TC") else if accion.ToUpperCase = "FOCUSCHANGED" Then 'Regresa descuentos maximas, SOLO correr esta parte si HASFOCUS es VERDADERO. If logger Then Log("FC") Private elMonto As String = traePrecio(id)*(traeDescXSku(clienteId, id)/100) If elMonto > 0 Then 'And HasFocus If logger Then Log("LA BONIFICACION: " & elMonto) Private tsRestantes As String = (TS_DESCUENTOS(0) - TS_DESCUENTOS(1) - traeAcumuladoHoyTS("descuentos")) If logger Then Log("Monto del PRESUPUESTO disponible: " & tsRestantes) lasMaximas = ((laCant * elMonto) + tsRestantes) / elMonto If logger Then Log("tsMaximas: " & lasMaximas) End If Return lasMaximas End If End If End Sub ' Trae el precio del RMI desde CAT_RMI. Sub traePrecioRMI(id As String) As String Private precio As String = "0" Private c As Cursor = tsdb.ExecQuery($"select cat_monto from cat_rmi where cat_id = '${id}'"$) If c.RowCount > 0 Then c.Position = 0 precio = c.GetString("CAT_MONTO") End If Return precio End Sub ' Traemos el monto (descuento total) del producto actual. ' Utiliza el descuento de condiciones comerciales por SKU (tabla CAT_DESCUENTOS). Sub traeMonto(clienteId As String, id As String) As String Private tsMonto As String tsMonto = NumberFormat2(traePrecio(id)*(traeDescXSku(clienteId, id)/100), 1, 2, 2, False) Return tsMonto End Sub ' Trae la cantidad máxima de rmis, bonificaciones o descuentos por presupuesto. Sub traeMaximas(tipo As String, clienteId As String, id As String, laCant As String, promoId As String) As Int Private tsMaximas As Int = 10000000 Private tsRestantes As String = 0 Private tsMonto As String '= traeMonto(clienteId, id) ' If tsMonto > 0 Then If tipo.ToUpperCase = "DESCUENTOS" Then tsMonto = NumberFormat2(traePrecio(id)*(traeDescXSku(clienteId, id)/100), 1, 2, 2, False) tsRestantes = (TS_DESCUENTOS(0) - TS_DESCUENTOS(1) - traeAcumuladoHoyTS("descuentos")) ' Traemos monto restante de Trend Spending para descuentos. else If tipo.ToUpperCase = "RMI" Then tsMonto = NumberFormat2(traePrecioRMI(id), 1, 2, 2, False) tsRestantes = (TS_RMI(0) - TS_RMI(1) - traeAcumuladoHoyTS("rmi")) ' Traemos monto restante de Trend Spending para rmis. ' else If tipo.ToUpperCase = "BONIFICACIONES" Then ' tsMonto = NumberFormat2(traeMontoBonificacion(id, promoId), 1, 2, 2, False) ' tsRestantes = (TS_BONIFICACIONES(0) - TS_BONIFICACIONES(1) - traeAcumuladoHoyTS("bonificaciones")) ' Traemos monto restante de Trend Spending para bonificaciones. End If ' Log($"${TS_BONIFICACIONES(0)} - ${TS_BONIFICACIONES(1)} - ${traeAcumuladoHoyTS("bonificaciones")}"$) ' Log($"((${laCant} * ${tsMonto}) + ${tsRestantes}) / ${tsMonto}"$) Log($"tsMonto: ${tsMonto}"$) Log($"tsRestantes: ${tsRestantes}"$) tsMaximas = ((laCant * tsMonto) + tsRestantes) / tsMonto ' End If Return tsMaximas End Sub ' Trae la cantidad máxima de productos con bonificacion por presupuesto. ' Si el presupuesto es 10 y la bonificacion del producto es 2, el máximo es 5 productos. Sub traeBonificacionesMaximas(tipo As String, clienteId As String, id As String, laCant As String, elPrecioVenta As String, promoId As String) As Int Private thisLog As Boolean = True Private tsMaximas As Int = 100000000 Private tsRestantes As String = 0 Private tsMonto As String Private mx As Map = traeInfoTrendSpending TS_RMI = Regex.Split(",", mx.Get("RMI")) TS_DESCUENTOS = Regex.Split(",", mx.Get("DESCUENTOS")) TS_BONIFICACIONES = Regex.Split(",", mx.Get("BONIFICACIONES")) If thisLog Then LogColor($" ============ INICIA BONIFICACIONES MAXIMAS (${id}) ========"$, Colors.RGB(0,197,110)) If thisLog Then LogColor($" Presupuesto: ${TS_BONIFICACIONES(0)} - Acumulado ayer: ${TS_BONIFICACIONES(1)} - Hoy: ${traeAcumuladoHoyTS("bonificaciones")}"$, Colors.Magenta) If tipo.ToUpperCase = "BONIFICACIONES" Then tsMonto = NumberFormat2(traeMontoBonificacion(id, elPrecioVenta, promoId), 1, 2, 2, False) tsRestantes = (TS_BONIFICACIONES(0) - TS_BONIFICACIONES(1) - traeAcumuladoHoyTS("bonificaciones")) ' Traemos monto restante de Trend Spending para bonificaciones. Log($" PresupuestoBonifs: ${TS_BONIFICACIONES(0)}, AcumuladoBonifs: ${TS_BONIFICACIONES(1)}, traeAcumuladoHoyTS('bonificaciones'): ${traeAcumuladoHoyTS("bonificaciones")}"$) ' Log($" ${TS_BONIFICACIONES(0)} - ${TS_BONIFICACIONES(1)} - ${traeAcumuladoHoyTS("bonificaciones")}"$) End If If thisLog Then Log($" Monto de bonificacion: ${tsMonto}"$) If thisLog Then Log($" Presupuesto disponible: ${tsRestantes}"$) ' If thisLog Then Log($"Cantidad: ${laCant}"$) If thisLog Then Log($" Floor(tsRestantes / (tsMonto * laCant)) <==> Floor(${tsRestantes} / (${tsMonto} * ${laCant})) = ${Floor(tsRestantes / (tsMonto * laCant))}"$) ' If thisLog Then Log($"Floor(${tsRestantes} / (${tsMonto} * ${laCant}))= ${Floor(tsRestantes / (tsMonto * laCant))}"$) If tsMonto > 0 Then tsMaximas = Floor(tsRestantes / (tsMonto * laCant)) End If If thisLog Then LogColor(" ************************************************", Colors.red) If thisLog Then LogColor(" ***** BONIFICACIONES MAXIMAS: " & tsMaximas & " *****", Colors.red) If thisLog Then LogColor(" ************************************************", Colors.red) If thisLog Then LogColor(" ============ TERMINA BONIFICACIONNES MAXIMAS ========", Colors.RGB(0,197,110)) Return tsMaximas End Sub ' Trae el monto de la bonificacion, que es el precio original MENOS el precio de venta con descuento. ' - Si CAT_DP_PRECIOB es 1, la bonificacion es: Precio original - precio de venta. ' - Si CAT_DP_PRECIOB es 0, la bonificacion es: Precio original. Sub traeMontoBonificacion(id As String, precio As String, promoId As String) As String Private thisLog As Boolean = True If thisLog Then LogColor($" ============ INICIA MONTO BONIFICACION (${id}) ========"$, Colors.RGB(151,0,171)) If thisLog Then LogColor($" ###### ${promoId}, ${precio}, ${id}"$, Colors.Magenta) Private tsMonto As String = 0 Private re As Cursor = Starter.skmt.ExecQuery($"select cat_gp_id from cat_gunaprod2 where (cat_gp_tipo like 'REGALO%' or cat_gp_tipo like 'EXHIBIDOR%') and cat_gp_id = '${id}'"$) ' Revisamos si el producto es regalo o exhibidor. If re.RowCount = 0 Then' No es regalo ni exhibidor. Private c As Cursor = tsdb.ExecQuery($"SELECT CAT_DP_ID, CAT_DP_IDPROD, CAT_DP_PRECIO, CAT_DP_TIPO, CAT_GP_PRECIO, CAT_DP_PRECIOB FROM CAT_DETALLES_PAQ join ${traeTablaProds(Starter.tipov)} on CAT_GP_ID = CAT_DP_IDPROD where CAT_GP_ID = '${id}' and CAT_DP_PRECIO = '${precio}' and CAT_DP_ID = '${promoId}'"$) ' Log($"SELECT CAT_DP_ID, CAT_DP_IDPROD, CAT_DP_PRECIO, CAT_DP_TIPO, CAT_GP_PRECIO, CAT_DP_PRECIOB FROM CAT_DETALLES_PAQ join ${traeTablaProds(Starter.tipov)} on CAT_GP_ID = CAT_DP_IDPROD where CAT_GP_ID = '${id}' and CAT_DP_PRECIO = '${precio}' and CAT_DP_ID = '${promoId}'"$) If thisLog Then Log($" Rowcount DP y CGP2: ${c.RowCount}"$) If c.RowCount > 0 Then c.Position = 0 If c.GetInt("CAT_DP_PRECIOB") = 1 Or (c.GetInt("CAT_DP_PRECIOB") = 0 And c.GetString("CAT_GP_PRECIO") = c.GetString("CAT_DP_PRECIO")) Then tsMonto = c.GetString("CAT_GP_PRECIO") - c.GetString("CAT_DP_PRECIO") ' Precio original - precio de venta. Else tsMonto = c.GetString("CAT_GP_PRECIO") ' Precio original. End If ' Log("PRECIOB: " & c.GetInt("CAT_DP_PRECIOB")) If thisLog Then Log($" Precio normal: ${c.GetString("CAT_GP_PRECIO")}, Precio desc: ${c.GetString("CAT_DP_PRECIO")}, Monto bonificacion: ${tsMonto}"$) End If ' Log("ROWCOUNT: " & c.RowCount) End If If thisLog Then LogColor($" ============ TERMINA MONTO BONIFICACION ========"$, Colors.RGB(151,0,171)) Return tsMonto End Sub ' Recibe una lista con los ids de los productos variables, revisa cada id para traer los maximos por presupuesto para ese producto ' y pone ese maximo en una lista, luego ordena esa lista para obtener el mas chico y regresa ese como maximo. ' esta funcion se va a aplicar en la funcion maxpromos como un limite mas para que no muestre las promociones. ' NOTA: hay que ver como y cuando dejar de mostrar promociones cuando quede poco presupuesto para bonificaciones. ' NOTA: Talvez se pueda hacer que cuando se entre a PROMOS, si ya no hay presupuesto suficiente, mande un toast o msgbox diciendo que ya ' se agoto el presupuesto. ' Aunque si hay suficiente para mostrar algunas promos ... pues que si las muestre. Sub maxPromosPorProdsVariables(idProdsVariables As List, promo As String)As Int Private logger As Boolean = False Private Maxs As Int = 10000000 Private prodsVariablesXPresupuestoBonificaciones As List Private prodsVariablesRequeridos As Int = traeProdsVariablesRequeridos(promo) prodsVariablesXPresupuestoBonificaciones.Initialize ' LogColor("===========> Prods Variables: " & idProdsVariables.Size & " <==========", Colors.red) For i = 0 To idProdsVariables.Size - 1 'Obtenemos total de productos variables disponibes. If logger Then LogColor($"=>> prodVariable ${i} : ${idProdsVariables.Get(i)}, ${Subs.traeProdNombre(idProdsVariables.Get(i))} <<=="$, Colors.blue) ' Log($"Este invDisponible: ${invDispParaPromo.Get(idProdsVariables.Get(i))}"$) If logger Then Log(">> Monto Bonificacion: " & traeMontoBonificacion(idProdsVariables.Get(i), 1, promo)) Private maxProds As Int = traeBonificacionesMaximas("bonificaciones", traeCliente, idProdsVariables.Get(i), prodsVariablesRequeridos, 1, promo) prodsVariablesXPresupuestoBonificaciones.Add(maxProds) Next prodsVariablesXPresupuestoBonificaciones.Sort(True) If prodsVariablesXPresupuestoBonificaciones.Size > 0 Then Maxs = prodsVariablesXPresupuestoBonificaciones.Get(0) End If If logger Then LogColor("=====>> Max prods variables x monto de bonificaciones: " & Maxs, Colors.blue) Return Maxs End Sub ' Regresa los productos variables requeridos de la promocion dada. Sub traeProdsVariablesRequeridos(promo As String) As Int Private pvr As Int = 0 Private c As Cursor = Starter.skmt.ExecQuery("Select CAT_GP_STS, CAT_GP_NOMBRE from CAT_GUNAPROD2 where CAT_GP_ID = '"& promo & "'") 'Obtenemos las piezas requeridas de productos variables para la promoción. If c.RowCount > 0 Then c.Position = 0 If c.RowCount > 0 Then c.Position = 0 pvr = c.GetString("CAT_GP_STS") End If End If c.Close Return pvr End Sub '######################################################################################## ' Los productos fijos NO estan restando del presupuesto de BONIFICACIONES '######################################################################################## 'Poner en una funcion (maxPromosPorProdsFijos) el codigo para traer las promos maximas por productos fijos, igual que la de productos ' variables, y ponerla igual en "traeMaxPromos" en lugar de en "revisaMaxPromosProdsFijosPorInventario". ' Falta el codigo para el funcionamiento diferente de las bonificaciones: ' Si CAT_DP_PRECIOB es 1 --> (Precio de original (cat_precio) - precio de venta) y se suma al acumulado de BONIFICACIONES ' Si CAT_DP_PRECIOB es 0 --> precio orginal se suma al acumulado de BONIFICACIONES 'Hay que traer desde web la columna "CAT_DP_PRECIOB" y gardarla en algun lado en movil!!