diff --git a/db/changes/10503-november/00-ticket_canMerge.sql b/db/changes/10503-november/00-ticket_canMerge.sql new file mode 100644 index 000000000..7e01f2fab --- /dev/null +++ b/db/changes/10503-november/00-ticket_canMerge.sql @@ -0,0 +1,9 @@ +DROP PROCEDURE IF EXISTS vn.ticket_canMerge; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) +BEGIN + CALL vn.ticket_canbePostponed(vDated,TIMESTAMPADD(DAY, vScopeDays, vDated),vLitersMax,vLinesMax,vWarehouseFk); +END $$ +DELIMITER ; diff --git a/db/changes/10503-november/00-ticket_canbePostposed.sql b/db/changes/10503-november/00-ticket_canbePostposed.sql new file mode 100644 index 000000000..113b09324 --- /dev/null +++ b/db/changes/10503-november/00-ticket_canbePostposed.sql @@ -0,0 +1,78 @@ +DROP PROCEDURE IF EXISTS vn.ticket_canbePostponed; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) +BEGIN +/** + * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro + * + * @param vOriginDated Fecha en cuestión + * @param vFutureDated Fecha en el futuro a sondear + * @param vLitersMax Volumen máximo de los tickets a catapultar + * @param vLinesMax Número máximo de lineas de los tickets a catapultar + * @param vWarehouseFk Identificador de vn.warehouse + */ + DROP TEMPORARY TABLE IF EXISTS tmp.filter; + CREATE TEMPORARY TABLE tmp.filter + (INDEX (id)) + SELECT sv.ticketFk id, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, + CAST(sum(litros) AS DECIMAL(10,0)) liters, + CAST(count(*) AS DECIMAL(10,0)) `lines`, + st.name state, + sub2.id ticketFuture, + t.landed originETD, + sub2.landed destETD, + sub2.iptd tfIpt, + sub2.state tfState, + t.clientFk, + t.warehouseFk, + ts.alertLevel, + t.shipped, + sub2.shipped tfShipped, + t.workerFk, + st.code code, + sub2.code tfCode + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = sv.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country c ON c.id = p.countryFk + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.alertLevel al ON al.id = ts.alertLevel + LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN ( + SELECT * + FROM ( + SELECT + t.addressFk , + t.id, + t.landed, + t.shipped, + st.name state, + st.code code, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd + FROM vn.ticket t + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + WHERE t.shipped BETWEEN vFutureDated + AND util.dayend(vFutureDated) + AND t.warehouseFk = vWarehouseFk + GROUP BY t.id + ) sub + GROUP BY sub.addressFk + ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id + WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) + AND t.warehouseFk = vWarehouseFk + AND al.code = 'FREE' + AND tp.ticketFk IS NULL + GROUP BY sv.ticketFk + HAVING liters <= IFNULL(vLitersMax, 9999) AND `lines` <= IFNULL(vLinesMax, 9999) AND ticketFuture; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index dfa7da733..cdb35c746 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -686,7 +686,10 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (24 ,NULL, 8, 1, 7, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE()), (25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE()), (26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE()), - (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE()); + (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE()), + (28, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE()), + (29, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE()), + (30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE()); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES @@ -984,7 +987,10 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (30, 4, 18, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE()), (32, 1, 24, 'Ranged weapon longbow 2m', -1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE()); + (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE()), + (34, 4, 28, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (35, 4, 29, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (36, 4, 30, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()); INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`) VALUES diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f0d726ed6..d952b86e2 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -727,6 +727,34 @@ export default { saveImport: 'button[response="accept"]', anyDocument: 'vn-ticket-dms-index > vn-data-viewer vn-tbody vn-tr' }, + ticketFuture: { + openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]', + originDated: 'vn-date-picker[label="Origin ETD"]', + futureDated: 'vn-date-picker[label="Destination ETD"]', + shipped: 'vn-date-picker[label="Origin date"]', + tfShipped: 'vn-date-picker[label="Destination date"]', + linesMax: 'vn-textfield[label="Max Lines"]', + litersMax: 'vn-textfield[label="Max Liters"]', + ipt: 'vn-autocomplete[label="Origin IPT"]', + tfIpt: 'vn-autocomplete[label="Destination IPT"]', + tableIpt: 'vn-autocomplete[name="ipt"]', + tableTfIpt: 'vn-autocomplete[name="tfIpt"]', + state: 'vn-autocomplete[label="Origin Grouped State"]', + tfState: 'vn-autocomplete[label="Destination Grouped State"]', + warehouseFk: 'vn-autocomplete[label="Warehouse"]', + problems: 'vn-check[label="With problems"]', + tableButtonSearch: 'vn-button[vn-tooltip="Search"]', + moveButton: 'vn-button[vn-tooltip="Future tickets"]', + acceptButton: '.vn-confirm.shown button[response="accept"]', + firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', + multiCheck: 'vn-multi-check', + tableId: 'vn-textfield[name="id"]', + tableTfId: 'vn-textfield[name="ticketFuture"]', + tableLiters: 'vn-textfield[name="litersMax"]', + tableLines: 'vn-textfield[name="linesMax"]', + submit: 'vn-submit[label="Search"]', + table: 'tbody > tr:not(.empty-rows)' + }, createStateView: { state: 'vn-autocomplete[ng-model="$ctrl.stateFk"]', worker: 'vn-autocomplete[ng-model="$ctrl.workerFk"]', diff --git a/e2e/paths/04-item/08_regularize.spec.js b/e2e/paths/04-item/08_regularize.spec.js index 400df666f..2e09a9f63 100644 --- a/e2e/paths/04-item/08_regularize.spec.js +++ b/e2e/paths/04-item/08_regularize.spec.js @@ -127,8 +127,8 @@ describe('Item regularize path', () => { await page.waitForState('ticket.index'); }); - it('should search for the ticket with id 28 once again', async() => { - await page.accessToSearchResult('28'); + it('should search for the ticket with id 31 once again', async() => { + await page.accessToSearchResult('31'); await page.waitForState('ticket.card.summary'); }); diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index d776f417d..67dfd83bf 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -291,7 +291,7 @@ describe('Ticket Edit sale path', () => { it('should confirm the transfered quantity is the correct one', async() => { const result = await page.waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); - expect(result).toContain('10'); + expect(result).toContain('20'); }); it('should go back to the original ticket sales section', async() => { diff --git a/e2e/paths/05-ticket/20_future.spec.js b/e2e/paths/05-ticket/20_future.spec.js new file mode 100644 index 000000000..23c2db77a --- /dev/null +++ b/e2e/paths/05-ticket/20_future.spec.js @@ -0,0 +1,287 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Ticket Future path', () => { + let browser; + let page; + + beforeAll(async () => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('employee', 'ticket'); + await page.accessToSection('ticket.future'); + }); + + afterAll(async () => { + await browser.close(); + }); + + const now = new Date(); + const tomorrow = new Date(now.getDate() + 1); + const ticket = { + originDated: now, + futureDated: now, + linesMax: '9999', + litersMax: '9999', + warehouseFk: 'Warehouse One' + }; + + it('should show errors snackbar because of the required data', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.originDated, ticket.originDated); + await page.pickDate(selectors.ticketFuture.futureDated, ticket.futureDated); + await page.write(selectors.ticketFuture.linesMax, ticket.linesMax); + await page.write(selectors.ticketFuture.litersMax, ticket.litersMax); + + await page.waitToClick(selectors.ticketFuture.submit); + let message = await page.waitForSnackbar(); + expect(message.text).toContain('warehouseFk is a required argument'); + + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.originDated, ticket.originDated); + await page.pickDate(selectors.ticketFuture.futureDated, ticket.futureDated); + await page.write(selectors.ticketFuture.linesMax, ticket.linesMax); + await page.autocompleteSearch(selectors.ticketFuture.warehouseFk, ticket.warehouseFk); + await page.waitToClick(selectors.ticketFuture.submit); + message = await page.waitForSnackbar(); + expect(message.text).toContain('litersMax is a required argument'); + + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.originDated, ticket.originDated); + await page.pickDate(selectors.ticketFuture.futureDated, ticket.futureDated); + await page.write(selectors.ticketFuture.litersMax, ticket.litersMax); + await page.autocompleteSearch(selectors.ticketFuture.warehouseFk, ticket.warehouseFk); + await page.waitToClick(selectors.ticketFuture.submit); + message = await page.waitForSnackbar(); + expect(message.text).toContain('linesMax is a required argument'); + + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.originDated, ticket.originDated); + await page.write(selectors.ticketFuture.linesMax, ticket.linesMax); + await page.write(selectors.ticketFuture.litersMax, ticket.litersMax); + await page.autocompleteSearch(selectors.ticketFuture.warehouseFk, ticket.warehouseFk); + await page.waitToClick(selectors.ticketFuture.submit); + message = await page.waitForSnackbar(); + expect(message.text).toContain('futureDated is a required argument'); + + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.futureDated, ticket.futureDated); + await page.write(selectors.ticketFuture.linesMax, ticket.linesMax); + await page.write(selectors.ticketFuture.litersMax, ticket.litersMax); + await page.autocompleteSearch(selectors.ticketFuture.warehouseFk, ticket.warehouseFk); + await page.waitToClick(selectors.ticketFuture.submit); + message = await page.waitForSnackbar(); + expect(message.text).toContain('originDated is a required argument'); + }); + + it('should search with the required data', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.originDated, ticket.originDated); + await page.pickDate(selectors.ticketFuture.futureDated, ticket.futureDated); + await page.write(selectors.ticketFuture.linesMax, ticket.linesMax); + await page.write(selectors.ticketFuture.litersMax, ticket.litersMax); + await page.autocompleteSearch(selectors.ticketFuture.warehouseFk, ticket.warehouseFk); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search with the origin shipped today', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.shipped, now); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search with the origin shipped tomorrow', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.shipped, tomorrow); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 0); + }); + + it('should search with the destination shipped today', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.clearInput(selectors.ticketFuture.shipped); + await page.pickDate(selectors.ticketFuture.tfShipped, now); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search with the destination shipped tomorrow', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.pickDate(selectors.ticketFuture.tfShipped, tomorrow); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 0); + }); + + it('should search with the origin IPT', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + + await page.clearInput(selectors.ticketFuture.shipped); + await page.clearInput(selectors.ticketFuture.tfShipped); + await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.tfIpt); + await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.tfState); + + await page.autocompleteSearch(selectors.ticketFuture.ipt, 'Horizontal'); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 0); + }); + + it('should search with the destination IPT', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + + await page.clearInput(selectors.ticketFuture.shipped); + await page.clearInput(selectors.ticketFuture.tfShipped); + await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.tfIpt); + await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.tfState); + + await page.autocompleteSearch(selectors.ticketFuture.tfIpt, 'Horizontal'); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 0); + }); + + it('should search with the origin grouped state', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + + await page.clearInput(selectors.ticketFuture.shipped); + await page.clearInput(selectors.ticketFuture.tfShipped); + await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.tfIpt); + await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.tfState); + + await page.autocompleteSearch(selectors.ticketFuture.state, 'Free'); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 3); + }); + + it('should search with the destination grouped state', async () => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + + await page.clearInput(selectors.ticketFuture.shipped); + await page.clearInput(selectors.ticketFuture.tfShipped); + await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.tfIpt); + await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.tfState); + + await page.autocompleteSearch(selectors.ticketFuture.tfState, 'Free'); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 0); + + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.clearInput(selectors.ticketFuture.shipped); + await page.clearInput(selectors.ticketFuture.tfShipped); + await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.tfIpt); + await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.tfState); + + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with an ID Origin', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableId, "13"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 2); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with an ID Destination', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableTfId, "12"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 5); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with an IPT Origin', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.autocompleteSearch(selectors.ticketFuture.tableIpt, 'Vertical'); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 1); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with an IPT Destination', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.autocompleteSearch(selectors.ticketFuture.tableTfIpt, 'Vertical'); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 1); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with especified Lines', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableLines, "0"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 1); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableLines, "1"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 5); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should search in smart-table with especified Liters', async () => { + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableLiters, "0"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 1); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.write(selectors.ticketFuture.tableLiters, "28"); + await page.keyboard.press("Enter"); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 5); + + await page.waitToClick(selectors.ticketFuture.tableButtonSearch); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); + await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); + }); + + it('should check the three last tickets and move to the future', async () => { + await page.waitToClick(selectors.ticketFuture.multiCheck); + await page.waitToClick(selectors.ticketFuture.firstCheck); + await page.waitToClick(selectors.ticketFuture.moveButton); + await page.waitToClick(selectors.ticketFuture.acceptButton); + const message = await page.waitForSnackbar(); + expect(message.text).toContain('Tickets moved successfully!'); + }); + +}); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index f03441c0f..ddf32c4a9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -136,5 +136,6 @@ "Not enough privileges to edit a client": "Not enough privileges to edit a client", "Claim pickup order sent": "Claim pickup order sent [({{claimId}})]({{{claimUrl}}}) to client *{{clientName}}*", "You don't have grant privilege": "You don't have grant privilege", - "You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user" + "You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user", + "MOVE_TICKET_CONFIRMATION": "Ticket {{id}} ({{originDated}}) merged with {{tfId}} ({{futureDated}}) [{{fullPath}}]" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8c6f2cac8..86221d755 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -239,5 +239,6 @@ "This route does not exists": "Esta ruta no existe", "Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*", "You don't have grant privilege": "No tienes privilegios para dar privilegios", - "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario" + "You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario", + "MOVE_TICKET_CONFIRMATION": "Ticket {{id}} ({{originDated}}) fusionado con {{tfId}} ({{futureDated}}) [{{fullPath}}]" } 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 0682cef09..9fcbf028f 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -11,7 +11,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {order: 'id DESC'}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toEqual(30); await tx.rollback(); } catch (e) { @@ -39,7 +39,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toEqual(16); + expect(result.length).toEqual(19); await tx.rollback(); } catch (e) { @@ -87,7 +87,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toEqual(30); await tx.rollback(); } catch (e) { @@ -130,7 +130,7 @@ describe('SalesMonitor salesFilter()', () => { const length = result.length; const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; - expect(length).toEqual(10); + expect(length).toEqual(13); expect(anyResult.state).toMatch(/(Libre|Arreglar)/); await tx.rollback(); @@ -171,7 +171,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toEqual(23); + expect(result.length).toEqual(26); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket-future/getTicketsFuture.js b/modules/ticket/back/methods/ticket-future/getTicketsFuture.js new file mode 100644 index 000000000..132df064f --- /dev/null +++ b/modules/ticket/back/methods/ticket-future/getTicketsFuture.js @@ -0,0 +1,222 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('getTicketsFuture', { + description: 'Find all tickets that can be moved to the future', + accessType: 'READ', + accepts: [ + { + arg: 'originDated', + type: 'date', + description: 'The date in question', + required: true + }, + { + arg: 'futureDated', + type: 'date', + description: 'The date to probe', + required: true + }, + { + arg: 'litersMax', + type: 'number', + description: 'Maximum volume of tickets to catapult', + required: true + }, + { + arg: 'linesMax', + type: 'number', + description: 'Maximum number of lines of tickets to catapult', + required: true + }, + { + arg: 'warehouseFk', + type: 'number', + description: 'Warehouse identifier', + required: true + }, + { + arg: 'shipped', + type: 'date', + description: 'Origin shipped', + required: false + }, + { + arg: 'tfShipped', + type: 'date', + description: 'Destination shipped', + required: false + }, + { + arg: 'ipt', + type: 'string', + description: 'Origin Item Packaging Type', + required: false + }, + { + arg: 'tfIpt', + type: 'string', + description: 'Destination Item Packaging Type', + required: false + }, + { + arg: 'id', + type: 'number', + description: 'Origin id', + required: false + }, + { + arg: 'tfId', + type: 'number', + description: 'Destination id', + required: false + }, + { + arg: 'state', + type: 'string', + description: 'Origin state', + required: false + }, + { + arg: 'tfState', + type: 'string', + description: 'Destination state', + required: false + }, + { + arg: 'problems', + type: 'boolean', + description: `Whether to show only tickets with problems`, + required: false + }, + { + arg: 'filter', + type: 'object', + description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string` + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getTicketsFuture`, + verb: 'GET' + } + }); + + Self.getTicketsFuture = async (ctx, options) => { + const args = ctx.args; + const conn = Self.dataSource.connector; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'id': + return { 'f.id': value }; + case 'tfId': + return { 'f.ticketFuture': value }; + case 'shipped': + return { 'f.shipped': value }; + case 'tfShipped': + return { 'f.tfShipped': value }; + case 'ipt': + return { 'f.ipt': value }; + case 'tfIpt': + return { 'f.tfIpt': value }; + case 'state': + return { 'f.code': { like: `%${value}%` } }; + case 'tfState': + return { 'f.tfCode': { like: `%${value}%` } }; + } + }); + + let filter = mergeFilters(ctx.args.filter, { where }); + const stmts = []; + let stmt; + + stmt = new ParameterizedSQL( + `CALL vn.ticket_canbePostponed(?,?,?,?,?)`, + [args.originDated, args.futureDated, args.litersMax, args.linesMax, args.warehouseFk]); + + stmts.push(stmt); + + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems'); + + stmt = new ParameterizedSQL(` + CREATE TEMPORARY TABLE tmp.sale_getProblems + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped + FROM tmp.filter f + LEFT JOIN alertLevel al ON al.id = f.alertLevel + WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)`); + stmts.push(stmt); + + stmts.push('CALL ticket_getProblems(FALSE)'); + + stmt = new ParameterizedSQL(` + SELECT f.*, tp.* + FROM tmp.filter f + LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id`); + + if (args.problems != undefined && (!args.originDated && !args.futureDated)) + throw new UserError('Choose a date range or days forward'); + + let condition; + let hasProblem; + let range; + let hasWhere; + switch (args.problems) { + case true: + condition = `or`; + hasProblem = true; + range = { neq: null }; + hasWhere = true; + break; + + case false: + condition = `and`; + hasProblem = null; + range = null; + hasWhere = true; + break; + } + + const problems = { + [condition]: [ + { 'tp.isFreezed': hasProblem }, + { 'tp.risk': hasProblem }, + { 'tp.hasTicketRequest': hasProblem }, + { 'tp.itemShortage': range }, + { 'tp.hasComponentLack': hasProblem }, + { 'tp.isTooLittle': hasProblem } + ] + }; + + if (hasWhere) { + filter = mergeFilters(filter, { where: problems }); + } + stmt.merge(conn.makeWhere(filter.where)); + + + const ticketsIndex = stmts.push(stmt) - 1; + + stmts.push( + `DROP TEMPORARY TABLE + tmp.filter, + tmp.ticket_problems`); + + const sql = ParameterizedSQL.join(stmts, ';'); + + const result = await conn.executeStmt(sql, myOptions); + + return result[ticketsIndex]; + }; +}; diff --git a/modules/ticket/back/methods/ticket-future/spec/getTicketsFuture.spec.js b/modules/ticket/back/methods/ticket-future/spec/getTicketsFuture.spec.js new file mode 100644 index 000000000..502ea3074 --- /dev/null +++ b/modules/ticket/back/methods/ticket-future/spec/getTicketsFuture.spec.js @@ -0,0 +1,438 @@ +const models = require('vn-loopback/server/server').models; + +describe('TicketFuture getTicketsFuture()', () => { + const today = new Date(); + today.setHours(0, 0, 0, 0); + const tomorrow = new Date(today.getDate() + 1); + + it('should return the tickets passing the required data', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the problems on true', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + problems: true + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the problems on false', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + problems: false + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the problems on null', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + problems: null + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the correct origin shipped', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + shipped: today + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the an incorrect origin shipped', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + shipped: tomorrow + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the correct destination shipped', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfShipped: today + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the an incorrect destination shipped', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfShipped: tomorrow + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the OK State in origin date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + state: "OK" + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the OK State in destination date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfState: "OK" + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the correct IPT in origin date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + ipt: null + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the incorrect IPT in origin date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + ipt: 0 + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the correct IPT in destination date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfIpt: null + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the incorrect IPT in destination date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfIpt: 0 + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the ID in origin date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + id: 13 + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets matching the ID in destination date', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const args = { + originDated: today, + futureDated: today, + litersMax: 9999, + linesMax: 9999, + warehouseFk: 1, + tfId: 12 + }; + + const ctx = { req: { accessToken: { userId: 9 } }, args }; + const result = await models.Ticket.getTicketsFuture(ctx, options); + + expect(result.length).toEqual(4); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + +}); diff --git a/modules/ticket/back/methods/ticket/merge.js b/modules/ticket/back/methods/ticket/merge.js new file mode 100644 index 000000000..e7f815128 --- /dev/null +++ b/modules/ticket/back/methods/ticket/merge.js @@ -0,0 +1,62 @@ +module.exports = Self => { + Self.remoteMethodCtx('merge', { + description: 'Merge one ticket into another', + accessType: 'WRITE', + accepts: [ + { + arg: 'tickets', + type: ['object'], + description: 'The array of tickets', + required: false + } + ], + returns: { + type: 'string', + root: true + }, + http: { + path: `/merge`, + verb: 'POST' + } + }); + + Self.merge = async (ctx, tickets, options) => { + const httpRequest = ctx.req; + const $t = httpRequest.__; + const origin = httpRequest.headers.origin; + 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 { + for (let ticket of tickets) { + const fullPath = `${origin}/#!/ticket/${ticket.ticketFuture}/summary`; + const message = $t('MOVE_TICKET_CONFIRMATION', { + originDated: new Date(ticket.originETD).toLocaleDateString('es-ES'), + futureDated: new Date(ticket.destETD).toLocaleDateString('es-ES'), + id: ticket.id, + tfId: ticket.ticketFuture, + fullPath + }); + if (!ticket.id || !ticket.ticketFuture) continue; + await models.Sale.updateAll({ ticketFk: ticket.id }, { ticketFk: ticket.ticketFuture }, myOptions); + await models.Ticket.setDeleted(ctx, ticket.id, myOptions); + await models.Chat.sendCheckingPresence(ctx, ticket.workerFk, message); + }; + if (tx) { + await tx.commit(); + } + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index c3dc40092..e2ab43aea 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -11,7 +11,7 @@ describe('ticket filter()', () => { const filter = {order: 'id DESC'}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toEqual(30); await tx.rollback(); } catch (e) { @@ -87,7 +87,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toEqual(30); await tx.rollback(); } catch (e) { @@ -130,7 +130,7 @@ describe('ticket filter()', () => { const length = result.length; const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; - expect(length).toEqual(10); + expect(length).toEqual(13); expect(anyResult.state).toMatch(/(Libre|Arreglar)/); await tx.rollback(); @@ -175,7 +175,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(23); + expect(result.length).toEqual(26); await tx.rollback(); } catch (e) { @@ -232,7 +232,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(22); + expect(result.length).toEqual(25); await tx.rollback(); } catch (e) { @@ -270,7 +270,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toEqual(30); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js new file mode 100644 index 000000000..713f86ad6 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -0,0 +1,58 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('ticket merge()', () => { + const tickets = [{ + id: 13, + ticketFuture: 12, + workerFk: 1, + originETD: new Date(), + destETD: new Date() + }]; + + const activeCtx = { + accessToken: { userId: 9 }, + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + const ctx = { + req: { + accessToken: { userId: 9 }, + headers: { origin: 'http://localhost:5000' }, + } + }; + ctx.req.__ = value => { + return value; + }; + + it('should merge two tickets', async () => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = { transaction: tx }; + const chatNotificationBeforeMerge = await models.Chat.find(); + + await models.Ticket.merge(ctx, tickets, options); + + const createdTicketLog = await models.TicketLog.find({ where: { originFk: tickets[0].id } }, options); + const deletedTicket = await models.Ticket.findOne({ where: { id: tickets[0].id } }, options); + const salesTicketFuture = await models.Sale.find({ where: { ticketFk: tickets[0].ticketFuture } }, options); + const chatNotificationAfterMerge = await models.Chat.find(); + + expect(createdTicketLog.length).toEqual(1); + expect(deletedTicket.isDeleted).toEqual(true); + expect(salesTicketFuture.length).toEqual(2); + expect(chatNotificationBeforeMerge.length).toEqual(chatNotificationAfterMerge.length - 2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index d8c785baa..96d29c46f 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -87,7 +87,7 @@ describe('sale priceDifference()', () => { const secondtItem = result.items[1]; expect(firstItem.movable).toEqual(410); - expect(secondtItem.movable).toEqual(1870); + expect(secondtItem.movable).toEqual(1810); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 21e800b36..82d8e3b1a 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -91,5 +91,8 @@ }, "TicketConfig": { "dataSource": "vn" + }, + "TicketFuture": { + "dataSource": "vn" } } diff --git a/modules/ticket/back/models/ticket-future.json b/modules/ticket/back/models/ticket-future.json new file mode 100644 index 000000000..5d0b24dbc --- /dev/null +++ b/modules/ticket/back/models/ticket-future.json @@ -0,0 +1,12 @@ +{ + "name": "TicketFuture", + "base": "PersistedModel", + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] + } \ No newline at end of file diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 9255e52e6..92036d77f 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -33,4 +33,6 @@ module.exports = function(Self) { require('../methods/ticket/closeByTicket')(Self); require('../methods/ticket/closeByAgency')(Self); require('../methods/ticket/closeByRoute')(Self); + require('../methods/ticket-future/getTicketsFuture')(Self); + require('../methods/ticket/merge')(Self); }; diff --git a/modules/ticket/front/future-search-panel/index.html b/modules/ticket/front/future-search-panel/index.html new file mode 100644 index 000000000..1b3ae453e --- /dev/null +++ b/modules/ticket/front/future-search-panel/index.html @@ -0,0 +1,111 @@ +
+ |
+ + Problems + | ++ Origin ID + | ++ Origin ETD + | ++ Origin State + | ++ IPT + | ++ Liters + | ++ Available Lines + | ++ Destination ID + | ++ Destination ETD + | ++ Destination State + | ++ IPT + | +
---|---|---|---|---|---|---|---|---|---|---|---|
+ |
+
+ |
+ + {{::ticket.id}} + | ++ + {{::ticket.originETD | date: 'dd/MM/yyyy'}} + + | ++ + {{::ticket.state}} + + | +{{::ticket.ipt}} | +{{::ticket.liters}} | +{{::ticket.lines}} | ++ + {{::ticket.ticketFuture}} + + | ++ + {{::ticket.destETD | date: 'dd/MM/yyyy'}} + + | ++ + {{::ticket.tfState}} + + | +{{::ticket.tfIpt}} | +