From 78eba23d1233e9d240b4ccef6dcb64d66c4db91b Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 24 Aug 2023 13:44:15 +0200 Subject: [PATCH 1/8] refs #6156 new field --- .../00-ModifyProc_ticket_canAdvance.sql | 128 ++++++++++++++++++ .../back/methods/ticket/getTicketsAdvance.js | 11 +- modules/ticket/front/advance/index.html | 12 +- modules/ticket/front/future/locale/es.yml | 1 + 4 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 db/changes/233601/00-ModifyProc_ticket_canAdvance.sql diff --git a/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql b/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql new file mode 100644 index 000000000..b0426711f --- /dev/null +++ b/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql @@ -0,0 +1,128 @@ +CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` ( + `id` INT auto_increment NULL, + `destinationOrder` INT NULL, + CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT INTO `vn`.`ticketCanAdvanceConfig` + SET `destinationOrder` = 5; + +DELIMITER $$ +CREATE OR REPLACE 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; + + CREATE OR REPLACE TEMPORARY TABLE tStock + (itemFk INT PRIMARY KEY, amount INT) + ENGINE = MEMORY; + + INSERT INTO tStock(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; + + CREATE OR REPLACE TEMPORARY TABLE tmp.filter + (INDEX (id)) + SELECT dest.*, + origin.* + FROM ( + SELECT s.ticketFk futureId, + t.workerFk, + t.shipped futureShipped, + t.totalWithVat futureTotalWithVat, + st.name futureState, + t.addressFk futureAddressFk, + 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(tst.amount,0))) hasStock, + st.classColor futureClassColor, + ( + count(s.id) - + SUM((s.quantity <= IFNULL(tst.amount,0))) + ) notMovableLines, + ( + count(s.id) = + SUM((s.quantity <= IFNULL(tst.amount,0))) + ) isFullMovable + 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 tStock tst ON tst.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, + 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`, + st.classColor, + IF(HOUR(t.shipped), + HOUR(t.shipped), + COALESCE(HOUR(zc.hour),HOUR(z.hour)) + ) preparation + 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 + JOIN ticketCanAdvanceConfig + LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) + AND t.warehouseFk = vWarehouseFk + AND st.order <= destinationOrder + GROUP BY t.id + ) dest ON dest.addressFk = origin.futureAddressFk + WHERE origin.hasStock != 0; + + DROP TEMPORARY TABLE tStock; +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index ec9314db2..5ad5152b9 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -110,13 +110,12 @@ module.exports = Self => { stmt = new ParameterizedSQL( `CALL vn.ticket_canAdvance(?,?,?)`, - [args.dateFuture, args.dateToAdvance, args.warehouseFk]); + [args.dateFuture, args.dateToAdvance, args.warehouseFk] + ); stmts.push(stmt); - stmt = new ParameterizedSQL(` - SELECT f.* - FROM tmp.filter f`); + stmt = new ParameterizedSQL(`SELECT f.* FROM tmp.filter f`); stmt.merge(conn.makeWhere(filter.where)); @@ -124,9 +123,7 @@ module.exports = Self => { stmt.merge(conn.makeLimit(filter)); const ticketsIndex = stmts.push(stmt) - 1; - stmts.push( - `DROP TEMPORARY TABLE - tmp.filter`); + stmts.push(`DROP TEMPORARY TABLE tmp.filter`); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); diff --git a/modules/ticket/front/advance/index.html b/modules/ticket/front/advance/index.html index e6f16c965..8c50325fa 100644 --- a/modules/ticket/front/advance/index.html +++ b/modules/ticket/front/advance/index.html @@ -32,8 +32,8 @@ - Destination - Origin + Destination + Origin @@ -43,8 +43,7 @@ check-field="checked"> - - + ID @@ -54,6 +53,9 @@ IPT + + Preparation + State @@ -120,6 +122,7 @@ {{::ticket.ipt | dashIfEmpty}} + {{::ticket.preparation | dashIfEmpty}} @@ -164,7 +167,6 @@ {{::(ticket.futureTotalWithVat ? ticket.futureTotalWithVat : 0) | currency: 'EUR': 2}} - diff --git a/modules/ticket/front/future/locale/es.yml b/modules/ticket/front/future/locale/es.yml index 9fceea111..3645ad8ac 100644 --- a/modules/ticket/front/future/locale/es.yml +++ b/modules/ticket/front/future/locale/es.yml @@ -14,3 +14,4 @@ Success: Tickets movidos correctamente IPT: Encajado Origin Date: Fecha origen Destination Date: Fecha destino +Preparation: Preparación From 31b04cba75e57d98cb0914acec72249a4017f498 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 12:08:12 +0200 Subject: [PATCH 2/8] feat(salix): refs #6156 #6156 Move to myt version --- .../00-ModifyProc_ticket_canAdvance.sql | 128 ------------- .../vn/procedures/ticket_canAdvance.sql | 181 +++++++++--------- .../11221-chocolateSalal/00-firstScript.sql | 12 ++ 3 files changed, 98 insertions(+), 223 deletions(-) delete mode 100644 db/changes/233601/00-ModifyProc_ticket_canAdvance.sql create mode 100644 db/versions/11221-chocolateSalal/00-firstScript.sql diff --git a/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql b/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql deleted file mode 100644 index b0426711f..000000000 --- a/db/changes/233601/00-ModifyProc_ticket_canAdvance.sql +++ /dev/null @@ -1,128 +0,0 @@ -CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` ( - `id` INT auto_increment NULL, - `destinationOrder` INT NULL, - CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `vn`.`ticketCanAdvanceConfig` - SET `destinationOrder` = 5; - -DELIMITER $$ -CREATE OR REPLACE 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; - - CREATE OR REPLACE TEMPORARY TABLE tStock - (itemFk INT PRIMARY KEY, amount INT) - ENGINE = MEMORY; - - INSERT INTO tStock(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; - - CREATE OR REPLACE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT dest.*, - origin.* - FROM ( - SELECT s.ticketFk futureId, - t.workerFk, - t.shipped futureShipped, - t.totalWithVat futureTotalWithVat, - st.name futureState, - t.addressFk futureAddressFk, - 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(tst.amount,0))) hasStock, - st.classColor futureClassColor, - ( - count(s.id) - - SUM((s.quantity <= IFNULL(tst.amount,0))) - ) notMovableLines, - ( - count(s.id) = - SUM((s.quantity <= IFNULL(tst.amount,0))) - ) isFullMovable - 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 tStock tst ON tst.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, - 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`, - st.classColor, - IF(HOUR(t.shipped), - HOUR(t.shipped), - COALESCE(HOUR(zc.hour),HOUR(z.hour)) - ) preparation - 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 - JOIN ticketCanAdvanceConfig - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN `zone` z ON z.id = t.zoneFk - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t.warehouseFk = vWarehouseFk - AND st.order <= destinationOrder - GROUP BY t.id - ) dest ON dest.addressFk = origin.futureAddressFk - WHERE origin.hasStock != 0; - - DROP TEMPORARY TABLE tStock; -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 44149126a..58b09e404 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -1,5 +1,7 @@ + + DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) +CREATE OR REPLACE 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. @@ -8,91 +10,79 @@ BEGIN * @param vDateToAdvance Fecha a cuando se quiere adelantar. * @param vWarehouseFk Almacén */ + DECLARE vDateInventory DATE; - CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL); - CALL item_getMinacum( - vWarehouseFk, - vDateToAdvance, - DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance), - NULL - ); + SELECT inventoried INTO vDateInventory FROM config; + + CREATE OR REPLACE TEMPORARY TABLE tStock + (itemFk INT PRIMARY KEY, amount INT) + ENGINE = MEMORY; + + INSERT INTO tStock(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; CREATE OR REPLACE 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, - dest.agencyModeFk, - origin.futureAgency, - origin.agencyModeFk futureAgencyModeFk, - dest.lines, - dest.liters, - origin.futureLines - origin.hasStock AS notMovableLines, - (origin.futureLines = origin.hasStock) AS isFullMovable, - dest.zoneFk, - origin.futureZoneFk, - origin.futureZoneName, - origin.classColor futureClassColor, - dest.classColor, - origin.clientFk futureClientFk, - origin.addressFk futureAddressFk, - origin.warehouseFk futureWarehouseFk, - origin.companyFk futureCompanyFk, - IFNULL(dest.nickname, origin.nickname) nickname, - dest.landed + SELECT dest.*, + origin.* FROM ( - SELECT - s.ticketFk, - c.salesPersonFk workerFk, - t.shipped, - t.totalWithVat, - st.name futureState, - 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(il.stock,0) + IFNULL(im.amount, 0))) hasStock, - z.id futureZoneFk, - z.name futureZoneName, - st.classColor, - t.clientFk, - t.nickname, + SELECT s.ticketFk futureId, + t.workerFk, + t.shipped futureShipped, + t.totalWithVat futureTotalWithVat, + st.name futureState, + t.addressFk futureAddressFk, + 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(tst.amount,0))) hasStock, + st.classColor futureClassColor, + ( + count(s.id) - + SUM((s.quantity <= IFNULL(tst.amount,0))) + ) notMovableLines, + ( + count(s.id) = + SUM((s.quantity <= IFNULL(tst.amount,0))) + ) isFullMovable + 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 tStock tst ON tst.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, t.addressFk, - t.warehouseFk, - t.companyFk, - t.agencyModeFk - FROM ticket t - JOIN client c ON c.id = t.clientFk - 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 - JOIN zone z ON t.zoneFk = z.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.itemMinacum im ON im.itemFk = i.id - AND im.warehouseFk = vWarehouseFk - LEFT JOIN tmp.itemList il ON il.itemFk = i.id - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) origin - LEFT JOIN ( - SELECT - t.id ticketFk, st.name state, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, t.shipped, @@ -101,31 +91,32 @@ BEGIN CAST(SUM(litros) AS DECIMAL(10,0)) liters, CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, st.classColor, - t.clientFk, - t.nickname, - t.addressFk, - t.zoneFk, - t.warehouseFk, - t.companyFk, - t.landed, - t.agencyModeFk + CONCAT_WS(':', + IF(HOUR(t.shipped), + HOUR(t.shipped), + COALESCE(HOUR(zc.hour),HOUR(z.hour))), + IF(MINUTE(t.shipped), + MINUTE(t.shipped), + COALESCE(MINUTE(zc.hour),MINUTE(z.hour))) + ) preparation 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 `state` st ON st.id = ts.stateFk JOIN agencyMode am ON t.agencyModeFk = am.id + JOIN ticketCanAdvanceConfig LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) AND t.warehouseFk = vWarehouseFk - AND st.order <= 5 + AND st.order <= destinationOrder GROUP BY t.id - ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock; + ) dest ON dest.addressFk = origin.futureAddressFk + WHERE origin.hasStock != 0; - DROP TEMPORARY TABLE IF EXISTS - tmp.itemList, - tmp.itemMinacum; + DROP TEMPORARY TABLE tStock; END$$ DELIMITER ; diff --git a/db/versions/11221-chocolateSalal/00-firstScript.sql b/db/versions/11221-chocolateSalal/00-firstScript.sql new file mode 100644 index 000000000..8dba40cb3 --- /dev/null +++ b/db/versions/11221-chocolateSalal/00-firstScript.sql @@ -0,0 +1,12 @@ +-- Place your SQL code here +CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` ( + `id` INT auto_increment NULL, + `destinationOrder` INT NULL, + CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT INTO `vn`.`ticketCanAdvanceConfig` + SET `destinationOrder` = 5; From 773933ca3c32bec8745457afd9e23fb80d96c0fe Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 15:11:55 +0200 Subject: [PATCH 3/8] feat(salix): refs #6156 #6156 change config sql --- db/versions/11221-chocolateSalal/00-firstScript.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/versions/11221-chocolateSalal/00-firstScript.sql b/db/versions/11221-chocolateSalal/00-firstScript.sql index 8dba40cb3..680f0ee0e 100644 --- a/db/versions/11221-chocolateSalal/00-firstScript.sql +++ b/db/versions/11221-chocolateSalal/00-firstScript.sql @@ -1,12 +1,12 @@ -- Place your SQL code here -CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` ( - `id` INT auto_increment NULL, - `destinationOrder` INT NULL, - CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id) +CREATE TABLE IF NOT EXISTS vn.ticketCanAdvanceConfig ( + id INT NOT NULL unsigned PRIMARY KEY, + destinationOrder INT NULL, + CONSTRAINT ticketCanAdvanceConfig_PK PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -INSERT INTO `vn`.`ticketCanAdvanceConfig` - SET `destinationOrder` = 5; +INSERT INTO vn.ticketCanAdvanceConfig + SET destinationOrder = 5; From f70f475223313874abe7e9ea787a4f9e12667db8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 15:12:44 +0200 Subject: [PATCH 4/8] feat(salix): refs #6156 #6156 change user definer --- db/routines/vn/procedures/ticket_canAdvance.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 58b09e404..b9e27784d 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -1,7 +1,7 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) +CREATE OR REPLACE DEFINER=`vn`@`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. From f9a25617f0eed7ab6e5c6e0a0eba104dd2263e47 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 15:13:08 +0200 Subject: [PATCH 5/8] feat(salix): refs #6156 #6156 add missing values --- db/routines/vn/procedures/ticket_canAdvance.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index b9e27784d..b1f135e5f 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -45,7 +45,10 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) SELECT dest.*, - origin.* + origin.*, + IFNULL(dest.nickname, origin.nickname) nickname, + (origin.futureLines = origin.hasStock) AS isFullMovable, + origin.futureLines - origin.hasStock AS notMovableLines FROM ( SELECT s.ticketFk futureId, t.workerFk, From 615f57b2e6d5fd2951bee7f5cd9822f61af87ee5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 15:13:32 +0200 Subject: [PATCH 6/8] feat(salix): refs #6156 #6156 simplify CONCAT_WS --- db/routines/vn/procedures/ticket_canAdvance.sql | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index b1f135e5f..5be8d7d7f 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -95,13 +95,9 @@ BEGIN CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, st.classColor, CONCAT_WS(':', - IF(HOUR(t.shipped), - HOUR(t.shipped), - COALESCE(HOUR(zc.hour),HOUR(z.hour))), - IF(MINUTE(t.shipped), - MINUTE(t.shipped), - COALESCE(MINUTE(zc.hour),MINUTE(z.hour))) - ) preparation + COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)), + COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) + ) preparation FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id From c407dde7a021c3defe5ca8003758dbf163995159 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Sep 2024 15:14:01 +0200 Subject: [PATCH 7/8] feat(salix): refs #6156 #6156 remove redundant condition --- db/routines/vn/procedures/ticket_canAdvance.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 5be8d7d7f..c5b918def 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -114,7 +114,7 @@ BEGIN AND st.order <= destinationOrder GROUP BY t.id ) dest ON dest.addressFk = origin.futureAddressFk - WHERE origin.hasStock != 0; + WHERE origin.hasStock; DROP TEMPORARY TABLE tStock; END$$ From 92f305b9fd5458f13291e8f8ff5b86bdb6e864f5 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 11 Sep 2024 10:19:55 +0200 Subject: [PATCH 8/8] fix: refs #6156 proc and version --- .../vn/procedures/ticket_canAdvance.sql | 142 ++++++++++-------- .../11221-chocolateSalal/00-firstScript.sql | 15 +- 2 files changed, 85 insertions(+), 72 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index c5b918def..57c3f4235 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -1,5 +1,3 @@ - - DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) BEGIN @@ -10,82 +8,90 @@ BEGIN * @param vDateToAdvance Fecha a cuando se quiere adelantar. * @param vWarehouseFk Almacén */ - DECLARE vDateInventory DATE; - SELECT inventoried INTO vDateInventory FROM config; - - CREATE OR REPLACE TEMPORARY TABLE tStock - (itemFk INT PRIMARY KEY, amount INT) - ENGINE = MEMORY; - - INSERT INTO tStock(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; + CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL); + CALL item_getMinacum( + vWarehouseFk, + vDateToAdvance, + DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance), + NULL + ); CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) - SELECT dest.*, - origin.*, - IFNULL(dest.nickname, origin.nickname) nickname, + 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, + dest.agencyModeFk, + origin.futureAgency, + origin.agencyModeFk futureAgencyModeFk, + dest.lines, + dest.liters, + origin.futureLines - origin.hasStock AS notMovableLines, (origin.futureLines = origin.hasStock) AS isFullMovable, - origin.futureLines - origin.hasStock AS notMovableLines + dest.zoneFk, + origin.futureZoneFk, + origin.futureZoneName, + origin.classColor futureClassColor, + dest.classColor, + origin.clientFk futureClientFk, + origin.addressFk futureAddressFk, + origin.warehouseFk futureWarehouseFk, + origin.companyFk futureCompanyFk, + IFNULL(dest.nickname, origin.nickname) nickname, + dest.landed, + dest.preparation FROM ( - SELECT s.ticketFk futureId, - t.workerFk, - t.shipped futureShipped, - t.totalWithVat futureTotalWithVat, + SELECT s.ticketFk, + c.salesPersonFk workerFk, + t.shipped, + t.totalWithVat, st.name futureState, - t.addressFk futureAddressFk, 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(tst.amount,0))) hasStock, - st.classColor futureClassColor, - ( - count(s.id) - - SUM((s.quantity <= IFNULL(tst.amount,0))) - ) notMovableLines, - ( - count(s.id) = - SUM((s.quantity <= IFNULL(tst.amount,0))) - ) isFullMovable + SUM(s.quantity <= (IFNULL(il.stock,0) + IFNULL(im.amount, 0))) hasStock, + z.id futureZoneFk, + z.name futureZoneName, + st.classColor, + t.clientFk, + t.nickname, + t.addressFk, + t.warehouseFk, + t.companyFk, + t.agencyModeFk FROM ticket t + JOIN client c ON c.id = t.clientFk 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 + JOIN `zone` z ON t.zoneFk = z.id + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tStock tst ON tst.itemFk = i.id + LEFT JOIN tmp.itemMinacum im ON im.itemFk = i.id + AND im.warehouseFk = vWarehouseFk + LEFT JOIN tmp.itemList il ON il.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, - t.addressFk, + ) origin + LEFT JOIN ( + SELECT t.id ticketFk, st.name state, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, t.shipped, @@ -94,9 +100,17 @@ BEGIN CAST(SUM(litros) AS DECIMAL(10,0)) liters, CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, st.classColor, - CONCAT_WS(':', - COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)), - COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) + t.clientFk, + t.nickname, + t.addressFk, + t.zoneFk, + t.warehouseFk, + t.companyFk, + t.landed, + t.agencyModeFk, + SEC_TO_TIME( + COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)) * 3600 + + COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) * 60 ) preparation FROM ticket t JOIN sale s ON s.ticketFk = t.id @@ -105,17 +119,19 @@ BEGIN JOIN ticketState ts ON ts.ticketFk = t.id JOIN `state` st ON st.id = ts.stateFk JOIN agencyMode am ON t.agencyModeFk = am.id - JOIN ticketCanAdvanceConfig LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk LEFT JOIN `zone` z ON z.id = t.zoneFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + JOIN ticketCanAdvanceConfig tc WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) AND t.warehouseFk = vWarehouseFk - AND st.order <= destinationOrder + AND st.order <= tc.destinationOrder GROUP BY t.id - ) dest ON dest.addressFk = origin.futureAddressFk + ) dest ON dest.addressFk = origin.addressFk WHERE origin.hasStock; - DROP TEMPORARY TABLE tStock; + DROP TEMPORARY TABLE IF EXISTS + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; diff --git a/db/versions/11221-chocolateSalal/00-firstScript.sql b/db/versions/11221-chocolateSalal/00-firstScript.sql index 680f0ee0e..bca742585 100644 --- a/db/versions/11221-chocolateSalal/00-firstScript.sql +++ b/db/versions/11221-chocolateSalal/00-firstScript.sql @@ -1,12 +1,9 @@ -- Place your SQL code here CREATE TABLE IF NOT EXISTS vn.ticketCanAdvanceConfig ( - id INT NOT NULL unsigned PRIMARY KEY, - destinationOrder INT NULL, - CONSTRAINT ticketCanAdvanceConfig_PK PRIMARY KEY (id) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; + id int(10) unsigned NOT NULL, + destinationOrder INT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `ticketCanAdvanceConfig_check` CHECK (`id` = 1) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -INSERT INTO vn.ticketCanAdvanceConfig - SET destinationOrder = 5; +INSERT INTO vn.ticketCanAdvanceConfig SET id =1, destinationOrder = 5; \ No newline at end of file