refs #4547 informe y email generados #1114
|
@ -0,0 +1,40 @@
|
|||
const {Email} = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('balanceCompensationEmail', {
|
||||
description: 'Sends the debit balances compensation email with an attached PDF',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The receipt id',
|
||||
http: { source: 'path' }
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: '/:id/balance-compensation-email',
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.balanceCompensationEmail = async (ctx, id) => {
|
||||
|
||||
const models = Self.app.models;
|
||||
const receipt = await models.Receipt.findById(id, {fields: ['clientFk']});
|
||||
const client = await models.Client.findById(receipt.clientFk, {fields:['email']});
|
||||
|
||||
const email = new Email('balance-compensation', {
|
||||
lang: ctx.req.getLocale(),
|
||||
recipient: client.email+',administracion@verdnatura.es',
|
||||
id
|
||||
});
|
||||
|
||||
return email.send();
|
||||
};
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
const { Report } = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('balanceCompensationPdf', {
|
||||
description: 'Returns the the debit balances compensation pdf',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The receipt id',
|
||||
http: { source: 'path' }
|
||||
}
|
||||
],
|
||||
returns: [
|
||||
{
|
||||
arg: 'body',
|
||||
type: 'file',
|
||||
root: true
|
||||
}, {
|
||||
arg: 'Content-Type',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}, {
|
||||
arg: 'Content-Disposition',
|
||||
type: 'String',
|
||||
http: {target: 'header'}
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: '/:id/balance-compensation-pdf',
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.balanceCompensationPdf = async(ctx, id) => {
|
||||
const args = Object.assign({}, ctx.args);
|
||||
const params = {lang: ctx.req.getLocale()};
|
||||
|
||||
delete args.ctx;
|
||||
for (const param in args)
|
||||
params[param] = args[param];
|
||||
|
||||
const report = new Report('balance-compensation', params);
|
||||
const stream = await report.toPdfStream();
|
||||
|
||||
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||
};
|
||||
};
|
|
@ -2,6 +2,8 @@ const LoopBackContext = require('loopback-context');
|
|||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/receipt/filter')(Self);
|
||||
require('../methods/receipt/balanceCompensationEmail')(Self);
|
||||
require('../methods/receipt/balanceCompensationPdf')(Self);
|
||||
require('../methods/receipt/receiptPdf')(Self);
|
||||
|
||||
Self.validateBinded('amountPaid', isNotZero, {
|
||||
|
|
|
@ -121,9 +121,22 @@
|
|||
</vn-icon-button>
|
||||
</a>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
<vn-td center shrink ng-if="!balance.isInvoice">
|
||||
<vn-icon-button
|
||||
vn-dialog="send_compensation"
|
||||
icon="outgoing_mail"
|
||||
title="{{'Send compensation' | translate}}">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
<vn-confirm
|
||||
vn-id="send_compensation"
|
||||
on-accept="$ctrl.sendEmail(balance)"
|
||||
question="Notify compensation"
|
||||
|
||||
message="Send compensation">
|
||||
</vn-confirm>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
</vn-card>
|
||||
</vn-data-viewer>
|
||||
</div>
|
||||
|
|
|
@ -2,8 +2,9 @@ import ngModule from '../../module';
|
|||
import Section from 'salix/components/section';
|
||||
|
||||
class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
constructor($element, $, vnEmail) {
|
||||
super($element, $);
|
||||
this.vnEmail = vnEmail;
|
||||
this.filter = {
|
||||
include: {
|
||||
relation: 'company',
|
||||
|
@ -54,45 +55,49 @@ class Controller extends Section {
|
|||
}
|
||||
})).then(() => this.getBalances());
|
||||
}
|
||||
|
||||
|
||||
getCurrentBalance() {
|
||||
const clientRisks = this.$.riskModel.data;
|
||||
const selectedCompany = this.companyId;
|
||||
const currentBalance = clientRisks.find(balance => {
|
||||
return balance.companyFk === selectedCompany;
|
||||
});
|
||||
|
||||
|
||||
return currentBalance && currentBalance.amount;
|
||||
}
|
||||
|
||||
|
||||
getBalances() {
|
||||
const balances = this.$.model.data;
|
||||
balances.forEach((balance, index) => {
|
||||
if (index === 0)
|
||||
balance.balance = this.getCurrentBalance();
|
||||
balance.balance = this.getCurrentBalance();
|
||||
if (index > 0) {
|
||||
let previousBalance = balances[index - 1];
|
||||
balance.balance = previousBalance.balance - (previousBalance.debit - previousBalance.credit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
showInvoiceOutDescriptor(event, balance) {
|
||||
if (!balance.isInvoice) return;
|
||||
if (event.defaultPrevented) return;
|
||||
|
||||
|
||||
this.$.invoiceOutDescriptor.show(event.target, balance.id);
|
||||
}
|
||||
|
||||
|
||||
changeDescription(balance) {
|
||||
const params = {description: balance.description};
|
||||
const endpoint = `Receipts/${balance.id}`;
|
||||
this.$http.patch(endpoint, params)
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||
}
|
||||
|
||||
sendEmail(balance) {
|
||||
return this.vnEmail.send(`Receipts/${balance.id}/balance-compensation-email`);
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope'];
|
||||
Controller.$inject = ['$element', '$scope', 'vnEmail'];
|
||||
|
||||
ngModule.vnComponent('vnClientBalanceIndex', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -8,4 +8,6 @@ Havings: Haber
|
|||
Balance: Balance
|
||||
Total by company: Total por empresa
|
||||
Download PDF: Descargar PDF
|
||||
BILL: N/FRA {{ref}}
|
||||
Send compensation: Enviar compensación
|
||||
BILL: N/FRA {{ref}}
|
||||
Notify compensation: ¿Desea informar de la compensación al cliente por correo?
|
|
@ -0,0 +1,11 @@
|
|||
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||
|
||||
const path = require('path');
|
||||
const vnPrintPath = path.resolve('print');
|
||||
|
||||
module.exports = new Stylesheet([
|
||||
`${vnPrintPath}/common/css/spacing.css`,
|
||||
`${vnPrintPath}/common/css/misc.css`,
|
||||
`${vnPrintPath}/common/css/layout.css`,
|
||||
`${vnPrintPath}/common/css/email.css`])
|
||||
.mergeStyles();
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
{
|
||||
"filename": "balance-compensation.pdf",
|
||||
"component": "balance-compensation"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,57 @@
|
|||
<!DOCTYPE html>
|
||||
<html v-bind:lang="$i18n.locale">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<title v-html="$t('subject')"></title>
|
||||
</head>
|
||||
<body>
|
||||
<table class="grid">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<!-- Empty block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block empty"></div>
|
||||
</div>
|
||||
<!-- Header block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block">
|
||||
<email-header v-bind="$props"></email-header>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block vn-pa-ml">
|
||||
<p>{{$t('description.instructions')}} {{client.name}}</p>
|
||||
<p>{{$t('description.attached')}}</p>
|
||||
<p>{{$t('description.response')}}</p>
|
||||
<p>{{$t('description.regards')}}</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Preview block -->
|
||||
<div class="grid-row" v-if="isPreview">
|
||||
<div class="grid-block vn-pa-ml">
|
||||
<attachment v-for="attachment in attachments"
|
||||
v-bind:key="attachment.filename"
|
||||
v-bind:attachment="attachment"
|
||||
v-bind:args="$props">
|
||||
</attachment>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Footer block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block">
|
||||
<email-footer v-bind="$props"></email-footer>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Empty block -->
|
||||
<div class="grid-row">
|
||||
<div class="grid-block empty"></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,39 @@
|
|||
const Component = require(`vn-print/core/component`);
|
||||
const emailHeader = new Component('email-header');
|
||||
const emailFooter = new Component('email-footer');
|
||||
const attachment = new Component('attachment');
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'balance-compensation',
|
||||
async serverPrefetch() {
|
||||
this.client = await this.fetchClient(this.id);
|
||||
},
|
||||
methods: {
|
||||
fetchClient(id) {
|
||||
return this.findOneFromDef('client', [id]);
|
||||
},
|
||||
},
|
||||
components: {
|
||||
'email-header': emailHeader.build(),
|
||||
'email-footer': emailFooter.build(),
|
||||
'attachment': attachment.build()
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
attachments: [
|
||||
{
|
||||
filename: 'balance-compensation.pdf',
|
||||
type: 'pdf',
|
||||
path: `Receipts/${this.id}/balance-compensation-pdf`
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
subject: Compensación VerdNatura SL
|
||||
description:
|
||||
instructions: Buenos días,
|
||||
attached: Adjuntamos escrito para su confirmación
|
||||
response: Rogamos su respuesta a la mayor brevedad
|
||||
regards: Un saludo
|
|
@ -0,0 +1,5 @@
|
|||
SELECT
|
||||
c.name
|
||||
FROM client c
|
||||
JOIN receipt r ON r.clientFk = c.id
|
||||
WHERE r.id = ?;
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html v-bind:lang="$i18n.locale">
|
||||
|
||||
<body>
|
||||
<table class="grid">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<!-- Header block -->
|
||||
<report-header v-bind="$props">
|
||||
</report-header>
|
||||
<div class="grid-row">
|
||||
<div class="grid-block">
|
||||
<div class="columns">
|
||||
<div class="size50">
|
||||
<p style="text-align: right;">{{$t('Place')}} {{currentDate()}}</p>
|
||||
<h3 style="text-align: center; margin-top: 8%;">{{$t('Compensation') | uppercase}}</h3>
|
||||
<p style="margin-top: 8%;">{{$t('In one hand')}}:</p>
|
||||
<p style="text-align: justify;">{{company.name}} {{$t('CIF')}} {{company.nif}} {{$t('Home')}} {{company.street}}, {{company.city}}.</p>
|
||||
<p style="margin-top: 5%;">{{$t('In other hand')}}:</p>
|
||||
<p style="text-align: justify;">{{$t('Sr')}} {{client.name}} {{$t('NIF')}} {{client.fi}} {{$t('Home')}} {{client.street}}, {{client.city}}.</p>
|
||||
<h4 style="text-align: center;margin-top: 10%;">{{$t('Agree') | uppercase}}</h4>
|
||||
<p style="margin-top: 8%;text-align: justify;">{{$t('Date')}} {{client.payed | date('%d-%m-%Y')}} {{$t('Compensate')}} {{client.amountPaid}} € {{$t('From client')}} {{client.name}} {{$t('To client')}} {{company.name}}.</p>
|
||||
<p style="margin-top: 8%;">{{$t('Reception')}} <span style="color:blue">administracion@verdnatura.es</span></p>
|
||||
<div style="margin-top: 8%;"><small >{{$t('Greetings')}}</small></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- Footer block -->
|
||||
<report-footer id="pageFooter"
|
||||
v-bind="$props">
|
||||
</report-footer>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,36 @@
|
|||
const Component = require(`vn-print/core/component`);
|
||||
const reportHeader = new Component('report-header');
|
||||
const reportFooter = new Component('report-footer');
|
||||
|
||||
module.exports = {
|
||||
name: 'balance-compensation',
|
||||
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-header': reportHeader.build(),
|
||||
'report-footer': reportFooter.build()
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
type: Number,
|
||||
required: true,
|
||||
description: 'The receipt id'
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||
|
||||
const path = require('path');
|
||||
const vnPrintPath = path.resolve('print');
|
||||
|
||||
module.exports = new Stylesheet([
|
||||
`${vnPrintPath}/common/css/spacing.css`,
|
||||
`${vnPrintPath}/common/css/misc.css`,
|
||||
`${vnPrintPath}/common/css/layout.css`,
|
||||
`${vnPrintPath}/common/css/report.css`,
|
||||
`${__dirname}/style.css`])
|
||||
.mergeStyles();
|
|
@ -0,0 +1,16 @@
|
|||
reportName: compensacion-saldo
|
||||
Place: Algemesí, a
|
||||
Compensation: Compensación de saldos deudores y acreedores
|
||||
In one hand: De una parte
|
||||
CIF: con CIF
|
||||
NIF: con NIF
|
||||
Home: y domicilio sito en
|
||||
In other hand: De la otra
|
||||
Sr: Don/Doña
|
||||
Agree: Acuerdan
|
||||
Date: En fecha de
|
||||
Compensate: se ha compensado el saldo de
|
||||
From client: del cliente/proveedor
|
||||
To client: con el cliente/proveedor
|
||||
Reception: Por favor, rogamos confirmen la recepción de esta compensación al email
|
||||
Greetings: Saludos cordiales,
|
|
@ -0,0 +1,12 @@
|
|||
SELECT
|
||||
c.name,
|
||||
c.socialName,
|
||||
c.street,
|
||||
c.fi,
|
||||
c.city,
|
||||
r.amountPaid,
|
||||
r.payed
|
||||
FROM client c
|
||||
JOIN receipt r ON r.clientFk = c.id
|
||||
JOIN supplier s ON c.fi = s.nif
|
||||
WHERE r.id = ?
|
|
@ -0,0 +1,8 @@
|
|||
SELECT
|
||||
s.name,
|
||||
s.nif,
|
||||
s.street,
|
||||
s.city
|
||||
FROM supplier s
|
||||
JOIN receipt r ON r.companyFk = s.id
|
||||
WHERE r.id = ?;
|
Loading…
Reference in New Issue
Falta una traducción aquí. No pueden haber frases en español en el código.