7983-testToMaster_2438 #2977
|
@ -996,7 +996,7 @@ INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`
|
|||
INSERT INTO `vn`.`itemMinimumQuantity`(`itemFk`, `quantity`, `started`, `ended`, `warehouseFk`)
|
||||
VALUES
|
||||
(1, 5, util.VN_CURDATE() - INTERVAL 2 MONTH, util.VN_CURDATE() + INTERVAL 1 MONTH, 1),
|
||||
(2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, NULL, 2),
|
||||
(2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, util.VN_CURDATE() - INTERVAL 1 DAY, 2),
|
||||
(3, 15, util.VN_CURDATE() + INTERVAL 3 DAY, util.VN_CURDATE() + INTERVAL 2 WEEK, 3),
|
||||
(2, 10, util.VN_CURDATE() + INTERVAL 2 MONTH, NULL, 5),
|
||||
(4, 8, util.VN_CURDATE() - INTERVAL 3 MONTH, NULL, NULL);
|
||||
|
|
|
@ -56,13 +56,21 @@ BEGIN
|
|||
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
|
||||
END IF;
|
||||
|
||||
SELECT quantity INTO vMinQuantity
|
||||
WITH itemMinQuantityPriority AS (
|
||||
SELECT quantity,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY itemFk
|
||||
ORDER BY warehouseFk IS NULL
|
||||
) priority
|
||||
FROM vn.itemMinimumQuantity
|
||||
WHERE itemFk = vItem
|
||||
AND `started` <= vShipment
|
||||
AND (`ended` >= vShipment OR `ended` IS NULL)
|
||||
AND (warehouseFk = vWarehouse OR warehouseFk IS NULL)
|
||||
LIMIT 1;
|
||||
)
|
||||
SELECT quantity INTO vMinQuantity
|
||||
FROM itemMinQuantityPriority
|
||||
WHERE priority = 1;
|
||||
|
||||
IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN
|
||||
CALL util.throw ('quantityLessThanMin');
|
||||
|
|
|
@ -180,15 +180,24 @@ BEGIN
|
|||
GROUP BY itemFk
|
||||
) bl ON bl.itemFk = tl.itemFk
|
||||
LEFT JOIN (
|
||||
SELECT itemFk, quantity, warehouseFk
|
||||
FROM itemMinimumQuantity
|
||||
WITH itemMinQuantityPriority AS (
|
||||
SELECT itemFk,
|
||||
quantity,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY itemFk
|
||||
ORDER BY warehouseFk IS NULL
|
||||
) priority
|
||||
FROM vn.itemMinimumQuantity
|
||||
WHERE `started` <= vShipped
|
||||
AND (`ended` >= vShipped OR `ended` IS NULL)
|
||||
GROUP BY itemFk, warehouseFk
|
||||
ORDER BY warehouseFk DESC
|
||||
AND (warehouseFk = vWarehouseFk OR warehouseFk IS NULL)
|
||||
)
|
||||
SELECT itemFk, quantity
|
||||
FROM itemMinQuantityPriority
|
||||
WHERE priority = 1
|
||||
) mq ON mq.itemFk = tl.itemFk
|
||||
AND (mq.warehouseFk = tl.warehouseFk OR mq.warehouseFk IS NULL)
|
||||
WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
|
||||
WHERE tl.zoneFk = vZoneFk
|
||||
AND tl.warehouseFk = vWarehouseFk
|
||||
GROUP BY tl.itemFk
|
||||
ON DUPLICATE KEY UPDATE available = available + VALUES(available);
|
||||
END LOOP;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE vn.itemMinimumQuantity
|
||||
ADD CONSTRAINT itemMinimumQuantity_check CHECK (quantity > 0);
|
|
@ -88,8 +88,8 @@ module.exports = Self => {
|
|||
|
||||
if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return;
|
||||
|
||||
const minQuantity = await models.ItemMinimumQuantity.findOne({
|
||||
fields: ['quantity'],
|
||||
const itemMinimalQuantity = await models.ItemMinimumQuantity.find({
|
||||
fields: ['quantity', 'warehouseFk'],
|
||||
where: {
|
||||
itemFk: itemId,
|
||||
started: {lte: ticket.shipped},
|
||||
|
@ -103,9 +103,14 @@ module.exports = Self => {
|
|||
{warehouseFk: null}
|
||||
]
|
||||
},
|
||||
limit: 1
|
||||
}, ctx.options);
|
||||
|
||||
const minQuantity = itemMinimalQuantity.reduce((selected, item) => {
|
||||
if (item.warehouseFk === ticket.warehouseFk) return item;
|
||||
if (item.warehouseFk === null && !selected) return item;
|
||||
return selected;
|
||||
}, null);
|
||||
|
||||
if (newQuantity < minQuantity?.quantity && newQuantity != available)
|
||||
throw new UserError('The amount cannot be less than the minimum');
|
||||
|
||||
|
|
Loading…
Reference in New Issue