diff --git a/CHANGELOG.md b/CHANGELOG.md index 74109c7c4..57848aa7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,89 @@ +# Version 24.38 - 2024-09-17 + +### Added 🆕 + +- chore: refs #7323 filter data by:jorgep +- chore: refs #7323 fix test by:jorgep +- chore: refs #7323 worker changes by:jorgep +- chore: refs #7323 worker changes wip by:jorgep +- chore: refs #7524 add select limit by:jorgep +- feat(AccessToken&ACL): refs #7547 upgrade security by:alexm +- feat: deleted code and redirect to Lilium by:Jon +- feat: refs #4515 New throw buy_checkItem by:guillermo +- feat: refs #6650 Added saleGroupLog by:guillermo +- feat: refs #6650 new itemShelvingLog by:guillermo +- feat: refs #6760 refs #actualiza campo nickname by:jgallego +- feat: refs #7277 fdescribe by:jgallego +- feat: refs #7277 fit by:jgallego +- feat: refs #7277 refundInvoices by:jgallego +- feat: refs #7277 test with warehouse by:jgallego +- feat: refs #7277 traducciones by:jgallego +- feat: refs #7277 transfer addressFk by:jgallego +- feat: refs #7532 Requested changes by:guillermo +- feat: refs #7564 Added proc by:guillermo +- feat: refs #7564 Added ticket_setVolumeItemCost by:guillermo +- feat: refs #7564 Added volume column by:guillermo +- feat: refs #7564 Fix version by:guillermo +- feat: refs #7564 Requested changes by:guillermo +- feat: refs #7615 setDeleted by:robert +- feat: refs #7650 Added no transfer lines to inventory entry and fixtures by:guillermo +- feat: refs #7650 Fix tests by:guillermo +- feat: refs #7747 Delete buyUltimate and buyUltimateFromInterval by:ivanm +- feat: refs #7759 Changed defined only of vn objects by:guillermo +- feat: refs #7759 Changed definer root to vn-admin by:guillermo +- feat: refs #7759 Changed name by:guillermo +- feat: refs #7759 Deleted version 11163-maroonEucalyptus by:guillermo +- feat: refs #7759 Revoke routine grants vn by:guillermo +- feat: refs #7811 Added comment by:guillermo +- feat: refs #7811 Added new params in datasources.json by:guillermo +- feat: refs #7898 Add column "floor" in vn.parking by:ivanm +- feat: refs #7898 Modify default by:ivanm +- feat: refs #7905 Added new method getBuysCsv by:guillermo +- feat: refs #7905 Added param toCsv by:guillermo +- feat: refs #7938 remove unnecessary insert in clientLog by:alexm +- feat: refs #7953 pullinfo (7953-devToTest_2438) by:alexm +- feat(salix): #7671 define isDestiny field in model by:Javier Segarra +- feat(salix): refs #7896 update version and changelog (origin/7896_down_devToTest_2436) by:Javier Segarra +- feat(salix): refs #7905 #7905 use getBuys toCSV flattened by:Javier Segarra +- feat(ssalix): refs #7671 #7671 checkDates by:Javier Segarra +- feat(ssalix): refs #7671 #7671 checkDates to present by:Javier Segarra +- feat: ticket 215005 Changed acl show transferClient by:guillermo + +### Changed 📦 + +- perf: refs #7671 improve showBadDates by:Javier Segarra +- perf(salix): refs #7671 #7671 imrpove and revert where changes by:Javier Segarra +- refactor: deleted e2e & added back descriptor and summary by:Jon + +### Fixed 🛠️ + +- chore: refs #7323 fix test by:jorgep +- feat: refs #7650 Added no transfer lines to inventory entry and fixtures by:guillermo +- fix by:guillermo +- fixes: refs #7760 collection problems by:Carlos Andrés +- fix merge dev (7407-workerMedical) by:alexm +- fix: refs #6727 No delete log tables data in clean procedures by:guillermo +- fix: refs #6897 back and tests by:carlossa +- fix: refs #6897 back by:carlossa +- fix: refs #6897 fix filter by:carlossa +- fix: refs #6897 fix json by:carlossa +- fix: refs #6897 travel filter by:carlossa +- fix: refs #6897 error test by:jgallego +- fix: refs #7323 fetch from right source by:jorgep +- fix: refs #7564 Deleted query by:guillermo +- fix: refs #7759 Added user 'vn'@'localhost' & grants by:guillermo +- fix: refs #7760 collection problems by:Carlos Andrés +- fix: refs #7760 tmp.ticketIPT by:Carlos Andrés +- fix: refs #7905 added comments to flatten.js by:guillermo +- fix: refs ##7905 Handle error by:guillermo +- fix(salix): refs #7905 #7905 use right fn to flatten data by:Javier Segarra +- perf(salix): refs #7671 #7671 imrpove and revert where changes by:Javier Segarra +- refs #6898 fix supplier remove by:carlossa +- refs #7407 fix acls fixtures by:carlossa +- test: fix connections e2e (7547-accessToken-security) by:alexm +- test: refs #7277 fix test proposal by:Javier Segarra +- test(salix): refs #7671 #7671 improve and revert where changes by:Javier Segarra + # Version 24.36 - 2024-09-03 ### Added 🆕 diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 1ab77f608..c8a5295f7 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -12,9 +12,8 @@ const ticket1 = { 'addressFk': 1, 'agencyModeFk': 999 }; - +let expedition; const expedition1 = { - 'id': 17, 'agencyModeFk': 999, 'ticketFk': 44, 'freightItemFk': 71, @@ -47,7 +46,7 @@ describe('MRWConfig createShipment()', () => { await createMrwConfig(); await models.Ticket.create(ticket1); - await models.Expedition.create(expedition1); + expedition = await models.Expedition.create(expedition1); }); afterAll(async() => { @@ -93,7 +92,7 @@ describe('MRWConfig createShipment()', () => { } it('should create a shipment and return a base64Binary label', async() => { - const {file} = await models.MrwConfig.createShipment(expedition1.id); + const {file} = await models.MrwConfig.createShipment(expedition.id); expect(file).toEqual(mockBase64Binary); }); @@ -101,7 +100,7 @@ describe('MRWConfig createShipment()', () => { it('should fail if mrwConfig has no data', async() => { let error; await models.MrwConfig.destroyAll(); - await models.MrwConfig.createShipment(expedition1.id).catch(e => { + await models.MrwConfig.createShipment(expedition.id).catch(e => { error = e; }).finally(async() => { expect(error.message).toEqual(`MRW service is not configured`); @@ -126,7 +125,7 @@ describe('MRWConfig createShipment()', () => { yesterday.setDate(yesterday.getDate() - 1); await models.Ticket.updateAll({id: ticket1.id}, {shipped: yesterday}); - await models.MrwConfig.createShipment(expedition1.id).catch(e => { + await models.MrwConfig.createShipment(expedition.id).catch(e => { error = e; }).finally(async() => { expect(error.message).toEqual(`This ticket has a shipped date earlier than today`); @@ -136,7 +135,7 @@ describe('MRWConfig createShipment()', () => { it('should send mail if you are past the dead line and is not notified today', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: null}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification.notificationFk).toEqual(filter.notificationFk); @@ -144,7 +143,7 @@ describe('MRWConfig createShipment()', () => { it('should send mail if you are past the dead line and it is notified from another day', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: new Date()}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification.notificationFk).toEqual(filter.notificationFk); @@ -152,7 +151,7 @@ describe('MRWConfig createShipment()', () => { it('should not send mail if you are past the dead line and it is notified', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: Date.vnNew()}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification).toEqual(null); diff --git a/back/methods/postcode/specs/filter.spec.js b/back/methods/postcode/specs/filter.spec.js index abf450a19..7ebce495a 100644 --- a/back/methods/postcode/specs/filter.spec.js +++ b/back/methods/postcode/specs/filter.spec.js @@ -29,7 +29,7 @@ describe('Postcode filter()', () => { } }, options); - expect(results.length).toEqual(4); + expect(results.length).toEqual(5); await tx.rollback(); } catch (e) { await tx.rollback(); @@ -63,7 +63,7 @@ describe('Postcode filter()', () => { search: 'one', }}, options); - expect(results.length).toEqual(4); + expect(results.length).toEqual(5); await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/back/methods/vn-user/update-user.js b/back/methods/vn-user/update-user.js index 202b01c65..2bb390cf9 100644 --- a/back/methods/vn-user/update-user.js +++ b/back/methods/vn-user/update-user.js @@ -26,7 +26,7 @@ module.exports = Self => { description: 'The user lang' }, { arg: 'twoFactor', - type: 'string', + type: 'any', description: 'The user twoFactor' } ], diff --git a/back/models/buyer.json b/back/models/buyer.json index a17d3b538..a1297eda3 100644 --- a/back/models/buyer.json +++ b/back/models/buyer.json @@ -15,6 +15,9 @@ "nickname": { "type": "string", "required": true + }, + "display": { + "type": "boolean" } }, "acls": [ diff --git a/back/models/vn-user.json b/back/models/vn-user.json index 415aa6810..8c49c8db9 100644 --- a/back/models/vn-user.json +++ b/back/models/vn-user.json @@ -165,7 +165,8 @@ "hasGrant", "realm", "email", - "emailVerified" + "emailVerified", + "twoFactor" ] } } diff --git a/db/dump/dump.after.sql b/db/dump/dump.after.sql index 7508a36a7..962d8e3f2 100644 --- a/db/dump/dump.after.sql +++ b/db/dump/dump.after.sql @@ -4,7 +4,9 @@ GRANT SELECT, INSERT, UPDATE, DELETE, + DROP, CREATE TEMPORARY TABLES, EXECUTE, + EVENT, TRIGGER ON *.* TO 'vn'@'localhost'; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ea689c609..c0d151b2c 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -179,12 +179,12 @@ INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `i (30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2); INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `countryFk`, `hasProduction`, `isOrigin`, `isDestiny`) - VALUES - (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), + VALUES (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 13, 1, 1, 0), (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1), (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), + (6, 'Warehouse six', 'VNH', 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); @@ -335,21 +335,21 @@ INSERT INTO `vn`.`payDem`(`id`, `payDem`) (2, 20), (7, 0); -INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) +INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`, `hasDailyInvoice`) VALUES - (1, 'Autonomy one', 1), - (2, 'Autonomy two', 1), - (3, 'Autonomy three', 2), - (4, 'Autonomy four', 13); + (1, 'Autonomy one', 1, 1), + (2, 'Autonomy two', 1, 0), + (3, 'Autonomy three', 2, 0), + (4, 'Autonomy four', 13, 0); INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `autonomyFk`, `warehouseFk`) VALUES - (1, 'Province one', 1, 1, NULL), - (2, 'Province two', 1, 1, NULL), - (3, 'Province three', 30, 2, NULL), - (4, 'Province four', 2, 3, NULL), - (5, 'Province five', 13, 4, NULL); + (1, 'Province one', 1, 1, NULL), + (2, 'Province two', 1, 1, NULL), + (3, 'Province three', 30, 2, NULL), + (4, 'Province four', 2, 3, NULL), + (5, 'Province five', 13, 4, NULL); INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) VALUES @@ -365,6 +365,7 @@ INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) ('46460', 2, 6), ('46680', 3, 6), ('46600', 4, 7), + ('46600',1, 6), ('EC170150', 5, 8); INSERT INTO `vn`.`clientType`(`code`, `type`) @@ -397,7 +398,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 19, 0, 'florist','normal'), (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 19, 0, 'florist','normal'), (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 9, 0, 'florist','normal'), - (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, NULL, 0, 'florist','normal'), + (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, NULL, 1, 'florist','normal'), (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'), (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); @@ -821,10 +822,10 @@ INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `userFk`, `created`) (12, 3, 19, util.VN_NOW()), (13, 3, 19, util.VN_NOW()), (14, 3, 19, util.VN_NOW()), - (15, 2, 19, util.VN_NOW()), + (15, 10, 19, util.VN_NOW()), (16, 3, 19, util.VN_NOW()), (17, 2, 19, util.VN_NOW()), - (18, 2, 19, util.VN_NOW()), + (37, 10, 19, util.VN_NOW()), (19, 2, 19, util.VN_NOW()), (20, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), (21, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), @@ -1031,19 +1032,20 @@ INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`, `hostFk`) VALUES - (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), - (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), - (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), - (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), - (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), - (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), - (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), - (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), - (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), - (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); + (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), + (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), + (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), + (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), + (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), + (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), + (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), + (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), + (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), + (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (13, 1, 10, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (14, 1, 37, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) @@ -1478,7 +1480,8 @@ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) (2, 1), (3, 2), (5, 6), - (15, 6); + (15, 6), + (17, 6); INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) VALUES @@ -1494,16 +1497,16 @@ INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk (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, 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); + 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() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -1516,30 +1519,31 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (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 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', 1, 1, ''); INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) VALUES (2, 4, 1); -INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWasteQuantity`, `saleInternalWaste`, `saleExternalWaste`) +INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWasteQuantity`, `saleExternalWaste`, `saleFaultWaste`, `saleContainerWaste`, `saleBreakWaste`, `saleOtherWaste`) VALUES - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 1, 1, '1062', '51', '56.20', '56.20'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 2, 1, '35074', '687', '53.12', '89.69'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 3, 1, '1777', '13', '12.02', '53.12'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 4, 1, '3182', '59', '51', '56.20'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 5, 1, '1747', '13', '53.12', '53.12'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '7182', '59', '51', '53.12'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '1777', '13', '89.69', '89.69'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 8, 1, '4181', '59', '53.12', '53.12'), - ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 9, 1, '7268', '59', '12.02', '56.20'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 2, 1, '-74', '0', '51', '89.69'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 3, 1, '-7', '0', '12.02', '53.12'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 4, 1, '1100', '0', '51', '56.20'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 5, 1, '848', '-187', '12.02', '89.69'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '186', '0', '51', '53.12'), - ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '277', '0', '53.12', '56.20'); + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 1, 1, '1062', '51', '56.20', '56.20', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 2, 1, '35074', '687', '53.12', '89.69', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 3, 1, '1777', '13', '12.02', '53.12', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 4, 1, '3182', '59', '51', '56.20', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 5, 1, '1747', '13', '53.12', '53.12', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '7182', '59', '51', '53.12', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '1777', '13', '89.69', '89.69', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 8, 1, '4181', '59', '53.12', '53.12', '56.20', '56.20', '56.20'), + ('35', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 9, 1, '7268', '59', '12.02', '56.20', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 2, 1, '-74', '0', '51', '89.69', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 3, 1, '-7', '0', '12.02', '53.12', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 4, 1, '1100', '0', '51', '56.20', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 5, 1, '848', '-187', '12.02', '89.69', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '186', '0', '51', '53.12', '56.20', '56.20', '56.20'), + ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '277', '0', '53.12', '56.20', '56.20', '56.20', '56.20'); -INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`) +INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,freightValue,packageValue,comissionValue,packing,grouping,groupingMode,location,price1,price2,price3,printedStickers,isChecked,isIgnored,weight,created) VALUES (1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH), (2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 1 MONTH), @@ -1555,7 +1559,8 @@ INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagi (12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), - (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()); + (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), + (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES @@ -2488,7 +2493,7 @@ INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`) (1104, 2), (1104, 3); -INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`) +INSERT INTO `vn`.`workerDms`(`id`, `workerFk`, `dmsFk`,`isReadableByWorker`) VALUES (1, 1106, 4, TRUE), (2, 1107, 3, FALSE); @@ -2573,18 +2578,18 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate (DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), (util.VN_CURDATE(), 1, 12, 17, 22, 27); -INSERT INTO `vn`.`dua` (id, code, awbFk__, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) +INSERT INTO `vn`.`dua` (id, code, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) VALUES - (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), - (2, '21ES00280136115760', 2, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), - (3, '19ES00280131956004', 3, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 3, 14268.50, 442), - (4, '19ES00280131955995', 4, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 8242.50, 442), - (5, '19ES00280132022070', 5, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 10012.49, 442), - (6, '19ES00280132032308', 6, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 19914.25, 442), - (7, '19ES00280132025489', 7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1934.06, 442), - (8, '19ES00280132025490', 8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 3618.52, 442), - (9, '19ES00280132025491', 9, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), - (10, '19ES00280132025492', 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); + (1, '19ES0028013A481523', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), + (2, '21ES00280136115760', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), + (3, '19ES00280131956004', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 3, 14268.50, 442), + (4, '19ES00280131955995', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 8242.50, 442), + (5, '19ES00280132022070', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 10012.49, 442), + (6, '19ES00280132032308', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 19914.25, 442), + (7, '19ES00280132025489', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1934.06, 442), + (8, '19ES00280132025490', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 3618.52, 442), + (9, '19ES00280132025491', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), + (10, '19ES00280132025492', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroValue`) VALUES @@ -3057,9 +3062,6 @@ INSERT INTO `vn`.`workerTimeControlMail` (`id`, `workerFk`, `year`, `week`, `sta (3, 9, 2000, 51, 'CONFIRMED', util.VN_NOW(), 1, NULL), (4, 9, 2001, 1, 'SENDED', util.VN_NOW(), 1, NULL); -INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`) - VALUES - (1, 1350, 1900, 200, 50, 6); INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) VALUES @@ -3068,15 +3070,19 @@ INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) (3, 'green', '#00ff00'), (4, 'blue', '#0000ff'); +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`, `defaultTrayColorFk`) + VALUES + (1, 1350, 1900, 200, 50, 6, 1); + INSERT INTO `vn`.`wagonType` (`id`, `name`, `divisible`) VALUES (1, 'Wagon Type #1', 1); -INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) +INSERT INTO `vn`.`wagonTypeTray` (`id`, `wagonTypeFk`, `height`, `wagonTypeColorFk`) VALUES - (1, 1, 100, 1), + (1, 1, 0, 1), (2, 1, 50, 2), - (3, 1, 0, 3); + (3, 1, 100, 3); INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`) VALUES @@ -3931,44 +3937,38 @@ INSERT INTO vn.medicalReview (id, workerFk, centerFk, `date`, `time`, isFit, amount, invoice, remark) VALUES(3, 9, 2, '2000-01-01', '8:00', 1, 150.0, NULL, NULL); -INSERT INTO vn.payrollComponent -(id, name, isSalaryAgreed, isVariable, isException) - VALUES - (1, 'Salario1', 1, 0, 0), +INSERT INTO vn.stockBought (workerFk, bought, reserve, dated) + VALUES(35, 1.00, 1.00, '2001-01-01'); + +INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk) + VALUES (1,0.6,6); + +INSERT INTO vn.payrollComponent (id, name, isSalaryAgreed, isVariable, isException) + VALUES (1, 'Salario1', 1, 0, 0), (2, 'Salario2', 1, 1, 0), (3, 'Salario3', 1, 0, 1); - -INSERT INTO vn.workerIncome -(debit, credit, incomeTypeFk, paymentDate, workerFk, concept) - VALUES - (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), +INSERT INTO vn.workerIncome (debit, credit, incomeTypeFk, paymentDate, workerFk, concept) + VALUES (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), (1001.00, 800.00, 2, '2000-01-01', 1106, NULL); +INSERT INTO dipole.printer (id, description) VALUES(1, ''); -INSERT INTO dipole.printer (id, description) -VALUES(1, ''); +INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) + VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); -INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, -truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) -VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +INSERT INTO vn.accountDetail (id, value, accountDetailTypeFk, supplierAccountFk) + VALUES (21, 'ES12345B12345678', 3, 241), + (35, 'ES12346B12345679', 3, 241); -INSERT INTO vn.accountDetail -(id, value, accountDetailTypeFk, supplierAccountFk) -VALUES - (21, 'ES12345B12345678', 3, 241), - (35, 'ES12346B12345679', 3, 241); +INSERT INTO vn.accountDetailType (id, description, code) + VALUES (1, 'IBAN', 'iban'), + (2, 'SWIFT', 'swift'), + (3, 'Referencia Remesas', 'remRef'), + (4, 'Referencia Transferencias', 'trnRef'), + (5, 'Referencia Nominas', 'payRef'), + (6, 'ABA', 'aba'); -INSERT INTO vn.accountDetailType -(id, description, code) -VALUES - (1, 'IBAN', 'iban'), - (2, 'SWIFT', 'swift'), - (3, 'Referencia Remesas', 'remRef'), - (4, 'Referencia Transferencias', 'trnRef'), - (5, 'Referencia Nominas', 'payRef'), - (6, 'ABA', 'aba'); - -INSERT IGNORE INTO ormConfig +INSERT IGNORE INTO ormConfig SET id =1, selectLimit = 1000; diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index 20eee5d49..ea4adbc27 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -1,8 +1,22 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`( + vDateFrom DATE, + vDateTo DATE +) BEGIN - DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; - DECLARE vDateTo DATE DEFAULT vDateFrom + INTERVAL 6 DAY; +/** + * Recalcula las mermas de un periodo. + * + * @param vDateFrom Fecha desde + * @param vDateTo Fecha hasta + */ + IF vDateFrom IS NULL THEN + SET vDateFrom = util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; + END IF; + + IF vDateTo IS NULL THEN + SET vDateTo = vDateFrom + INTERVAL 6 DAY; + END IF; CALL cache.last_buy_refresh(FALSE); @@ -14,16 +28,32 @@ BEGIN s.itemFk, SUM((b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity), SUM(IF(aw.`type`, s.quantity, 0)), - SUM( - IF( - aw.`type` = 'internal', + SUM(IF( + aw.`type` = 'external', (b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity, 0 ) - ), - SUM( - IF( - aw.`type` = 'external', + ), + SUM(IF( + aw.`type` = 'fault', + (b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity, + 0 + ) + ), + SUM(IF( + aw.`type` = 'container', + (b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity, + 0 + ) + ), + SUM(IF( + aw.`type` = 'break', + (b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity, + 0 + ) + ), + SUM(IF( + aw.`type` = 'other', (b.buyingValue + b.freightValue + b.comissionValue + b.packageValue) * s.quantity, 0 ) @@ -40,6 +70,6 @@ BEGIN JOIN vn.buy b ON b.id = lb.buy_id WHERE t.shipped BETWEEN vDateFrom AND vDateTo AND w.isManaged - GROUP BY i.id; + GROUP BY YEAR(t.shipped), WEEK(t.shipped, 4), i.id; END$$ DELIMITER ; diff --git a/db/routines/bs/procedures/waste_addSalesLauncher.sql b/db/routines/bs/procedures/waste_addSalesLauncher.sql new file mode 100644 index 000000000..5eaea9be4 --- /dev/null +++ b/db/routines/bs/procedures/waste_addSalesLauncher.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSalesLauncher`() +BEGIN + CALL waste_addSales(NULL, NULL); +END$$ +DELIMITER ; diff --git a/db/routines/edi/events/floramondo.sql b/db/routines/edi/events/floramondo.sql deleted file mode 100644 index 0a38f3537..000000000 --- a/db/routines/edi/events/floramondo.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `edi`.`floramondo` - ON SCHEDULE EVERY 6 MINUTE - STARTS '2022-01-28 09:52:45.000' - ON COMPLETION NOT PRESERVE - DISABLE -DO CALL edi.floramondo_offerRefresh()$$ -DELIMITER ; diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql deleted file mode 100644 index 18d3f8b7e..000000000 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ /dev/null @@ -1,522 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() -proc: BEGIN - DECLARE vLanded DATETIME; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - DECLARE vDayRange INT; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); - SET @isTriggerDisabled = FALSE; - RESIGNAL; - END; - - IF 'test' = (SELECT environment FROM util.config) THEN - LEAVE proc; - END IF; - - IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN - LEAVE proc; - END IF; - - SELECT dayRange INTO vDayRange - FROM offerRefreshConfig; - - IF vDayRange IS NULL THEN - CALL util.throw("Variable vDayRange not declared"); - END IF; - - SET vStartingTime = util.VN_NOW(); - - TRUNCATE edi.offerList; - - INSERT INTO edi.offerList(supplier, total) - SELECT v.name, COUNT(DISTINCT sr.ID) total - FROM edi.supplyResponse sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - WHERE sr.NumberOfUnits > 0 - AND sr.EmbalageCode != 999 - GROUP BY sr.vmpID; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(*) total - FROM edi.supplyOffer sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.`filter` = sub.total; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - CREATE OR REPLACE TEMPORARY TABLE tmp - (INDEX (`Item_ArticleCode`)) - ENGINE = MEMORY - SELECT t.* - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, - NumberOfUnits DESC LIMIT 10000000000000000000) t - GROUP BY t.srId; - - CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, - ev1.type_description s1Value, - ev2.type_description s2Value, - ev3.type_description s3Value, - ev4.type_description s4Value, - ev5.type_description s5Value, - ev6.type_description s6Value, - eif1.feature ef1, - eif2.feature ef2, - eif3.feature ef3, - eif4.feature ef4, - eif5.feature ef5, - eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 - AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 - AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 - AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 - AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 - AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 - AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature - AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature - AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature - AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature - AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature - AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature - AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk - AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk - AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) - SET i.supplyResponseFk = o.srID - WHERE (sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - - CREATE OR REPLACE TEMPORARY TABLE itemToInsert - ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF vDone THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item(id, - `name`, - longName, - subName, - expenseFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - -- Inserta la foto de los articulos nuevos (prioridad alta) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL - AND i.image IS NULL; - - INSERT INTO edi.`log`(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - -- Inserta los tags sólo en los articulos nuevos - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.product_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.Quality IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.company_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s1Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s2Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s3Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s4Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s5Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s6Value IS NULL; - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id - AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - CREATE OR REPLACE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - DROP TABLE tmp.item; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF( - fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), - util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - 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.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); - - IF vLanded IS NOT NULL THEN - -- Actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask - OR b.buyingValue <> o.price); - - -- Inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy ( - entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packagingFk, - deliveryFk) - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask quantity, - o.Price, - o.NumberOfUnits etiquetas, - o.NumberOfItemsPerCask packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, - 'packing', - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id - LIKE o.embalageCode - LEFT JOIN vn.buy b ON b.itemFk = i.id - AND b.entryFk = wf.entryFk - WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL - - INSERT INTO vn.itemCost( - itemFk, - warehouseFk, - cm3, - cm3delivery) - SELECT b.itemFk, - wf.warehouseFk, - @cm3 := vn.buy_getUnitVolume(b.id), - IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) - FROM warehouseFloramondo wf - JOIN vn.volumeConfig vc - JOIN vn.buy b ON b.entryFk = wf.entryFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk - AND ic.warehouseFk = wf.warehouseFk - WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) - ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); - - CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'VNH' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.vnh = sub.total; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'ALGEMESI' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.algemesi = sub.total; - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - SET @isTriggerDisabled = FALSE; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - -- Refresca las fotos de los items existentes que mostramos (prioridad baja) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) - SELECT i.id, sr.PictureReference, 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN edi.supplyOffer so ON so.srId = sr.ID - JOIN hedera.image i2 ON i2.name = i.image - AND i2.collectionFk = 'catalog' - WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) - AND sr.NumberOfUnits; - - INSERT INTO edi.`log` - SET tableName = 'floramondo_offerRefresh', - fieldName = 'Tiempo de proceso', - fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); - - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/MIDNIGHT.sql b/db/routines/vn/functions/MIDNIGHT.sql deleted file mode 100644 index d40734fcf..000000000 --- a/db/routines/vn/functions/MIDNIGHT.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`MIDNIGHT`(vDate DATE) - RETURNS datetime - DETERMINISTIC -BEGIN - RETURN TIMESTAMP(vDate,'23:59:59'); -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/entry_getForLogiflora.sql b/db/routines/vn/functions/entry_getForLogiflora.sql deleted file mode 100644 index 57e787afa..000000000 --- a/db/routines/vn/functions/entry_getForLogiflora.sql +++ /dev/null @@ -1,64 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - /** - * Devuelve una entrada para Logiflora. Si no existe la crea. - * - * @param vLanded Fecha de llegada al almacén - * @param vWarehouseFk Identificador de vn.warehouse - */ - - DECLARE vTravelFk INT; - DECLARE vEntryFk INT; - DECLARE previousEntryFk INT; - - SET vTravelFk = vn.travel_getForLogiflora(vLanded, vWarehouseFk); - - IF vLanded THEN - - SELECT IFNULL(MAX(id),0) INTO vEntryFk - FROM vn.entry - WHERE travelFk = vTravelFk - AND isRaid; - - IF NOT vEntryFk THEN - - INSERT INTO vn.entry(travelFk, supplierFk, commission, companyFk, currencyFk, isRaid) - SELECT vTravelFk, s.id, 4, c.id, cu.id, TRUE - FROM vn.supplier s - JOIN vn.company c ON c.code = 'VNL' - JOIN vn.currency cu ON cu.code = 'EUR' - WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk - FROM vn.entry - WHERE travelFk = vTravelFk; - - END IF; - - END IF; - - SELECT entryFk INTO previousEntryFk - FROM edi.warehouseFloramondo wf - WHERE wf.warehouseFk = vWarehouseFk; - - IF IFNULL(previousEntryFk,0) != vEntryFk THEN - - UPDATE buy b - SET b.printedStickers = 0 - WHERE entryFk = previousEntryFk; - - DELETE FROM buy WHERE entryFk = previousEntryFk; - - DELETE FROM entry WHERE id = previousEntryFk; - - END IF; - - RETURN vEntryFk; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/routeProposal_.sql b/db/routines/vn/functions/routeProposal_.sql deleted file mode 100644 index a307d8fc0..000000000 --- a/db/routines/vn/functions/routeProposal_.sql +++ /dev/null @@ -1,30 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`routeProposal_`(vTicketFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - DECLARE vRouteFk INT; - DECLARE vAddressFk INT; - DECLARE vShipped DATETIME; - - SELECT addressFk, date(shipped) INTO vAddressFk, vShipped - FROM vn.ticket - WHERE id = vTicketFk; - - SELECT routeFk INTO vRouteFk - FROM - (SELECT t.routeFk, sum(af.friendship) friendshipSum - FROM vn.ticket t - JOIN cache.addressFriendship af ON af.addressFk2 = t.addressFk AND af.addressFk1 = vAddressFk - WHERE t.shipped BETWEEN vShipped and MIDNIGHT(vShipped) - AND t.routeFk - GROUP BY routeFk - ORDER BY friendshipSum DESC - ) sub - LIMIT 1; - - RETURN vRouteFk; -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/travel_getForLogiflora.sql b/db/routines/vn/functions/travel_getForLogiflora.sql deleted file mode 100644 index 39c3086b7..000000000 --- a/db/routines/vn/functions/travel_getForLogiflora.sql +++ /dev/null @@ -1,52 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) - RETURNS int(11) - NOT DETERMINISTIC - READS SQL DATA -BEGIN - - /** - * Devuelve un número de travel para compras de Logiflora a partir de la fecha de llegada y del almacén. - * Si no existe lo genera. - * - * @param vLanded Fecha de llegada al almacén - * @param vWarehouseFk Identificador de vn.warehouse - */ - - DECLARE vTravelFk INT; - - IF vLanded THEN - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - WHERE wIn.id = vWarehouseFk - AND wOut.name = 'Holanda' - AND am.name = 'LOGIFLORA' - AND landed = vLanded; - - IF NOT vTravelFk THEN - - INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) - SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id - FROM vn.warehouse wOut - JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' - WHERE wOut.name = 'Holanda'; - - SELECT MAX(tr.id) INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk - WHERE wIn.id = vWarehouseFk - AND wOut.name = 'Holanda' - AND landed = vLanded; - END IF; - - END IF; - - RETURN vTravelFk; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index a5a9a61c7..53f5500a0 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -167,7 +167,8 @@ BEGIN OR LENGTH(pb.problem) OR pb.lines > vLinesLimit OR pb.m3 > vVolumeLimit - OR sub.maxSize > vSizeLimit; + OR sub.maxSize > vSizeLimit + OR pb.hasPlantTray; END IF; -- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede diff --git a/db/routines/vn/procedures/creditInsurance_getRisk.sql b/db/routines/vn/procedures/creditInsurance_getRisk.sql index ea19f8aef..5562c91d4 100644 --- a/db/routines/vn/procedures/creditInsurance_getRisk.sql +++ b/db/routines/vn/procedures/creditInsurance_getRisk.sql @@ -10,7 +10,7 @@ BEGIN SELECT * FROM ( SELECT cc.client clientFk, ci.grade FROM creditClassification cc - JOIN creditInsurance ci ON cc.id = ci.creditClassification + JOIN creditInsurance ci ON cc.id = ci.creditClassificationFk WHERE dateEnd IS NULL ORDER BY ci.creationDate DESC LIMIT 10000000000000000000) t1 diff --git a/db/routines/vn/procedures/itemShelvingProblem.sql b/db/routines/vn/procedures/itemShelvingProblem.sql index bb4725434..06c7a376c 100644 --- a/db/routines/vn/procedures/itemShelvingProblem.sql +++ b/db/routines/vn/procedures/itemShelvingProblem.sql @@ -38,7 +38,7 @@ BEGIN AND IFNULL(sub3.transit,0) < s.quantity AND s.isPicked = FALSE AND s.reserved = FALSE - AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() AND tst.isPreviousPreparable = TRUE AND t.warehouseFk = vWarehouseFk AND iss.sectorFk = vSectorFk diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index fbb93c524..aa50f0ed8 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -75,6 +75,9 @@ proc: BEGIN WHERE saleFk = vSaleFk; IF vTotalReservedQuantity <> vSaleQuantity THEN + CALL util.debugAdd('itemShelvingSale_addBySale', + CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); + UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; @@ -93,7 +96,8 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - + CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', + CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); INSERT INTO itemShelvingSale( itemShelvingFk, saleFk, diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index 16e7713cd..92d1609e4 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -46,7 +46,8 @@ BEGIN AND buyFk = vBuyFk) THEN UPDATE itemShelving - SET visible = visible + vQuantity + SET visible = visible + vQuantity, + available = available + vQuantity WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE @@ -68,6 +69,6 @@ BEGIN id FROM buy b WHERE id = vBuyFk; - END IF; + END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 823625b97..b524e30a7 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -1,48 +1,64 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getSimilar`( - vSelf INT, - vWarehouseFk INT, - vDated DATE, - vShowType BOOL + vSelf INT, + vWarehouseFk INT, + vDated DATE, + vShowType BOOL, + vDaysInForward INT ) BEGIN /** -* Propone articulos disponibles ordenados, con la cantidad +* Propone articulos ordenados, con la cantidad * de veces usado y segun sus caracteristicas. * * @param vSelf Id de artículo * @param vWarehouseFk Id de almacen * @param vDated Fecha * @param vShowType Mostrar tipos +* @param vDaysInForward Días de alcance para las ventas */ - DECLARE vAvailableCalcFk INT; - DECLARE vVisibleCalcFk INT; - DECLARE vTypeFk INT; - DECLARE vPriority INT DEFAULT 1; + DECLARE vAvailableCalcFk INT; + DECLARE vPriority INT DEFAULT 1; - CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); - CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); + CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); - WITH itemTags AS ( - SELECT i.id, - typeFk, - tag5, - value5, - tag6, - value6, - tag7, - value7, - tag8, - value8, - t.name, - it.value + WITH itemTags AS ( + SELECT i.id, + typeFk, + tag5, + value5, + tag6, + value6, + tag7, + value7, + tag8, + value8, + t.name, + it.value FROM vn.item i LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk WHERE i.id = vSelf - ) - SELECT i.id itemFk, + ), + stock AS ( + SELECT itemFk, SUM(visible) stock + FROM vn.itemShelvingStock + WHERE warehouseFk = vWarehouseFk + GROUP BY itemFk + ), + sold AS ( + SELECT SUM(s.quantity) quantity, s.itemFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + WHERE t.shipped BETWEEN CURDATE() AND CURDATE() + INTERVAL vDaysInForward DAY + AND iss.saleFk IS NULL + AND t.warehouseFk = vWarehouseFk + GROUP BY s.itemFk + ) + SELECT i.id itemFk, + CAST(sd.quantity AS INT) advanceable, i.longName, i.subName, i.tag5, @@ -64,13 +80,13 @@ BEGIN WHEN b.groupingMode = 'packing' THEN b.packing ELSE 1 END minQuantity, - v.visible located, + sk.stock located, b.price2 FROM vn.item i + LEFT JOIN sold sd ON sd.itemFk = i.id JOIN cache.available a ON a.item_id = i.id AND a.calc_id = vAvailableCalcFk - LEFT JOIN cache.visible v ON v.item_id = i.id - AND v.calc_id = vVisibleCalcFk + LEFT JOIN stock sk ON sk.itemFk = i.id LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id @@ -80,20 +96,21 @@ BEGIN LEFT JOIN vn.tag t ON t.id = it.tagFk LEFT JOIN vn.buy b ON b.id = lb.buy_id JOIN itemTags its - WHERE a.available > 0 + WHERE (a.available > 0 OR sd.quantity < sk.stock) AND (i.typeFk = its.typeFk OR NOT vShowType) AND i.id <> vSelf - ORDER BY `counter` DESC, - (t.name = its.name) DESC, - (it.value = its.value) DESC, - (i.tag5 = its.tag5) DESC, - match5 DESC, - (i.tag6 = its.tag6) DESC, - match6 DESC, - (i.tag7 = its.tag7) DESC, - match7 DESC, - (i.tag8 = its.tag8) DESC, - match8 DESC + ORDER BY (a.available > 0) DESC, + `counter` DESC, + (t.name = its.name) DESC, + (it.value = its.value) DESC, + (i.tag5 = its.tag5) DESC, + match5 DESC, + (i.tag6 = its.tag6) DESC, + match6 DESC, + (i.tag7 = its.tag7) DESC, + match7 DESC, + (i.tag8 = its.tag8) DESC, + match8 DESC LIMIT 100; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index e5323e84e..3bd53c311 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -211,8 +211,6 @@ proc: BEGIN salesInParkingCount INT DEFAULT 0) ENGINE = MEMORY; - -- Insertamos todos los tickets que tienen productos parkineados - -- en sectores de previa, segun el sector CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock (PRIMARY KEY(itemFk, sectorFk)) ENGINE = MEMORY @@ -245,7 +243,6 @@ proc: BEGIN AND s.quantity > 0 GROUP BY pb.ticketFk; - -- Se calcula la cantidad de productos que estan ya preparados porque su saleGroup está aparcado UPDATE tmp.ticketWithPrevia twp JOIN ( SELECT pb.ticketFk, COUNT(DISTINCT s.id) salesInParkingCount @@ -259,12 +256,29 @@ proc: BEGIN ) sub ON twp.ticketFk = sub.ticketFk SET twp.salesInParkingCount = sub.salesInParkingCount; - -- Marcamos como pendientes aquellos que no coinciden las cantidades UPDATE tmp.productionBuffer pb JOIN tmp.ticketWithPrevia twp ON twp.ticketFk = pb.ticketFk SET pb.previousWithoutParking = TRUE WHERE twp.salesCount > twp.salesInParkingCount; + -- hasPlantTray + ALTER TABLE tmp.productionBuffer + ADD hasPlantTray BOOL DEFAULT FALSE; + + UPDATE tmp.productionBuffer pb + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN cache.last_buy lb ON lb.warehouse_id = vWarehouseFk AND lb.item_id = s.itemFk + JOIN buy b ON b.id = lb.buy_id + JOIN packaging p ON p.id = b.packagingFk + JOIN productionConfig pc + SET hasPlantTray = TRUE + WHERE ic.code = 'plant' + AND p.`depth` >= pc.minPlantTrayLength + AND pb.isOwn; + DROP TEMPORARY TABLE tmp.productionTicket, tmp.ticket, diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql index f61ec7ec9..ed6eff147 100644 --- a/db/routines/vn/procedures/productionSectorList.sql +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -55,7 +55,6 @@ BEGIN i.itemPackingTypeFk, isa.`size`, isa.Estado, - isa.sectorProdPriority, isa.available, isa.sectorFk, isa.matricula, diff --git a/db/routines/vn/procedures/sale_boxPickingPrint.sql b/db/routines/vn/procedures/sale_boxPickingPrint.sql index acb60ed31..6bb954a78 100644 --- a/db/routines/vn/procedures/sale_boxPickingPrint.sql +++ b/db/routines/vn/procedures/sale_boxPickingPrint.sql @@ -160,7 +160,10 @@ w1: WHILE vQuantity >= vPacking DO UPDATE sale SET quantity = quantity - vPacking WHERE id = vSaleFk; - UPDATE itemShelving SET visible = visible - vPacking WHERE id = vItemShelvingFk; + UPDATE itemShelving + SET visible = visible - vPacking, + available = available - vPacking + WHERE id = vItemShelvingFk; SET vNewSaleFk = NULL; diff --git a/db/routines/vn/procedures/stockBought_calculate.sql b/db/routines/vn/procedures/stockBought_calculate.sql new file mode 100644 index 000000000..6eabe015c --- /dev/null +++ b/db/routines/vn/procedures/stockBought_calculate.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`() +BEGIN +/** + * Inserts the purchase volume per buyer + * into stockBought according to the current date. + */ + DECLARE vDated DATE; + SET vDated = util.VN_CURDATE(); + + CREATE OR REPLACE TEMPORARY TABLE tStockBought + SELECT workerFk, reserve + FROM stockBought + WHERE dated = vDated + AND reserve; + + DELETE FROM stockBought WHERE dated = vDated; + + INSERT INTO stockBought (workerFk, bought, dated) + SELECT it.workerFk, + ROUND(SUM( + (ac.conversionCoefficient * + (b.quantity / b.packing) * + buy_getVolume(b.id) + ) / (vc.trolleyM3 * 1000000) + ), 1), + vDated + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + 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 auctionConfig ac + JOIN volumeConfig vc + WHERE t.shipped = vDated + AND t.warehouseInFk = ac.warehouseFk + GROUP BY it.workerFk; + + UPDATE stockBought s + JOIN tStockBought ts ON ts.workerFk = s.workerFk + SET s.reserve = ts.reserve + WHERE s.dated = vDated; + + INSERT INTO stockBought (workerFk, reserve, dated) + SELECT ts.workerFk, ts.reserve, vDated + FROM tStockBought ts + WHERE ts.workerFk NOT IN (SELECT workerFk FROM stockBought WHERE dated = vDated); + + DROP TEMPORARY TABLE tStockBought; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index df3b918a7..55b271296 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -17,14 +17,14 @@ BEGIN * @param vOrderBy Order by criteria * @param vIsConciliated Indicates whether it is reconciled or not * @param vHasEntries Indicates if future entries must be shown -* @return tmp.supplierStatement +* @return tmp.supplierStatement */ DECLARE vBalanceStartingDate DATETIME; SET @euroBalance:= 0; SET @currencyBalance:= 0; - SELECT balanceStartingDate + SELECT balanceStartingDate INTO vBalanceStartingDate FROM invoiceInConfig; @@ -64,14 +64,14 @@ BEGIN c.code, 'invoiceIn' statementType FROM invoiceIn ii - JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id + LEFT JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id JOIN currency c ON c.id = ii.currencyFk WHERE ii.issued >= vBalanceStartingDate - AND ii.supplierFk = vSupplierFk + AND ii.supplierFk = vSupplierFk AND vCurrencyFk IN (ii.currencyFk, 0) AND vCompanyFk IN (ii.companyFk, 0) AND (vIsConciliated = ii.isBooked OR NOT vIsConciliated) - GROUP BY iid.id + GROUP BY iid.id, ii.id UNION ALL SELECT p.bankFk, p.companyFk, @@ -107,7 +107,7 @@ BEGIN AND vCurrencyFk IN (p.currencyFk, 0) AND vCompanyFk IN (p.companyFk, 0) AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) - UNION ALL + UNION ALL SELECT NULL, companyFk, NULL, @@ -134,7 +134,7 @@ BEGIN AND vCurrencyFk IN (se.currencyFk,0) AND vCompanyFk IN (se.companyFk,0) AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) - UNION ALL + UNION ALL SELECT NULL bankFk, e.companyFk, 'E' serial, @@ -150,7 +150,7 @@ BEGIN FALSE isBooked, c.code, 'order' - FROM entry e + FROM entry e JOIN travel tr ON tr.id = e.travelFk JOIN currency c ON c.id = e.currencyFk WHERE e.supplierFk = vSupplierFk diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql index 8bf2c4d80..1851bce47 100644 --- a/db/routines/vn/procedures/ticket_getProblems.sql +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -36,7 +36,7 @@ BEGIN UPDATE tmp.ticket_problems SET totalProblems = ( (isFreezed) + - (hasRisk) + + (hasHighRisk) + (hasTicketRequest) + (!isTaxDataChecked) + (hasComponentLack) + diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index b5b77d2ef..407b8cdde 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -10,6 +10,7 @@ BEGIN * * @param vSelf Id ticket * @param vOriginalItemPackingTypeFk Tipo empaquetado al que se mantiene el ticket original + * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) */ DECLARE vDone INT DEFAULT FALSE; DECLARE vHasItemPackingType BOOL; @@ -72,6 +73,16 @@ BEGIN SET s.ticketFk = stm.ticketFk WHERE stm.ticketFk; + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT( + ticketFk INT, + itemPackingTypeFk VARCHAR(1) + ) ENGINE=MEMORY + SELECT ticketFk, itemPackingTypeFk + FROM tSalesToMove + GROUP BY ticketFk + UNION + SELECT vSelf, vOriginalItemPackingTypeFk; + DROP TEMPORARY TABLE tSalesToMove; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/creditInsurance_afterInsert.sql b/db/routines/vn/triggers/creditInsurance_afterInsert.sql index c865f31a4..f4857a730 100644 --- a/db/routines/vn/triggers/creditInsurance_afterInsert.sql +++ b/db/routines/vn/triggers/creditInsurance_afterInsert.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`creditInsurance_afterIn BEGIN UPDATE `client` c JOIN vn.creditClassification cc ON cc.client = c.id - SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; + SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassificationFk; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/creditInsurance_beforeInsert.sql b/db/routines/vn/triggers/creditInsurance_beforeInsert.sql deleted file mode 100644 index 8e036d373..000000000 --- a/db/routines/vn/triggers/creditInsurance_beforeInsert.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`creditInsurance_beforeInsert` - BEFORE INSERT ON `creditInsurance` - FOR EACH ROW -BEGIN - IF NEW.creditClassificationFk THEN - SET NEW.creditClassification = NEW.creditClassificationFk; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index ee2178024..8e5a326a0 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -71,7 +71,10 @@ BEGIN SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); END IF; - IF NOT (NEW.travelFk <=> OLD.travelFk) OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN + IF NOT (NEW.travelFk <=> OLD.travelFk) + OR NOT (NEW.currencyFk <=> OLD.currencyFk) + OR NOT (NEW.supplierFk <=> OLD.supplierFk) THEN + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk, NEW.supplierFk); END IF; END$$ diff --git a/db/routines/vn/triggers/solunionCAP_afterInsert.sql b/db/routines/vn/triggers/solunionCAP_afterInsert.sql index b4df7dc61..d09cadd95 100644 --- a/db/routines/vn/triggers/solunionCAP_afterInsert.sql +++ b/db/routines/vn/triggers/solunionCAP_afterInsert.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`solunionCAP_afterInsert BEGIN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_afterUpdate.sql b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql index ccfba96f2..1199067bb 100644 --- a/db/routines/vn/triggers/solunionCAP_afterUpdate.sql +++ b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql @@ -6,12 +6,12 @@ BEGIN IF NEW.dateLeaving IS NOT NULL THEN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; ELSE UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; END IF; END$$ diff --git a/db/routines/vn/triggers/solunionCAP_beforeDelete.sql b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql index a8b6732c1..7913a0d78 100644 --- a/db/routines/vn/triggers/solunionCAP_beforeDelete.sql +++ b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`solunionCAP_beforeDelet BEGIN UPDATE client c JOIN creditClassification cc ON cc.client = c.id - JOIN creditInsurance ci ON ci.creditClassification = cc.id + JOIN creditInsurance ci ON ci.creditClassificationFk = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/workerDocument_afterDelete.sql b/db/routines/vn/triggers/workerDms_afterDelete.sql similarity index 71% rename from db/routines/vn/triggers/workerDocument_afterDelete.sql rename to db/routines/vn/triggers/workerDms_afterDelete.sql index 8d4878248..bfb7d481e 100644 --- a/db/routines/vn/triggers/workerDocument_afterDelete.sql +++ b/db/routines/vn/triggers/workerDms_afterDelete.sql @@ -1,11 +1,11 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_afterDelete` - AFTER DELETE ON `workerDocument` +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_afterDelete` + AFTER DELETE ON `workerDms` FOR EACH ROW BEGIN INSERT INTO workerLog SET `action` = 'delete', - `changedModel` = 'WorkerDocument', + `changedModel` = 'WorkerDms', `changedModelId` = OLD.id, `userFk` = account.myUser_getId(); END$$ diff --git a/db/routines/vn/triggers/workerDocument_beforeInsert.sql b/db/routines/vn/triggers/workerDms_beforeInsert.sql similarity index 73% rename from db/routines/vn/triggers/workerDocument_beforeInsert.sql rename to db/routines/vn/triggers/workerDms_beforeInsert.sql index f0675e68f..a52c60961 100644 --- a/db/routines/vn/triggers/workerDocument_beforeInsert.sql +++ b/db/routines/vn/triggers/workerDms_beforeInsert.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeInsert` - BEFORE INSERT ON `workerDocument` +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeInsert` + BEFORE INSERT ON `workerDms` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); diff --git a/db/routines/vn/triggers/workerDocument_beforeUpdate.sql b/db/routines/vn/triggers/workerDms_beforeUpdate.sql similarity index 73% rename from db/routines/vn/triggers/workerDocument_beforeUpdate.sql rename to db/routines/vn/triggers/workerDms_beforeUpdate.sql index ffb6efd74..564064444 100644 --- a/db/routines/vn/triggers/workerDocument_beforeUpdate.sql +++ b/db/routines/vn/triggers/workerDms_beforeUpdate.sql @@ -1,6 +1,6 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDocument_beforeUpdate` - BEFORE UPDATE ON `workerDocument` +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerDms_beforeUpdate` + BEFORE UPDATE ON `workerDms` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); diff --git a/db/routines/vn/views/buyer.sql b/db/routines/vn/views/buyer.sql index 4f668d35d..e690dc16f 100644 --- a/db/routines/vn/views/buyer.sql +++ b/db/routines/vn/views/buyer.sql @@ -2,10 +2,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`buyer` AS SELECT DISTINCT `u`.`id` AS `userFk`, - `u`.`nickname` AS `nickname` + `u`.`nickname` AS `nickname`, + `ic`.`display` AS `display` FROM ( `account`.`user` `u` JOIN `vn`.`itemType` `it` ON(`it`.`workerFk` = `u`.`id`) + JOIN `vn`.`itemCategory` `ic` ON(`ic`.`id` = `it`.`categoryFk`) ) WHERE `u`.`active` <> 0 ORDER BY `u`.`nickname` diff --git a/db/routines/vn/views/itemShelvingAvailable.sql b/db/routines/vn/views/itemShelvingAvailable.sql index 561569285..15083e6cc 100644 --- a/db/routines/vn/views/itemShelvingAvailable.sql +++ b/db/routines/vn/views/itemShelvingAvailable.sql @@ -10,7 +10,6 @@ AS SELECT `s`.`id` AS `saleFk`, `s`.`concept` AS `concept`, `i`.`size` AS `size`, `st`.`name` AS `Estado`, - `st`.`sectorProdPriority` AS `sectorProdPriority`, `stock`.`visible` AS `available`, `stock`.`sectorFk` AS `sectorFk`, `stock`.`shelvingFk` AS `matricula`, diff --git a/db/routines/vn/views/ticketStateToday.sql b/db/routines/vn/views/ticketStateToday.sql index 0c9e01188..8c11fcc87 100644 --- a/db/routines/vn/views/ticketStateToday.sql +++ b/db/routines/vn/views/ticketStateToday.sql @@ -13,4 +13,4 @@ FROM ( `vn`.`ticketState` `ts` JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ts`.`ticketFk`) ) -WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()) +WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`midnight`() diff --git a/db/routines/vn2008/views/Articles.sql b/db/routines/vn2008/views/Articles.sql index 385bf310b..87f1b6d5e 100644 --- a/db/routines/vn2008/views/Articles.sql +++ b/db/routines/vn2008/views/Articles.sql @@ -41,7 +41,6 @@ AS SELECT `i`.`id` AS `Id_Article`, `i`.`hasKgPrice` AS `hasKgPrice`, `i`.`equivalent` AS `Equivalente`, `i`.`isToPrint` AS `Imprimir`, - `i`.`family` AS `Familia__`, `i`.`doPhoto` AS `do_photo`, `i`.`created` AS `odbc_date`, `i`.`isFloramondo` AS `isFloramondo`, diff --git a/db/routines/vn2008/views/state.sql b/db/routines/vn2008/views/state.sql index 63f6589af..9f7fcccd8 100644 --- a/db/routines/vn2008/views/state.sql +++ b/db/routines/vn2008/views/state.sql @@ -6,7 +6,6 @@ AS SELECT `s`.`id` AS `id`, `s`.`order` AS `order`, `s`.`alertLevel` AS `alert_level`, `s`.`code` AS `code`, - `s`.`sectorProdPriority` AS `sectorProdPriority`, `s`.`nextStateFk` AS `nextStateFk`, `s`.`isPreviousPreparable` AS `isPreviousPreparable`, `s`.`isPicked` AS `isPicked` diff --git a/db/versions/11088-bronzeAspidistra/00-firstScript.sql b/db/versions/11088-bronzeAspidistra/00-firstScript.sql new file mode 100644 index 000000000..5c56993fd --- /dev/null +++ b/db/versions/11088-bronzeAspidistra/00-firstScript.sql @@ -0,0 +1,19 @@ +ALTER TABLE vn.collectionWagonTicket DROP FOREIGN KEY IF EXISTS collectionWagonTicket_tray; +ALTER TABLE vn.wagonConfig DROP FOREIGN KEY IF EXISTS wagonConfig_wagonTypeColor_FK; +CREATE OR REPLACE TABLE vn.wagonTypeTray ( + id INT(11) UNSIGNED auto_increment, + wagonTypeFk INT(11) UNSIGNED NULL, + height INT(11) UNSIGNED NULL, + wagonTypeColorFk int(11) UNSIGNED NULL, + CONSTRAINT wagonTypeTray_pk PRIMARY KEY (id), + CONSTRAINT wagonTypeTray_wagonType_FK FOREIGN KEY (wagonTypeFk) REFERENCES vn.wagonType(id) ON DELETE CASCADE ON UPDATE RESTRICT, + CONSTRAINT wagonTypeTray_wagonTypeColor_FK FOREIGN KEY (wagonTypeColorFk) REFERENCES vn.wagonTypeColor(id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultHeight INT UNSIGNED DEFAULT 0 NULL COMMENT 'Default height in cm for a base tray'; +ALTER TABLE vn.wagonConfig ADD IF NOT EXISTS defaultTrayColorFk int(11) UNSIGNED NULL COMMENT 'Default color for a base tray'; +ALTER TABLE vn.wagonConfig ADD CONSTRAINT wagonConfig_wagonTypeColor_FK FOREIGN KEY (defaultTrayColorFk) REFERENCES vn.wagonTypeColor(id); +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_tray FOREIGN KEY (trayFk) REFERENCES vn.wagonTypeTray(id); diff --git a/db/versions/11113-bronzeDendro/00-firstScript.sql b/db/versions/11113-bronzeDendro/00-firstScript.sql new file mode 100644 index 000000000..63db65378 --- /dev/null +++ b/db/versions/11113-bronzeDendro/00-firstScript.sql @@ -0,0 +1,16 @@ +ALTER TABLE IF EXISTS `vn`.`payrollWorker` + MODIFY COLUMN IF EXISTS `nss__` varchar(23) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codpuesto__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codcontrato__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `FAntiguedad__` date NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `grupotarifa__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `codcategoria__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `ContratoTemporal__` tinyint(1) NOT NULL DEFAULT 0 COMMENT '@deprecated 2024-03-15'; + +ALTER TABLE IF EXISTS `vn`.`payrollWorkCenter` + MODIFY COLUMN IF EXISTS `Centro__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `nss_cotizacion__` varchar(15) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `domicilio__` varchar(255) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `poblacion__` varchar(45) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `cp__` varchar(5) NOT NULL COMMENT '@deprecated 2024-03-15', + MODIFY COLUMN IF EXISTS `empresa_id__` int(10) NOT NULL COMMENT '@deprecated 2024-03-15'; diff --git a/db/versions/11115-turquoiseRose/00-firstScript.sql b/db/versions/11115-turquoiseRose/00-firstScript.sql new file mode 100644 index 000000000..3982936fc --- /dev/null +++ b/db/versions/11115-turquoiseRose/00-firstScript.sql @@ -0,0 +1,30 @@ +-- Place your SQL code here +-- vn.stockBought definition + +CREATE TABLE IF NOT EXISTS vn.stockBought ( + id INT UNSIGNED auto_increment NOT NULL, + workerFk int(10) unsigned NOT NULL, + bought decimal(10,2) NOT NULL COMMENT 'purchase volume in m3 for the day', + reserve decimal(10,2) NULL COMMENT 'reserved volume in m3 for the day', + dated DATE NOT NULL DEFAULT current_timestamp(), + CONSTRAINT stockBought_pk PRIMARY KEY (id), + CONSTRAINT stockBought_unique UNIQUE KEY (workerFk,dated), + CONSTRAINT stockBought_worker_FK FOREIGN KEY (workerFk) REFERENCES vn.worker(id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + + +INSERT IGNORE vn.stockBought (workerFk, bought, reserve, dated) + SELECT userFk, SUM(buyed), SUM(IFNULL(reserved,0)), dated + FROM vn.stockBuyed + WHERE userFk IS NOT NULL + AND buyed IS NOT NULL + GROUP BY userFk, dated; + +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('StockBought','*','READ','ALLOW','ROLE','buyer'), + ('StockBought','*','WRITE','ALLOW','ROLE','buyer'), + ('Buyer','*','READ','ALLOW','ROLE','buyer'); + diff --git a/db/versions/11210-greenDendro/00-firstScript.sql b/db/versions/11210-greenDendro/00-firstScript.sql new file mode 100644 index 000000000..58e6450d6 --- /dev/null +++ b/db/versions/11210-greenDendro/00-firstScript.sql @@ -0,0 +1,8 @@ +ALTER TABLE util.config + CHANGE dbVersion dbVersion__ char(11) DEFAULT NULL COMMENT '@deprecated 2024-09-02 refs #7819'; + +ALTER TABLE util.config + CHANGE hasTriggersDisabled hasTriggersDisabled__ tinyint(1) DEFAULT 0 NOT NULL COMMENT '@deprecated 2024-09-02 refs #7819'; + +RENAME TABLE account.accountLog TO account.accountLog__; + ALTER TABLE account.accountLog__ COMMENT='@deprecated 2024-09-02 refs #7819'; diff --git a/db/versions/11210-greenDendro/01-firstScript.sql b/db/versions/11210-greenDendro/01-firstScript.sql new file mode 100644 index 000000000..787011343 --- /dev/null +++ b/db/versions/11210-greenDendro/01-firstScript.sql @@ -0,0 +1 @@ +DROP DATABASE IF EXISTS `.mysqlworkbench`; \ No newline at end of file diff --git a/db/versions/11210-greenDendro/02-firstScript.sql b/db/versions/11210-greenDendro/02-firstScript.sql new file mode 100644 index 000000000..2603c5df5 --- /dev/null +++ b/db/versions/11210-greenDendro/02-firstScript.sql @@ -0,0 +1,84 @@ +ALTER TABLE bi.rutasBoard DROP COLUMN coste_bulto__; +ALTER TABLE bi.rutasBoard DROP COLUMN Dia__; +ALTER TABLE bi.rutasBoard DROP COLUMN km__; +ALTER TABLE bi.rutasBoard DROP COLUMN m3__; +ALTER TABLE bi.rutasBoard DROP COLUMN Matricula__; +ALTER TABLE bi.rutasBoard DROP COLUMN month__; +ALTER TABLE bi.rutasBoard DROP COLUMN Terceros__; +ALTER TABLE bi.rutasBoard DROP COLUMN Tipo__; +ALTER TABLE bi.rutasBoard DROP COLUMN warehouse_id__; +ALTER TABLE bi.rutasBoard DROP COLUMN year__; + +ALTER TABLE bs.clientDied DROP COLUMN Boss__; +ALTER TABLE bs.clientDied DROP COLUMN clientName__; +ALTER TABLE bs.clientDied DROP COLUMN workerCode__; + +ALTER TABLE bs.salesByItemTypeDay DROP COLUMN netSale__; + +ALTER TABLE vn.agency DROP FOREIGN KEY agency_FK; +ALTER TABLE vn.agency DROP COLUMN warehouseAliasFk__; + +ALTER TABLE vn.awbComponent DROP COLUMN dated__; + +ALTER TABLE vn.buy DROP COLUMN containerFk__; + +ALTER TABLE vn.chat DROP COLUMN status__; + +ALTER TABLE vn.claim DROP COLUMN rma__; + +ALTER TABLE vn.client DROP COLUMN clientTypeFk__; +ALTER TABLE vn.client DROP COLUMN hasIncoterms__; + +ALTER TABLE vn.clientType DROP COLUMN id__; + +ALTER TABLE vn.cmr DROP FOREIGN KEY cmr_fk1; +ALTER TABLE vn.cmr DROP COLUMN ticketFk__; + +ALTER TABLE vn.company DROP COLUMN sage200Company__; + +ALTER TABLE vn.country DROP FOREIGN KEY country_FK; +ALTER TABLE vn.country DROP COLUMN politicalCountryFk__; + +ALTER TABLE vn.deliveryNote DROP FOREIGN KEY albaran_FK; +ALTER TABLE vn.deliveryNote DROP COLUMN farmingFk__; + +ALTER TABLE vn.dmsType DROP COLUMN path__; + +ALTER TABLE vn.dua DROP COLUMN awbFk__; + +ALTER TABLE vn.entry DROP COLUMN isBlocked__; + +ALTER TABLE vn.expedition DROP COLUMN itemFk__; + +ALTER TABLE vn.item DROP COLUMN minQuantity__; +ALTER TABLE vn.item DROP COLUMN packingShelve__; + +ALTER TABLE vn.itemType DROP COLUMN compression__; +ALTER TABLE vn.itemType DROP COLUMN density__; +ALTER TABLE vn.itemType DROP COLUMN hasComponents__; +ALTER TABLE vn.itemType DROP COLUMN location__; +ALTER TABLE vn.itemType DROP COLUMN maneuver__; +ALTER TABLE vn.itemType DROP COLUMN profit__; +ALTER TABLE vn.itemType DROP COLUMN target__; +ALTER TABLE vn.itemType DROP COLUMN topMargin__; +ALTER TABLE vn.itemType DROP COLUMN transaction__; +ALTER TABLE vn.itemType DROP FOREIGN KEY warehouseFk5; +ALTER TABLE vn.itemType DROP COLUMN warehouseFk__; + +ALTER TABLE vn.ledgerConfig DROP COLUMN lastBookEntry__; + +ALTER TABLE vn.saleTracking DROP FOREIGN KEY saleTracking_FK_1; +ALTER TABLE vn.saleTracking DROP COLUMN actionFk__; + +ALTER TABLE vn.supplier DROP COLUMN isFarmer__; + +ALTER TABLE vn.supplierAccount DROP COLUMN description__; + +ALTER TABLE vn.ticketRequest DROP COLUMN buyerCode__; + +ALTER TABLE vn.travel DROP COLUMN agencyFk__; + +ALTER TABLE vn.warehouse DROP FOREIGN KEY warehouse_ibfk_2; +ALTER TABLE vn.warehouse DROP COLUMN aliasFk__; + +ALTER TABLE vn.worker DROP COLUMN labelerFk__; diff --git a/db/versions/11210-greenDendro/03-firstScript.sql b/db/versions/11210-greenDendro/03-firstScript.sql new file mode 100644 index 000000000..f8157b756 --- /dev/null +++ b/db/versions/11210-greenDendro/03-firstScript.sql @@ -0,0 +1,21 @@ +DROP TABLE IF EXISTS account.mailClientAccess__; +DROP TABLE IF EXISTS account.mailSenderAccess__; +DROP TABLE IF EXISTS bi.analisis_ventas_familia_evolution__; +DROP TABLE IF EXISTS bi.live_counter__; +DROP TABLE IF EXISTS bi.partitioning_information__; +DROP TABLE IF EXISTS bi.primer_pedido__; +DROP TABLE IF EXISTS bi.tarifa_premisas__; +DROP TABLE IF EXISTS bi.tarifa_warehouse__; +DROP TABLE IF EXISTS bs.compradores__; +DROP TABLE IF EXISTS bs.salesMonthlySnapshot___; +DROP TABLE IF EXISTS bs.salesPerson__; +DROP TABLE IF EXISTS bs.vendedores_evolution__; +DROP TABLE IF EXISTS vn.botanicExport__; +DROP TABLE IF EXISTS vn.claimRma__; +DROP TABLE IF EXISTS vn.coolerPathDetail__; +DROP TABLE IF EXISTS vn.forecastedBalance__; +DROP TABLE IF EXISTS vn.routeLoadWorker__; +DROP TABLE IF EXISTS vn.routeUserPercentage__; +DROP TABLE IF EXISTS vn.ticketSms__; +DROP TABLE IF EXISTS vn.ticketTrackingState__; +DROP TABLE IF EXISTS vn.warehouseAlias__; diff --git a/db/versions/11222-azureCordyline/00-firstScript.sql b/db/versions/11222-azureCordyline/00-firstScript.sql new file mode 100644 index 000000000..c63228911 --- /dev/null +++ b/db/versions/11222-azureCordyline/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.state DROP COLUMN sectorProdPriority; diff --git a/db/versions/11223-turquoiseLilium/00-firstScript.sql b/db/versions/11223-turquoiseLilium/00-firstScript.sql new file mode 100644 index 000000000..9003451c4 --- /dev/null +++ b/db/versions/11223-turquoiseLilium/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES( 'Device', 'handleUser', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/versions/11224-whiteMastic/00-firstScript.sql b/db/versions/11224-whiteMastic/00-firstScript.sql new file mode 100644 index 000000000..de74dfc55 --- /dev/null +++ b/db/versions/11224-whiteMastic/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.creditInsurance DROP FOREIGN KEY CreditInsurance_Fk1; +ALTER TABLE vn.creditInsurance + CHANGE creditClassification creditClassification__ int(11) DEFAULT NULL COMMENT '@deprecated 2024-09-11'; diff --git a/db/versions/11225-goldenLaurel/00-firstScript.sql b/db/versions/11225-goldenLaurel/00-firstScript.sql new file mode 100644 index 000000000..87f521a03 --- /dev/null +++ b/db/versions/11225-goldenLaurel/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.workerDocument CHANGE worker workerFk int(10) unsigned DEFAULT NULL NULL; diff --git a/db/versions/11225-goldenLaurel/01-firstScript.sql b/db/versions/11225-goldenLaurel/01-firstScript.sql new file mode 100644 index 000000000..3aa3a1876 --- /dev/null +++ b/db/versions/11225-goldenLaurel/01-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.workerDocument CHANGE document dmsFk int(11) DEFAULT NULL NULL; diff --git a/db/versions/11225-goldenLaurel/02-firstScript.sql b/db/versions/11225-goldenLaurel/02-firstScript.sql new file mode 100644 index 000000000..d0e789534 --- /dev/null +++ b/db/versions/11225-goldenLaurel/02-firstScript.sql @@ -0,0 +1 @@ +RENAME TABLE vn.workerDocument TO vn.workerDms; diff --git a/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql b/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql new file mode 100644 index 000000000..330dcb839 --- /dev/null +++ b/db/versions/11227-maroonEucalyptus/00-addWorkerTimeControlMailAcl.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES ('WorkerTimeControlMail', 'count', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('Worker', '__get__mail', 'READ', 'ALLOW', 'ROLE', 'hr'); diff --git a/db/versions/11229-salmonAsparagus/00-firstScript.sql b/db/versions/11229-salmonAsparagus/00-firstScript.sql new file mode 100644 index 000000000..80547db38 --- /dev/null +++ b/db/versions/11229-salmonAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.productionConfig ADD IF NOT EXISTS minPlantTrayLength INT DEFAULT 53 NOT NULL +COMMENT 'minimum length for plant tray restriction. Avoid to make collection of the ticket with this kind of item'; diff --git a/db/versions/11234-yellowRuscus/00-firstScript.sql b/db/versions/11234-yellowRuscus/00-firstScript.sql new file mode 100644 index 000000000..2cbac598b --- /dev/null +++ b/db/versions/11234-yellowRuscus/00-firstScript.sql @@ -0,0 +1,13 @@ +ALTER TABLE `vn`.`payrollWorkCenter` DROP PRIMARY KEY; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `empresa_id__`; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `Centro__`; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `nss_cotizacion__`; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `domicilio__`; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `poblacion__`; +ALTER TABLE `vn`.`payrollWorkCenter` DROP COLUMN `cp__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `nss__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `codpuesto__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `codcontrato__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `FAntiguedad__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `codcategoria__`; +ALTER TABLE `vn`.`payrollWorker` DROP COLUMN `ContratoTemporal__`; diff --git a/db/versions/11235-purpleCordyline/00-firstScript.sql b/db/versions/11235-purpleCordyline/00-firstScript.sql new file mode 100644 index 000000000..f3bb6ddab --- /dev/null +++ b/db/versions/11235-purpleCordyline/00-firstScript.sql @@ -0,0 +1,12 @@ +ALTER TABLE vn.collectionWagon DROP FOREIGN KEY IF EXISTS collectionWagon_FK_1; +ALTER TABLE vn.collectionWagonTicket DROP FOREIGN KEY IF EXISTS collectionWagonTicket_FK_1; +ALTER TABLE vn.wagonVolumetry DROP FOREIGN KEY IF EXISTS wagonVolumetry_FK_1; + +ALTER TABLE vn.wagon MODIFY COLUMN id int(11) unsigned auto_increment NOT NULL COMMENT '26 letras de alfabeto inglés'; +ALTER TABLE vn.collectionWagon MODIFY COLUMN wagonFk int(11) unsigned NOT NULL; +ALTER TABLE vn.collectionWagonTicket MODIFY COLUMN wagonFk int(11) unsigned NOT NULL; +ALTER TABLE vn.wagonVolumetry MODIFY COLUMN wagonFk int(11) unsigned NOT NULL; + +ALTER TABLE vn.collectionWagon ADD CONSTRAINT collectionWagon_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.wagonVolumetry ADD CONSTRAINT wagonVolumetry_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/11236-blackMedeola/00-firstScript.sql b/db/versions/11236-blackMedeola/00-firstScript.sql new file mode 100644 index 000000000..8729e40e1 --- /dev/null +++ b/db/versions/11236-blackMedeola/00-firstScript.sql @@ -0,0 +1,19 @@ +ALTER TABLE vn.addressWaste + MODIFY COLUMN `type` enum('external', 'fault', 'container', 'break', 'other') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; + +UPDATE vn.addressWaste + SET `type`='container' + WHERE addressFk=77; + +UPDATE vn.addressWaste + SET `type`='fault' + WHERE addressFk=317; + +UPDATE vn.addressWaste + SET `type`='break' + WHERE addressFk=57702; + +UPDATE vn.addressWaste + SET `type`='other' + WHERE addressFk=43432; diff --git a/db/versions/11236-blackMedeola/01-firstScript.sql b/db/versions/11236-blackMedeola/01-firstScript.sql new file mode 100644 index 000000000..87262115b --- /dev/null +++ b/db/versions/11236-blackMedeola/01-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE bs.waste + DROP COLUMN saleInternalWaste, + ADD saleFaultWaste decimal(10,2) DEFAULT NULL NULL, + ADD saleContainerWaste decimal(10,2) DEFAULT NULL NULL, + ADD saleBreakWaste decimal(10,2) DEFAULT NULL NULL, + ADD saleOtherWaste decimal(10,2) DEFAULT NULL NULL; diff --git a/db/versions/11237-goldenBamboo/00-firstScript.sql b/db/versions/11237-goldenBamboo/00-firstScript.sql new file mode 100644 index 000000000..3e387eba8 --- /dev/null +++ b/db/versions/11237-goldenBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ +UPDATE bs.nightTask + SET `procedure` = 'waste_addSalesLauncher' + WHERE `procedure` = 'waste_addSales'; diff --git a/db/versions/11240-aquaCyca/00-firstScript.sql b/db/versions/11240-aquaCyca/00-firstScript.sql new file mode 100644 index 000000000..97ad39ef1 --- /dev/null +++ b/db/versions/11240-aquaCyca/00-firstScript.sql @@ -0,0 +1 @@ +GRANT EXECUTE ON PROCEDURE bs.waste_addSales TO buyerBoss; diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index 1caf91f9c..370d422e6 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -19,7 +19,7 @@ describe('Ticket descriptor path', () => { it('should count the amount of tickets in the turns section', async() => { const result = await page.countElement(selectors.ticketsIndex.weeklyTicket); - expect(result).toEqual(5); + expect(result).toEqual(6); }); it('should go back to the ticket index then search and access a ticket summary', async() => { @@ -106,7 +106,7 @@ describe('Ticket descriptor path', () => { await page.doSearch(); const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); - expect(nResults).toEqual(5); + expect(nResults).toEqual(6); }); it('should update the agency then remove it afterwards', async() => { diff --git a/loopback/locale/en.json b/loopback/locale/en.json index d9d9c8511..352e08826 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -235,7 +235,10 @@ "Cannot add holidays on this day": "Cannot add holidays on this day", "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", + "Original invoice not found": "Original invoice not found", + "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", "This postcode already exists": "This postcode already exists", - "Original invoice not found": "Original invoice not found" - -} + "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 064ea4a95..49c44a4d8 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -366,13 +366,17 @@ "The invoices have been created but the PDFs could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", - "Cannot send mail": "Não é possível enviar o email", + "Cannot send mail": "No se ha podido enviar el correo", "CONSTRAINT `supplierAccountTooShort` failed for `vn`.`supplier`": "La cuenta debe tener exactamente 10 dígitos", "The sale not exists in the item shelving": "La venta no existe en la estantería del artículo", - "The entry not have stickers": "La entrada no tiene etiquetas", - "Too many records": "Demasiados registros", "Original invoice not found": "Factura original no encontrada", "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe", "Weight already set": "El peso ya está establecido", - "This ticket is not allocated to your department": "Este ticket no está asignado a tu departamento" + "This ticket is not allocated to your department": "Este ticket no está asignado a tu departamento", + "There is already a tray with the same height": "Ya existe una bandeja con la misma altura", + "The height must be greater than 50cm": "La altura debe ser superior a 50cm", + "The maximum height of the wagon is 200cm": "La altura máxima es 200cm", + "The entry does not have stickers": "La entrada no tiene etiquetas", + "Too many records": "Demasiados registros", + "This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha" } \ No newline at end of file diff --git a/modules/account/back/model-config.json b/modules/account/back/model-config.json index 0cd43d0ce..cfec1fbe4 100644 --- a/modules/account/back/model-config.json +++ b/modules/account/back/model-config.json @@ -1,4 +1,7 @@ { + "Account": { + "dataSource": "vn" + }, "AccountConfig": { "dataSource": "vn" }, @@ -47,9 +50,6 @@ "SipConfig": { "dataSource": "vn" }, - "Account": { - "dataSource": "vn" - }, "UserLog": { "dataSource": "vn" }, diff --git a/modules/account/back/models/account.json b/modules/account/back/models/account.json index 6c2784696..fc1bbeb3d 100644 --- a/modules/account/back/models/account.json +++ b/modules/account/back/models/account.json @@ -46,4 +46,4 @@ "permission": "ALLOW" } ] -} +} \ No newline at end of file diff --git a/modules/account/back/models/mail-alias-account.js b/modules/account/back/models/mail-alias-account.js index 61ca344e9..0eee6a123 100644 --- a/modules/account/back/models/mail-alias-account.js +++ b/modules/account/back/models/mail-alias-account.js @@ -1,5 +1,6 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/modules/client/back/models/address.js b/modules/client/back/models/address.js index 4a93b5d5c..7011008a4 100644 --- a/modules/client/back/models/address.js +++ b/modules/client/back/models/address.js @@ -43,8 +43,14 @@ module.exports = Self => { include: [{ relation: 'province', scope: { - fields: ['id', 'name'] - } + fields: ['id', 'name', 'countryFk'], + include: [ + { + relation: 'country', + scope: {fields: ['id', 'name']}, + }, + ], + }, }, { relation: 'agencyMode', scope: { diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index f4ff0e3aa..f1474e10c 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -33,7 +33,6 @@ class Controller extends Dialog { } }; - this.getAmountPaid(); this.$http.get(`Clients/findOne`, {filter}) .then(res => { this.receipt.email = res.data.email; @@ -52,6 +51,7 @@ class Controller extends Dialog { set companyFk(value) { this.receipt.companyFk = value; + this.getAmountPaid(); } set description(value) { diff --git a/modules/entry/back/methods/entry/print.js b/modules/entry/back/methods/entry/print.js index c155c3d8b..11abf0788 100644 --- a/modules/entry/back/methods/entry/print.js +++ b/modules/entry/back/methods/entry/print.js @@ -52,7 +52,14 @@ module.exports = Self => { await merger.add(new Uint8Array(pdfBuffer[0])); } - if (!merger._doc) throw new UserError('The entry not have stickers'); + if (!merger._doc) throw new UserError('The entry does not have stickers'); + + await Self.rawSql(` + UPDATE buy + SET printedStickers = stickers + WHERE entryFk = ? + `, [id], myOptions); + return [await merger.saveAsBuffer(), 'application/pdf', `filename="entry-${id}.pdf"`]; }; }; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index c7156062a..145da170a 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + expect(result.length).toEqual(12); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(10); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { diff --git a/modules/entry/back/methods/stock-bought/getStockBought.js b/modules/entry/back/methods/stock-bought/getStockBought.js new file mode 100644 index 000000000..94e206ece --- /dev/null +++ b/modules/entry/back/methods/stock-bought/getStockBought.js @@ -0,0 +1,60 @@ +module.exports = Self => { + Self.remoteMethod('getStockBought', { + description: 'Returns the stock bought for a given date', + accessType: 'READ', + accepts: [{ + arg: 'workerFk', + type: 'number', + description: 'The id for a buyer', + }, + { + arg: 'dated', + type: 'date', + description: 'The date to filter', + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getStockBought`, + verb: 'GET' + } + }); + + Self.getStockBought = async(workerFk, dated = Date.vnNew()) => { + const models = Self.app.models; + const today = Date.vnNew(); + dated.setHours(0, 0, 0, 0); + today.setHours(0, 0, 0, 0); + + if (dated.getTime() === today.getTime()) + await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`); + + const filter = { + where: { + dated: dated + }, + include: [ + { + relation: 'worker', + scope: { + include: [ + { + relation: 'user', + scope: { + fields: ['id', 'name'] + } + } + ] + } + } + ] + }; + + if (workerFk) filter.where.workerFk = workerFk; + + return models.StockBought.find(filter); + }; +}; diff --git a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js new file mode 100644 index 000000000..6f09f1f67 --- /dev/null +++ b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js @@ -0,0 +1,58 @@ +module.exports = Self => { + Self.remoteMethod('getStockBoughtDetail', { + description: 'Returns the detail of stock bought for a given date and a worker', + accessType: 'READ', + accepts: [{ + arg: 'workerFk', + type: 'number', + description: 'The worker to filter', + required: true, + }, { + arg: 'dated', + type: 'string', + description: 'The date to filter', + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getStockBoughtDetail`, + verb: 'GET' + } + }); + + Self.getStockBoughtDetail = async(workerFk, dated) => { + if (!dated) { + dated = Date.vnNew(); + dated.setHours(0, 0, 0, 0); + } + return Self.rawSql( + `SELECT e.id entryFk, + i.id itemFk, + i.longName itemName, + b.quantity, + ROUND((ac.conversionCoefficient * + (b.quantity / b.packing) * + buy_getVolume(b.id) + ) / (vc.trolleyM3 * 1000000), + 2 + ) volume, + b.packagingFk, + b.packing + FROM entry e + JOIN travel t ON t.id = e.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 worker w ON w.id = it.workerFk + JOIN auctionConfig ac + JOIN volumeConfig vc + WHERE t.warehouseInFk = ac.warehouseFk + AND it.workerFk = ? + AND t.shipped = util.VN_CURDATE()`, + [workerFk] + ); + }; +}; diff --git a/modules/entry/back/model-config.json b/modules/entry/back/model-config.json index dc7fd86be..85f5e8285 100644 --- a/modules/entry/back/model-config.json +++ b/modules/entry/back/model-config.json @@ -25,5 +25,8 @@ }, "EntryType": { "dataSource": "vn" + }, + "StockBought": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/modules/entry/back/models/stock-bought.js b/modules/entry/back/models/stock-bought.js new file mode 100644 index 000000000..ae52e7654 --- /dev/null +++ b/modules/entry/back/models/stock-bought.js @@ -0,0 +1,10 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + require('../methods/stock-bought/getStockBought')(Self); + require('../methods/stock-bought/getStockBoughtDetail')(Self); + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`This buyer has already made a reservation for this date`); + return err; + }); +}; diff --git a/modules/entry/back/models/stock-bought.json b/modules/entry/back/models/stock-bought.json new file mode 100644 index 000000000..18c9f0347 --- /dev/null +++ b/modules/entry/back/models/stock-bought.json @@ -0,0 +1,34 @@ +{ + "name": "StockBought", + "base": "VnModel", + "options": { + "mysql": { + "table": "stockBought" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "workerFk": { + "type": "number" + }, + "bought": { + "type": "number" + }, + "reserve": { + "type": "number" + }, + "dated": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 47dbcbea4..bab1fa375 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -83,8 +83,10 @@ module.exports = Self => { const invoiceOutSerial = await Self.app.models.InvoiceOutSerial.findById(serial); if (invoiceOutSerial?.taxAreaFk == 'WORLD') { const address = await Self.app.models.Address.findById(addressId); - if (!address || !address.customsAgentFk || !address.incotermsFk) - throw new UserError('The address of the customer must have information about Incoterms and Customs Agent'); + if (!address?.customsAgentFk || !address.incotermsFk) { + throw new UserError( + 'The address of the customer must have information about Incoterms and Customs Agent'); + } } return serial; diff --git a/modules/item/back/methods/item/getWasteByItem.js b/modules/item/back/methods/item/getWasteByItem.js index 548f28008..b4cc566ae 100644 --- a/modules/item/back/methods/item/getWasteByItem.js +++ b/modules/item/back/methods/item/getWasteByItem.js @@ -52,7 +52,13 @@ module.exports = Self => { it.name family, w.itemFk, SUM(w.saleTotal) total, - SUM(w.saleInternalWaste + w.saleExternalWaste) dwindle + SUM( + w.saleExternalWaste + + w.saleFaultWaste + + w.saleContainerWaste + + w.saleBreakWaste + + w.saleOtherWaste + ) dwindle FROM bs.waste w JOIN account.user u ON u.id = w.buyerFk JOIN vn.itemType it ON it.id = w.itemTypeFk diff --git a/modules/item/back/methods/item/getWasteByWorker.js b/modules/item/back/methods/item/getWasteByWorker.js index 9af49478f..d2c2f7f59 100644 --- a/modules/item/back/methods/item/getWasteByWorker.js +++ b/modules/item/back/methods/item/getWasteByWorker.js @@ -28,7 +28,13 @@ module.exports = Self => { it.name family, w.itemFk, SUM(w.saleTotal) total, - SUM(w.saleInternalWaste + w.saleExternalWaste) dwindle + SUM( + w.saleExternalWaste + + w.saleFaultWaste + + w.saleContainerWaste + + w.saleBreakWaste + + w.saleOtherWaste + ) dwindle FROM bs.waste w JOIN account.user u ON u.id = w.buyerFk JOIN vn.itemType it ON it.id = w.itemTypeFk @@ -44,7 +50,13 @@ module.exports = Self => { FROM ( SELECT u.name buyer, SUM(w.saleTotal) total, - SUM(w.saleInternalWaste + w.saleExternalWaste) dwindle + SUM( + w.saleExternalWaste + + w.saleFaultWaste + + w.saleContainerWaste + + w.saleBreakWaste + + w.saleOtherWaste + ) dwindle FROM bs.waste w JOIN account.user u ON u.id = w.buyerFk WHERE w.year = YEAR(TIMESTAMPADD(WEEK, -1, ?)) diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index 9460addfa..738af5219 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -39,7 +39,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toBeGreaterThan(10); + expect(result.length).toBeGreaterThan(9); await tx.rollback(); } catch (e) { @@ -146,13 +146,20 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; + const alertLevel = await models.AlertLevel.findOne({ + where: {code: 'FREE'}, + options + }); + + const alertLevelFree = alertLevel.id; + const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; const filter = {order: 'alertLevel ASC'}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - const firstRow = result[0]; - expect(result.length).toEqual(15); - expect(firstRow.alertLevel).not.toEqual(0); + result.forEach(row => { + expect(row.alertLevel).toBeGreaterThan(alertLevelFree); + }); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index a43b5e270..6c9ed4f8b 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -38,13 +38,14 @@ module.exports = Self => { Object.assign(myOptions, options); const where = buildFilter(ctx.args, (param, value) => { - switch (param) { - case 'search': - return {or: [ - {'t.id': value}, - {'c.id': value}, - {'c.name': {like: `%${value}%`}} - ]}; + if (param === 'search') { + return { + or: [ + {'t.id': value}, + {'c.id': value}, + {'c.name': {like: `%${value}%`}} + ] + }; } }); diff --git a/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js index 453b7924f..9b1ad5209 100644 --- a/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js @@ -13,11 +13,11 @@ describe('ticket-weekly filter()', () => { const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}}; const result = await models.TicketWeekly.filter(ctx, null, options); - + const totalRecords = await models.TicketWeekly.count(); const firstRow = result[0]; expect(firstRow.ticketFk).toEqual(2); - expect(result.length).toEqual(4); + expect(result.length).toEqual(totalRecords); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/closeByAgency.js b/modules/ticket/back/methods/ticket/closeByAgency.js deleted file mode 100644 index eb1aee349..000000000 --- a/modules/ticket/back/methods/ticket/closeByAgency.js +++ /dev/null @@ -1,79 +0,0 @@ -const closure = require('./closure'); - -module.exports = Self => { - Self.remoteMethodCtx('closeByAgency', { - description: 'Makes the closure process by agency mode', - accessType: 'WRITE', - accepts: [ - { - arg: 'agencyModeFk', - type: ['number'], - required: true, - description: 'The agencies mode ids', - }, - { - arg: 'warehouseFk', - type: 'number', - description: 'The ticket warehouse id', - required: true - }, - { - arg: 'to', - type: 'date', - description: 'Max closure date', - required: true - } - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/close-by-agency`, - verb: 'POST' - } - }); - - Self.closeByAgency = async ctx => { - const args = ctx.args; - - const tickets = await Self.rawSql(` - SELECT - t.id, - t.clientFk, - t.companyFk, - c.name clientName, - c.email recipient, - c.salesPersonFk, - c.isToBeMailed, - c.hasToInvoice, - co.hasDailyInvoice, - eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.id = ts.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk - WHERE al.code = 'PACKED' - AND t.agencyModeFk IN(?) - AND t.warehouseFk = ? - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) - AND util.dayEnd(?) - AND t.refFk IS NULL - GROUP BY e.ticketFk`, [ - args.agencyModeFk, - args.warehouseFk, - args.to, - args.to - ]); - - await closure(Self, tickets); - - return { - message: 'Success' - }; - }; -}; diff --git a/modules/ticket/back/methods/ticket/closeByRoute.js b/modules/ticket/back/methods/ticket/closeByRoute.js deleted file mode 100644 index 58e130b8e..000000000 --- a/modules/ticket/back/methods/ticket/closeByRoute.js +++ /dev/null @@ -1,75 +0,0 @@ -const closure = require('./closure'); -const {Email} = require('vn-print'); - -module.exports = Self => { - Self.remoteMethodCtx('closeByRoute', { - description: 'Makes the closure process by route', - accessType: 'WRITE', - accepts: [ - { - arg: 'routeFk', - type: 'number', - required: true, - description: 'The routes ids', - }, - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/close-by-route`, - verb: 'POST' - } - }); - - Self.closeByRoute = async ctx => { - const args = ctx.args; - - const tickets = await Self.rawSql(` - SELECT - t.id, - t.clientFk, - t.companyFk, - c.name clientName, - c.email recipient, - c.salesPersonFk, - c.isToBeMailed, - c.hasToInvoice, - co.hasDailyInvoice, - eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.id = ts.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk - LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk - WHERE al.code = 'PACKED' - AND t.routeFk = ? - AND t.refFk IS NULL - GROUP BY e.ticketFk`, [args.routeFk]); - - await closure(Self, tickets); - - // Send route report to the agency - const [agencyMail] = await Self.rawSql(` - SELECT am.reportMail - FROM route r - JOIN agencyMode am ON am.id = r.agencyModeFk - WHERE r.id = ?`, [args.routeFk]); - - if (agencyMail) { - const email = new Email('driver-route', { - id: args.routeFk, - recipient: agencyMail - }); - await email.send(); - } - - return { - message: 'Success' - }; - }; -}; diff --git a/modules/ticket/back/methods/ticket/closeByTicket.js b/modules/ticket/back/methods/ticket/closeByTicket.js index 8884897c2..40fe048a5 100644 --- a/modules/ticket/back/methods/ticket/closeByTicket.js +++ b/modules/ticket/back/methods/ticket/closeByTicket.js @@ -23,11 +23,25 @@ module.exports = Self => { } }); - Self.closeByTicket = async ctx => { + Self.closeByTicket = async(ctx, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + const userId = ctx.req.accessToken.userId; + myOptions.userId = userId; + const args = ctx.args; const tickets = await Self.rawSql(` - SELECT + SELECT t.id, t.clientFk, t.companyFk, @@ -37,7 +51,8 @@ module.exports = Self => { c.isToBeMailed, c.hasToInvoice, co.hasDailyInvoice, - eu.email salesPersonEmail + eu.email salesPersonEmail, + t.addressFk FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = t.id @@ -49,9 +64,14 @@ module.exports = Self => { WHERE al.code = 'PACKED' AND t.id = ? AND t.refFk IS NULL - GROUP BY e.ticketFk`, [args.id]); + GROUP BY e.ticketFk`, + [args.id], + myOptions); - await closure(Self, tickets); + await closure(ctx, Self, tickets, myOptions); + + if (tx) + await tx.commit(); return { message: 'Success' diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 4622ba271..a75596bac 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -1,13 +1,22 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ - const Report = require('vn-print/core/report'); const Email = require('vn-print/core/email'); const smtp = require('vn-print/core/smtp'); const config = require('vn-print/core/config'); const storage = require('vn-print/core/storage'); -module.exports = async function(ctx, Self, tickets, reqArgs = {}) { +module.exports = async function(ctx, Self, tickets, options) { const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let tx; + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + if (tickets.length == 0) return; const failedtickets = []; @@ -17,7 +26,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id], - {userId} + myOptions ); const [invoiceOut] = await Self.rawSql(` @@ -26,7 +35,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { JOIN invoiceOut io ON io.ref = t.refFk JOIN company cny ON cny.id = io.companyFk WHERE t.id = ? - `, [ticket.id]); + `, [ticket.id], myOptions); const mailOptions = { overrideAttachments: true, @@ -63,7 +72,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { await Self.rawSql( 'UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id], - {userId}, + myOptions ); if (isToBeMailed) { @@ -108,7 +117,9 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { WHERE t.clientFk = ? AND NOT t.isDeleted AND c.isVies - `, [ticket.clientFk]); + `, + [ticket.clientFk], + myOptions); if (firstOrder == 1) { const args = { @@ -127,20 +138,22 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { SELECT id FROM sample WHERE code = 'incoterms-authorization' - `); + `, + null, + myOptions); await Self.rawSql(` INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?) - `, [ticket.clientFk, sample.id, ticket.companyFk], {userId}); + `, + [ticket.clientFk, sample.id, ticket.companyFk], + myOptions); } } catch (error) { - // Domain not found if (error.responseCode == 450) { await invalidEmail(ticket); continue; } - // Save tickets on a list of failed ids failedtickets.push({ id: ticket.id, stacktrace: error, @@ -148,7 +161,6 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { } } - // Send email with failed tickets if (failedtickets.length > 0) { let body = 'This following tickets have failed:

