diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 80166db62..4570de332 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -32,7 +32,7 @@ BEGIN JOIN duaEntry de ON de.entryFk = e.id JOIN invoiceInConfig iic WHERE de.duaFk = vDuaFk - AND iidd.dueDated <= util.VN_CURDATE() + INTERVAL iic.dueDateMarginDays DAY; + AND iidd.dueDated < util.VN_CURDATE() + INTERVAL iic.dueDateMarginDays DAY; IF vIncorrectInvoiceInDueDay THEN CALL util.throw(CONCAT('Incorrect due date, invoice: ', vIncorrectInvoiceInDueDay)); diff --git a/db/routines/vn/procedures/expeditionScan_Put.sql b/db/routines/vn/procedures/expeditionScan_Put.sql index 9744a7cd7..cbc76d317 100644 --- a/db/routines/vn/procedures/expeditionScan_Put.sql +++ b/db/routines/vn/procedures/expeditionScan_Put.sql @@ -1,11 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_Put`(vPalletFk INT, vExpeditionFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_Put`( + vPalletFk INT, + vExpeditionFk INT +) BEGIN - - REPLACE vn.expeditionScan(expeditionFk, palletFk) - VALUES(vExpeditionFk, vPalletFk); - - SELECT LAST_INSERT_ID() INTO vPalletFk; - + IF NOT (SELECT TRUE FROM expedition WHERE id = vExpeditionFk LIMIT 1) THEN + CALL util.throw('Expedition not exists'); + END IF; + + IF NOT (SELECT TRUE FROM expeditionPallet WHERE id = vPalletFk LIMIT 1) THEN + CALL util.throw('Pallet not exists'); + END IF; + + REPLACE expeditionScan(expeditionFk, palletFk) + VALUES(vExpeditionFk, vPalletFk); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_beforeUpdate.sql b/db/routines/vn/triggers/ticket_beforeUpdate.sql index 34b6711ff..6d5d7f908 100644 --- a/db/routines/vn/triggers/ticket_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticket_beforeUpdate.sql @@ -8,7 +8,13 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); IF NOT (NEW.routeFk <=> OLD.routeFk) THEN - IF NEW.isSigned THEN + IF NEW.isSigned AND NOT ( + SELECT (COUNT(s.id) = COUNT(cb.saleFk) + AND SUM(s.quantity) = SUM(cb.quantity)) + FROM sale s + LEFT JOIN claimBeginning cb ON cb.saleFk = s.id + WHERE s.ticketFk = NEW.id + ) THEN CALL util.throw('A signed ticket cannot be rerouted'); END IF; INSERT IGNORE INTO routeRecalc(routeFk) diff --git a/modules/route/back/methods/route/getTickets.js b/modules/route/back/methods/route/getTickets.js index 5aa4fdf0f..c0b952b70 100644 --- a/modules/route/back/methods/route/getTickets.js +++ b/modules/route/back/methods/route/getTickets.js @@ -90,7 +90,7 @@ module.exports = Self => { stmt.merge(conn.makeWhere(filter.where)); stmt.merge(conn.makeGroupBy('t.id')); - stmt.merge(conn.makePagination(filter)); + stmt.merge(conn.makeOrderBy(filter.order)); return conn.executeStmt(stmt, myOptions); };