Merge pull request 'feat: refs #7363 item_getBalance saleTracking no mostrar duplicados' (!2438) from 7363-item_getBalance into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-on: #2438 Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
c706f1cc2b
|
@ -9,7 +9,7 @@ BEGIN
|
||||||
* @vItemFk item a buscar
|
* @vItemFk item a buscar
|
||||||
* @vWarehouseFk almacen donde buscar
|
* @vWarehouseFk almacen donde buscar
|
||||||
* @vDate Si la fecha es null, muestra el histórico desde el inventario.
|
* @vDate Si la fecha es null, muestra el histórico desde el inventario.
|
||||||
* Si la fecha no es null, muestra histórico desde la fecha pasada.
|
* Si la fecha no es null, muestra histórico desde la fecha de vDate.
|
||||||
*/
|
*/
|
||||||
DECLARE vDateInventory DATETIME;
|
DECLARE vDateInventory DATETIME;
|
||||||
|
|
||||||
|
@ -40,117 +40,154 @@ BEGIN
|
||||||
inventorySupplierFk INT(10)
|
inventorySupplierFk INT(10)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO tItemDiary
|
INSERT INTO tItemDiary
|
||||||
SELECT tr.landed shipped,
|
WITH entriesIn AS (
|
||||||
b.quantity `in`,
|
SELECT tr.landed shipped,
|
||||||
NULL `out`,
|
b.quantity `in`,
|
||||||
st.alertLevel ,
|
NULL `out`,
|
||||||
st.name stateName,
|
st.alertLevel ,
|
||||||
s.name `name`,
|
st.name stateName,
|
||||||
e.invoiceNumber reference,
|
s.name `name`,
|
||||||
e.id origin,
|
e.invoiceNumber reference,
|
||||||
s.id clientFk,
|
e.id origin,
|
||||||
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
s.id clientFk,
|
||||||
FALSE isTicket,
|
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||||
b.id lineFk,
|
FALSE isTicket,
|
||||||
NULL `order`,
|
b.id lineFk,
|
||||||
NULL clientType,
|
NULL `order`,
|
||||||
NULL claimFk,
|
NULL clientType,
|
||||||
ec.inventorySupplierFk
|
NULL claimFk,
|
||||||
FROM buy b
|
ec.inventorySupplierFk
|
||||||
JOIN entry e ON e.id = b.entryFk
|
FROM vn.buy b
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN vn.entry e ON e.id = b.entryFk
|
||||||
JOIN supplier s ON s.id = e.supplierFk
|
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||||
JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||||
OR (util.VN_CURDATE() AND tr.isReceived),
|
JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
||||||
'DELIVERED',
|
OR (util.VN_CURDATE() AND tr.isReceived),
|
||||||
'FREE')
|
'DELIVERED',
|
||||||
JOIN entryConfig ec
|
'FREE')
|
||||||
WHERE tr.landed >= vDateInventory
|
JOIN vn.entryConfig ec
|
||||||
AND vWarehouseFk = tr.warehouseInFk
|
WHERE tr.landed >= vDateInventory
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND vWarehouseFk = tr.warehouseInFk
|
||||||
AND b.itemFk = vItemFk
|
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
AND b.itemFk = vItemFk
|
||||||
AND e.isRaid = FALSE
|
AND NOT e.isExcludedFromAvailable
|
||||||
UNION ALL
|
AND NOT e.isRaid
|
||||||
SELECT tr.shipped,
|
), entriesOut AS (
|
||||||
NULL,
|
SELECT tr.shipped,
|
||||||
b.quantity,
|
NULL,
|
||||||
st.alertLevel,
|
b.quantity,
|
||||||
st.name,
|
st.alertLevel,
|
||||||
s.name,
|
st.name stateName,
|
||||||
e.invoiceNumber,
|
s.name ,
|
||||||
e.id,
|
e.invoiceNumber,
|
||||||
s.id,
|
e.id entryFk,
|
||||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
s.id supplierFk,
|
||||||
FALSE,
|
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||||
b.id,
|
FALSE isTicket,
|
||||||
NULL,
|
b.id,
|
||||||
NULL,
|
NULL `order`,
|
||||||
NULL,
|
NULL clientType,
|
||||||
ec.inventorySupplierFk
|
NULL claimFk,
|
||||||
FROM buy b
|
ec.inventorySupplierFk
|
||||||
JOIN entry e ON e.id = b.entryFk
|
FROM vn.buy b
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN vn.entry e ON e.id = b.entryFk
|
||||||
JOIN warehouse w ON w.id = tr.warehouseOutFk
|
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||||
JOIN supplier s ON s.id = e.supplierFk
|
JOIN vn.warehouse w ON w.id = tr.warehouseOutFk
|
||||||
JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||||
|
JOIN vn.state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
||||||
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
'FREE')
|
'FREE')
|
||||||
JOIN entryConfig ec
|
JOIN vn.entryConfig ec
|
||||||
WHERE tr.shipped >= vDateInventory
|
WHERE tr.shipped >= vDateInventory
|
||||||
AND vWarehouseFk = tr.warehouseOutFk
|
AND vWarehouseFk = tr.warehouseOutFk
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND w.isFeedStock = FALSE
|
AND NOT w.isFeedStock
|
||||||
AND e.isRaid = FALSE
|
AND NOT e.isRaid
|
||||||
UNION ALL
|
), sales AS (
|
||||||
SELECT DATE(t.shipped),
|
SELECT DATE(t.shipped) shipped,
|
||||||
NULL,
|
s.quantity,
|
||||||
s.quantity,
|
st2.alertLevel,
|
||||||
st2.alertLevel,
|
st2.name,
|
||||||
st2.name,
|
t.nickname,
|
||||||
t.nickname,
|
t.refFk,
|
||||||
t.refFk,
|
t.id ticketFk,
|
||||||
t.id,
|
t.clientFk,
|
||||||
t.clientFk,
|
s.id saleFk,
|
||||||
stk.id,
|
st.`order`,
|
||||||
TRUE,
|
c.typeFk,
|
||||||
s.id,
|
cb.claimFk
|
||||||
st.`order`,
|
FROM vn.sale s
|
||||||
c.typeFk,
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
cb.claimFk,
|
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
||||||
NULL
|
LEFT JOIN vn.state st ON st.`code` = ts.`code`
|
||||||
FROM sale s
|
JOIN vn.client c ON c.id = t.clientFk
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
'DELIVERED',
|
||||||
LEFT JOIN state st ON st.`code` = ts.`code`
|
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||||
JOIN client c ON c.id = t.clientFk
|
'FREE',
|
||||||
JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
IFNULL(ts.code, 'FREE')))
|
||||||
'DELIVERED',
|
LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
|
||||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
WHERE t.shipped >= vDateInventory
|
||||||
'FREE',
|
AND s.itemFk = vItemFk
|
||||||
IFNULL(ts.code, 'FREE')))
|
AND vWarehouseFk = t.warehouseFk
|
||||||
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
),sale AS (
|
||||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id
|
SELECT s.shipped,
|
||||||
AND stk.stateFk = stPrep.id
|
NULL `in`,
|
||||||
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
s.quantity,
|
||||||
WHERE t.shipped >= vDateInventory
|
s.alertLevel,
|
||||||
AND s.itemFk = vItemFk
|
s.name,
|
||||||
AND vWarehouseFk =t.warehouseFk
|
s.nickname,
|
||||||
ORDER BY shipped,
|
s.refFk,
|
||||||
(inventorySupplierFk = clientFk) DESC,
|
s.ticketFk,
|
||||||
alertLevel DESC,
|
s.clientFk,
|
||||||
isTicket,
|
IF(stk.saleFk, TRUE, NULL),
|
||||||
`order` DESC,
|
TRUE,
|
||||||
isPicked DESC,
|
s.saleFk,
|
||||||
`in` DESC,
|
s.`order`,
|
||||||
`out` DESC;
|
s.typeFk,
|
||||||
|
s.claimFk,
|
||||||
|
NULL
|
||||||
|
FROM sales s
|
||||||
|
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
|
||||||
|
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
|
||||||
|
AND stk.stateFk = stPrep.id
|
||||||
|
GROUP BY s.saleFk
|
||||||
|
) SELECT shipped,
|
||||||
|
`in`,
|
||||||
|
`out`,
|
||||||
|
alertLevel,
|
||||||
|
stateName,
|
||||||
|
`name`,
|
||||||
|
reference,
|
||||||
|
origin,
|
||||||
|
clientFk,
|
||||||
|
isPicked,
|
||||||
|
isTicket,
|
||||||
|
lineFk,
|
||||||
|
`order`,
|
||||||
|
clientType,
|
||||||
|
claimFk,
|
||||||
|
inventorySupplierFk
|
||||||
|
FROM entriesIn
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM entriesOut
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM sale
|
||||||
|
ORDER BY shipped,
|
||||||
|
(inventorySupplierFk = clientFk) DESC,
|
||||||
|
alertLevel DESC,
|
||||||
|
isTicket,
|
||||||
|
`order` DESC,
|
||||||
|
isPicked DESC,
|
||||||
|
`in` DESC,
|
||||||
|
`out` DESC;
|
||||||
|
|
||||||
IF vDate IS NULL THEN
|
IF vDate IS NULL THEN
|
||||||
|
|
||||||
SET @a := 0;
|
SET @a := 0;
|
||||||
SET @currentLineFk := 0;
|
SET @currentLineFk := 0;
|
||||||
SET @shipped := '';
|
SET @shipped := '';
|
||||||
|
@ -220,7 +257,7 @@ BEGIN
|
||||||
FROM tItemDiary
|
FROM tItemDiary
|
||||||
WHERE shipped >= vDate;
|
WHERE shipped >= vDate;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tItemDiary;
|
DROP TEMPORARY TABLE tItemDiary;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue