refs #4547 informe y email generados #1114

Merged
alexandre merged 6 commits from 4547-informe-compensacion into dev 2022-11-09 12:34:36 +00:00
17 changed files with 424 additions and 136 deletions
Showing only changes of commit 1246a65f32 - Show all commits

View File

@ -0,0 +1,40 @@
const {Email} = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('debBalancesCompEmail', {
Outdated
Review

Mejor balanceCompensationEmail. en general no solemos utilizar abreviaturas

Mejor balanceCompensationEmail. en general no solemos utilizar abreviaturas
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/deb-balances-comp-email',
verb: 'POST'
}
});
Self.debBalancesCompEmail = 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('deb-balances-comp', {
lang: ctx.req.getLocale(),
recipient: client.name+',administracion@verdnatura.es',
Outdated
Review

A la espera de que a javi le confirmen

A la espera de que a javi le confirmen
id
});
return email.send();
};
};

View File

@ -0,0 +1,50 @@
const { Report } = require('vn-print');
module.exports = Self => {
Self.remoteMethodCtx('debBalancesCompPdf', {
Outdated
Review

Mejor balanceCompensationPdf. en general no solemos utilizar abreviaturas

Mejor balanceCompensationPdf. en general no solemos utilizar abreviaturas
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/deb-balances-comp-pdf',
verb: 'GET'
}
});
Self.debBalancesCompPdf = 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('deb-balances-comp', params);
const stream = await report.toPdfStream();
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
};
};

View File

