4157-send-sms-to-routes #1106

Merged
pau merged 16 commits from 4157-send-sms-to-routes into dev 2022-11-16 08:09:29 +00:00
25 changed files with 447 additions and 18 deletions
Showing only changes of commit b1a068ea48 - Show all commits

View File

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

View File

@ -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"`];
};
};

View File

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

View File

@ -121,6 +121,19 @@
</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>
</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>

View File

@ -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',
@ -90,9 +91,13 @@ class Controller extends Section {
this.$http.patch(endpoint, params)
.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'),

View File

@ -8,4 +8,6 @@ Havings: Haber
Balance: Balance
Total by company: Total por empresa
Download PDF: Descargar PDF
Send compensation: Enviar compensación
BILL: N/FRA {{ref}}
Notify compensation: ¿Desea informar de la compensación al cliente por correo?

View File

@ -188,7 +188,7 @@ module.exports = Self => {
async function createSaleComponent(saleId, value, componentId, myOptions) {
const models = Self.app.models;
return models.SaleComponent.create({
return models.SaleComponent.upsert({
saleFk: saleId,
value: value,
componentFk: componentId

View File

@ -5,6 +5,13 @@
<vn-menu vn-id="menu">
<vn-list>
<vn-item
vn-acl="administrative"
vn-acl-action="remove"
ng-click="transferClient.show()"
translate>
Transfer client
</vn-item>
<vn-item
ng-click="addTurn.show()"
vn-acl="buyer"
@ -242,6 +249,36 @@
</tpl-buttons>
</vn-dialog>
<!-- Transfer Client popup -->
<vn-dialog
vn-id="transferClient"
title="transferClient"
size="sm"
on-accept="$ctrl.transferClient($client)">
<tpl-body>
<vn-autocomplete
vn-one
vn-id="client"
required="true"
url="Clients"
label="Client"
show-field="name"
value-field="id"
search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}"
ng-model="$ctrl.ticket.client.id"
initial-data="$ctrl.ticket.client.id"
order="id">
<tpl-item>
#{{id}} - {{::name}}
</tpl-item>
</vn-autocomplete>
</tpl-body>
<tpl-buttons>
<button response="accept" translate>Transfer client</button>
</tpl-buttons>
</vn-dialog>
<!-- Send SMS popup -->
<vn-ticket-sms
vn-id="sms"

View File

@ -95,6 +95,23 @@ class Controller extends Section {
});
}
transferClient() {
this.$http.get(`Clients/${this.ticket.client.id}`).then(client => {
const ticket = this.ticket;
const params =
{
clientFk: client.data.id,
addressFk: client.data.defaultAddressFk,
};
this.$http.patch(`Tickets/${ticket.id}`, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.reload();
});
});
}
isTicketEditable() {
if (!this.ticket) return;

View File

@ -281,4 +281,17 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
$httpBackend.flush();
});
});
describe('transferClient()', () => {
it(`should perform two queries, a get to obtain the clientData and a patch to update the ticket`, () => {
const client =
{
clientFk: 1101,
addressFk: 1,
};
$httpBackend.expect('GET', `Clients/${ticket.client.id}`).respond(client);
$httpBackend.expect('PATCH', `Tickets/${ticket.id}`).respond();
controller.transferClient();
});
});
});

View File

@ -10,3 +10,4 @@ Send PDF Delivery Note: Enviar albarán en PDF
Show Proforma: Ver proforma
Refund all: Abonar todo
The following refund ticket have been created: "Se ha creado siguiente ticket de abono: {{ticketId}}"
Transfer client: Transferir cliente

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": "balance-compensation.pdf",
"component": "balance-compensation"
}
]

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: '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
}
}
};

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

View File

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

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

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
JOIN supplier s ON c.fi = s.nif
WHERE r.id = ?

View File

@ -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 = ?;

View File

@ -81,7 +81,7 @@
</div>
</div>
<!-- Route ticket list -->
<div class="no-page-break" v-for="ticket in route.tickets">
<div v-if="route.tickets" v-for="ticket in route.tickets" class="no-page-break">
<div>
<table class="column-oriented repeatable">
<thead>