tested proc
This commit is contained in:
parent
87b69e0455
commit
8c5f468087
|
@ -1,14 +1,14 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`(
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`(
|
||||
vFromDated DATE,
|
||||
vSupplierFk INT
|
||||
)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue