diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql
index 4f85db98a..d918007e7 100644
--- a/db/dump/fixtures.before.sql
+++ b/db/dump/fixtures.before.sql
@@ -115,6 +115,9 @@ INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType`
VALUES
(1, 978, 1, 0, 2000, 9, 0);
+INSERT INTO hedera.orderConfig (`id`, `employeeFk`, `defaultAgencyFk`, `guestMethod`, `guestAgencyFk`, `reserveTime`, `defaultCompanyFk`)
+ VALUES (1, 1, 2, 'PICKUP', 1, '00:20:00', 442);
+
INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`)
VALUES
(1101, 'brucewayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es','1101'),
@@ -301,6 +304,17 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23;
UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10;
+UPDATE `vn`.`agencyMode` SET `description` = 'inhouse pickup' WHERE `id` = 1;
+UPDATE `vn`.`agencyMode` SET `description` = 'Super-Man delivery' WHERE `id` = 2;
+UPDATE `vn`.`agencyMode` SET `description` = 'Teleportation device' WHERE `id` = 3;
+UPDATE `vn`.`agencyMode` SET `description` = 'Entanglement' WHERE `id` = 4;
+UPDATE `vn`.`agencyMode` SET `description` = 'Quantum break device' WHERE `id` = 5;
+UPDATE `vn`.`agencyMode` SET `description` = 'Walking' WHERE `id` = 6;
+UPDATE `vn`.`agencyMode` SET `description` = 'Gotham247' WHERE `id` = 7;
+UPDATE `vn`.`agencyMode` SET `description` = 'Gotham247Expensive' WHERE `id` = 8;
+UPDATE `vn`.`agencyMode` SET `description` = 'Other agency' WHERE `id` = 10;
+UPDATE `vn`.`agencyMode` SET `description` = 'Refund' WHERE `id` = 23;
+
UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com';
UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23;
@@ -979,6 +993,14 @@ INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`
(2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()),
(3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE());
+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),
+ (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);
+
INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`)
VALUES
(71,0.141,1);
diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql
index 63b42dfd9..78d23dbfb 100644
--- a/db/routines/cache/procedures/visible_refresh.sql
+++ b/db/routines/cache/procedures/visible_refresh.sql
@@ -1,13 +1,13 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT)
-proc: BEGIN
+proc:BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
CALL cache_calc_unlock (v_calc);
RESIGNAL;
END;
- CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
+ CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
IF !v_refresh THEN
LEAVE proc;
@@ -15,22 +15,23 @@ proc: BEGIN
-- Calculamos el stock hasta ayer
- CALL `cache`.stock_refresh(false);
+ CALL cache.stock_refresh(false);
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
(PRIMARY KEY (item_id))
ENGINE = MEMORY
- SELECT item_id, amount stock, amount visible FROM `cache`.stock
+ SELECT item_id, amount stock, amount visible
+ FROM cache.stock
WHERE warehouse_id = v_warehouse;
-- Calculamos los movimientos confirmados de hoy
- CALL vn.item_GetVisible(v_warehouse, NULL);
+ CALL vn.item_calcVisible(NULL, v_warehouse);
DELETE FROM visible WHERE calc_id = v_calc;
INSERT INTO visible (calc_id, item_id,visible)
SELECT v_calc, item_id, visible FROM tmp.itemVisible;
- CALL cache_calc_end (v_calc);
+ CALL cache_calc_end (v_calc);
DROP TEMPORARY TABLE tmp.itemVisible;
END$$
diff --git a/db/routines/hedera/procedures/item_calcCatalog.sql b/db/routines/hedera/procedures/item_calcCatalog.sql
index 4da878d23..fae89bd5c 100644
--- a/db/routines/hedera/procedures/item_calcCatalog.sql
+++ b/db/routines/hedera/procedures/item_calcCatalog.sql
@@ -25,12 +25,7 @@ BEGIN
JOIN vn.warehouse w ON w.id = p.warehouseFk
ORDER BY warehouseFk, `grouping`;
- DROP TEMPORARY TABLE
- tmp.ticketCalculateItem,
- tmp.ticketComponentPrice,
- tmp.ticketComponent,
- tmp.ticketLot,
- tmp.zoneGetShipped,
- tmp.item;
+ CALL vn.ticketCalculatePurge();
+ DROP TEMPORARY TABLE tmp.item;
END$$
DELIMITER ;
diff --git a/db/routines/hedera/procedures/order_addItem.sql b/db/routines/hedera/procedures/order_addItem.sql
index d9c15c0eb..50c2f3489 100644
--- a/db/routines/hedera/procedures/order_addItem.sql
+++ b/db/routines/hedera/procedures/order_addItem.sql
@@ -56,11 +56,15 @@ BEGIN
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
END IF;
- SELECT IFNULL(minQuantity, 0) INTO vMinQuantity
- FROM vn.item
- WHERE id = vItem;
+ SELECT quantity INTO vMinQuantity
+ 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;
- IF vAmount < LEAST(vMinQuantity, vAvailable) THEN
+ IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN
CALL util.throw ('quantityLessThanMin');
END IF;
diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql
new file mode 100644
index 000000000..5d94170a0
--- /dev/null
+++ b/db/routines/vn/events/claim_changeState.sql
@@ -0,0 +1,22 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState`
+ ON SCHEDULE EVERY 1 DAY
+ STARTS '2024-06-06 07:52:46.000'
+ ON COMPLETION PRESERVE
+ ENABLE
+DO BEGIN
+
+ DECLARE vClaimState INT;
+
+ SELECT id INTO vClaimState
+ FROM claimState cs
+ WHERE cs.code = 'canceled';
+
+ UPDATE claim c
+ JOIN claimState cs ON cs.id = c.claimStateFk
+ SET c.claimStateFk = vClaimState
+ WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH
+ AND cs.code IN('incomplete','coming','waiting','out');
+
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/procedures/address_updateCoordinates.sql b/db/routines/vn/procedures/address_updateCoordinates.sql
new file mode 100644
index 000000000..bdeb886df
--- /dev/null
+++ b/db/routines/vn/procedures/address_updateCoordinates.sql
@@ -0,0 +1,25 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_updateCoordinates`(
+ vTicketFk INT,
+ vLongitude INT,
+ vLatitude INT)
+BEGIN
+/**
+ * Actualiza las coordenadas de una dirección.
+ *
+ * @param vTicketFk Id del ticket
+ * @param vLongitude Longitud de la dirección
+ * @param vLatitude Latitud de la dirección
+ */
+ DECLARE vAddressFK INT;
+
+ SELECT addressFK INTO vAddressFK
+ FROM ticket
+ WHERE id = vTicketFk;
+
+ UPDATE address
+ SET longitude = vLongitude,
+ latitude = vLatitude
+ WHERE id = vAddressFK;
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql
index bb52020df..e79f2da0b 100644
--- a/db/routines/vn/procedures/catalog_calculate.sql
+++ b/db/routines/vn/procedures/catalog_calculate.sql
@@ -45,8 +45,7 @@ BEGIN
CALL catalog_componentPrepare();
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem;
- CREATE TEMPORARY TABLE tmp.ticketCalculateItem(
+ CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem(
itemFk INT(11) NOT NULL,
available INT(11),
producer VARCHAR(50),
@@ -60,11 +59,11 @@ BEGIN
price DECIMAL(10,2),
priceKg DECIMAL(10,2),
`grouping` INT(10) UNSIGNED,
+ minQuantity INT(10) UNSIGNED,
PRIMARY KEY `itemFk` (`itemFk`)
) ENGINE = MEMORY DEFAULT CHARSET=utf8;
OPEN cTravelTree;
-
l: LOOP
SET vDone = FALSE;
FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped;
@@ -136,7 +135,7 @@ BEGIN
CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
- INSERT INTO tmp.ticketCalculateItem (
+ INSERT INTO tmp.ticketCalculateItem(
itemFk,
available,
producer,
@@ -149,9 +148,9 @@ BEGIN
origin,
price,
priceKg,
- `grouping`)
- SELECT
- tl.itemFk,
+ `grouping`,
+ minQuantity)
+ SELECT tl.itemFk,
SUM(tl.available) available,
p.name producer,
i.name item,
@@ -163,7 +162,8 @@ BEGIN
o.code origin,
bl.price,
bl.priceKg,
- bl.`grouping`
+ bl.`grouping`,
+ mq.quantity
FROM tmp.ticketLot tl
JOIN item i ON tl.itemFk = i.id
LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible
@@ -179,12 +179,19 @@ BEGIN
) sub
GROUP BY itemFk
) bl ON bl.itemFk = tl.itemFk
+ LEFT JOIN (
+ SELECT itemFk, quantity, warehouseFk
+ FROM itemMinimumQuantity
+ WHERE `started` <= vShipped
+ AND (`ended` >= vShipped OR `ended` IS NULL)
+ GROUP BY itemFk, warehouseFk
+ ORDER BY warehouseFk DESC
+ ) mq ON mq.itemFk = tl.itemFk
+ AND (mq.warehouseFk = tl.warehouseFk OR mq.warehouseFk IS NULL)
WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk
GROUP BY tl.itemFk
ON DUPLICATE KEY UPDATE available = available + VALUES(available);
-
END LOOP;
-
CLOSE cTravelTree;
END$$
DELIMITER ;
diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql
index bf130b2c6..f9032a91d 100644
--- a/db/routines/vn/procedures/collection_assign.sql
+++ b/db/routines/vn/procedures/collection_assign.sql
@@ -26,16 +26,16 @@ BEGIN
vErrorNumber = MYSQL_ERRNO,
vErrorMsg = MESSAGE_TEXT;
+ CALL util.debugAdd('collection_assign', JSON_OBJECT(
+ 'errorNumber', vErrorNumber,
+ 'errorMsg', vErrorMsg,
+ 'lockName', vLockName,
+ 'userFk', vUserFk
+ )); -- Tmp
+
IF vLockName IS NOT NULL THEN
DO RELEASE_LOCK(vLockName);
- CALL util.debugAdd('collection_assign', JSON_OBJECT(
- 'errorNumber', vErrorNumber,
- 'errorMsg', vErrorMsg,
- 'lockName', vLockName,
- 'userFk', vUserFk
- )); -- Tmp
END IF;
-
RESIGNAL;
END;
diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql
index 029427306..0bd6e1b25 100644
--- a/db/routines/vn/procedures/collection_new.sql
+++ b/db/routines/vn/procedures/collection_new.sql
@@ -53,17 +53,17 @@ BEGIN
vErrorNumber = MYSQL_ERRNO,
vErrorMsg = MESSAGE_TEXT;
+ CALL util.debugAdd('collection_new', JSON_OBJECT(
+ 'errorNumber', vErrorNumber,
+ 'errorMsg', vErrorMsg,
+ 'lockName', vLockName,
+ 'userFk', vUserFk,
+ 'ticketFk', vTicketFk
+ )); -- Tmp
+
IF vLockName IS NOT NULL THEN
DO RELEASE_LOCK(vLockName);
- CALL util.debugAdd('collection_new', JSON_OBJECT(
- 'errorNumber', vErrorNumber,
- 'errorMsg', vErrorMsg,
- 'lockName', vLockName,
- 'userFk', vUserFk,
- 'ticketFk', vTicketFk
- )); -- Tmp
END IF;
-
RESIGNAL;
END;
diff --git a/db/routines/vn/procedures/collection_setParking.sql b/db/routines/vn/procedures/collection_setParking.sql
index 73aa87bfb..5f6ca75da 100644
--- a/db/routines/vn/procedures/collection_setParking.sql
+++ b/db/routines/vn/procedures/collection_setParking.sql
@@ -1,15 +1,18 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT)
-proc: BEGIN
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(
+ vSelf INT,
+ vParkingFk INT
+)
+BEGIN
/**
* Aparca una colección en un parking.
*
- * @param vCollectionFk Id de la colección
- * @param vParkingFk Id del parking
+ * @param vSelf Id colección
+ * @param vParkingFk Id parking
*/
- REPLACE vn.ticketParking(ticketFk, parkingFk)
+ REPLACE ticketParking(ticketFk, parkingFk)
SELECT tc.ticketFk, vParkingFk
- FROM vn.ticketCollection tc
- WHERE tc.collectionFk = vCollectionFk;
+ FROM ticketCollection tc
+ WHERE tc.collectionFk = vSelf;
END$$
DELIMITER ;
diff --git a/db/routines/vn/procedures/item_GetVisible.sql b/db/routines/vn/procedures/item_GetVisible.sql
deleted file mode 100644
index ca5e43107..000000000
--- a/db/routines/vn/procedures/item_GetVisible.sql
+++ /dev/null
@@ -1,43 +0,0 @@
-DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT)
-BEGIN
- DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE());
-
- INSERT INTO tmp.itemVisible (item_id, visible)
- SELECT item_id, SUM(amount) amount
- FROM (
- SELECT i.itemFk AS item_id, quantity AS amount
- FROM itemTicketOut i
- LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
- JOIN state s ON s.id = ts.stateFk
- LEFT JOIN (SELECT DISTINCT saleFk
- FROM saleTracking st
- JOIN state s ON s.id = st.stateFk
- WHERE st.created > util.VN_CURDATE()
- AND (s.isPicked OR st.isChecked)
- ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
- WHERE i.warehouseFk = vWarehouse
- AND (vItem IS NULL OR i.itemFk = vItem)
- AND (s.isPicked OR i.reserved OR stPrevious.saleFk )
- AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow
- UNION ALL
- SELECT iei.itemFk, quantity
- FROM itemEntryIn iei
- WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/)
- AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow
- AND iei.warehouseInFk = vWarehouse
- AND (vItem IS NULL OR iei.itemFk = vItem)
- AND iei.isVirtualStock is FALSE
- UNION ALL
- SELECT itemFk, quantity
- FROM itemEntryOut
- WHERE isDelivered != FALSE
- AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow
- AND warehouseOutFk = vWarehouse
- AND (vItem IS NULL OR itemFk = vItem)
- ) t
- GROUP BY item_id
- ON DUPLICATE KEY UPDATE
- visible = IFNULL(stock,0) + VALUES(visible);
-END$$
-DELIMITER ;
diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql
new file mode 100644
index 000000000..820e73a7e
--- /dev/null
+++ b/db/routines/vn/procedures/item_calcVisible.sql
@@ -0,0 +1,56 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`(
+ vSelf INT,
+ vWarehouseFk INT
+)
+BEGIN
+/**
+ * Calcula el visible de un artículo o de todos.
+ *
+ * @param vWarehouse Warehouse id
+ * @param vSelf Item id
+ * @param tmp.itemVisible(item_id, stock, visible)
+ */
+ DECLARE vDated DATE DEFAULT util.VN_CURDATE();
+ DECLARE vTomorrow DATETIME DEFAULT util.tomorrow();
+
+ INSERT INTO tmp.itemVisible(item_id, visible)
+ SELECT itemFk, SUM(quantity)
+ FROM (
+ SELECT i.itemFk, i.quantity
+ FROM itemTicketOut i
+ LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
+ JOIN `state` s ON s.id = ts.stateFk
+ LEFT JOIN (
+ SELECT DISTINCT st.saleFk
+ FROM saleTracking st
+ JOIN state s ON s.id = st.stateFk
+ WHERE st.created > vDated
+ AND (s.isPicked OR st.isChecked)
+ ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
+ WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk
+ AND (vSelf IS NULL OR i.itemFk = vSelf)
+ AND (s.isPicked OR i.reserved OR stPrevious.saleFk)
+ AND i.shipped >= vDated AND i.shipped < vTomorrow
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM itemEntryIn
+ WHERE isReceived
+ AND landed >= vDated AND landed < vTomorrow
+ AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk
+ AND (vSelf IS NULL OR itemFk = vSelf)
+ AND NOT isVirtualStock
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM itemEntryOut
+ WHERE isDelivered
+ AND shipped >= vDated
+ AND shipped < vTomorrow
+ AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk
+ AND (vSelf IS NULL OR itemFk = vSelf)
+ ) t
+ GROUP BY itemFk
+ ON DUPLICATE KEY UPDATE
+ visible = IFNULL(stock, 0) + VALUES(visible);
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql
index a4942af6f..0de59b478 100644
--- a/db/routines/vn/procedures/item_getBalance.sql
+++ b/db/routines/vn/procedures/item_getBalance.sql
@@ -2,94 +2,84 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(
vItemFk INT,
vWarehouseFk INT,
- vDate DATETIME
+ vDated DATETIME
)
BEGIN
/**
- * @vItemFk item a buscar
- * @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 de vDate.
+ * Calcula el balance de un artículo.
+ *
+ * @vItemFk Id de artículo
+ * @vWarehouseFk Id de almacén
+ * @vDated Fecha a calcular, si es NULL muestra el histórico desde el inventario
*/
- DECLARE vDateInventory DATETIME;
+ DECLARE vDateInventory DATETIME
+ DEFAULT (
+ SELECT IF(vDated, uc.mockUtcTime, c.inventoried)
+ FROM config c
+ JOIN util.config uc
+ );
+ DECLARE vSupplierInventoryFk INT
+ DEFAULT (SELECT supplierFk FROM inventoryConfig);
- IF vDate IS NULL THEN
- SELECT inventoried INTO vDateInventory
- FROM config;
- ELSE
- SELECT mockUtcTime INTO vDateInventory
- FROM util.config;
+ IF NOT vSupplierInventoryFk OR NOT vDateInventory THEN
+ CALL util.throw('Config variables are not set');
END IF;
- CREATE OR REPLACE TEMPORARY TABLE tItemDiary(
- shipped DATE,
- `in` INT(11),
- `out` INT(11),
- alertLevel INT(11),
- stateName VARCHAR(20),
- `name` VARCHAR(50),
- reference VARCHAR(50),
- origin INT(11),
- clientFk INT(11),
- isPicked INT(11),
- isTicket TINYINT(1),
- lineFk INT(11),
- `order` TINYINT(3) UNSIGNED,
- clientType VARCHAR(20),
- claimFk INT(10) UNSIGNED,
- inventorySupplierFk INT(10)
- );
-
- INSERT INTO tItemDiary
+ CREATE OR REPLACE TEMPORARY TABLE tItemDiary
+ ENGINE = MEMORY
WITH entriesIn AS (
- SELECT tr.landed shipped,
+ SELECT 'entry' originType,
+ e.id originId,
+ tr.landed shipped,
b.quantity `in`,
NULL `out`,
st.alertLevel ,
st.name stateName,
- s.name `name`,
e.invoiceNumber reference,
- e.id origin,
- s.id clientFk,
+ 'supplier' entityType,
+ s.id entityId,
+ s.name entityName,
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
FALSE isTicket,
b.id lineFk,
NULL `order`,
NULL clientType,
NULL claimFk,
- ec.inventorySupplierFk
+ vSupplierInventoryFk inventorySupplierFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
JOIN vn.supplier s ON s.id = e.supplierFk
- JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
+ JOIN vn.state st ON st.`code` = IF(tr.landed < util.VN_CURDATE()
OR (util.VN_CURDATE() AND tr.isReceived),
'DELIVERED',
'FREE')
- JOIN vn.entryConfig ec
WHERE tr.landed >= vDateInventory
- AND vWarehouseFk = tr.warehouseInFk
- AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
+ AND tr.warehouseInFk = vWarehouseFk
+ AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
- ), entriesOut AS (
- SELECT tr.shipped,
+ ),
+ entriesOut AS (
+ SELECT 'entry',
+ e.id originType,
+ tr.shipped,
NULL,
b.quantity,
st.alertLevel,
st.name stateName,
- s.name ,
e.invoiceNumber,
- e.id entryFk,
- s.id supplierFk,
+ 'supplier' entityType,
+ s.id entityId,
+ s.name,
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
FALSE isTicket,
b.id,
NULL `order`,
NULL clientType,
NULL claimFk,
- ec.inventorySupplierFk
+ vSupplierInventoryFk
FROM vn.buy b
JOIN vn.entry e ON e.id = b.entryFk
JOIN vn.travel tr ON tr.id = e.travelFk
@@ -99,86 +89,108 @@ BEGIN
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
'DELIVERED',
'FREE')
- JOIN vn.entryConfig ec
WHERE tr.shipped >= vDateInventory
- AND vWarehouseFk = tr.warehouseOutFk
- AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
+ AND tr.warehouseOutFk = vWarehouseFk
+ AND (s.id <> vSupplierInventoryFk OR vDated IS NULL)
AND b.itemFk = vItemFk
AND NOT e.isExcludedFromAvailable
AND NOT w.isFeedStock
AND NOT e.isRaid
- ), sales AS (
- SELECT DATE(t.shipped) shipped,
- s.quantity,
- st2.alertLevel,
- st2.name,
- t.nickname,
- t.refFk,
- t.id ticketFk,
- t.clientFk,
- s.id saleFk,
- st.`order`,
- c.typeFk,
- cb.claimFk
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
- LEFT JOIN vn.state st ON st.`code` = ts.`code`
- JOIN vn.client c ON c.id = t.clientFk
- JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
- 'DELIVERED',
- IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
- 'FREE',
- IFNULL(ts.code, 'FREE')))
- LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
- WHERE t.shipped >= vDateInventory
- AND s.itemFk = vItemFk
- AND vWarehouseFk = t.warehouseFk
- ),sale AS (
- SELECT s.shipped,
+ ),
+ sales AS (
+ WITH itemSales AS (
+ SELECT DATE(t.shipped) shipped,
+ s.quantity,
+ st2.alertLevel,
+ st2.name,
+ t.refFk,
+ t.id ticketFk,
+ 'client' entityType,
+ t.clientFk entityId,
+ t.nickname,
+ s.id saleFk,
+ st.`order`,
+ c.typeFk,
+ cb.claimFk
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ LEFT JOIN vn.state st ON st.code = ts.code
+ JOIN vn.client c ON c.id = t.clientFk
+ JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
+ 'DELIVERED',
+ IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
+ 'FREE',
+ IFNULL(st.code, 'FREE')))
+ LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
+ WHERE t.shipped >= vDateInventory
+ AND s.itemFk = vItemFk
+ AND t.warehouseFk = vWarehouseFk
+ )
+ SELECT 'ticket',
+ s.ticketFk,
+ s.shipped,
NULL `in`,
s.quantity,
s.alertLevel,
s.name,
- s.nickname,
s.refFk,
- s.ticketFk,
- s.clientFk,
- IF(stk.saleFk, TRUE, NULL),
+ s.entityType,
+ s.entityId,
+ s.nickname,
+ IF(stk.saleFk, TRUE, FALSE),
TRUE,
s.saleFk,
s.`order`,
s.typeFk,
s.claimFk,
NULL
- FROM sales s
+ FROM itemSales s
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN vn.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 entriesIn
+ ),
+ orders AS (
+ SELECT 'order' originType,
+ o.id originId,
+ r.shipment,
+ NULL 'in',
+ r.amount,
+ NULL alertLevel,
+ NULL stateName,
+ NULL invoiceNumber,
+ 'client' entityType,
+ c.id,
+ c.name,
+ FALSE,
+ FALSE isTicket,
+ NULL buyFk,
+ NULL 'order',
+ c.typeFk,
+ NULL claimFk,
+ NULL
+ FROM hedera.orderRow r
+ JOIN hedera.`order` o ON o.id = r.orderFk
+ JOIN vn.client c ON c.id = o.customer_id
+ WHERE r.shipment >= vDateInventory
+ AND r.warehouseFk = vWarehouseFk
+ AND r.created >= (
+ SELECT SUBTIME(util.VN_NOW(), reserveTime)
+ FROM hedera.orderConfig
+ )
+ AND NOT o.confirmed
+ AND r.itemFk = vItemFk
+ )
+ SELECT * FROM entriesIn
UNION ALL
SELECT * FROM entriesOut
UNION ALL
- SELECT * FROM sale
+ SELECT * FROM sales
+ UNION ALL
+ SELECT * FROM orders
ORDER BY shipped,
- (inventorySupplierFk = clientFk) DESC,
+ (inventorySupplierFk = entityId) DESC,
alertLevel DESC,
isTicket,
`order` DESC,
@@ -186,19 +198,20 @@ BEGIN
`in` DESC,
`out` DESC;
- IF vDate IS NULL THEN
-
+ IF vDated IS NULL THEN
SET @a := 0;
SET @currentLineFk := 0;
SET @shipped := '';
- SELECT DATE(@shipped:= t.shipped) shipped,
+ SELECT t.originType,
+ t.originId,
+ DATE(@shipped:= t.shipped) shipped,
t.alertLevel,
t.stateName,
- t.origin,
t.reference,
- t.clientFk,
- t.name,
+ t.entityType,
+ t.entityId,
+ t.entityName,
t.`in` invalue,
t.`out`,
@a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance,
@@ -214,37 +227,41 @@ BEGIN
t.`order`
FROM tItemDiary t
LEFT JOIN alertLevel a ON a.id = t.alertLevel;
-
ELSE
SELECT IFNULL(SUM(IFNULL(`in`, 0)) - SUM(IFNULL(`out`, 0)), 0) INTO @a
FROM tItemDiary
- WHERE shipped < vDate;
+ WHERE shipped < vDated;
- SELECT vDate shipped,
- 0 alertLevel,
- 0 stateName,
- 0 origin,
- '' reference,
- 0 clientFk,
+ SELECT NULL originType,
+ NULL originId,
+ vDated shipped,
+ NULL alertLevel,
+ NULL stateName,
+ NULL reference,
+ NULL entityType,
+ NULL entityId,
'Inventario calculado',
@a invalue,
NULL `out`,
@a balance,
- 0 lastPreparedLineFk,
- 0 isTicket,
- 0 lineFk,
- 0 isPicked,
- 0 clientType,
- 0 claimFk,
+ NULL lastPreparedLineFk,
+ NULL isTicket,
+ NULL lineFk,
+ NULL isPicked,
+ NULL clientType,
+ NULL claimFk,
NULL `order`
UNION ALL
- SELECT shipped,
+ SELECT originType,
+ originId,
+ shipped,
alertlevel,
stateName,
- origin,
- reference,
- clientFk,
- name, `in`,
+ reference,
+ entityType,
+ entityId,
+ entityName,
+ `in`,
`out`,
@a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0),
0,
@@ -255,7 +272,7 @@ BEGIN
claimFk,
`order`
FROM tItemDiary
- WHERE shipped >= vDate;
+ WHERE shipped >= vDated;
END IF;
DROP TEMPORARY TABLE tItemDiary;
diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql
index 557d77bdf..72c543b40 100644
--- a/db/routines/vn/procedures/item_getSimilar.sql
+++ b/db/routines/vn/procedures/item_getSimilar.sql
@@ -63,7 +63,7 @@ BEGIN
WHEN b.groupingMode = 'grouping' THEN b.grouping
WHEN b.groupingMode = 'packing' THEN b.packing
ELSE 1
- END AS minQuantity,
+ END minQuantity,
v.visible located,
b.price2
FROM vn.item i
diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql
index 941ac6c3d..6cd584c6e 100644
--- a/db/routines/vn/procedures/multipleInventory.sql
+++ b/db/routines/vn/procedures/multipleInventory.sql
@@ -10,6 +10,7 @@ proc: BEGIN
DECLARE vDateTo DATETIME;
DECLARE vDateToTomorrow DATETIME;
DECLARE vDefaultDayRange INT;
+ DECLARE vCalcFk INT;
IF vDate < util.VN_CURDATE() THEN
LEAVE proc;
@@ -82,50 +83,18 @@ proc: BEGIN
ai.sd = iic.quantity;
-- Cálculo del visible
- CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
- (PRIMARY KEY (itemFk))
- ENGINE = MEMORY
- SELECT itemFk, SUM(quantity) visible
- FROM (
- SELECT s.itemFk, s.quantity
- FROM sale s
- JOIN ticket t ON t.id = s.ticketFk
- JOIN warehouse w ON w.id = t.warehouseFk
- WHERE t.shipped >= vDate
- AND t.shipped < vDateTomorrow
- AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
- AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
- AND w.isComparative
- UNION ALL
- SELECT b.itemFk, - b.quantity
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- JOIN warehouse w ON w.id = t.warehouseInFk
- WHERE t.landed = vDate
- AND NOT t.isReceived
- AND NOT e.isExcludedFromAvailable
- AND NOT e.isRaid
- AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
- AND w.isComparative
- UNION ALL
- SELECT b.itemFk, b.quantity
- FROM buy b
- JOIN entry e ON e.id = b.entryFk
- JOIN travel t ON t.id = e.travelFk
- JOIN warehouse w ON w.id = t.warehouseOutFk
- WHERE t.shipped = vDate
- AND NOT t.isReceived
- AND NOT e.isExcludedFromAvailable
- AND NOT e.isRaid
- AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
- AND w.isComparative
- ) sub2
- GROUP BY itemFk;
+ CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk);
- UPDATE tmp.itemInventory ai
- JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
- SET ai.visible = ai.visible + ivc.visible;
+ CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
+ (PRIMARY KEY (item_id))
+ ENGINE = MEMORY
+ SELECT item_id, visible
+ FROM cache.visible
+ WHERE calc_id = vCalcFk;
+
+ UPDATE tmp.itemInventory it
+ JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id
+ SET it.visible = it.visible + ivc.visible;
-- Calculo del disponible
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
@@ -196,8 +165,8 @@ proc: BEGIN
DROP TEMPORARY TABLE
tmp.itemTravel,
tmp.itemCalc,
+ tmp.itemAtp,
tItemInventoryCalc,
- tItemVisibleCalc,
- tmp.itemAtp;
+ tItemVisibleCalc;
END$$
DELIMITER ;
diff --git a/db/routines/vn/procedures/saleGroup_setParking.sql b/db/routines/vn/procedures/saleGroup_setParking.sql
index 4872f74c6..551ca6386 100644
--- a/db/routines/vn/procedures/saleGroup_setParking.sql
+++ b/db/routines/vn/procedures/saleGroup_setParking.sql
@@ -1,17 +1,25 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT)
-proc: BEGIN
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(
+ vSaleGroupFk VARCHAR(8),
+ vParkingFk INT
+)
+BEGIN
/**
- * Aparca una preparación previa en un parking
+ * Aparca una preparación previa en un parking.
*
* @param vSaleGroupFk id de la preparación previa
* @param vParkingFk id del parking
*/
- UPDATE vn.saleGroup sg
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ RESIGNAL;
+ END;
+
+ UPDATE saleGroup sg
SET sg.parkingFk = vParkingFk
WHERE sg.id = vSaleGroupFk
- AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
+ AND sg.created >= util.VN_CURDATE() - INTERVAL 1 WEEK;
- CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk));
+ CALL ticket_setNextState(ticket_get(vSaleGroupFk));
END$$
DELIMITER ;
diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql
index 20319cc3f..689090051 100644
--- a/db/routines/vn/procedures/sale_setProblem.sql
+++ b/db/routines/vn/procedures/sale_setProblem.sql
@@ -5,14 +5,32 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
BEGIN
/**
* Update column sale.problem with a problem code
+ *
* @param vProblemCode Code to set or unset
* @table tmp.sale(saleFk, hasProblem)
*/
- UPDATE sale s
- JOIN tmp.sale ts ON ts.saleFk = s.id
- SET s.problem = CONCAT(
- IF(ts.hasProblem,
- CONCAT(s.problem, ',', vProblemCode),
- REPLACE(s.problem, vProblemCode , '')));
+ DECLARE vSaleFk INT;
+ DECLARE vHasProblem INT;
+ DECLARE vDone BOOL;
+ DECLARE vSaleList CURSOR FOR SELECT saleFk, hasProblem FROM tmp.sale;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ OPEN vSaleList;
+ l: LOOP
+ SET vDone = FALSE;
+ FETCH vSaleList INTO vSaleFk, vHasProblem;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ UPDATE sale
+ SET problem = CONCAT(
+ IF(vHasProblem,
+ CONCAT(problem, ',', vProblemCode),
+ REPLACE(problem, vProblemCode , '')))
+ WHERE id = vSaleFk;
+ END LOOP;
+ CLOSE vSaleList;
END$$
DELIMITER ;
\ No newline at end of file
diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql
index d6def07de..1aa4f920a 100644
--- a/db/routines/vn/procedures/setParking.sql
+++ b/db/routines/vn/procedures/setParking.sql
@@ -1,6 +1,9 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8))
-proc: BEGIN
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(
+ vParam VARCHAR(8),
+ vParkingCode VARCHAR(8)
+)
+BEGIN
/**
* Aparca una colección, un ticket, un saleGroup o un shelving en un parking
*
@@ -8,56 +11,41 @@ proc: BEGIN
* @param vParkingCode código del parking
*/
DECLARE vParkingFk INT;
- DECLARE vIsSaleGroup BOOL;
- DECLARE vIsTicket BOOL;
- DECLARE vIsCollection BOOL;
+ DECLARE vLastWeek DATE;
- SET vParkingCode = replace(vParkingCode,' ','');
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ SET vParkingCode = REPLACE(vParkingCode, ' ', '');
SELECT id INTO vParkingFk
- FROM vn.parking
+ FROM parking
WHERE code = vParkingCode COLLATE utf8_unicode_ci;
IF vParkingFk IS NULL THEN
CALL util.throw('parkingNotExist');
- LEAVE proc;
END IF;
-
- IF vParam REGEXP '^[0-9]+$' THEN
- -- Se comprueba si es una preparación previa
- SELECT COUNT(*) INTO vIsSaleGroup
- FROM vn.saleGroup sg
- WHERE sg.id = vParam;
- IF vIsSaleGroup THEN
- CALL vn.saleGroup_setParking(vParam, vParkingFk);
- LEAVE proc;
- END IF;
+ START TRANSACTION;
- -- Se comprueba si es un ticket
- SELECT COUNT(*) INTO vIsTicket
- FROM vn.ticket t
- WHERE t.id = vParam
- AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
+ SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK;
- IF vIsTicket THEN
- CALL vn.ticket_setParking(vParam, vParkingFk);
- LEAVE proc;
- END IF;
-
- -- Se comprueba si es una coleccion de tickets
- SELECT COUNT(*) INTO vIsCollection
- FROM vn.collection c
- WHERE c.id = vParam
- AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE());
-
- IF vIsCollection THEN
- CALL vn.collection_setParking(vParam, vParkingFk);
- LEAVE proc;
- END IF;
+ -- Comprobamos si es una prep. previa, ticket, colección o shelving
+ IF (SELECT TRUE FROM saleGroup WHERE id = vParam) THEN
+ CALL saleGroup_setParking(vParam, vParkingFk);
+ ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam AND shipped >= vLastWeek) THEN
+ CALL ticket_setParking(vParam, vParkingFk);
+ ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN
+ CALL collection_setParking(vParam, vParkingFk);
+ ELSEIF (SELECT TRUE FROM shelving WHERE code = vParam COLLATE utf8_unicode_ci) THEN
+ CALL shelving_setParking(vParam, vParkingFk);
ELSE
- -- Por descarte, se considera una matrícula
- CALL vn.shelving_setParking(vParam, vParkingFk);
+ CALL util.throw('paramNotExist');
END IF;
+
+ COMMIT;
END$$
DELIMITER ;
diff --git a/db/routines/vn/procedures/ticket_setNextState.sql b/db/routines/vn/procedures/ticket_setNextState.sql
index d13cd53f0..b09309a47 100644
--- a/db/routines/vn/procedures/ticket_setNextState.sql
+++ b/db/routines/vn/procedures/ticket_setNextState.sql
@@ -1,14 +1,21 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT)
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(
+ vSelf INT
+)
BEGIN
/**
- * Cambia el estado del ticket al siguiente estado según la tabla state
+ * Cambia el estado del ticket al siguiente estado según la tabla state.
*
- * @param vSelf id dle ticket
+ * @param vSelf Id ticket
*/
DECLARE vStateFk INT;
DECLARE vNewStateFk INT;
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ RESIGNAL;
+ END;
+
SELECT stateFk INTO vStateFk
FROM ticketState
WHERE ticketFk = vSelf;
@@ -17,6 +24,10 @@ BEGIN
FROM state
WHERE id = vStateFk;
+ IF vNewStateFk IS NULL THEN
+ CALL util.throw('The ticket not have next state');
+ END IF;
+
INSERT INTO ticketTracking(stateFk, ticketFk, userFk)
VALUES (vNewStateFk, vSelf, account.myUser_getId());
END$$
diff --git a/db/routines/vn/procedures/ticket_setParking.sql b/db/routines/vn/procedures/ticket_setParking.sql
index 54c64daea..7935e0d60 100644
--- a/db/routines/vn/procedures/ticket_setParking.sql
+++ b/db/routines/vn/procedures/ticket_setParking.sql
@@ -1,11 +1,14 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT)
-proc: BEGIN
+CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(
+ vSelf INT,
+ vParkingFk INT
+)
+BEGIN
/**
- * Aparca un ticket en un parking
+ * Aparca un ticket en un parking.
*
- * @param vTicketFk id del ticket
- * @param vParkingFk id del parking
+ * @param vSelf Id ticket
+ * @param vParkingFk Id parking
*/
DECLARE vDone INT DEFAULT FALSE;
DECLARE vCollectionTicketFk INT;
@@ -14,16 +17,21 @@ proc: BEGIN
FROM ticket t
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
- WHERE t.id = vTicketFk;
+ WHERE t.id = vSelf;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ RESIGNAL;
+ END;
+
INSERT INTO vn.ticketParking(ticketFk, parkingFk)
SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk
FROM ticket t
LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id
LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk
- WHERE t.id = vTicketFk
+ WHERE t.id = vSelf
ON DUPLICATE KEY UPDATE parkingFk = vParkingFk;
OPEN vCursor;
diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql
index bab8f1f52..3d6e14516 100644
--- a/db/routines/vn/procedures/ticket_setProblem.sql
+++ b/db/routines/vn/procedures/ticket_setProblem.sql
@@ -9,11 +9,28 @@ BEGIN
* @param vProblemCode Code to set or unset
* @table tmp.ticket(ticketFk, hasProblem)
*/
- UPDATE ticket t
- JOIN tmp.ticket tt ON tt.ticketFk = t.id
- SET t.problem = CONCAT(
- IF(tt.hasProblem,
- CONCAT(problem, ',', vProblemCode),
- REPLACE(problem, vProblemCode , '')));
+ DECLARE vTicketFk INT;
+ DECLARE vHasProblem INT;
+ DECLARE vDone BOOL;
+ DECLARE vTicketList CURSOR FOR SELECT ticketFk, hasProblem FROM tmp.ticket;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ OPEN vTicketList;
+ l: LOOP
+ SET vDone = FALSE;
+ FETCH vTicketList INTO vTicketFk, vHasProblem;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ UPDATE ticket
+ SET problem = CONCAT(
+ IF(vHasProblem,
+ CONCAT(problem, ',', vProblemCode),
+ REPLACE(problem, vProblemCode , '')))
+ WHERE id = vTicketFk;
+ END LOOP;
+ CLOSE vTicketList;
END$$
DELIMITER ;
\ No newline at end of file
diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql
index db2d1e4c1..c2ec50fd9 100644
--- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql
+++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql
@@ -16,6 +16,9 @@ BEGIN
DECLARE vNewTicketFk INT;
DECLARE vPackingTypesToSplit INT;
DECLARE vDone INT DEFAULT FALSE;
+ DECLARE vErrorNumber INT;
+ DECLARE vErrorMsg TEXT;
+
DECLARE vSaleGroup CURSOR FOR
SELECT itemPackingTypeFk
FROM tSaleGroup
@@ -26,6 +29,15 @@ BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
+ GET DIAGNOSTICS CONDITION 1
+ vErrorNumber = MYSQL_ERRNO,
+ vErrorMsg = MESSAGE_TEXT;
+
+ CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT(
+ 'errorNumber', vErrorNumber,
+ 'errorMsg', vErrorMsg,
+ 'ticketFk', vSelf
+ )); -- Tmp
ROLLBACK;
RESIGNAL;
END;
diff --git a/db/routines/vn/triggers/delivery_beforeInsert.sql b/db/routines/vn/triggers/delivery_beforeInsert.sql
index 89431c30f..eb4a6f21a 100644
--- a/db/routines/vn/triggers/delivery_beforeInsert.sql
+++ b/db/routines/vn/triggers/delivery_beforeInsert.sql
@@ -3,18 +3,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert
BEFORE INSERT ON `delivery`
FOR EACH ROW
BEGIN
-
- IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL)
+ IF (NEW.longitude IS NOT NULL
+ AND NEW.latitude IS NOT NULL
+ AND NEW.ticketFK IS NOT NULL)
THEN
- UPDATE address
- SET longitude = NEW.longitude,
- latitude = NEW.latitude
- WHERE id IN (
- SELECT addressFK
- FROM ticket
- WHERE id = NEW.ticketFk
- );
+ CALL address_updateCoordinates(NEW.ticketFk, NEW.longitude, NEW.latitude);
END IF;
-
END$$
DELIMITER ;
diff --git a/db/routines/vn/triggers/delivery_beforeUpdate.sql b/db/routines/vn/triggers/delivery_beforeUpdate.sql
index 7e6aa7d4c..6206d4722 100644
--- a/db/routines/vn/triggers/delivery_beforeUpdate.sql
+++ b/db/routines/vn/triggers/delivery_beforeUpdate.sql
@@ -3,18 +3,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate
BEFORE UPDATE ON `delivery`
FOR EACH ROW
BEGIN
-
-IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL)
+ IF (NEW.longitude IS NOT NULL
+ AND NEW.latitude IS NOT NULL
+ AND NEW.ticketFK IS NOT NULL)
THEN
- UPDATE address
- SET longitude = NEW.longitude,
- latitude = NEW.latitude
- WHERE id IN (
- SELECT addressFK
- FROM ticket
- WHERE id = NEW.ticketFk
- );
+ CALL address_updateCoordinates(NEW.ticketFk, NEW.longitude, NEW.latitude);
END IF;
-
END$$
DELIMITER ;
diff --git a/db/routines/vn/triggers/itemMinimumQuantity_afterDelete.sql b/db/routines/vn/triggers/itemMinimumQuantity_afterDelete.sql
new file mode 100644
index 000000000..1da5a5942
--- /dev/null
+++ b/db/routines/vn/triggers/itemMinimumQuantity_afterDelete.sql
@@ -0,0 +1,12 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_afterDelete`
+ AFTER DELETE ON `itemMinimumQuantity`
+ FOR EACH ROW
+BEGIN
+ INSERT INTO itemLog
+ SET `action` = 'delete',
+ `changedModel` = 'ItemMinimumQuantity',
+ `changedModelId` = OLD.id,
+ `userFk` = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/triggers/itemMinimumQuantity_beforeInsert.sql b/db/routines/vn/triggers/itemMinimumQuantity_beforeInsert.sql
new file mode 100644
index 000000000..8833ac968
--- /dev/null
+++ b/db/routines/vn/triggers/itemMinimumQuantity_beforeInsert.sql
@@ -0,0 +1,8 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_beforeInsert`
+ BEFORE INSERT ON `itemMinimumQuantity`
+ FOR EACH ROW
+BEGIN
+ SET NEW.editorFk = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/triggers/itemMinimumQuantity_beforeUpdate.sql b/db/routines/vn/triggers/itemMinimumQuantity_beforeUpdate.sql
new file mode 100644
index 000000000..ef030f9f9
--- /dev/null
+++ b/db/routines/vn/triggers/itemMinimumQuantity_beforeUpdate.sql
@@ -0,0 +1,8 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemMinimumQuantity_beforeUpdate`
+ BEFORE UPDATE ON `itemMinimumQuantity`
+ FOR EACH ROW
+BEGIN
+ SET NEW.editorFk = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/triggers/itemShelving _afterDelete.sql b/db/routines/vn/triggers/itemShelving _afterDelete.sql
index 7c0d54358..9a1759eff 100644
--- a/db/routines/vn/triggers/itemShelving _afterDelete.sql
+++ b/db/routines/vn/triggers/itemShelving _afterDelete.sql
@@ -1,5 +1,5 @@
DELIMITER $$
-CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving _afterDelete`
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterDelete`
AFTER DELETE ON `itemShelving`
FOR EACH ROW
BEGIN
diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql
new file mode 100644
index 000000000..384bf681e
--- /dev/null
+++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql
@@ -0,0 +1,12 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_afterDelete`
+ AFTER DELETE ON `productionConfig`
+ FOR EACH ROW
+BEGIN
+ INSERT INTO productionConfig
+ SET `action` = 'delete',
+ `changedModel` = 'ProductionConfig',
+ `changedModelId` = OLD.id,
+ `userFk` = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/triggers/productionConfig_beforeInsert.sql b/db/routines/vn/triggers/productionConfig_beforeInsert.sql
new file mode 100644
index 000000000..99b217be4
--- /dev/null
+++ b/db/routines/vn/triggers/productionConfig_beforeInsert.sql
@@ -0,0 +1,8 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeInsert`
+ BEFORE INSERT ON `productionConfig`
+ FOR EACH ROW
+BEGIN
+ SET NEW.editorFk = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn/triggers/productionConfig_beforeUpdate.sql b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql
new file mode 100644
index 000000000..f1ceaa471
--- /dev/null
+++ b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql
@@ -0,0 +1,8 @@
+DELIMITER $$
+CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeUpdate`
+ BEFORE UPDATE ON `productionConfig`
+ FOR EACH ROW
+BEGIN
+ SET NEW.editorFk = account.myUser_getId();
+END$$
+DELIMITER ;
diff --git a/db/routines/vn2008/views/buySource.sql b/db/routines/vn2008/views/buySource.sql
index 33226a1dc..850483833 100644
--- a/db/routines/vn2008/views/buySource.sql
+++ b/db/routines/vn2008/views/buySource.sql
@@ -54,8 +54,7 @@ AS SELECT `b`.`entryFk` AS `Id_Entrada`,
`i`.`packingOut` AS `packingOut`,
`b`.`itemOriginalFk` AS `itemOriginalFk`,
`io`.`longName` AS `itemOriginalName`,
- `it`.`gramsMax` AS `gramsMax`,
- `i`.`minQuantity` AS `minQuantity`
+ `it`.`gramsMax` AS `gramsMax`
FROM (
(
(
diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql
index 228e0b014..c53a09549 100644
--- a/db/versions/10960-silverRoebelini/00-firstScript.sql
+++ b/db/versions/10960-silverRoebelini/00-firstScript.sql
@@ -5,4 +5,19 @@ CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` (
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
-COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';;
\ No newline at end of file
+COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';
+
+INSERT IGNORE INTO vn.agencyIncoming (agencyModeFk) VALUES
+(1343), (1002), (1282), (841), (1303), (714), (556), (1786), (1785), (1784),
+(1780), (1783), (1758), (1782), (1772), (1789), (1776), (1791), (1778), (1792),
+(1779), (1362), (681), (1765), (15), (1594), (1706), (1707), (907), (1260),
+(1715), (1371), (1372), (53), (689), (1375), (738), (742), (1307), (1700), (608),
+(1311), (1315), (1339), (1433), (1338), (1332), (1844), (842), (1382), (1466),
+(1719), (1723), (1725), (1720), (1732), (1736), (1728), (1724), (1726), (1727),
+(1767), (1734), (1730), (1845), (1729), (1746), (1699), (2), (671), (1379), (614),
+(1718), (1697), (62), (1529), (1392), (1378), (1438), (1796), (1688), (686),
+(1326), (1691), (1), (1560), (1695), (1696), (1558), (1648), (1649), (1598),
+(1680), (1694), (1600), (1601), (1602), (1712), (1603), (1604), (1641), (1692),
+(1693), (1650), (1683), (1682), (1681), (1713), (1826), (1768), (1769), (1770),
+(1593), (1443), (1244), (1679), (1006), (1361), (1102), (1655), (1744), (1225),
+(1007);
diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql
new file mode 100644
index 000000000..c93f2f6b7
--- /dev/null
+++ b/db/versions/11130-crimsonIvy/00-firstScript.sql
@@ -0,0 +1,23 @@
+ALTER TABLE vn.productionConfig
+ ADD editorFk int(10) unsigned DEFAULT NULL NULL;
+ALTER TABLE vn.productionConfig
+ ADD CONSTRAINT productionConfig_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id);
+
+CREATE OR REPLACE TABLE `vn`.`productionConfigLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) DEFAULT NULL,
+ `userFk` int(10) unsigned DEFAULT NULL,
+ `action` set('insert','update','delete','select') NOT NULL,
+ `creationDate` timestamp NULL DEFAULT current_timestamp(),
+ `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
+ `changedModel` enum('ProductionConfig') NOT NULL DEFAULT 'ProductionConfig',
+ `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)),
+ `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)),
+ `changedModelId` int(11) NOT NULL,
+ `changedModelValue` varchar(45) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `productionConfigLog_userFk` (`userFk`),
+ KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`),
+ KEY `productionConfigLog_originFk` (`originFk`,`creationDate`),
+ CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
diff --git a/db/versions/11135-whiteErica/00-firstScript.sql b/db/versions/11135-whiteErica/00-firstScript.sql
new file mode 100644
index 000000000..902608a3e
--- /dev/null
+++ b/db/versions/11135-whiteErica/00-firstScript.sql
@@ -0,0 +1 @@
+CREATE INDEX travel_landed_IDX USING BTREE ON vn.travel (landed DESC,warehouseInFk,warehouseOutFk);
diff --git a/db/versions/11140-azurePhormium/00-firstScript.sql b/db/versions/11140-azurePhormium/00-firstScript.sql
new file mode 100644
index 000000000..7c89110bb
--- /dev/null
+++ b/db/versions/11140-azurePhormium/00-firstScript.sql
@@ -0,0 +1,3 @@
+ALTER TABLE vn.vehicle DROP FOREIGN KEY provinceFk;
+ALTER TABLE vn.vehicle
+ ADD CONSTRAINT vehicle_warehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/db/versions/11145-pinkLaurel/00-firstScript.sql b/db/versions/11145-pinkLaurel/00-firstScript.sql
new file mode 100644
index 000000000..ba1946d3b
--- /dev/null
+++ b/db/versions/11145-pinkLaurel/00-firstScript.sql
@@ -0,0 +1,2 @@
+ALTER TABLE vn.payrollWorker CHANGE grupotarifa__ grupotarifa int(10) NOT NULL;
+ALTER TABLE vn.payrollWorker MODIFY COLUMN grupotarifa int(10) NOT NULL;
\ No newline at end of file
diff --git a/db/versions/11149-silverSalal/00-firstScript.sql b/db/versions/11149-silverSalal/00-firstScript.sql
new file mode 100644
index 000000000..e642dd2e4
--- /dev/null
+++ b/db/versions/11149-silverSalal/00-firstScript.sql
@@ -0,0 +1,30 @@
+ALTER TABLE vn.item CHANGE minQuantity minQuantity__ int(10) unsigned DEFAULT
+ NULL NULL COMMENT '@deprecated 2024-07-11 refs #7704 Cantidad mínima para una línea de venta';
+
+CREATE TABLE `vn`.`itemMinimumQuantity` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `itemFk` int(10) NOT NULL,
+ `quantity` int(10) NOT NULL,
+ `started` date NOT NULL,
+ `ended` date DEFAULT NULL,
+ `warehouseFk` smallint(5) unsigned DEFAULT NULL,
+ `created` timestamp NOT NULL DEFAULT current_timestamp(),
+ `editorFk` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `itemMinimumQuantity_UNIQUE` (`itemFk`, `started`, `ended`, `warehouseFk`),
+ KEY `itemFk` (`itemFk`),
+ KEY `started` (`started`),
+ KEY `ended` (`ended`),
+ KEY `warehouseFk` (`warehouseFk`),
+ KEY `editorFk` (`editorFk`),
+ CONSTRAINT `itemMinimumQuantity_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `itemMinimumQuantity_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `itemMinimumQuantity_ibfk_3` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`),
+ CONSTRAINT `itemMinimumQuantity_check_1` CHECK (`started` <= `ended`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
+
+GRANT SELECT, UPDATE, DELETE, INSERT ON TABLE vn.itemMinimumQuantity TO buyer;
+GRANT EXECUTE ON PROCEDURE vn.ticketCalculatePurge TO guest;
+
+ALTER TABLE vn.itemLog MODIFY COLUMN changedModel enum('Item','ItemBarcode','ItemBotanical','ItemNiche','ItemTag','ItemTaxCountry','ItemMinimumQuantity')
+ CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Item' NOT NULL;
diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js
index bae0997bb..95de3cc50 100644
--- a/modules/item/back/methods/item/specs/getBalance.spec.js
+++ b/modules/item/back/methods/item/specs/getBalance.spec.js
@@ -61,7 +61,7 @@ describe('item getBalance()', () => {
const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options);
expect(firstItemBalance[9].claimFk).toEqual(null);
- expect(secondItemBalance[7].claimFk).toEqual(2);
+ expect(secondItemBalance[7].claimFk).toEqual(1);
await tx.rollback();
} catch (e) {
diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json
index 2d06e1ada..5dbe4d62a 100644
--- a/modules/item/back/model-config.json
+++ b/modules/item/back/model-config.json
@@ -32,6 +32,9 @@
"ItemLog": {
"dataSource": "vn"
},
+ "ItemMinimumQuantity": {
+ "dataSource": "vn"
+ },
"ItemPackingType": {
"dataSource": "vn"
},
diff --git a/modules/item/back/models/item-minimum-quantity.json b/modules/item/back/models/item-minimum-quantity.json
new file mode 100644
index 000000000..74eac39fc
--- /dev/null
+++ b/modules/item/back/models/item-minimum-quantity.json
@@ -0,0 +1,63 @@
+{
+ "name": "ItemMinimumQuantity",
+ "base": "VnModel",
+ "options": {
+ "mysql": {
+ "table": "itemMinimumQuantity"
+ }
+ },
+ "mixins": {
+ "Loggable": true
+ },
+ "properties": {
+ "id": {
+ "type": "number",
+ "id": true,
+ "description": "Id"
+ },
+ "itemFk": {
+ "type": "number",
+ "required": true
+ },
+ "quantity": {
+ "type": "number",
+ "required": true
+ },
+ "started": {
+ "type": "date",
+ "required": true
+ },
+ "ended": {
+ "type": "date"
+ },
+ "warehouseFk": {
+ "type": "number"
+ },
+ "created": {
+ "type": "date"
+ },
+ "editorFk": {
+ "type": "number"
+ }
+ },
+ "relations": {
+ "item": {
+ "type": "belongsTo",
+ "model": "Item",
+ "foreignKey": "itemFk"
+ },
+ "warehouse": {
+ "type": "belongsTo",
+ "model": "Warehouse",
+ "foreignKey": "warehouseFk"
+ }
+ },
+ "acls": [
+ {
+ "accessType": "READ",
+ "principalType": "ROLE",
+ "principalId": "buyer",
+ "permission": "ALLOW"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json
index 10cff3e04..eda56e938 100644
--- a/modules/item/back/models/item.json
+++ b/modules/item/back/models/item.json
@@ -152,10 +152,6 @@
"columnName": "doPhoto"
}
},
- "minQuantity": {
- "type": "number",
- "description": "Min quantity"
- },
"photoMotivation": {
"type": "string"
}
diff --git a/modules/item/back/models/specs/itemMinimumQuantity.spec.js b/modules/item/back/models/specs/itemMinimumQuantity.spec.js
new file mode 100644
index 000000000..072a80f94
--- /dev/null
+++ b/modules/item/back/models/specs/itemMinimumQuantity.spec.js
@@ -0,0 +1,101 @@
+const {models} = require('vn-loopback/server/server');
+
+describe('itemMinimumQuantity model', () => {
+ const itemFk = 5;
+ const warehouseFk = 60;
+
+ beforeAll(async() => {
+ await models.ItemMinimumQuantity.destroyAll({where: {itemFk: itemFk}});
+ });
+
+ describe('CRUD operations', () => {
+ it('should create a new itemMinimumQuantity record', async() => {
+ const newRecord = {
+ itemFk: itemFk,
+ quantity: 100,
+ started: Date.vnNew(),
+ ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 1)),
+ warehouseFk: warehouseFk
+ };
+
+ const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
+
+ expect(createdRecord).toBeDefined();
+ expect(createdRecord.quantity).toEqual(newRecord.quantity);
+ });
+
+ it('should read an existing itemMinimumQuantity record', async() => {
+ const newRecord = {
+ itemFk: itemFk,
+ quantity: 100,
+ started: Date.vnNew(),
+ ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 2)),
+ warehouseFk: warehouseFk
+ };
+
+ await models.ItemMinimumQuantity.create(newRecord);
+
+ const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
+
+ expect(existingRecord).toBeDefined();
+ expect(existingRecord.itemFk).toEqual(itemFk);
+ });
+
+ it('should update an existing itemMinimumQuantity record', async() => {
+ const newRecord = {
+ itemFk: itemFk,
+ quantity: 100,
+ started: Date.vnNew(),
+ ended: new Date(Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 3)),
+ warehouseFk: warehouseFk
+ };
+
+ await models.ItemMinimumQuantity.create(newRecord);
+
+ const newQuantity = 150;
+ const existingRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
+ existingRecord.quantity = newQuantity;
+
+ await existingRecord.save();
+ const updatedRecord = await models.ItemMinimumQuantity.findOne({where: {itemFk: itemFk}});
+
+ expect(updatedRecord.quantity).toEqual(newQuantity);
+ });
+ });
+
+ describe('validation and constraints', () => {
+ it('should enforce unique constraint on itemFk, started, ended, and warehouseFk', async() => {
+ const newRecord = {
+ itemFk: itemFk,
+ quantity: 100,
+ started: Date.vnNew(),
+ ended: Date.vnNew().setFullYear(Date.vnNew().getFullYear() + 5),
+ warehouseFk: warehouseFk
+ };
+
+ try {
+ await models.ItemMinimumQuantity.create(newRecord);
+ await models.ItemMinimumQuantity.create(newRecord);
+ } catch (e) {
+ expect(e).toBeDefined();
+ expect(e.code).toContain('ER_DUP_ENTRY');
+ }
+ });
+
+ it('should allow null values for ended and warehouseFk', async() => {
+ const newRecord = {
+ itemFk: itemFk,
+ quantity: 100,
+ started: Date.vnNew(),
+ ended: null,
+ warehouseFk: null
+ };
+
+ const createdRecord = await models.ItemMinimumQuantity.create(newRecord);
+
+ expect(createdRecord).toBeDefined();
+ expect(createdRecord.ended).toBeNull();
+ expect(createdRecord.warehouseFk).toBeNull();
+ });
+ });
+});
diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html
index 13c671d29..0e4cfc955 100644
--- a/modules/item/front/summary/index.html
+++ b/modules/item/front/summary/index.html
@@ -128,9 +128,6 @@
-
-
diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js
index ab1d7784e..27048457c 100644
--- a/modules/order/back/methods/order/catalogFilter.js
+++ b/modules/order/back/methods/order/catalogFilter.js
@@ -119,7 +119,7 @@ module.exports = Self => {
w.firstName,
tci.priceKg,
ink.hex,
- i.minQuantity
+ tci.minQuantity
FROM tmp.ticketCalculateItem tci
JOIN vn.item i ON i.id = tci.itemFk
JOIN vn.itemType it ON it.id = i.typeFk
@@ -158,21 +158,19 @@ module.exports = Self => {
// Apply item prices
const pricesIndex = stmts.push(
- `SELECT
- tcp.itemFk,
+ `SELECT tcp.itemFk,
tcp.grouping,
tcp.price,
tcp.rate,
tcp.warehouseFk,
tcp.priceKg,
- w.name AS warehouse
+ w.name warehouse
FROM tmp.ticketComponentPrice tcp
JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1;
// Get tags from all items
const itemTagsIndex = stmts.push(
- `SELECT
- t.id,
+ `SELECT t.id,
t.name,
t.isFree,
t.sourceTable,
diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html
index 081ce05a0..b047e1e6a 100644
--- a/modules/order/front/catalog-view/index.html
+++ b/modules/order/front/catalog-view/index.html
@@ -37,18 +37,18 @@
value="{{::item.value7}}">
-
-
-
-
-
- {{::item.minQuantity}}
-
+
+
+
+
+
+ {{::item.minQuantity}}
+