From 3a2fc984dd6f6ab905b4344196461ba5191ceb45 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 26 Oct 2022 15:18:14 +0200 Subject: [PATCH 01/10] refs #4564 --- print/core/report.js | 54 ++++++++++--------- .../claim-pickup-order/claim-pickup-order.js | 2 + 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/print/core/report.js b/print/core/report.js index c5182d1a8..d37b79c6d 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -23,39 +23,43 @@ class Report extends Component { } async toPdfStream() { - const template = await this.render(); - const defaultOptions = Object.assign({}, config.pdf); + try { + const template = await this.render(); + const defaultOptions = Object.assign({}, config.pdf); - const optionsPath = `${this.path}/options.json`; - const fullPath = path.resolve(__dirname, optionsPath); - let options = defaultOptions; - if (fs.existsSync(fullPath)) - options = require(optionsPath); + const optionsPath = `${this.path}/options.json`; + const fullPath = path.resolve(__dirname, optionsPath); + let options = defaultOptions; + if (fs.existsSync(fullPath)) + options = require(optionsPath); - return new Promise(resolve => { - Cluster.pool.queue({}, async({page}) => { - await page.emulateMediaType('screen'); - await page.setContent(template); + return new Promise(resolve => { + Cluster.pool.queue({}, async({page}) => { + await page.emulateMediaType('screen'); + await page.setContent(template); - const element = await page.$('#pageFooter'); + const element = await page.$('#pageFooter'); - let footer = '\n'; - if (element) { - footer = await page.evaluate(el => { - const html = el.innerHTML; - el.remove(); - return html; - }, element); - } + let footer = '\n'; + if (element) { + footer = await page.evaluate(el => { + const html = el.innerHTML; + el.remove(); + return html; + }, element); + } - options.headerTemplate = '\n'; - options.footerTemplate = footer; + options.headerTemplate = '\n'; + options.footerTemplate = footer; - const stream = await page.pdf(options); + const stream = await page.pdf(options); - resolve(stream); + resolve(stream); + }); }); - }); + } catch (e) { + console.log('ERROR CATCHED:', e); + } } /** diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index f7d21a2d3..2982379db 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -5,6 +5,8 @@ const reportFooter = new Component('report-footer'); module.exports = { name: 'claim-pickup-order', async serverPrefetch() { + // FORCE FAIL FOR TEST + throw new Error('Something went wrong'); this.client = await this.fetchClient(this.id); this.sales = await this.fetchSales(this.id); this.claimConfig = await this.fetchClaimConfig(); From 91e27d76be6caadc75982049b240b8d2a408c1d0 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 20 Jan 2023 07:44:04 +0100 Subject: [PATCH 02/10] Updated version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9633751a0..bd9dfe017 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "9.0.0", + "version": "230203", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From b1be6addd12cbe5d1eb6db09a49b38e73b43f91a Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 20 Jan 2023 12:16:06 +0100 Subject: [PATCH 03/10] fix: delete unnecessary code --- .../methods/sale-tracking/listSaleTracking.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/modules/ticket/back/methods/sale-tracking/listSaleTracking.js b/modules/ticket/back/methods/sale-tracking/listSaleTracking.js index c0d63ef62..653703596 100644 --- a/modules/ticket/back/methods/sale-tracking/listSaleTracking.js +++ b/modules/ticket/back/methods/sale-tracking/listSaleTracking.js @@ -48,24 +48,6 @@ module.exports = Self => { const trackings = await Self.rawStmt(stmt, myOptions); - const salesFilter = { - include: [ - { - relation: 'item' - } - ], - where: {ticketFk: filter.where.ticketFk} - }; - - const sales = await Self.app.models.Sale.find(salesFilter, myOptions); - - for (const tracking of trackings) { - for (const sale of sales) { - if (tracking.itemFk == sale.itemFk) - tracking.item = sale.item(); - } - } - return trackings; }; }; From ab1a9389cb8b06d4f37b21838202370397721ed8 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 20 Jan 2023 12:37:41 +0100 Subject: [PATCH 04/10] fix: cambiados de donde coge el item id --- modules/ticket/front/sale-tracking/index.html | 28 ++++++++----------- modules/ticket/front/sale-tracking/index.js | 4 +-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 851817551..86f81c75c 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -30,12 +30,12 @@ - - {{::sale.itemFk | zeroFill:6}} + {{::sale.item.id}} - +
{{::sale.item.name}} @@ -96,27 +96,23 @@ - - {{::sale.quantity}} - {{::sale.originalQuantity}} + + {{::saleTracking.quantity}} + {{::saleTracking.originalQuantity}} - {{::sale.userNickname | dashIfEmpty}} + ng-click="itemDescriptor.show($event, sale.item.id)" + class="link"> + {{::sale.item.id}} - {{::sale.state}} - {{::sale.created | date: 'dd/MM/yyyy HH:mm'}} + {{::saleTracking.state}} + {{::saleTracking.created | date: 'dd/MM/yyyy HH:mm'}} - - diff --git a/modules/ticket/front/sale-tracking/index.js b/modules/ticket/front/sale-tracking/index.js index 60e42a461..d1c80f30f 100644 --- a/modules/ticket/front/sale-tracking/index.js +++ b/modules/ticket/front/sale-tracking/index.js @@ -45,14 +45,14 @@ class Controller extends Section { btnThree: { icon: 'icon-transaction', state: `item.card.diary({ - id: ${sale.itemFk}, + id: ${sale.item.id}, warehouseFk: ${this.ticket.warehouseFk}, lineFk: ${sale.id} })`, tooltip: 'Item diary' } }; - this.$.itemDescriptor.show(event.target, sale.itemFk); + this.$.itemDescriptor.show(event.target, sale.item.id); } chipHasSaleGroupDetail(hasSaleGroupDetail) { From 9523991b04c9628dd7e64f98f2c106ca3dc17bb2 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 20 Jan 2023 12:45:02 +0100 Subject: [PATCH 05/10] fix: mostrar descriptor worker en vez de item --- .../ticket/back/methods/sale-tracking/listSaleTracking.js | 2 +- modules/ticket/front/sale-tracking/index.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/sale-tracking/listSaleTracking.js b/modules/ticket/back/methods/sale-tracking/listSaleTracking.js index 653703596..98743d8cc 100644 --- a/modules/ticket/back/methods/sale-tracking/listSaleTracking.js +++ b/modules/ticket/back/methods/sale-tracking/listSaleTracking.js @@ -36,7 +36,7 @@ module.exports = Self => { st.originalQuantity, st.created, st.workerFk, - u.nickname userNickname, + u.name, ste.name AS state FROM saleTracking st JOIN sale s ON s.id = st.saleFk diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index 86f81c75c..c21eaa46a 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -101,9 +101,9 @@ {{::saleTracking.originalQuantity}} - {{::sale.item.id}} + class="link" + ng-click="workerDescriptor.show($event, saleTracking.workerFk)"> + {{::saleTracking.name | dashIfEmpty}} {{::saleTracking.state}} From 6b6f27c2f234f933ec98b370416a9ebca454040e Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 23 Jan 2023 08:44:58 +0100 Subject: [PATCH 06/10] fix: typo --- front/salix/components/reset-password/locale/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/salix/components/reset-password/locale/es.yml b/front/salix/components/reset-password/locale/es.yml index 0771d5dc3..30893a152 100644 --- a/front/salix/components/reset-password/locale/es.yml +++ b/front/salix/components/reset-password/locale/es.yml @@ -1,6 +1,6 @@ Reset password: Restrablecer contraseña New password: Nueva contraseña -Repeat password: Repetir contraseñaç +Repeat password: Repetir contraseña Password changed!: ¡Contraseña cambiada! Password requirements: > La contraseña debe tener al menos {{ length }} caracteres de longitud, From 96becec9d3450c847184c091b8a10ea84eaaa9ea Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 23 Jan 2023 10:12:34 +0100 Subject: [PATCH 07/10] refs #4564 mixin vn-report created --- loopback/util/not-found-error.js | 9 ++++++ print/core/mixins/vn-report.js | 22 +++++++++++++ print/core/report.js | 54 +++++++++++++++----------------- 3 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 loopback/util/not-found-error.js create mode 100644 print/core/mixins/vn-report.js diff --git a/loopback/util/not-found-error.js b/loopback/util/not-found-error.js new file mode 100644 index 000000000..7a05254f9 --- /dev/null +++ b/loopback/util/not-found-error.js @@ -0,0 +1,9 @@ +module.exports = class NotFoundError extends Error { + constructor(message = 'Not found', code = 'NOT_FOUND', ...translateArgs) { + super(message); + this.name = 'NotFoundError'; + this.statusCode = 404; + this.code = code; + this.translateArgs = translateArgs; + } +}; diff --git a/print/core/mixins/vn-report.js b/print/core/mixins/vn-report.js new file mode 100644 index 000000000..66b9704e7 --- /dev/null +++ b/print/core/mixins/vn-report.js @@ -0,0 +1,22 @@ +const Component = require(`vn-print/core/component`); +const reportHeader = new Component('report-header'); +const reportFooter = new Component('report-footer'); +const reportBody = new Component('report-body'); +const NotFoundError = require('vn-loopback/util/not-found-error'); + +module.exports = { + components: { + 'report-body': reportBody.build(), + 'report-header': reportHeader.build(), + 'report-footer': reportFooter.build() + }, + methods: { + checkMainEntity: function(entity) { + if (entity == null) + throw new NotFoundError(); + }, + dated: function(filters, date, format) { + return filters.date(date, format); + } + }, +}; diff --git a/print/core/report.js b/print/core/report.js index d37b79c6d..c5182d1a8 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -23,43 +23,39 @@ class Report extends Component { } async toPdfStream() { - try { - const template = await this.render(); - const defaultOptions = Object.assign({}, config.pdf); + const template = await this.render(); + const defaultOptions = Object.assign({}, config.pdf); - const optionsPath = `${this.path}/options.json`; - const fullPath = path.resolve(__dirname, optionsPath); - let options = defaultOptions; - if (fs.existsSync(fullPath)) - options = require(optionsPath); + const optionsPath = `${this.path}/options.json`; + const fullPath = path.resolve(__dirname, optionsPath); + let options = defaultOptions; + if (fs.existsSync(fullPath)) + options = require(optionsPath); - return new Promise(resolve => { - Cluster.pool.queue({}, async({page}) => { - await page.emulateMediaType('screen'); - await page.setContent(template); + return new Promise(resolve => { + Cluster.pool.queue({}, async({page}) => { + await page.emulateMediaType('screen'); + await page.setContent(template); - const element = await page.$('#pageFooter'); + const element = await page.$('#pageFooter'); - let footer = '\n'; - if (element) { - footer = await page.evaluate(el => { - const html = el.innerHTML; - el.remove(); - return html; - }, element); - } + let footer = '\n'; + if (element) { + footer = await page.evaluate(el => { + const html = el.innerHTML; + el.remove(); + return html; + }, element); + } - options.headerTemplate = '\n'; - options.footerTemplate = footer; + options.headerTemplate = '\n'; + options.footerTemplate = footer; - const stream = await page.pdf(options); + const stream = await page.pdf(options); - resolve(stream); - }); + resolve(stream); }); - } catch (e) { - console.log('ERROR CATCHED:', e); - } + }); } /** From 765e4ed3328047a433fbbac188659694c10c5755 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 23 Jan 2023 13:15:30 +0100 Subject: [PATCH 08/10] refs #4564 all reports refactored --- print/core/mixins/vn-report.js | 3 +- .../balance-compensation.html | 4 +- .../balance-compensation.js | 26 ++------- .../campaign-metrics/campaign-metrics.html | 4 +- .../campaign-metrics/campaign-metrics.js | 25 ++------- .../claim-pickup-order.html | 2 +- .../claim-pickup-order/claim-pickup-order.js | 36 ++---------- .../client-debt-statement.html | 4 +- .../client-debt-statement.js | 42 ++------------ .../collection-label/collection-label.js | 11 +--- .../credit-request/credit-request.html | 2 +- .../reports/credit-request/credit-request.js | 19 +------ .../reports/delivery-note/delivery-note.html | 4 +- .../reports/delivery-note/delivery-note.js | 56 ++++--------------- .../reports/driver-route/driver-route.html | 4 +- .../reports/driver-route/driver-route.js | 24 ++------ .../reports/entry-order/entry-order.html | 2 +- .../reports/entry-order/entry-order.js | 30 ++-------- .../expedition-pallet-label.js | 11 +--- .../reports/exportation/exportation.html | 4 +- .../reports/exportation/exportation.js | 28 ++-------- .../extra-community/extra-community.html | 4 +- .../extra-community/extra-community.js | 41 ++++---------- .../incoterms-authorization.js | 17 +----- .../invoice-incoterms/invoice-incoterms.html | 2 +- .../invoice-incoterms/invoice-incoterms.js | 33 ++--------- print/templates/reports/invoice/invoice.html | 6 +- print/templates/reports/invoice/invoice.js | 53 ++++-------------- .../reports/invoiceIn/invoiceIn.html | 4 +- .../templates/reports/invoiceIn/invoiceIn.js | 37 +++--------- .../reports/item-label/item-label.html | 2 +- .../reports/item-label/item-label.js | 21 ++----- .../reports/letter-debtor/letter-debtor.html | 4 +- .../reports/letter-debtor/letter-debtor.js | 33 ++--------- .../reports/previa-label/previa-label.js | 22 ++------ print/templates/reports/receipt/receipt.js | 25 ++------- .../reports/sepa-core/sepa-core.html | 2 +- .../templates/reports/sepa-core/sepa-core.js | 46 ++------------- .../supplier-campaign-metrics.html | 6 +- .../supplier-campaign-metrics.js | 29 ++-------- .../vehicle-event-expired.html | 2 +- .../vehicle-event-expired.js | 19 ++----- print/templates/reports/zone/zone.html | 2 +- print/templates/reports/zone/zone.js | 18 ++---- 44 files changed, 169 insertions(+), 600 deletions(-) diff --git a/print/core/mixins/vn-report.js b/print/core/mixins/vn-report.js index 66b9704e7..4831d8cd9 100644 --- a/print/core/mixins/vn-report.js +++ b/print/core/mixins/vn-report.js @@ -15,7 +15,8 @@ module.exports = { if (entity == null) throw new NotFoundError(); }, - dated: function(filters, date, format) { + formatDate: function(date, format) { + const filters = this.$options.filters; return filters.date(date, format); } }, diff --git a/print/templates/reports/balance-compensation/balance-compensation.html b/print/templates/reports/balance-compensation/balance-compensation.html index 59af1bd11..1e9aa5661 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.html +++ b/print/templates/reports/balance-compensation/balance-compensation.html @@ -3,7 +3,7 @@
-

{{$t('Place')}} {{currentDate()}}

+

{{$t('Place')}} {{formatDate(new Date(), '%d-%m-%Y')}}

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

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

@@ -17,7 +17,7 @@

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

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

diff --git a/print/templates/reports/balance-compensation/balance-compensation.js b/print/templates/reports/balance-compensation/balance-compensation.js index 98a9cf577..bae7c5c3c 100644 --- a/print/templates/reports/balance-compensation/balance-compensation.js +++ b/print/templates/reports/balance-compensation/balance-compensation.js @@ -1,28 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'balance-compensation', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.company = await this.fetchCompany(this.id); - }, - methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchCompany(id) { - return this.findOneFromDef('company', [id]); - }, - - currentDate() { - const current = new Date(); - const date = `${current.getDate()}/${current.getMonth() + 1}/${current.getFullYear()}`; - return date; - } - }, - components: { - 'report-body': reportBody.build() + this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); + this.company = await this.findOneFromDef('company', [this.id]); }, props: { id: { diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.html b/print/templates/reports/campaign-metrics/campaign-metrics.html index e86d4cd3b..57d616a29 100644 --- a/print/templates/reports/campaign-metrics/campaign-metrics.html +++ b/print/templates/reports/campaign-metrics/campaign-metrics.html @@ -13,11 +13,11 @@ {{$t('From')}} - {{from | date('%d-%m-%Y')}} + {{formatDate(from, '%d-%m-%Y')}} {{$t('To')}} - {{to | date('%d-%m-%Y')}} + {{formatDate(to, '%d-%m-%Y')}} diff --git a/print/templates/reports/campaign-metrics/campaign-metrics.js b/print/templates/reports/campaign-metrics/campaign-metrics.js index 14a4b6a9b..45bca88dc 100755 --- a/print/templates/reports/campaign-metrics/campaign-metrics.js +++ b/print/templates/reports/campaign-metrics/campaign-metrics.js @@ -1,27 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'campaign-metrics', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.sales = await this.fetchSales(this.id, this.from, this.to); - - if (!this.client) - throw new Error('Something went wrong'); - }, - methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchSales(id, from, to) { - return this.rawSqlFromDef('sales', [id, from, to]); - }, - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() + this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); + this.sales = await this.rawSqlFromDef('sales', [this.id, this.from, this.to]); }, props: { id: { diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.html b/print/templates/reports/claim-pickup-order/claim-pickup-order.html index b14f5410c..000568ef2 100644 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.html +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.html @@ -20,7 +20,7 @@ {{$t('date')}} - {{dated}} + {{formatDate(new Date(), '%d-%m-%Y')}} diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index fc82ee518..cc5cec1ea 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -1,36 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'claim-pickup-order', + mixins: [vnReport], async serverPrefetch() { - // FORCE FAIL FOR TEST - throw new Error('Something went wrong'); - this.client = await this.fetchClient(this.id); - this.sales = await this.fetchSales(this.id); - - if (!this.client) - throw new Error('Something went wrong'); - }, - computed: { - dated: function() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%d-%m-%Y'); - } - }, - methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchSales(id) { - return this.rawSqlFromDef('sales', [id]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() + this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); + this.sales = await this.rawSqlFromDef('sales', [this.id]); }, props: { id: { @@ -38,5 +14,5 @@ module.exports = { required: true, description: 'The claim id' } - } + }, }; diff --git a/print/templates/reports/client-debt-statement/client-debt-statement.html b/print/templates/reports/client-debt-statement/client-debt-statement.html index 962af021d..fb7bfd625 100644 --- a/print/templates/reports/client-debt-statement/client-debt-statement.html +++ b/print/templates/reports/client-debt-statement/client-debt-statement.html @@ -13,7 +13,7 @@ {{$t('date')}} - {{dated}} + {{formatDate(new Date(), '%d-%m-%Y');}} @@ -44,7 +44,7 @@ - {{sale.issued | date('%d-%m-%Y')}} + {{formatDate(sale.issued, '%d-%m-%Y');}} {{sale.ref}} {{sale.debtOut}} {{sale.debtIn}} diff --git a/print/templates/reports/client-debt-statement/client-debt-statement.js b/print/templates/reports/client-debt-statement/client-debt-statement.js index 45b97518f..a74595200 100755 --- a/print/templates/reports/client-debt-statement/client-debt-statement.js +++ b/print/templates/reports/client-debt-statement/client-debt-statement.js @@ -1,44 +1,18 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'client-debt-statement', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.sales = await this.fetchSales(this.id, this.from); - - if (!this.client) - throw new Error('Something went wrong'); - }, - computed: { - dated: function() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%d-%m-%Y'); - } + this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); + this.sales = await this.rawSqlFromDef('sales', + [this.from, this.id, this.from, this.id, this.from, this.id, this.from, this.id, this.from, this.id]); }, data() { return {totalBalance: 0.00}; }, methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchSales(id, from) { - return this.rawSqlFromDef('sales', [ - from, - id, - from, - id, - from, - id, - from, - id, - from, - id - ]); - }, getBalance(sale) { if (sale.debtOut) this.totalBalance += parseFloat(sale.debtOut); @@ -63,10 +37,6 @@ module.exports = { return debtIn.toFixed(2); }, }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() - }, props: { id: { type: Number, diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js index e73afaeea..74024bb56 100644 --- a/print/templates/reports/collection-label/collection-label.js +++ b/print/templates/reports/collection-label/collection-label.js @@ -1,11 +1,10 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); const jsBarcode = require('jsbarcode'); const {DOMImplementation, XMLSerializer} = require('xmldom'); -const UserError = require('vn-loopback/util/user-error'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'collection-label', + mixins: [vnReport], props: { id: { type: Number, @@ -30,8 +29,7 @@ module.exports = { ticketIds = [this.id]; this.labelsData = await this.rawSqlFromDef('labelsData', [ticketIds]); - if (!this.labelsData.length) - throw new UserError('Empty data source'); + this.checkMainEntity(this.labelsData); }, methods: { getBarcode(id) { @@ -62,7 +60,4 @@ module.exports = { return value; }, }, - components: { - 'report-body': reportBody.build() - }, }; diff --git a/print/templates/reports/credit-request/credit-request.html b/print/templates/reports/credit-request/credit-request.html index d5e336809..c8e3f8c34 100644 --- a/print/templates/reports/credit-request/credit-request.html +++ b/print/templates/reports/credit-request/credit-request.html @@ -159,6 +159,6 @@

diff --git a/print/templates/reports/credit-request/credit-request.js b/print/templates/reports/credit-request/credit-request.js index c1aa74e1b..75e0b2263 100755 --- a/print/templates/reports/credit-request/credit-request.js +++ b/print/templates/reports/credit-request/credit-request.js @@ -1,20 +1,7 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body') -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); -const rptCreditRequest = { +module.exports = { name: 'credit-request', - computed: { - dated: function() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%d-%m-%Y'); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() - } + mixins: [vnReport], }; -module.exports = rptCreditRequest; diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 06653c949..9f217ba22 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -20,7 +20,7 @@ {{$t('date')}} - {{ticket.shipped | date('%d-%m-%Y')}} + {{formatDate(ticket.shipped, '%d-%m-%Y')}} {{$t('packages')}} @@ -231,7 +231,7 @@
{{$t('digitalSignature')}}
-
{{signature.created | date('%d-%m-%Y')}}
+
{{formatDate(signature.created, '%d-%m-%Y')}}
diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index 1a1a57c59..d9544a58c 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -1,25 +1,21 @@ const config = require(`vn-print/core/config`); -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); const md5 = require('md5'); const fs = require('fs-extra'); module.exports = { name: 'delivery-note', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.ticket = await this.fetchTicket(this.id); - this.sales = await this.fetchSales(this.id); - this.address = await this.fetchAddress(this.id); - this.services = await this.fetchServices(this.id); - this.taxes = await this.fetchTaxes(this.id); - this.packagings = await this.fetchPackagings(this.id); - this.signature = await this.fetchSignature(this.id); - - if (!this.ticket) - throw new Error('Something went wrong'); + this.ticket = await this.findOneFromDef('ticket', [this.id]); + this.checkMainEntity(this.ticket); + this.client = await this.findOneFromDef('client', [this.id]); + this.sales = await this.rawSqlFromDef('sales', [this.id]); + this.address = await this.findOneFromDef(`address`, [this.id]); + this.services = await this.rawSqlFromDef('services', [this.id]); + this.taxes = await this.rawSqlFromDef('taxes', [this.id]); + this.packagings = await this.rawSqlFromDef('packagings', [this.id]); + this.signature = await this.findOneFromDef('signature', [this.id]); }, data() { return {totalBalance: 0.00}; @@ -61,31 +57,6 @@ module.exports = { } }, methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchTicket(id) { - return this.findOneFromDef('ticket', [id]); - }, - fetchAddress(id) { - return this.findOneFromDef(`address`, [id]); - }, - fetchSignature(id) { - return this.findOneFromDef('signature', [id]); - }, - fetchTaxes(id) { - return this.findOneFromDef(`taxes`, [id]); - }, - fetchSales(id) { - return this.rawSqlFromDef('sales', [id]); - }, - fetchPackagings(id) { - return this.rawSqlFromDef('packagings', [id]); - }, - fetchServices(id) { - return this.rawSqlFromDef('services', [id]); - }, - getSubTotal() { let subTotal = 0.00; this.sales.forEach(sale => { @@ -125,11 +96,6 @@ module.exports = { ).join(', '); } }, - components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build(), - 'report-footer': reportFooter.build() - }, props: { id: { type: Number, diff --git a/print/templates/reports/driver-route/driver-route.html b/print/templates/reports/driver-route/driver-route.html index 48489de6f..1475b8e77 100644 --- a/print/templates/reports/driver-route/driver-route.html +++ b/print/templates/reports/driver-route/driver-route.html @@ -16,13 +16,13 @@ {{$t('date')}} - {{route.created | date('%d-%m-%Y')}} + {{formatDate(route.created, '%d-%m-%Y')}} {{$t('vehicle')}} {{route.vehicleTradeMark}} {{route.vehicleModel}} {{$t('time')}} - {{route.time | date('%H:%M')}} + {{formatDate(route.time, '%H:%M')}} {{route.plateNumber}} diff --git a/print/templates/reports/driver-route/driver-route.js b/print/templates/reports/driver-route/driver-route.js index 1b2e8871a..c166e3809 100755 --- a/print/templates/reports/driver-route/driver-route.js +++ b/print/templates/reports/driver-route/driver-route.js @@ -1,9 +1,8 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'driver-route', + mixins: [vnReport], async serverPrefetch() { let ids = this.id; @@ -11,8 +10,8 @@ module.exports = { if (hasMultipleRoutes) ids = this.id.split(','); - const routes = await this.fetchRoutes(ids); - const tickets = await this.fetchTickets(ids); + const routes = await this.rawSqlFromDef('routes', [ids]); + const tickets = await this.rawSqlFromDef('tickets', [ids, ids]); const map = new Map(); @@ -27,20 +26,7 @@ module.exports = { this.routes = routes; - if (!this.routes) - throw new Error('Something went wrong'); - }, - methods: { - fetchRoutes(ids) { - return this.rawSqlFromDef('routes', [ids]); - }, - fetchTickets(ids) { - return this.rawSqlFromDef('tickets', [ids, ids]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() + this.checkMainEntity(this.routes); }, props: { id: { diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index 26294787b..5d362dea9 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -16,7 +16,7 @@ {{$t('date')}} - {{entry.landed | date('%d-%m-%Y')}} + {{formatDate(entry.landed,'%d-%m-%Y')}} {{$t('ref')}} diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js index 22c5b55fe..d31ad1a36 100755 --- a/print/templates/reports/entry-order/entry-order.js +++ b/print/templates/reports/entry-order/entry-order.js @@ -1,31 +1,18 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'entry-order', + mixins: [vnReport], async serverPrefetch() { - this.supplier = await this.fetchSupplier(this.id); - this.entry = await this.fetchEntry(this.id); - this.buys = await this.fetchBuys(this.id); - - if (!this.entry) - throw new Error('Something went wrong'); + this.entry = await this.findOneFromDef('entry', [this.id]); + this.checkMainEntity(this.entry); + this.supplier = await this.findOneFromDef('supplier', [this.id]); + this.buys = await this.rawSqlFromDef('buys', [this.id]); }, data() { return {totalBalance: 0.00}; }, methods: { - fetchSupplier(id) { - return this.findOneFromDef('supplier', [id]); - }, - fetchEntry(id) { - return this.findOneFromDef('entry', [id]); - }, - fetchBuys(id) { - return this.rawSqlFromDef('buys', [id]); - }, getTotal() { let total = 0.00; this.buys.forEach(buy => { @@ -35,11 +22,6 @@ module.exports = { return total; } }, - components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build(), - 'report-footer': reportFooter.build() - }, props: { id: { type: Number, diff --git a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js index 0e8c297e8..321862671 100644 --- a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js +++ b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js @@ -1,12 +1,11 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); +const vnReport = require('../../../core/mixins/vn-report.js'); const jsBarcode = require('jsbarcode'); const {DOMImplementation, XMLSerializer} = require('xmldom'); -const UserError = require('vn-loopback/util/user-error'); const qrcode = require('qrcode'); module.exports = { name: 'expedition-pallet-label', + mixins: [vnReport], props: { id: { type: Number, @@ -33,8 +32,7 @@ module.exports = { }); this.QR = await this.getQR(QRdata); - if (!this.labelsData.length) - throw new UserError('Empty data source'); + this.checkMainEntity(this.labelsData); }, methods: { getQR(id) { @@ -56,7 +54,4 @@ module.exports = { return xmlSerializer.serializeToString(svgNode); }, }, - components: { - 'report-body': reportBody.build() - }, }; diff --git a/print/templates/reports/exportation/exportation.html b/print/templates/reports/exportation/exportation.html index 920e32a48..0800c024d 100644 --- a/print/templates/reports/exportation/exportation.html +++ b/print/templates/reports/exportation/exportation.html @@ -3,7 +3,7 @@

{{$t('title')}}

{{$t('toAttention')}}

-

+

  • @@ -32,4 +32,4 @@ - \ No newline at end of file + diff --git a/print/templates/reports/exportation/exportation.js b/print/templates/reports/exportation/exportation.js index 9f39aa1a1..123b350ee 100755 --- a/print/templates/reports/exportation/exportation.js +++ b/print/templates/reports/exportation/exportation.js @@ -1,33 +1,13 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'exportation', + mixins: [vnReport], async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.reference); - - if (!this.invoice) - throw new Error('Something went wrong'); - + this.invoice = await this.findOneFromDef('invoice', [this.reference]); + this.checkMainEntity(this.invoice); this.company = await this.findOneFromDef('company', [this.invoice.companyFk]); }, - methods: { - fetchInvoice(reference) { - return this.findOneFromDef('invoice', [reference]); - } - }, - computed: { - issued: function() { - const filters = this.$options.filters; - - return filters.date(this.invoice.issued, '%d-%m-%Y'); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() - }, props: { reference: { type: Number, diff --git a/print/templates/reports/extra-community/extra-community.html b/print/templates/reports/extra-community/extra-community.html index 6a46cc689..cd61a4f4d 100644 --- a/print/templates/reports/extra-community/extra-community.html +++ b/print/templates/reports/extra-community/extra-community.html @@ -26,7 +26,7 @@ {{$t('shipped')}} - {{travel.shipped | date('%d-%m-%Y')}} + {{formatDate(travel.shipped, '%d-%m-%Y')}} {{$t('physicalKg')}} {{travel.loadedKg | number($i18n.locale)}} @@ -62,6 +62,6 @@
diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js index 4dfe6e278..9941faa35 100755 --- a/print/templates/reports/extra-community/extra-community.js +++ b/print/templates/reports/extra-community/extra-community.js @@ -1,12 +1,10 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); const db = require(`vn-print/core/database`); module.exports = { name: 'extra-community', + mixins: [vnReport], async serverPrefetch() { - this.filters = this.$options.filters; const args = { landedTo: this.landedEnd, shippedFrom: this.shippedStart, @@ -21,8 +19,9 @@ module.exports = { }; const travels = await this.fetchTravels(args); + this.checkMainEntity(travels); const travelIds = travels.map(travel => travel.id); - const entries = await this.fetchEntries(travelIds); + const entries = await this.rawSqlFromDef('entries', [travelIds]); const map = new Map(); for (let travel of travels) @@ -35,23 +34,15 @@ module.exports = { } this.travels = travels; - - if (!this.travels) - throw new Error('Something went wrong'); }, computed: { - dated: function() { - return this.filters.date(new Date(), '%d-%m-%Y'); - }, landedEnd: function() { if (!this.landedTo) return; - - return this.filters.date(this.landedTo, '%Y-%m-%d'); + return formatDate(this.landedTo, '%Y-%m-%d'); }, shippedStart: function() { if (!this.shippedFrom) return; - - return this.filters.date(this.shippedFrom, '%Y-%m-%d'); + return formatDate(this.shippedFrom, '%Y-%m-%d'); } }, methods: { @@ -83,25 +74,17 @@ module.exports = { query = db.merge(query, where); query = db.merge(query, 'GROUP BY t.id'); query = db.merge(query, ` - ORDER BY - shipped ASC, - landed ASC, - travelFk, - loadPriority, - agencyModeFk, + ORDER BY + shipped ASC, + landed ASC, + travelFk, + loadPriority, + agencyModeFk, evaNotes `); return this.rawSql(query); }, - - fetchEntries(travelIds) { - return this.rawSqlFromDef('entries', [travelIds]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() }, props: [ 'landedTo', diff --git a/print/templates/reports/incoterms-authorization/incoterms-authorization.js b/print/templates/reports/incoterms-authorization/incoterms-authorization.js index bfe675985..53425487e 100755 --- a/print/templates/reports/incoterms-authorization/incoterms-authorization.js +++ b/print/templates/reports/incoterms-authorization/incoterms-authorization.js @@ -1,23 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'incoterms-authorization', + mixins: [vnReport], async serverPrefetch() { this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); this.company = await this.findOneFromDef('company', [this.companyId]); - if (!this.client) - throw new Error('Something went wrong'); - }, - computed: { - issued: function() { - return new Date(); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() }, props: { id: { diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.html b/print/templates/reports/invoice-incoterms/invoice-incoterms.html index 20c9ad440..1915828ba 100644 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.html +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.html @@ -20,7 +20,7 @@ {{$t('date')}} - {{invoice.issued | date('%d-%m-%Y')}} + {{formatDate(invoice.issued, '%d-%m-%Y')}} diff --git a/print/templates/reports/invoice-incoterms/invoice-incoterms.js b/print/templates/reports/invoice-incoterms/invoice-incoterms.js index 3afc50376..fcaffe5de 100755 --- a/print/templates/reports/invoice-incoterms/invoice-incoterms.js +++ b/print/templates/reports/invoice-incoterms/invoice-incoterms.js @@ -1,34 +1,13 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'invoice-incoterms', + mixins: [vnReport], async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.reference); - this.client = await this.fetchClient(this.reference); - this.incoterms = await this.fetchIncoterms(this.reference); - - if (!this.invoice) - throw new Error('Something went wrong'); - }, - computed: { - - }, - methods: { - fetchInvoice(reference) { - return this.findOneFromDef('invoice', [reference]); - }, - fetchClient(reference) { - return this.findOneFromDef('client', [reference]); - }, - fetchIncoterms(reference) { - return this.findOneFromDef('incoterms', [reference, reference, reference]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build() + this.invoice = await this.findOneFromDef('invoice', [this.reference]); + this.checkMainEntity(this.invoice); + this.client = await this.findOneFromDef('client', [this.reference]); + this.incoterms = await this.findOneFromDef('incoterms', [this.reference, this.reference, this.reference]); }, props: { reference: { diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index d23bba1e9..60d06d528 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -21,7 +21,7 @@ {{$t('date')}} - {{invoice.issued | date('%d-%m-%Y')}} + {{formatDate(invoice.issued, '%d-%m-%Y')}} @@ -53,7 +53,7 @@ {{row.ref}} - {{row.issued | date}} + {{formatDate(row.issued, '%d-%m-%Y')}} {{row.amount | currency('EUR', $i18n.locale)}} {{row.description}} @@ -75,7 +75,7 @@
- {{ticket.shipped | date}} + {{formatDate(ticket.shipped, '%d-%m-%Y')}}
diff --git a/print/templates/reports/invoice/invoice.js b/print/templates/reports/invoice/invoice.js index f7011ad81..7b572d970 100755 --- a/print/templates/reports/invoice/invoice.js +++ b/print/templates/reports/invoice/invoice.js @@ -1,22 +1,21 @@ -const Component = require(`vn-print/core/component`); const Report = require(`vn-print/core/report`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); const invoiceIncoterms = new Report('invoice-incoterms'); module.exports = { name: 'invoice', + mixins: [vnReport], async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.reference); - this.client = await this.fetchClient(this.reference); - this.taxes = await this.fetchTaxes(this.reference); - this.intrastat = await this.fetchIntrastat(this.reference); - this.rectified = await this.fetchRectified(this.reference); - this.hasIncoterms = await this.fetchHasIncoterms(this.reference); + this.invoice = await this.findOneFromDef('invoice', [this.reference]); + this.checkMainEntity(this.invoice); + this.client = await this.findOneFromDef('client', [this.reference]); + this.taxes = await this.rawSqlFromDef(`taxes`, [this.reference]); + this.intrastat = await this.rawSqlFromDef(`intrastat`, [this.reference, this.reference, this.reference]); + this.rectified = await this.rawSqlFromDef(`rectified`, [this.reference]); + this.hasIncoterms = await this.findValueFromDef(`hasIncoterms`, [this.reference]); - const tickets = await this.fetchTickets(this.reference); - const sales = await this.fetchSales(this.reference); + const tickets = await this.rawSqlFromDef('tickets', [this.reference]); + const sales = await this.rawSqlFromDef('sales', [this.reference, this.reference]); const map = new Map(); @@ -33,9 +32,6 @@ module.exports = { } this.tickets = tickets; - - if (!this.invoice) - throw new Error('Something went wrong'); }, data() { return {totalBalance: 0.00}; @@ -66,30 +62,6 @@ module.exports = { } }, methods: { - fetchInvoice(reference) { - return this.findOneFromDef('invoice', [reference]); - }, - fetchClient(reference) { - return this.findOneFromDef('client', [reference]); - }, - fetchTickets(reference) { - return this.rawSqlFromDef('tickets', [reference]); - }, - fetchSales(reference) { - return this.rawSqlFromDef('sales', [reference, reference]); - }, - fetchTaxes(reference) { - return this.rawSqlFromDef(`taxes`, [reference]); - }, - fetchIntrastat(reference) { - return this.rawSqlFromDef(`intrastat`, [reference, reference, reference]); - }, - fetchRectified(reference) { - return this.rawSqlFromDef(`rectified`, [reference]); - }, - fetchHasIncoterms(reference) { - return this.findValueFromDef(`hasIncoterms`, [reference]); - }, saleImport(sale) { const price = sale.quantity * sale.price; @@ -111,9 +83,6 @@ module.exports = { } }, components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build(), - 'report-footer': reportFooter.build(), 'invoice-incoterms': invoiceIncoterms.build() }, props: { diff --git a/print/templates/reports/invoiceIn/invoiceIn.html b/print/templates/reports/invoiceIn/invoiceIn.html index f101f7408..22988b654 100644 --- a/print/templates/reports/invoiceIn/invoiceIn.html +++ b/print/templates/reports/invoiceIn/invoiceIn.html @@ -19,7 +19,7 @@ {{$t('date')}} - {{invoice.created | date('%d-%m-%Y')}} + {{formatDate(invoice.created, '%d-%m-%Y')}} @@ -54,7 +54,7 @@
- {{entry.landed | date}} + {{formatDate(entry.landed, '%d-%m-%Y')}}
diff --git a/print/templates/reports/invoiceIn/invoiceIn.js b/print/templates/reports/invoiceIn/invoiceIn.js index 03549c276..c59f4da7d 100755 --- a/print/templates/reports/invoiceIn/invoiceIn.js +++ b/print/templates/reports/invoiceIn/invoiceIn.js @@ -1,15 +1,14 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'invoiceIn', + mixins: [vnReport], async serverPrefetch() { - this.invoice = await this.fetchInvoice(this.id); + this.invoice = await this.findOneFromDef('invoice', [this.id]); + this.checkMainEntity(this.invoice); this.taxes = await this.fetchTaxes(this.id); - let defaultTax = await this.fetchDefaultTax(); + let defaultTax = await this.findOneFromDef('defaultTax'); if (defaultTax) { defaultTax = Object.assign(defaultTax, { @@ -19,11 +18,8 @@ module.exports = { this.taxes.push(defaultTax); } - if (!this.invoice) - throw new Error('Something went wrong'); - - const entries = await this.fetchEntry(this.id); - const buys = await this.fetchBuy(this.id); + const entries = await this.rawSqlFromDef('entry', [this.id]); + const buys = await this.rawSqlFromDef('buy', [this.id]); const map = new Map(); @@ -41,21 +37,7 @@ module.exports = { this.entries = entries; }, - computed: { - }, methods: { - fetchInvoice(id) { - return this.findOneFromDef('invoice', [id]); - }, - fetchEntry(id) { - return this.rawSqlFromDef('entry', [id]); - }, - fetchBuy(id) { - return this.rawSqlFromDef('buy', [id]); - }, - fetchDefaultTax() { - return this.findOneFromDef('defaultTax'); - }, async fetchTaxes(id) { const taxes = await this.rawSqlFromDef(`taxes`, [id]); return this.taxVat(taxes); @@ -95,11 +77,6 @@ module.exports = { return base + vat; } }, - components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build(), - 'report-footer': reportFooter.build(), - }, props: { id: { type: Number, diff --git a/print/templates/reports/item-label/item-label.html b/print/templates/reports/item-label/item-label.html index 49593f7dd..66509ab38 100644 --- a/print/templates/reports/item-label/item-label.html +++ b/print/templates/reports/item-label/item-label.html @@ -16,7 +16,7 @@
{{packing()}}
-
{{dated}}
+
{{formatDate(new Date(), '%W/%d')}}
{{labelPage}}
{{item.size}}
diff --git a/print/templates/reports/item-label/item-label.js b/print/templates/reports/item-label/item-label.js index 6341bd11a..c5b9cdfd7 100755 --- a/print/templates/reports/item-label/item-label.js +++ b/print/templates/reports/item-label/item-label.js @@ -1,24 +1,17 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); +const vnReport = require('../../../core/mixins/vn-report.js'); const qrcode = require('qrcode'); module.exports = { name: 'item-label', + mixins: [vnReport], async serverPrefetch() { - this.item = await this.fetchItem(this.id, this.warehouseId); + this.item = await this.findOneFromDef('item', [this.id, this.warehouseId]); + this.checkMainEntity(this.item); this.tags = await this.fetchItemTags(this.id); this.barcode = await this.getBarcodeBase64(this.id); - - if (!this.item) - throw new Error('Something went wrong'); }, computed: { - dated() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%W/%d'); - }, labelPage() { const labelNumber = this.labelNumber ? this.labelNumber : 1; const totalLabels = this.totalLabels ? this.totalLabels : 1; @@ -27,9 +20,6 @@ module.exports = { } }, methods: { - fetchItem(id, warehouseId) { - return this.findOneFromDef('item', [id, warehouseId]); - }, fetchItemTags(id) { return this.rawSqlFromDef('itemTags', [id]).then(rows => { const tags = {}; @@ -48,9 +38,6 @@ module.exports = { return `${this.item.packing}x${stems}`; } }, - components: { - 'report-body': reportBody.build() - }, props: { id: { type: Number, diff --git a/print/templates/reports/letter-debtor/letter-debtor.html b/print/templates/reports/letter-debtor/letter-debtor.html index 962af021d..30fbbe003 100644 --- a/print/templates/reports/letter-debtor/letter-debtor.html +++ b/print/templates/reports/letter-debtor/letter-debtor.html @@ -13,7 +13,7 @@ {{$t('date')}} - {{dated}} + {{formatDate(new Date(), '%d-%m-%Y')}} @@ -44,7 +44,7 @@ - {{sale.issued | date('%d-%m-%Y')}} + {{formatDate(sale.issued, '%d-%m-%Y')}} {{sale.ref}} {{sale.debtOut}} {{sale.debtIn}} diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js index 749fde4ed..4446b13ae 100755 --- a/print/templates/reports/letter-debtor/letter-debtor.js +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -1,36 +1,17 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'letter-debtor', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.sales = await this.fetchSales(this.id, this.companyId); - - if (!this.client) - throw new Error('Something went wrong'); - }, - computed: { - dated: function() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%d-%m-%Y'); - } + this.client = await this.findOneFromDef('client', [this.id]); + this.checkMainEntity(this.client); + this.sales = await this.findOneFromDef('sales', [this.id, this.companyId]); }, data() { return {totalBalance: 0.00}; }, methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchSales(id, companyId) { - return this.findOneFromDef('sales', [ - id, - companyId - ]); - }, getBalance(sale) { if (sale.debtOut) this.totalBalance += parseFloat(sale.debtOut); @@ -57,10 +38,6 @@ module.exports = { return debtIn.toFixed(2); }, }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() - }, props: { id: { type: Number, diff --git a/print/templates/reports/previa-label/previa-label.js b/print/templates/reports/previa-label/previa-label.js index 7ad5ea961..833a15499 100755 --- a/print/templates/reports/previa-label/previa-label.js +++ b/print/templates/reports/previa-label/previa-label.js @@ -1,36 +1,24 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); +const vnReport = require('../../../core/mixins/vn-report.js'); const qrcode = require('qrcode'); -const UserError = require('vn-loopback/util/user-error'); module.exports = { name: 'previa-label', + mixins: [vnReport], async serverPrefetch() { - this.previa = await this.fetchPrevia(this.id); - this.sector = await this.fetchSector(this.id); + this.sector = await this.findOneFromDef('sector', [this.id]); + this.checkMainEntity(this.sector); + this.previa = await this.findOneFromDef('previa', [this.id]); this.barcode = await this.getBarcodeBase64(this.id); if (this.previa) this.previa = this.previa[0]; - - if (!this.sector) - throw new UserError('Something went wrong - no sector found'); }, methods: { - fetchPrevia(id) { - return this.findOneFromDef('previa', [id]); - }, getBarcodeBase64(id) { const data = String(id); return qrcode.toDataURL(data, {margin: 0}); }, - fetchSector(id) { - return this.findOneFromDef('sector', [id]); - } - }, - components: { - 'report-body': reportBody.build() }, props: { id: { diff --git a/print/templates/reports/receipt/receipt.js b/print/templates/reports/receipt/receipt.js index 9a9ccd452..89a431adf 100755 --- a/print/templates/reports/receipt/receipt.js +++ b/print/templates/reports/receipt/receipt.js @@ -1,27 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'receipt', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id); - this.receipt = await this.fetchReceipt(this.id); - - if (!this.receipt) - throw new Error('Something went wrong'); - }, - methods: { - fetchClient(id) { - return this.findOneFromDef('client', [id]); - }, - fetchReceipt(id) { - return this.findOneFromDef('receipt', [id]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() + this.receipt = await this.findOneFromDef('receipt', [this.id]); + this.checkMainEntity(this.receipt); + this.client = await this.findOneFromDef('client', [this.id]); }, props: { id: { diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index f2326e43c..a8c270ad5 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -147,7 +147,7 @@ {{$t('client.signLocation')}} - {{dated}}, {{client.province}} + {{formatDate(new Date(), '%d-%m-%Y')}}, {{client.province}} {{$t('client.sign')}} diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index ee8a64842..0e19d2a6a 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -1,44 +1,12 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportHeader = new Component('report-header'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); -const rptSepaCore = { +module.exports = { name: 'sepa-core', + mixins: [vnReport], async serverPrefetch() { - this.client = await this.fetchClient(this.id, this.companyId); - this.supplier = await this.fetchSupplier(this.id, this.companyId); - - if (!this.client) - throw new Error('Something went wrong'); - }, - computed: { - dated: function() { - const filters = this.$options.filters; - - return filters.date(new Date(), '%d-%m-%Y'); - } - }, - methods: { - fetchClient(id, companyId) { - return this.findOneFromDef('client', [ - companyId, - companyId, - id - ]); - }, - fetchSupplier(id, companyId) { - return this.findOneFromDef('supplier', [ - companyId, - companyId, - id - ]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-header': reportHeader.build(), - 'report-footer': reportFooter.build() + this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); + this.checkMainEntity(this.client); + this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); }, props: { id: { @@ -52,5 +20,3 @@ const rptSepaCore = { } } }; - -module.exports = rptSepaCore; diff --git a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html index baff51bfe..08b27d0bd 100644 --- a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html +++ b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.html @@ -13,11 +13,11 @@ {{$t('From')}} - {{from | date('%d-%m-%Y')}} + {{formatDate(from, '%d-%m-%Y')}} {{$t('To')}} - {{to | date('%d-%m-%Y')}} + {{formatDate(to, '%d-%m-%Y')}} @@ -38,7 +38,7 @@

{{$t('entry')}} {{entry.id}} - {{$t('dated')}} {{entry.shipped | date('%d-%m-%Y')}} + {{$t('dated')}} {{formatDate(entry.shipped, '%d-%m-%Y')}} {{$t('reference')}} {{entry.reference}}

diff --git a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js index f6fb4bd4e..32a7e9b0a 100755 --- a/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js +++ b/print/templates/reports/supplier-campaign-metrics/supplier-campaign-metrics.js @@ -1,19 +1,19 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); -const reportFooter = new Component('report-footer'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'supplier-campaign-metrics', + mixins: [vnReport], async serverPrefetch() { - this.supplier = await this.fetchSupplier(this.id); - let entries = await this.fetchEntries(this.id, this.from, this.to); + this.supplier = await this.findOneFromDef('supplier', [this.id]); + this.checkMainEntity(this.supplier); + let entries = await this.rawSqlFromDef('entries', [this.id, this.from, this.to]); const entriesId = []; for (let entry of entries) entriesId.push(entry.id); - const buys = await this.fetchBuys(entriesId); + const buys = await this.rawSqlFromDef('buys', [entriesId]); const entriesMap = new Map(); for (let entry of entries) @@ -29,23 +29,6 @@ module.exports = { } this.entries = entries; - if (!this.supplier) - throw new Error('Something went wrong'); - }, - methods: { - fetchSupplier(supplierId) { - return this.findOneFromDef('supplier', [supplierId]); - }, - fetchEntries(supplierId, from, to) { - return this.rawSqlFromDef('entries', [supplierId, from, to]); - }, - fetchBuys(entriesId) { - return this.rawSqlFromDef('buys', [entriesId]); - } - }, - components: { - 'report-body': reportBody.build(), - 'report-footer': reportFooter.build() }, props: { id: { diff --git a/print/templates/reports/vehicle-event-expired/vehicle-event-expired.html b/print/templates/reports/vehicle-event-expired/vehicle-event-expired.html index 65776851d..7435f272d 100644 --- a/print/templates/reports/vehicle-event-expired/vehicle-event-expired.html +++ b/print/templates/reports/vehicle-event-expired/vehicle-event-expired.html @@ -16,7 +16,7 @@ - +
{{vehicleEvent.numberPlate}} {{vehicleEvent.description}}{{vehicleEvent.finished | date('%d-%m-%Y')}}{{formatDate(vehicleEvent.finished, '%d-%m-%Y')}}
diff --git a/print/templates/reports/vehicle-event-expired/vehicle-event-expired.js b/print/templates/reports/vehicle-event-expired/vehicle-event-expired.js index ab6cffc00..b49e770a5 100755 --- a/print/templates/reports/vehicle-event-expired/vehicle-event-expired.js +++ b/print/templates/reports/vehicle-event-expired/vehicle-event-expired.js @@ -1,21 +1,10 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); - +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'vehicle-event-expired', + mixins: [vnReport], async serverPrefetch() { - this.vehicleEvents = await this.fetchVehicleEvent(this.eventIds); - - if (!this.vehicleEvents) - throw new Error('Something went wrong'); - }, - methods: { - fetchVehicleEvent(vehicleEventIds) { - return this.rawSqlFromDef('vehicleEvents', [vehicleEventIds]); - }, - }, - components: { - 'report-body': reportBody.build() + this.vehicleEvents = await this.rawSqlFromDef('vehicleEvents', [this.eventIds]); + this.checkMainEntity(this.vehicleEvents); }, props: { eventIds: { diff --git a/print/templates/reports/zone/zone.html b/print/templates/reports/zone/zone.html index 54c55e168..fe42fb2ad 100644 --- a/print/templates/reports/zone/zone.html +++ b/print/templates/reports/zone/zone.html @@ -1,5 +1,5 @@
{{zone.agencyName}}
{{zone.id}}
-
{{zone.plateNumber}} {{zone.time | date('%H:%M')}}
+
{{zone.plateNumber}} {{formatDate(zone.time, '%H:%M')}}
diff --git a/print/templates/reports/zone/zone.js b/print/templates/reports/zone/zone.js index 720542cd6..5baa41b8e 100755 --- a/print/templates/reports/zone/zone.js +++ b/print/templates/reports/zone/zone.js @@ -1,21 +1,11 @@ -const Component = require(`vn-print/core/component`); -const reportBody = new Component('report-body'); +const vnReport = require('../../../core/mixins/vn-report.js'); module.exports = { name: 'zone', + mixins: [vnReport], async serverPrefetch() { - this.zone = await this.fetchZone(this.id); - - if (!this.zone) - throw new Error('Something went wrong'); - }, - methods: { - fetchZone(id) { - return this.findOneFromDef('zone', [id]); - } - }, - components: { - 'report-body': reportBody.build() + this.zone = await this.findOneFromDef('zone', [this.id]); + this.checkMainEntity(this.zone); }, props: { id: { From ca7154bff1f8f32432ef8992b2ba7df97e86e437 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 24 Jan 2023 12:16:10 +0100 Subject: [PATCH 09/10] hotfix itemName --- modules/order/front/catalog/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 5fdd2e238..c0777ebc9 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -157,7 +157,7 @@ class Controller extends Section { * Apply order to model */ applyOrder() { - if (this.typeId || this.tagGroups.length > 0) + if (this.typeId || this.tagGroups.length > 0 || this.itemName) this.$.model.addFilter(null, {orderBy: this.getOrderBy()}); } From 3ed04211fd82d788e018994abeccf12238d4c407 Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 26 Jan 2023 13:05:12 +0100 Subject: [PATCH 10/10] Updated package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2031da475..46b7d4ffc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.02.03", + "version": "23.04.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0",