feat: gestión packing proveedores refs #7143
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Carlos Andrés 2024-03-26 11:30:46 +01:00
parent 9dcc885484
commit 42768f527f
2 changed files with 70 additions and 6 deletions

View File

@ -10,9 +10,15 @@ BEGIN
* @param vFromDated Fecha de la que partir
* @param vSupplierFk Id del proveedor
*/
DECLARE vClientfk INTEGER;
SET @vBalance = 0;
SET @vItemFk = NULL;
SELECT c.id INTO vClientFk
FROM supplier s
JOIN client c ON c.fi = s.nif
WHERE s.id = vSupplierFk;
CREATE OR REPLACE TEMPORARY TABLE tSupplierPackaging
SELECT supplierFk,
itemFk,
@ -45,6 +51,46 @@ BEGIN
WHERE supplierFk = vSupplierFk
AND landed >= vFromDated
UNION ALL
SELECT vSupplierFk,
p.itemFk,
i.name,
c.name,
t.id,
t.landed,
0,
SUM(tp.quantity),
NULL,
0
FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk
JOIN item i ON i.id = p.itemFk
JOIN ticket t ON t.id = tp.ticketFk
JOIN client c ON c.id = t.clientFk
WHERE c.id = vClientFk
AND t.landed >= vFromDated
AND tp.quantity > 0
AND p.itemFk
UNION ALL
SELECT vSupplierFk,
p.itemFk,
i.name,
c.name,
t.id,
t.landed,
SUM(tp.quantity),
0,
NULL,
0
FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk
JOIN item i ON i.id = p.itemFk
JOIN ticket t ON t.id = tp.ticketFk
JOIN client c ON c.id = t.clientFk
WHERE c.id = vClientFk
AND t.landed >= vFromDated
AND tp.quantity < 0
AND p.itemFk
UNION ALL
SELECT vSupplierFk,
itemFk,
longName,
@ -59,7 +105,8 @@ BEGIN
WHERE supplierFk = vSupplierFk
AND landed < vFromDated
GROUP BY itemFk
ORDER BY itemFk, landed, entryFk
ORDER BY itemFk, landed, entryFk DESC
LIMIT 10000000000000000000
) sub
WHERE `out` OR `in`;

View File

@ -64,16 +64,15 @@ BEGIN
SET vGraceDate = vGraceDate -INTERVAL 1 MONTH;
END IF;
DROP TEMPORARY TABLE IF EXISTS tmp.packagingToInvoice;
CREATE TEMPORARY TABLE tmp.packagingToInvoice
CREATE OR REPLACE TEMPORARY TABLE tmp.packagingToInvoice
(INDEX (clientFk))
ENGINE = MEMORY
SELECT p.itemFk,
tp.packagingFk,
tp.quantity,
tp.ticketFk,
p.price,
t.clientFk
t.clientFk,
NULL
FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk
JOIN ticket t ON t.id = tp.ticketFk
@ -83,7 +82,25 @@ BEGIN
AND t.shipped BETWEEN vDateStart AND vDateEnd
AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate))
AND tp.quantity
AND p.itemFk;
AND p.itemFk
UNION ALL
(SELECT i.id,
p.id,
SUM(`in`) - SUM(`out`) quantity,
p.price,
c.id,
landed
FROM supplierPackaging sp
JOIN supplier s ON s.id = sp.supplierFk
JOIN client c ON c.fi = s.nif
JOIN item i ON i.id = sp.itemFk
JOIN packaging p ON p.itemFk = i.id
WHERE (vClientFk IS NULL OR c.id = vClientFk)
AND landed BETWEEN vDateStart AND vDateEnd
AND p.itemFk
GROUP BY c.id, i.id, landed
HAVING (quantity < 0 OR (quantity > 0 AND landed < vGraceDate))
AND quantity);
OPEN vCursor;
l: LOOP