From 62243e164a3d44f2ad4cd02f85a82baebad076eb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Nov 2024 14:47:21 +0100 Subject: [PATCH 01/20] 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 0000000000..c051a67510 --- /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 0000000000..dce9c31d4e --- /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 7e6908d57c..20313801e6 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/20] 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 e093c05cb1..4ba377005a 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/20] 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 4ba377005a..2dcedcc929 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/20] 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 c0014f8e5c..b678588fec 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/20] 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 dce9c31d4e..474cd256f2 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/20] 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 c051a67510..8fa61f0c91 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 20313801e6..6bf9ecf32f 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/20] 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 ed354969e5..2bc6655033 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 0000000000..0ce8f96069 --- /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 0000000000..112741422b --- /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 0000000000..005607c9a8 --- /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 0000000000..d40e24039c --- /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 8fa61f0c91..9dce4d9276 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 3691daded492b3ca57f25875fff0bf9d8a09b2e3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 27 Dec 2024 13:26:38 +0100 Subject: [PATCH 08/20] 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 b678588fec..625b5195e2 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 474cd256f2..68865a2427 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 09/20] 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 68865a2427..9dcef17de5 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 420bb2a57ed8113309bb2931c35ccd729dae9692 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 13 Jan 2025 12:41:16 +0100 Subject: [PATCH 10/20] 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 0ce8f96069..0000000000 --- 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 112741422b..0000000000 --- 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 005607c9a8..0000000000 --- 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 d40e24039c..0000000000 --- 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 9dce4d9276..0000000000 --- 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 11/20] 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 3d2101604a..4042246df9 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 9dcef17de5..1b4dfe40be 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 12/20] 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 1b4dfe40be..50f4610dab 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 6bf9ecf32f..63bd65fbd8 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 13/20] 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 625b5195e2..827e4b24db 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 14/20] 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 50f4610dab..cc7b03a42d 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 294c2f832efaea595b6279381f7a4f740ecad52e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Jan 2025 14:53:19 +0100 Subject: [PATCH 15/20] 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 827e4b24db..ad80e2c9f8 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 16/20] 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 79ee2463cf..34da74d51d 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 8482743baf33eebc495504731fa3ac17cd898386 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 28 Jan 2025 11:26:48 +0100 Subject: [PATCH 17/20] 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 5b83ae5321..c02365092b 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 0000000000..d8d16a29f7 --- /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 db68736633..fc1c4808af 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 f2be71be6cc467e261022a183065f7c427683707 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 29 Jan 2025 09:54:05 +0100 Subject: [PATCH 18/20] 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 e852a3931a..acbb40efeb 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 d53669019794843a3289235b8a3c5da8e5dd8a0a Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 29 Jan 2025 12:43:46 +0100 Subject: [PATCH 19/20] 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 d8d16a29f7..f8b194e8a4 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'); From 0a89a6a6fdb366e944ad6c8527c5dde86f21ba94 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 30 Jan 2025 12:40:48 +0100 Subject: [PATCH 20/20] fix: refs #7488 deleted nif validation --- modules/worker/back/models/worker.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 97e6a283c3..4895a6107f 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -1,5 +1,4 @@ module.exports = Self => { - const validateTin = require('vn-loopback/util/validateTin'); require('../methods/worker/filter')(Self); require('../methods/worker/mySubordinates')(Self); require('../methods/worker/isSubordinate')(Self); @@ -23,26 +22,10 @@ module.exports = Self => { require('../methods/worker/getAvailablePda')(Self); require('../methods/worker/myTeam')(Self); - Self.validateAsync('fi', tinIsValid, { - message: 'Invalid TIN' - }); - Self.canModifyAbsenceInPast = async(ctx, time) => { const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); return hasPrivs || today.getTime() < time; }; - - async function tinIsValid(err, done) { - const country = await Self.app.models.Country.findOne({ - fields: ['code'], - where: {id: this.originCountryFk} - }); - const code = country ? country.code.toLowerCase() : null; - - if (!this.fi || !validateTin(this.fi, code)) - err(); - done(); - } };