|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
DELIMITER $$
|
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventoryHistory`(
|
|
|
|
|
vItemFk INT)
|
|
|
|
|
vItemFk INT)
|
|
|
|
|
BEGIN
|
|
|
|
|
/**
|
|
|
|
|
* Calcula y proporciona un historial de inventario detallado
|
|
|
|
@ -17,58 +17,58 @@ BEGIN
|
|
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE tMultipleHistory1
|
|
|
|
|
SELECT DATE(`date`) `date`,
|
|
|
|
|
input,
|
|
|
|
|
input,
|
|
|
|
|
`output`,
|
|
|
|
|
ok,
|
|
|
|
|
reference,
|
|
|
|
|
history.id,
|
|
|
|
|
warehouse,
|
|
|
|
|
`name` warehouseName
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT tr.landed `date`,
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT tr.landed `date`,
|
|
|
|
|
c.quantity input,
|
|
|
|
|
NULL `output`,
|
|
|
|
|
IF(warehouseInFk = 44, 1, 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`,
|
|
|
|
|
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.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`,
|
|
|
|
|
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,
|
|
|
|
|
tr.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;
|
|
|
|
|
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;
|
|
|
|
@ -86,76 +86,76 @@ BEGIN
|
|
|
|
|
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;
|
|
|
|
|
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 ;
|