sref
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Pako Natek 2024-06-21 08:32:22 +02:00
parent b117352e1a
commit fe154b9ee8
1 changed files with 18 additions and 19 deletions

View File

@ -22,7 +22,7 @@ BEGIN
landed, landed,
`in`, `in`,
`out`, `out`,
warehouse, sref,
buyingValue, buyingValue,
IF ( IF (
NOT (@vItemFk <=> sub.itemFk), NOT (@vItemFk <=> sub.itemFk),
@ -31,19 +31,20 @@ BEGIN
) balance, ) balance,
@vItemFk := sub.itemFk previousItemFk @vItemFk := sub.itemFk previousItemFk
FROM ( FROM (
SELECT supplierFk, SELECT sp.supplierFk,
itemFk, sp.itemFk,
longName, sp.longName,
supplier, sp.supplier,
CONCAT('E',entryFk) entryFk, CONCAT('E',sp.entryFk) entryFk,
landed, sp.landed,
`in`, sp.`in`,
`out`, sp.`out`,
warehouse, e.invoiceNumber sref,
buyingValue sp.buyingValue
FROM supplierPackaging FROM supplierPackaging sp
WHERE supplierFk = vSupplierFk JOIN entry e ON e.id = sp.entryFk
AND landed >= vFromDated WHERE sp.supplierFk = vSupplierFk
AND sp.landed >= vFromDated
UNION ALL UNION ALL
SELECT vSupplierFk, SELECT vSupplierFk,
itemFk, itemFk,
@ -68,7 +69,7 @@ BEGIN
DATE(t.shipped), DATE(t.shipped),
-LEAST(s.quantity,0) `in`, -LEAST(s.quantity,0) `in`,
GREATEST(s.quantity,0) `out`, GREATEST(s.quantity,0) `out`,
w.name, t.cmrFk,
s.price * (100 - s.discount) / 100 s.price * (100 - s.discount) / 100
FROM sale s FROM sale s
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
@ -76,7 +77,6 @@ BEGIN
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 JOIN supplier su ON su.nif = c.fi
JOIN warehouse w ON w.id = t.warehouseFk
WHERE su.id = vSupplierFk WHERE su.id = vSupplierFk
AND t.shipped >= vFromDated AND t.shipped >= vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
@ -111,7 +111,7 @@ BEGIN
DATE(t.shipped), DATE(t.shipped),
-LEAST(tp.quantity,0) `in`, -LEAST(tp.quantity,0) `in`,
GREATEST(tp.quantity,0) `out`, GREATEST(tp.quantity,0) `out`,
w.name, t.cmrFk,
0 0
FROM ticketPackaging tp FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk JOIN packaging p ON p.id = tp.packagingFk
@ -119,7 +119,6 @@ BEGIN
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 JOIN supplier su ON su.nif = c.fi
JOIN warehouse w ON w.id = t.warehouseFk
WHERE su.id = vSupplierFk WHERE su.id = vSupplierFk
AND t.shipped >= vFromDated AND t.shipped >= vFromDated
AND p.isPackageReturnable AND p.isPackageReturnable
@ -157,7 +156,7 @@ BEGIN
landed, landed,
CAST(`in` AS DECIMAL(10,0)) `in`, CAST(`in` AS DECIMAL(10,0)) `in`,
CAST(`out` AS DECIMAL(10,0)) `out`, CAST(`out` AS DECIMAL(10,0)) `out`,
warehouse, sref,
buyingValue, buyingValue,
balance balance
FROM tSupplierPackaging FROM tSupplierPackaging