@ -2,6 +2,8 @@ const LoopBackContext = require('loopback-context');
module.exports = function(Self) {
require('../methods/receipt/filter')(Self);
require('../methods/receipt/debBalancesCompEmail')(Self);
require('../methods/receipt/debBalancesCompPdf')(Self);
Self.validateBinded('amountPaid', isNotZero, {
message: 'Amount cannot be zero',

View File

@ -1,40 +1,17 @@
<vn-crud-model
vn-id="model"
url="Receipts/filter"
limit="20"
data="$ctrl.balances">
<vn-crud-model vn-id="model" url="Receipts/filter" limit="20" data="$ctrl.balances">
</vn-crud-model>
<vn-crud-model
vn-id="riskModel"
url="ClientRisks"
filter="$ctrl.filter"
data="$ctrl.clientRisks">
<vn-crud-model vn-id="riskModel" url="ClientRisks" filter="$ctrl.filter" data="$ctrl.clientRisks">
</vn-crud-model>
<vn-crud-model
auto-load="true"
url="Companies"
data="companies"
order="code">
<vn-crud-model auto-load="true" url="Companies" data="companies" order="code">
</vn-crud-model>
<vn-side-menu side="right">
<div class="vn-pa-md">
<vn-autocomplete
vn-one
vn-id="company"
ng-model="$ctrl.companyId"
data="companies"
show-field="code"
value-field="id"
label="Company">
<vn-autocomplete vn-one vn-id="company" ng-model="$ctrl.companyId" data="companies" show-field="code"
value-field="id" label="Company">
</vn-autocomplete>
<div
class="totalBox"
style="text-align: center;"
ng-if="$ctrl.clientRisks.length">
<div class="totalBox" style="text-align: center;" ng-if="$ctrl.clientRisks.length">
<h6 translate>Total by company</h6>
<vn-label-value
ng-repeat="riskByCompany in $ctrl.clientRisks"
label="{{riskByCompany.company.code}}"
<vn-label-value ng-repeat="riskByCompany in $ctrl.clientRisks" label="{{riskByCompany.company.code}}"
value="{{riskByCompany.amount | currency: 'EUR':2}}">
</vn-label-value>
</div>
@ -43,108 +20,94 @@
<div class="vn-w-lg">
<vn-data-viewer model="model">
<vn-card>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th expand>Date</vn-th>
<vn-th>Creation date</vn-th>
<vn-th>Employee</vn-th>
<vn-th>Reference</vn-th>
<vn-th number>Bank</vn-th>
<vn-th number>Debit</vn-th>
<vn-th number>Havings</vn-th>
<vn-th number>Balance</vn-th>
<vn-th center>Conciliated</vn-th>
<vn-th></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="balance in $ctrl.balances">
<vn-td expand>
<span title="{{::balance.payed | date:'dd/MM/yyyy'}}">
{{::balance.payed | date:'dd/MM/yyyy'}}
</span>
</vn-td>
<vn-td shrink-datetime>
<span title="{{::balance.created | date:'dd/MM/yyyy HH:mm'}}">
{{::balance.created | date:'dd/MM/yyyy HH:mm'}}
</span>
</vn-td>
<vn-td>
<span
vn-click-stop="workerDescriptor.show($event, balance.workerFk)"
class="link">
{{::balance.userName}}
</span>
</vn-td>
<vn-td-editable disabled="balance.isInvoice || !$ctrl.isAdministrative" expand>
<text>
<div ng-show="::balance.description">
<span
ng-if="balance.isInvoice"
title="{{'BILL' | translate: {ref: balance.description} }}"
vn-click-stop="$ctrl.showInvoiceOutDescriptor($event, balance)"
class="link">
{{'BILL' | translate: {ref: balance.description} }}
</span>
<span
ng-if="!balance.isInvoice"
title="{{::balance.description}}">
{{balance.description}}
</span>
</div>
</text>
<field>
<vn-textfield vn-acl="administrative" class="dense" vn-focus
ng-model="balance.description"
on-change="$ctrl.changeDescription(balance)">
</vn-textfield>
</field>
</vn-td-editable>
<vn-td number>{{::balance.bankFk}}</vn-td>
<vn-td number expand>{{::balance.debit | currency: 'EUR':2}}</vn-td>
<vn-td number expand>{{::balance.credit | currency: 'EUR':2}}</vn-td>
<vn-td number expand>{{balance.balance | currency: 'EUR':2}}</vn-td>
<vn-td center shrink>
<vn-check
ng-model="balance.isConciliate"
disabled="true">
</vn-check>
</vn-td>
<vn-td center shrink>
<a ng-show="balance.hasPdf"
target="_blank"
href="api/InvoiceOuts/{{::balance.id}}/download?access_token={{::$ctrl.vnToken.token}}">
<vn-icon-button
icon="cloud_download"
title="{{'Download PDF' | translate}}">
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th expand>Date</vn-th>
<vn-th>Creation date</vn-th>
<vn-th>Employee</vn-th>
<vn-th>Reference</vn-th>
<vn-th number>Bank</vn-th>
<vn-th number>Debit</vn-th>
<vn-th number>Havings</vn-th>
<vn-th number>Balance</vn-th>
<vn-th center>Conciliated</vn-th>
<vn-th></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="balance in $ctrl.balances">
<vn-td expand>
<span title="{{::balance.payed | date:'dd/MM/yyyy'}}">
{{::balance.payed | date:'dd/MM/yyyy'}}
</span>
</vn-td>
<vn-td shrink-datetime>
<span title="{{::balance.created | date:'dd/MM/yyyy HH:mm'}}">
{{::balance.created | date:'dd/MM/yyyy HH:mm'}}
</span>
</vn-td>
<vn-td>
<span vn-click-stop="workerDescriptor.show($event, balance.workerFk)" class="link">
{{::balance.userName}}
</span>
</vn-td>
<vn-td-editable disabled="balance.isInvoice || !$ctrl.isAdministrative" expand>
<text>
<div ng-show="::balance.description">
<span ng-if="balance.isInvoice"
title="{{'BILL' | translate: {ref: balance.description} }}"
vn-click-stop="$ctrl.showInvoiceOutDescriptor($event, balance)" class="link">
{{'BILL' | translate: {ref: balance.description} }}
</span>
<span ng-if="!balance.isInvoice" title="{{::balance.description}}">
{{balance.description}}
</span>
</div>
</text>
<field>
<vn-textfield vn-acl="administrative" class="dense" vn-focus
ng-model="balance.description" on-change="$ctrl.changeDescription(balance)">
</vn-textfield>
</field>
</vn-td-editable>
<vn-td number>{{::balance.bankFk}}</vn-td>
<vn-td number expand>{{::balance.debit | currency: 'EUR':2}}</vn-td>
<vn-td number expand>{{::balance.credit | currency: 'EUR':2}}</vn-td>
<vn-td number expand>{{balance.balance | currency: 'EUR':2}}</vn-td>
<vn-td center shrink>
<vn-check ng-model="balance.isConciliate" disabled="true">
</vn-check>
</vn-td>
<vn-td center shrink>
<a ng-show="balance.hasPdf" target="_blank"
href="api/InvoiceOuts/{{::balance.id}}/download?access_token={{::$ctrl.vnToken.token}}">
<vn-icon-button icon="cloud_download" title="{{'Download PDF' | translate}}">
</vn-icon-button>
</a>
</vn-td>
<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>
</a>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-td>
<vn-confirm vn-id="send_compensation" on-accept="$ctrl.sendEmail(balance)"
question="¿Desea informar de la compensacion al cliente por correo?"
message="Send compensation">
</vn-confirm>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</vn-data-viewer>
</div>
<vn-float-button
vn-acl="salesAssistant"
vn-acl-action="remove"
icon="add"
vn-tooltip="New payment"
vn-bind="+"
fixed-bottom-right
ng-click="balanceCreate.show()">
<vn-float-button vn-acl="salesAssistant" vn-acl-action="remove" icon="add" vn-tooltip="New payment" vn-bind="+"
fixed-bottom-right ng-click="balanceCreate.show()">
</vn-float-button>
<vn-client-balance-create
vn-id="balance-create"
on-accept="$ctrl.getData()"
company-fk="$ctrl.companyId"
<vn-client-balance-create vn-id="balance-create" on-accept="$ctrl.getData()" company-fk="$ctrl.companyId"
client-fk="$ctrl.$params.id">
</vn-client-balance-create>
<vn-worker-descriptor-popover
vn-id="workerDescriptor">
<vn-worker-descriptor-popover vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-invoice-out-descriptor-popover
vn-id="invoiceOutDescriptor">
<vn-invoice-out-descriptor-popover vn-id="invoiceOutDescriptor">
</vn-invoice-out-descriptor-popover>

View File

@ -2,8 +2,10 @@ import ngModule from '../../module';
import Section from 'salix/components/section';
class Controller extends Section {
constructor($element, $) {
constructor($element, $, vnReport, vnEmail) {
super($element, $);
this.vnReport = vnReport;
this.vnEmail = vnEmail;
this.filter = {
include: {
relation: 'company',
@ -43,6 +45,7 @@ class Controller extends Section {
return this.aclService.hasAny(['administrative']);
}
getData() {
return this.$.model.applyFilter(null, {
clientId: this.$params.id,
@ -54,45 +57,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}/deb-balances-comp-email`);
}
}
Controller.$inject = ['$element', '$scope'];
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
ngModule.vnComponent('vnClientBalanceIndex', {
template: require('./index.html'),

View File

@ -8,4 +8,5 @@ Havings: Haber
Balance: Balance
Total by company: Total por empresa
Download PDF: Descargar PDF
Send compensation: Enviar compensación
BILL: N/FRA {{ref}}

View File

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

View File

@ -0,0 +1,6 @@
[
{
"filename": "deb-balances-comp.pdf",
Outdated
Review

Cambiar nombre

Cambiar nombre
"component": "deb-balances-comp"
}
]

View File

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

View File

@ -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: 'deb-balances-comp',
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: 'deb-balances-comp.pdf',
type: 'pdf',
path: `Receipts/${this.id}/deb-balances-comp-pdf`
}
]
};
},
props: {
id: {
type: Number,
required: true
}
}
};

View File

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

View File

@ -0,0 +1,5 @@
SELECT
c.name
FROM client c
JOIN receipt r ON r.clientFk = c.id
WHERE r.id = ?;

View File

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

View File

@ -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;">Algemesí, a {{currentDate()}}</p>
<h3 style="text-align: center; margin-top: 8%;">{{'Compensación de saldos deudores y acreedores' | uppercase}}</h3>
<p style="margin-top: 8%;">De una parte:</p>
Outdated
Review

Añadir traducciones

Añadir traducciones
<p style="text-align: justify;">Verdnatura Levante SL con CIF B-97367486 y domicilio sito en calle Fenollar 2, Valencia.</p>
Outdated
Review

Obtener información de la tabla company

Obtener información de la tabla company
<p style="margin-top: 5%;">De la otra:</p>
<p style="text-align: justify;">Don/Doña {{client.name}} con NIF {{client.fi}}, y domicilio sito en {{client.street}}, {{client.city}}.</p>
<h4 style="text-align: center;margin-top: 10%;">{{'Acuerdan' | uppercase}}</h4>
<p style="margin-top: 8%;text-align: justify;">En fecha de {{client.payed | date('%d-%m-%Y')}} se ha compensado el saldo de {{client.amountPaid}} € del cliente/proveedor {{client.name}} con el cliente/proveedor Verdnatura Levante SL.</p>
<p style="margin-top: 8%;">Por favor, rogamos confirmen la recepción de esta compensación al email <span style="color:blue">administracion@verdnatura.es</span></p>
<div style="margin-top: 8%;"><small >Saludos cordiales,</small></div>
</div>
</div>
</div>
</div>
<!-- Footer block -->
<report-footer id="pageFooter"
v-bind="$props">
</report-footer>
</td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,35 @@
const config = require(`vn-print/core/config`);
const Component = require(`vn-print/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
const md5 = require('md5');
const fs = require('fs-extra');
module.exports = {
name: 'deb-balances-comp',
async serverPrefetch() {
this.client = await this.fetchClient(this.id);
},
methods: {
fetchClient(id) {
return this.findOneFromDef('client', [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, String],
Outdated
Review

type: Number

type: Number
required: true,
description: 'The receipt id'
}
}
};

View File

@ -0,0 +1 @@
reportName: compensacion-saldo

View File

@ -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
Outdated
Review

tabular joins

tabular joins
JOIN supplier s ON c.fi = s.nif
WHERE r.id = ?;