This commit is contained in:
parent
354ecfaa16
commit
7947d6644e
|
@ -1,6 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
|
||||||
vItemFk INT, vWarehouse INT, vDate DATETIME)
|
vItemFk INT,
|
||||||
|
vWarehouseFk INT,
|
||||||
|
vDate DATETIME
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula y proporciona un historial de inventario absoluto
|
* Calcula y proporciona un historial de inventario absoluto
|
||||||
|
@ -8,13 +11,11 @@ BEGIN
|
||||||
* hasta una fecha determinada.
|
* hasta una fecha determinada.
|
||||||
*
|
*
|
||||||
* @param vItemFk Id de artículo
|
* @param vItemFk Id de artículo
|
||||||
* @param vWarehouse Almacén
|
* @param vWarehouseFk Id de almacén
|
||||||
* @param vDate Fecha
|
* @param vDate Fecha
|
||||||
*/
|
*/
|
||||||
DECLARE vCalculatedInventory INT;
|
DECLARE vCalculatedInventory INT;
|
||||||
DECLARE vToday DATETIME;
|
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
|
||||||
|
|
||||||
SET vToday = util.VN_CURDATE();
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
|
CREATE OR REPLACE TEMPORARY TABLE tHistoricalPast
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -23,7 +24,7 @@ BEGIN
|
||||||
SELECT tr.landed `date`,
|
SELECT tr.landed `date`,
|
||||||
b.quantity input,
|
b.quantity input,
|
||||||
NULL `output`,
|
NULL `output`,
|
||||||
(tr.isReceived != FALSE) ok,
|
tr.isReceived ok,
|
||||||
s.name alias,
|
s.name alias,
|
||||||
e.invoiceNumber reference,
|
e.invoiceNumber reference,
|
||||||
e.id id,
|
e.id id,
|
||||||
|
@ -34,7 +35,7 @@ BEGIN
|
||||||
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 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
|
||||||
|
@ -52,7 +53,7 @@ BEGIN
|
||||||
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 vWarehouseFk = tr.warehouseOutFk
|
||||||
AND s.id <> 4
|
AND s.id <> 4
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
|
@ -61,7 +62,7 @@ BEGIN
|
||||||
SELECT t.shipped `date`,
|
SELECT t.shipped `date`,
|
||||||
NULL input,
|
NULL input,
|
||||||
m.quantity `output`,
|
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.nickname alias,
|
||||||
t.refFk reference,
|
t.refFk reference,
|
||||||
t.id,
|
t.id,
|
||||||
|
@ -71,16 +72,16 @@ BEGIN
|
||||||
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 >= '2001-01-01'
|
||||||
AND m.itemFk = vItemFk
|
AND m.itemFk = vItemFk
|
||||||
AND vWarehouse IN (t.warehouseFk , 0)
|
AND vWarehouseFk IN (t.warehouseFk , 0)
|
||||||
) t1
|
) t1
|
||||||
ORDER BY `date`, input DESC, ok DESC;
|
ORDER BY `date`, input DESC, ok DESC;
|
||||||
|
|
||||||
SELECT sum(input) - sum(`output`) INTO vCalculatedInventory
|
SELECT SUM(input) - SUM(`output`) INTO vCalculatedInventory
|
||||||
FROM tHistoricalPast
|
FROM tHistoricalPast
|
||||||
WHERE `date` < vDate;
|
WHERE `date` < vDate;
|
||||||
|
|
||||||
SELECT p1.*, NULL v_virtual
|
SELECT p1.*, NULL v_virtual
|
||||||
FROM(
|
FROM (
|
||||||
SELECT vDate `date`,
|
SELECT vDate `date`,
|
||||||
vCalculatedInventory input,
|
vCalculatedInventory input,
|
||||||
NULL `output`,
|
NULL `output`,
|
||||||
|
|
|
@ -29,16 +29,16 @@ BEGIN
|
||||||
c.quantity input,
|
c.quantity input,
|
||||||
NULL `output`,
|
NULL `output`,
|
||||||
IF(warehouseInFk = 44, 1, warehouseInFk) warehouse,
|
IF(warehouseInFk = 44, 1, warehouseInFk) warehouse,
|
||||||
(tr.isReceived <> FALSE) ok,
|
tr.isReceived ok,
|
||||||
e.invoiceNumber reference,
|
e.invoiceNumber reference,
|
||||||
e.id 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
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
WHERE tr.landed >= vDateInventory
|
WHERE tr.landed >= vDateInventory
|
||||||
AND c.itemFk = vItemFk
|
AND c.itemFk = vItemFk
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
AND c.quantity <> 0
|
AND c.quantity
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT tr.shipped `date`,
|
SELECT tr.shipped `date`,
|
||||||
NULL input,
|
NULL input,
|
||||||
|
@ -46,20 +46,20 @@ BEGIN
|
||||||
tr.warehouseOutFk warehouse,
|
tr.warehouseOutFk warehouse,
|
||||||
tr.isDelivered ok,
|
tr.isDelivered ok,
|
||||||
e.invoiceNumber reference,
|
e.invoiceNumber reference,
|
||||||
e.id 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
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
WHERE tr.shipped >= vDateInventory
|
WHERE tr.shipped >= vDateInventory
|
||||||
AND c.itemFk = vItemFk
|
AND c.itemFk = vItemFk
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
AND c.quantity <> 0
|
AND c.quantity
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT t.shipped `date`,
|
SELECT t.shipped `date`,
|
||||||
NULL input,
|
NULL input,
|
||||||
m.quantity `output`,
|
m.quantity `output`,
|
||||||
tr.warehouseInFk warehouse,
|
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.refFk reference,
|
||||||
t.id id
|
t.id id
|
||||||
FROM sale m
|
FROM sale m
|
||||||
|
@ -70,13 +70,8 @@ BEGIN
|
||||||
JOIN warehouse ON warehouse.id = history.warehouse
|
JOIN warehouse ON warehouse.id = history.warehouse
|
||||||
ORDER BY `date`, input DESC, ok DESC;
|
ORDER BY `date`, input DESC, ok DESC;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2;
|
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory2, tMultipleHistory3,
|
||||||
DROP TEMPORARY TABLE IF EXISTS tMultipleHistory3;
|
tMultipleHistory4, tMultipleHistory5, tMultipleHistory6, tMultipleHistory7, tMultipleHistory8;
|
||||||
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 tMultipleHistory2 SELECT * FROM tMultipleHistory1 WHERE warehouse = 19;
|
||||||
CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7;
|
CREATE TEMPORARY TABLE tMultipleHistory3 SELECT * FROM tMultipleHistory1 WHERE warehouse = 7;
|
||||||
CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60;
|
CREATE TEMPORARY TABLE tMultipleHistory4 SELECT * FROM tMultipleHistory1 WHERE warehouse = 60;
|
||||||
|
@ -156,6 +151,7 @@ BEGIN
|
||||||
input, `output`, ok, reference, id
|
input, `output`, ok, reference, id
|
||||||
FROM tMultipleHistory8
|
FROM tMultipleHistory8
|
||||||
) sub
|
) 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$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
Loading…
Reference in New Issue