From ea2fd59cdc8e8e59ca3b6d12519ceb6a27e43166 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 14 Feb 2023 12:41:36 +0100 Subject: [PATCH 1/3] refs #5223 changed ref and email text --- db/changes/230402/00-clienteCompensado.sql | 3 + .../back/methods/client/createReceipt.js | 23 ++------ .../client/getClientOrSupplierReference.js | 58 +++++++++++++++++++ modules/client/back/models/client-methods.js | 1 + .../client/front/balance/create/index.html | 24 ++++---- modules/client/front/balance/create/index.js | 33 +++++++++-- .../client/front/balance/create/locale/es.yml | 4 +- .../balance-compensation.html | 4 +- .../balance-compensation/locale/es.yml | 8 +-- .../balance-compensation/sql/client.sql | 1 + 10 files changed, 115 insertions(+), 44 deletions(-) create mode 100644 db/changes/230402/00-clienteCompensado.sql create mode 100644 modules/client/back/methods/client/getClientOrSupplierReference.js diff --git a/db/changes/230402/00-clienteCompensado.sql b/db/changes/230402/00-clienteCompensado.sql new file mode 100644 index 000000000..ff1982b93 --- /dev/null +++ b/db/changes/230402/00-clienteCompensado.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Client', 'getClientOrSupplierReference', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/client/back/methods/client/createReceipt.js b/modules/client/back/methods/client/createReceipt.js index a75ee8844..b268aba35 100644 --- a/modules/client/back/methods/client/createReceipt.js +++ b/modules/client/back/methods/client/createReceipt.js @@ -67,7 +67,7 @@ module.exports = function(Self) { try { delete args.ctx; // Remove unwanted properties - const newReceipt = await models.Receipt.create(args, myOptions); + const originalClient = await models.Client.findById(args.clientFk, null, myOptions); const bank = await models.Bank.findById(args.bankFk, null, myOptions); const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); @@ -76,23 +76,8 @@ module.exports = function(Self) { if (!args.compensationAccount) throw new UserError('Compensation account is empty'); - const supplierCompensation = await models.Supplier.findOne({ - where: { - account: args.compensationAccount - } - }, myOptions); - - let clientCompensation = {}; - - if (!supplierCompensation) { - clientCompensation = await models.Client.findOne({ - where: { - accountingAccount: args.compensationAccount - } - }, myOptions); - } - if (!supplierCompensation && !clientCompensation) - throw new UserError('Invalid account'); + // Check compensation account exists + await models.Client.getClientOrSupplierReference(args.compensationAccount, myOptions); await Self.rawSql( `CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`, @@ -151,7 +136,7 @@ module.exports = function(Self) { myOptions ); } - + const newReceipt = await models.Receipt.create(args, myOptions); if (tx) await tx.commit(); return newReceipt; diff --git a/modules/client/back/methods/client/getClientOrSupplierReference.js b/modules/client/back/methods/client/getClientOrSupplierReference.js new file mode 100644 index 000000000..afb427315 --- /dev/null +++ b/modules/client/back/methods/client/getClientOrSupplierReference.js @@ -0,0 +1,58 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('getClientOrSupplierReference', { + description: 'Returns the reference of a compensation providing a bank account', + accessType: 'READ', + accepts: { + arg: 'bankAccount', + type: 'number', + required: true, + description: 'The bank account of a client or a supplier', + http: {source: 'path'} + }, + returns: { + type: 'string', + root: true + }, + http: { + path: `/:bankAccount/getClientOrSupplierReference`, + verb: 'GET' + } + }); + + Self.getClientOrSupplierReference = async(bankAccount, options) => { + const models = Self.app.models; + const myOptions = {}; + let reference = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const supplierCompensation = await models.Supplier.findOne({ + where: { + account: bankAccount + } + }, myOptions); + + reference.supplierId = supplierCompensation?.id; + reference.supplierName = supplierCompensation?.name; + + let clientCompensation = {}; + + if (!supplierCompensation) { + clientCompensation = await models.Client.findOne({ + where: { + accountingAccount: bankAccount + } + }, myOptions); + reference.clientId = clientCompensation?.id; + reference.clientName = clientCompensation?.name; + } + + if (!supplierCompensation && !clientCompensation) + throw new UserError('Invalid account'); + + return reference; + }; +}; diff --git a/modules/client/back/models/client-methods.js b/modules/client/back/models/client-methods.js index 4b20a822c..9241d80cf 100644 --- a/modules/client/back/models/client-methods.js +++ b/modules/client/back/models/client-methods.js @@ -47,4 +47,5 @@ module.exports = Self => { require('../methods/client/incotermsAuthorizationEmail')(Self); require('../methods/client/consumptionSendQueued')(Self); require('../methods/client/filter')(Self); + require('../methods/client/getClientOrSupplierReference')(Self); }; diff --git a/modules/client/front/balance/create/index.html b/modules/client/front/balance/create/index.html index 56e505463..b76c09356 100644 --- a/modules/client/front/balance/create/index.html +++ b/modules/client/front/balance/create/index.html @@ -11,7 +11,7 @@ @@ -48,6 +48,14 @@ max="$ctrl.maxAmount"> + +
Compensation
+ + +
- -
Compensation
- - -
- @@ -89,4 +89,4 @@ - \ No newline at end of file + diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index ab97a7291..b22d15936 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -60,11 +60,15 @@ class Controller extends Dialog { const accountingType = value.accountingType; this.viewReceipt = accountingType.code == 'cash'; - if (accountingType.receiptDescription != null) { - this.receipt.description = accountingType.receiptDescription; - if (this.originalDescription) this.receipt.description += `, ${this.originalDescription}`; - } else if (this.originalDescription) - this.receipt.description = this.originalDescription; + if (accountingType.code == 'compensation') + this.receipt.description = ''; + else { + if (accountingType.receiptDescription != null) { + this.receipt.description = accountingType.receiptDescription; + if (this.originalDescription) this.receipt.description += `, ${this.originalDescription}`; + } else if (this.originalDescription) + this.receipt.description = this.originalDescription; + } this.maxAmount = accountingType && accountingType.maxAmount; this.receipt.payed = new Date(); @@ -110,7 +114,24 @@ class Controller extends Dialog { } accountShortToStandard(value) { - this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length)); + if (value) { + this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length)); + this.$http.get(`Clients/${this.receipt.compensationAccount}/getClientOrSupplierReference`) + .then(res => { + if (res.data.clientId) { + this.receipt.description = this.$t('Client Compensation Reference', { + clientId: res.data.clientId, + clientName: res.data.clientName + }); + } else { + this.receipt.description = this.$t('Supplier Compensation Reference', { + supplierId: res.data.supplierId, + supplierName: res.data.supplierName + }); + } + }); + } else + this.receipt.description = ''; } getAmountPaid() { diff --git a/modules/client/front/balance/create/locale/es.yml b/modules/client/front/balance/create/locale/es.yml index 056590966..8c407708a 100644 --- a/modules/client/front/balance/create/locale/es.yml +++ b/modules/client/front/balance/create/locale/es.yml @@ -1,2 +1,4 @@ View receipt: Ver recibo -Amount exceeded: Según ley contra el fraude no se puede recibir cobros por importe igual o superior a {{maxAmount}} \ No newline at end of file +Amount exceeded: Según ley contra el fraude no se puede recibir cobros por importe igual o superior a {{maxAmount}} +Client Compensation Reference: "({{clientId}}) Ntro Cliente: {{clientName}}" +Supplier Compensation Reference: "({{supplierId}}) Ntro Proveedor: {{supplierName}}" diff --git a/print/templates/reports/balance-compensation/balance-compensation.html b/print/templates/reports/balance-compensation/balance-compensation.html index 1e9aa5661..d1a2788ed 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.html +++ b/print/templates/reports/balance-compensation/balance-compensation.html @@ -17,8 +17,8 @@

{{$t('Agree') | uppercase}}

- {{$t('Date')}} {{formatDate(client.payed, '%d-%m-%Y')}} {{$t('Compensate')}} {{client.amountPaid}} € - {{$t('From client')}} {{client.name}} {{$t('Toclient')}} {{company.name}}. + {{$t('Date')}} {{client.payed | date('%d-%m-%Y')}} {{$t('Compensate')}} {{client.amountPaid}} € + {{$t('From client')}} {{client.name}} {{$t('Against the balance of')}}: {{client.invoiceFk}}.

{{$t('Reception')}} administracion@verdnatura.es diff --git a/print/templates/reports/balance-compensation/locale/es.yml b/print/templates/reports/balance-compensation/locale/es.yml index 546e55f06..1c76274ae 100644 --- a/print/templates/reports/balance-compensation/locale/es.yml +++ b/print/templates/reports/balance-compensation/locale/es.yml @@ -4,13 +4,13 @@ Compensation: Compensación de saldos deudores y acreedores In one hand: De una parte CIF: con CIF NIF: con NIF -Home: y domicilio sito en +Home: y domicilio sito en In other hand: De la otra Sr: Don/Doña Agree: Acuerdan Date: En fecha de -Compensate: se ha compensado el saldo de +Compensate: se ha compensado el saldo de From client: del cliente/proveedor -To client: con el cliente/proveedor +Against the balance of: contra el saldo de Reception: Por favor, rogamos confirmen la recepción de esta compensación al email -Greetings: Saludos cordiales, \ No newline at end of file +Greetings: Saludos cordiales, diff --git a/print/templates/reports/balance-compensation/sql/client.sql b/print/templates/reports/balance-compensation/sql/client.sql index b4463be23..c3679b68a 100644 --- a/print/templates/reports/balance-compensation/sql/client.sql +++ b/print/templates/reports/balance-compensation/sql/client.sql @@ -4,6 +4,7 @@ SELECT c.street, c.fi, c.city, + r.invoiceFk, r.amountPaid, r.payed FROM client c From e68afa316925d34e17e0e04f220604343a33638d Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Feb 2023 12:59:19 +0100 Subject: [PATCH 2/3] refs #5223 moved sql --- db/changes/{230402 => 230403}/00-clienteCompensado.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{230402 => 230403}/00-clienteCompensado.sql (100%) diff --git a/db/changes/230402/00-clienteCompensado.sql b/db/changes/230403/00-clienteCompensado.sql similarity index 100% rename from db/changes/230402/00-clienteCompensado.sql rename to db/changes/230403/00-clienteCompensado.sql From dca5ae0f72e61720d491515ccf3f3e80894ded78 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 15 Feb 2023 13:14:52 +0100 Subject: [PATCH 3/3] refs #5223 added params --- .../back/methods/client/getClientOrSupplierReference.js | 5 ++--- modules/client/front/balance/create/index.js | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/client/back/methods/client/getClientOrSupplierReference.js b/modules/client/back/methods/client/getClientOrSupplierReference.js index afb427315..4c7201ee3 100644 --- a/modules/client/back/methods/client/getClientOrSupplierReference.js +++ b/modules/client/back/methods/client/getClientOrSupplierReference.js @@ -8,15 +8,14 @@ module.exports = Self => { arg: 'bankAccount', type: 'number', required: true, - description: 'The bank account of a client or a supplier', - http: {source: 'path'} + description: 'The bank account of a client or a supplier' }, returns: { type: 'string', root: true }, http: { - path: `/:bankAccount/getClientOrSupplierReference`, + path: `/getClientOrSupplierReference`, verb: 'GET' } }); diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index b22d15936..6d6e99e29 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -116,7 +116,8 @@ class Controller extends Dialog { accountShortToStandard(value) { if (value) { this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length)); - this.$http.get(`Clients/${this.receipt.compensationAccount}/getClientOrSupplierReference`) + const params = {bankAccount: this.receipt.compensationAccount}; + this.$http.get(`Clients/getClientOrSupplierReference`, {params}) .then(res => { if (res.data.clientId) { this.receipt.description = this.$t('Client Compensation Reference', {