diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4fbe16f33..595027b09 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1505,32 +1505,32 @@ INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); -INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) - VALUES (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150.00, 2000, 'second travel', 2, 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), - (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10), - (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4), - (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); +INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`, `daysInForward`) + VALUES (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1, NULL), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150.00, 2000, 'second travel', 2, 2, 2, NULL), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3, NULL), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4, NULL), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5, NULL), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6, NULL), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7, 2), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10, NULL), + (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10, 2), + (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, NULL), + (12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4, NULL); -INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) +INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `evaNotes`) VALUES - (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, 0, ''), - (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 0, 'observation two'), - (3, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'IN2003', 'Movement 3', 0, 0, 'observation three'), - (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 0, 'observation four'), - (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'), - (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'), - (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), - (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), - (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''), - (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 0, 0, ''); + (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, ''), + (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 'observation two'), + (3, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'IN2003', 'Movement 3', 0, 'observation three'), + (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 'observation four'), + (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 'observation five'), + (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 'observation six'), + (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 'observation seven'), + (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1,''), + (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, ''), + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, ''), + (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 0, ''); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) VALUES (2, 4, 1); diff --git a/db/routines/cache/procedures/availableNoRaids_refresh.sql b/db/routines/cache/procedures/availableNoRaids_refresh.sql index 37715d270..efbbf6a13 100644 --- a/db/routines/cache/procedures/availableNoRaids_refresh.sql +++ b/db/routines/cache/procedures/availableNoRaids_refresh.sql @@ -53,7 +53,7 @@ proc: BEGIN WHERE t.landed BETWEEN vInventoryDate AND vStartDate AND t.warehouseInFk = vWarehouse AND s.name != 'INVENTARIO' - AND NOT e.isRaid + AND NOT t.daysInForward GROUP BY b.itemFk ) c JOIN vn.item i ON i.id = c.itemFk diff --git a/db/routines/edi/triggers/supplyResponse_afterUpdate.sql b/db/routines/edi/triggers/supplyResponse_afterUpdate.sql index 389ef9f1c..28a8c9466 100644 --- a/db/routines/edi/triggers/supplyResponse_afterUpdate.sql +++ b/db/routines/edi/triggers/supplyResponse_afterUpdate.sql @@ -6,16 +6,16 @@ BEGIN UPDATE vn.buy b JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk JOIN vn.item i ON i.id = b.itemFk JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID SET b.quantity = NEW.NumberOfItemsPerCask * NEW.NumberOfUnits, b.stickers = NEW.NumberOfUnits WHERE i.supplyResponseFk = NEW.ID AND am.name = 'LOGIFLORA' - AND e.isRaid + AND tr.daysInForward AND tr.landed >= util.VN_CURDATE(); - + END$$ DELIMITER ; diff --git a/db/routines/hedera/procedures/item_getVisible.sql b/db/routines/hedera/procedures/item_getVisible.sql index 2f4ef32ab..365161bdf 100644 --- a/db/routines/hedera/procedures/item_getVisible.sql +++ b/db/routines/hedera/procedures/item_getVisible.sql @@ -59,7 +59,7 @@ BEGIN JOIN vn.travel t ON t.id = e.travelFk WHERE t.landed BETWEEN vDateInv AND vDate AND t.warehouseInFk = vWarehouse - AND NOT e.isRaid + AND NOT t.daysInForward UNION ALL SELECT b.itemFk, -b.quantity FROM vn.buy b @@ -67,7 +67,7 @@ BEGIN JOIN vn.travel t ON t.id = e.travelFk WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() AND t.warehouseOutFk = vWarehouse - AND NOT e.isRaid + AND NOT t.daysInForward AND t.isDelivered UNION ALL SELECT m.itemFk, -m.quantity diff --git a/db/routines/stock/procedures/log_refreshBuy.sql b/db/routines/stock/procedures/log_refreshBuy.sql index 488c00a28..d8e727f17 100644 --- a/db/routines/stock/procedures/log_refreshBuy.sql +++ b/db/routines/stock/procedures/log_refreshBuy.sql @@ -11,7 +11,7 @@ BEGIN e.id entryFk, t.id travelFk, b.itemFk, - e.isRaid, + t.daysInForward, ADDTIME(t.shipped, IFNULL(t.shipmentHour, '00:00:00')) shipped, t.warehouseOutFk, @@ -50,7 +50,7 @@ BEGIN itemFk, TIMESTAMPADD(DAY, life, @dated), quantity, - IF(isIn, isReceived, isDelivered) AND !isRaid + IF(isIn, isReceived, isDelivered) AND NOT daysInForward FROM tValues WHERE isIn OR !lessThanInventory; @@ -65,7 +65,7 @@ BEGIN itemFk, created, quantity, - IF(isIn, isDelivered, isReceived) AND !isRaid + IF(isIn, isDelivered, isReceived) AND NOT daysInForward FROM tValues WHERE !isIn OR !lessThanInventory; diff --git a/db/routines/vn/events/raidUpdate.sql b/db/routines/vn/events/raidUpdate.sql deleted file mode 100644 index c0c6f03c5..000000000 --- a/db/routines/vn/events/raidUpdate.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`raidUpdate` - ON SCHEDULE EVERY 1 DAY - STARTS '2017-12-29 00:05:00.000' - ON COMPLETION PRESERVE - ENABLE -DO CALL raidUpdate$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/absoluteInventoryHistory.sql b/db/routines/vn/procedures/absoluteInventoryHistory.sql index d2a2029f0..3ea8cf4de 100644 --- a/db/routines/vn/procedures/absoluteInventoryHistory.sql +++ b/db/routines/vn/procedures/absoluteInventoryHistory.sql @@ -39,7 +39,7 @@ BEGIN AND vWarehouseFk IN (tr.warehouseInFk, 0) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid + AND NOT tr.daysInForward UNION ALL SELECT tr.shipped, NULL, @@ -58,7 +58,7 @@ BEGIN AND s.id <> (SELECT supplierFk FROM inventoryConfig) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid + AND NOT tr.daysInForward UNION ALL SELECT t.shipped, NULL, @@ -81,7 +81,7 @@ BEGIN FROM tHistoricalPast WHERE `date` < vDate; - SELECT p1.*, NULL v_virtual + SELECT p1.*, NULL v_virtual FROM ( SELECT vDate `date`, vCalculatedInventory input, @@ -96,7 +96,7 @@ BEGIN FROM tHistoricalPast WHERE `date` >= vDate ) p1; - + DROP TEMPORARY TABLE tHistoricalPast; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/available_traslate.sql b/db/routines/vn/procedures/available_traslate.sql index 03eb376ab..513f58e36 100644 --- a/db/routines/vn/procedures/available_traslate.sql +++ b/db/routines/vn/procedures/available_traslate.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`available_traslate`( vWarehouseShipment INT) proc: BEGIN /** - * Calcular la disponibilidad dependiendo del almacen + * Calcular la disponibilidad dependiendo del almacen * de origen y destino según la fecha. * * @param vWarehouseLanding Almacén de llegada @@ -42,10 +42,10 @@ proc: BEGIN WHERE t.landed BETWEEN vDatedInventory AND vDatedFrom AND t.warehouseInFk = vWarehouseLanding AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid + AND NOT t.daysInForward GROUP BY c.itemFk; - -- Tabla con el ultimo dia de last_buy para cada producto + -- Tabla con el ultimo dia de last_buy para cada producto -- que hace un replace de la anterior. CALL buy_getUltimate (NULL, vWarehouseShipment, util.VN_CURDATE()); @@ -57,7 +57,7 @@ proc: BEGIN JOIN travel tr ON tr.id = e.travelFk LEFT JOIN tItemRange i ON t.itemFk = i.itemFk WHERE t.warehouseFk = vWarehouseShipment - AND NOT e.isRaid + AND NOT tr.daysInForward ON DUPLICATE KEY UPDATE tItemRange.dated = GREATEST(tItemRange.dated, tr.landed); @@ -94,7 +94,7 @@ proc: BEGIN JOIN tItemRangeLive ir ON ir.itemFk = b.itemFk WHERE NOT e.isExcludedFromAvailable AND b.quantity <> 0 - AND NOT e.isRaid + AND NOT t.daysInForward AND t.warehouseInFk = vWarehouseLanding AND t.landed >= vDatedFrom AND (ir.dated IS NULL OR t.landed <= ir.dated) @@ -135,4 +135,4 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.itemList, tItemRange, tItemRangeLive; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/clean_logiflora.sql b/db/routines/vn/procedures/clean_logiflora.sql index fd645a158..ac119631d 100644 --- a/db/routines/vn/procedures/clean_logiflora.sql +++ b/db/routines/vn/procedures/clean_logiflora.sql @@ -28,7 +28,7 @@ BEGIN JOIN agencyMode am ON am.id = tr.agencyModeFk WHERE NOT b.quantity AND am.code = 'logiflora' - AND e.isRaid; + AND tr.daysInForward; START TRANSACTION; diff --git a/db/routines/vn/procedures/entry_cloneHeader.sql b/db/routines/vn/procedures/entry_cloneHeader.sql index c988cc592..f83c5c501 100644 --- a/db/routines/vn/procedures/entry_cloneHeader.sql +++ b/db/routines/vn/procedures/entry_cloneHeader.sql @@ -17,7 +17,6 @@ BEGIN supplierFk, dated, isExcludedFromAvailable, - isRaid, commission, currencyFk, companyFk, @@ -28,7 +27,6 @@ BEGIN supplierFk, dated, isExcludedFromAvailable, - isRaid, commission, currencyFk, companyFk, diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index c83556408..9527e0bf2 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_getTransfer`( BEGIN /** * Retorna los artículos trasladables a partir de una entrada. - * + * * @param vSelf Id de entrada */ DECLARE vDateShipped DATE; @@ -166,7 +166,7 @@ BEGIN LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id LEFT JOIN buy b3 ON b3.id = bufi.buyFk WHERE ic.display - AND NOT e.isRaid + AND NOT tr.daysInForward AND (ti.visible OR ti.available) ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name; diff --git a/db/routines/vn/procedures/inventoryMake.sql b/db/routines/vn/procedures/inventoryMake.sql index 91065771a..65dceef3d 100644 --- a/db/routines/vn/procedures/inventoryMake.sql +++ b/db/routines/vn/procedures/inventoryMake.sql @@ -137,7 +137,7 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk WHERE tr.warehouseInFk = vWarehouseFk AND tr.landed BETWEEN vDateLastInventory AND vDateYesterday - AND NOT isRaid + AND NOT tr.daysInForward GROUP BY b.itemFk; -- Transfers @@ -150,7 +150,7 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk WHERE tr.warehouseOutFk = vWarehouseFk AND tr.shipped BETWEEN vDateLastInventory AND vDateYesterday - AND NOT isRaid + AND NOT tr.daysInForward GROUP BY b.itemFk ) sub ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity, 0) + sub.quantityOut; diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 4aa589d19..260f0a527 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -50,16 +50,16 @@ BEGIN 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') WHERE tr.landed >= vDateInventory AND tr.warehouseInFk = vWarehouseFk - AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) + AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid + AND NOT tr.daysInForward ), entriesOut AS ( SELECT 'entry', @@ -95,7 +95,7 @@ BEGIN AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT w.isFeedStock - AND NOT e.isRaid + AND NOT tr.daysInForward ), sales AS ( WITH itemSales AS ( @@ -147,10 +147,10 @@ BEGIN NULL FROM itemSales s LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED' - LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk + LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk AND stk.stateFk = stPrep.id GROUP BY s.saleFk - ), + ), orders AS ( SELECT 'order' originType, o.id originId, @@ -215,9 +215,9 @@ BEGIN t.`in` invalue, t.`out`, @a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance, - @currentLineFk := IF (@shipped < util.VN_CURDATE() + @currentLineFk := IF (@shipped < util.VN_CURDATE() OR (@shipped = util.VN_CURDATE() AND (t.isPicked OR a.`code` >= 'ON_PREPARATION')), - t.lineFk, + t.lineFk, @currentLineFk) lastPreparedLineFk, t.isTicket, t.lineFk, @@ -254,21 +254,21 @@ BEGIN UNION ALL SELECT originType, originId, - shipped, - alertlevel, - stateName, + shipped, + alertlevel, + stateName, reference, entityType, - entityId, + entityId, entityName, - `in`, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), - 0, - isTicket, - lineFk, - isPicked, - clientType, + `in`, + `out`, + @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), + 0, + isTicket, + lineFk, + isPicked, + clientType, claimFk, `order` FROM tItemDiary diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index 85474fc3f..8a42bd737 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -63,7 +63,7 @@ BEGIN AND NOT e.isExcludedFromAvailable AND b.quantity <> 0 AND (vItemFk IS NULL OR b.itemFk = vItemFk) - AND NOT e.isRaid + AND NOT t.daysInForward UNION ALL SELECT r.itemFk, r.shipment, diff --git a/db/routines/vn/procedures/item_multipleBuyByDate.sql b/db/routines/vn/procedures/item_multipleBuyByDate.sql index 115202895..7bd809312 100644 --- a/db/routines/vn/procedures/item_multipleBuyByDate.sql +++ b/db/routines/vn/procedures/item_multipleBuyByDate.sql @@ -17,22 +17,22 @@ BEGIN ALTER TABLE tmp.itemInventory ADD `buy_date` datetime NOT NULL; - + CREATE OR REPLACE TEMPORARY TABLE lastBuyScope SELECT i.id, MAX(t.landed) lastLanded - FROM item i - JOIN buy b ON b.itemFk = i.id + FROM item i + JOIN buy b ON b.itemFk = i.id JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk + JOIN travel t ON t.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk JOIN warehouse w ON w.id = t.warehouseInFk WHERE t.landed BETWEEN (vDated + INTERVAL - vLastBuyScope DAY) AND vDated AND NOT s.name = 'INVENTARIO' AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) AND w.isComparative - AND NOT e.isRaid + AND NOT t.daysInForward GROUP BY i.id; - + UPDATE tmp.itemInventory y JOIN lastBuyScope lbs ON lbs.id = y.id SET y.buy_date = lbs.lastLanded; diff --git a/db/routines/vn/procedures/item_valuateInventory.sql b/db/routines/vn/procedures/item_valuateInventory.sql index 5642ba812..b6d687960 100644 --- a/db/routines/vn/procedures/item_valuateInventory.sql +++ b/db/routines/vn/procedures/item_valuateInventory.sql @@ -25,7 +25,7 @@ BEGIN LIMIT 1; SET vHasNotInventory = (vInventoried IS NULL); - + IF vHasNotInventory THEN SELECT landed INTO vInventoryClone FROM travel tr @@ -50,7 +50,7 @@ BEGIN PRIMARY KEY (warehouseInventory, itemFk) USING HASH ) ENGINE = MEMORY; - + -- Inventario inicial IF vHasNotInventory THEN INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) @@ -109,7 +109,7 @@ BEGIN JOIN warehouse w ON w.id = tr.warehouseInFk WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE) - AND NOT e.isRaid + AND NOT tr.daysInForward AND w.valuatedInventory AND t.isInventory AND e.supplierFk <> vInventorySupplierFk @@ -131,7 +131,7 @@ BEGIN JOIN itemCategory ic ON ic.id = t.categoryFk JOIN warehouse w ON w.id = tr.warehouseOutFk WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd - AND NOT e.isRaid + AND NOT tr.daysInForward AND w.valuatedInventory AND t.isInventory AND (t.id = vItemTypeFk OR vItemTypeFk IS NULL) @@ -159,7 +159,7 @@ BEGIN ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 1, -1); -- Volver a poner lo que esta aun en las estanterias - IF vDated = util.VN_CURDATE() THEN + IF vDated = util.VN_CURDATE() THEN INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) SELECT w.id, s.itemFk, @@ -196,14 +196,14 @@ BEGIN JOIN warehouse wIn ON wIn.id = tr.warehouseInFk JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk WHERE vDated >= tr.shipped AND vDated < tr.landed - AND NOT isRaid + AND NOT tr.daysInForward AND wIn.valuatedInventory AND t.isInventory AND e.isConfirmed AND (t.id = vItemTypeFk OR vItemTypeFk IS NULL) AND (ic.id = vItemCategoryFk OR vItemCategoryFk IS NULL) ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); - + CALL buy_getUltimate (NULL, NULL, vDateDayEnd); DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity; @@ -233,7 +233,7 @@ BEGIN JOIN warehouse w ON w.id = warehouseFk JOIN item i ON i.id = ti.itemFk JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN itemCategory ic ON ic.id = tp.categoryFk WHERE w.valuatedInventory AND ti.total > 0; diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index c051706b7..6b26e456f 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -1,173 +1,173 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`multipleInventory`( - vDate DATE, - vWarehouseFk TINYINT, - vMaxDays TINYINT -) -proc: BEGIN - DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; - DECLARE vDateFrom DATE DEFAULT vDate; - DECLARE vDateTo DATETIME; - DECLARE vDateToTomorrow DATETIME; - DECLARE vDefaultDayRange INT; - DECLARE vCalcFk INT; - - IF vDate < util.VN_CURDATE() THEN - LEAVE proc; - END IF; - - IF vDate = util.VN_CURDATE() THEN - SELECT inventoried INTO vDateFrom - FROM config; - END IF; - - SELECT defaultDayRange INTO vDefaultDayRange - FROM comparativeConfig; - - SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; - SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; - - ALTER TABLE tmp.itemInventory - ADD `avalaible` INT NOT NULL, - ADD `sd` INT NOT NULL, - ADD `rest` INT NOT NULL, - ADD `expected` INT NOT NULL, - ADD `inventory` INT NOT NULL, - ADD `visible` INT NOT NULL, - ADD `life` TINYINT NOT NULL DEFAULT '0'; - - -- Calculo del inventario - CREATE OR REPLACE TEMPORARY TABLE tItemInventoryCalc - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT itemFk, - SUM(quantity) quantity - FROM ( - SELECT s.itemFk, - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) - 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 BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - 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 BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub - GROUP BY itemFk; - - -- Cálculo del visible - CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - - 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 - LEFT JOIN tItemInventoryCalc iic ON iic.itemFk = it.id - LEFT JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id - SET it.inventory = iic.quantity, - it.visible = ivc.visible, - it.avalaible = iic.quantity, - it.sd = iic.quantity; - - -- Calculo del disponible - CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT sub.itemFk, - vWarehouseFk warehouseFk, - sub.dated, - SUM(sub.quantity) quantity - FROM ( - SELECT s.itemFk, - DATE(t.shipped) dated, - - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, t.landed, 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 BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, t.shipped, - 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 BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub - GROUP BY sub.itemFk, sub.dated; - - CALL item_getAtp(vDate); - CALL travel_upcomingArrivals(vWarehouseFk, vDate); - - CREATE OR REPLACE TEMPORARY TABLE tItemAvailableCalc - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT it.itemFk, - SUM(it.quantity) quantity, - im.quantity minQuantity - FROM tmp.itemCalc it - JOIN tmp.itemAtp im ON im.itemFk = it.itemFk - JOIN item i ON i.id = it.itemFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN tmp.itemTravel t ON t.wh = o.warehouseFk - WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, - t.landing, - vDateToTomorrow) - GROUP BY it.itemFk; - - UPDATE tmp.itemInventory it - JOIN tItemAvailableCalc iac ON iac.itemFk = it.id - SET it.avalaible = IF(iac.minQuantity > 0, - it.avalaible, - it.avalaible + iac.minQuantity), - it.sd = it.inventory + iac.quantity; - - DROP TEMPORARY TABLE - tmp.itemTravel, - tmp.itemCalc, - tmp.itemAtp, - tItemInventoryCalc, - tItemVisibleCalc, - tItemAvailableCalc; -END$$ -DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`multipleInventory`( + vDate DATE, + vWarehouseFk TINYINT, + vMaxDays TINYINT +) +proc: BEGIN + DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; + DECLARE vDateFrom DATE DEFAULT vDate; + DECLARE vDateTo DATETIME; + DECLARE vDateToTomorrow DATETIME; + DECLARE vDefaultDayRange INT; + DECLARE vCalcFk INT; + + IF vDate < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + IF vDate = util.VN_CURDATE() THEN + SELECT inventoried INTO vDateFrom + FROM config; + END IF; + + SELECT defaultDayRange INTO vDefaultDayRange + FROM comparativeConfig; + + SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; + SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; + + ALTER TABLE tmp.itemInventory + ADD `avalaible` INT NOT NULL, + ADD `sd` INT NOT NULL, + ADD `rest` INT NOT NULL, + ADD `expected` INT NOT NULL, + ADD `inventory` INT NOT NULL, + ADD `visible` INT NOT NULL, + ADD `life` TINYINT NOT NULL DEFAULT '0'; + + -- Calculo del inventario + CREATE OR REPLACE TEMPORARY TABLE tItemInventoryCalc + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT itemFk, + SUM(quantity) quantity + FROM ( + SELECT s.itemFk, - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + 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 BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT t.daysInForward + 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 BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT t.daysInForward + ) sub + GROUP BY itemFk; + + -- Cálculo del visible + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); + + 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 + LEFT JOIN tItemInventoryCalc iic ON iic.itemFk = it.id + LEFT JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id + SET it.inventory = iic.quantity, + it.visible = ivc.visible, + it.avalaible = iic.quantity, + it.sd = iic.quantity; + + -- Calculo del disponible + CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT sub.itemFk, + vWarehouseFk warehouseFk, + sub.dated, + SUM(sub.quantity) quantity + FROM ( + SELECT s.itemFk, + DATE(t.shipped) dated, + - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, t.landed, 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 BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT t.daysInForward + UNION ALL + SELECT b.itemFk, t.shipped, - 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 BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT t.daysInForward + ) sub + GROUP BY sub.itemFk, sub.dated; + + CALL item_getAtp(vDate); + CALL travel_upcomingArrivals(vWarehouseFk, vDate); + + CREATE OR REPLACE TEMPORARY TABLE tItemAvailableCalc + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT it.itemFk, + SUM(it.quantity) quantity, + im.quantity minQuantity + FROM tmp.itemCalc it + JOIN tmp.itemAtp im ON im.itemFk = it.itemFk + JOIN item i ON i.id = it.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN tmp.itemTravel t ON t.wh = o.warehouseFk + WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, + t.landing, + vDateToTomorrow) + GROUP BY it.itemFk; + + UPDATE tmp.itemInventory it + JOIN tItemAvailableCalc iac ON iac.itemFk = it.id + SET it.avalaible = IF(iac.minQuantity > 0, + it.avalaible, + it.avalaible + iac.minQuantity), + it.sd = it.inventory + iac.quantity; + + DROP TEMPORARY TABLE + tmp.itemTravel, + tmp.itemCalc, + tmp.itemAtp, + tItemInventoryCalc, + tItemVisibleCalc, + tItemAvailableCalc; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/raidUpdate.sql b/db/routines/vn/procedures/raidUpdate.sql deleted file mode 100644 index 71352868e..000000000 --- a/db/routines/vn/procedures/raidUpdate.sql +++ /dev/null @@ -1,31 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`raidUpdate`() -BEGIN -/** - * Actualiza el travel de las entradas de redadas - */ - UPDATE entry e - JOIN entryVirtual ev ON ev.entryFk = e.id - JOIN travel t ON t.id = e.travelFk - JOIN ( - SELECT * - FROM ( - SELECT t.id, t.landed, tt.warehouseInFk, tt.warehouseOutFk - FROM travel t - JOIN ( - SELECT t.warehouseInFk, t.warehouseOutFk - FROM entryVirtual ev - JOIN entry e ON e.id = ev.entryFk - JOIN travel t ON t.id = e.travelFk - GROUP BY t.warehouseInFk, t.warehouseOutFk - ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk - WHERE shipped > util.VN_CURDATE() AND NOT isDelivered - ORDER BY t.landed - LIMIT 10000000000000000000 - ) t - GROUP BY t.warehouseInFk, t.warehouseOutFk - ) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk - SET e.travelFk = t.id; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/travelVolume_get.sql b/db/routines/vn/procedures/travelVolume_get.sql index 99c0acbb8..bb98cacdf 100644 --- a/db/routines/vn/procedures/travelVolume_get.sql +++ b/db/routines/vn/procedures/travelVolume_get.sql @@ -10,7 +10,7 @@ BEGIN JOIN vn.entry e ON e.travelFk = tr.id JOIN vn.buy b ON b.entryFk = e.id WHERE tr.landed BETWEEN vFromDated AND vToDated - AND e.isRaid = FALSE + AND NOT tr.daysInForward AND tr.warehouseInFk = vWarehouseFk GROUP BY tr.landed , a.name ; END$$ diff --git a/db/routines/vn/procedures/travel_moveRaids.sql b/db/routines/vn/procedures/travel_moveRaids.sql index 95e02ec55..aa554a1a0 100644 --- a/db/routines/vn/procedures/travel_moveRaids.sql +++ b/db/routines/vn/procedures/travel_moveRaids.sql @@ -1,72 +1,68 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`travel_moveRaids`() BEGIN - -/* - * Desplaza al dia siguiente los travels que contengan redadas y avisa a los compradores +/** + * Desplaza los travels en el futuro y avisa a los compradores * */ DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWorkerName VARCHAR(50); - DECLARE vRaid TEXT; - DECLARE vWorker VARCHAR(50) DEFAULT ''; + DECLARE vBuyerEmail VARCHAR(40); + DECLARE vTravelLink TEXT; DECLARE vMailBody TEXT DEFAULT ''; DECLARE vCur CURSOR FOR - SELECT GROUP_CONCAT( DISTINCT CONCAT('https://salix.verdnatura.es/#!/travel/', ttr.id, '/summary ') ORDER BY ttr.id SEPARATOR '\n\r'), - u.name - FROM tmp.travel ttr - JOIN entry e ON e.travelFk = ttr.id + SELECT GROUP_CONCAT(DISTINCT + CONCAT('https://salix.verdnatura.es/#!/travel/', + ttm.travelFk, + '/summary ') + ORDER BY ttm.travelFk SEPARATOR '\n\r') travelLink, + CONCAT(u.name, '@verdnatura.es') buyerEmail + FROM tTravelToMove ttm + JOIN entry e ON e.travelFk = ttm.travelFk JOIN buy b ON b.entryFk = e.id JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk JOIN account.user u ON u.id = it.workerFk GROUP BY u.name; - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; - - DROP TEMPORARY TABLE IF EXISTS tmp.travel; - CREATE TEMPORARY TABLE tmp.travel - SELECT tr.id,tr.landed - FROM travel tr - JOIN entry e ON e.travelFk = tr.id - WHERE tr.landed = util.tomorrow() - AND e.isRaid - GROUP BY tr.id; + + CREATE OR REPLACE TEMPORARY TABLE tTravelToMove + SELECT id travelFk, + util.VN_CURDATE() + INTERVAL daysInForward DAY newLanded + FROM travel + WHERE daysInForward; START TRANSACTION; UPDATE travel tr - JOIN tmp.travel ttr ON ttr.id = tr.id - SET tr.landed = TIMESTAMPADD(DAY, 1, tr.landed); + JOIN tTravelToMove ttm ON ttm.travelFk = tr.id + SET tr.landed = ttm.newLanded; OPEN vCur; l: LOOP SET vDone = FALSE; - FETCH vCur INTO vRaid, vWorkerName; + FETCH vCur INTO vTravelLink, vBuyerEmail; IF vDone THEN LEAVE l; END IF; - CALL `vn`.`mail_insert`(CONCAT(vWorkerName, '@verdnatura.es'), - 'noreply@verdnatura.es', - 'Cambio de fecha en Redadas', - CONCAT('Se ha movido las siguientes redadas: \n\r ', vRaid) - ); - + CALL `vn`.`mail_insert`( + vBuyerEmail, + 'noreply@verdnatura.es', + 'Cambio de fecha en Redadas', + CONCAT('Se ha movido los siguientes travels: \n\r ', vTravelLink)); END LOOP; CLOSE vCur; COMMIT; - DROP TEMPORARY TABLE tmp.travel; - + DROP TEMPORARY TABLE tTravelToMove; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index 8e5a326a0..3b999012f 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`entry_beforeUpdate` BEFORE UPDATE ON `entry` FOR EACH ROW BEGIN - DECLARE vIsVirtual BOOL; + DECLARE vDaysInForward INT; DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; DECLARE vTotalBuy INT; @@ -37,18 +37,20 @@ BEGIN IF NEW.travelFk IS NOT NULL THEN CALL travel_throwAwb(NEW.travelFk); END IF; - - SELECT COUNT(*) > 0 INTO vIsVirtual - FROM entryVirtual WHERE entryFk = NEW.id; + + SELECT daysInForward INTO vDaysInForward + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE entryFk = NEW.id; SELECT NOT (o.warehouseInFk <=> n.warehouseInFk) - OR NOT (o.warehouseOutFk <=> n.warehouseOutFk) + OR NOT (o.warehouseOutFk <=> n.warehouseOutFk) INTO vHasDistinctWarehouses FROM travel o, travel n WHERE o.id = OLD.travelFk AND n.id = NEW.travelFk; - IF vIsVirtual AND vHasDistinctWarehouses THEN + IF vDaysInForward AND vHasDistinctWarehouses THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses'; END IF; @@ -71,7 +73,7 @@ BEGIN SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); END IF; - IF NOT (NEW.travelFk <=> OLD.travelFk) + IF NOT (NEW.travelFk <=> OLD.travelFk) OR NOT (NEW.currencyFk <=> OLD.currencyFk) OR NOT (NEW.supplierFk <=> OLD.supplierFk) THEN diff --git a/db/routines/vn/triggers/itemType_afterDelete.sql b/db/routines/vn/triggers/itemType_afterDelete.sql new file mode 100644 index 000000000..32a1ba31c --- /dev/null +++ b/db/routines/vn/triggers/itemType_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_afterDelete` + AFTER DELETE ON `itemType` + FOR EACH ROW +BEGIN + INSERT INTO itemTypeLog + SET `action` = 'delete', + `changedModel` = 'ItemType', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemType_beforeInsert.sql b/db/routines/vn/triggers/itemType_beforeInsert.sql new file mode 100644 index 000000000..d33d8fb56 --- /dev/null +++ b/db/routines/vn/triggers/itemType_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_beforeInsert` + BEFORE INSERT ON `itemType` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemType_beforeUpdate.sql b/db/routines/vn/triggers/itemType_beforeUpdate.sql index 613ae8bfa..6a03d40d0 100644 --- a/db/routines/vn/triggers/itemType_beforeUpdate.sql +++ b/db/routines/vn/triggers/itemType_beforeUpdate.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemType_beforeUpdate` BEFORE UPDATE ON `itemType` FOR EACH ROW BEGIN + SET NEW.editorFk = account.myUser_getId(); IF NEW.itemPackingTypeFk = '' THEN SET NEW.itemPackingTypeFk = NULL; diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql index 6b6800d4f..bd485d590 100644 --- a/db/routines/vn/triggers/productionConfig_afterDelete.sql +++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`productionConfig_afterD AFTER DELETE ON `productionConfig` FOR EACH ROW BEGIN - INSERT INTO productionConfig + INSERT INTO productionConfigLog SET `action` = 'delete', `changedModel` = 'ProductionConfig', `changedModelId` = OLD.id, diff --git a/db/routines/vn/views/itemEntryIn.sql b/db/routines/vn/views/itemEntryIn.sql index 4f7855d2b..6196e9396 100644 --- a/db/routines/vn/views/itemEntryIn.sql +++ b/db/routines/vn/views/itemEntryIn.sql @@ -6,7 +6,7 @@ AS SELECT `t`.`warehouseInFk` AS `warehouseInFk`, `b`.`itemFk` AS `itemFk`, `b`.`quantity` AS `quantity`, `t`.`isReceived` AS `isReceived`, - `e`.`isRaid` AS `isVirtualStock`, + `t`.`daysInForward` AS `isVirtualStock`, `e`.`id` AS `entryFk` FROM ( ( diff --git a/db/routines/vn/views/itemEntryOut.sql b/db/routines/vn/views/itemEntryOut.sql index 1e8718c53..f18116e61 100644 --- a/db/routines/vn/views/itemEntryOut.sql +++ b/db/routines/vn/views/itemEntryOut.sql @@ -15,5 +15,5 @@ FROM ( JOIN `vn`.`travel` `t` ON(`e`.`travelFk` = `t`.`id`) ) WHERE `e`.`isExcludedFromAvailable` = 0 - AND `e`.`isRaid` = 0 + AND NOT `t`.`daysInForward` AND `b`.`quantity` <> 0 diff --git a/db/routines/vn/views/lastPurchases.sql b/db/routines/vn/views/lastPurchases.sql index 3099acd00..9dc5ec898 100644 --- a/db/routines/vn/views/lastPurchases.sql +++ b/db/routines/vn/views/lastPurchases.sql @@ -31,5 +31,5 @@ FROM ( LEFT JOIN `edi`.`ekt` `ek` ON(`ek`.`id` = `b`.`ektFk`) ) WHERE `tr`.`landed` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`() - AND `e`.`isRaid` = 0 + AND NOT `tr`.`daysInForward` AND `b`.`stickers` > 0 diff --git a/db/routines/vn2008/views/Entradas.sql b/db/routines/vn2008/views/Entradas.sql index 63fbaa728..78b73bb24 100644 --- a/db/routines/vn2008/views/Entradas.sql +++ b/db/routines/vn2008/views/Entradas.sql @@ -8,7 +8,6 @@ AS SELECT `e`.`id` AS `Id_Entrada`, `e`.`isExcludedFromAvailable` AS `Inventario`, `e`.`isConfirmed` AS `Confirmada`, `e`.`isOrdered` AS `Pedida`, - `e`.`isRaid` AS `Redada`, `e`.`commission` AS `comision`, `e`.`created` AS `odbc_date`, `e`.`evaNotes` AS `Notas_Eva`, diff --git a/db/routines/vn2008/views/Entradas_Auto.sql b/db/routines/vn2008/views/Entradas_Auto.sql deleted file mode 100644 index 5d1266965..000000000 --- a/db/routines/vn2008/views/Entradas_Auto.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Entradas_Auto` -AS SELECT `ev`.`entryFk` AS `Id_Entrada` -FROM `vn`.`entryVirtual` `ev` diff --git a/db/routines/vn2008/views/entrySource.sql b/db/routines/vn2008/views/entrySource.sql index 3a8df41bf..9c0c0f6ed 100644 --- a/db/routines/vn2008/views/entrySource.sql +++ b/db/routines/vn2008/views/entrySource.sql @@ -8,7 +8,7 @@ AS SELECT `e`.`gestDocFk` AS `gestdoc_id`, `e`.`isExcludedFromAvailable` AS `Inventario`, `e`.`isConfirmed` AS `Confirmada`, `e`.`isOrdered` AS `Pedida`, - `e`.`isRaid` AS `Redada`, + `tr`.`daysInForward` AS `daysInForward`, `e`.`evaNotes` AS `notas`, `e`.`supplierFk` AS `Id_Proveedor`, `tr`.`shipped` AS `shipment`, diff --git a/db/routines/vn2008/views/travel.sql b/db/routines/vn2008/views/travel.sql index b55dbf9b6..0e1f5acb2 100644 --- a/db/routines/vn2008/views/travel.sql +++ b/db/routines/vn2008/views/travel.sql @@ -17,5 +17,6 @@ AS SELECT `t`.`id` AS `id`, `t`.`cargoSupplierFk` AS `cargoSupplierFk`, `t`.`totalEntries` AS `totalEntries`, `t`.`appointment` AS `appointment`, - `t`.`awbFk` AS `awbFk` + `t`.`awbFk` AS `awbFk`, + `t`.`daysInForward` AS `daysInForward` FROM `vn`.`travel` `t` diff --git a/db/routines/vn2008/views/v_compres.sql b/db/routines/vn2008/views/v_compres.sql index 8bd6a4a64..324e459f6 100644 --- a/db/routines/vn2008/views/v_compres.sql +++ b/db/routines/vn2008/views/v_compres.sql @@ -28,7 +28,6 @@ AS SELECT `TP`.`Id_Tipo` AS `Familia`, `E`.`Id_Proveedor` AS `Id_Proveedor`, `E`.`Fecha` AS `Fecha`, `E`.`Confirmada` AS `Confirmada`, - `E`.`Redada` AS `Redada`, `E`.`empresa_id` AS `empresa_id`, `E`.`travel_id` AS `travel_id`, `E`.`Pedida` AS `Pedida`, @@ -85,6 +84,6 @@ FROM ( ) JOIN `vn2008`.`Cubos` `cb` ON(`cb`.`Id_Cubo` = `C`.`Id_Cubo`) ) -WHERE `W_IN`.`isFeedStock` = 0 - AND `E`.`Inventario` = 0 - AND `E`.`Redada` = 0 +WHERE NOT `W_IN`.`isFeedStock` + AND NOT `E`.`Inventario` + AND NOT `TR`.`daysInForward` diff --git a/db/versions/11297-graySalal/00-firstScript.sql b/db/versions/11297-graySalal/00-firstScript.sql new file mode 100644 index 000000000..4d4711306 --- /dev/null +++ b/db/versions/11297-graySalal/00-firstScript.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.itemType + ADD editorFk int(10) unsigned DEFAULT NULL NULL, + ADD CONSTRAINT itemType_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE TABLE `vn`.`itemTypeLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('ItemType') NOT NULL DEFAULT 'ItemType', + `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, + `summaryId` varchar(30) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `itemTypeLogUserFk_idx` (`userFk`), + KEY `itemTypeLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `itemTypeLog_originFk` (`originFk`,`creationDate`), + KEY `itemTypeLog_creationDate_IDX` (`creationDate` DESC) USING BTREE, + CONSTRAINT `itemTypeLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; + +INSERT IGNORE INTO salix.ACL (model,property,principalId) + VALUES ('ItemTypeLog','find','employee'); diff --git a/db/versions/11297-graySalal/01-firstScript.sql b/db/versions/11297-graySalal/01-firstScript.sql new file mode 100644 index 000000000..78ce1a540 --- /dev/null +++ b/db/versions/11297-graySalal/01-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.itemType + ADD CONSTRAINT itemType_itemPackingType_FK FOREIGN KEY (itemPackingTypeFk) + REFERENCES vn.itemPackingType(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/11316-chocolateErica/00-firstScript.sql b/db/versions/11316-chocolateErica/00-firstScript.sql new file mode 100644 index 000000000..9f2f15bdd --- /dev/null +++ b/db/versions/11316-chocolateErica/00-firstScript.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.travel ADD IF NOT EXISTS daysInForward INT UNSIGNED DEFAULT 0 NOT NULL + COMMENT 'Indica que sus entradas son redadas: 0 significa que no es un travel de redadas, y un valor distinto a 0 indica el número de días para el landed respecto a hoy'; + +ALTER TABLE vn.entry CHANGE isRaid isRaid_ tinyint(1) DEFAULT 0 NOT NULL COMMENT '@deprecated 2024-11-05'; + +RENAME TABLE vn.entryVirtual TO vn.entryVirtual__; +ALTER TABLE vn.entryVirtual__ COMMENT='@deprecated 2024-11-05'; diff --git a/db/versions/11325-navyEucalyptus/00-firstScript.sql b/db/versions/11325-navyEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..8bc4bd82b --- /dev/null +++ b/db/versions/11325-navyEucalyptus/00-firstScript.sql @@ -0,0 +1,7 @@ +UPDATE salix.ACL + SET property='buyLabelSupplier' + WHERE property = 'buyLabel' + AND model = 'Entry'; + +INSERT IGNORE INTO salix.ACL (model,property,principalId) + VALUES ('Entry','buyLabel','employee'); diff --git a/db/versions/11326-limeOrchid/00-firstScript.sql b/db/versions/11326-limeOrchid/00-firstScript.sql new file mode 100644 index 000000000..afec99459 --- /dev/null +++ b/db/versions/11326-limeOrchid/00-firstScript.sql @@ -0,0 +1,7 @@ +DELETE FROM vn.report + WHERE `name` = 'LabelItemQr'; + +UPDATE vn.report + SET `method` = 'Entries/{id}/{itemType}/buy-label', + `name` = 'LabelBuy' + WHERE `name` = 'LabelItemBarcode'; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a7e21960b..4ad3f76e2 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,6 +240,10 @@ "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", - "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" -} + "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", + "There are tickets for this area, delete them first": "There are tickets for this area, delete them first", + "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", + "null": "null", + "Invalid or expired verification code": "Invalid or expired verification code", + "Payment method is required": "Payment method is required" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9f01bd290..37976c0ea 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -385,5 +385,7 @@ "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero", - "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén" + "There is no company associated with that warehouse": "No hay ninguna empresa asociada a ese almacén", + "ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}", + "The web user's email already exists": "El correo del usuario web ya existe" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 23bd5cc04..0e876f89c 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -123,8 +123,8 @@ "Added sale to ticket": "J'ai ajouté la ligne suivante au ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", "Changed sale discount": "J'ai changé le rabais des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "J'ai créé la réclamation [{{claimId}}]({{{claimUrl}}}) des lignes suivantes du ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})",, - "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale price": " le prix de [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* du ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "J'ai changé {{changes}} du ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": "la quantité de {{itemId}} {{concept}} de {{oldQuantity}} ➔ {{newQuantity}}", "State": "État", "regular": "normal", @@ -362,6 +362,8 @@ "The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", - "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne" -} + "Original invoice not found": "Facture originale introuvable", + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", + "The web user's email already exists": "L'email de l'internaute existe déjà" +} \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index f85afd607..e08336273 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -124,7 +124,7 @@ "Changed sale discount": "Desconto da venda alterado no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Created claim": "Reclamação criada [{{claimId}}]({{{claimUrl}}}) no ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", "Changed sale price": "Preço da venda alterado para [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) de {{oldPrice}}€ ➔ *{{newPrice}}€* no ticket [{{ticketId}}]({{{ticketUrl}}})", - "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "Quantidade da venda alterada para {{changes}} no ticket [{{ticketId}}]({{{ticketUrl}}})", "Changes in sales": " [{{itemId}} {{concept}}]({{{itemUrl}}}) de {{oldQuantity}} ➔ *{{newQuantity}}* ", "State": "Estado", "regular": "normal", @@ -361,7 +361,9 @@ "It was not able to create the invoice": "Não foi possível criar a fatura", "The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado", "It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso", - "Original invoice not found": "Fatura original não encontrada", + "Original invoice not found": "Fatura original não encontrada", "Cannot send mail": "Não é possível enviar o email", - "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha" -} + "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", + "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", + "The web user's email already exists": "O e-mail do utilizador da web já existe." +} \ No newline at end of file diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index c8cd282e1..1d5e71fca 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -1,3 +1,4 @@ +/* eslint max-len: ["error", { "code": 150 }]*/ const UserError = require('vn-loopback/util/user-error'); module.exports = function(Self) { @@ -98,6 +99,8 @@ module.exports = function(Self) { return client; } catch (e) { if (tx) await tx.rollback(); + if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`The web user's email already exists`); + throw e; } }; diff --git a/modules/entry/back/locale/entry/en.yml b/modules/entry/back/locale/entry/en.yml index 6bc2333e6..ab8c0fd1c 100644 --- a/modules/entry/back/locale/entry/en.yml +++ b/modules/entry/back/locale/entry/en.yml @@ -9,7 +9,6 @@ columns: notes: notes isConfirmed: confirmed isVirtual: virtual - isRaid: raid commission: commission isOrdered: price3 created: created diff --git a/modules/entry/back/locale/entry/es.yml b/modules/entry/back/locale/entry/es.yml index a892b05d2..18bf1ca33 100644 --- a/modules/entry/back/locale/entry/es.yml +++ b/modules/entry/back/locale/entry/es.yml @@ -9,7 +9,6 @@ columns: notes: notas isConfirmed: confirmado isVirtual: virtual - isRaid: redada commission: comisión isOrdered: pedida created: creado diff --git a/modules/entry/back/methods/entry/buyLabel.js b/modules/entry/back/methods/entry/buyLabel.js index 919f7c4d7..fb807fb5f 100644 --- a/modules/entry/back/methods/entry/buyLabel.js +++ b/modules/entry/back/methods/entry/buyLabel.js @@ -1,14 +1,28 @@ module.exports = Self => { Self.remoteMethodCtx('buyLabel', { - description: 'Returns the entry buy labels', + description: 'Returns the buy label', accessType: 'READ', accepts: [ { arg: 'id', type: 'number', required: true, - description: 'The entry id', + description: 'The buy id', http: {source: 'path'} + }, { + arg: 'labelType', + type: 'string', + required: true, + description: 'The label type', + http: {source: 'path'} + }, { + arg: 'packing', + type: 'number', + required: false + }, { + arg: 'copies', + type: 'number', + required: false } ], returns: [ @@ -27,11 +41,16 @@ module.exports = Self => { } ], http: { - path: '/:id/buy-label', + path: '/:id/:labelType/buy-label', verb: 'GET' }, accessScopes: ['DEFAULT', 'read:multimedia'] }); - Self.buyLabel = (ctx, id) => Self.printReport(ctx, id, 'buy-label'); + Self.buyLabel = (ctx, id, labelType) => { + if (labelType == 'qr') + return Self.printReport(ctx, id, 'buy-label-qr'); + else + return Self.printReport(ctx, id, 'buy-label-barcode'); + }; }; diff --git a/modules/entry/back/methods/entry/buyLabelSupplier.js b/modules/entry/back/methods/entry/buyLabelSupplier.js new file mode 100644 index 000000000..61938f2f8 --- /dev/null +++ b/modules/entry/back/methods/entry/buyLabelSupplier.js @@ -0,0 +1,37 @@ +module.exports = Self => { + Self.remoteMethodCtx('buyLabelSupplier', { + description: 'Returns the entry buy labels', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'The entry id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: '/:id/buy-label-supplier', + verb: 'GET' + }, + accessScopes: ['DEFAULT', 'read:multimedia'] + }); + + Self.buyLabelSupplier = (ctx, id) => Self.printReport(ctx, id, 'buy-label-supplier'); +}; diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index f4703245c..a5c236fe4 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -194,7 +194,7 @@ module.exports = Self => { e.evaNotes observation, e.isConfirmed, e.isOrdered, - e.isRaid, + t.daysInForward, e.commission, e.created, e.travelFk, diff --git a/modules/entry/back/methods/entry/getEntry.js b/modules/entry/back/methods/entry/getEntry.js index cac3c65f8..4612de9a5 100644 --- a/modules/entry/back/methods/entry/getEntry.js +++ b/modules/entry/back/methods/entry/getEntry.js @@ -48,7 +48,9 @@ module.exports = Self => { 'warehouseInFk', 'isReceived', 'isDelivered', - 'ref'], + 'ref', + 'daysInForward', + ], include: [ { relation: 'agency', @@ -85,7 +87,6 @@ module.exports = Self => { } ], }; - return models.Entry.findOne(filter, myOptions); }; }; diff --git a/modules/entry/back/models/buy.js b/modules/entry/back/models/buy.js index 34f19e765..a027a861e 100644 --- a/modules/entry/back/models/buy.js +++ b/modules/entry/back/models/buy.js @@ -2,4 +2,5 @@ module.exports = Self => { require('../methods/entry/editLatestBuys')(Self); require('../methods/entry/latestBuysFilter')(Self); require('../methods/entry/deleteBuys')(Self); + require('../methods/entry/buyLabel')(Self); }; diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index 383585fce..4a09c7d6a 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -33,15 +33,6 @@ "isConfirmed": { "type": "boolean" }, - "isVirtual": { - "type": "boolean", - "mysql": { - "columnName": "isRaid" - } - }, - "isRaid": { - "type": "boolean" - }, "commission": { "type": "number" }, @@ -88,7 +79,8 @@ "travel": { "type": "belongsTo", "model": "Travel", - "foreignKey": "travelFk" + "foreignKey": "travelFk", + "daysInForward": "daysInForward" }, "company": { "type": "belongsTo", diff --git a/modules/entry/front/descriptor/index.html b/modules/entry/front/descriptor/index.html index 3354d4155..40625a4d5 100644 --- a/modules/entry/front/descriptor/index.html +++ b/modules/entry/front/descriptor/index.html @@ -1,65 +1,65 @@ - - - - Show entry report - - - -
- - - - - - -
-
- - - - -
- -
-
- - - \ No newline at end of file + + + + Show entry report + + + +
+ + + + + + +
+
+ + + + +
+ +
+
+ + + diff --git a/modules/entry/front/summary/index.html b/modules/entry/front/summary/index.html index 22ea87bdf..e58169fa5 100644 --- a/modules/entry/front/summary/index.html +++ b/modules/entry/front/summary/index.html @@ -86,7 +86,7 @@ auto-load="true"> { type: 'integer', description: 'Type id', }, + { + arg: 'producerFk', + type: 'integer', + description: 'Producer id', + }, + { + arg: 'instrastatFk', + type: 'string', + description: 'intrastat id', + }, { arg: 'isActive', type: 'boolean', description: 'Whether the item is or not active', }, { - arg: 'buyerFk', + arg: 'workerFk', type: 'integer', description: 'The buyer of the item', }, @@ -126,14 +136,16 @@ module.exports = Self => { return {'i.stemMultiplier': value}; case 'categoryFk': return {'ic.id': value}; - case 'buyerFk': + case 'workerFk': return {'it.workerFk': value}; + case 'producerFk': + return {'pr.id': value}; case 'supplierFk': return {'s.id': value}; case 'origin': return {'ori.code': value}; - case 'intrastat': - return {'intr.description': value}; + case 'intrastatFk': + return {'i.intrastatFk': value}; case 'landed': return {'lb.landed': value}; } @@ -172,6 +184,7 @@ module.exports = Self => { u.name AS userName, ori.code AS origin, ic.name AS category, + i.intrastatFk, intr.description AS intrastat, b.grouping, b.packing, diff --git a/modules/item/back/methods/item/labelBarcodePdf.js b/modules/item/back/methods/item/labelBarcodePdf.js deleted file mode 100644 index 3325e3da1..000000000 --- a/modules/item/back/methods/item/labelBarcodePdf.js +++ /dev/null @@ -1,55 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('labelBarcodePdf', { - description: 'Returns the item label pdf with barcode', - accessType: 'READ', - accepts: [ - { - arg: 'id', - type: 'number', - required: true, - description: 'The item id', - http: {source: 'path'} - }, { - arg: 'warehouseId', - type: 'number', - required: true - }, { - arg: 'packing', - type: 'number', - required: false - }, { - arg: 'copies', - type: 'number', - required: false - }, { - arg: 'userId', - type: 'number', - description: 'The user id from accessToken', - http: ctx => ctx.req.accessToken.userId, - required: true - } - ], - returns: [ - { - arg: 'body', - type: 'file', - root: true - }, { - arg: 'Content-Type', - type: 'String', - http: {target: 'header'} - }, { - arg: 'Content-Disposition', - type: 'String', - http: {target: 'header'} - } - ], - http: { - path: '/:id/label-barcode-pdf', - verb: 'GET' - }, - accessScopes: ['DEFAULT', 'read:multimedia'] - }); - - Self.labelBarcodePdf = (ctx, id) => Self.printReport(ctx, id, 'item-label-barcode'); -}; diff --git a/modules/item/back/methods/item/labelQrPdf.js b/modules/item/back/methods/item/labelQrPdf.js deleted file mode 100644 index 4d0e34528..000000000 --- a/modules/item/back/methods/item/labelQrPdf.js +++ /dev/null @@ -1,55 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('labelQrPdf', { - description: 'Returns the item label pdf with qr', - accessType: 'READ', - accepts: [ - { - arg: 'id', - type: 'number', - required: true, - description: 'The item id', - http: {source: 'path'} - }, { - arg: 'warehouseId', - type: 'number', - required: true - }, { - arg: 'packing', - type: 'number', - required: false - }, { - arg: 'copies', - type: 'number', - required: false - }, { - arg: 'userId', - type: 'number', - description: 'The user id from accessToken', - http: ctx => ctx.req.accessToken.userId, - required: true - } - ], - returns: [ - { - arg: 'body', - type: 'file', - root: true - }, { - arg: 'Content-Type', - type: 'String', - http: {target: 'header'} - }, { - arg: 'Content-Disposition', - type: 'String', - http: {target: 'header'} - } - ], - http: { - path: '/:id/label-qr-pdf', - verb: 'GET' - }, - accessScopes: ['DEFAULT', 'read:multimedia'] - }); - - Self.labelQrPdf = (ctx, id) => Self.printReport(ctx, id, 'item-label-qr'); -}; diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index 14467d1d8..a8aaca786 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -86,7 +86,7 @@ describe('item filter()', () => { try { const filter = {}; - const ctx = {args: {filter: filter, buyerFk: 16}, req: {accessToken: {userId: 1}}}; + const ctx = {args: {filter: filter, workerFk: 16}, req: {accessToken: {userId: 1}}}; const result = await models.Item.filter(ctx, filter, options); expect(result.length).toEqual(2); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 5dbe4d62a..dcd973524 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -47,6 +47,9 @@ "ItemType": { "dataSource": "vn" }, + "ItemTypeLog": { + "dataSource": "vn" + }, "ItemTypeTag": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-type-log.json b/modules/item/back/models/item-type-log.json new file mode 100644 index 000000000..82a218aa6 --- /dev/null +++ b/modules/item/back/models/item-type-log.json @@ -0,0 +1,9 @@ +{ + "name": "ItemTypeLog", + "base": "Log", + "options": { + "mysql": { + "table": "itemTypeLog" + } + } +} diff --git a/modules/item/back/models/item-type.json b/modules/item/back/models/item-type.json index c5c920b2f..88f66899e 100644 --- a/modules/item/back/models/item-type.json +++ b/modules/item/back/models/item-type.json @@ -29,6 +29,12 @@ }, "isLaid": { "type": "boolean" + }, + "maxRefs": { + "type": "string" + }, + "isFragile": { + "type": "boolean" } }, "relations": { diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index d39586a90..44a51594c 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -15,8 +15,6 @@ module.exports = Self => { require('../methods/item/getWasteByItem')(Self); require('../methods/item/createIntrastat')(Self); require('../methods/item/buyerWasteEmail')(Self); - require('../methods/item/labelBarcodePdf')(Self); - require('../methods/item/labelQrPdf')(Self); require('../methods/item/setVisibleDiscard')(Self); require('../methods/item/get')(Self); diff --git a/modules/shelving/back/models/parking.json b/modules/shelving/back/models/parking.json index 47a3305ae..a9393fc6a 100644 --- a/modules/shelving/back/models/parking.json +++ b/modules/shelving/back/models/parking.json @@ -38,5 +38,13 @@ "model": "Sector", "foreignKey": "sectorFk" } + }, + "scope": { + "include": { + "relation": "sector", + "scope": { + "fields": ["id", "description"] + } + } } } diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index 747352286..71bc453de 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -2,6 +2,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index fd3d6aa9b..ea71032d0 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -48,7 +48,7 @@ module.exports = Self => { CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; - const recalculation = await Self.rawSql(query, salesIds, myOptions); + const recalculation = await Self.rawSql(query, [salesIds], myOptions); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 9d1403df0..100f74bf0 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -85,6 +85,25 @@ describe('sale updatePrice()', () => { } }); + it('should check if priceFixed has changed', async() => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const price = 3; + const beforeUpdate = await models.Sale.findById(saleId, null, options); + await models.Sale.updatePrice(ctx, saleId, price, options); + const afterUpdate = await models.Sale.findById(saleId, null, options); + + expect(beforeUpdate.priceFixed).not.toEqual(afterUpdate.priceFixed); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + it('should set price as a decimal number and check the sale has the mana component changing the salesPersonMana', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index 191fd09e3..d4f128082 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -91,7 +91,21 @@ module.exports = Self => { value: componentValue }, myOptions); } - await sale.updateAttributes({price: newPrice}, myOptions); + + const [priceFixed] = await Self.rawSql(` + SELECT SUM(value) value + FROM sale s + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk + WHERE ct.isBase + AND s.id = ? + `, [id], myOptions); + + await sale.updateAttributes({ + price: newPrice, + priceFixed: priceFixed.value + }, myOptions); await Self.rawSql('CALL vn.manaSpellersRequery(?)', [userId], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [sale.ticketFk], myOptions); diff --git a/modules/ticket/back/models/expedition-state.js b/modules/ticket/back/models/expedition-state.js index 496dd88d3..f819dc05c 100644 --- a/modules/ticket/back/models/expedition-state.js +++ b/modules/ticket/back/models/expedition-state.js @@ -1,4 +1,66 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/expedition-state/filter')(Self); require('../methods/expedition-state/addExpeditionState')(Self); + + Self.observe('before save', async ctx => { + const models = Self.app.models; + const changes = ctx.data || ctx.instance; + const instance = ctx.currentInstance; + const loopBackContext = LoopBackContext.getCurrentContext(); + const httpCtx = {req: loopBackContext.active}; + const httpRequest = httpCtx.req.http.req; + const $t = httpRequest.__; + const myOptions = {}; + + if (ctx.options && ctx.options.transaction) + myOptions.transaction = ctx.options.transaction; + + const newStateType = changes?.typeFk; + if (newStateType == null) return; + + const expeditionId = changes?.expeditionFk || instance?.expeditionFk; + + const {code} = await models.ExpeditionStateType.findById( + newStateType, + { + fields: ['code'] + }, + myOptions); + + if (code !== 'LOST') return; + + const dataExpedition = await models.Expedition.findById( + expeditionId, { + fields: ['ticketFk'], + include: [{ + relation: 'ticket', + scope: { + fields: ['clientFk'], + include: [{ + relation: 'client', + scope: { + fields: ['name', 'salesPersonFk'] + } + }] + } + }], + + }, myOptions); + + const salesPersonFk = dataExpedition.ticket()?.client()?.salesPersonFk; + + if (salesPersonFk) { + const url = await Self.app.models.Url.getUrl(); + const fullUrl = `${url}ticket/${dataExpedition.ticketFk}/expedition`; + const message = $t('ticketLostExpedition', { + ticketId: dataExpedition.ticketFk, + expeditionId: expeditionId, + url: fullUrl + }); + await models.Chat.sendCheckingPresence(httpCtx, salesPersonFk, message); + } + }); }; + diff --git a/modules/ticket/back/models/expedition-state.json b/modules/ticket/back/models/expedition-state.json index e96d2544c..7d8079b33 100644 --- a/modules/ticket/back/models/expedition-state.json +++ b/modules/ticket/back/models/expedition-state.json @@ -19,7 +19,8 @@ "type": "number" }, "typeFk": { - "type": "number" + "type": "number", + "required": true }, "userFk": { "type": "number" diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 96a36bbc9..947115f5c 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -28,6 +28,9 @@ "discount": { "type": "number" }, + "priceFixed": { + "type": "number" + }, "reserved": { "type": "boolean" }, diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index e24a7659c..30910fa46 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -155,6 +155,7 @@ module.exports = Self => { t.landingHour, t.cargoSupplierFk, t.totalEntries, + t.daysInForward, am.name agencyModeName, win.name warehouseInName, wout.name warehouseOutName, diff --git a/modules/travel/back/methods/travel/getTravel.js b/modules/travel/back/methods/travel/getTravel.js index 171b64db1..59d30a0c7 100644 --- a/modules/travel/back/methods/travel/getTravel.js +++ b/modules/travel/back/methods/travel/getTravel.js @@ -44,7 +44,6 @@ module.exports = Self => { ], }; - let travel = await Self.app.models.Travel.findOne(filter); - return travel; + return Self.app.models.Travel.findOne(filter); }; }; diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 0ebf683e7..04f53f1c8 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -50,6 +50,9 @@ }, "landingHour": { "type": "string" + }, + "daysInForward": { + "type": "number" } }, "relations": { diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index c334c0d05..937df98c0 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -204,6 +204,15 @@ ] }, "summary": { + "fields": [ + "id", + "firstName", + "lastName", + "bossFk", + "sex", + "phone", + "mobileExtension" + ], "include": [ { "relation": "user", @@ -247,10 +256,21 @@ } }, { - "relation": "boss" + "relation": "boss", + "scope": { + "fields": [ + "id", + "name" + ] + } }, { - "relation": "client" + "relation": "client", + "scope": { + "fields": [ + "id" + ] + } }, { "relation": "sip", @@ -272,14 +292,16 @@ "fields": [ "id", "fiDueDate", - "sex", "seniority", "fi", "isFreelance", "isSsDiscounted", "hasMachineryAuthorized", "isDisable", - "birth" + "birth", + "educationLevelFk", + "originCountryFk", + "maritalStatus" ] } } diff --git a/print/templates/reports/buy-label/assets/css/import.js b/print/templates/reports/buy-label-barcode/assets/css/import.js similarity index 100% rename from print/templates/reports/buy-label/assets/css/import.js rename to print/templates/reports/buy-label-barcode/assets/css/import.js diff --git a/print/templates/reports/item-label-barcode/assets/css/style.css b/print/templates/reports/buy-label-barcode/assets/css/style.css similarity index 95% rename from print/templates/reports/item-label-barcode/assets/css/style.css rename to print/templates/reports/buy-label-barcode/assets/css/style.css index 884faef56..fabecd28e 100644 --- a/print/templates/reports/item-label-barcode/assets/css/style.css +++ b/print/templates/reports/buy-label-barcode/assets/css/style.css @@ -1,7 +1,7 @@ html { font-family: "Roboto", "Helvetica", "Arial", sans-serif; margin-top: -9px; - margin-left: -6px; + margin-left: -3px; } table { width: 100%; @@ -52,8 +52,8 @@ td { max-height: 50px; } .md-height { - height: 75px; - max-height: 75px; + height: 70px; + max-height: 70px; } .sm-width { width: 60px; diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.html b/print/templates/reports/buy-label-barcode/buy-label-barcode.html similarity index 67% rename from print/templates/reports/item-label-barcode/item-label-barcode.html rename to print/templates/reports/buy-label-barcode/buy-label-barcode.html index 929ce5fe2..f14f0b70b 100644 --- a/print/templates/reports/item-label-barcode/item-label-barcode.html +++ b/print/templates/reports/buy-label-barcode/buy-label-barcode.html @@ -1,16 +1,16 @@ - + @@ -18,61 +18,64 @@ diff --git a/print/templates/reports/item-label-barcode/item-label-barcode.js b/print/templates/reports/buy-label-barcode/buy-label-barcode.js similarity index 67% rename from print/templates/reports/item-label-barcode/item-label-barcode.js rename to print/templates/reports/buy-label-barcode/buy-label-barcode.js index 5f9a11ea1..8c39a7046 100755 --- a/print/templates/reports/item-label-barcode/item-label-barcode.js +++ b/print/templates/reports/buy-label-barcode/buy-label-barcode.js @@ -4,20 +4,11 @@ const moment = require('moment'); const jsbarcode = require('jsbarcode'); module.exports = { - name: 'item-label-barcode', + name: 'buy-label-barcode', async serverPrefetch() { - this.company = await this.findOneFromDef('company', [this.warehouseId]); - if (!this.company) - throw new UserError(`There is no company associated with that warehouse`); - this.date = Date.vnNew(); - this.lastBuy = await this.findOneFromDef('lastBuy', [ - this.id, - this.warehouseId, - this.date - ]); - this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy.id]); - if (!this.items.length) throw new UserError(`Empty data source`); + this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]); + if (!this.buys.length) throw new UserError(`Empty data source`); this.date = moment(this.date).format('WW/E'); }, methods: { @@ -51,8 +42,8 @@ module.exports = { copies: { type: Number }, - userId: { - type: Number + typeId: { + type: String } } }; diff --git a/print/templates/reports/item-label-barcode/locale/es.yml b/print/templates/reports/buy-label-barcode/locale/es.yml similarity index 100% rename from print/templates/reports/item-label-barcode/locale/es.yml rename to print/templates/reports/buy-label-barcode/locale/es.yml diff --git a/print/templates/reports/item-label-barcode/options.json b/print/templates/reports/buy-label-barcode/options.json similarity index 85% rename from print/templates/reports/item-label-barcode/options.json rename to print/templates/reports/buy-label-barcode/options.json index 1ae2630b0..17c43e69f 100644 --- a/print/templates/reports/item-label-barcode/options.json +++ b/print/templates/reports/buy-label-barcode/options.json @@ -3,7 +3,7 @@ "height": "4.9cm", "margin": { "top": "0.17cm", - "right": "0.745cm", + "right": "0.37cm", "bottom": "0cm", "left": "0cm" }, diff --git a/print/templates/reports/item-label-barcode/sql/item.sql b/print/templates/reports/buy-label-barcode/sql/buy.sql similarity index 82% rename from print/templates/reports/item-label-barcode/sql/item.sql rename to print/templates/reports/buy-label-barcode/sql/buy.sql index 3cb42d139..739f8449f 100644 --- a/print/templates/reports/item-label-barcode/sql/item.sql +++ b/print/templates/reports/buy-label-barcode/sql/buy.sql @@ -22,7 +22,9 @@ SELECT ROW_NUMBER() OVER() labelNum, ig.longName, ig.subName, i.comment, - w.code buyerName + w.code buyerName, + i.isLaid, + c.code company FROM vn.buy b JOIN vn.item i ON i.id = b.itemFk LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk @@ -30,5 +32,7 @@ SELECT ROW_NUMBER() OVER() labelNum, LEFT JOIN vn.producer p ON p.id = i.producerFk JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.worker w ON w.id = it.workerFk + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.company c ON c.id = e.companyFk JOIN numbers num WHERE b.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/assets/css/import.js b/print/templates/reports/buy-label-qr/assets/css/import.js similarity index 100% rename from print/templates/reports/item-label-barcode/assets/css/import.js rename to print/templates/reports/buy-label-qr/assets/css/import.js diff --git a/print/templates/reports/item-label-qr/assets/css/style.css b/print/templates/reports/buy-label-qr/assets/css/style.css similarity index 98% rename from print/templates/reports/item-label-qr/assets/css/style.css rename to print/templates/reports/buy-label-qr/assets/css/style.css index fe6668c9a..0e288704b 100644 --- a/print/templates/reports/item-label-qr/assets/css/style.css +++ b/print/templates/reports/buy-label-qr/assets/css/style.css @@ -1,7 +1,7 @@ html { font-family: "Roboto", "Helvetica", "Arial", sans-serif; margin-top: -7px; - margin-left: -6px; + margin-left: -3px; } .leftTable { width: 47%; diff --git a/print/templates/reports/item-label-qr/item-label-qr.html b/print/templates/reports/buy-label-qr/buy-label-qr.html similarity index 68% rename from print/templates/reports/item-label-qr/item-label-qr.html rename to print/templates/reports/buy-label-qr/buy-label-qr.html index 712bd6c7d..00e64b57d 100644 --- a/print/templates/reports/item-label-qr/item-label-qr.html +++ b/print/templates/reports/buy-label-qr/buy-label-qr.html @@ -1,6 +1,6 @@ - +
- {{item.item}} + {{buy.item}}
- {{item.size}} + {{buy.size}}
{{ - (item.longName && item.size && item.subName) - ? `${item.longName} ${item.size} ${item.subName}` - : item.comment + (buy.longName && buy.size && buy.subName) + ? `${buy.longName} ${buy.size} ${buy.subName}` + : buy.comment }}
- {{item.producerName || item.producerFk}} + {{buy.producerName || buy.producerFk}}
- {{item.inkFk}} + {{buy.inkFk}}
- {{item.itemFk}} + {{buy.itemFk}}
- {{`${(packing || item.packing)} x ${item.stems || ''}`}} + {{`${(packing || buy.packing)} x ${buy.stems || ''}`}}
-
+
-
- {{item.entryFk}} +
+ {{'LAID'}} +
+
+ {{buy.entryFk}}
- {{item.buyerName}} + {{buy.buyerName}}
- {{item.origin}} + {{buy.origin}}
- {{item.buyFk}} + {{buy.buyFk}}
@@ -82,7 +85,7 @@
- {{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}} + {{`${buy.labelNum}/${buy.quantity / (packing || buy.packing)}`}}
@@ -28,58 +28,65 @@ + - @@ -104,9 +111,9 @@ diff --git a/print/templates/reports/item-label-qr/item-label-qr.js b/print/templates/reports/buy-label-qr/buy-label-qr.js similarity index 61% rename from print/templates/reports/item-label-qr/item-label-qr.js rename to print/templates/reports/buy-label-qr/buy-label-qr.js index 1a0ef767b..74470ad6d 100755 --- a/print/templates/reports/item-label-qr/item-label-qr.js +++ b/print/templates/reports/buy-label-qr/buy-label-qr.js @@ -3,27 +3,18 @@ const moment = require('moment'); const qrcode = require('qrcode'); module.exports = { - name: 'item-label-qr', + name: 'buy-label-qr', async serverPrefetch() { - this.company = await this.findOneFromDef('company', [this.warehouseId]); - if (!this.company) - throw new UserError(`There is no company associated with that warehouse`); - this.date = Date.vnNew(); - this.lastBuy = await this.findOneFromDef('lastBuy', [ - this.id, - this.warehouseId, - this.date - ]); - this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.lastBuy.id]); - if (!this.items.length) throw new UserError(`Empty data source`); - this.qr = await this.getQr(this.items[0].buyFk); + this.buys = await this.rawSqlFromDef('buy', [this.copies || 1, this.id]); + if (!this.buys.length) throw new UserError(`Empty data source`); + this.qr = await this.getQr(this.buys[0].buyFk); this.date = moment(this.date).format('WW/E'); }, methods: { getQr(data) { data = { - company: this.company, + company: this.buys.company, user: this.userId, created: this.date, table: 'buy', @@ -52,6 +43,9 @@ module.exports = { }, userId: { type: Number + }, + typeId: { + type: String } } }; diff --git a/print/templates/reports/item-label-qr/locale/es.yml b/print/templates/reports/buy-label-qr/locale/es.yml similarity index 100% rename from print/templates/reports/item-label-qr/locale/es.yml rename to print/templates/reports/buy-label-qr/locale/es.yml diff --git a/print/templates/reports/item-label-qr/options.json b/print/templates/reports/buy-label-qr/options.json similarity index 86% rename from print/templates/reports/item-label-qr/options.json rename to print/templates/reports/buy-label-qr/options.json index c3c395040..c6ffaddea 100644 --- a/print/templates/reports/item-label-qr/options.json +++ b/print/templates/reports/buy-label-qr/options.json @@ -3,7 +3,7 @@ "height": "4.9cm", "margin": { "top": "0.17cm", - "right": "0.6cm", + "right": "0.3cm", "bottom": "0cm", "left": "0cm" }, diff --git a/print/templates/reports/item-label-qr/sql/item.sql b/print/templates/reports/buy-label-qr/sql/buy.sql similarity index 82% rename from print/templates/reports/item-label-qr/sql/item.sql rename to print/templates/reports/buy-label-qr/sql/buy.sql index 3cb42d139..739f8449f 100644 --- a/print/templates/reports/item-label-qr/sql/item.sql +++ b/print/templates/reports/buy-label-qr/sql/buy.sql @@ -22,7 +22,9 @@ SELECT ROW_NUMBER() OVER() labelNum, ig.longName, ig.subName, i.comment, - w.code buyerName + w.code buyerName, + i.isLaid, + c.code company FROM vn.buy b JOIN vn.item i ON i.id = b.itemFk LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk @@ -30,5 +32,7 @@ SELECT ROW_NUMBER() OVER() labelNum, LEFT JOIN vn.producer p ON p.id = i.producerFk JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.worker w ON w.id = it.workerFk + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.company c ON c.id = e.companyFk JOIN numbers num WHERE b.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/assets/css/import.js b/print/templates/reports/buy-label-supplier/assets/css/import.js similarity index 100% rename from print/templates/reports/item-label-qr/assets/css/import.js rename to print/templates/reports/buy-label-supplier/assets/css/import.js diff --git a/print/templates/reports/buy-label/assets/css/style.css b/print/templates/reports/buy-label-supplier/assets/css/style.css similarity index 100% rename from print/templates/reports/buy-label/assets/css/style.css rename to print/templates/reports/buy-label-supplier/assets/css/style.css diff --git a/print/templates/reports/buy-label/buy-label.html b/print/templates/reports/buy-label-supplier/buy-label-supplier.html similarity index 100% rename from print/templates/reports/buy-label/buy-label.html rename to print/templates/reports/buy-label-supplier/buy-label-supplier.html diff --git a/print/templates/reports/buy-label/buy-label.js b/print/templates/reports/buy-label-supplier/buy-label-supplier.js similarity index 97% rename from print/templates/reports/buy-label/buy-label.js rename to print/templates/reports/buy-label-supplier/buy-label-supplier.js index 289483051..3cef5f295 100755 --- a/print/templates/reports/buy-label/buy-label.js +++ b/print/templates/reports/buy-label-supplier/buy-label-supplier.js @@ -5,7 +5,7 @@ const jsBarcode = require('jsbarcode'); const moment = require('moment'); module.exports = { - name: 'buy-label', + name: 'buy-label-supplier', mixins: [vnReport], async serverPrefetch() { const buy = await models.Buy.findById(this.id, null); diff --git a/print/templates/reports/buy-label/locale/en.yml b/print/templates/reports/buy-label-supplier/locale/en.yml similarity index 100% rename from print/templates/reports/buy-label/locale/en.yml rename to print/templates/reports/buy-label-supplier/locale/en.yml diff --git a/print/templates/reports/buy-label/locale/es.yml b/print/templates/reports/buy-label-supplier/locale/es.yml similarity index 100% rename from print/templates/reports/buy-label/locale/es.yml rename to print/templates/reports/buy-label-supplier/locale/es.yml diff --git a/print/templates/reports/buy-label/options.json b/print/templates/reports/buy-label-supplier/options.json similarity index 100% rename from print/templates/reports/buy-label/options.json rename to print/templates/reports/buy-label-supplier/options.json diff --git a/print/templates/reports/buy-label/sql/buy.sql b/print/templates/reports/buy-label-supplier/sql/buy.sql similarity index 100% rename from print/templates/reports/buy-label/sql/buy.sql rename to print/templates/reports/buy-label-supplier/sql/buy.sql diff --git a/print/templates/reports/item-label-barcode/sql/company.sql b/print/templates/reports/item-label-barcode/sql/company.sql deleted file mode 100644 index 4047786a9..000000000 --- a/print/templates/reports/item-label-barcode/sql/company.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT co.code - FROM warehouse w - JOIN address a ON a.id = w.addressFk - JOIN company co ON co.clientFk = a.clientFk - WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-barcode/sql/lastBuy.sql b/print/templates/reports/item-label-barcode/sql/lastBuy.sql deleted file mode 100644 index d10339998..000000000 --- a/print/templates/reports/item-label-barcode/sql/lastBuy.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT buy_getUltimate(?, ?, ?) id \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/sql/company.sql b/print/templates/reports/item-label-qr/sql/company.sql deleted file mode 100644 index 4047786a9..000000000 --- a/print/templates/reports/item-label-qr/sql/company.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT co.code - FROM warehouse w - JOIN address a ON a.id = w.addressFk - JOIN company co ON co.clientFk = a.clientFk - WHERE w.id = ? \ No newline at end of file diff --git a/print/templates/reports/item-label-qr/sql/lastBuy.sql b/print/templates/reports/item-label-qr/sql/lastBuy.sql deleted file mode 100644 index d10339998..000000000 --- a/print/templates/reports/item-label-qr/sql/lastBuy.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT buy_getUltimate(?, ?, ?) id \ No newline at end of file
@@ -12,7 +12,7 @@
- {{item.buyFk}} + {{buy.buyFk}}
- {{item.itemFk}} + {{buy.itemFk}}
- {{item.item}} + {{buy.item}}
- {{item.size}} + {{buy.size}}
- Color: {{item.inkFk}} + Color: {{buy.inkFk}}
- {{packing || item.packing}} + {{packing || buy.packing}}
- {{item.stems}} + {{buy.stems}}
- Origen: {{item.origin}} + Origen: {{buy.origin}}
- Productor: {{item.producerName || item.producerFk}} + Productor: {{buy.producerName || buy.producerFk}} +
+
+
+ {{'LAID'}} +
+
+ {{buy.entryFk}}
- Comprador: {{item.buyerName}} + Comprador: {{buy.buyerName}}
@@ -89,14 +96,14 @@
- {{`${item.labelNum}/${item.quantity / (packing || item.packing)}`}} + {{`${buy.labelNum}/${buy.quantity / (packing || buy.packing)}`}}
- Entrada: {{item.entryFk}} + Entrada: {{buy.entryFk}}
{{ - (item.longName && item.size && item.subName) - ? `${item.longName} ${item.size} ${item.subName}` - : item.comment + (buy.longName && buy.size && buy.subName) + ? `${buy.longName} ${buy.size} ${buy.subName}` + : buy.comment }}