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 216 additions and 54 deletions
Showing only changes of commit 68846d3018 - Show all commits

View File

@ -1,13 +1,13 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
vIdArticle INT, vWarehouse INT, vDate DATETIME) vItemFk INT, vWarehouse INT, vDate DATETIME)
BEGIN BEGIN
/** /**
* Calcula y proporciona un historial de inventario absoluto * Calcula y proporciona un historial de inventario absoluto
* para un artículo específico en un almacén dado * para un artículo específico en un almacén dado
* hasta una fecha determinada. * hasta una fecha determinada.
* *
* @param vIdArticle Id de artículo * @param vItemFk Id de artículo
* @param vWarehouse Almacén * @param vWarehouse Almacén
guillermo marked this conversation as resolved
Review

Cambiar nombre de variable a vWarehouseFk y comentario a Id de almacén

Cambiar nombre de variable a vWarehouseFk y comentario a `Id de almacén`
* @param vDate Fecha * @param vDate Fecha
*/ */
@ -16,84 +16,85 @@ BEGIN
SET vToday = util.VN_CURDATE(); SET vToday = util.VN_CURDATE();
guillermo marked this conversation as resolved
Review

Quitar linea

Quitar linea
CREATE OR REPLACE TEMPORARY TABLE historicalPast CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
ENGINE = MEMORY ENGINE = MEMORY
SELECT * SELECT *
FROM ( FROM (
SELECT tr.landed Fecha, SELECT tr.landed `date`,
b.quantity Entrada, b.quantity input,
NULL Salida, NULL `output`,
(tr.isReceived != FALSE) OK, (tr.isReceived != FALSE) ok,
guillermo marked this conversation as resolved
Review
tr.isReceived ok,
``` tr.isReceived ok, ```
s.name Alias, s.name alias,
e.invoiceNumber Referencia, e.invoiceNumber reference,
e.id id, e.id id,
tr.isDelivered F5 tr.isDelivered f5
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.landed >= '2001-01-01' WHERE tr.landed >= '2001-01-01'
AND s.id <> 4 AND s.id <> 4
AND vWarehouse IN (tr.warehouseInFk, 0) AND vWarehouse IN (tr.warehouseInFk, 0)
AND b.itemFk = vIdArticle AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = 0 AND NOT e.isExcludedFromAvailable
AND e.isRaid = 0 AND NOT e.isRaid
UNION ALL UNION ALL
SELECT tr.shipped Fecha, SELECT tr.shipped `date`,
NULL Entrada, NULL input,
b.quantity Salida, b.quantity `output`,
tr.isDelivered OK, tr.isDelivered ok,
s.name Alias, s.name alias,
e.invoiceNumber Referencia, e.invoiceNumber reference,
e.id id, e.id id,
tr.isDelivered F5 tr.isDelivered f5
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 >= '2001-01-01'
AND vWarehouse = tr.warehouseOutFk AND vWarehouse = tr.warehouseOutFk
AND s.id <> 4 AND s.id <> 4
AND b.itemFk = vIdArticle AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = 0 AND NOT e.isExcludedFromAvailable
AND e.isRaid = 0 AND NOT e.isRaid
UNION ALL UNION ALL
SELECT t.shipped Fecha, SELECT t.shipped `date`,
NULL Entrada, NULL input,
m.quantity Salida, m.quantity `output`,
(m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) OK, (m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok,
t.nickname Alias, t.nickname alias,
t.refFk Referencia, t.refFk reference,
t.id, t.id,
t.isPrinted t.isPrinted
FROM sale m FROM sale m
JOIN Tickets T USING (Id_Ticket) JOIN ticket t ON t.id = m.ticketFk
JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente JOIN client c ON c.id = t.clientFk
WHERE T.Fecha >= '2001-01-01' WHERE t.shipped >= '2001-01-01'
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'
AND M.Id_Article = vIdArticle AND m.itemFk = vItemFk
AND vWarehouse IN (T.warehouse_id , 0) AND vWarehouse IN (t.warehouseFk , 0)
) t1 ) t1
ORDER BY Fecha, Entrada DESC, OK DESC; ORDER BY `date`, input DESC, ok DESC;
SELECT sum(Entrada) - sum(Salida) INTO vCalculatedInventory SELECT sum(input) - sum(`output`) INTO vCalculatedInventory
FROM historicalPast FROM tHistoricalPast
WHERE Fecha < vDate; WHERE `date` < vDate;
SELECT p1.*, NULL v_virtual SELECT p1.*, NULL v_virtual
FROM( FROM(
guillermo marked this conversation as resolved
Review

Espacio entre el FROM y el (

Espacio entre el FROM y el (
SELECT vDate Fecha, SELECT vDate `date`,
vCalculatedInventory Entrada, vCalculatedInventory input,
NULL Salida, NULL `output`,
1 OK, 1 ok,
'Inventario calculado' Alias, 'Inventario calculado' alias,
'' Referencia, 0 id, '' reference,
1 F5 0 id,
1 f5
UNION ALL UNION ALL
SELECT * SELECT *
FROM historicalPast FROM tHistoricalPast
WHERE Fecha >= vDate WHERE `date` >= vDate
) p1; ) p1;
DROP TEMPORARY TABLE historicalPast; DROP TEMPORARY TABLE tHistoricalPast;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -0,0 +1,161 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`(
vItemFk INT)
BEGIN
/**
* Calcula y proporciona un historial de inventario detallado
* para un artículo dividiendo la información
* por almacén.
*
* @param vItemFk Artículo
*/
DECLARE vDateInventory DATETIME;
SELECT inventoried INTO vDateInventory FROM config;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory1;
CREATE TEMPORARY TABLE tMultipleHistory1
SELECT DATE(`date`) `date`,
input,
`output`,
ok,
reference,
history.id,
warehouse,
`name` warehouseName
FROM (
SELECT tr.landed `date`,
c.quantity input,
NULL `output`,
IF(warehouseInFk = 44, 1, warehouseInFk) warehouse,
guillermo marked this conversation as resolved
Review

warehouseInFk warehouse

warehouseInFk warehouse
(tr.isReceived <> FALSE) ok,
e.invoiceNumber reference,
e.id id
FROM buy c
JOIN `entry` e ON e.id = c.entryFk
JOIN travel tr ON tr.id = e.travelFk
WHERE tr.landed >= vDateInventory
AND c.itemFk = vItemFk
AND NOT e.isRaid
AND c.quantity <> 0
UNION ALL
SELECT tr.shipped `date`,
NULL input,
c.quantity `output`,
warehouseOutFk warehouse,
tr.isDelivered ok,
e.invoiceNumber reference,
e.id id
FROM buy c
JOIN `entry` e ON e.id = c.entryFk
JOIN travel tr ON tr.id = e.travelFk
WHERE tr.shipped >= vDateInventory
AND c.itemFk = vItemFk
AND NOT e.isRaid
AND c.quantity <> 0
UNION ALL
SELECT t.shipped `date`,
NULL input,
m.quantity `output`,
warehouseInFk warehouse,
(m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok,
t.refFk reference,
t.id id
FROM sale m
JOIN ticket t ON t.id = m.ticketFk
WHERE t.shipped >= vDateInventory
AND m.itemFk = vItemFk
) history
JOIN warehouse ON warehouse.id = history.warehouse
ORDER BY `date`, input DESC, ok DESC;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory3;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory4;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory5;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory6;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory7;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory8;
CREATE TEMPORARY TABLE tMultipleHistory2 SELECT * FROM tMultipleHistory1 WHERE warehouse = 19;
CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7;
CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60;
CREATE TEMPORARY TABLE tMultipleHistory5 SELECT * FROM tMultipleHistory1 WHERE warehouse = 5;
CREATE TEMPORARY TABLE tMultipleHistory6 SELECT * FROM tMultipleHistory1 WHERE warehouse = 17;
CREATE TEMPORARY TABLE tMultipleHistory7 SELECT * FROM tMultipleHistory1 WHERE warehouse = 37;
CREATE TEMPORARY TABLE tMultipleHistory8 SELECT * FROM tMultipleHistory1 WHERE warehouse = 55;
SELECT *
FROM (
SELECT `date`, input BOGinput, `output` BOGoutput, ok BOGok, reference BOGreference, id BOGid,
NULL VNHinput, NULL VNHoutput, NULL VNHok, NULL VNHreference, NULL VNHid,
NULL ALGinput, NULL ALGoutput, NULL ALGok, NULL ALGreference, NULL ALGid,
NULL MADinput, NULL MADoutput, NULL MADok, NULL MADreference, NULL MADid,
NULL MCFinput, NULL MCFoutput, NULL MCFok, NULL MCFreference, NULL MCFid,
NULL VILinput, NULL VILoutput, NULL VILok, NULL VILreference, NULL VILid,
NULL BARinput, NULL BARoutput, NULL BARok, NULL BARreference, NULL BARid
FROM tMultipleHistory2
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory3
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory4
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory5
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory6
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id,
NULL, NULL, NULL, NULL, NULL
FROM tMultipleHistory7
UNION ALL
SELECT `date`,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
input, `output`, ok, reference, id
FROM tMultipleHistory8
) sub
ORDER BY `date`, BOGinput IS NULL, VNHinput IS NULL, ALGinput IS NULL, MADinput IS NULL, MCFinput IS NULL, VILinput IS NULL, BARinput IS NULL;
END$$
DELIMITER ;