Merge branch 'master' into 5699-hoFixClientsDisable
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-05-08 10:44:15 +00:00
commit ce42cbf287
2 changed files with 70 additions and 80 deletions

View File

@ -31,56 +31,49 @@ BEGIN
INTO vManaFromDays, vManaToDays INTO vManaFromDays, vManaToDays
FROM vn.salespersonConfig; FROM vn.salespersonConfig;
SELECT MAX(dated) SELECT MAX(dated) INTO vFromDated
INTO vFromDated
FROM vn.clientManaCache; FROM vn.clientManaCache;
DELETE DELETE FROM vn.clientManaCache
FROM vn.clientManaCache
WHERE dated = vFromDated; WHERE dated = vFromDated;
SELECT MAX(dated) SELECT MAX(dated) INTO vFromDated
INTO vFromDated
FROM vn.clientManaCache; FROM vn.clientManaCache;
IF ISNULL(vFromDated) THEN IF vFromDated IS NULL THEN
SELECT manaDateFrom SELECT manaDateFrom
INTO vFromDated INTO vFromDated
FROM vn.salespersonConfig; FROM vn.salespersonConfig;
END IF; END IF;
WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO
SELECT SELECT vFromDated + INTERVAL vManaToDays DAY,
vFromDated + INTERVAL vManaToDays DAY,
vFromDated - INTERVAL vManaFromDays DAY vFromDated - INTERVAL vManaFromDays DAY
INTO INTO vToDated,
vToDated,
vForDeleteDated; vForDeleteDated;
DELETE FROM vn.clientManaCache DELETE FROM vn.clientManaCache
WHERE dated <= vForDeleteDated; WHERE dated <= vForDeleteDated;
INSERT INTO vn.clientManaCache(clientFk, mana, dated) INSERT INTO vn.clientManaCache(clientFk, mana, dated)
SELECT SELECT Id_Cliente,
Id_Cliente,
SUM(mana), SUM(mana),
vToDated vToDated
FROM FROM (
( SELECT a.clientFk Id_Cliente, s.quantity * sc.value mana
SELECT cs.Id_Cliente, Cantidad * Valor as mana
FROM vn.ticket t FROM vn.ticket t
JOIN vn2008.Consignatarios cs using(Id_Consigna) JOIN vn.address a ON a.id = t.addressFk
JOIN vn2008.Movimientos m on m.Id_Ticket = t.id JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento JOIN vn.saleComponent sc ON sc.saleFk = s.id
WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId) WHERE sc.componentFk IN (vManaAutoId, vManaId, vClaimManaId)
AND t.shipped > vFromDated AND t.shipped > vFromDated
AND date(t.shipped) <= vToDated AND DATE(t.shipped) <= vToDated
UNION ALL UNION ALL
SELECT r.Id_Cliente, - Entregado SELECT clientFk, - amountPaid
FROM vn2008.Recibos r FROM vn.receipt
WHERE Id_Banco = vManaBankId WHERE bankFk = vManaBankId
AND Fechacobro > vFromDated AND payed > vFromDated
AND Fechacobro <= vToDated AND payed <= vToDated
UNION ALL UNION ALL
SELECT clientFk, amount SELECT clientFk, amount
FROM vn.greuge FROM vn.greuge

View File

@ -21,9 +21,6 @@ BEGIN
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDated);
-- Añadido temporalmente para ver si ya no sucede el cuelgue de db
SET vShowType = TRUE;
WITH itemTags AS ( WITH itemTags AS (
SELECT i.id, SELECT i.id,
typeFk, typeFk,
@ -82,7 +79,7 @@ BEGIN
AND iss.warehouseFk = vWarehouseFk AND iss.warehouseFk = vWarehouseFk
JOIN itemTags its JOIN itemTags its
WHERE a.available > 0 WHERE a.available > 0
AND IF(vShowType, i.typeFk = its.typeFk, TRUE) AND (i.typeFk = its.typeFk OR NOT vShowType)
AND i.id <> vSelf AND i.id <> vSelf
ORDER BY `counter` DESC, ORDER BY `counter` DESC,
(t.name = its.name) DESC, (t.name = its.name) DESC,