feat: refs #7709 supplierPackaging_ReportSource
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-07-29 13:26:52 +02:00
parent a95475ef61
commit f1dfd515e8
1 changed files with 28 additions and 18 deletions

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`(
vFromDated DATE, vFromDated DATE,
vSupplierFk INT vNif VARCHAR(50)
) )
BEGIN BEGIN
/** /**
@ -10,11 +10,23 @@ BEGIN
* @param vFromDated Starting date * @param vFromDated Starting date
* @param vSupplierFk Supplier ID * @param vSupplierFk Supplier ID
*/ */
DECLARE vUser INT;
SET @vBalance = 0; SET @vBalance = 0;
SET @vItemFk = NULL; SET @vItemFk = NULL;
SELECT id INTO vUser
FROM supplier
WHERE nif = vNif;
IF vUser IS NULL THEN
SELECT id INTO vUser
FROM client
WHERE fi = vNif;
END IF;
CREATE OR REPLACE TEMPORARY TABLE tSupplierPackaging CREATE OR REPLACE TEMPORARY TABLE tSupplierPackaging
SELECT supplierFk, SELECT vUser supplierFk,
itemFk, itemFk,
longName, longName,
supplier, supplier,
@ -31,7 +43,7 @@ BEGIN
) balance, ) balance,
@vItemFk := sub.itemFk previousItemFk @vItemFk := sub.itemFk previousItemFk
FROM ( FROM (
SELECT sp.supplierFk, SELECT vUser,
sp.itemFk, sp.itemFk,
sp.longName, sp.longName,
sp.supplier, sp.supplier,
@ -43,10 +55,11 @@ BEGIN
sp.buyingValue sp.buyingValue
FROM supplierPackaging sp FROM supplierPackaging sp
JOIN entry e ON e.id = sp.entryFk JOIN entry e ON e.id = sp.entryFk
WHERE sp.supplierFk = vSupplierFk JOIN supplier s ON s.id = sp.supplierFk
WHERE s.nif = vNif
AND sp.landed >= vFromDated AND sp.landed >= vFromDated
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vUser,
itemFk, itemFk,
longName, longName,
supplier, supplier,
@ -57,11 +70,12 @@ BEGIN
NULL, NULL,
AVG(buyingValue) AVG(buyingValue)
FROM supplierPackaging FROM supplierPackaging
WHERE supplierFk = vSupplierFk JOIN supplier s ON s.id = sp.supplierFk
WHERE s.nif = vNif
AND landed < vFromDated AND landed < vFromDated
GROUP BY itemFk GROUP BY itemFk
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vUser,
s.itemFk, s.itemFk,
i.longName, i.longName,
c.name, c.name,
@ -76,12 +90,11 @@ BEGIN
JOIN packaging p ON p.itemFk = i.id JOIN packaging p ON p.itemFk = i.id
JOIN ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN supplier su ON su.nif = c.fi WHERE c.fi = vNif
WHERE su.id = vSupplierFk
AND t.shipped >= vFromDated AND t.shipped >= vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vUser,
s.itemFk, s.itemFk,
i.longName, i.longName,
c.name, c.name,
@ -96,14 +109,13 @@ BEGIN
JOIN packaging p ON p.itemFk = i.id JOIN packaging p ON p.itemFk = i.id
JOIN ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN supplier su ON su.nif = c.fi WHERE c.fi = vNif
WHERE su.id = vSupplierFk
AND t.shipped < vFromDated AND t.shipped < vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
AND NOT t.isDeleted AND NOT t.isDeleted
GROUP BY s.itemFk GROUP BY s.itemFk
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vUser,
p.itemFk, p.itemFk,
i.longName, i.longName,
c.name, c.name,
@ -118,12 +130,11 @@ BEGIN
JOIN item i ON i.id = p.itemFk JOIN item i ON i.id = p.itemFk
JOIN ticket t ON t.id = tp.ticketFk JOIN ticket t ON t.id = tp.ticketFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN supplier su ON su.nif = c.fi WHERE c.fi = vNif
WHERE su.id = vSupplierFk
AND t.shipped >= vFromDated AND t.shipped >= vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vUser,
p.itemFk, p.itemFk,
i.longName, i.longName,
c.name, c.name,
@ -138,8 +149,7 @@ BEGIN
JOIN item i ON i.id = p.itemFk JOIN item i ON i.id = p.itemFk
JOIN ticket t ON t.id = tp.ticketFk JOIN ticket t ON t.id = tp.ticketFk
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN supplier su ON su.nif = c.fi WHERE c.fi = vNif
WHERE su.id = vSupplierFk
AND t.shipped < vFromDated AND t.shipped < vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
AND NOT t.isDeleted AND NOT t.isDeleted