salix/modules/client/back/methods/receipt/balanceCompensationEmail.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-10-28 12:49:22 +00:00
const {Email} = require('vn-print');
module.exports = Self => {
2022-11-02 14:54:23 +00:00
Self.remoteMethodCtx('balanceCompensationEmail', {
2022-10-28 12:49:22 +00:00
description: 'Sends the debit balances compensation email with an attached PDF',
accessType: 'WRITE',
accepts: [
{
arg: 'id',
2022-11-02 14:54:23 +00:00
type: 'Number',
2022-10-28 12:49:22 +00:00
required: true,
description: 'The receipt id',
http: { source: 'path' }
}
],
returns: {
type: ['object'],
root: true
},
http: {
2022-11-02 14:54:23 +00:00
path: '/:id/balance-compensation-email',
2022-10-28 12:49:22 +00:00
verb: 'POST'
}
});
2022-11-02 14:54:23 +00:00
Self.balanceCompensationEmail = async (ctx, id) => {
2022-10-28 12:49:22 +00:00
const models = Self.app.models;
const receipt = await models.Receipt.findById(id, {fields: ['clientFk']});
const client = await models.Client.findById(receipt.clientFk, {fields:['email']});
2022-11-02 14:54:23 +00:00
const email = new Email('balance-compensation', {
2022-10-28 12:49:22 +00:00
lang: ctx.req.getLocale(),
2022-11-02 14:54:23 +00:00
recipient: client.email+',administracion@verdnatura.es',
2022-10-28 12:49:22 +00:00
id
});
return email.send();
};
};