'; @@ -164,11 +176,14 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { }).catch(err => console.error(err)); } + if (tx) + await tx.commit(); + async function invalidEmail(ticket) { await Self.rawSql( `UPDATE client SET email = NULL WHERE id = ?`, [ticket.clientFk], - {userId}, + myOptions ); const body = `No se ha podido enviar el albarán ${ticket.id} diff --git a/modules/ticket/back/methods/ticket/saveCmr.js b/modules/ticket/back/methods/ticket/saveCmr.js index f8d0af8ef..339ac1e38 100644 --- a/modules/ticket/back/methods/ticket/saveCmr.js +++ b/modules/ticket/back/methods/ticket/saveCmr.js @@ -39,7 +39,7 @@ module.exports = Self => { }, myOptions); for (const ticketId of tickets) { - const ticket = await models.Ticket.findById(ticketId, myOptions); + const ticket = await models.Ticket.findById(ticketId, null, myOptions); if (ticket.cmrFk) { const hasDmsCmr = await Self.rawSql(` diff --git a/modules/ticket/back/methods/ticket/specs/closure.spec.js b/modules/ticket/back/methods/ticket/specs/closure.spec.js new file mode 100644 index 000000000..303c38233 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/closure.spec.js @@ -0,0 +1,119 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); +const smtp = require('vn-print/core/smtp'); +const Email = require('vn-print/core/email'); +const config = require('vn-print/core/config'); +const closure = require('../closure'); + +describe('Ticket closure functionality', () => { + const userId = 19; + const companyFk = 442; + const activeCtx = { + getLocale: () => 'es', + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + }; + let ctx = {req: activeCtx}; + let tx; + let options; + + beforeEach(async() => { + LoopBackContext.getCurrentContext = () => ({ + active: activeCtx, + }); + + tx = await models.Sale.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should successfully close a ticket and not invoiced', async() => { + const ticketId = 15; + const tickets = [{ + id: ticketId, + clientFk: 1101, + companyFk, + addressFk: 1, + isToBeMailed: true, + recipient: 'some@email.com', + salesPersonFk: userId + }]; + + const ticketStateBefore = await models.TicketState.findById(ticketId, null, options); + + await closure(ctx, models.Ticket, tickets, options); + + const ticketStateAfter = await models.TicketState.findById(ticketId, null, options); + + expect(ticketStateBefore.code).not.toBe(ticketStateAfter.code); + + const ticketAfter = await models.TicketState.findById(ticketId, null, options); + + expect(ticketAfter.refFk).toBeUndefined(); + }); + + it('should send Incoterms authorization email on first order', async() => { + const ticketId = 37; + ctx.args = { + id: ticketId, + }; + + const ticket = await models.Ticket.findById(ticketId, null, options); + spyOn(Email.prototype, 'send').and.returnValue(Promise.resolve()); + + await models.Ticket.closeByTicket(ctx, options); + + const sample = await models.Sample.findOne({ + where: {code: 'incoterms-authorization'}, + fields: ['id'] + }, + options); + + const insertedSample = await models.ClientSample.findOne({ + where: { + clientFk: ticket.clientFk, + typeFk: sample.id, + companyFk: companyFk + } + }, options); + + expect(insertedSample.clientFk).toEqual(ticket.clientFk); + }); + + it('should report failed tickets and set client email to null', async() => { + const ticketId = 37; + const clientId = 1110; + const tickets = [{ + id: ticketId, + clientFk: clientId, + companyFk, + addressFk: 1, + isToBeMailed: true, + recipient: 'invalid@example.com', + salesPersonFk: userId + }]; + + spyOn(Email.prototype, 'send').and.callFake(() => { + const error = new Error('Invalid email'); + error.responseCode = 450; + return Promise.reject(error); + }); + + await closure(ctx, models.Ticket, tickets, options); + + const client = await models.Client.findById(clientId, null, options); + + expect(client.email).toBeNull(); + + const reportEmail = await smtp.send({ + to: config.app.reportEmail, + subject: '[API] Nightly ticket closure report', + html: `This following tickets have failed:` + }); + + expect(reportEmail).not.toBeNull(); + }); +}); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 72249fe5d..d0edb24e3 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -21,7 +21,7 @@ describe('ticket filter()', () => { } }); - it('should return the tickets matching the problems on true', async() => { + it('should return at least one ticket matching the problems on true', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -41,7 +41,15 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toBeGreaterThan(3); + const hasProblemTicket = result.some(ticket => + ticket.isFreezed === true || + ticket.hasRisk === true || + ticket.hasTicketRequest === true || + (typeof ticket.hasRounding === 'string' && ticket.hasRounding.trim().length > 0) || + (typeof ticket.itemShortage === 'string' && ticket.itemShortage.trim().length > 0) + ); + + expect(hasProblemTicket).toBe(true); await tx.rollback(); } catch (e) { @@ -71,7 +79,13 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(11); + result.forEach(ticket => { + expect(ticket.isFreezed).toEqual(null); + expect(ticket.hasRisk).toEqual(null); + expect(ticket.hasTicketRequest).toEqual(null); + expect(ticket.itemShortage).toEqual(null); + expect(ticket.hasRounding).toEqual(null); + }); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index 883b0de2e..1a8025f09 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -65,7 +65,7 @@ describe('ticket isEditableOrThrow()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 1}}}; - await models.Ticket.isEditableOrThrow(ctx, 15, options); + await models.Ticket.isEditableOrThrow(ctx, 17, options); await tx.rollback(); } catch (e) { error = e; diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 12161d5f5..7fe968b26 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -33,8 +33,6 @@ module.exports = function(Self) { require('../methods/ticket/deliveryNoteCsvEmail')(Self); require('../methods/ticket/closeAll')(Self); require('../methods/ticket/closeByTicket')(Self); - require('../methods/ticket/closeByAgency')(Self); - require('../methods/ticket/closeByRoute')(Self); require('../methods/ticket/getTicketsFuture')(Self); require('../methods/ticket/merge')(Self); require('../methods/ticket/getTicketsAdvance')(Self); diff --git a/modules/wagon/back/methods/wagonType/createWagonType.js b/modules/wagon/back/methods/wagonType/createWagonType.js deleted file mode 100644 index fed915b28..000000000 --- a/modules/wagon/back/methods/wagonType/createWagonType.js +++ /dev/null @@ -1,57 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('createWagonType', { - description: 'Creates a new wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'name', - type: 'String', - required: true - }, - { - arg: 'divisible', - type: 'boolean', - required: true - }, { - arg: 'trays', - type: 'any', - required: true - } - ], - http: { - path: `/createWagonType`, - verb: 'PATCH' - } - }); - - Self.createWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const newWagonType = await models.WagonType.create({name: args.name, divisible: args.divisible}, myOptions); - args.trays.forEach(async tray => { - await models.WagonTypeTray.create({ - typeFk: newWagonType.id, - height: tray.position, - colorFk: tray.color.id - }, myOptions); - }); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/deleteWagonType.js b/modules/wagon/back/methods/wagonType/deleteWagonType.js deleted file mode 100644 index 46b65e32f..000000000 --- a/modules/wagon/back/methods/wagonType/deleteWagonType.js +++ /dev/null @@ -1,43 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('deleteWagonType', { - description: 'Deletes a wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'Number', - required: true - } - ], - http: { - path: `/deleteWagonType`, - verb: 'DELETE' - } - }); - - Self.deleteWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - await models.Wagon.destroyAll({typeFk: args.id}, myOptions); - await models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); - await models.WagonType.destroyAll({id: args.id}, myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/editWagonType.js b/modules/wagon/back/methods/wagonType/editWagonType.js deleted file mode 100644 index bd5ad1f16..000000000 --- a/modules/wagon/back/methods/wagonType/editWagonType.js +++ /dev/null @@ -1,64 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('editWagonType', { - description: 'Edits a new wagon type', - accessType: 'WRITE', - accepts: [ - { - arg: 'id', - type: 'String', - required: true - }, - { - arg: 'name', - type: 'String', - required: true - }, - { - arg: 'divisible', - type: 'boolean', - required: true - }, { - arg: 'trays', - type: 'any', - required: true - } - ], - http: { - path: `/editWagonType`, - verb: 'PATCH' - } - }); - - Self.editWagonType = async(ctx, options) => { - const args = ctx.args; - const models = Self.app.models; - const myOptions = {}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const wagonType = await models.WagonType.findById(args.id, null, myOptions); - wagonType.updateAttributes({name: args.name, divisible: args.divisible}, myOptions); - models.WagonTypeTray.destroyAll({typeFk: args.id}, myOptions); - args.trays.forEach(async tray => { - await models.WagonTypeTray.create({ - typeFk: args.id, - height: tray.position, - colorFk: tray.color.id - }, myOptions); - }); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js index 92ac61060..96f0980f9 100644 --- a/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js +++ b/modules/wagon/back/methods/wagonType/specs/crudWagonType.spec.js @@ -1,58 +1,16 @@ const models = require('vn-loopback/server/server').models; describe('WagonType crudWagonType()', () => { - const ctx = { - args: { - name: 'Mock wagon type', - divisible: true, - trays: [{position: 0, color: {id: 1}}, - {position: 50, color: {id: 2}}, - {position: 100, color: {id: 3}}] - } - }; - it(`should create, edit and delete a new wagon type and its trays`, async() => { const tx = await models.WagonType.beginTransaction({}); try { const options = {transaction: tx}; - // create - await models.WagonType.createWagonType(ctx, options); + const wagonType = await models.WagonType.create({name: 'Mock wagon type'}, options); + const newWagonTrays = await models.WagonTypeTray.findOne({where: {typeFk: wagonType.id}}, options); - const newWagonType = await models.WagonType.findOne({where: {name: ctx.args.name}}, options); - const newWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(newWagonType).not.toEqual(null); - expect(newWagonType.name).toEqual(ctx.args.name); - expect(newWagonType.divisible).toEqual(ctx.args.divisible); - expect(newWagonTrays.length).toEqual(ctx.args.trays.length); - - ctx.args = { - id: newWagonType.id, - name: 'Edited wagon type', - divisible: false, - trays: [{position: 0, color: {id: 1}}] - }; - - // edit - await models.WagonType.editWagonType(ctx, options); - - const editedWagonType = await models.WagonType.findById(newWagonType.id, null, options); - const editedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(editedWagonType.name).toEqual(ctx.args.name); - expect(editedWagonType.divisible).toEqual(ctx.args.divisible); - expect(editedWagonTrays.length).toEqual(ctx.args.trays.length); - - // delete - await models.WagonType.deleteWagonType(ctx, options); - - const deletedWagonType = await models.WagonType.findById(newWagonType.id, null, options); - const deletedWagonTrays = await models.WagonTypeTray.find({where: {typeFk: newWagonType.id}}, options); - - expect(deletedWagonType).toEqual(null); - expect(deletedWagonTrays).toEqual([]); + expect(newWagonTrays).toBeDefined(); await tx.rollback(); } catch (e) { diff --git a/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js new file mode 100644 index 000000000..783c1a621 --- /dev/null +++ b/modules/wagon/back/methods/wagonType/specs/wagonTray.spec.js @@ -0,0 +1,58 @@ +const models = require('vn-loopback/server/server').models; + +describe('WagonTray max height()', () => { + it(`should throw an error if the tray's height is above the maximum of the wagon`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 210, wagonTypeFk: 1, wagonTypeColorFk: 4}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('The maximum height of the wagon is 200cm'); + }); + + it(`should throw an error if the tray's height is already in the wagon`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 50, wagonTypeFk: 1, wagonTypeColorFk: 2}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('There is already a tray with the same height'); + }); + + it(`should throw an error if the tray's height is below the minimum between the trays`, async() => { + const tx = await models.WagonTypeTray.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + await models.WagonTypeTray.create({height: 40, wagonTypeFk: 1, wagonTypeColorFk: 4}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toBe('The height must be greater than 50cm'); + }); +}); + diff --git a/modules/wagon/back/models/wagon-config.json b/modules/wagon/back/models/wagon-config.json index 3d96e2864..d76558564 100644 --- a/modules/wagon/back/models/wagon-config.json +++ b/modules/wagon/back/models/wagon-config.json @@ -25,6 +25,19 @@ }, "maxTrays": { "type": "number" + }, + "defaultHeight": { + "type": "number" + }, + "defaultTrayColorFk": { + "type": "number" } + }, + "relations": { + "WagonTypeColor": { + "type": "belongsTo", + "model": "WagonTypeColor", + "foreignKey": "defaultTrayColorFk" + } } } diff --git a/modules/wagon/back/models/wagon-type-tray.js b/modules/wagon/back/models/wagon-type-tray.js new file mode 100644 index 000000000..219f20bfb --- /dev/null +++ b/modules/wagon/back/models/wagon-type-tray.js @@ -0,0 +1,25 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.observe('before save', async ctx => { + if (ctx.isNewInstance) { + const models = Self.app.models; + const {wagonTypeFk, height} = ctx.instance; + const trays = await models.WagonTypeTray.find({where: {wagonTypeFk}}); + + const config = await models.WagonConfig.findOne(); + const tray = await models.WagonTypeTray.find({where: {wagonTypeFk, height}}); + + if (!trays.length) return; + + if (tray.length) + throw new UserError('There is already a tray with the same height'); + + if (height < config.minHeightBetweenTrays) + throw new UserError('The height must be greater than 50cm'); + + if (height > config.maxWagonHeight) + throw new UserError('The maximum height of the wagon is 200cm'); + } + }); +}; diff --git a/modules/wagon/back/models/wagon-type-tray.json b/modules/wagon/back/models/wagon-type-tray.json index b61510bcf..61b32694d 100644 --- a/modules/wagon/back/models/wagon-type-tray.json +++ b/modules/wagon/back/models/wagon-type-tray.json @@ -11,13 +11,13 @@ "id": true, "type": "number" }, - "typeFk": { + "wagonTypeFk": { "type": "number" }, "height": { "type": "number" }, - "colorFk": { + "wagonTypeColorFk": { "type": "number" } }, @@ -25,12 +25,12 @@ "type": { "type": "belongsTo", "model": "WagonType", - "foreignKey": "typeFk" + "foreignKey": "wagonTypeFk" }, "color": { "type": "belongsTo", "model": "WagonTypeColor", - "foreignKey": "colorFk" + "foreignKey": "wagonTypeColorFk" } } } diff --git a/modules/wagon/back/models/wagon-type.js b/modules/wagon/back/models/wagon-type.js index bebf7a9d9..0610adcb4 100644 --- a/modules/wagon/back/models/wagon-type.js +++ b/modules/wagon/back/models/wagon-type.js @@ -1,5 +1,14 @@ module.exports = Self => { - require('../methods/wagonType/createWagonType')(Self); - require('../methods/wagonType/editWagonType')(Self); - require('../methods/wagonType/deleteWagonType')(Self); + Self.observe('after save', async ctx => { + if (ctx.isNewInstance) { + const models = Self.app.models; + const config = await models.WagonConfig.findOne(); + + await models.WagonTypeTray.create({ + wagonTypeFk: ctx.instance.id, + height: config.defaultHeight, + wagonTypeColorFk: config.defaultTrayColorFk + }, ctx.options); + } + }); }; diff --git a/modules/worker/back/methods/device/handle-user.js b/modules/worker/back/methods/device/handle-user.js new file mode 100644 index 000000000..ac4ff2704 --- /dev/null +++ b/modules/worker/back/methods/device/handle-user.js @@ -0,0 +1,118 @@ + +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('handleUser', { + description: 'Manage various aspects related to a user with the app', + accepts: [ + { + arg: 'androidId', + type: 'String', + description: 'Android id' + }, + { + arg: 'deviceId', + type: 'String', + description: 'Device id' + }, + { + arg: 'versionApp', + type: 'String', + description: 'Version app' + }, { + arg: 'nameApp', + type: 'String', + description: 'Version app' + }, + + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/handleUser`, + verb: 'POST' + } + }); + + Self.handleUser = async(ctx, androidId, deviceId, versionApp, nameApp, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const accessToken = ctx.req.accessToken; + let user = await models.VnUser.findById(accessToken.userId); + + const [[{vIsAuthorized, vMessage}]] = + await Self.rawSql('CALL vn.device_checkLogin(?, ?);', + [user.id, androidId], myOptions); + + if (!vIsAuthorized) + throw new UserError('Not authorized'); + + const isUserInOperator = await models.Operator.findOne({ + where: { + workerFk: user.id + } + }, myOptions); + + if (!isUserInOperator) { + await models.Operator.create({ + 'workerFk': user.id, + 'isOnReservationMode': false + }); + } + + const whereCondition = deviceId ? {id: deviceId} : {android_id: androidId}; + const serialNumber = + (await models.DeviceProduction.findOne({where: whereCondition}, myOptions))?.serialNumber ?? ''; + + await models.DeviceLog.create({ + 'android_id': androidId, + 'userFk': user.id, + 'nameApp': nameApp, + 'versionApp': versionApp, + 'serialNumber': serialNumber + }, myOptions); + const getDataUser = await models.VnUser.getCurrentUserData(ctx); + + const getDataOperator = await models.Operator.findOne({ + where: {workerFk: user.id}, + fields: ['numberOfWagons', 'warehouseFk', 'itemPackingTypeFk', 'sectorFk', 'sector', + 'trainFk', 'train', 'labelerFk', 'printer'], + include: [ + { + relation: 'sector', + scope: { + fields: ['warehouseFk', 'description'], + } + }, { + relation: 'printer', + scope: { + fields: ['name'], + } + }, { + relation: 'train', + scope: { + fields: ['name'], + } + } + + ] + }, myOptions); + + const getVersion = await models.MobileAppVersionControl.getVersion(ctx, nameApp); + + const combinedResult = { + ...getDataOperator.toObject(), + ...getDataUser.toObject(), + ...getVersion, + message: vMessage, + serialNumber, + }; + return combinedResult; + }; +}; diff --git a/modules/worker/back/methods/device/specs/handle-user.spec.js b/modules/worker/back/methods/device/specs/handle-user.spec.js new file mode 100644 index 000000000..c4cd37e33 --- /dev/null +++ b/modules/worker/back/methods/device/specs/handle-user.spec.js @@ -0,0 +1,16 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Device handleUser()', () => { + const ctx = {req: {accessToken: {userId: 9}}}; + + it('should return data from user', async() => { + const androidId = 'androidid11234567890'; + const deviceId = 1; + const nameApp = 'warehouse'; + const versionApp = '10'; + + const data = await models.Device.handleUser(ctx, androidId, deviceId, versionApp, nameApp); + + expect(data.numberOfWagons).toBe(2); + }); +}); diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index b7802a689..597084e60 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -8,19 +8,19 @@ module.exports = Self => { accepts: [ { arg: 'id', - type: 'Number', + type: 'number', description: 'The worker id', http: {source: 'path'} }, { arg: 'filter', - type: 'Object', + type: 'object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', http: {source: 'query'} } ], returns: { - type: ['Object'], + type: ['object'], root: true }, http: { @@ -36,38 +36,50 @@ module.exports = Self => { // Get ids alloweds const account = await models.VnUser.findById(userId); + const stmt = new ParameterizedSQL( `SELECT d.id, d.id dmsFk - FROM workerDocument wd - JOIN dms d ON d.id = wd.document + FROM workerDms wd + JOIN dms d ON d.id = wd.dmsFk JOIN dmsType dt ON dt.id = d.dmsTypeFk - LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk AND rr.role = ? + LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk + AND rr.role = ? `, [account.roleFk] ); - const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]}; - const where = { - or: [yourOwnDms, { - role: { - neq: null - } - }] + const yourOwnDms = { + or: [ + {and: [ + {isReadableByWorker: true}, + {'wd.workerFk': userId} + ]}, + { + role: { + neq: null + } + }] }; - stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where))); - // Get workerDms alloweds + const where = mergeWhere(filter.where, yourOwnDms); + stmt.merge(conn.makeSuffix({where})); const dmsIds = await conn.executeStmt(stmt); + const allowedIds = dmsIds.map(dms => dms.id); const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}}); - let workerDms = await models.WorkerDms.find(allowedFilter); - // Get docuware info - const docuware = await models.Docuware.findOne({ - fields: ['dmsTypeFk'], - where: {code: 'hr', action: 'find'} - }); - const docuwareDmsType = docuware.dmsTypeFk; - let workerDocuware = []; - if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) { + const workerDms = await models.WorkerDms.find(allowedFilter); + + const workerDocuware = filter.skip ? [] : await getDocuware(ctx, id); + return workerDms.concat(workerDocuware); + + async function getDocuware(ctx, id) { + const {dmsTypeFk} = await models.Docuware.findOne({ + fields: ['dmsTypeFk'], + where: {code: 'hr', action: 'find'} + }); + + if (!await models.DmsType.hasReadRole(ctx, dmsTypeFk)) return []; + + let workerDocuware = []; const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { 'Filename': 'dmsFk', @@ -80,7 +92,7 @@ module.exports = Self => { }; workerDocuware = - await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; + await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; for (document of workerDocuware) { const docuwareId = document.id; @@ -105,7 +117,7 @@ module.exports = Self => { }; Object.assign(document, defaultData); } + return workerDocuware; } - return workerDms.concat(workerDocuware); }; }; diff --git a/modules/worker/back/models/device.js b/modules/worker/back/models/device.js index cda7a958f..6a7d5dba5 100644 --- a/modules/worker/back/models/device.js +++ b/modules/worker/back/models/device.js @@ -1,6 +1,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { + require('../methods/device/handle-user')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(``); diff --git a/modules/worker/back/models/worker-dms.json b/modules/worker/back/models/worker-dms.json index a5c0f30b2..ef5684025 100644 --- a/modules/worker/back/models/worker-dms.json +++ b/modules/worker/back/models/worker-dms.json @@ -6,7 +6,7 @@ }, "options": { "mysql": { - "table": "workerDocument" + "table": "workerDms" } }, "properties": { @@ -16,17 +16,11 @@ }, "dmsFk": { "type": "number", - "required": true, - "mysql": { - "columnName": "document" - } + "required": true }, "workerFk": { "type": "number", - "required": true, - "mysql": { - "columnName": "worker" - } + "required": true }, "isReadableByWorker": { "type": "boolean" diff --git a/modules/worker/back/models/worker-time-control-mail.json b/modules/worker/back/models/worker-time-control-mail.json index 87eae9217..192178c2d 100644 --- a/modules/worker/back/models/worker-time-control-mail.json +++ b/modules/worker/back/models/worker-time-control-mail.json @@ -32,13 +32,5 @@ "sendedCounter": { "type": "number" } - }, - "acls": [ - { - "accessType": "READ", - "principalType": "ROLE", - "principalId": "employee", - "permission": "ALLOW" - } - ] -} + } +} \ No newline at end of file diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 82cd1cc2d..21c5bd10f 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -130,6 +130,11 @@ "type": "hasMany", "model": "TrainingCourse", "foreignKey": "workerFk" + }, + "mail": { + "type": "hasMany", + "model": "WorkerTimeControlMail", + "foreignKey": "workerFk" } }, "acls": [ @@ -139,6 +144,13 @@ "permission": "ALLOW", "principalType": "ROLE", "principalId": "$owner" + }, + { + "property": "__get__mail", + "accessType": "READ", + "permission": "ALLOW", + "principalType": "ROLE", + "principalId": "$owner" } ], "scopes": { diff --git a/myt.config.yml b/myt.config.yml index ffa4188b2..663b1aec2 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -2,6 +2,7 @@ code: vn-database versionSchema: util replace: true sumViews: false +defaultDefiner: vn@localhost mockDate: '2001-01-01 12:00:00' subdir: db schemas: @@ -375,7 +376,7 @@ localFixtures: - workerBosses - workerBusinessType - workerConfig - - workerDocument + - workerDms - workerLog - workerMana - workerManaExcluded @@ -393,4 +394,4 @@ localFixtures: - zoneExclusionGeo - zoneGeo - zoneIncluded - - zoneWarehouse \ No newline at end of file + - zoneWarehouse diff --git a/package.json b/package.json index 1d3b9d253..2ae7c3764 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@babel/register": "^7.7.7", "@commitlint/cli": "^19.2.1", "@commitlint/config-conventional": "^19.1.0", - "@verdnatura/myt": "^1.6.9", + "@verdnatura/myt": "^1.6.11", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b4030d779..e2480cf4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -143,8 +143,8 @@ devDependencies: specifier: ^19.1.0 version: 19.1.0 '@verdnatura/myt': - specifier: ^1.6.9 - version: 1.6.9 + specifier: ^1.6.11 + version: 1.6.11 angular-mocks: specifier: ^1.7.9 version: 1.8.3 @@ -2846,8 +2846,8 @@ packages: dev: false optional: true - /@verdnatura/myt@1.6.9: - resolution: {integrity: sha512-29IauYra9igfdPWwV4+pVV/tBXvIg0fkVHEpSz8Zz3G3lRtzm286FN2Kv6hZkxmD/F1n52O37jN9WLiLHDTW1Q==} + /@verdnatura/myt@1.6.11: + resolution: {integrity: sha512-uqdbSJSznBBzAoRkvBt600nUMEPL1PJ2v73eWMZbaoGUMiZiNAehYjs4gIrObP1cxC85JOx97XoLpG0BzPsaig==} hasBin: true dependencies: '@sqltools/formatter': 1.2.5 @@ -3306,6 +3306,7 @@ packages: /are-we-there-yet@1.1.7: resolution: {integrity: sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==} + deprecated: This package is no longer supported. dependencies: delegates: 1.0.0 readable-stream: 2.3.8 @@ -6593,6 +6594,7 @@ packages: /gauge@2.7.4: resolution: {integrity: sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==} + deprecated: This package is no longer supported. dependencies: aproba: 1.2.0 console-control-strings: 1.1.0 @@ -10814,6 +10816,7 @@ packages: /npmlog@4.1.2: resolution: {integrity: sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==} + deprecated: This package is no longer supported. dependencies: are-we-there-yet: 1.1.7 console-control-strings: 1.1.0 @@ -11055,6 +11058,7 @@ packages: /osenv@0.1.5: resolution: {integrity: sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==} + deprecated: This package is no longer supported. dependencies: os-homedir: 1.0.2 os-tmpdir: 1.0.2 diff --git a/print/core/email.js b/print/core/email.js index a0bcf9122..a673685bb 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -33,7 +33,7 @@ class Email extends Component { const attachments = []; const getAttachments = async(componentPath, files) => { for (const file of files) { - const fileCopy = Object.assign({}, file); + const fileCopy = {...file}; const fileName = fileCopy.filename; if (options.overrideAttachments && !fileName.includes('.png')) continue; diff --git a/print/templates/email/buyer-week-waste/sql/wasteWeekly.sql b/print/templates/email/buyer-week-waste/sql/wasteWeekly.sql index 1b486a004..e5dbdfcb6 100644 --- a/print/templates/email/buyer-week-waste/sql/wasteWeekly.sql +++ b/print/templates/email/buyer-week-waste/sql/wasteWeekly.sql @@ -1,8 +1,14 @@ SELECT *, 100 * dwindle / total `percentage` FROM ( SELECT u.name buyer, - SUM(saleTotal) total, - SUM(w.saleInternalWaste + w.saleExternalWaste) dwindle + SUM(w.saleTotal) total, + SUM( + w.saleExternalWaste + + w.saleFaultWaste + + w.saleContainerWaste + + w.saleBreakWaste + + w.saleOtherWaste + ) dwindle FROM bs.waste w JOIN account.user u ON u.id = w.buyerFk JOIN vn.itemType it ON it.id = w.itemTypeFk