Compare commits

..

8 Commits

Author SHA1 Message Date
Pako Natek 3a5eb00a45 Merge pull request '8069-Overstocking' (!3051) from 8069-Overstocking into dev
gitea/salix/pipeline/head This commit looks good Details
Reviewed-on: #3051
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
2024-10-02 12:34:13 +00:00
Pako Natek abb39ec0e7 Merge branch 'dev' into 8069-Overstocking
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-02 12:32:45 +00:00
Pako Natek fc1ea280fa fix: refs #8069 new conception
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-02 14:03:57 +02:00
Pako Natek b53f6d4008 Merge branch 'dev' into 8069-Overstocking
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-02 06:53:43 +00:00
Pako Natek 9d84c39fce feat: refs #8069 orderRow_updateOverstocking
gitea/salix/pipeline/pr-dev This commit looks good Details
2024-10-02 08:52:20 +02:00
Pako Natek 03ea7580d8 feat: refs #8069 new proc 2024-10-01 15:02:24 +02:00
Pako Natek fd262e32c1 feat: refs #8069 new trigger hedera.orderRow_afterInsert 2024-10-01 14:25:10 +02:00
Pako Natek 304992e7cf feat: refs #8069 starting branch 2024-10-01 13:40:33 +02:00
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,52 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost`
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
BEGIN
/**
* Set amount = 0 to avoid overbooking sales
*
* @param vOrderFk hedera.order.id
*/
DECLARE vCalcFk INT;
DECLARE vDone BOOL;
DECLARE vWarehouseFk INT;
DECLARE cWarehouses CURSOR FOR
SELECT DISTINCT warehouseFk
FROM orderRow
WHERE orderFk = vOrderFk
AND shipped = util.VN_CURDATE();
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
OPEN cWarehouses;
checking: LOOP
SET vDone = FALSE;
FETCH cWarehouses INTO vWarehouseFk;
IF vDone THEN
LEAVE checking;
END IF;
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE());
UPDATE orderRow r
JOIN `order` o ON o.id = r.orderFk
JOIN orderConfig oc
JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk
SET r.amount = 0
WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW()
AND a.available <= 0
AND r.warehouseFk = vWarehouseFk
AND r.orderFk = vOrderFk;
END LOOP;
CLOSE cWarehouses;
END$$
DELIMITER ;

View File

@ -12,6 +12,7 @@ BEGIN
* @param vUser The user identifier
*/
DECLARE vHasRows BOOL;
DECLARE vHas0Amount BOOL;
DECLARE vDone BOOL;
DECLARE vWarehouseFk INT;
DECLARE vShipment DATE;
@ -101,6 +102,8 @@ BEGIN
CALL order_checkEditable(vSelf);
CALL orderRow_updateOverstocking(vSelf);
-- Check order is not empty
SELECT COUNT(*) > 0 INTO vHasRows
FROM orderRow
@ -111,6 +114,18 @@ BEGIN
CALL util.throw('ORDER_EMPTY');
END IF;
-- Check if any product has a quantity of 0
SELECT EXISTS (
SELECT id
FROM orderRow
WHERE orderFk = vSelf
AND amount = 0
) INTO vHas0Amount;
IF vHas0Amount THEN
CALL util.throw('Remove lines with quantity = 0 before confirming');
END IF;
-- Crea los tickets del pedido
OPEN vDates;
lDates: LOOP

View File

@ -0,0 +1,10 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert`
AFTER INSERT ON `orderRow`
FOR EACH ROW
BEGIN
UPDATE `order`
SET rowUpdated = NOW()
WHERE id = NEW.orderFk;
END$$
DELIMITER ;

View File

@ -0,0 +1,3 @@
-- Place your SQL code here
ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL
COMMENT 'Timestamp for last updated record in orderRow table';