refs #6498 procRefactor6 #2134

Merged
ivanm merged 8 commits from 6499-procRefactor6 into dev 2024-03-21 11:03:33 +00:00
2 changed files with 37 additions and 35 deletions
Showing only changes of commit 6b2533cfb1 - Show all commits

View File

@ -16,6 +16,7 @@ BEGIN
*/ */
DECLARE vCalculatedInventory INT; DECLARE vCalculatedInventory INT;
guillermo marked this conversation as resolved
Review

Quitar linea

Quitar linea
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE(); DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
DECLARE vStartDate DATE DEFAULT '2001-01-01';
CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
ENGINE = MEMORY ENGINE = MEMORY
@ -33,44 +34,44 @@ BEGIN
JOIN `entry` e ON e.id = b.entryFk JOIN `entry` e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk JOIN supplier s ON s.id = e.supplierFk

No poner números a pelo en el código, para ello:

AND s.id <> (SELECT supplierFk FROM inventoryConfig)
No poner números a pelo en el código, para ello: ``` AND s.id <> (SELECT supplierFk FROM inventoryConfig) ```
WHERE tr.landed >= '2001-01-01' WHERE tr.landed >= vStartDate
AND s.id <> 4 AND s.id <> (SELECT supplierFk FROM inventoryConfig)
AND vWarehouseFk IN (tr.warehouseInFk, 0) AND vWarehouseFk IN (tr.warehouseInFk, 0)
AND b.itemFk = vItemFk AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid AND NOT e.isRaid
UNION ALL UNION ALL
SELECT tr.shipped `date`, SELECT tr.shipped,
NULL input, NULL,
b.quantity `output`, b.quantity,
tr.isDelivered ok, tr.isDelivered,
s.name alias, s.name,
e.invoiceNumber reference, e.invoiceNumber,
e.id id, e.id,
tr.isDelivered f5 tr.isDelivered
FROM buy b FROM buy b
JOIN `entry` e ON e.id = b.entryFk JOIN `entry` e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk JOIN supplier s ON s.id = e.supplierFk
WHERE tr.shipped >= '2001-01-01' WHERE tr.shipped >= vStartDate
AND vWarehouseFk = tr.warehouseOutFk AND vWarehouseFk = tr.warehouseOutFk
AND s.id <> 4 AND s.id <> (SELECT supplierFk FROM inventoryConfig)
AND b.itemFk = vItemFk AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid AND NOT e.isRaid
UNION ALL UNION ALL
SELECT t.shipped `date`, SELECT t.shipped,
NULL input, NULL,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL)
``` (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ```
m.quantity `output`, m.quantity,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL),
t.nickname alias, t.nickname,
t.refFk reference, t.refFk,
t.id, t.id,
t.isPrinted t.isPrinted
FROM sale m FROM sale m
JOIN ticket t ON t.id = m.ticketFk JOIN ticket t ON t.id = m.ticketFk
Review

'2001-01-01' repetido en el código, crear variable con DEFAULT '2001-01-01'

'2001-01-01' repetido en el código, crear variable con DEFAULT '2001-01-01'
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= '2001-01-01' WHERE t.shipped >= vStartDate
AND m.itemFk = vItemFk AND m.itemFk = vItemFk
AND vWarehouseFk IN (t.warehouseFk, 0) AND vWarehouseFk IN (t.warehouseFk, 0)
) t1 ) t1

View File

@ -1,6 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`(
vItemFk INT) vItemFk INT
)
BEGIN BEGIN
/** /**
* Calcula y proporciona un historial de inventario detallado * Calcula y proporciona un historial de inventario detallado
@ -28,7 +29,7 @@ BEGIN
SELECT tr.landed `date`, SELECT tr.landed `date`,
c.quantity input, c.quantity input,
NULL `output`, NULL `output`,
guillermo marked this conversation as resolved
Review

warehouseInFk warehouse

warehouseInFk warehouse
IF(warehouseInFk = 44, 1, warehouseInFk) warehouse, tr.warehouseInFk warehouse,

tr.isReceived

`tr.isReceived`
tr.isReceived ok, tr.isReceived ok,
e.invoiceNumber reference, e.invoiceNumber reference,

e.id

e.id
e.id e.id
@ -40,12 +41,12 @@ BEGIN
AND NOT e.isRaid AND NOT e.isRaid

AND c.quantity

`AND c.quantity`
AND c.quantity AND c.quantity
UNION ALL UNION ALL
SELECT tr.shipped `date`, SELECT tr.shipped,
NULL input, NULL,
c.quantity `output`, c.quantity,
tr.warehouseOutFk warehouse, tr.warehouseOutFk,
tr.isDelivered ok, tr.isDelivered,
e.invoiceNumber reference, e.invoiceNumber,

Quitar alias siempre a partir del segundo select cuando se haga un UNION

Quitar alias siempre a partir del segundo select cuando se haga un UNION
e.id e.id
FROM buy c FROM buy c
JOIN `entry` e ON e.id = c.entryFk JOIN `entry` e ON e.id = c.entryFk
@ -55,13 +56,13 @@ BEGIN
AND NOT e.isRaid AND NOT e.isRaid

c.quantity

`c.quantity`
AND c.quantity AND c.quantity
UNION ALL UNION ALL
SELECT t.shipped `date`, SELECT t.shipped,
NULL input, NULL,
m.quantity `output`, m.quantity,
tr.warehouseInFk warehouse, t.warehouseFk,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok, (m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL),
t.refFk reference, t.refFk,
t.id id t.id
FROM sale m FROM sale m
JOIN ticket t ON t.id = m.ticketFk JOIN ticket t ON t.id = m.ticketFk
WHERE t.shipped >= vDateInventory WHERE t.shipped >= vDateInventory