diff --git a/modules/client/back/models/receipt.json b/modules/client/back/models/receipt.json index 19107f561..da7879df9 100644 --- a/modules/client/back/models/receipt.json +++ b/modules/client/back/models/receipt.json @@ -62,6 +62,11 @@ "type": "belongsTo", "model": "Bank", "foreignKey": "bankFk" + }, + "supplier": { + "type": "belongsTo", + "model": "Supplier", + "foreignKey": "companyFk" } } -} \ No newline at end of file +} diff --git a/print/templates/reports/balance-compensation/balance-compensation.html b/print/templates/reports/balance-compensation/balance-compensation.html index 1e9aa5661..6849c70c8 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.html +++ b/print/templates/reports/balance-compensation/balance-compensation.html @@ -7,18 +7,18 @@

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

{{$t('In one hand')}}:

- {{company.name}} {{$t('CIF')}} {{company.nif}} {{$t('Home')}} {{company.street}}, - {{company.city}}. + {{receipt.supplier().name}} {{$t('CIF')}} {{receipt.supplier().nif}} {{$t('Home')}} {{receipt.supplier().street}}, + {{receipt.supplier().city}}.

{{$t('In other hand')}}:

- {{$t('Sr')}} {{client.name}} {{$t('NIF')}} {{client.fi}} {{$t('Home')}} {{client.street}}, - {{client.city}}. + {{$t('Sr')}} {{receipt.client().name}} {{$t('NIF')}} {{receipt.client().fi}} {{$t('Home')}} {{receipt.client().street}}, + {{receipt.client().city}}.

{{$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')}} {{formatDate(receipt.payed, '%d-%m-%Y')}} {{$t('Compensate')}} {{receipt.amountPaid}} € + {{$t('From client')}} {{receipt.client().name}} {{$t('To client')}} {{receipt.supplier().name}}.

{{$t('Reception')}} administracion@verdnatura.es diff --git a/print/templates/reports/balance-compensation/balance-compensation.js b/print/templates/reports/balance-compensation/balance-compensation.js index bae7c5c3c..7b7a1053e 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.js +++ b/print/templates/reports/balance-compensation/balance-compensation.js @@ -1,12 +1,28 @@ const vnReport = require('../../../core/mixins/vn-report.js'); +const app = require('vn-loopback/server/server'); module.exports = { name: 'balance-compensation', mixins: [vnReport], async serverPrefetch() { - this.client = await this.findOneFromDef('client', [this.id]); - this.checkMainEntity(this.client); - this.company = await this.findOneFromDef('company', [this.id]); + this.receipt = await app.models.Receipt.findOne({ + fields: ['amountPaid', 'payed', 'clientFk', 'companyFk'], + include: [ + { + relation: 'client', + scope: { + fields: ['name', 'street', 'fi', 'city'], + } + }, { + relation: 'supplier', + scope: { + fields: ['name', 'street', 'nif', 'city'], + } + } + ], + where: {id: this.id} + }); + this.checkMainEntity(this.receipt); }, props: { id: { diff --git a/print/templates/reports/balance-compensation/sql/client.sql b/print/templates/reports/balance-compensation/sql/client.sql deleted file mode 100644 index b4463be23..000000000 --- a/print/templates/reports/balance-compensation/sql/client.sql +++ /dev/null @@ -1,11 +0,0 @@ -SELECT - c.name, - c.socialName, - c.street, - c.fi, - c.city, - r.amountPaid, - r.payed - FROM client c - JOIN receipt r ON r.clientFk = c.id - WHERE r.id = ? diff --git a/print/templates/reports/balance-compensation/sql/company.sql b/print/templates/reports/balance-compensation/sql/company.sql deleted file mode 100644 index e61228a10..000000000 --- a/print/templates/reports/balance-compensation/sql/company.sql +++ /dev/null @@ -1,8 +0,0 @@ -SELECT - s.name, - s.nif, - s.street, - s.city - FROM supplier s - JOIN receipt r ON r.companyFk = s.id - WHERE r.id = ?; \ No newline at end of file