feat: gestión packing proveedores refs #7143 #2212
|
@ -10,9 +10,15 @@ BEGIN
|
||||||
* @param vFromDated Fecha de la que partir
|
* @param vFromDated Fecha de la que partir
|
||||||
* @param vSupplierFk Id del proveedor
|
* @param vSupplierFk Id del proveedor
|
||||||
*/
|
*/
|
||||||
|
DECLARE vClientfk INTEGER;
|
||||||
SET @vBalance = 0;
|
SET @vBalance = 0;
|
||||||
SET @vItemFk = NULL;
|
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
|
CREATE OR REPLACE TEMPORARY TABLE tSupplierPackaging
|
||||||
SELECT supplierFk,
|
SELECT supplierFk,
|
||||||
itemFk,
|
itemFk,
|
||||||
|
@ -45,6 +51,46 @@ BEGIN
|
||||||
WHERE supplierFk = vSupplierFk
|
WHERE supplierFk = vSupplierFk
|
||||||
AND landed >= vFromDated
|
AND landed >= vFromDated
|
||||||
UNION ALL
|
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,
|
SELECT vSupplierFk,
|
||||||
itemFk,
|
itemFk,
|
||||||
longName,
|
longName,
|
||||||
|
@ -59,7 +105,8 @@ BEGIN
|
||||||
WHERE supplierFk = vSupplierFk
|
WHERE supplierFk = vSupplierFk
|
||||||
AND landed < vFromDated
|
AND landed < vFromDated
|
||||||
GROUP BY itemFk
|
GROUP BY itemFk
|
||||||
ORDER BY itemFk, landed, entryFk
|
ORDER BY itemFk, landed, entryFk DESC
|
||||||
|
LIMIT 10000000000000000000
|
||||||
) sub
|
) sub
|
||||||
WHERE `out` OR `in`;
|
WHERE `out` OR `in`;
|
||||||
|
|
||||||
|
|
|
@ -64,16 +64,15 @@ BEGIN
|
||||||
SET vGraceDate = vGraceDate -INTERVAL 1 MONTH;
|
SET vGraceDate = vGraceDate -INTERVAL 1 MONTH;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.packagingToInvoice;
|
CREATE OR REPLACE TEMPORARY TABLE tmp.packagingToInvoice
|
||||||
CREATE TEMPORARY TABLE tmp.packagingToInvoice
|
|
||||||
(INDEX (clientFk))
|
(INDEX (clientFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT p.itemFk,
|
SELECT p.itemFk,
|
||||||
tp.packagingFk,
|
tp.packagingFk,
|
||||||
tp.quantity,
|
tp.quantity,
|
||||||
tp.ticketFk,
|
|
||||||
p.price,
|
p.price,
|
||||||
t.clientFk
|
t.clientFk,
|
||||||
|
NULL
|
||||||
FROM ticketPackaging tp
|
FROM ticketPackaging tp
|
||||||
JOIN packaging p ON p.id = tp.packagingFk
|
JOIN packaging p ON p.id = tp.packagingFk
|
||||||
JOIN ticket t ON t.id = tp.ticketFk
|
JOIN ticket t ON t.id = tp.ticketFk
|
||||||
|
@ -83,7 +82,25 @@ BEGIN
|
||||||
AND t.shipped BETWEEN vDateStart AND vDateEnd
|
AND t.shipped BETWEEN vDateStart AND vDateEnd
|
||||||
AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate))
|
AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate))
|
||||||
AND tp.quantity
|
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;
|
OPEN vCursor;
|
||||||
l: LOOP
|
l: LOOP
|
||||||
|
|
Loading…
Reference in New Issue