7773-testToMaster_2430 #2774
|
@ -21,7 +21,7 @@ BEGIN
|
||||||
FROM config c
|
FROM config c
|
||||||
JOIN util.config uc;
|
JOIN util.config uc;
|
||||||
|
|
||||||
SELECT COALESCE(vDated, vDateInventory) - INTERVAL MAX(life) DAY
|
SELECT vDateInventory - INTERVAL MAX(life) DAY
|
||||||
INTO vLifeScope
|
INTO vLifeScope
|
||||||
FROM itemType;
|
FROM itemType;
|
||||||
|
|
||||||
|
@ -50,30 +50,32 @@ BEGIN
|
||||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
JOIN warehouse w ON w.id = t.warehouseInFk
|
||||||
JOIN item i ON i.id = b.itemFk
|
JOIN item i ON i.id = b.itemFk
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
WHERE t.landed BETWEEN vLifeScope AND COALESCE(vDated, vDateInventory)
|
WHERE t.landed BETWEEN vLifeScope AND vDateInventory
|
||||||
AND t.warehouseInFk = vWarehouseFk
|
AND t.warehouseInFk = vWarehouseFk
|
||||||
AND t.warehouseOutFk <> vWarehouseInventoryFk
|
AND t.warehouseOutFk <> vWarehouseInventoryFk
|
||||||
AND it.life
|
AND it.life
|
||||||
|
AND i.id = vItemFk
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
GROUP BY b.itemFk
|
GROUP BY b.itemFk
|
||||||
) c ON i.id = c.itemFk
|
) c ON i.id = c.itemFk
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL;
|
WHERE i.id = vItemFk
|
||||||
|
HAVING ended >= vDateInventory OR life IS NULL;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
|
CREATE OR REPLACE TEMPORARY TABLE tItemDiary
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH entriesIn AS (
|
WITH entriesIn AS (
|
||||||
SELECT 'entry' originType,
|
SELECT 'entry' originType,
|
||||||
e.id origin,
|
e.id originId,
|
||||||
tr.landed shipped,
|
tr.landed shipped,
|
||||||
b.quantity `in`,
|
b.quantity `in`,
|
||||||
NULL `out`,
|
NULL `out`,
|
||||||
st.alertLevel ,
|
st.alertLevel ,
|
||||||
st.name stateName,
|
st.name stateName,
|
||||||
s.name `name`,
|
|
||||||
e.invoiceNumber reference,
|
e.invoiceNumber reference,
|
||||||
'supplier' entityType,
|
'supplier' entityType,
|
||||||
s.id entity,
|
s.id entityId,
|
||||||
|
s.name entityName,
|
||||||
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||||
FALSE isTicket,
|
FALSE isTicket,
|
||||||
b.id lineFk,
|
b.id lineFk,
|
||||||
|
@ -104,10 +106,10 @@ BEGIN
|
||||||
b.quantity,
|
b.quantity,
|
||||||
st.alertLevel,
|
st.alertLevel,
|
||||||
st.name stateName,
|
st.name stateName,
|
||||||
s.name,
|
|
||||||
e.invoiceNumber,
|
e.invoiceNumber,
|
||||||
'supplier' entityType,
|
'supplier' entityType,
|
||||||
s.id entity,
|
s.id entityId,
|
||||||
|
s.name,
|
||||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||||
FALSE isTicket,
|
FALSE isTicket,
|
||||||
b.id,
|
b.id,
|
||||||
|
@ -125,7 +127,7 @@ BEGIN
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
'FREE')
|
'FREE')
|
||||||
WHERE tr.shipped >= vDateInventory
|
WHERE tr.shipped >= vDateInventory
|
||||||
AND vWarehouseFk = tr.warehouseOutFk
|
AND tr.warehouseOutFk = vWarehouseFk
|
||||||
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
|
AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND NOT e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
|
@ -138,29 +140,30 @@ BEGIN
|
||||||
s.quantity,
|
s.quantity,
|
||||||
st2.alertLevel,
|
st2.alertLevel,
|
||||||
st2.name,
|
st2.name,
|
||||||
t.nickname,
|
|
||||||
t.refFk,
|
t.refFk,
|
||||||
t.id ticketFk,
|
t.id ticketFk,
|
||||||
'client' entityType,
|
'client' entityType,
|
||||||
t.clientFk entity,
|
t.clientFk entityId,
|
||||||
|
t.nickname,
|
||||||
s.id saleFk,
|
s.id saleFk,
|
||||||
st.`order`,
|
st.`order`,
|
||||||
c.typeFk,
|
c.typeFk,
|
||||||
cb.claimFk
|
cb.claimFk
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
LEFT JOIN vn.ticketLastState tls ON tls.ticketFk = t.id
|
||||||
LEFT JOIN vn.state st ON st.`code` = ts.`code`
|
LEFT JOIN vn.ticketTracking tt ON tt.id = tls.ticketTrackingFk
|
||||||
|
LEFT JOIN vn.state st ON st.id = tt.stateFk
|
||||||
JOIN vn.client c ON c.id = t.clientFk
|
JOIN vn.client c ON c.id = t.clientFk
|
||||||
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||||
'DELIVERED',
|
'DELIVERED',
|
||||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||||
'FREE',
|
'FREE',
|
||||||
IFNULL(ts.code, 'FREE')))
|
IFNULL(st.code, 'FREE')))
|
||||||
LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
|
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
|
||||||
WHERE t.shipped >= vDateInventory
|
WHERE t.shipped >= vDateInventory
|
||||||
AND s.itemFk = vItemFk
|
AND s.itemFk = vItemFk
|
||||||
AND vWarehouseFk = t.warehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
)
|
)
|
||||||
SELECT 'ticket',
|
SELECT 'ticket',
|
||||||
s.ticketFk,
|
s.ticketFk,
|
||||||
|
@ -169,10 +172,10 @@ BEGIN
|
||||||
s.quantity,
|
s.quantity,
|
||||||
s.alertLevel,
|
s.alertLevel,
|
||||||
s.name,
|
s.name,
|
||||||
s.nickname,
|
|
||||||
s.refFk,
|
s.refFk,
|
||||||
s.entityType,
|
s.entityType,
|
||||||
s.entity,
|
s.entityId,
|
||||||
|
s.nickname,
|
||||||
IF(stk.saleFk, TRUE, FALSE),
|
IF(stk.saleFk, TRUE, FALSE),
|
||||||
TRUE,
|
TRUE,
|
||||||
s.saleFk,
|
s.saleFk,
|
||||||
|
@ -188,16 +191,16 @@ BEGIN
|
||||||
),
|
),
|
||||||
orders AS (
|
orders AS (
|
||||||
SELECT 'order' originType,
|
SELECT 'order' originType,
|
||||||
o.id origin,
|
o.id originId,
|
||||||
r.shipment,
|
r.shipment,
|
||||||
NULL 'in',
|
NULL 'in',
|
||||||
r.amount,
|
r.amount,
|
||||||
NULL alertLevel,
|
NULL alertLevel,
|
||||||
NULL stateName,
|
NULL stateName,
|
||||||
c.name,
|
|
||||||
NULL invoiceNumber,
|
NULL invoiceNumber,
|
||||||
'client' entityType,
|
'client' entityType,
|
||||||
c.id,
|
c.id,
|
||||||
|
c.name,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE isTicket,
|
FALSE isTicket,
|
||||||
NULL buyFk,
|
NULL buyFk,
|
||||||
|
@ -212,6 +215,10 @@ BEGIN
|
||||||
WHERE r.shipment >= vDateInventory
|
WHERE r.shipment >= vDateInventory
|
||||||
AND (ir.ended IS NULL OR r.shipment <= ir.ended)
|
AND (ir.ended IS NULL OR r.shipment <= ir.ended)
|
||||||
AND r.warehouseFk = vWarehouseFk
|
AND r.warehouseFk = vWarehouseFk
|
||||||
|
AND r.created >= (
|
||||||
|
SELECT SUBTIME(util.VN_NOW(), reserveTime)
|
||||||
|
FROM hedera.orderConfig
|
||||||
|
)
|
||||||
AND NOT o.confirmed
|
AND NOT o.confirmed
|
||||||
AND r.itemFk = vItemFk
|
AND r.itemFk = vItemFk
|
||||||
)
|
)
|
||||||
|
@ -223,7 +230,7 @@ BEGIN
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT * FROM orders
|
SELECT * FROM orders
|
||||||
ORDER BY shipped,
|
ORDER BY shipped,
|
||||||
(inventorySupplierFk = entity) DESC,
|
(inventorySupplierFk = entityId) DESC,
|
||||||
alertLevel DESC,
|
alertLevel DESC,
|
||||||
isTicket,
|
isTicket,
|
||||||
`order` DESC,
|
`order` DESC,
|
||||||
|
@ -237,14 +244,14 @@ BEGIN
|
||||||
SET @shipped := '';
|
SET @shipped := '';
|
||||||
|
|
||||||
SELECT t.originType,
|
SELECT t.originType,
|
||||||
t.origin,
|
t.originId,
|
||||||
DATE(@shipped:= t.shipped) shipped,
|
DATE(@shipped:= t.shipped) shipped,
|
||||||
t.alertLevel,
|
t.alertLevel,
|
||||||
t.stateName,
|
t.stateName,
|
||||||
t.reference,
|
t.reference,
|
||||||
t.entityType,
|
t.entityType,
|
||||||
t.entity,
|
t.entityId,
|
||||||
t.name,
|
t.entityName,
|
||||||
t.`in` invalue,
|
t.`in` invalue,
|
||||||
t.`out`,
|
t.`out`,
|
||||||
@a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance,
|
@a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance,
|
||||||
|
@ -266,13 +273,13 @@ BEGIN
|
||||||
WHERE shipped < vDated;
|
WHERE shipped < vDated;
|
||||||
|
|
||||||
SELECT NULL originType,
|
SELECT NULL originType,
|
||||||
NULL origin,
|
NULL originId,
|
||||||
vDated shipped,
|
vDated shipped,
|
||||||
NULL alertLevel,
|
NULL alertLevel,
|
||||||
NULL stateName,
|
NULL stateName,
|
||||||
NULL reference,
|
NULL reference,
|
||||||
NULL entityType,
|
NULL entityType,
|
||||||
NULL entity,
|
NULL entityId,
|
||||||
'Inventario calculado',
|
'Inventario calculado',
|
||||||
@a invalue,
|
@a invalue,
|
||||||
NULL `out`,
|
NULL `out`,
|
||||||
|
@ -286,14 +293,15 @@ BEGIN
|
||||||
NULL `order`
|
NULL `order`
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT originType,
|
SELECT originType,
|
||||||
origin,
|
originId,
|
||||||
shipped,
|
shipped,
|
||||||
alertlevel,
|
alertlevel,
|
||||||
stateName,
|
stateName,
|
||||||
reference,
|
reference,
|
||||||
entityType,
|
entityType,
|
||||||
entity,
|
entityId,
|
||||||
name, `in`,
|
entityName,
|
||||||
|
`in`,
|
||||||
`out`,
|
`out`,
|
||||||
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
CREATE INDEX travel_landed_IDX USING BTREE ON vn.travel (landed DESC,warehouseInFk,warehouseOutFk);
|
Loading…
Reference in New Issue