tested proc
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
a303d22a18
commit
f999010c6c
|
@ -5,10 +5,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_R
|
||||||
)
|
)
|
||||||
BEGIN
|
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 vFromDated Starting date
|
||||||
* @param vSupplierFk Id del proveedor
|
* @param vSupplierFk Supplier ID
|
||||||
*/
|
*/
|
||||||
SET @vBalance = 0;
|
SET @vBalance = 0;
|
||||||
SET @vItemFk = NULL;
|
SET @vItemFk = NULL;
|
||||||
|
@ -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`,
|
||||||
t.warehouseFk,
|
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
|
||||||
|
@ -99,6 +100,7 @@ BEGIN
|
||||||
WHERE su.id = vSupplierFk
|
WHERE su.id = vSupplierFk
|
||||||
AND t.shipped < vFromDated
|
AND t.shipped < vFromDated
|
||||||
AND p.isPackageReturnable
|
AND p.isPackageReturnable
|
||||||
|
AND NOT t.isDeleted
|
||||||
GROUP BY s.itemFk
|
GROUP BY s.itemFk
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT vSupplierFk,
|
SELECT vSupplierFk,
|
||||||
|
@ -109,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`,
|
||||||
t.warehouseFk,
|
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
|
||||||
|
@ -138,8 +140,9 @@ BEGIN
|
||||||
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
|
||||||
WHERE su.id = vSupplierFk
|
WHERE su.id = vSupplierFk
|
||||||
AND t.shipped >= vFromDated
|
AND t.shipped < vFromDated
|
||||||
AND p.isPackageReturnable
|
AND p.isPackageReturnable
|
||||||
|
AND NOT t.isDeleted
|
||||||
GROUP BY p.itemFk
|
GROUP BY p.itemFk
|
||||||
ORDER BY itemFk, landed, entryFk
|
ORDER BY itemFk, landed, entryFk
|
||||||
) sub
|
) sub
|
||||||
|
@ -153,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
|
||||||
|
|
Loading…
Reference in New Issue