Merge pull request 'supplierPackaging_ReportSource_hotFix' (!2633) from supplierPackaging_ReportSource_hotFix into test
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2633
Reviewed-by: Pablo Natek <pablone@verdnatura.es>
This commit is contained in:
Pako Natek 2024-06-24 10:50:49 +00:00
commit 6244509e3d
1 changed files with 24 additions and 21 deletions

View File

@ -5,10 +5,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_R
)
BEGIN
/**
* Selecciona los embalajes de un proveedor a partir de una fecha
* Create a report with packaging balance
*
* @param vFromDated Fecha de la que partir
* @param vSupplierFk Id del proveedor
* @param vFromDated Starting date
* @param vSupplierFk Supplier ID
*/
SET @vBalance = 0;
SET @vItemFk = NULL;
@ -22,7 +22,7 @@ BEGIN
landed,
`in`,
`out`,
warehouse,
sref,
buyingValue,
IF (
NOT (@vItemFk <=> sub.itemFk),
@ -31,19 +31,20 @@ BEGIN
) balance,
@vItemFk := sub.itemFk previousItemFk
FROM (
SELECT supplierFk,
itemFk,
longName,
supplier,
CONCAT('E',entryFk) entryFk,
landed,
`in`,
`out`,
warehouse,
buyingValue
FROM supplierPackaging
WHERE supplierFk = vSupplierFk
AND landed >= vFromDated
SELECT sp.supplierFk,
sp.itemFk,
sp.longName,
sp.supplier,
CONCAT('E',sp.entryFk) entryFk,
sp.landed,
sp.`in`,
sp.`out`,
e.invoiceNumber sref,
sp.buyingValue
FROM supplierPackaging sp
JOIN entry e ON e.id = sp.entryFk
WHERE sp.supplierFk = vSupplierFk
AND sp.landed >= vFromDated
UNION ALL
SELECT vSupplierFk,
itemFk,
@ -68,7 +69,7 @@ BEGIN
DATE(t.shipped),
-LEAST(s.quantity,0) `in`,
GREATEST(s.quantity,0) `out`,
t.warehouseFk,
t.cmrFk,
s.price * (100 - s.discount) / 100
FROM sale s
JOIN item i ON i.id = s.itemFk
@ -99,6 +100,7 @@ BEGIN
WHERE su.id = vSupplierFk
AND t.shipped < vFromDated
AND p.isPackageReturnable
AND NOT t.isDeleted
GROUP BY s.itemFk
UNION ALL
SELECT vSupplierFk,
@ -109,7 +111,7 @@ BEGIN
DATE(t.shipped),
-LEAST(tp.quantity,0) `in`,
GREATEST(tp.quantity,0) `out`,
t.warehouseFk,
t.cmrFk,
0
FROM ticketPackaging tp
JOIN packaging p ON p.id = tp.packagingFk
@ -138,8 +140,9 @@ BEGIN
JOIN client c ON c.id = t.clientFk
JOIN supplier su ON su.nif = c.fi
WHERE su.id = vSupplierFk
AND t.shipped >= vFromDated
AND t.shipped < vFromDated
AND p.isPackageReturnable
AND NOT t.isDeleted
GROUP BY p.itemFk
ORDER BY itemFk, landed, entryFk
) sub
@ -153,7 +156,7 @@ BEGIN
landed,
CAST(`in` AS DECIMAL(10,0)) `in`,
CAST(`out` AS DECIMAL(10,0)) `out`,
warehouse,
sref,
buyingValue,
balance
FROM tSupplierPackaging