refactor changes
gitea/salix/1466-print_refactor This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-11-04 08:54:21 +01:00
parent 8bce163099
commit d063bb4568
10 changed files with 118 additions and 136 deletions

View File

@ -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');
}
});

View File

@ -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;
}
},

View File

@ -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);

View File

@ -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`,

View File

@ -1,9 +1,12 @@
<!DOCTYPE html>
<html lang="es">
<html v-bind:lang="locale">
<body>
<section class="container">
<!-- Header component -->
<report-header :locale="locale"></report-header>
<report-header
v-bind:is-preview="isPreview"
v-bind:locale="locale">
</report-header>
<!-- End header component -->
<section class="main">
<section class="columns">
@ -14,11 +17,11 @@
<tbody>
<tr>
<td class="font gray uppercase">{{$t('clientId')}}</td>
<th>{{clientId}}</th>
<th>{{client.id}}</th>
</tr>
<tr>
<td class="font gray uppercase">{{$t('date')}}</td>
<th>{{dated()}}</th>
<td class="font gray uppercase">{{$t('dated')}}</td>
<th>{{dated}}</th>
</tr>
</tbody>
</table>
@ -28,15 +31,15 @@
<section class="panel">
<section class="header">{{$t('clientData')}}</section>
<section class="body">
<h3 class="uppercase">{{clientName}}</h3>
<h3 class="uppercase">{{client.socialName}}</h3>
<section>
{{street}}
{{client.street}}
</section>
<section>
{{postcode}}, {{city}} ({{province}})
{{client.postcode}}, {{client.city}} ({{client.province}})
</section>
<section>
{{country}}
{{client.country}}
</section>
</section>
</section>
@ -55,7 +58,7 @@
</thead>
<tbody>
<tr v-for="sale in sales" :key="sale.id">
<td>{{toISOString(sale.issued)}}</td>
<td>{{sale.issued | date('%d-%m-%Y')}}</td>
<td>{{sale.ref}}</td>
<td class="number">{{sale.debtOut}}</td>
<td class="number">{{sale.debtIn}}</td>
@ -75,9 +78,10 @@
</section>
<!-- Footer component -->
<report-footer id="pageFooter"
:left-text="$t('client', [clientId])"
:center-text="clientName"
:locale="locale">
v-bind:left-text="$t('client', [client.id])"
v-bind:center-text="client.socialName"
v-bind:is-preview="isPreview"
v-bind:locale="locale">
</report-footer>
<!-- End footer component -->
</section>

View File

@ -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
}
}
};

View File

@ -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}

View File

@ -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'),
},
};

View File

@ -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}'
},
},
};