feat: refs #6769 itemDiary #2683

Merged
guillermo merged 10 commits from 6769-itemDiary into dev 2024-07-12 08:13:29 +00:00
1 changed files with 38 additions and 57 deletions
Showing only changes of commit cf7de14de6 - Show all commits

View File

@ -61,29 +61,11 @@ BEGIN
JOIN itemType it ON it.id = i.typeFk
HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL;
CREATE OR REPLACE TEMPORARY TABLE tItemDiary(
shipped DATE,
`in` INT(11),
`out` INT(11),
alertLevel INT(11),
stateName VARCHAR(20),
`name` VARCHAR(50),
reference VARCHAR(50),
origin INT(11),
clientFk INT(11),
isPicked INT(11),
isTicket TINYINT(1),
lineFk INT(11),
`order` TINYINT(3) UNSIGNED,
clientType VARCHAR(20),
claimFk INT(10) UNSIGNED,
inventorySupplierFk INT(10),
orderFk INT(10) UNSIGNED
) ENGINE = MEMORY;
INSERT INTO tItemDiary
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
ENGINE = MEMORY
WITH entriesIn AS (
SELECT tr.landed shipped,
SELECT 'entry' `type`,
tr.landed shipped,
b.quantity `in`,
NULL `out`,
st.alertLevel ,
@ -98,13 +80,12 @@ BEGIN
NULL `order`,
NULL clientType,
NULL claimFk,
vSupplierInventoryFk inventorySupplierFk,
NULL orderFk
vSupplierInventoryFk inventorySupplierFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
JOIN vn.supplier s ON s.id = e.supplierFk
JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
JOIN vn.state st ON st.`code` = IF(tr.landed < util.VN_CURDATE()
OR (util.VN_CURDATE() AND tr.isReceived),
'DELIVERED',
'FREE')
@ -116,7 +97,8 @@ BEGIN
AND NOT e.isRaid
),
entriesOut AS (
SELECT tr.shipped,
SELECT 'entry',
tr.shipped,
NULL,
b.quantity,
st.alertLevel,
@ -131,8 +113,7 @@ BEGIN
NULL `order`,
NULL clientType,
NULL claimFk,
vSupplierInventoryFk,
NULL orderFk
vSupplierInventoryFk
FROM vn.buy b
guillermo marked this conversation as resolved Outdated

este es el troç de la vista que hem comentat

este es el troç de la vista que hem comentat
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
@ -180,7 +161,8 @@ BEGIN
AND s.itemFk = vItemFk
AND vWarehouseFk = t.warehouseFk
)
SELECT s.shipped,
SELECT 'ticket',
s.shipped,
NULL `in`,
s.quantity,
s.alertLevel,
@ -195,8 +177,7 @@ BEGIN
s.`order`,
s.typeFk,
s.claimFk,
NULL,
NULL orderFk
NULL
FROM itemSales s
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
@ -204,23 +185,23 @@ BEGIN
GROUP BY s.saleFk
),
orders AS (
SELECT r.shipment,
SELECT 'order' `type`,
r.shipment,
NULL 'in',
r.amount,
NULL alertLevel,
NULL stateName,
NULL,
c.name,
NULL invoiceNumber,
NULL entryFk,
NULL supplierFk,
o.id origin,
c.id,
FALSE,
FALSE isTicket,
NULL buyFk,
NULL 'order',
c.typeFk,
NULL claimFk,
NULL inventorySupplierFk,
o.id
NULL
FROM hedera.orderRow r
JOIN hedera.`order` o ON o.id = r.orderFk
JOIN tItemRange ir ON ir.itemFk = r.itemFk
@ -252,7 +233,8 @@ BEGIN
SET @currentLineFk := 0;
SET @shipped := '';
SELECT DATE(@shipped:= t.shipped) shipped,
SELECT t.type,
DATE(@shipped:= t.shipped) shipped,
t.alertLevel,
t.stateName,
t.origin,
@ -271,8 +253,7 @@ BEGIN
t.isPicked,
t.clientType,
t.claimFk,
t.`order`,
t.orderFk
t.`order`
FROM tItemDiary t
LEFT JOIN alertLevel a ON a.id = t.alertLevel;
ELSE
@ -280,26 +261,27 @@ BEGIN
FROM tItemDiary
WHERE shipped < vDated;
SELECT vDated shipped,
0 alertLevel,
0 stateName,
0 origin,
'' reference,
0 clientFk,
SELECT NULL `type`,
vDated shipped,
NULL alertLevel,
NULL stateName,
NULL origin,
NULL reference,
NULL clientFk,
'Inventario calculado',
@a invalue,
NULL `out`,
@a balance,
0 lastPreparedLineFk,
0 isTicket,
0 lineFk,
0 isPicked,
0 clientType,
0 claimFk,
NULL `order`,
0 orderFk
NULL lastPreparedLineFk,
NULL isTicket,
NULL lineFk,
NULL isPicked,
NULL clientType,
NULL claimFk,
NULL `order`
UNION ALL
SELECT shipped,
SELECT `type`,
shipped,
alertlevel,
stateName,
origin,
@ -314,8 +296,7 @@ BEGIN
isPicked,
clientType,
claimFk,
`order`,
orderFk
`order`
FROM tItemDiary
WHERE shipped >= vDated;
END IF;