diff --git a/db/changes/230402/00-ticket_canAdvance.sql b/db/changes/230402/00-ticket_canAdvance.sql new file mode 100644 index 000000000..d7386e9d1 --- /dev/null +++ b/db/changes/230402/00-ticket_canAdvance.sql @@ -0,0 +1,127 @@ +DROP PROCEDURE IF EXISTS `vn`.`ticket_canAdvance`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) +BEGIN +/** + * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. + * + * @param vDateFuture Fecha de los tickets que se quieren adelantar. + * @param vDateToAdvance Fecha a cuando se quiere adelantar. + * @param vWarehouseFk Almacén + */ + + DECLARE vDateInventory DATE; + + SELECT inventoried INTO vDateInventory FROM config; + + DROP TEMPORARY TABLE IF EXISTS tmp.stock; + CREATE TEMPORARY TABLE tmp.stock + (itemFk INT PRIMARY KEY, + amount INT) + ENGINE = MEMORY; + + INSERT INTO tmp.stock(itemFk, amount) + SELECT itemFk, SUM(quantity) amount FROM + ( + SELECT itemFk, quantity + FROM itemTicketOut + WHERE shipped >= vDateInventory + AND shipped < vDateFuture + AND warehouseFk = vWarehouseFk + UNION ALL + SELECT itemFk, quantity + FROM itemEntryIn + WHERE landed >= vDateInventory + AND landed < vDateFuture + AND isVirtualStock = FALSE + AND warehouseInFk = vWarehouseFk + UNION ALL + SELECT itemFk, quantity + FROM itemEntryOut + WHERE shipped >= vDateInventory + AND shipped < vDateFuture + AND warehouseOutFk = vWarehouseFk + ) t + GROUP BY itemFk HAVING amount != 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.filter; + CREATE TEMPORARY TABLE tmp.filter + (INDEX (id)) + + SELECT + origin.ticketFk futureId, + dest.ticketFk id, + dest.state, + origin.futureState, + origin.futureIpt, + dest.ipt, + origin.workerFk, + origin.futureLiters, + origin.futureLines, + dest.shipped, + origin.shipped futureShipped, + dest.totalWithVat, + origin.totalWithVat futureTotalWithVat, + dest.agency, + origin.futureAgency, + dest.lines, + dest.liters, + origin.futureLines - origin.hasStock AS notMovableLines, + (origin.futureLines = origin.hasStock) AS isFullMovable + FROM ( + SELECT + s.ticketFk, + t.workerFk, + t.shipped, + t.totalWithVat, + st.name futureState, + t.addressFk, + am.name futureAgency, + count(s.id) futureLines, + GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, + CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, + SUM((s.quantity <= IFNULL(st.amount,0))) hasStock + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN saleVolume sv ON sv.saleFk = s.id + JOIN item i ON i.id = s.itemFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN state st ON st.id = ts.stateFk + JOIN agencyMode am ON t.agencyModeFk = am.id + LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + LEFT JOIN tmp.stock st ON st.itemFk = i.id + WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) + AND t.warehouseFk = vWarehouseFk + GROUP BY t.id + ) origin + JOIN ( + SELECT + t.id ticketFk, + t.addressFk, + st.name state, + GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, + t.shipped, + t.totalWithVat, + am.name agency, + CAST(SUM(litros) AS DECIMAL(10,0)) liters, + CAST(COUNT(*) AS DECIMAL(10,0)) `lines` + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN saleVolume sv ON sv.saleFk = s.id + JOIN item i ON i.id = s.itemFk + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN state st ON st.id = ts.stateFk + JOIN agencyMode am ON t.agencyModeFk = am.id + LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) + AND t.warehouseFk = vWarehouseFk + AND st.order <= 5 + GROUP BY t.id + ) dest ON dest.addressFk = origin.addressFk + WHERE origin.hasStock != 0; + + DROP TEMPORARY TABLE tmp.stock; +END$$ +DELIMITER ; diff --git a/db/changes/230601/00-ticket_canAdvance.sql b/db/changes/230601/00-ticket_canAdvance.sql deleted file mode 100644 index 68942a286..000000000 --- a/db/changes/230601/00-ticket_canAdvance.sql +++ /dev/null @@ -1,114 +0,0 @@ -DROP PROCEDURE IF EXISTS vn.ticket_canAdvance; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM vn.config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM vn.itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - - SELECT - *, - CASE WHEN sub.futureLines = hasStock THEN '1' ELSE '0' END AS fullMovable - FROM (SELECT s.ticketFk futureId, - t2.ticketFk id, - count(DISTINCT s.id) saleCount, - t2.state, - st.name futureState, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - t2.ipt, - t.workerFk, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - CAST(COUNT(*) AS DECIMAL(10,0)) `futureLines`, - t2.shipped, - t.shipped futureShipped, - t2.totalWithVat, - t.totalWithVat futureTotalWithVat, - t2.agency, - am.name futureAgency, - t2.lines, - t2.liters, - SUM((s.quantity <= IFNULL(st.amount,0))) AS hasStock - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.saleVolume sv ON sv.saleFk = s.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id - JOIN (SELECT - t2.id ticketFk, - t2.addressFk, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t2.shipped, - t2.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines` - FROM vn.ticket t2 - JOIN vn.sale s ON s.ticketFk = t2.id - JOIN vn.saleVolume sv ON sv.saleFk = s.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticketState ts ON ts.ticketFk = t2.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.agencyMode am ON t2.agencyModeFk = am.id - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t2.warehouseFk = vWarehouseFk - AND st.order <= 5 - GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) sub - WHERE hasStock != 0; - - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 32f1de99f..e592bc123 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -778,18 +778,16 @@ export default { ipt: 'vn-autocomplete[label="Destination IPT"]', tableIpt: 'vn-autocomplete[name="ipt"]', tableFutureIpt: 'vn-autocomplete[name="futureIpt"]', - futureState: 'vn-check[label="Pending Origin"]', - state: 'vn-check[label="Pending Destination"]', + isFullMovable: 'vn-check[ng-model="filter.isFullMovable"]', warehouseFk: 'vn-autocomplete[label="Warehouse"]', tableButtonSearch: 'vn-button[vn-tooltip="Search"]', moveButton: 'vn-button[vn-tooltip="Advance tickets"]', acceptButton: '.vn-confirm.shown button[response="accept"]', - multiCheck: 'vn-multi-check', + firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', tableId: 'vn-textfield[name="id"]', tableFutureId: 'vn-textfield[name="futureId"]', tableLiters: 'vn-textfield[name="liters"]', tableLines: 'vn-textfield[name="lines"]', - tableStock: 'vn-textfield[name="hasStock"]', submit: 'vn-submit[label="Search"]', table: 'tbody > tr:not(.empty-rows)' }, diff --git a/e2e/paths/05-ticket/22_advance.spec.js b/e2e/paths/05-ticket/22_advance.spec.js index 49ab5b0fc..c92cd7a20 100644 --- a/e2e/paths/05-ticket/22_advance.spec.js +++ b/e2e/paths/05-ticket/22_advance.spec.js @@ -88,7 +88,7 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); await page.autocompleteSearch(selectors.ticketAdvance.tableFutureIpt, 'Vertical'); - const request = httpRequests.find(req => req.includes(('ipt'))); + const request = httpRequests.find(req => req.includes(('futureIpt'))); expect(request).toBeDefined(); @@ -103,7 +103,7 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); await page.autocompleteSearch(selectors.ticketAdvance.tableIpt, 'Vertical'); - const request = httpRequests.find(req => req.includes(('futureIpt'))); + const request = httpRequests.find(req => req.includes(('ipt'))); expect(request).toBeDefined(); @@ -114,8 +114,8 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.submit); }); - it('should check the one ticket and move to the present', async() => { - await page.waitToClick(selectors.ticketAdvance.multiCheck); + it('should check the first ticket and move to the present', async() => { + await page.waitToClick(selectors.ticketAdvance.firstCheck); await page.waitToClick(selectors.ticketAdvance.moveButton); await page.waitToClick(selectors.ticketAdvance.acceptButton); const message = await page.waitForSnackbar(); diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 86911a477..ec9314db2 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,7 +50,7 @@ module.exports = Self => { required: false }, { - arg: 'fullMovable', + arg: 'isFullMovable', type: 'boolean', description: 'True when lines and stock of origin are equal', required: false @@ -99,8 +99,8 @@ module.exports = Self => { {'f.futureIpt': null} ] }; - case 'fullMovable': - return {'f.fullMovable': value}; + case 'isFullMovable': + return {'f.isFullMovable': value}; } }); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 1d1681b09..126f6b1af 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -39,7 +39,7 @@ describe('ticket getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - fullMovable: true + isFullMovable: true }; const ctx = {req: {accessToken: {userId: 9}}, args}; @@ -64,7 +64,7 @@ describe('ticket getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - fullMovable: false + isFullMovable: false }; const ctx = {req: {accessToken: {userId: 9}}, args}; diff --git a/modules/ticket/front/advance-search-panel/index.html b/modules/ticket/front/advance-search-panel/index.html index 233d00127..ee18c26f9 100644 --- a/modules/ticket/front/advance-search-panel/index.html +++ b/modules/ticket/front/advance-search-panel/index.html @@ -42,7 +42,7 @@ Liters - - Stock + + Not Movable Lines @@ -155,7 +155,7 @@ {{::ticket.futureLiters | dashIfEmpty}} - {{::ticket.hasStock | dashIfEmpty}} + {{::ticket.notMovableLines | dashIfEmpty}} {{::ticket.futureLines | dashIfEmpty}}