diff --git a/db/changes/240601/01-updateACLItemLack.sql b/db/changes/240601/01-updateACLItemLack.sql new file mode 100644 index 000000000..13521325f --- /dev/null +++ b/db/changes/240601/01-updateACLItemLack.sql @@ -0,0 +1,3 @@ +-- Auto-generated SQL script #202401191358 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Ticket','itemLack','READ','ALLOW','ROLE','employee'); diff --git a/db/changes/240601/01-updateProcedureGetItemLack.sql b/db/changes/240601/01-updateProcedureGetItemLack.sql new file mode 100644 index 000000000..a5cb41b3a --- /dev/null +++ b/db/changes/240601/01-updateProcedureGetItemLack.sql @@ -0,0 +1,65 @@ +DROP PROCEDURE IF EXISTS vn.item_getLack; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getLack`(IN vForce BOOLEAN, IN vDays INT, IN vSearch VARCHAR(500)) +BEGIN +/** + * Calcula una tabla con el máximo negativo visible para cada producto y almacen + * + * @param vForce Fuerza el recalculo del stock + * @param vDays Numero de dias a considerar + * @param vSearch Filtro items +**/ + + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; + CALL `cache`.stock_refresh(vForce); + CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL); + CALL item_getMinETD(); + CALL item_zoneClosure(); + + IF vIsSearch THEN + SET vSearch =' '; + END IF; + + SELECT i.id itemFk, + i.longName, + w.id warehouseFk, + p.`name` producer, + i.`size`, + i.category, + w.name warehouse, + SUM(IFNULL(sub.amount,0)) lack, + i.inkFk, + IFNULL(im.timed, util.midnight()) timed, + IFNULL(izc.timed, util.midnight()) minTimed + FROM (SELECT item_id, + warehouse_id, + amount + FROM cache.stock + WHERE amount > 0 + UNION ALL + SELECT itemFk, + warehouseFk, + amount + FROM tmp.itemMinacum + ) sub + JOIN warehouse w ON w.id = sub.warehouse_id + JOIN item i ON i.id = sub.item_id + LEFT JOIN producer p ON p.id = i.producerFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id + LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id + WHERE w.isForTicket + AND ic.display + AND it.code != 'GEN' + GROUP BY i.id, w.id + HAVING lack < 0; + + DROP TEMPORARY TABLE tmp.itemMinacum; + DROP TEMPORARY TABLE tmp.itemMinETD; + DROP TEMPORARY TABLE tmp.itemZoneClosure; +END +$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index ba513ee15..6533cf273 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -3043,6 +3043,12 @@ INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) (4, 1103, 4, 32), (13, 1101, 1, NULL), (14, 1101, 4, 27); --- Auto-generated SQL script #202401191358 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Ticket','itemLack','READ','ALLOW','ROLE','employee'); +INSERT INTO cache.stock (warehouse_id,item_id,amount) VALUES + (60,1,25), + (13,1,-20), + (4,1,-1000); + -- Auto-generated SQL script #202401220930 +UPDATE vn.warehouse + SET isForTicket=1 + WHERE id=2; +