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 @@
Compensation
+ Compensation
-
- {{$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