From 62243e164a3d44f2ad4cd02f85a82baebad076eb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Nov 2024 14:47:21 +0100 Subject: [PATCH 01/39] feat: refs #7134 refs #6427 #7134 add new supplier/receipts method --- .../back/methods/supplier/createReceipt.js | 173 ++++++++++++++++++ .../back/methods/supplier/receipts.js | 73 ++++++++ modules/supplier/back/models/supplier.js | 2 + 3 files changed, 248 insertions(+) create mode 100644 modules/supplier/back/methods/supplier/createReceipt.js create mode 100644 modules/supplier/back/methods/supplier/receipts.js diff --git a/modules/supplier/back/methods/supplier/createReceipt.js b/modules/supplier/back/methods/supplier/createReceipt.js new file mode 100644 index 000000000..c051a6751 --- /dev/null +++ b/modules/supplier/back/methods/supplier/createReceipt.js @@ -0,0 +1,173 @@ +const UserError = require('vn-loopback/util/user-error'); +// Insert payment + +// divisa = solo en caso que la moneda sea distinta a €, +module.exports = function(Self) { + Self.remoteMethodCtx('createReceipt', { + description: 'Creates receipt and its compensation if necessary', + accessType: 'READ', + accepts: [{ + arg: 'supplierFk', + type: 'number', + description: 'The supplier id', + http: {source: 'path'} + }, + { + arg: 'received', + type: 'Date', + required: true + }, + { + arg: 'dueDate', + type: 'Date', + required: true + }, + { + arg: 'companyFk', + type: 'number', + required: true + }, + { + arg: 'currencyFk', + type: 'number', + required: true + }, + { + arg: 'bankFk', + type: 'number', + required: true + }, + { + arg: 'payMethodFk', + type: 'number', + required: true + }, + { + arg: 'amount', + type: 'number', + required: true + }, + { + arg: 'concept', + type: 'string', + required: true + }, + { + arg: 'divisa', + type: 'number' + }, + { + arg: 'compensationAccount', + type: 'any' + }], + returns: { + root: true, + type: 'Object' + }, + http: { + verb: 'post', + path: '/:supplierFk/createReceipt' + }, + accessScopes: ['DEFAULT', 'read:multimedia'] + }); + + Self.createReceipt = async(ctx, options) => { + const models = Self.app.models; + const args = ctx.args; + const date = Date.vnNew(); + date.setHours(0, 0, 0, 0); + + let tx; + const myOptions = {userId: ctx.req.accessToken.userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + delete args.ctx; // Remove unwanted properties + + const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions); + const bank = await models.Accounting.findById(args.bankFk, null, myOptions); + const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); + + if (accountingType.code == 'compensation') { + if (!args.compensationAccount) + throw new UserError('Compensation account is empty'); + + // Check compensation account exists + await models.Supplier.getClientOrSupplierReference(args.compensationAccount, myOptions); + + await Self.rawSql( + `CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`, + [ + date, + args.compensationAccount, + args.bankFk, + accountingType.receiptDescription + originalSupplier.accountingAccount, + args.amountPaid, + args.companyFk, + originalSupplier.accountingAccount + ], + myOptions + ); + } else if (accountingType.isAutoConciliated == true) { + const description = + `${originalSupplier.id} : ${originalSupplier.socialName} - ${accountingType.receiptDescription}`; + const [, [xdiarioNew]] = await Self.rawSql( + `CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew); + SELECT @xdiarioNew ledger;`, + [ + null, + date, + bank.account, + originalSupplier.accountingAccount, + description, + args.amountPaid, + 0, + 0, + '', + '', + null, + null, + false, + args.companyFk + ], + myOptions + ); + + await Self.rawSql( + `CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);`, + [ + xdiarioNew.ledger, + date, + originalSupplier.accountingAccount, + bank.account, + description, + 0, + args.amountPaid, + 0, + '', + '', + null, + null, + false, + args.companyFk + ], + myOptions + ); + } + const newReceipt = await models.Receipt.create(args, myOptions); + if (tx) await tx.commit(); + + return newReceipt; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js new file mode 100644 index 000000000..dce9c31d4 --- /dev/null +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -0,0 +1,73 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +module.exports = Self => { + Self.remoteMethodCtx('receipts', { + description: 'Find all clients matched by the filter', + accessType: 'READ', + accepts: [ + { + arg: 'supplierId', + type: 'number', + description: 'The supplier id', + }, + { + arg: 'companyId', + type: 'number', + description: 'The company id', + }, + { + arg: 'currencyFk', + type: 'number', + description: 'The currency', + default: 1, + }, + { + arg: 'orderBy', + type: 'string', + description: 'The client fiscal id', + enum: ['issued', ' bookEntried', ' booked', ' dueDate'], + }, + { + arg: 'isConciliated', + default: false, + type: 'boolean', + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/receipts`, + verb: 'GET' + } + }); + + Self.receipts = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; + const myOptions = {userId: ctx.req.accessToken.userId}; + const args = ctx.args; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let stmts = []; + stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ + args.supplierId, + args.currencyFk ?? 1, + args.companyId, + args.orderBy ?? 'issued', + args.isConciliated ?? false, + false + ])); + stmts.push(` + SELECT * + FROM tmp.supplierStatement`); + stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); + const sql = ParameterizedSQL.join(stmts, ';'); + const results = await conn.executeStmt(sql); + const resultsIndex = stmts.length - 1; + const result = results[resultsIndex]; + return result; + }; +}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 7e6908d57..20313801e 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -8,6 +8,8 @@ module.exports = Self => { require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); require('../methods/supplier/freeAgencies')(Self); + require('../methods/supplier/createReceipt')(Self); + require('../methods/supplier/receipts')(Self); require('../methods/supplier/campaignMetricsPdf')(Self); require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); From 771e06743ebf4be3fe2fc9c02433105933b2fce9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Nov 2024 14:06:52 +0100 Subject: [PATCH 02/39] feat: refs #7134 add supplier payment --- db/dump/fixtures.before.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e093c05cb..4ba377005 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4030,5 +4030,9 @@ INSERT IGNORE INTO vn.saySimpleCountry (countryFk, channel) VALUES (19, '1169'), (8, '1183'); -INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) - VALUES ('saysimle-url-mock', 1320); \ No newline at end of file +INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) + VALUES ('saysimle-url-mock', 1320); + + + INSERT INTO vn.payment (received,supplierFk,amount,currencyFk,divisa,bankFk,payMethodFk,bankingFees,concept,companyFk,created,isConciliated,dueDated,workerFk) VALUES + ('2024-09-15',1,1000.00,1,NULL,1,1,0.0,'n/pago',442,'2024-11-20 13:06:02.000',1,'2024-09-15',9); From f46a46359e94f95723285253358613bf37856439 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Nov 2024 14:07:00 +0100 Subject: [PATCH 03/39] feat: refs #7134 #7134 modify balanceStartingDate --- db/dump/fixtures.before.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4ba377005..2dcedcc92 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2629,9 +2629,9 @@ REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issu (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1,util.VN_CURDATE()), (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1,util.VN_CURDATE()); -INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`) +INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`, `balanceStartingDate`) VALUES - (1, -2, '2% retention', 2, 45); + (1, -2, '2% retention', 2, 45, '2000-01-01'); INSERT INTO `vn`.`invoiceInDueDay`(`invoiceInFk`, `dueDated`, `bankFk`, `amount`) VALUES @@ -4012,10 +4012,10 @@ INSERT INTO vn.routeAction (id, name, price, isMainlineDelivered) VALUES(1, 'Pin INSERT INTO vn.routeComplement (id, dated, workerFk, price, routeActionFk) VALUES(1, util.VN_CURDATE(), 9, 50.00, 1); -INSERT INTO srt.buffer (id, x, y, `size`, `length`, stateFk, typeFk, isActive, code, stratus, hasWorkerWaiting, reserve, routeFk, dayMinute, lastUnloaded, hasStrapper, typeDefaultFk, motors, editorFk) +INSERT INTO srt.buffer (id, x, y, `size`, `length`, stateFk, typeFk, isActive, code, stratus, hasWorkerWaiting, reserve, routeFk, dayMinute, lastUnloaded, hasStrapper, typeDefaultFk, motors, editorFk) VALUES (0, 0, 0, 0, NULL, 3, 1, 0, 'ENT', 0, 0, NULL, NULL, NULL, NULL, 0, 1, 1, NULL), (1, 0, 9900, 0, NULL, 1, 0, 0, 'NOK', 0, 0, NULL, NULL, NULL, NULL, 0, 1, 1, NULL), - (2, 0, 0, 450, 13000, 1, 0, 1, '01A', 1, 1, NULL, NULL, NULL, NULL, 0, 1, 1, NULL), + (2, 0, 0, 450, 13000, 1, 0, 1, '01A', 1, 1, NULL, NULL, NULL, NULL, 0, 1, 1, NULL), (3, 1400, 0, 450, 13000, 1, 0, 1, '01B', 1, 0, NULL, NULL, NULL, NULL, 0, 1, 1, NULL), (4, 0, 500, 500, 13000, 1, 4, 1, '02A', 2, 1, NULL, NULL, NULL, NULL, 1, 4, 13, NULL), (5, 1400, 500, 500, 13000, 1, 4, 1, '02B', 2, 1, NULL, NULL, NULL, NULL, 1, 4, 13, NULL), @@ -4026,7 +4026,7 @@ INSERT INTO srt.buffer (id, x, y, `size`, `length`, stateFk, typeFk, isActive, c (10, 0, 2000, 500, 13000, 1, 1, 1, '05A', 5, 0, NULL, NULL, NULL, NULL, 0, 1, 1, NULL); -INSERT IGNORE INTO vn.saySimpleCountry (countryFk, channel) +INSERT IGNORE INTO vn.saySimpleCountry (countryFk, channel) VALUES (19, '1169'), (8, '1183'); From aab595e9dd10f128e80bbc92c873524c31364d8a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Nov 2024 14:07:14 +0100 Subject: [PATCH 04/39] feat: refs #7134 #7134 use VN_CURDATE --- db/routines/vn/procedures/supplier_statementWithEntries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index c0014f8e5..b678588fe 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -154,7 +154,7 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk JOIN currency c ON c.id = e.currencyFk WHERE e.supplierFk = vSupplierFk - AND tr.landed >= CURDATE() + AND tr.landed >= util.VN_CURDATE() AND e.invoiceInFk IS NULL AND vHasEntries ORDER BY (dated IS NULL AND NOT isBooked), From aa2f9985cdde35ec901b5fa76d5d83f0e7434f24 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 20 Nov 2024 14:07:35 +0100 Subject: [PATCH 05/39] feat: refs #7134 change index --- modules/supplier/back/methods/supplier/receipts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index dce9c31d4..474cd256f 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -66,7 +66,7 @@ module.exports = Self => { stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); const sql = ParameterizedSQL.join(stmts, ';'); const results = await conn.executeStmt(sql); - const resultsIndex = stmts.length - 1; + const resultsIndex = stmts.length - 2; const result = results[resultsIndex]; return result; }; From 0a4f4c5926b5a86138d0771f7e8ff80c73e209f5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 5 Dec 2024 14:54:01 +0100 Subject: [PATCH 06/39] feat: refs #7134 rename supplier.createReceipt by createPayment --- .../{createReceipt.js => createPayment.js} | 151 ++++++++++-------- modules/supplier/back/models/supplier.js | 2 +- 2 files changed, 88 insertions(+), 65 deletions(-) rename modules/supplier/back/methods/supplier/{createReceipt.js => createPayment.js} (56%) diff --git a/modules/supplier/back/methods/supplier/createReceipt.js b/modules/supplier/back/methods/supplier/createPayment.js similarity index 56% rename from modules/supplier/back/methods/supplier/createReceipt.js rename to modules/supplier/back/methods/supplier/createPayment.js index c051a6751..8fa61f0c9 100644 --- a/modules/supplier/back/methods/supplier/createReceipt.js +++ b/modules/supplier/back/methods/supplier/createPayment.js @@ -1,77 +1,89 @@ -const UserError = require('vn-loopback/util/user-error'); +// const UserError = require('vn-loopback/util/user-error'); // Insert payment // divisa = solo en caso que la moneda sea distinta a €, module.exports = function(Self) { - Self.remoteMethodCtx('createReceipt', { + Self.remoteMethodCtx('createPayment', { description: 'Creates receipt and its compensation if necessary', accessType: 'READ', - accepts: [{ - arg: 'supplierFk', - type: 'number', - description: 'The supplier id', - http: {source: 'path'} - }, - { - arg: 'received', - type: 'Date', - required: true - }, - { - arg: 'dueDate', - type: 'Date', - required: true - }, - { - arg: 'companyFk', - type: 'number', - required: true - }, - { - arg: 'currencyFk', - type: 'number', - required: true - }, - { - arg: 'bankFk', - type: 'number', - required: true - }, - { - arg: 'payMethodFk', - type: 'number', - required: true - }, - { - arg: 'amount', - type: 'number', - required: true - }, - { - arg: 'concept', - type: 'string', - required: true - }, - { - arg: 'divisa', - type: 'number' - }, - { - arg: 'compensationAccount', - type: 'any' - }], + accepts: [ + { + arg: 'received', + type: 'Date', + required: true + }, + { + arg: 'dueDate', + type: 'Date', + required: true + }, + { + arg: 'supplierFk', + type: 'number', + description: 'The supplier id', + http: {source: 'path'} + }, + { + arg: 'amount', + type: 'number', + required: true + }, + { + arg: 'currencyFk', + type: 'number', + required: true + }, { + arg: 'divisa', + type: 'number', + required: true + }, + { + arg: 'bankFk', + type: 'number', + required: true + }, + { + arg: 'payMethodFk', + type: 'number', + required: true + }, + { + arg: 'bankingFees', + type: 'number', + required: true + }, + + { + arg: 'concept', + type: 'string', + required: true + }, { + arg: 'companyFk', + type: 'number', + required: true + }, + + { + arg: 'isConciliated', + type: 'boolean' + }, + { + arg: 'compensationAccount', + type: 'any' + } + ], returns: { root: true, type: 'Object' }, http: { verb: 'post', - path: '/:supplierFk/createReceipt' + path: '/:supplierFk/createPayment' }, accessScopes: ['DEFAULT', 'read:multimedia'] }); - Self.createReceipt = async(ctx, options) => { + Self.createPayment = async(ctx, options) => { const models = Self.app.models; const args = ctx.args; const date = Date.vnNew(); @@ -91,11 +103,11 @@ module.exports = function(Self) { try { delete args.ctx; // Remove unwanted properties - const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions); - const bank = await models.Accounting.findById(args.bankFk, null, myOptions); - const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); + // const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions); + // const bank = await models.Accounting.findById(args.bankFk, null, myOptions); + // const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); - if (accountingType.code == 'compensation') { + /* if (accountingType.code == 'compensation') { if (!args.compensationAccount) throw new UserError('Compensation account is empty'); @@ -161,10 +173,21 @@ module.exports = function(Self) { myOptions ); } - const newReceipt = await models.Receipt.create(args, myOptions); + */ + const newPayment = await models.Payment.create(args, myOptions); + // if (/* Supplier is client*/ false) { + // const newReceipt = await models.Receipt.create({ + // invoiceFk: newPayment.id, + // amountPaid: args.amount, + // payed: args.received, + // bankFk: args.bankFk, + // companyFk: args.companyFk, + // clientFk: args.supplierFk, + // }, myOptions); + // } if (tx) await tx.commit(); - return newReceipt; + return newPayment; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 20313801e..6bf9ecf32 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -8,7 +8,7 @@ module.exports = Self => { require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); require('../methods/supplier/freeAgencies')(Self); - require('../methods/supplier/createReceipt')(Self); + require('../methods/supplier/createPayment')(Self); require('../methods/supplier/receipts')(Self); require('../methods/supplier/campaignMetricsPdf')(Self); require('../methods/supplier/campaignMetricsEmail')(Self); From f86bd1233bc2c05d499fdd51f4b79a1342cd5009 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 9 Dec 2024 14:19:43 +0100 Subject: [PATCH 07/39] feat: refs #7134 tiller --- back/models/payment.json | 4 +- modules/client/back/models/till.js | 6 + modules/client/back/models/tillIn.js | 9 ++ modules/client/back/models/tillOut.js | 9 ++ modules/client/back/models/tiller.js | 6 + .../back/methods/supplier/createPayment.js | 107 +++++++++++++++++- 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 modules/client/back/models/till.js create mode 100644 modules/client/back/models/tillIn.js create mode 100644 modules/client/back/models/tillOut.js create mode 100644 modules/client/back/models/tiller.js diff --git a/back/models/payment.json b/back/models/payment.json index ed354969e..2bc665503 100644 --- a/back/models/payment.json +++ b/back/models/payment.json @@ -52,7 +52,7 @@ }, "payMethod": { "type": "belongsTo", - "model": "PayMethodFk", + "model": "PayMethod", "foreignKey": "payMethodFk" }, "company": { @@ -61,4 +61,4 @@ "foreignKey": "companyFk" } } -} \ No newline at end of file +} diff --git a/modules/client/back/models/till.js b/modules/client/back/models/till.js new file mode 100644 index 000000000..0ce8f9606 --- /dev/null +++ b/modules/client/back/models/till.js @@ -0,0 +1,6 @@ + +module.exports = Self => { + require('./tillIn')(Self); + require('./tillOut')(Self); + require('./tiller')(Self); +}; diff --git a/modules/client/back/models/tillIn.js b/modules/client/back/models/tillIn.js new file mode 100644 index 000000000..112741422 --- /dev/null +++ b/modules/client/back/models/tillIn.js @@ -0,0 +1,9 @@ + +module.exports = Self => { + Self.tillIn = async(ctx, options) => { + const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`; + const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); + if (pagareId) return pagareId; + throw new UserError('Till In'); + }; +}; diff --git a/modules/client/back/models/tillOut.js b/modules/client/back/models/tillOut.js new file mode 100644 index 000000000..005607c9a --- /dev/null +++ b/modules/client/back/models/tillOut.js @@ -0,0 +1,9 @@ + +module.exports = Self => { + Self.tillOut = async(ctx, options) => { + const query = `INSERT INTO vn.promissoryNote ( id, dated, serie, concept, in, out, bankFk, companyFk, isAccountable, InForeignValue, OutForeignValue, workerFk, calculatedCode, number, isLinked, created, isOk, warehouseFk, isConciliate, supplierAccountFk) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )`; + const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); + if (pagareId) return pagareId; + throw new UserError('Till Out'); + }; +}; diff --git a/modules/client/back/models/tiller.js b/modules/client/back/models/tiller.js new file mode 100644 index 000000000..d40e24039 --- /dev/null +++ b/modules/client/back/models/tiller.js @@ -0,0 +1,6 @@ + +module.exports = Self => { + Self.tiller = async(ctx, options) => { + throw new UserError('Till In'); + }; +}; diff --git a/modules/supplier/back/methods/supplier/createPayment.js b/modules/supplier/back/methods/supplier/createPayment.js index 8fa61f0c9..9dce4d927 100644 --- a/modules/supplier/back/methods/supplier/createPayment.js +++ b/modules/supplier/back/methods/supplier/createPayment.js @@ -34,8 +34,7 @@ module.exports = function(Self) { required: true }, { arg: 'divisa', - type: 'number', - required: true + type: 'any', }, { arg: 'bankFk', @@ -174,7 +173,11 @@ module.exports = function(Self) { ); } */ - const newPayment = await models.Payment.create(args, myOptions); + const bodyPayment = { + ...args, + dueDate: args.received, + }; + const newPayment = await models.Payment.create(bodyPayment, myOptions); // if (/* Supplier is client*/ false) { // const newReceipt = await models.Receipt.create({ // invoiceFk: newPayment.id, @@ -185,8 +188,99 @@ module.exports = function(Self) { // clientFk: args.supplierFk, // }, myOptions); // } + // const supplier = await Self.app.models.Supplier.findById(args.supplierFk, {fields: ['nif'], include: { + // relation: 'client' + // }}, myOptions); + // const client = await Self.app.models.Client.findOne({where: {nif: supplier.fi}}, myOptions); + if (tx) await tx.commit(); + switch (bodyPayment.payMethodFk) { + case 1: + case 10: + case 20: + await models.Till.tillIn(args, myOptions); + throw new UserError('Metálico'); + // Call Salidadecaja( + // strCONCEPTO & " : " & DFirst("[Proveedor]", "Proveedores", + // " [Id_Proveedor] = " & vSupplierFk), + // "R", + // _ "0", + // _ Replace(str(Me.n_pago), ",", "."), _ + // Me.n_fecha, _ + // DFirst("[oficial]", "Proveedores", "[Id_Proveedor] =" & vSupplierFk), + // _ Me.n_caja, Me.empresa) + + // Call sql(msql("UPDATE pago SET conciliado = TRUE WHERE id = %", pagoId), False, True) + // Public Function Salidadecaja(strCONCEPTE As String, strSERIE As String, strREF As String, strSALIDA As String, _ + // datfecha As Date, strCOLOR As String, strCAJA As String, intEmp As Integer) + + // Select Case Trim(strCAJA) + + // Case "11", "12", "13" + + // Call abrecajon + + // End Select + + // Call sql(msql("INSERT INTO Cajas ( Concepto, Serie, Numero, Salida, Cajafecha, Partida, Id_Banco, Id_Trabajador,empresa_id ) " & _ + // "SELECT %,%,%,%,%,%,%,%,%", strCONCEPTE, strSERIE, Nz(strREF, 0), strSALIDA, datfecha, strCOLOR, strCAJA, workerId, intEmp), _ + // False, True) + + // End Function + // break; + case 2: + // Call emitir_pagare(pagoId, strCONCEPTO) + await emitPagare(args.concept, newPayment.id); + + // Public Function emitir_pagare(pagoId As Long, strCONCEPTO As String) + // Call sql(msql("INSERT INTO Pagares(pago_id,Concepto) " & _ + // "VALUES (%,%)", pagoId, strCONCEPTO), False, True) + + // Call sql("SELECT LAST_INSERT_ID() as id", True, False) + + // Call sql("SELECT Pagares.Id_Pagare, Pagares.Concepto, Proveedores.Proveedor, Proveedores.Domicilio,empresa.logo, " & _ + // "Proveedores.codpos, Proveedores.Localidad, [importe] AS texto, Pagares.Fechaemision, pago.importe,pago.fecha, " & _ + // "pago.empresa_id, Proveedores.postcode_id AS CP FROM ((Proveedores INNER JOIN pago ON Proveedores.Id_Proveedor = pago.id_proveedor) " & _ + // "INNER JOIN Pagares ON pago.id = Pagares.pago_id) INNER JOIN empresa ON pago.empresa_id = empresa.id " & _ + // "WHERE Pagares.Id_Pagare = " & DFirst("[id]", "cstSQL"), True, False, "pagareultimo") + // DoCmd.openReport "Pagare", acViewPreview + // End Function + // break; + case 3: + throw new UserError('Compensación'); + // Dim vOriginalAccount As String + // vOriginalAccount = db.getValueV("SELECT account FROM vn.supplier WHERE id = #", vSupplierFk) + // 'Call compensar(Me.n_caja, Me.n_fecha, strCONCEPTO, Me.empresa, Me.n_pago, vOriginalAccount, pagoId) + // db.execV "CALL vn.ledger_doCompensation(#, #, #, #, #, #, #)", Me.n_fecha, vCompensationAccount, Me.n_caja, strCONCEPTO, Me.n_pago, Me.empresa, vOriginalAccount + // db.execV "UPDATE pago SET conciliado = TRUE, concepte = CONCAT(concepte, ' ', #) WHERE id = #", vCompensationAccount, pagoId + // break; + case 8: + throw new UserError('SEPA-CORE/B2B'); + + // If db.getValueFromDefV("paymentHasIban", vSupplierFk) = 0 Then + // MsgBox "Rellene los campos iban y entidad.", vbCritical + // Exit Sub + // End If + // Dim isUeeMember As Boolean + // isUeeMember = db.getValueV("SELECT c.isUeeMember FROM vn.supplier s JOIN vn.country c ON c.id = s.countryFk WHERE s.id = #", vSupplierFk) + + // Call GenerarPagoSEPA( _ + // Me.n_fecha, _ + // Me.empresa, _ + // Replace(Format(IIf(Me.n_moneda.column(1) = "EUR", Me.n_pago, Me.n_cambio), "0.00"), ",", "."), _ + // Me.n_caja, _ + // isUeeMember, _ + // "TRANSFER_" & DFirst("alias", "Proveedores", "[Id_Proveedor] =" & vSupplierFk), _ + // 1, _ + // Me.n_moneda.column(1), _ + // vSupplierFk) + // MsgBox "Fichero Generado CORRECTAMENTE", vbInformation + // break; + + default: + break; + } return newPayment; } catch (e) { if (tx) await tx.rollback(); @@ -194,3 +288,10 @@ module.exports = function(Self) { } }; }; + +async function emitPagare(concept, paymentFk) { + const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`; + const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); + if (pagareId) return pagareId; + throw new UserError('Pagaré'); +} From afb01ed021d61a00b9c36b05e212a18e08ed8c2e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 11:55:48 +0100 Subject: [PATCH 08/39] fix: refs #7917 fix route filter freeLancer --- db/dump/fixtures.before.sql | 14 +++- .../11393-redCamellia/00-firstScript.sql | 17 +++++ modules/route/back/methods/route/filter.js | 9 +++ .../back/methods/route/specs/filter.spec.js | 70 ++++++++++++++++--- 4 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 db/versions/11393-redCamellia/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 97ed0ae47..6a425cf09 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4038,7 +4038,7 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); -INSERT INTO vn.referenceRate (currencyFk, dated, value) +INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), (2, '2001-01-01', 1.0531), (2, '2001-02-01', 7.6347); @@ -4049,3 +4049,15 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance) INSERT IGNORE INTO vn.inventoryConfig SET id = 1, supplierFk = 4; + +UPDATE vn.worker + SET isFreelance=1 + WHERE firstName='deliveryFreelancer'; + +INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) + VALUES (132,100,'2001-01-01 00:00:00.000',1,1,'1899-12-30 12:15:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',10.0,1.8,'eighth route',1,0,1,100,'2001-01-01'); +INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) + VALUES (132,100,'2001-01-01 00:00:00.000',1,2,'1899-12-30 13:20:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',20.0,0.2,'ninth route',9,0,2,100,'2001-01-01'); +UPDATE vn.route + SET workerFk=132 + WHERE id=1; diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql new file mode 100644 index 000000000..6e7499702 --- /dev/null +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -0,0 +1,17 @@ +INSERT INTO account.`role` (name,description,hasLogin,created,modified) + VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); + +-- INSERT INTO account.roleInherit (`role`, inheritsFrom) VALUES(132, 2); +-- CALL account.role_sync(); + +INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) + VALUES + ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('AgencyTerm', 'filter', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'getRouteByAgency', 'WRITE', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'), + ('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'), + ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); + diff --git a/modules/route/back/methods/route/filter.js b/modules/route/back/methods/route/filter.js index 70bf7ba67..d4e127a92 100644 --- a/modules/route/back/methods/route/filter.js +++ b/modules/route/back/methods/route/filter.js @@ -87,6 +87,8 @@ module.exports = Self => { Self.filter = async(ctx, filter) => { let conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; + const models = Self.app.models; let where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -110,6 +112,13 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); + const worker = await models.Worker.findById(userId, {fields: ['isFreelance']}); + const getMyRoute = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE'); + + if (userId && getMyRoute && worker.isFreelance) { + if (!filter.where) filter.where = {}; + filter.where[`workerFk`] = userId; + } let stmts = []; let stmt; diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 18c0ca04f..1f21bfa74 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -1,21 +1,39 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; -describe('Route filter()', () => { +fdescribe('Route filter()', () => { const today = Date.vnNew(); today.setHours(2, 0, 0, 0); it('should return the routes matching "search"', async() => { const ctx = { args: { - search: 1, + search: 5, + }, + req: { + accessToken: { + userId: 9 + } + } + }; + const result = await app.models.Route.filter(ctx); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(5); + }); + + it('should return all results matching the filter', async() => { + const ctx = { + req: { + accessToken: { + userId: 132 + } } }; const result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(1); - expect(result[0].id).toEqual(1); + expect(result.length).toEqual(3); }); it('should return results matching "from" and "to"', async() => { @@ -32,12 +50,16 @@ describe('Route filter()', () => { args: { from: from, to: to + }, + req: { + accessToken: { + userId: 9 + } } }; - const results = await models.Route.filter(ctx, options); - expect(results.length).toBe(7); + expect(results.length).toBe(9); await tx.rollback(); } catch (e) { @@ -50,6 +72,11 @@ describe('Route filter()', () => { const ctx = { args: { m3: 0.1, + }, + req: { + accessToken: { + userId: 9 + } } }; @@ -62,6 +89,11 @@ describe('Route filter()', () => { const ctx = { args: { description: 'third route', + }, + req: { + accessToken: { + userId: 9 + } } }; @@ -74,24 +106,33 @@ describe('Route filter()', () => { const ctx = { args: { workerFk: 56, + }, + req: { + accessToken: { + userId: 9 + } } }; - const result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(5); + expect(result.length).toEqual(4); }); it('should return the routes matching "warehouseFk"', async() => { const ctx = { args: { warehouseFk: 1, + }, + req: { + accessToken: { + userId: 9 + } } }; let result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(7); + expect(result.length).toEqual(9); ctx.args.warehouseFk = 2; @@ -104,9 +145,13 @@ describe('Route filter()', () => { const ctx = { args: { vehicleFk: 2, + }, + req: { + accessToken: { + userId: 9 + } } }; - const result = await app.models.Route.filter(ctx); expect(result.length).toEqual(1); @@ -116,6 +161,11 @@ describe('Route filter()', () => { const ctx = { args: { agencyModeFk: 7, + }, + req: { + accessToken: { + userId: 9 + } } }; From 419815ff87914382396524cacbb1ab9c81b2e138 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 11:59:40 +0100 Subject: [PATCH 09/39] fix: refs #7917 fix back --- db/versions/11393-redCamellia/00-firstScript.sql | 3 --- modules/route/back/methods/route/specs/filter.spec.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index 6e7499702..b3ccb880f 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -1,9 +1,6 @@ INSERT INTO account.`role` (name,description,hasLogin,created,modified) VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); --- INSERT INTO account.roleInherit (`role`, inheritsFrom) VALUES(132, 2); --- CALL account.role_sync(); - INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 1f21bfa74..8f199e34a 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; -fdescribe('Route filter()', () => { +describe('Route filter()', () => { const today = Date.vnNew(); today.setHours(2, 0, 0, 0); From a30cad1da1851924bde0da91e5820d2ec4d37533 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 12:14:16 +0100 Subject: [PATCH 10/39] fix: refs #7917 fix tback --- .../methods/agency-term/specs/filter.spec.js | 12 +- .../back/methods/roadmap/specs/clone.spec.js | 109 ------------------ 2 files changed, 6 insertions(+), 115 deletions(-) delete mode 100644 modules/route/back/methods/roadmap/specs/clone.spec.js diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 41e696157..449028f1e 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -18,7 +18,7 @@ describe('AgencyTerm filter()', () => { const firstAgencyTerm = agencyTerms[0]; expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(5); + expect(agencyTerms.length).toEqual(7); await tx.rollback(); } catch (e) { @@ -36,7 +36,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(1); }); @@ -49,7 +49,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(4); }); it('should return results matching "from" and "to"', async() => { @@ -72,7 +72,7 @@ describe('AgencyTerm filter()', () => { const results = await models.AgencyTerm.filter(ctx, options); - expect(results.length).toBe(5); + expect(results.length).toBe(7); await tx.rollback(); } catch (e) { @@ -90,7 +90,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(1); }); @@ -103,7 +103,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); expect(result[0].routeFk).toEqual(2); }); }); diff --git a/modules/route/back/methods/roadmap/specs/clone.spec.js b/modules/route/back/methods/roadmap/specs/clone.spec.js deleted file mode 100644 index 41e696157..000000000 --- a/modules/route/back/methods/roadmap/specs/clone.spec.js +++ /dev/null @@ -1,109 +0,0 @@ -const app = require('vn-loopback/server/server'); -const models = require('vn-loopback/server/server').models; - -describe('AgencyTerm filter()', () => { - const authUserId = 9; - const today = Date.vnNew(); - today.setHours(2, 0, 0, 0); - - it('should return all results matching the filter', async() => { - const tx = await models.AgencyTerm.beginTransaction({}); - - try { - const options = {transaction: tx}; - const filter = {}; - const ctx = {req: {accessToken: {userId: authUserId}}}; - - const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options); - const firstAgencyTerm = agencyTerms[0]; - - expect(firstAgencyTerm.routeFk).toEqual(1); - expect(agencyTerms.length).toEqual(5); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return results matching "search" searching by integer', async() => { - let ctx = { - args: { - search: 1, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(1); - }); - - it('should return results matching "search" searching by string', async() => { - let ctx = { - args: { - search: 'Plants SL', - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(2); - }); - - it('should return results matching "from" and "to"', async() => { - const tx = await models.Buy.beginTransaction({}); - const options = {transaction: tx}; - - try { - const from = Date.vnNew(); - from.setHours(0, 0, 0, 0); - - const to = Date.vnNew(); - to.setHours(23, 59, 59, 999); - - const ctx = { - args: { - from: from, - to: to - } - }; - - const results = await models.AgencyTerm.filter(ctx, options); - - expect(results.length).toBe(5); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return results matching "agencyModeFk"', async() => { - let ctx = { - args: { - agencyModeFk: 1, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(1); - }); - - it('should return results matching "agencyFk"', async() => { - let ctx = { - args: { - agencyFk: 2, - } - }; - - let result = await app.models.AgencyTerm.filter(ctx); - - expect(result.length).toEqual(1); - expect(result[0].routeFk).toEqual(2); - }); -}); From 16bbcf8185120fbc5347ef787832db6fcbc77427 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 23 Dec 2024 12:18:40 +0100 Subject: [PATCH 11/39] fix: refs #7917 fix summary test --- modules/route/back/methods/route/specs/summary.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index a9516f7c5..096abe62c 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -25,7 +25,7 @@ describe('route summary()', () => { const result = await app.models.Route.summary(1); const worker = result.route.worker().user(); - expect(worker.name).toEqual('delivery'); + expect(worker.name).toEqual('deliveryfreelancer'); }); it(`should return a summary object containing data from the tickets`, async() => { From 85163a13fa72790b9da63e40735c5a411f3d8a4d Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 24 Dec 2024 08:13:00 +0100 Subject: [PATCH 12/39] fix: refs #7917 fix fixtures --- db/dump/fixtures.before.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6a425cf09..fba3b3487 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -754,6 +754,8 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()); + (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES From 3691daded492b3ca57f25875fff0bf9d8a09b2e3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 27 Dec 2024 13:26:38 +0100 Subject: [PATCH 13/39] feat: refs #7134 add bank name --- .../vn/procedures/supplier_statementWithEntries.sql | 8 ++++++-- modules/supplier/back/methods/supplier/receipts.js | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index b678588fe..625b5195e 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -40,7 +40,7 @@ BEGIN IFNULL(invoiceCurrency, 0), 2 ) currencyBalance FROM ( - SELECT NULL bankFk, + SELECT NULL bankFk, NULL bank, ii.companyFk, ii.serial, ii.id, @@ -74,6 +74,7 @@ BEGIN GROUP BY iid.id, ii.id UNION ALL SELECT p.bankFk, + a.bank 'bank' , p.companyFk, NULL, p.id, @@ -102,13 +103,15 @@ BEGIN LEFT JOIN accounting a ON a.id = p.bankFk LEFT JOIN payMethod pm ON pm.id = p.payMethodFk LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id + + WHERE p.received >= vBalanceStartingDate AND p.supplierFk = vSupplierFk AND vCurrencyFk IN (p.currencyFk, 0) AND vCompanyFk IN (p.companyFk, 0) AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) UNION ALL - SELECT NULL, + SELECT NULL, NULL bankFk, companyFk, NULL, se.id, @@ -136,6 +139,7 @@ BEGIN AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) UNION ALL SELECT NULL bankFk, + NULL, e.companyFk, 'E' serial, e.invoiceNumber id, diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 474cd256f..68865a242 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -60,9 +60,11 @@ module.exports = Self => { args.isConciliated ?? false, false ])); - stmts.push(` + const stmt = new ParameterizedSQL(` SELECT * FROM tmp.supplierStatement`); + stmt.merge(conn.makeSuffix(filter)); + stmts.push(stmt); stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); const sql = ParameterizedSQL.join(stmts, ';'); const results = await conn.executeStmt(sql); From a69a767c8a8d3f631d261b3f009d9e85433fd615 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 27 Dec 2024 13:57:28 +0100 Subject: [PATCH 14/39] feat: refs #7134 use filter to order by --- .../back/methods/supplier/receipts.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 68865a242..9dcef17de 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -1,11 +1,17 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('receipts', { description: 'Find all clients matched by the filter', accessType: 'READ', accepts: [ { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { arg: 'supplierId', type: 'number', description: 'The supplier id', @@ -21,6 +27,12 @@ module.exports = Self => { description: 'The currency', default: 1, }, + { + arg: 'bankFk', + type: 'number', + description: 'The bank', + default: 1, + }, { arg: 'orderBy', type: 'string', @@ -50,7 +62,12 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'bankFk': + return {'bankFk': value}; + } + }); let stmts = []; stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ args.supplierId, @@ -63,6 +80,8 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * FROM tmp.supplierStatement`); + filter = mergeFilters(args.filter, {where}); + stmt.merge(conn.makeSuffix(filter)); stmts.push(stmt); stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); From 78a8f80321139bbf6c405581a94b692d458012d8 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 2 Jan 2025 08:38:24 +0100 Subject: [PATCH 15/39] fix: refs #7917 fix tback --- db/dump/fixtures.before.sql | 6 +----- modules/route/back/methods/agency-term/specs/filter.spec.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0593eda92..d62248dfd 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -753,7 +753,7 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), - (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()); + (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); @@ -4060,10 +4060,6 @@ UPDATE vn.worker SET isFreelance=1 WHERE firstName='deliveryFreelancer'; -INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) - VALUES (132,100,'2001-01-01 00:00:00.000',1,1,'1899-12-30 12:15:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',10.0,1.8,'eighth route',1,0,1,100,'2001-01-01'); -INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated) - VALUES (132,100,'2001-01-01 00:00:00.000',1,2,'1899-12-30 13:20:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',20.0,0.2,'ninth route',9,0,2,100,'2001-01-01'); UPDATE vn.route SET workerFk=132 WHERE id=1; diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index 449028f1e..aa2743868 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -36,7 +36,7 @@ describe('AgencyTerm filter()', () => { let result = await app.models.AgencyTerm.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(1); expect(result[0].routeFk).toEqual(1); }); From 420bb2a57ed8113309bb2931c35ccd729dae9692 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 12:41:16 +0100 Subject: [PATCH 16/39] perf: refs #7134 remove unnecessary code --- modules/client/back/models/till.js | 6 - modules/client/back/models/tillIn.js | 9 - modules/client/back/models/tillOut.js | 9 - modules/client/back/models/tiller.js | 6 - .../back/methods/supplier/createPayment.js | 297 ------------------ 5 files changed, 327 deletions(-) delete mode 100644 modules/client/back/models/till.js delete mode 100644 modules/client/back/models/tillIn.js delete mode 100644 modules/client/back/models/tillOut.js delete mode 100644 modules/client/back/models/tiller.js delete mode 100644 modules/supplier/back/methods/supplier/createPayment.js diff --git a/modules/client/back/models/till.js b/modules/client/back/models/till.js deleted file mode 100644 index 0ce8f9606..000000000 --- a/modules/client/back/models/till.js +++ /dev/null @@ -1,6 +0,0 @@ - -module.exports = Self => { - require('./tillIn')(Self); - require('./tillOut')(Self); - require('./tiller')(Self); -}; diff --git a/modules/client/back/models/tillIn.js b/modules/client/back/models/tillIn.js deleted file mode 100644 index 112741422..000000000 --- a/modules/client/back/models/tillIn.js +++ /dev/null @@ -1,9 +0,0 @@ - -module.exports = Self => { - Self.tillIn = async(ctx, options) => { - const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`; - const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); - if (pagareId) return pagareId; - throw new UserError('Till In'); - }; -}; diff --git a/modules/client/back/models/tillOut.js b/modules/client/back/models/tillOut.js deleted file mode 100644 index 005607c9a..000000000 --- a/modules/client/back/models/tillOut.js +++ /dev/null @@ -1,9 +0,0 @@ - -module.exports = Self => { - Self.tillOut = async(ctx, options) => { - const query = `INSERT INTO vn.promissoryNote ( id, dated, serie, concept, in, out, bankFk, companyFk, isAccountable, InForeignValue, OutForeignValue, workerFk, calculatedCode, number, isLinked, created, isOk, warehouseFk, isConciliate, supplierAccountFk) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )`; - const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); - if (pagareId) return pagareId; - throw new UserError('Till Out'); - }; -}; diff --git a/modules/client/back/models/tiller.js b/modules/client/back/models/tiller.js deleted file mode 100644 index d40e24039..000000000 --- a/modules/client/back/models/tiller.js +++ /dev/null @@ -1,6 +0,0 @@ - -module.exports = Self => { - Self.tiller = async(ctx, options) => { - throw new UserError('Till In'); - }; -}; diff --git a/modules/supplier/back/methods/supplier/createPayment.js b/modules/supplier/back/methods/supplier/createPayment.js deleted file mode 100644 index 9dce4d927..000000000 --- a/modules/supplier/back/methods/supplier/createPayment.js +++ /dev/null @@ -1,297 +0,0 @@ -// const UserError = require('vn-loopback/util/user-error'); -// Insert payment - -// divisa = solo en caso que la moneda sea distinta a €, -module.exports = function(Self) { - Self.remoteMethodCtx('createPayment', { - description: 'Creates receipt and its compensation if necessary', - accessType: 'READ', - accepts: [ - { - arg: 'received', - type: 'Date', - required: true - }, - { - arg: 'dueDate', - type: 'Date', - required: true - }, - { - arg: 'supplierFk', - type: 'number', - description: 'The supplier id', - http: {source: 'path'} - }, - { - arg: 'amount', - type: 'number', - required: true - }, - { - arg: 'currencyFk', - type: 'number', - required: true - }, { - arg: 'divisa', - type: 'any', - }, - { - arg: 'bankFk', - type: 'number', - required: true - }, - { - arg: 'payMethodFk', - type: 'number', - required: true - }, - { - arg: 'bankingFees', - type: 'number', - required: true - }, - - { - arg: 'concept', - type: 'string', - required: true - }, { - arg: 'companyFk', - type: 'number', - required: true - }, - - { - arg: 'isConciliated', - type: 'boolean' - }, - { - arg: 'compensationAccount', - type: 'any' - } - ], - returns: { - root: true, - type: 'Object' - }, - http: { - verb: 'post', - path: '/:supplierFk/createPayment' - }, - accessScopes: ['DEFAULT', 'read:multimedia'] - }); - - Self.createPayment = async(ctx, options) => { - const models = Self.app.models; - const args = ctx.args; - const date = Date.vnNew(); - date.setHours(0, 0, 0, 0); - - let tx; - const myOptions = {userId: ctx.req.accessToken.userId}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - delete args.ctx; // Remove unwanted properties - - // const originalSupplier = await models.Supplier.findById(args.supplierFk, null, myOptions); - // const bank = await models.Accounting.findById(args.bankFk, null, myOptions); - // const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); - - /* if (accountingType.code == 'compensation') { - if (!args.compensationAccount) - throw new UserError('Compensation account is empty'); - - // Check compensation account exists - await models.Supplier.getClientOrSupplierReference(args.compensationAccount, myOptions); - - await Self.rawSql( - `CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`, - [ - date, - args.compensationAccount, - args.bankFk, - accountingType.receiptDescription + originalSupplier.accountingAccount, - args.amountPaid, - args.companyFk, - originalSupplier.accountingAccount - ], - myOptions - ); - } else if (accountingType.isAutoConciliated == true) { - const description = - `${originalSupplier.id} : ${originalSupplier.socialName} - ${accountingType.receiptDescription}`; - const [, [xdiarioNew]] = await Self.rawSql( - `CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew); - SELECT @xdiarioNew ledger;`, - [ - null, - date, - bank.account, - originalSupplier.accountingAccount, - description, - args.amountPaid, - 0, - 0, - '', - '', - null, - null, - false, - args.companyFk - ], - myOptions - ); - - await Self.rawSql( - `CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);`, - [ - xdiarioNew.ledger, - date, - originalSupplier.accountingAccount, - bank.account, - description, - 0, - args.amountPaid, - 0, - '', - '', - null, - null, - false, - args.companyFk - ], - myOptions - ); - } - */ - const bodyPayment = { - ...args, - dueDate: args.received, - }; - const newPayment = await models.Payment.create(bodyPayment, myOptions); - // if (/* Supplier is client*/ false) { - // const newReceipt = await models.Receipt.create({ - // invoiceFk: newPayment.id, - // amountPaid: args.amount, - // payed: args.received, - // bankFk: args.bankFk, - // companyFk: args.companyFk, - // clientFk: args.supplierFk, - // }, myOptions); - // } - // const supplier = await Self.app.models.Supplier.findById(args.supplierFk, {fields: ['nif'], include: { - // relation: 'client' - // }}, myOptions); - // const client = await Self.app.models.Client.findOne({where: {nif: supplier.fi}}, myOptions); - - if (tx) await tx.commit(); - - switch (bodyPayment.payMethodFk) { - case 1: - case 10: - case 20: - await models.Till.tillIn(args, myOptions); - throw new UserError('Metálico'); - // Call Salidadecaja( - // strCONCEPTO & " : " & DFirst("[Proveedor]", "Proveedores", - // " [Id_Proveedor] = " & vSupplierFk), - // "R", - // _ "0", - // _ Replace(str(Me.n_pago), ",", "."), _ - // Me.n_fecha, _ - // DFirst("[oficial]", "Proveedores", "[Id_Proveedor] =" & vSupplierFk), - // _ Me.n_caja, Me.empresa) - - // Call sql(msql("UPDATE pago SET conciliado = TRUE WHERE id = %", pagoId), False, True) - // Public Function Salidadecaja(strCONCEPTE As String, strSERIE As String, strREF As String, strSALIDA As String, _ - // datfecha As Date, strCOLOR As String, strCAJA As String, intEmp As Integer) - - // Select Case Trim(strCAJA) - - // Case "11", "12", "13" - - // Call abrecajon - - // End Select - - // Call sql(msql("INSERT INTO Cajas ( Concepto, Serie, Numero, Salida, Cajafecha, Partida, Id_Banco, Id_Trabajador,empresa_id ) " & _ - // "SELECT %,%,%,%,%,%,%,%,%", strCONCEPTE, strSERIE, Nz(strREF, 0), strSALIDA, datfecha, strCOLOR, strCAJA, workerId, intEmp), _ - // False, True) - - // End Function - // break; - case 2: - // Call emitir_pagare(pagoId, strCONCEPTO) - await emitPagare(args.concept, newPayment.id); - - // Public Function emitir_pagare(pagoId As Long, strCONCEPTO As String) - // Call sql(msql("INSERT INTO Pagares(pago_id,Concepto) " & _ - // "VALUES (%,%)", pagoId, strCONCEPTO), False, True) - - // Call sql("SELECT LAST_INSERT_ID() as id", True, False) - - // Call sql("SELECT Pagares.Id_Pagare, Pagares.Concepto, Proveedores.Proveedor, Proveedores.Domicilio,empresa.logo, " & _ - // "Proveedores.codpos, Proveedores.Localidad, [importe] AS texto, Pagares.Fechaemision, pago.importe,pago.fecha, " & _ - // "pago.empresa_id, Proveedores.postcode_id AS CP FROM ((Proveedores INNER JOIN pago ON Proveedores.Id_Proveedor = pago.id_proveedor) " & _ - // "INNER JOIN Pagares ON pago.id = Pagares.pago_id) INNER JOIN empresa ON pago.empresa_id = empresa.id " & _ - // "WHERE Pagares.Id_Pagare = " & DFirst("[id]", "cstSQL"), True, False, "pagareultimo") - // DoCmd.openReport "Pagare", acViewPreview - // End Function - // break; - case 3: - throw new UserError('Compensación'); - // Dim vOriginalAccount As String - // vOriginalAccount = db.getValueV("SELECT account FROM vn.supplier WHERE id = #", vSupplierFk) - // 'Call compensar(Me.n_caja, Me.n_fecha, strCONCEPTO, Me.empresa, Me.n_pago, vOriginalAccount, pagoId) - // db.execV "CALL vn.ledger_doCompensation(#, #, #, #, #, #, #)", Me.n_fecha, vCompensationAccount, Me.n_caja, strCONCEPTO, Me.n_pago, Me.empresa, vOriginalAccount - // db.execV "UPDATE pago SET conciliado = TRUE, concepte = CONCAT(concepte, ' ', #) WHERE id = #", vCompensationAccount, pagoId - // break; - case 8: - throw new UserError('SEPA-CORE/B2B'); - - // If db.getValueFromDefV("paymentHasIban", vSupplierFk) = 0 Then - // MsgBox "Rellene los campos iban y entidad.", vbCritical - // Exit Sub - // End If - // Dim isUeeMember As Boolean - // isUeeMember = db.getValueV("SELECT c.isUeeMember FROM vn.supplier s JOIN vn.country c ON c.id = s.countryFk WHERE s.id = #", vSupplierFk) - - // Call GenerarPagoSEPA( _ - // Me.n_fecha, _ - // Me.empresa, _ - // Replace(Format(IIf(Me.n_moneda.column(1) = "EUR", Me.n_pago, Me.n_cambio), "0.00"), ",", "."), _ - // Me.n_caja, _ - // isUeeMember, _ - // "TRANSFER_" & DFirst("alias", "Proveedores", "[Id_Proveedor] =" & vSupplierFk), _ - // 1, _ - // Me.n_moneda.column(1), _ - // vSupplierFk) - // MsgBox "Fichero Generado CORRECTAMENTE", vbInformation - // break; - - default: - break; - } - return newPayment; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; - -async function emitPagare(concept, paymentFk) { - const query = `INSERT INTO vn.promissoryNote ( concept, paymentFk) VALUES(?, ? )`; - const pagareId = await Self.rawSql(query, [concept, paymentFk], myOptions); - if (pagareId) return pagareId; - throw new UserError('Pagaré'); -} From f6c3893d000a6fe1f7aeeadb39893f5b6fd20116 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 12:41:36 +0100 Subject: [PATCH 17/39] feat: refs #7134 minor changes --- db/dump/fixtures.before.sql | 4 ++-- modules/supplier/back/methods/supplier/receipts.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 3d2101604..4042246df 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4045,8 +4045,8 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); -INSERT INTO vn.payment (received,supplierFk,amount,currencyFk,divisa,bankFk,payMethodFk,bankingFees,concept,companyFk,created,isConciliated,dueDated,workerFk) VALUES - ('2024-09-15',1,1000.00,1,NULL,1,1,0.0,'n/pago',442,'2024-11-20 13:06:02.000',1,'2024-09-15',9); +INSERT INTO vn.payment (received, supplierFk, amount, currencyFk, divisa, bankFk, payMethodFk, bankingFees, concept, companyFk, created, isConciliated, dueDated, workerFk) VALUES + ('2024-09-15', 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, '2024-11-20 13:06:02.000', 1, '2024-09-15', 9); INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 9dcef17de..1b4dfe40b 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -3,7 +3,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('receipts', { - description: 'Find all clients matched by the filter', + description: 'Find all suppliers matched by the filter', accessType: 'READ', accepts: [ { @@ -36,7 +36,7 @@ module.exports = Self => { { arg: 'orderBy', type: 'string', - description: 'The client fiscal id', + description: 'The supplier fiscal id', enum: ['issued', ' bookEntried', ' booked', ' dueDate'], }, { From f0e9cce2286a08a59f555573e5ac0daf3bdd664a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 22:52:35 +0100 Subject: [PATCH 18/39] fix: refs #7134 remove unnused method --- modules/supplier/back/methods/supplier/receipts.js | 8 +++++++- modules/supplier/back/models/supplier.js | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 1b4dfe40b..50f4610da 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -62,13 +62,16 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'bankFk': - return {'bankFk': value}; + return {[param]: value}; } }); + let stmts = []; + stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ args.supplierId, args.currencyFk ?? 1, @@ -77,14 +80,17 @@ module.exports = Self => { args.isConciliated ?? false, false ])); + const stmt = new ParameterizedSQL(` SELECT * FROM tmp.supplierStatement`); + filter = mergeFilters(args.filter, {where}); stmt.merge(conn.makeSuffix(filter)); stmts.push(stmt); stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); + const sql = ParameterizedSQL.join(stmts, ';'); const results = await conn.executeStmt(sql); const resultsIndex = stmts.length - 2; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 6bf9ecf32..63bd65fbd 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -8,7 +8,6 @@ module.exports = Self => { require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); require('../methods/supplier/freeAgencies')(Self); - require('../methods/supplier/createPayment')(Self); require('../methods/supplier/receipts')(Self); require('../methods/supplier/campaignMetricsPdf')(Self); require('../methods/supplier/campaignMetricsEmail')(Self); From 9bfc2a01c5ea12bc2164c2eb98de3bae82b52201 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 23:09:13 +0100 Subject: [PATCH 19/39] perf: refs #7134 sql style --- .../vn/procedures/supplier_statementWithEntries.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index 625b5195e..827e4b24d 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -40,7 +40,8 @@ BEGIN IFNULL(invoiceCurrency, 0), 2 ) currencyBalance FROM ( - SELECT NULL bankFk, NULL bank, + SELECT NULL bankFk, + NULL bank, ii.companyFk, ii.serial, ii.id, @@ -74,7 +75,7 @@ BEGIN GROUP BY iid.id, ii.id UNION ALL SELECT p.bankFk, - a.bank 'bank' , + a.bank 'bank', p.companyFk, NULL, p.id, @@ -103,15 +104,14 @@ BEGIN LEFT JOIN accounting a ON a.id = p.bankFk LEFT JOIN payMethod pm ON pm.id = p.payMethodFk LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id - - WHERE p.received >= vBalanceStartingDate AND p.supplierFk = vSupplierFk AND vCurrencyFk IN (p.currencyFk, 0) AND vCompanyFk IN (p.companyFk, 0) AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) UNION ALL - SELECT NULL, NULL bankFk, + SELECT NULL, + NULL bankFk, companyFk, NULL, se.id, From 96649f5d8a0d51687a7b068ed8489a4a1236068b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 23:13:26 +0100 Subject: [PATCH 20/39] feat: refs #7134 remove default value --- modules/supplier/back/methods/supplier/receipts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js index 50f4610da..cc7b03a42 100644 --- a/modules/supplier/back/methods/supplier/receipts.js +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -74,7 +74,7 @@ module.exports = Self => { stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ args.supplierId, - args.currencyFk ?? 1, + args.currencyFk, args.companyId, args.orderBy ?? 'issued', args.isConciliated ?? false, From 86dde8dfb3a92112529fec716725c3359d3d0a64 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 14 Jan 2025 07:18:05 +0100 Subject: [PATCH 21/39] fix: refs #7917 fix pr --- db/dump/fixtures.before.sql | 4 ++-- db/versions/11393-redCamellia/00-firstScript.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index d62248dfd..e2d8ca425 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -754,8 +754,8 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), - (8, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), - (9, '1899-12-30 13:20:00', 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); + (8, NULL, 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, NULL, 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index b3ccb880f..ae6c909e8 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -1,5 +1,5 @@ -INSERT INTO account.`role` (name,description,hasLogin,created,modified) - VALUES ('deliveryFreelancer','Repartidor autónomo',1,'2024-07-05 10:18:58.000','2024-07-05 10:18:58.000'); +INSERT INTO account.`role` (name,description,hasLogin) + VALUES ('deliveryFreelancer','Repartidor autónomo',1); INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId) VALUES From 516147b8bb4f2ded4c2bc747f328f340c6eadcb8 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 15 Jan 2025 13:04:49 +0100 Subject: [PATCH 22/39] fix: refs #7917 fix acls --- db/versions/11393-redCamellia/00-firstScript.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index ae6c909e8..c8f13fe69 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -10,5 +10,7 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'), ('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); From d66b8f49637d3d7a1cccb7d0c1fdc5586d082151 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 21 Jan 2025 13:54:02 +0100 Subject: [PATCH 23/39] fix: refs #7917 acls --- db/versions/11393-redCamellia/00-firstScript.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index c8f13fe69..c7a2488c1 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -12,5 +12,6 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), - ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'); - + ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), + ('Ticket','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Ticket','upsert','WRITE','ALLOW','ROLE','deliveryFreelancer'); From 294c2f832efaea595b6279381f7a4f740ecad52e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Jan 2025 14:53:19 +0100 Subject: [PATCH 24/39] Merge branch 'dev' into 7134-supplierBalance --- db/routines/vn/procedures/supplier_statementWithEntries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index 827e4b24d..ad80e2c9f 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -75,7 +75,7 @@ BEGIN GROUP BY iid.id, ii.id UNION ALL SELECT p.bankFk, - a.bank 'bank', + a.bank, p.companyFk, NULL, p.id, From 630d86778797f6a50e24b6927ed989b8a74209be Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Jan 2025 23:09:07 +0100 Subject: [PATCH 25/39] fix: refs #7134 use vn_curdate --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 79ee2463c..34da74d51 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4046,7 +4046,7 @@ INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); INSERT INTO vn.payment (received, supplierFk, amount, currencyFk, divisa, bankFk, payMethodFk, bankingFees, concept, companyFk, created, isConciliated, dueDated, workerFk) VALUES - ('2024-09-15', 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, '2024-11-20 13:06:02.000', 1, '2024-09-15', 9); + (util.VN_CURDATE(), 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, '2024-11-20 13:06:02.000', 1, util.VN_CURDATE(), 9); INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), From 99b5433e624dcc518f37abb5990558a78d00b57e Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 22 Jan 2025 10:02:20 +0100 Subject: [PATCH 26/39] fix: refs #7917 fix acls --- db/versions/11393-redCamellia/00-firstScript.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/versions/11393-redCamellia/00-firstScript.sql b/db/versions/11393-redCamellia/00-firstScript.sql index c7a2488c1..19ea2a9ef 100644 --- a/db/versions/11393-redCamellia/00-firstScript.sql +++ b/db/versions/11393-redCamellia/00-firstScript.sql @@ -13,5 +13,7 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p ('Route','guessPriority','WRITE','ALLOW','ROLE','deliveryFreelancer'), ('Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryFreelancer'), ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'), - ('Ticket','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), - ('Ticket','upsert','WRITE','ALLOW','ROLE','deliveryFreelancer'); + ('Route','sendSms','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Ticket','updateAttributes','WRITE','ALLOW','ROLE','deliveryFreelancer'), + ('Client','findById','READ','ALLOW','ROLE','deliveryFreelancer'); +; From c4a7fbf6e82066a3e15e1452469ee82a2a5cf79e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Jan 2025 10:57:54 +0100 Subject: [PATCH 27/39] fix: refs #7917 fix tests --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 00fa54281..1622a48c1 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -747,7 +747,7 @@ INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1'); INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`, `dated`) VALUES - (1, '1899-12-30 12:15:00', 56, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (1, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()), (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10, util.VN_CURDATE()), (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), From d659e05ce854dd73d7d103c59b1c936bf31a8925 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Jan 2025 11:46:29 +0100 Subject: [PATCH 28/39] fix: refs #7917 remove update --- db/dump/fixtures.before.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 1622a48c1..2e73ef7df 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4063,6 +4063,3 @@ UPDATE vn.worker SET isFreelance=1 WHERE firstName='deliveryFreelancer'; -UPDATE vn.route - SET workerFk=132 - WHERE id=1; From 8482743baf33eebc495504731fa3ac17cd898386 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 28 Jan 2025 11:26:48 +0100 Subject: [PATCH 29/39] feat: refs #6822 ACL --- db/routines/vn/procedures/entry_transfer.sql | 2 +- db/versions/11425-aquaCordyline/00-firstScript.sql | 2 ++ modules/entry/back/methods/entry/transfer.js | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/versions/11425-aquaCordyline/00-firstScript.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 5b83ae532..c02365092 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`( +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_transfer`( vOriginalEntry INT, OUT vNewEntryFk INT ) diff --git a/db/versions/11425-aquaCordyline/00-firstScript.sql b/db/versions/11425-aquaCordyline/00-firstScript.sql new file mode 100644 index 000000000..d8d16a29f --- /dev/null +++ b/db/versions/11425-aquaCordyline/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId, editorFk) +VALUES(1019, 'Entry', 'transfer', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss', 100); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index db6873663..fc1c4808a 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -1,6 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('transfer', { description: 'Transfer merchandise from one entry to the next day', + accessType: 'WRITE', accepts: [ { arg: 'id', From a01c419b44f2633ef74a8786f877d6b63d92028b Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 28 Jan 2025 12:51:21 +0100 Subject: [PATCH 30/39] fix: refs #7917 fix tback --- modules/route/back/methods/route/specs/summary.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/back/methods/route/specs/summary.spec.js b/modules/route/back/methods/route/specs/summary.spec.js index 096abe62c..2ef052c7e 100644 --- a/modules/route/back/methods/route/specs/summary.spec.js +++ b/modules/route/back/methods/route/specs/summary.spec.js @@ -22,10 +22,10 @@ describe('route summary()', () => { }); it(`should return a summary object containing it's worker`, async() => { - const result = await app.models.Route.summary(1); + const result = await app.models.Route.summary(2); const worker = result.route.worker().user(); - expect(worker.name).toEqual('deliveryfreelancer'); + expect(worker.name).toEqual('delivery'); }); it(`should return a summary object containing data from the tickets`, async() => { From b383725f9fa3311ef26fdc19864507c084803939 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 28 Jan 2025 12:56:30 +0100 Subject: [PATCH 31/39] fix: refs #7917 fix user tests --- db/dump/fixtures.before.sql | 6 +++--- modules/route/back/methods/route/specs/filter.spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0d3029cfe..76ccc7c1e 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -752,15 +752,15 @@ INSERT INTO `vn`.`zoneConfig` (`id`, `scope`) VALUES (1, '1'); INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`, `dated`) VALUES - (1, '1899-12-30 12:15:00', 132, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (1, '1899-12-30 12:15:00', 133, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()), (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10, util.VN_CURDATE()), (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12, util.VN_CURDATE()), (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13, util.VN_CURDATE()), (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3, util.VN_CURDATE()), (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5, util.VN_CURDATE()), - (8, NULL, 132, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), - (9, NULL, 132, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); + (8, NULL, 133, util.VN_CURDATE(), 1, 1, 'eighth route', 1.8, 10.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1, util.VN_CURDATE()), + (9, NULL, 133, util.VN_CURDATE(), 1, 2, 'ninth route', 0.2, 20.0, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9, util.VN_CURDATE()); INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`, `cmrFk`, `problem`, `risk`) VALUES diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 8f199e34a..11bf0b7b0 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -26,7 +26,7 @@ describe('Route filter()', () => { const ctx = { req: { accessToken: { - userId: 132 + userId: 133 } } }; From a6a875cb2c12e469948d9d346ea3a52097569aea Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 28 Jan 2025 13:27:35 +0100 Subject: [PATCH 32/39] feat: refs #8077 redirection lilium --- e2e/paths/02-client/21_defaulter.spec.js | 65 ------ modules/client/front/defaulter/index.html | 198 ------------------- modules/client/front/defaulter/index.js | 192 +----------------- modules/client/front/defaulter/index.spec.js | 179 ----------------- modules/client/front/defaulter/locale/es.yml | 14 -- 5 files changed, 3 insertions(+), 645 deletions(-) delete mode 100644 e2e/paths/02-client/21_defaulter.spec.js delete mode 100644 modules/client/front/defaulter/index.spec.js delete mode 100644 modules/client/front/defaulter/locale/es.yml diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js deleted file mode 100644 index 01f394bc8..000000000 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ /dev/null @@ -1,65 +0,0 @@ -import selectors from '../../helpers/selectors.js'; -import getBrowser from '../../helpers/puppeteer'; - -describe('Client defaulter path', () => { - let browser; - let page; - - beforeAll(async() => { - browser = await getBrowser(); - page = browser.page; - await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter'); - }); - - afterAll(async() => { - await browser.close(); - }); - - it('should count the amount of clients in the turns section', async() => { - const result = await page.countElement(selectors.clientDefaulter.anyClient); - - expect(result).toEqual(6); - }); - - it('should check contain expected client', async() => { - const clientName = - await page.waitToGetProperty(selectors.clientDefaulter.firstClientName, 'innerText'); - const salesPersonName = - await page.waitToGetProperty(selectors.clientDefaulter.firstSalesPersonName, 'innerText'); - - expect(clientName).toEqual('Ororo Munroe'); - expect(salesPersonName).toEqual('salesperson'); - }); - - it('should first observation not changed', async() => { - const expectedObservation = 'Madness, as you know, is like gravity, all it takes is a little push'; - const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value'); - - expect(result).toContain(expectedObservation); - }); - - it('should not add empty observation', async() => { - await page.waitToClick(selectors.clientDefaulter.allDefaulterCheckbox); - - await page.waitToClick(selectors.clientDefaulter.addObservationButton); - await page.write(selectors.clientDefaulter.observation, ''); - await page.waitToClick(selectors.clientDefaulter.saveButton); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain(`The message can't be empty`); - }); - - it('should checked all defaulters', async() => { - await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter'); - - await page.waitToClick(selectors.clientDefaulter.allDefaulterCheckbox); - }); - - it('should add observation for all clients', async() => { - await page.waitToClick(selectors.clientDefaulter.addObservationButton); - await page.write(selectors.clientDefaulter.observation, 'My new observation'); - await page.waitToClick(selectors.clientDefaulter.saveButton); - }); -}); diff --git a/modules/client/front/defaulter/index.html b/modules/client/front/defaulter/index.html index 440f34d3d..7fb3b870e 100644 --- a/modules/client/front/defaulter/index.html +++ b/modules/client/front/defaulter/index.html @@ -1,200 +1,2 @@ - - - - - - - - -
-
-
Total
- - -
-
-
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - Client - - Es trabajador - - Comercial - - Country - - P.Method - - Balance D. - - Author - - Last observation - - L. O. Date - - Credit I. - - From -
- - - - - {{::defaulter.clientName}} - - - - - - - {{::defaulter.salesPersonName | dashIfEmpty}} - - - {{::defaulter.country}} - - {{::defaulter.payMethod}} - {{::defaulter.amount | currency: 'EUR': 2}} - - {{::defaulter.workerName | dashIfEmpty}} - - - - - - - {{::defaulter.created | date: 'dd/MM/yyyy'}} - - {{::defaulter.creditInsurance | currency: 'EUR': 2}}{{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}}
-
-
- - - - - - - - - - - - -
-
{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}
- - - - -
-
- - - - -
diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 2ec53d380..9df546a85 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -1,199 +1,13 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -import UserError from 'core/lib/user-error'; export default class Controller extends Section { constructor($element, $) { super($element, $); - this.defaulter = {}; - this.defaulters = []; - this.checkedDefaulers = []; - - this.smartTableOptions = { - activeButtons: { - search: true - }, - columns: [ - { - field: 'clientFk', - autocomplete: { - url: 'Clients', - showField: 'name', - valueField: 'id' - } - }, { - field: 'salesPersonFk', - autocomplete: { - url: 'Workers/activeWithInheritedRole', - where: `{role: 'salesPerson'}`, - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', - } - }, { - field: 'countryFk', - autocomplete: { - url: 'Countries', - showField: 'country', - valueField: 'id' - } - }, { - field: 'payMethodFk', - autocomplete: { - showField: 'name', - valueField: 'id' - } - }, - { - field: 'workerFk', - autocomplete: { - url: 'Workers/activeWithInheritedRole', - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', - } - }, - { - field: 'observation', - searchable: false - }, - { - field: 'isWorker', - checkbox: true, - - }, - { - field: 'created', - datepicker: true - }, - { - field: 'defaulterSinced', - datepicker: true - } - ] - }; - - this.getBalanceDueTotal(); } - - set defaulters(value) { - if (!value || !value.length) return; - this._defaulters = value; - } - - get defaulters() { - return this._defaulters; - } - - get checked() { - const clients = this.$.model.data || []; - const checkedLines = []; - for (let defaulter of clients) { - if (defaulter.checked) - checkedLines.push(defaulter); - } - - return checkedLines; - } - - saveChecked(clientId) { - this.checkedDefaulers = this.checkedDefaulers.includes(clientId) ? - this.checkedDefaulers.filter(id => id !== clientId) : [...this.checkedDefaulers, clientId]; - } - - reCheck() { - if (!this.$.model.data || !this.checkedDefaulers.length) return; - - this.$.model.data.forEach(defaulter => { - defaulter.checked = this.checkedDefaulers.includes(defaulter.clientFk); - }); - } - - getBalanceDueTotal() { - this.$http.get('Defaulters/filter') - .then(res => { - if (!res.data) return 0; - - this.balanceDueTotal = res.data.reduce( - (accumulator, currentValue) => { - return accumulator + (currentValue['amount'] || 0); - }, 0); - }); - } - - chipColor(date) { - const day = 24 * 60 * 60 * 1000; - const today = Date.vnNew(); - today.setHours(0, 0, 0, 0); - - const observationShipped = new Date(date); - observationShipped.setHours(0, 0, 0, 0); - - const difference = today - observationShipped; - - if (difference > (day * 20)) - return 'alert'; - if (difference > (day * 10)) - return 'warning'; - } - - onResponse() { - if (!this.defaulter.observation) - throw new UserError(`The message can't be empty`); - - const params = []; - for (let defaulter of this.checked) { - params.push({ - text: this.defaulter.observation, - clientFk: defaulter.clientFk - }); - } - - this.$http.post(`ClientObservations`, params) .then(() => { - this.vnApp.showSuccess(this.$t('Observation saved!')); - this.sendMail(); - this.$state.reload(); - }); - } - - sendMail() { - const params = { - defaulters: this.checked, - observation: this.defaulter.observation, - }; - this.$http.post(`Defaulters/observationEmail`, params); - } - - exprBuilder(param, value) { - switch (param) { - case 'isWorker': - return {isWorker: value}; - case 'creditInsurance': - case 'amount': - case 'clientFk': - case 'workerFk': - case 'countryFk': - case 'payMethod': - case 'salesPersonFk': - return {[`d.${param}`]: value}; - case 'created': - return {'d.created': { - between: this.dateRange(value)} - }; - case 'defaulterSinced': - return {'d.defaulterSinced': { - between: this.dateRange(value)} - }; - } - } - - dateRange(value) { - const minHour = new Date(value); - minHour.setHours(0, 0, 0, 0); - const maxHour = new Date(value); - maxHour.setHours(23, 59, 59, 59); - - return [minHour, maxHour]; + async $onInit() { + this.$state.go('customer.defaulter', {id: this.$params.id}); + window.location.href = await this.vnApp.getUrl(`customer/defaulter`); } } diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js deleted file mode 100644 index b4a9df184..000000000 --- a/modules/client/front/defaulter/index.spec.js +++ /dev/null @@ -1,179 +0,0 @@ -import './index'; -import crudModel from 'core/mocks/crud-model'; - -describe('client defaulter', () => { - describe('Component vnClientDefaulter', () => { - let controller; - let $httpBackend; - - beforeEach(ngModule('client')); - - beforeEach(inject(($componentController, _$httpBackend_) => { - $httpBackend = _$httpBackend_; - const $element = angular.element(''); - controller = $componentController('vnClientDefaulter', {$element}); - controller.$.model = crudModel; - controller.$.model.data = [ - {clientFk: 1101, amount: 125}, - {clientFk: 1102, amount: 500}, - {clientFk: 1103, amount: 250} - ]; - })); - - describe('checked() getter', () => { - it('should return the checked lines', () => { - const data = controller.$.model.data; - data[1].checked = true; - data[2].checked = true; - - const checkedRows = controller.checked; - - const firstCheckedRow = checkedRows[0]; - const secondCheckedRow = checkedRows[1]; - - expect(firstCheckedRow.clientFk).toEqual(1102); - expect(secondCheckedRow.clientFk).toEqual(1103); - }); - }); - - describe('chipColor()', () => { - it('should return undefined when the date is the present', () => { - let today = Date.vnNew(); - let result = controller.chipColor(today); - - expect(result).toEqual(undefined); - }); - - it('should return warning when the date is 10 days in the past', () => { - let pastDate = Date.vnNew(); - pastDate = pastDate.setDate(pastDate.getDate() - 11); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('warning'); - }); - - it('should return alert when the date is 20 days in the past', () => { - let pastDate = Date.vnNew(); - pastDate = pastDate.setDate(pastDate.getDate() - 21); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('alert'); - }); - }); - - describe('onResponse()', () => { - it('should return error for empty message', () => { - let error; - try { - controller.onResponse(); - } catch (e) { - error = e; - } - - expect(error).toBeDefined(); - expect(error.message).toBe(`The message can't be empty`); - }); - - it('should return saved message', () => { - const data = controller.$.model.data; - data[1].checked = true; - controller.defaulter = {observation: 'My new observation'}; - - const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; - - jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expect('GET', `Defaulters/filter`).respond(200); - $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); - $httpBackend.expect('POST', `Defaulters/observationEmail`).respond(200); - - controller.onResponse(); - $httpBackend.flush(); - - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Observation saved!'); - }); - }); - - describe('exprBuilder()', () => { - it('should search by sales person', () => { - const expr = controller.exprBuilder('salesPersonFk', '5'); - - expect(expr).toEqual({'d.salesPersonFk': '5'}); - }); - - it('should search by client', () => { - const expr = controller.exprBuilder('clientFk', '5'); - - expect(expr).toEqual({'d.clientFk': '5'}); - }); - }); - - describe('getBalanceDueTotal()', () => { - it('should return balance due total', () => { - const defaulters = controller.$.model.data; - $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); - - controller.getBalanceDueTotal(); - $httpBackend.flush(); - - expect(controller.balanceDueTotal).toEqual(875); - }); - }); - - describe('dateRange()', () => { - it('should return two dates with the hours at the start and end of the given date', () => { - const now = Date.vnNew(); - - const today = now.getDate(); - - const dateRange = controller.dateRange(now); - const start = dateRange[0].toString(); - const end = dateRange[1].toString(); - - expect(start).toContain(today); - expect(start).toContain('00:00:00'); - - expect(end).toContain(today); - expect(end).toContain('23:59:59'); - }); - }); - - describe('reCheck()', () => { - it(`should recheck buys`, () => { - controller.$.model.data = [ - {checked: false, clientFk: 1}, - {checked: false, clientFk: 2}, - {checked: false, clientFk: 3}, - {checked: false, clientFk: 4}, - ]; - controller.checkedDefaulers = [1, 2]; - - controller.reCheck(); - - expect(controller.$.model.data[0].checked).toEqual(true); - expect(controller.$.model.data[1].checked).toEqual(true); - expect(controller.$.model.data[2].checked).toEqual(false); - expect(controller.$.model.data[3].checked).toEqual(false); - }); - }); - - describe('saveChecked()', () => { - it(`should check buy`, () => { - const buyCheck = 3; - controller.checkedDefaulers = [1, 2]; - - controller.saveChecked(buyCheck); - - expect(controller.checkedDefaulers[2]).toEqual(buyCheck); - }); - - it(`should uncheck buy`, () => { - const buyUncheck = 3; - controller.checkedDefaulers = [1, 2, 3]; - - controller.saveChecked(buyUncheck); - - expect(controller.checkedDefaulers[2]).toEqual(undefined); - }); - }); - }); -}); diff --git a/modules/client/front/defaulter/locale/es.yml b/modules/client/front/defaulter/locale/es.yml deleted file mode 100644 index 7d93d4fe2..000000000 --- a/modules/client/front/defaulter/locale/es.yml +++ /dev/null @@ -1,14 +0,0 @@ -Add observation: Añadir observación -Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) -Balance D.: Saldo V. -Credit I.: Crédito A. -Last observation: Última observación -L. O. Date: Fecha Ú. O. -Last observation date: Fecha última observación -Search client: Buscar clientes -Worker who made the last observation: Trabajador que ha realizado la última observación -Email sended!: Email enviado! -Observation saved!: Observación añadida! -P.Method: F.Pago -Pay Method: Forma de Pago -Country: Pais \ No newline at end of file From 801629c8dbd50ef44eb29650b13355f868873bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 28 Jan 2025 18:04:02 +0100 Subject: [PATCH 33/39] fix: refs #8492 Sage invoiceInTax Check VAT --- .../procedures/accountingMovements_add.sql | 65 ++++++++++++------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index 8c129beb2..060d89a3f 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -1,11 +1,11 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`( - vYear INT, + vYear INT, vCompanyFk INT ) BEGIN /** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta + * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta * para poder ejecutar posteriormente el proceso de importación de datos de SQL Server * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE * @vYear Año contable del que se quiere trasladar la información @@ -23,6 +23,7 @@ BEGIN DECLARE vInvoiceTypeInformativeCode VARCHAR(1); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); DECLARE vCompanyCode INT; + DECLARE vHasErrorTax BOOL DEFAULT FALSE; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -44,12 +45,12 @@ BEGIN FROM taxType WHERE code = 'import4'; - SELECT shipmentTransactionTypeFk, - definitiveExportTransactionTypeFk, + SELECT shipmentTransactionTypeFk, + definitiveExportTransactionTypeFk, pendingServiceTransactionTypeFk, company_getCode(vCompanyFk) INTO vTransactionExportTaxFreeFk, - vTransactionExportFk, + vTransactionExportFk, vDuaTransactionFk, vCompanyCode FROM config; @@ -66,6 +67,24 @@ BEGIN WHERE enlazadoSage = FALSE AND Asiento <> 1 ; + SELECT EXISTS ( + SELECT TRUE + FROM vn.XDiario x + JOIN vn.invoiceIn ii ON ii.id = x.CLAVE + JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id + LEFT JOIN TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk + LEFT JOIN taxType tt ON tt.id = it.taxTypeSageFk + WHERE x.FECHA BETWEEN vDatedFrom AND vDatedTo + AND NOT x.enlazadoSage + AND x.empresa_id = vCompanyFk + AND it.taxTypeSageFk + AND (ti.CodigoIva IS NULL OR tt.id IS NULL) + ) INTO vHasErrorTax; + + IF vHasErrorTax tHEN + CALL util.throw ('Error in tables for received invoices tax'); + END IF; + CALL invoiceOut_manager(vYear, vCompanyFk); CALL invoiceIn_manager(vYear, vCompanyFk); @@ -306,8 +325,8 @@ BEGIN mci.FechaFacturaOriginal = x.FECHA_EX, mci.SuFacturaNo = x.FACTURAEX, mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -326,7 +345,7 @@ BEGIN mci.CodigoIva2 = vTaxImportFk, mci.IvaDeducible2 = TRUE, mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -344,8 +363,8 @@ BEGIN mci.CodigoTransaccion3 = vDuaTransactionFk , mci.CodigoIva3 = vTaxImportSuperReducedFk, mci.IvaDeducible3 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -379,14 +398,14 @@ BEGIN OR CodigoTransaccion2 = vTransactionExportFk OR CodigoTransaccion3 = vTransactionExportFk OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); UPDATE movConta mc SET CodigoDivisa = 'USD', FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, - ImporteAsiento / ImporteDivisa, + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, + ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) WHERE enlazadoSage = FALSE AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); @@ -403,20 +422,20 @@ BEGIN WITH client AS( SELECT DISTINCT c.id FROM sage.movConta mc - JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta - WHERE NOT enlazadoSage - ),supplier AS( + JOIN vn.client c ON c.accountingAccount = mc.CodigoCuenta + WHERE NOT enlazadoSage + ),supplier AS( SELECT DISTINCT s.id FROM sage.movConta mc - JOIN vn.supplier s ON s.account = mc.CodigoCuenta - WHERE NOT enlazadoSage + JOIN vn.supplier s ON s.account = mc.CodigoCuenta + WHERE NOT enlazadoSage ),clientSupplierSync AS( SELECT idClientSupplier, `type` - FROM sage.clientSupplier cs - WHERE isSync + FROM sage.clientSupplier cs + WHERE isSync ) SELECT idClientSupplier, `type` - FROM sage.clientSupplier cs + FROM sage.clientSupplier cs WHERE NOT isSync UNION SELECT id, 'C' @@ -424,7 +443,7 @@ BEGIN LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = c.id AND cs.Type ='C' WHERE cs.idClientSupplier IS NULL - UNION + UNION SELECT id, 'P' FROM supplier s LEFT JOIN clientSupplierSync cs ON cs.idClientSupplier = s.id @@ -436,7 +455,7 @@ BEGIN INSERT IGNORE INTO sage.clientSupplier (companyFk, `type`, idClientSupplier, isSync) SELECT vCompanyCode, `type`, idClientSupplier, FALSE FROM tmp.clientSupplier; - + DROP TEMPORARY TABLE tmp.clientSupplier; CALL pgc_add(vCompanyFk); From f2be71be6cc467e261022a183065f7c427683707 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 29 Jan 2025 09:54:05 +0100 Subject: [PATCH 34/39] fix: refs #7134 replace value by util.VN_CURDATE() --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e852a3931..acbb40efe 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -4051,7 +4051,7 @@ INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); INSERT INTO vn.payment (received, supplierFk, amount, currencyFk, divisa, bankFk, payMethodFk, bankingFees, concept, companyFk, created, isConciliated, dueDated, workerFk) VALUES - (util.VN_CURDATE(), 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, '2024-11-20 13:06:02.000', 1, util.VN_CURDATE(), 9); + (util.VN_CURDATE(), 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, util.VN_CURDATE(), 1, util.VN_CURDATE(), 9); INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), From 1d53f2c49073fde57547da7c79b2d6cb3d6b27a5 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 29 Jan 2025 11:43:15 +0100 Subject: [PATCH 35/39] fix: worker filter limit --- modules/worker/back/methods/worker/filter.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/worker/back/methods/worker/filter.js b/modules/worker/back/methods/worker/filter.js index 087f080bd..da12dceca 100644 --- a/modules/worker/back/methods/worker/filter.js +++ b/modules/worker/back/methods/worker/filter.js @@ -166,12 +166,11 @@ module.exports = Self => { LEFT JOIN account.emailUser eu ON eu.userFk = u.id` ); - stmt.merge(conn.makeWhere(filter.where)); - stmts.push(stmt); + stmt.merge(conn.makeSuffix(filter)); + let itemsIndex = stmts.push(stmt) - 1; - const itemsIndex = stmts.push(stmt) - 1; - const sql = ParameterizedSQL.join(stmts, ';'); - const result = await conn.executeStmt(sql, myOptions); - return result[itemsIndex]; + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql); + return itemsIndex === 0 ? result : result[itemsIndex]; }; }; From 0de9c3c1722b4415cc8e1844dd5022464341b83e Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 29 Jan 2025 12:03:55 +0100 Subject: [PATCH 36/39] feat(available): refs #8408 available refreshing now includes time Refs: #8408 --- db/routines/cache/procedures/available_refresh.sql | 14 +++++++++----- db/routines/vn/procedures/item_getStock.sql | 6 ------ db/routines/vn/views/itemEntryIn.sql | 3 ++- .../00-agencyIncomingForeign.sql | 4 +++- db/versions/11424-navyRose/00-travel.sql | 3 +++ 5 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 db/versions/11424-navyRose/00-travel.sql diff --git a/db/routines/cache/procedures/available_refresh.sql b/db/routines/cache/procedures/available_refresh.sql index 87c003648..0e42a62cd 100644 --- a/db/routines/cache/procedures/available_refresh.sql +++ b/db/routines/cache/procedures/available_refresh.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refres OUT `vCalc` INT, `vRefresh` INT, `vWarehouse` INT, - `vDated` DATE + `vAvailabled` DATETIME ) proc: BEGIN DECLARE vStartDate DATE; @@ -12,6 +12,7 @@ proc: BEGIN DECLARE vInventoryDate DATE; DECLARE vLifeScope DATE; DECLARE vWarehouseFkInventory INT; + DECLARE vDated DATE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -19,13 +20,17 @@ proc: BEGIN RESIGNAL; END; - IF vDated < util.VN_CURDATE() THEN + IF vAvailabled < util.VN_CURDATE() THEN LEAVE proc; END IF; + SET vDated = DATE(vAvailabled); + + SET vAvailabled = vDated + INTERVAL HOUR(vAvailabled) HOUR; + CALL vn.item_getStock(vWarehouse, vDated, NULL); - SET vParams = CONCAT_WS('/', vWarehouse, vDated); + SET vParams = CONCAT_WS('/', vWarehouse, vAvailabled); CALL cache_calc_start (vCalc, vRefresh, 'available', vParams); IF !vRefresh THEN @@ -87,11 +92,10 @@ proc: BEGIN SELECT i.itemFk, i.landed, i.quantity FROM vn.itemEntryIn i JOIN itemRange ir ON ir.itemFk = i.itemFk - LEFT JOIN edi.warehouseFloramondo wf ON wf.entryFk = i.entryFk WHERE i.landed >= vStartDate + AND IFNULL(i.availabled, i.landed) <= vAvailabled AND (ir.ended IS NULL OR i.landed <= ir.ended) AND i.warehouseInFk = vWarehouse - AND ISNULL(wf.entryFk) UNION ALL SELECT i.itemFk, i.shipped, i.quantity FROM vn.itemEntryOut i diff --git a/db/routines/vn/procedures/item_getStock.sql b/db/routines/vn/procedures/item_getStock.sql index 8c0eea251..cd5bc4bdc 100644 --- a/db/routines/vn/procedures/item_getStock.sql +++ b/db/routines/vn/procedures/item_getStock.sql @@ -15,8 +15,6 @@ BEGIN * * @return tmp.itemList(itemFk, stock, visible, available) */ - DECLARE vIsLogifloraDay BOOL DEFAULT vn.isLogifloraDay(vDated, vWarehouseFk); - SET vDated = TIMESTAMP(vDated, '00:00:00'); CREATE OR REPLACE TEMPORARY TABLE tmp.itemList @@ -36,14 +34,11 @@ BEGIN UNION ALL SELECT iei.itemFk, iei.quantity FROM itemEntryIn iei - LEFT JOIN edi.warehouseFloramondo wf ON wf.entryFk = iei.entryFk JOIN item i ON i.id = iei.itemFk WHERE iei.landed >= util.VN_CURDATE() AND iei.landed < vDated AND iei.warehouseInFk = vWarehouseFk AND (vItemFk IS NULL OR iei.itemFk = vItemFk) - AND (wf.entryFk IS NULL OR vIsLogifloraDay) - AND NOT (iei.landed > util.VN_CURDATE() AND i.isFloramondo) UNION ALL SELECT ieo.itemFk, ieo.quantity FROM itemEntryOut ieo @@ -52,7 +47,6 @@ BEGIN AND ieo.shipped < vDated AND ieo.warehouseOutFk = vWarehouseFk AND (vItemFk IS NULL OR ieo.itemFk = vItemFk) - AND NOT (ieo.shipped > util.VN_CURDATE() AND i.isFloramondo) ) sub GROUP BY itemFk HAVING stock; diff --git a/db/routines/vn/views/itemEntryIn.sql b/db/routines/vn/views/itemEntryIn.sql index 60af585f2..5be558a43 100644 --- a/db/routines/vn/views/itemEntryIn.sql +++ b/db/routines/vn/views/itemEntryIn.sql @@ -7,7 +7,8 @@ AS SELECT `t`.`warehouseInFk` AS `warehouseInFk`, `b`.`quantity` AS `quantity`, `t`.`isReceived` AS `isReceived`, `t`.`isRaid` AS `isVirtualStock`, - `e`.`id` AS `entryFk` + `e`.`id` AS `entryFk`, + `t`.`availabled` FROM ( ( `vn`.`buy` `b` diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql index 829236a2a..7d8f44040 100644 --- a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -1,3 +1,5 @@ +USE vn; + DELETE ai from `vn`.`agencyIncoming` ai LEFT JOIN `vn`.`agencyMode` am ON @@ -7,6 +9,6 @@ DELETE ai from ALTER TABLE `vn`.`agencyIncoming` ADD CONSTRAINT `fk_agencyIncoming_agencyMode` FOREIGN KEY (`agencyModeFk`) - REFERENCES `agencyMode`(`id`) + REFERENCES `vn`.`agencyMode`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/11424-navyRose/00-travel.sql b/db/versions/11424-navyRose/00-travel.sql new file mode 100644 index 000000000..eabd83d5e --- /dev/null +++ b/db/versions/11424-navyRose/00-travel.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.travel ADD IF NOT EXISTS availabled DATETIME NULL +COMMENT 'Indicates the moment in time when the goods become available for picking'; From 4e2a6d275a229e2058390c68d3938e27f6593bb0 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 29 Jan 2025 12:12:23 +0100 Subject: [PATCH 37/39] fix(travel): refs #8408 trigger restriction for wrong availabled value Refs: #8408 --- db/routines/vn/triggers/travel_beforeInsert.sql | 4 ++++ db/routines/vn/triggers/travel_beforeUpdate.sql | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql index 5356ed537..2cae96cd9 100644 --- a/db/routines/vn/triggers/travel_beforeInsert.sql +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -16,5 +16,9 @@ BEGIN IF NEW.awbFk IS NOT NULL THEN CALL travel_throwAwb(NEW.id); END IF; + + IF NEW.availabled < NEW.landed THEN + CALL util.throw('The travel availabled cannot be earlier than landed'); + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql index 5a27b43b4..093dee082 100644 --- a/db/routines/vn/triggers/travel_beforeUpdate.sql +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -40,5 +40,9 @@ BEGIN IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL THEN CALL travel_throwAwb(NEW.id); END IF; + + IF NEW.availabled < NEW.landed THEN + CALL util.throw('The travel availabled cannot be earlier than landed'); + END IF; END$$ DELIMITER ; From 597615facbcc34d5ba630c0ac23ecb5f5e2dd403 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 29 Jan 2025 12:15:04 +0100 Subject: [PATCH 38/39] fix(agencyIncomingForeign): refs #8408 version changes rolled back Refs: #8408 --- .../11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql index 7d8f44040..829236a2a 100644 --- a/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql +++ b/db/versions/11411-turquoiseEucalyptus/00-agencyIncomingForeign.sql @@ -1,5 +1,3 @@ -USE vn; - DELETE ai from `vn`.`agencyIncoming` ai LEFT JOIN `vn`.`agencyMode` am ON @@ -9,6 +7,6 @@ DELETE ai from ALTER TABLE `vn`.`agencyIncoming` ADD CONSTRAINT `fk_agencyIncoming_agencyMode` FOREIGN KEY (`agencyModeFk`) - REFERENCES `vn`.`agencyMode`(`id`) + REFERENCES `agencyMode`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; From d53669019794843a3289235b8a3c5da8e5dd8a0a Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 29 Jan 2025 12:43:46 +0100 Subject: [PATCH 39/39] feat: refs #6822 changes request --- db/versions/11425-aquaCordyline/00-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11425-aquaCordyline/00-firstScript.sql b/db/versions/11425-aquaCordyline/00-firstScript.sql index d8d16a29f..f8b194e8a 100644 --- a/db/versions/11425-aquaCordyline/00-firstScript.sql +++ b/db/versions/11425-aquaCordyline/00-firstScript.sql @@ -1,2 +1,2 @@ -INSERT IGNORE INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId, editorFk) -VALUES(1019, 'Entry', 'transfer', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss', 100); +INSERT IGNORE INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES('Entry', 'transfer', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss');