refactor changes
gitea/salix/1466-print_refactor This commit looks good
Details
gitea/salix/1466-print_refactor This commit looks good
Details
This commit is contained in:
parent
8bce163099
commit
d063bb4568
|
@ -5,8 +5,5 @@ Vue.directive('pin', {
|
||||||
el.style.position = 'fixed';
|
el.style.position = 'fixed';
|
||||||
el.style.top = binding.value + 'px';
|
el.style.top = binding.value + 'px';
|
||||||
el.style.backgroundColor = 'red';
|
el.style.backgroundColor = 'red';
|
||||||
},
|
|
||||||
update() {
|
|
||||||
console.log('asd');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ const imageSrc = {
|
||||||
getReportSrc(image) {
|
getReportSrc(image) {
|
||||||
const assetsPath = `${config.app.host}/api/assets`;
|
const assetsPath = `${config.app.host}/api/assets`;
|
||||||
const imagePath = `${assetsPath}/${this.$options.name}/images/${image}`;
|
const imagePath = `${assetsPath}/${this.$options.name}/images/${image}`;
|
||||||
console.log(imagePath);
|
|
||||||
return imagePath;
|
return imagePath;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,8 +27,6 @@ class Report extends Component {
|
||||||
if (fs.existsSync(fullPath))
|
if (fs.existsSync(fullPath))
|
||||||
options = Object.assign(options, require(optionsPath));
|
options = Object.assign(options, require(optionsPath));
|
||||||
|
|
||||||
console.log(fs.existsSync(optionsPath));
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
pdf.create(template, options).toStream((err, stream) => {
|
pdf.create(template, options).toStream((err, stream) => {
|
||||||
resolve(stream);
|
resolve(stream);
|
||||||
|
|
|
@ -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/layout.css`,
|
||||||
`${appPath}/common/css/report.css`,
|
`${appPath}/common/css/report.css`,
|
||||||
`${appPath}/common/css/misc.css`,
|
`${appPath}/common/css/misc.css`,
|
|
@ -1,9 +1,12 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html v-bind:lang="locale">
|
||||||
<body>
|
<body>
|
||||||
<section class="container">
|
<section class="container">
|
||||||
<!-- Header component -->
|
<!-- Header component -->
|
||||||
<report-header :locale="locale"></report-header>
|
<report-header
|
||||||
|
v-bind:is-preview="isPreview"
|
||||||
|
v-bind:locale="locale">
|
||||||
|
</report-header>
|
||||||
<!-- End header component -->
|
<!-- End header component -->
|
||||||
<section class="main">
|
<section class="main">
|
||||||
<section class="columns">
|
<section class="columns">
|
||||||
|
@ -14,11 +17,11 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="font gray uppercase">{{$t('clientId')}}</td>
|
<td class="font gray uppercase">{{$t('clientId')}}</td>
|
||||||
<th>{{clientId}}</th>
|
<th>{{client.id}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="font gray uppercase">{{$t('date')}}</td>
|
<td class="font gray uppercase">{{$t('dated')}}</td>
|
||||||
<th>{{dated()}}</th>
|
<th>{{dated}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -28,15 +31,15 @@
|
||||||
<section class="panel">
|
<section class="panel">
|
||||||
<section class="header">{{$t('clientData')}}</section>
|
<section class="header">{{$t('clientData')}}</section>
|
||||||
<section class="body">
|
<section class="body">
|
||||||
<h3 class="uppercase">{{clientName}}</h3>
|
<h3 class="uppercase">{{client.socialName}}</h3>
|
||||||
<section>
|
<section>
|
||||||
{{street}}
|
{{client.street}}
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
{{postcode}}, {{city}} ({{province}})
|
{{client.postcode}}, {{client.city}} ({{client.province}})
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
{{country}}
|
{{client.country}}
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
@ -55,7 +58,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="sale in sales" :key="sale.id">
|
<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>{{sale.ref}}</td>
|
||||||
<td class="number">{{sale.debtOut}}</td>
|
<td class="number">{{sale.debtOut}}</td>
|
||||||
<td class="number">{{sale.debtIn}}</td>
|
<td class="number">{{sale.debtIn}}</td>
|
||||||
|
@ -75,9 +78,10 @@
|
||||||
</section>
|
</section>
|
||||||
<!-- Footer component -->
|
<!-- Footer component -->
|
||||||
<report-footer id="pageFooter"
|
<report-footer id="pageFooter"
|
||||||
:left-text="$t('client', [clientId])"
|
v-bind:left-text="$t('client', [client.id])"
|
||||||
:center-text="clientName"
|
v-bind:center-text="client.socialName"
|
||||||
:locale="locale">
|
v-bind:is-preview="isPreview"
|
||||||
|
v-bind:locale="locale">
|
||||||
</report-footer>
|
</report-footer>
|
||||||
<!-- End footer component -->
|
<!-- End footer component -->
|
||||||
</section>
|
</section>
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -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}
|
|
@ -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'),
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -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}'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
Reference in New Issue