From cdaf8a7a6771db503a724fb747e6df29ea13d751 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Sep 2024 08:43:53 +0200 Subject: [PATCH 1/6] fix: refs #6900 fine tunning --- modules/invoiceIn/back/methods/invoice-in/filter.js | 5 ++--- modules/invoiceIn/back/methods/invoice-in/getTotals.js | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/filter.js b/modules/invoiceIn/back/methods/invoice-in/filter.js index 8a884e211..936f7bb6c 100644 --- a/modules/invoiceIn/back/methods/invoice-in/filter.js +++ b/modules/invoiceIn/back/methods/invoice-in/filter.js @@ -138,9 +138,9 @@ module.exports = Self => { ? {'ii.id': value} : {'s.name': {like: `%${value}%`}}; case 'from': - return {'ii.created': {gte: value}}; + return {'ii.issued': {gte: value}}; case 'to': - return {'ii.created': {lte: value}}; + return {'ii.issued': {lte: value}}; case 'fi': return {'s.nif': value}; case 'account': @@ -173,7 +173,6 @@ module.exports = Self => { const stmt = new ParameterizedSQL( `SELECT ii.id, - ii.serialNumber, ii.serial, ii.issued, ii.isBooked, diff --git a/modules/invoiceIn/back/methods/invoice-in/getTotals.js b/modules/invoiceIn/back/methods/invoice-in/getTotals.js index 7bef9f7e9..c4e73abc2 100644 --- a/modules/invoiceIn/back/methods/invoice-in/getTotals.js +++ b/modules/invoiceIn/back/methods/invoice-in/getTotals.js @@ -27,10 +27,12 @@ module.exports = Self => { const [result] = await Self.rawSql(` SELECT iit.*, - SUM(iidd.amount) totalDueDay + SUM(iidd.amount) totalDueDay, + SUM(iidd.foreignValue) totalDueDayForeignValue FROM vn.invoiceIn ii LEFT JOIN ( SELECT SUM(iit.taxableBase) totalTaxableBase, + SUM(iit.foreignValue) totalTaxableBaseForeignValue, CAST( SUM(IFNULL(iit.taxableBase * (1 + (ti.PorcentajeIva / 100)), iit.taxableBase)) AS DECIMAL(10, 2) From 4ea1177d385811cf2d8c42a9623fa3ad4c5323a6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 2 Sep 2024 13:55:44 +0200 Subject: [PATCH 2/6] chore: refs #6900 fix test --- .../methods/invoice-in/specs/filter.spec.js | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js index ff2164783..48310b32a 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js @@ -47,29 +47,6 @@ describe('InvoiceIn filter()', () => { } }); - it('should return the invoice in matching the serial number', async() => { - const tx = await models.InvoiceIn.beginTransaction({}); - const options = {transaction: tx}; - - try { - const ctx = { - args: { - serialNumber: '1002', - } - }; - - const result = await models.InvoiceIn.filter(ctx, {}, options); - - expect(result.length).toEqual(1); - expect(result[0].serialNumber).toEqual(1002); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - it('should return the invoice in matching the account', async() => { const tx = await models.InvoiceIn.beginTransaction({}); const options = {transaction: tx}; @@ -158,7 +135,7 @@ describe('InvoiceIn filter()', () => { const result = await models.InvoiceIn.filter(ctx, {}, options); - expect(result.length).toEqual(5); + expect(result.length).toEqual(6); await tx.rollback(); } catch (e) { From 74a5d1f2173b7c4d7f924d1cf3dcc8590ef389cb Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 4 Sep 2024 12:23:01 +0200 Subject: [PATCH 3/6] fix: ticket #216260 buy_recalcPrices --- .../vn/procedures/buy_recalcPrices.sql | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/db/routines/vn/procedures/buy_recalcPrices.sql b/db/routines/vn/procedures/buy_recalcPrices.sql index 35eb00cf1..c63e7c55c 100644 --- a/db/routines/vn/procedures/buy_recalcPrices.sql +++ b/db/routines/vn/procedures/buy_recalcPrices.sql @@ -2,51 +2,56 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPrices`() BEGIN /** - * Recalcula los precios para las compras insertadas en tmp.buyRecalc + * Recalcula los precios para las compras insertadas en tmp.buyRecalc. * * @param tmp.buyRecalc (id) */ DECLARE vLanded DATE; DECLARE vWarehouseFk INT; - DECLARE vHasNotPrice BOOL; - DECLARE vBuyingValue DECIMAL(10,4); - DECLARE vPackagingFk VARCHAR(10); DECLARE vIsWarehouseFloramondo BOOL; + DECLARE vDone BOOL; + DECLARE vTravels CURSOR FOR + SELECT t.landed, t.warehouseInFk, (w.code = 'flm') + FROM tmp.buyRecalc br + JOIN buy b ON b.id = br.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + GROUP BY t.landed, t.warehouseInFk, (w.code = 'flm'); - SELECT t.landed, t.warehouseInFk, (w.`name` = 'Floramondo') - INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo - FROM tmp.buyRecalc br - JOIN buy b ON b.id = br.id - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - LIMIT 1; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - CALL rate_getPrices(vLanded, vWarehouseFk); + OPEN vTravels; + l: LOOP + SET vDone = FALSE; + FETCH vTravels INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo; - UPDATE buy b - JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id) - LEFT JOIN packaging p ON p.id = b.packagingFk - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN itemType it ON it.id = i.typeFk - JOIN travel tr ON tr.id = e.travelFk - JOIN agencyMode am ON am.id = tr.agencyModeFk - JOIN tmp.rate r - JOIN volumeConfig vc - SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000) - / b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0), - b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3), - b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)), - b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 - b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), - b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); + IF vDone THEN + LEAVE l; + END IF; - SELECT (b.buyingValue = b.price2), b.buyingValue, b.packagingFk - INTO vHasNotPrice, vBuyingValue, vPackagingFk - FROM vn.buy b - WHERE b.id = @buyId AND b.buyingValue <> 0.01; + CALL rate_getPrices(vLanded, vWarehouseFk); - DROP TEMPORARY TABLE tmp.rate; + UPDATE buy b + JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id) + LEFT JOIN packaging p ON p.id = b.packagingFk + JOIN item i ON i.id = b.itemFk + JOIN entry e ON e.id = b.entryFk + JOIN itemType it ON it.id = i.typeFk + JOIN travel tr ON tr.id = e.travelFk + JOIN agencyMode am ON am.id = tr.agencyModeFk + JOIN tmp.rate r + JOIN volumeConfig vc + SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000) + / b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0), + b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3), + b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)), + b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 + b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), + b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); + + DROP TEMPORARY TABLE tmp.rate; + END LOOP; + CLOSE vTravels; END$$ DELIMITER ; From 297eb30395cbfc1d4202b67f5ee6bb823cce24b1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 4 Sep 2024 12:41:44 +0200 Subject: [PATCH 4/6] fix: ticket #216260 buy_recalcPrices --- db/routines/vn/procedures/buy_recalcPrices.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/buy_recalcPrices.sql b/db/routines/vn/procedures/buy_recalcPrices.sql index c63e7c55c..d4f205595 100644 --- a/db/routines/vn/procedures/buy_recalcPrices.sql +++ b/db/routines/vn/procedures/buy_recalcPrices.sql @@ -17,7 +17,7 @@ BEGIN JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk JOIN warehouse w ON w.id = t.warehouseInFk - GROUP BY t.landed, t.warehouseInFk, (w.code = 'flm'); + GROUP BY t.landed, t.warehouseInFk; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -48,7 +48,9 @@ BEGIN b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)), b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), - b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); + b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2) + WHERE t.landed = vLanded + AND t.warehouseInFk = vWarehouseFk; DROP TEMPORARY TABLE tmp.rate; END LOOP; From afcb590a9e790ecac64bb72926ef40ab89a4d32f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 4 Sep 2024 12:45:33 +0200 Subject: [PATCH 5/6] fix: ticket #216260 buy_recalcPrices --- db/routines/vn/procedures/buy_recalcPrices.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/buy_recalcPrices.sql b/db/routines/vn/procedures/buy_recalcPrices.sql index d4f205595..b05a9bfa9 100644 --- a/db/routines/vn/procedures/buy_recalcPrices.sql +++ b/db/routines/vn/procedures/buy_recalcPrices.sql @@ -49,8 +49,8 @@ BEGIN b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2) - WHERE t.landed = vLanded - AND t.warehouseInFk = vWarehouseFk; + WHERE tr.landed = vLanded + AND tr.warehouseInFk = vWarehouseFk; DROP TEMPORARY TABLE tmp.rate; END LOOP; From 95d4c706d49497a31cc77bc27ed14faffa08faee Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 5 Sep 2024 09:23:58 +0200 Subject: [PATCH 6/6] fix: refs #7346 multiple to quick in closure.js --- modules/ticket/back/methods/ticket/closure.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index c39d51c02..89343b193 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -13,7 +13,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'multiple'); + await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id],