From 885a98457e954a75af86083399006392e6fd4672 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 17 Feb 2023 09:11:20 +0100 Subject: [PATCH 1/5] feat: sustido sql por loopback del report 'balance-compensation' --- modules/client/back/models/receipt.json | 7 +++++- .../balance-compensation.html | 12 +++++----- .../balance-compensation.js | 22 ++++++++++++++++--- .../balance-compensation/sql/client.sql | 11 ---------- .../balance-compensation/sql/company.sql | 8 ------- 5 files changed, 31 insertions(+), 29 deletions(-) delete mode 100644 print/templates/reports/balance-compensation/sql/client.sql delete mode 100644 print/templates/reports/balance-compensation/sql/company.sql 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 From 19fcf5d53600643b4bb4c9db4bd36f24c0bd568b Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 10 Mar 2023 07:46:36 +0100 Subject: [PATCH 2/5] feat: add column 'description' --- .../reports/balance-compensation/balance-compensation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/balance-compensation/balance-compensation.js b/print/templates/reports/balance-compensation/balance-compensation.js index 7b7a1053e..f9fd594db 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.js +++ b/print/templates/reports/balance-compensation/balance-compensation.js @@ -6,7 +6,7 @@ module.exports = { mixins: [vnReport], async serverPrefetch() { this.receipt = await app.models.Receipt.findOne({ - fields: ['amountPaid', 'payed', 'clientFk', 'companyFk'], + fields: ['amountPaid', 'payed', 'clientFk', 'companyFk', 'description'], include: [ { relation: 'client', From 1ef454681c9a8a8e2abb70c72a13ec41cf7c4868 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 10 Mar 2023 12:51:25 +0100 Subject: [PATCH 3/5] fix: faltaba this delante de formateDate --- print/templates/reports/extra-community/extra-community.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js index 9941faa35..8f93fdc13 100755 --- a/print/templates/reports/extra-community/extra-community.js +++ b/print/templates/reports/extra-community/extra-community.js @@ -38,11 +38,11 @@ module.exports = { computed: { landedEnd: function() { if (!this.landedTo) return; - return formatDate(this.landedTo, '%Y-%m-%d'); + return this.formatDate(this.landedTo, '%Y-%m-%d'); }, shippedStart: function() { if (!this.shippedFrom) return; - return formatDate(this.shippedFrom, '%Y-%m-%d'); + return this.formatDate(this.shippedFrom, '%Y-%m-%d'); } }, methods: { From da5886243eb803fb9459921723577874d225a1d7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Mar 2023 10:22:34 +0100 Subject: [PATCH 4/5] refs #5120 refactor: no utilizar receipt directamente --- .../balance-compensation/balance-compensation.html | 10 +++++----- .../balance-compensation/balance-compensation.js | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/print/templates/reports/balance-compensation/balance-compensation.html b/print/templates/reports/balance-compensation/balance-compensation.html index 4b100b1af..c7448eeb9 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')}}:

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

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

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

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

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

{{$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 f9fd594db..228cb77d1 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.js +++ b/print/templates/reports/balance-compensation/balance-compensation.js @@ -22,6 +22,10 @@ module.exports = { ], where: {id: this.id} }); + console.log(this.receipt); + this.client = this.receipt.client(); + this.company = this.receipt.supplier(); + this.checkMainEntity(this.receipt); }, props: { From 286bc541b6ec5d722642894fd1d66f0f45297e08 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 15 Mar 2023 11:27:01 +0100 Subject: [PATCH 5/5] refs #5120 delete console.log --- .../reports/balance-compensation/balance-compensation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/print/templates/reports/balance-compensation/balance-compensation.js b/print/templates/reports/balance-compensation/balance-compensation.js index 228cb77d1..c2c2e9288 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.js +++ b/print/templates/reports/balance-compensation/balance-compensation.js @@ -22,7 +22,6 @@ module.exports = { ], where: {id: this.id} }); - console.log(this.receipt); this.client = this.receipt.client(); this.company = this.receipt.supplier();