This commit is contained in:
parent
dfdd3a1733
commit
10a25ff590
|
@ -115,7 +115,7 @@
|
||||||
"This client is not invoiceable": "This client is not invoiceable",
|
"This client is not invoiceable": "This client is not invoiceable",
|
||||||
"INACTIVE_PROVIDER": "Inactive provider",
|
"INACTIVE_PROVIDER": "Inactive provider",
|
||||||
"reference duplicated": "reference duplicated",
|
"reference duplicated": "reference duplicated",
|
||||||
"The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option",
|
"The PDF document does not exist": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option",
|
||||||
"This item is not available": "This item is not available",
|
"This item is not available": "This item is not available",
|
||||||
"Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}",
|
"Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}",
|
||||||
"The type of business must be filled in basic data": "The type of business must be filled in basic data",
|
"The type of business must be filled in basic data": "The type of business must be filled in basic data",
|
||||||
|
|
|
@ -211,7 +211,7 @@
|
||||||
"You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito",
|
"You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito",
|
||||||
"You can't change the credit set to zero from a financialBoss": "No puedes cambiar el cŕedito establecido a cero por un jefe de finanzas",
|
"You can't change the credit set to zero from a financialBoss": "No puedes cambiar el cŕedito establecido a cero por un jefe de finanzas",
|
||||||
"Amounts do not match": "Las cantidades no coinciden",
|
"Amounts do not match": "Las cantidades no coinciden",
|
||||||
"The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'",
|
"The PDF document does not exist": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'",
|
||||||
"The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos",
|
"The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos",
|
||||||
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días",
|
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días",
|
||||||
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
|
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
|
||||||
|
@ -293,5 +293,7 @@
|
||||||
"Pass expired": "La contraseña ha caducado, cambiela desde Salix",
|
"Pass expired": "La contraseña ha caducado, cambiela desde Salix",
|
||||||
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
||||||
"Ticket does not exist": "Este ticket no existe",
|
"Ticket does not exist": "Este ticket no existe",
|
||||||
"Ticket is already signed": "Este ticket ya ha sido firmado"
|
"Ticket is already signed": "Este ticket ya ha sido firmado",
|
||||||
}
|
"Fecha fuera de rango": "Fecha fuera de rango",
|
||||||
|
"Error while generating PDF": "Error while generating PDF"
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const print = require('vn-print');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('createPdf', {
|
Self.remoteMethodCtx('createPdf', {
|
||||||
|
@ -26,9 +25,6 @@ module.exports = Self => {
|
||||||
Self.createPdf = async function(ctx, id, options) {
|
Self.createPdf = async function(ctx, id, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
if (process.env.NODE_ENV == 'test')
|
|
||||||
throw new UserError(`Action not allowed on the test environment`);
|
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
|
@ -41,40 +37,20 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invoiceOut = await Self.findById(id, null, myOptions);
|
const invoiceOut = await Self.findById(id, {fields: ['hasPdf']}, myOptions);
|
||||||
const canCreatePdf = await models.ACL.checkAccessAcl(ctx, 'InvoiceOut', 'canCreatePdf', 'WRITE');
|
|
||||||
|
|
||||||
if (invoiceOut.hasPdf && !canCreatePdf)
|
if (invoiceOut.hasPdf) {
|
||||||
throw new UserError(`You don't have enough privileges`);
|
const canCreatePdf = await models.ACL.checkAccessAcl(ctx, 'InvoiceOut', 'canCreatePdf', 'WRITE');
|
||||||
|
if (!canCreatePdf)
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
}
|
||||||
|
|
||||||
await invoiceOut.updateAttributes({
|
await Self.makePdf(id, myOptions);
|
||||||
hasPdf: true
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const invoiceReport = new print.Report('invoice', {
|
|
||||||
reference: invoiceOut.ref,
|
|
||||||
recipientId: invoiceOut.clientFk
|
|
||||||
});
|
|
||||||
const buffer = await invoiceReport.toPdfStream();
|
|
||||||
|
|
||||||
const issued = invoiceOut.issued;
|
|
||||||
const year = issued.getFullYear().toString();
|
|
||||||
const month = (issued.getMonth() + 1).toString();
|
|
||||||
const day = issued.getDate().toString();
|
|
||||||
|
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
|
||||||
|
|
||||||
// Store invoice
|
|
||||||
await print.storage.write(buffer, {
|
|
||||||
type: 'invoice',
|
|
||||||
path: `${year}/${month}/${day}`,
|
|
||||||
fileName: fileName
|
|
||||||
});
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,7 +43,9 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const invoiceOut = await models.InvoiceOut.findById(id, null, myOptions);
|
const invoiceOut = await models.InvoiceOut.findById(id, {
|
||||||
|
fields: ['ref', 'issued']
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
const issued = invoiceOut.issued;
|
const issued = invoiceOut.issued;
|
||||||
const year = issued.getFullYear().toString();
|
const year = issued.getFullYear().toString();
|
||||||
|
@ -73,7 +75,7 @@ module.exports = Self => {
|
||||||
return [stream, file.contentType, `filename="${file.name}"`];
|
return [stream, file.contentType, `filename="${file.name}"`];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT')
|
if (error.code === 'ENOENT')
|
||||||
throw new UserError('The PDF document does not exists');
|
throw new UserError('The PDF document does not exist');
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,17 +109,22 @@ module.exports = Self => {
|
||||||
], myOptions);
|
], myOptions);
|
||||||
|
|
||||||
const [newInvoice] = await Self.rawSql(`SELECT @invoiceId id`, null, myOptions);
|
const [newInvoice] = await Self.rawSql(`SELECT @invoiceId id`, null, myOptions);
|
||||||
if (newInvoice.id) {
|
if (!newInvoice)
|
||||||
await Self.rawSql('CALL invoiceOutBooking(?)', [newInvoice.id], myOptions);
|
throw new UserError('No tickets to invoice', 'notInvoiced');
|
||||||
|
|
||||||
invoiceOut = await models.InvoiceOut.findById(newInvoice.id, {
|
await Self.rawSql('CALL invoiceOutBooking(?)', [newInvoice.id], myOptions);
|
||||||
include: {
|
|
||||||
relation: 'client'
|
invoiceOut = await models.InvoiceOut.findById(newInvoice.id, {
|
||||||
|
fields: ['id', 'ref', 'clientFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
fields: ['email', 'isToBeMailed']
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
invoiceId = newInvoice.id;
|
invoiceId = newInvoice.id;
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -127,26 +132,32 @@ module.exports = Self => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invoiceId) {
|
try {
|
||||||
if (!invoiceOut.client().isToBeMailed) {
|
await Self.makePdf(invoiceId);
|
||||||
const query = `
|
} catch (err) {
|
||||||
CALL vn.report_print(
|
console.error(err);
|
||||||
'invoice',
|
throw new UserError('Error while generating PDF', 'pdfError');
|
||||||
?,
|
|
||||||
account.myUser_getId(),
|
|
||||||
JSON_OBJECT('refFk', ?),
|
|
||||||
'normal'
|
|
||||||
);`;
|
|
||||||
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref]);
|
|
||||||
} else {
|
|
||||||
ctx.args = {
|
|
||||||
reference: invoiceOut.ref,
|
|
||||||
recipientId: invoiceOut.clientFk,
|
|
||||||
recipient: invoiceOut.client().email
|
|
||||||
};
|
|
||||||
await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (invoiceOut.client().isToBeMailed) {
|
||||||
|
ctx.args = {
|
||||||
|
reference: invoiceOut.ref,
|
||||||
|
recipientId: args.clientId,
|
||||||
|
recipient: invoiceOut.client().email
|
||||||
|
};
|
||||||
|
await models.InvoiceOut.invoiceEmail(ctx, invoiceOut.ref);
|
||||||
|
} else {
|
||||||
|
const query = `
|
||||||
|
CALL vn.report_print(
|
||||||
|
'invoice',
|
||||||
|
?,
|
||||||
|
account.myUser_getId(),
|
||||||
|
JSON_OBJECT('refFk', ?),
|
||||||
|
'normal'
|
||||||
|
);`;
|
||||||
|
await models.InvoiceOut.rawSql(query, [args.printerFk, invoiceOut.ref]);
|
||||||
|
}
|
||||||
|
|
||||||
return invoiceId;
|
return invoiceId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const {Email} = require('vn-print');
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
@ -74,6 +75,10 @@ module.exports = Self => {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
return email.send(mailOptions);
|
try {
|
||||||
|
return email.send(mailOptions);
|
||||||
|
} catch(err) {
|
||||||
|
throw new UserError('Error when sending mail to client', 'mailNotSent');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const print = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/invoiceOut/filter')(Self);
|
require('../methods/invoiceOut/filter')(Self);
|
||||||
require('../methods/invoiceOut/summary')(Self);
|
require('../methods/invoiceOut/summary')(Self);
|
||||||
|
@ -19,4 +21,35 @@ module.exports = Self => {
|
||||||
require('../methods/invoiceOut/getInvoiceDate')(Self);
|
require('../methods/invoiceOut/getInvoiceDate')(Self);
|
||||||
require('../methods/invoiceOut/negativeBases')(Self);
|
require('../methods/invoiceOut/negativeBases')(Self);
|
||||||
require('../methods/invoiceOut/negativeBasesCsv')(Self);
|
require('../methods/invoiceOut/negativeBasesCsv')(Self);
|
||||||
|
|
||||||
|
Self.makePdf = async function(id, options) {
|
||||||
|
const fields = ['id', 'hasPdf', 'ref', 'issued'];
|
||||||
|
const invoiceOut = await Self.findById(id, {fields}, options);
|
||||||
|
|
||||||
|
const invoiceReport = new print.Report('invoice', {
|
||||||
|
reference: invoiceOut.ref
|
||||||
|
});
|
||||||
|
const buffer = await invoiceReport.toPdfStream();
|
||||||
|
|
||||||
|
const issued = invoiceOut.issued;
|
||||||
|
const year = issued.getFullYear().toString();
|
||||||
|
const month = (issued.getMonth() + 1).toString();
|
||||||
|
const day = issued.getDate().toString();
|
||||||
|
|
||||||
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
|
// Store invoice
|
||||||
|
|
||||||
|
await invoiceOut.updateAttributes({
|
||||||
|
hasPdf: true
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
|
await print.storage.write(buffer, {
|
||||||
|
type: 'invoice',
|
||||||
|
path: `${year}/${month}/${day}`,
|
||||||
|
fileName: fileName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,11 @@
|
||||||
{{::error.address.nickname}}
|
{{::error.address.nickname}}
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td expand>
|
<vn-td expand>
|
||||||
<span class="chip alert">{{::error.message}}</span>
|
<span
|
||||||
|
class="chip"
|
||||||
|
ng-class="error.isWarning ? 'warning': 'alert'">
|
||||||
|
{{::error.message}}
|
||||||
|
</span>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-tbody>
|
</vn-tbody>
|
||||||
|
|
|
@ -108,9 +108,18 @@ class Controller extends Section {
|
||||||
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
this.$http.post(`InvoiceOuts/invoiceClient`, params)
|
||||||
.then(() => this.invoiceNext())
|
.then(() => this.invoiceNext())
|
||||||
.catch(res => {
|
.catch(res => {
|
||||||
const message = res.data?.error?.message || res.message;
|
|
||||||
if (res.status >= 400 && res.status < 500) {
|
if (res.status >= 400 && res.status < 500) {
|
||||||
this.errors.unshift({address, message});
|
const error = res.data?.error;
|
||||||
|
let isWarning;
|
||||||
|
switch(error?.code) {
|
||||||
|
case 'pdfError':
|
||||||
|
case 'mailNotSent':
|
||||||
|
isWarning = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = error?.message || res.message;
|
||||||
|
this.errors.unshift({address, message, isWarning});
|
||||||
this.invoiceNext();
|
this.invoiceNext();
|
||||||
} else {
|
} else {
|
||||||
this.invoicing = false;
|
this.invoicing = false;
|
||||||
|
|
|
@ -46,14 +46,21 @@ module.exports = {
|
||||||
const fileNames = attachments.join(',\n');
|
const fileNames = attachments.join(',\n');
|
||||||
|
|
||||||
await db.rawSql(`
|
await db.rawSql(`
|
||||||
INSERT INTO vn.mail (receiver, replyTo, sent, subject, body, attachment, status)
|
INSERT INTO vn.mail
|
||||||
VALUES (?, ?, 1, ?, ?, ?, ?)`, [
|
SET receiver = ?,
|
||||||
|
replyTo = ?,
|
||||||
|
sent = ?,
|
||||||
|
subject = ?,
|
||||||
|
body = ?,
|
||||||
|
attachment = ?,
|
||||||
|
status = ?`, [
|
||||||
options.to,
|
options.to,
|
||||||
options.replyTo,
|
options.replyTo,
|
||||||
|
error ? 2 : 1,
|
||||||
options.subject,
|
options.subject,
|
||||||
options.text || options.html,
|
options.text || options.html,
|
||||||
fileNames,
|
fileNames,
|
||||||
error && error.message || 'Sent'
|
error && error.message || 'OK'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue