Merge pull request 'feat(closure): should mail the PDF invoice invoiceable clients' (#754) from 3211-closure_invoicing into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #754 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
a6dbf2c43c
|
@ -485,7 +485,8 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF
|
||||||
VALUES
|
VALUES
|
||||||
('A', 'Global nacional', 1, 'NATIONAL', 0),
|
('A', 'Global nacional', 1, 'NATIONAL', 0),
|
||||||
('T', 'Española rapida', 1, 'NATIONAL', 0),
|
('T', 'Española rapida', 1, 'NATIONAL', 0),
|
||||||
('V', 'Intracomunitaria global', 0, 'CEE', 1);
|
('V', 'Intracomunitaria global', 0, 'CEE', 1),
|
||||||
|
('M', 'Múltiple nacional', 1, 'NATIONAL', 0);
|
||||||
|
|
||||||
INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`)
|
INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -190,8 +190,7 @@ module.exports = app => {
|
||||||
try {
|
try {
|
||||||
await db.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id]);
|
await db.rawSql(`CALL vn.ticket_closeByTicket(?)`, [ticket.id]);
|
||||||
|
|
||||||
const hasToInvoice = ticket.hasToInvoice && ticket.hasDailyInvoice;
|
if (!ticket.salesPersonFk || !ticket.isToBeMailed) continue;
|
||||||
if (!ticket.salesPersonFk || !ticket.isToBeMailed || hasToInvoice) continue;
|
|
||||||
|
|
||||||
if (!ticket.recipient) {
|
if (!ticket.recipient) {
|
||||||
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
|
const body = `No se ha podido enviar el albarán <strong>${ticket.id}</strong>
|
||||||
|
@ -206,15 +205,35 @@ module.exports = app => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = Object.assign({
|
const hasToInvoice = ticket.hasToInvoice && ticket.hasDailyInvoice;
|
||||||
ticketId: ticket.id,
|
if (hasToInvoice) {
|
||||||
recipientId: ticket.clientFk,
|
const invoiceId = await db.findValue(`
|
||||||
recipient: ticket.recipient,
|
SELECT io.id
|
||||||
replyTo: ticket.salesPersonEmail
|
FROM ticket t
|
||||||
}, reqArgs);
|
JOIN invoiceOut io ON io.ref = t.refFk
|
||||||
|
WHERE t.id = ?
|
||||||
|
`, [ticket.id]);
|
||||||
|
|
||||||
const email = new Email('delivery-note-link', args);
|
const args = Object.assign({
|
||||||
await email.send();
|
invoiceId: invoiceId,
|
||||||
|
recipientId: ticket.clientFk,
|
||||||
|
recipient: ticket.recipient,
|
||||||
|
replyTo: ticket.salesPersonEmail
|
||||||
|
}, reqArgs);
|
||||||
|
|
||||||
|
const email = new Email('invoice', args);
|
||||||
|
await email.send();
|
||||||
|
} else {
|
||||||
|
const args = Object.assign({
|
||||||
|
ticketId: ticket.id,
|
||||||
|
recipientId: ticket.clientFk,
|
||||||
|
recipient: ticket.recipient,
|
||||||
|
replyTo: ticket.salesPersonEmail
|
||||||
|
}, reqArgs);
|
||||||
|
|
||||||
|
const email = new Email('delivery-note-link', args);
|
||||||
|
await email.send();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Domain not found
|
// Domain not found
|
||||||
if (error.responseCode == 450)
|
if (error.responseCode == 450)
|
||||||
|
|
Loading…
Reference in New Issue