refs #6498 Correcion errores
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Ivan Mas 2024-03-06 12:44:59 +01:00
parent 354ecfaa16
commit 7947d6644e
2 changed files with 23 additions and 26 deletions

View File

@ -1,6 +1,9 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
vItemFk INT, vWarehouse INT, vDate DATETIME)
vItemFk INT,
vWarehouseFk INT,
vDate DATETIME
)
BEGIN
/**
* Calcula y proporciona un historial de inventario absoluto
@ -8,13 +11,11 @@ BEGIN
* hasta una fecha determinada.
*
* @param vItemFk Id de artículo
* @param vWarehouse Almacén
* @param vWarehouseFk Id de almacén
* @param vDate Fecha
*/
DECLARE vCalculatedInventory INT;
DECLARE vToday DATETIME;
SET vToday = util.VN_CURDATE();
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
ENGINE = MEMORY
@ -23,7 +24,7 @@ BEGIN
SELECT tr.landed `date`,
b.quantity input,
NULL `output`,
(tr.isReceived != FALSE) ok,
tr.isReceived ok,
s.name alias,
e.invoiceNumber reference,
e.id id,
@ -34,7 +35,7 @@ BEGIN
JOIN supplier s ON s.id = e.supplierFk
WHERE tr.landed >= '2001-01-01'
AND s.id <> 4
AND vWarehouse IN (tr.warehouseInFk, 0)
AND vWarehouseFk IN (tr.warehouseInFk, 0)
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
@ -52,7 +53,7 @@ BEGIN
JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk
WHERE tr.shipped >= '2001-01-01'
AND vWarehouse = tr.warehouseOutFk
AND vWarehouseFk = tr.warehouseOutFk
AND s.id <> 4
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
@ -61,7 +62,7 @@ BEGIN
SELECT t.shipped `date`,
NULL input,
m.quantity `output`,
(m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok,
t.nickname alias,
t.refFk reference,
t.id,
@ -71,16 +72,16 @@ BEGIN
JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= '2001-01-01'
AND m.itemFk = vItemFk
AND vWarehouse IN (t.warehouseFk , 0)
AND vWarehouseFk IN (t.warehouseFk , 0)
) t1
ORDER BY `date`, input DESC, ok DESC;
SELECT sum(input) - sum(`output`) INTO vCalculatedInventory
SELECT SUM(input) - SUM(`output`) INTO vCalculatedInventory
FROM tHistoricalPast
WHERE `date` < vDate;
SELECT p1.*, NULL v_virtual
FROM(
FROM (
SELECT vDate `date`,
vCalculatedInventory input,
NULL `output`,

View File

@ -29,16 +29,16 @@ BEGIN
c.quantity input,
NULL `output`,
IF(warehouseInFk = 44, 1, warehouseInFk) warehouse,
(tr.isReceived <> FALSE) ok,
tr.isReceived ok,
e.invoiceNumber reference,
e.id id
e.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
AND c.quantity
UNION ALL
SELECT tr.shipped `date`,
NULL input,
@ -46,20 +46,20 @@ BEGIN
tr.warehouseOutFk warehouse,
tr.isDelivered ok,
e.invoiceNumber reference,
e.id id
e.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
AND c.quantity
UNION ALL
SELECT t.shipped `date`,
NULL input,
m.quantity `output`,
tr.warehouseInFk warehouse,
(m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) ok,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL) ok,
t.refFk reference,
t.id id
FROM sale m
@ -70,13 +70,8 @@ BEGIN
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;
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2, tMultipleHistory3,
tMultipleHistory4, tMultipleHistory5, tMultipleHistory6, tMultipleHistory7, 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;
@ -156,6 +151,7 @@ BEGIN
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;
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 ;