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