Merge pull request 'hotfix item_getBalance' (!1563) from hotfix-item_getBalance into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1563
This commit is contained in:
commit
c46e6cd862
|
@ -59861,141 +59861,205 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getBalance`(IN vItemId int, IN vWarehouse int)
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(vItemFk int, vWarehouseFk int, vDate DATETIME)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vDateInventory DATETIME;
|
/**
|
||||||
DECLARE vCurdate DATE DEFAULT util.VN_CURDATE();
|
* @vItemFk item a buscar
|
||||||
DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate);
|
* @vWarehouseFk almacen donde buscar
|
||||||
|
* @vDate Si la fecha es null, muestra el histórico desde el inventario. Si la fecha no es null, muestra histórico desde la fecha pasada.
|
||||||
|
*/
|
||||||
|
|
||||||
SELECT inventoried INTO vDateInventory FROM config;
|
DECLARE vDateInventory DATETIME;
|
||||||
SET @a = 0;
|
DECLARE vInvCalculated INT;
|
||||||
SET @currentLineFk = 0;
|
|
||||||
SET @shipped = '';
|
|
||||||
|
|
||||||
SELECT DATE(@shipped:= shipped) shipped,
|
IF vDate IS NULL THEN
|
||||||
alertLevel,
|
SELECT inventoried INTO vDateInventory
|
||||||
stateName,
|
FROM config;
|
||||||
origin,
|
ELSE
|
||||||
reference,
|
SELECT mockUtcTime INTO vDateInventory
|
||||||
clientFk,
|
FROM util.config;
|
||||||
name,
|
END IF;
|
||||||
`in` AS invalue,
|
|
||||||
`out`,
|
|
||||||
@a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
|
|
||||||
@currentLineFk := IF (@shipped < util.VN_CURDATE()
|
|
||||||
OR (@shipped = util.VN_CURDATE() AND (isPicked OR alertLevel >= 2)),
|
|
||||||
lineFk,@currentLineFk) lastPreparedLineFk,
|
|
||||||
isTicket,
|
|
||||||
lineFk,
|
|
||||||
isPicked,
|
|
||||||
clientType,
|
|
||||||
claimFk
|
|
||||||
FROM
|
|
||||||
( SELECT tr.landed AS shipped,
|
|
||||||
b.quantity AS `in`,
|
|
||||||
NULL AS `out`,
|
|
||||||
al.id AS alertLevel,
|
|
||||||
st.name AS stateName,
|
|
||||||
s.name AS name,
|
|
||||||
e.invoiceNumber AS reference,
|
|
||||||
e.id AS origin,
|
|
||||||
s.id AS clientFk,
|
|
||||||
IF(al.id = 3, TRUE, FALSE) isPicked,
|
|
||||||
FALSE AS isTicket,
|
|
||||||
b.id lineFk,
|
|
||||||
NULL `order`,
|
|
||||||
NULL AS clientType,
|
|
||||||
NULL AS claimFk
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
|
||||||
JOIN supplier s ON s.id = e.supplierFk
|
|
||||||
JOIN alertLevel al ON al.id =
|
|
||||||
CASE
|
|
||||||
WHEN tr.landed < util.VN_CURDATE() THEN 3
|
|
||||||
WHEN tr.landed = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
JOIN state st ON st.code = al.code
|
|
||||||
WHERE tr.landed >= vDateInventory
|
|
||||||
AND vWarehouse = tr.warehouseInFk
|
|
||||||
AND b.itemFk = vItemId
|
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
|
||||||
AND e.isRaid = FALSE
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT tr.shipped,
|
CREATE OR REPLACE TEMPORARY TABLE itemDiary(
|
||||||
NULL,
|
shipped DATE,
|
||||||
b.quantity,
|
`in` INT(11),
|
||||||
al.id,
|
`out` INT(11),
|
||||||
st.name,
|
alertLevel INT(11),
|
||||||
s.name,
|
stateName VARCHAR(20),
|
||||||
e.invoiceNumber,
|
`name` VARCHAR(50),
|
||||||
e.id,
|
reference VARCHAR(50),
|
||||||
s.id,
|
origin INT(11),
|
||||||
IF(al.id = 3, TRUE, FALSE),
|
clientFk INT(11),
|
||||||
FALSE,
|
isPicked INT(11),
|
||||||
b.id,
|
isTicket TINYINT(1),
|
||||||
NULL,
|
lineFk INT(11),
|
||||||
NULL,
|
`order` TINYINT(3) UNSIGNED,
|
||||||
NULL
|
clientType VARCHAR(20),
|
||||||
FROM buy b
|
claimFk INT(10) UNSIGNED
|
||||||
JOIN entry e ON e.id = b.entryFk
|
);
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = tr.warehouseOutFk
|
|
||||||
JOIN supplier s ON s.id = e.supplierFk
|
|
||||||
JOIN alertLevel al ON al.id =
|
|
||||||
CASE
|
|
||||||
WHEN tr.shipped < util.VN_CURDATE() THEN 3
|
|
||||||
WHEN tr.shipped = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3
|
|
||||||
ELSE 0
|
|
||||||
END
|
|
||||||
JOIN state st ON st.code = al.code
|
|
||||||
WHERE tr.shipped >= vDateInventory
|
|
||||||
AND vWarehouse =tr.warehouseOutFk
|
|
||||||
AND s.id <> 4
|
|
||||||
AND b.itemFk = vItemId
|
|
||||||
AND e.isExcludedFromAvailable = FALSE
|
|
||||||
AND w.isFeedStock = FALSE
|
|
||||||
AND e.isRaid = FALSE
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT DATE(t.shipped),
|
INSERT INTO itemDiary
|
||||||
NULL,
|
SELECT tr.landed shipped,
|
||||||
s.quantity,
|
b.quantity `in`,
|
||||||
al.id,
|
NULL `out`,
|
||||||
st.name,
|
al.id alertLevel,
|
||||||
t.nickname,
|
st.name stateName,
|
||||||
t.refFk,
|
s.name `name`,
|
||||||
t.id,
|
e.invoiceNumber reference,
|
||||||
t.clientFk,
|
e.id origin,
|
||||||
stk.id,
|
s.id clientFk,
|
||||||
TRUE,
|
IF(al.code = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||||
s.id,
|
FALSE isTicket,
|
||||||
st.`order`,
|
b.id lineFk,
|
||||||
ct.code,
|
NULL `order`,
|
||||||
cb.claimFk
|
NULL clientType,
|
||||||
FROM sale s
|
NULL claimFk
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
FROM buy b
|
||||||
LEFT JOIN ticketState ts ON ts.ticket = t.id
|
JOIN entry e ON e.id = b.entryFk
|
||||||
LEFT JOIN state st ON st.code = ts.code
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN supplier s ON s.id = e.supplierFk
|
||||||
JOIN clientType ct ON ct.id = c.clientTypeFk
|
JOIN alertLevel al ON al.code =
|
||||||
JOIN alertLevel al ON al.id =
|
CASE
|
||||||
CASE
|
WHEN tr.landed < util.VN_CURDATE() THEN 'DELIVERED'
|
||||||
WHEN t.shipped < util.VN_CURDATE() THEN 3
|
WHEN tr.landed = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 'DELIVERED'
|
||||||
WHEN t.shipped > util.dayEnd(util.VN_CURDATE()) THEN 0
|
ELSE 'FREE'
|
||||||
ELSE IFNULL(ts.alertLevel, 0)
|
END
|
||||||
END
|
JOIN state st ON st.code = al.code
|
||||||
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
WHERE tr.landed >= vDateInventory
|
||||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id
|
AND vWarehouseFk = tr.warehouseInFk
|
||||||
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
AND b.itemFk = vItemFk
|
||||||
WHERE t.shipped >= vDateInventory
|
AND e.isExcludedFromAvailable = FALSE
|
||||||
AND s.itemFk = vItemId
|
AND e.isRaid = FALSE
|
||||||
AND vWarehouse =t.warehouseFk
|
UNION ALL
|
||||||
ORDER BY shipped, alertLevel DESC, isTicket, `order` DESC, isPicked DESC, `in` DESC, `out` DESC
|
SELECT tr.shipped,
|
||||||
) AS itemDiary;
|
NULL,
|
||||||
|
b.quantity,
|
||||||
|
al.id,
|
||||||
|
st.name,
|
||||||
|
s.name,
|
||||||
|
e.invoiceNumber,
|
||||||
|
e.id,
|
||||||
|
s.id,
|
||||||
|
IF(al.code = 'DELIVERED', TRUE, FALSE),
|
||||||
|
FALSE,
|
||||||
|
b.id,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
|
JOIN warehouse w ON w.id = tr.warehouseOutFk
|
||||||
|
JOIN supplier s ON s.id = e.supplierFk
|
||||||
|
JOIN alertLevel al ON al.code =
|
||||||
|
CASE
|
||||||
|
WHEN tr.shipped < util.VN_CURDATE() THEN 'DELIVERED'
|
||||||
|
WHEN tr.shipped = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 'DELIVERED'
|
||||||
|
ELSE 'FREE'
|
||||||
|
END
|
||||||
|
JOIN state st ON st.code = al.code
|
||||||
|
JOIN entryConfig ec
|
||||||
|
WHERE tr.shipped >= vDateInventory
|
||||||
|
AND vWarehouseFk =tr.warehouseOutFk
|
||||||
|
AND s.id <> ec.inventorySupplierFk
|
||||||
|
AND b.itemFk = vItemFk
|
||||||
|
AND e.isExcludedFromAvailable = FALSE
|
||||||
|
AND w.isFeedStock = FALSE
|
||||||
|
AND e.isRaid = FALSE
|
||||||
|
UNION ALL
|
||||||
|
SELECT DATE(t.shipped),
|
||||||
|
NULL,
|
||||||
|
s.quantity,
|
||||||
|
al3.id,
|
||||||
|
st.name,
|
||||||
|
t.nickname,
|
||||||
|
t.refFk,
|
||||||
|
t.id,
|
||||||
|
t.clientFk,
|
||||||
|
stk.id,
|
||||||
|
TRUE,
|
||||||
|
s.id,
|
||||||
|
st.`order`,
|
||||||
|
ct.code,
|
||||||
|
cb.claimFk
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
LEFT JOIN ticketState ts ON ts.ticket = t.id
|
||||||
|
LEFT JOIN state st ON st.code = ts.code
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
JOIN clientType ct ON ct.id = c.clientTypeFk
|
||||||
|
JOIN alertLevel al ON al.code = 'DELIVERED'
|
||||||
|
JOIN alertLevel al2 ON al2.code = 'FREE'
|
||||||
|
JOIN alertLevel al3 ON al3.id =
|
||||||
|
CASE
|
||||||
|
WHEN t.shipped < util.VN_CURDATE() THEN al.code
|
||||||
|
WHEN t.shipped > util.dayEnd(util.VN_CURDATE()) THEN al2.code
|
||||||
|
ELSE IFNULL(ts.alertLevel, al2.code)
|
||||||
|
END
|
||||||
|
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
|
||||||
|
WHERE t.shipped >= vDateInventory
|
||||||
|
AND s.itemFk = vItemFk
|
||||||
|
AND vWarehouseFk =t.warehouseFk
|
||||||
|
ORDER BY shipped, alertLevel DESC, isTicket, `order` DESC, isPicked DESC, `in` DESC, `out` DESC;
|
||||||
|
|
||||||
|
IF vDate IS NULL THEN
|
||||||
|
SET @a = 0;
|
||||||
|
SET @currentLineFk = 0;
|
||||||
|
SET @shipped = '';
|
||||||
|
|
||||||
|
SELECT DATE(@shipped:= shipped) shipped,
|
||||||
|
alertLevel,
|
||||||
|
stateName,
|
||||||
|
origin,
|
||||||
|
reference,
|
||||||
|
clientFk,
|
||||||
|
name,
|
||||||
|
`in` AS invalue,
|
||||||
|
`out`,
|
||||||
|
@a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
|
||||||
|
@currentLineFk := IF (@shipped < util.VN_CURDATE()
|
||||||
|
OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.code >= 'ON_PREPARATION')),
|
||||||
|
lineFk, @currentLineFk) lastPreparedLineFk,
|
||||||
|
isTicket,
|
||||||
|
lineFk,
|
||||||
|
isPicked,
|
||||||
|
clientType,
|
||||||
|
claimFk
|
||||||
|
FROM itemDiary
|
||||||
|
JOIN alertLevel a ON a.id = itemDiary.alertLevel;
|
||||||
|
ELSE
|
||||||
|
SELECT sum(`in`) - sum(`out`) INTO vInvCalculated
|
||||||
|
FROM itemDiary
|
||||||
|
WHERE shipped < vDate;
|
||||||
|
|
||||||
|
SELECT p1.*
|
||||||
|
FROM(
|
||||||
|
SELECT vDate shipped,
|
||||||
|
0 alertLevel,
|
||||||
|
0 stateName,
|
||||||
|
0 origin,
|
||||||
|
'' reference,
|
||||||
|
0 clientFk,
|
||||||
|
'Inventario calculado',
|
||||||
|
vInvCalculated invalue,
|
||||||
|
NULL `out`,
|
||||||
|
0 balance,
|
||||||
|
0 lastPreparedLineFk,
|
||||||
|
0 isTicket,
|
||||||
|
0 lineFk,
|
||||||
|
0 isPicked,
|
||||||
|
0 clientType,
|
||||||
|
0 claimFk
|
||||||
|
UNION ALL
|
||||||
|
SELECT shipped, alertlevel, stateName, origin, reference, clientFk, name, `in`, `out`, 0,0, isTicket, lineFk, isPicked, clientType, claimFk
|
||||||
|
FROM itemDiary
|
||||||
|
WHERE shipped >= vDate
|
||||||
|
)as p1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE itemDiary;
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
|
|
@ -26,8 +26,8 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const where = filter.where;
|
const where = filter.where;
|
||||||
const query = 'CALL vn.item_getBalance(?, ?)';
|
const query = 'CALL vn.item_getBalance(?, ?, ?)';
|
||||||
const [diary] = await Self.rawSql(query, [where.itemFk, where.warehouseFk], myOptions);
|
const [diary] = await Self.rawSql(query, [where.itemFk, where.warehouseFk, null], myOptions);
|
||||||
|
|
||||||
for (const entry of diary)
|
for (const entry of diary)
|
||||||
if (entry.clientType === 'loses') entry.highlighted = true;
|
if (entry.clientType === 'loses') entry.highlighted = true;
|
||||||
|
|
Loading…
Reference in New Issue