41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
|
const {Email} = require('vn-print');
|
||
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('debBalancesCompEmail', {
|
||
|
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',
|
||
|
id
|
||
|
});
|
||
|
|
||
|
return email.send();
|
||
|
};
|
||
|
};
|