feat: refs #7363 item_getBalance saleTracking no mostrar duplicados
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
6207d79244
commit
cb9cacc1ea
|
@ -41,6 +41,7 @@ BEGIN
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO tItemDiary
|
INSERT INTO tItemDiary
|
||||||
|
WITH entries AS (
|
||||||
SELECT tr.landed shipped,
|
SELECT tr.landed shipped,
|
||||||
b.quantity `in`,
|
b.quantity `in`,
|
||||||
NULL `out`,
|
NULL `out`,
|
||||||
|
@ -70,24 +71,25 @@ BEGIN
|
||||||
AND vWarehouseFk = tr.warehouseInFk
|
AND vWarehouseFk = tr.warehouseInFk
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND e.isRaid = FALSE
|
AND NOT e.isRaid
|
||||||
UNION ALL
|
),
|
||||||
|
deliveried AS (
|
||||||
SELECT tr.shipped,
|
SELECT tr.shipped,
|
||||||
NULL,
|
NULL,
|
||||||
b.quantity,
|
b.quantity,
|
||||||
st.alertLevel,
|
st.alertLevel,
|
||||||
st.name,
|
st.name stateName,
|
||||||
s.name ,
|
s.name ,
|
||||||
e.invoiceNumber,
|
e.invoiceNumber,
|
||||||
e.id,
|
e.id entryFk,
|
||||||
s.id,
|
s.id supplierFk,
|
||||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||||
FALSE,
|
FALSE isTicket,
|
||||||
b.id,
|
b.id,
|
||||||
NULL,
|
NULL `order`,
|
||||||
NULL,
|
NULL clientType,
|
||||||
NULL,
|
NULL claimFk,
|
||||||
ec.inventorySupplierFk
|
ec.inventorySupplierFk
|
||||||
FROM buy b
|
FROM buy b
|
||||||
JOIN entry e ON e.id = b.entryFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
@ -103,26 +105,23 @@ BEGIN
|
||||||
AND vWarehouseFk = tr.warehouseOutFk
|
AND vWarehouseFk = tr.warehouseOutFk
|
||||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||||
AND b.itemFk = vItemFk
|
AND b.itemFk = vItemFk
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND w.isFeedStock = FALSE
|
AND NOT w.isFeedStock
|
||||||
AND e.isRaid = FALSE
|
AND NOT e.isRaid
|
||||||
UNION ALL
|
),
|
||||||
SELECT DATE(t.shipped),
|
sales AS (
|
||||||
NULL,
|
SELECT DATE(t.shipped) shipped,
|
||||||
s.quantity,
|
s.quantity,
|
||||||
st2.alertLevel,
|
st2.alertLevel,
|
||||||
st2.name,
|
st2.name,
|
||||||
t.nickname,
|
t.nickname,
|
||||||
t.refFk,
|
t.refFk,
|
||||||
t.id,
|
t.id ticketFk,
|
||||||
t.clientFk,
|
t.clientFk,
|
||||||
stk.id,
|
s.id saleFk,
|
||||||
TRUE,
|
|
||||||
s.id,
|
|
||||||
st.`order`,
|
st.`order`,
|
||||||
c.typeFk,
|
c.typeFk,
|
||||||
cb.claimFk,
|
cb.claimFk
|
||||||
NULL
|
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
|
@ -133,13 +132,53 @@ BEGIN
|
||||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||||
'FREE',
|
'FREE',
|
||||||
IFNULL(ts.code, 'FREE')))
|
IFNULL(ts.code, 'FREE')))
|
||||||
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
|
||||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id
|
|
||||||
AND stk.stateFk = stPrep.id
|
|
||||||
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
||||||
WHERE t.shipped >= vDateInventory
|
WHERE t.shipped >= vDateInventory
|
||||||
AND s.itemFk = vItemFk
|
AND s.itemFk = vItemFk
|
||||||
AND vWarehouseFk = t.warehouseFk
|
AND vWarehouseFk = t.warehouseFk
|
||||||
|
),sale AS (
|
||||||
|
SELECT s.shipped,
|
||||||
|
NULL `in`,
|
||||||
|
s.quantity,
|
||||||
|
s.alertLevel,
|
||||||
|
s.name,
|
||||||
|
s.nickname,
|
||||||
|
s.refFk,
|
||||||
|
s.ticketFk,
|
||||||
|
s.clientFk,
|
||||||
|
IF(stk.saleFk, TRUE, NULL),
|
||||||
|
TRUE,
|
||||||
|
s.saleFk,
|
||||||
|
s.`order`,
|
||||||
|
s.typeFk,
|
||||||
|
s.claimFk,
|
||||||
|
NULL
|
||||||
|
FROM sales s
|
||||||
|
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
||||||
|
LEFT JOIN saleTracking stk ON stk.saleFk = s.saleFk
|
||||||
|
AND stk.stateFk = stPrep.id
|
||||||
|
GROUP BY s.saleFk
|
||||||
|
) SELECT shipped,
|
||||||
|
`in`,
|
||||||
|
`out`,
|
||||||
|
alertLevel,
|
||||||
|
stateName,
|
||||||
|
`name`,
|
||||||
|
reference,
|
||||||
|
origin,
|
||||||
|
clientFk,
|
||||||
|
isPicked,
|
||||||
|
isTicket,
|
||||||
|
lineFk,
|
||||||
|
`order`,
|
||||||
|
clientType,
|
||||||
|
claimFk,
|
||||||
|
inventorySupplierFk
|
||||||
|
FROM entries
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM deliveried
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM sale
|
||||||
ORDER BY shipped,
|
ORDER BY shipped,
|
||||||
(inventorySupplierFk = clientFk) DESC,
|
(inventorySupplierFk = clientFk) DESC,
|
||||||
alertLevel DESC,
|
alertLevel DESC,
|
||||||
|
|
Loading…
Reference in New Issue