From d063bb4568517a96d0566dde02fec849f2151916 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 4 Nov 2019 08:54:21 +0100 Subject: [PATCH] refactor changes --- print/core/directives/pin.js | 3 - print/core/mixins/image-src.js | 2 +- print/core/report.js | 2 - .../assets/css/import.js} | 4 +- .../assets/css/style.css | 0 .../letter-debtor.html} | 30 +++--- .../reports/letter-debtor/letter-debtor.js | 88 +++++++++++++++++ .../reports/letter-debtor/locale/es.yml | 10 ++ .../reports/rpt-letter-debtor/index.js | 99 ------------------- .../reports/rpt-letter-debtor/locale.js | 16 --- 10 files changed, 118 insertions(+), 136 deletions(-) rename print/templates/reports/{rpt-letter-debtor/assets/css/index.js => letter-debtor/assets/css/import.js} (64%) rename print/templates/reports/{rpt-letter-debtor => letter-debtor}/assets/css/style.css (100%) rename print/templates/reports/{rpt-letter-debtor/index.html => letter-debtor/letter-debtor.html} (78%) create mode 100755 print/templates/reports/letter-debtor/letter-debtor.js create mode 100644 print/templates/reports/letter-debtor/locale/es.yml delete mode 100755 print/templates/reports/rpt-letter-debtor/index.js delete mode 100644 print/templates/reports/rpt-letter-debtor/locale.js diff --git a/print/core/directives/pin.js b/print/core/directives/pin.js index 3f276b92d..bf4bb6e6e 100644 --- a/print/core/directives/pin.js +++ b/print/core/directives/pin.js @@ -5,8 +5,5 @@ Vue.directive('pin', { el.style.position = 'fixed'; el.style.top = binding.value + 'px'; el.style.backgroundColor = 'red'; - }, - update() { - console.log('asd'); } }); diff --git a/print/core/mixins/image-src.js b/print/core/mixins/image-src.js index 89079f39d..992ebe17a 100644 --- a/print/core/mixins/image-src.js +++ b/print/core/mixins/image-src.js @@ -15,7 +15,7 @@ const imageSrc = { getReportSrc(image) { const assetsPath = `${config.app.host}/api/assets`; const imagePath = `${assetsPath}/${this.$options.name}/images/${image}`; - console.log(imagePath); + return imagePath; } }, diff --git a/print/core/report.js b/print/core/report.js index 24d89af19..db4c9f427 100644 --- a/print/core/report.js +++ b/print/core/report.js @@ -27,8 +27,6 @@ class Report extends Component { if (fs.existsSync(fullPath)) options = Object.assign(options, require(optionsPath)); - console.log(fs.existsSync(optionsPath)); - return new Promise(resolve => { pdf.create(template, options).toStream((err, stream) => { resolve(stream); diff --git a/print/templates/reports/rpt-letter-debtor/assets/css/index.js b/print/templates/reports/letter-debtor/assets/css/import.js similarity index 64% rename from print/templates/reports/rpt-letter-debtor/assets/css/index.js rename to print/templates/reports/letter-debtor/assets/css/import.js index 515dea750..a2a9334cb 100644 --- a/print/templates/reports/rpt-letter-debtor/assets/css/index.js +++ b/print/templates/reports/letter-debtor/assets/css/import.js @@ -1,6 +1,6 @@ -const CssReader = require(`${appPath}/lib/cssReader`); +const Stylesheet = require(`${appPath}/core/stylesheet`); -module.exports = new CssReader([ +module.exports = new Stylesheet([ `${appPath}/common/css/layout.css`, `${appPath}/common/css/report.css`, `${appPath}/common/css/misc.css`, diff --git a/print/templates/reports/rpt-letter-debtor/assets/css/style.css b/print/templates/reports/letter-debtor/assets/css/style.css similarity index 100% rename from print/templates/reports/rpt-letter-debtor/assets/css/style.css rename to print/templates/reports/letter-debtor/assets/css/style.css diff --git a/print/templates/reports/rpt-letter-debtor/index.html b/print/templates/reports/letter-debtor/letter-debtor.html similarity index 78% rename from print/templates/reports/rpt-letter-debtor/index.html rename to print/templates/reports/letter-debtor/letter-debtor.html index 6763bfbe7..ec91fc616 100644 --- a/print/templates/reports/rpt-letter-debtor/index.html +++ b/print/templates/reports/letter-debtor/letter-debtor.html @@ -1,9 +1,12 @@ - +
- + +
@@ -14,11 +17,11 @@ {{$t('clientId')}} - {{clientId}} + {{client.id}} - {{$t('date')}} - {{dated()}} + {{$t('dated')}} + {{dated}} @@ -28,15 +31,15 @@
{{$t('clientData')}}
-

{{clientName}}

+

{{client.socialName}}

- {{street}} + {{client.street}}
- {{postcode}}, {{city}} ({{province}}) + {{client.postcode}}, {{client.city}} ({{client.province}})
- {{country}} + {{client.country}}
@@ -55,7 +58,7 @@ - {{toISOString(sale.issued)}} + {{sale.issued | date('%d-%m-%Y')}} {{sale.ref}} {{sale.debtOut}} {{sale.debtIn}} @@ -75,9 +78,10 @@
+ v-bind:left-text="$t('client', [client.id])" + v-bind:center-text="client.socialName" + v-bind:is-preview="isPreview" + v-bind:locale="locale">
diff --git a/print/templates/reports/letter-debtor/letter-debtor.js b/print/templates/reports/letter-debtor/letter-debtor.js new file mode 100755 index 000000000..7e70c88d1 --- /dev/null +++ b/print/templates/reports/letter-debtor/letter-debtor.js @@ -0,0 +1,88 @@ +const Component = require(`${appPath}/core/component`); +const reportHeader = new Component('report-header'); +const reportFooter = new Component('report-footer'); +const db = require(`${appPath}/core/database`); + +module.exports = { + name: 'letter-debtor', + async serverPrefetch() { + this.client = await this.fetchClient(this.clientId); + this.sales = await this.fetchSales(this.clientId, 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'); + } + }, + data() { + return {totalBalance: 0.00}; + }, + methods: { + fetchClient(clientId) { + return db.findOne( + `SELECT + c.id, + c.socialName, + c.street, + c.postcode, + c.city, + c.fi, + p.name AS province, + ct.country + FROM client c + JOIN country ct ON ct.id = c.countryFk + LEFT JOIN province p ON p.id = c.provinceFk + WHERE c.id = ?`, [clientId]); + }, + fetchSales(clientId, companyId) { + return db.find( + `CALL vn.clientGetDebtDiary(?, ?)`, [clientId, companyId]).then(rows => { + return rows[0]; + }); + }, + getBalance(sale) { + if (sale.debtOut) + this.totalBalance += parseFloat(sale.debtOut); + + if (sale.debtIn) + this.totalBalance -= parseFloat(sale.debtIn); + + return parseFloat(this.totalBalance.toFixed(2)); + }, + getTotalDebtOut() { + let debtOut = 0.00; + this.sales.forEach(sale => { + debtOut += sale.debtOut ? parseFloat(sale.debtOut) : 0; + }); + + return debtOut.toFixed(2); + }, + getTotalDebtIn() { + let debtIn = 0.00; + this.sales.forEach(sale => { + debtIn += sale.debtIn ? parseFloat(sale.debtIn) : 0; + }); + + return debtIn.toFixed(2); + }, + }, + components: { + 'report-header': reportHeader.build(), + 'report-footer': reportFooter.build() + }, + props: { + clientId: { + type: String, + required: true + }, + companyId: { + type: String, + required: true + } + } +}; diff --git a/print/templates/reports/letter-debtor/locale/es.yml b/print/templates/reports/letter-debtor/locale/es.yml new file mode 100644 index 000000000..09a31ee5b --- /dev/null +++ b/print/templates/reports/letter-debtor/locale/es.yml @@ -0,0 +1,10 @@ +title: Extracto +claimId: ReclamaciĆ³n +clientId: Cliente +clientData: Datos del cliente +dated: Fecha +concept: Concepto +invoiced: Facturado +payed: Pagado +balance: Saldo +client: Cliente {0} \ No newline at end of file diff --git a/print/templates/reports/rpt-letter-debtor/index.js b/print/templates/reports/rpt-letter-debtor/index.js deleted file mode 100755 index 7fa049a9e..000000000 --- a/print/templates/reports/rpt-letter-debtor/index.js +++ /dev/null @@ -1,99 +0,0 @@ -const strftime = require('strftime'); -const database = require(`${appPath}/lib/database`); -const UserException = require(`${appPath}/lib/exceptions/userException`); - -module.exports = { - name: 'rpt-letter-debtor', - async asyncData(ctx, params) { - const promises = []; - const data = {}; - - if (!params.clientFk) - throw new UserException('No client id specified'); - - if (!params.companyFk) - throw new UserException('No company id specified'); - - promises.push(this.methods.fetchClient(params.clientFk)); - promises.push(this.methods.fetchSales(params.clientFk, params.companyFk)); - - return Promise.all(promises).then(result => { - const [[client]] = result[0]; - const [[sales]] = result[1]; - - if (!client) - throw new UserException('No client data found'); - - Object.assign(data, client, {sales}); - - return data; - }); - }, - created() { - if (this.locale) - this.$i18n.locale = this.locale; - }, - data() { - return {totalBalance: 0.00}; - }, - methods: { - fetchClient(clientFk) { - return database.pool.query( - `SELECT - c.id clientId, - u.lang locale, - c.email AS recipient, - c.socialName AS clientName, - c.street, - c.postcode, - c.city, - c.fi, - p.name AS province, - ct.country - FROM client c - JOIN account.user u ON u.id = c.id - JOIN country ct ON ct.id = c.countryFk - LEFT JOIN province p ON p.id = c.provinceFk - WHERE c.id = ?`, [clientFk]); - }, - fetchSales(clientFk, companyFk) { - return database.pool.query( - `CALL vn.clientGetDebtDiary(?, ?)`, [clientFk, companyFk]); - }, - dated: () => { - return strftime('%d-%m-%Y', new Date()); - }, - toISOString: date => { - return strftime('%d-%m-%Y', date); - }, - getBalance(sale) { - if (sale.debtOut) - this.totalBalance += parseFloat(sale.debtOut); - - if (sale.debtIn) - this.totalBalance -= parseFloat(sale.debtIn); - - return parseFloat(this.totalBalance.toFixed(2)); - }, - getTotalDebtOut() { - let debtOut = 0.00; - this.sales.forEach(sale => { - debtOut += sale.debtOut ? parseFloat(sale.debtOut) : 0; - }); - - return debtOut.toFixed(2); - }, - getTotalDebtIn() { - let debtIn = 0.00; - this.sales.forEach(sale => { - debtIn += sale.debtIn ? parseFloat(sale.debtIn) : 0; - }); - - return debtIn.toFixed(2); - }, - }, - components: { - 'report-header': require('../report-header'), - 'report-footer': require('../report-footer'), - }, -}; diff --git a/print/templates/reports/rpt-letter-debtor/locale.js b/print/templates/reports/rpt-letter-debtor/locale.js deleted file mode 100644 index 8ace81596..000000000 --- a/print/templates/reports/rpt-letter-debtor/locale.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - messages: { - es: { - title: 'Extracto', - claimId: 'ReclamaciĆ³n', - clientId: 'Cliente', - clientData: 'Datos del cliente', - date: 'Fecha', - concept: 'Concepto', - invoiced: 'Facturado', - payed: 'Pagado', - balance: 'Saldo', - client: 'Cliente {0}' - }, - }, -};