Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
0b704db353
|
@ -22,6 +22,9 @@
|
||||||
},
|
},
|
||||||
"code": {
|
"code": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"isAutoConciliated": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [{
|
"acls": [{
|
||||||
|
|
|
@ -65,6 +65,7 @@ module.exports = Self => {
|
||||||
let clientId = args.clientFk;
|
let clientId = args.clientFk;
|
||||||
let maxShipped = args.maxShipped;
|
let maxShipped = args.maxShipped;
|
||||||
let companyId;
|
let companyId;
|
||||||
|
let newInvoice;
|
||||||
let query;
|
let query;
|
||||||
try {
|
try {
|
||||||
if (ticketId) {
|
if (ticketId) {
|
||||||
|
@ -137,18 +138,18 @@ module.exports = Self => {
|
||||||
], myOptions);
|
], myOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [newInvoice] = await Self.rawSql(`SELECT @newInvoiceId id`, null, myOptions);
|
[newInvoice] = await Self.rawSql(`SELECT @newInvoiceId id`, null, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
if (newInvoice.id)
|
if (newInvoice.id)
|
||||||
await Self.createPdf(ctx, newInvoice.id);
|
await Self.createPdf(ctx, newInvoice.id);
|
||||||
|
|
||||||
return newInvoice;
|
return newInvoice;
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function isInvoiceable(clientId, options) {
|
async function isInvoiceable(clientId, options) {
|
||||||
|
|
|
@ -43,8 +43,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.globalInvoicing = async(ctx, options) => {
|
Self.globalInvoicing = async(ctx, options) => {
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const invoicesIds = [];
|
|
||||||
const failedClients = [];
|
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
@ -57,6 +55,8 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const invoicesIds = [];
|
||||||
|
const failedClients = [];
|
||||||
let query;
|
let query;
|
||||||
try {
|
try {
|
||||||
query = `
|
query = `
|
||||||
|
@ -155,16 +155,16 @@ module.exports = Self => {
|
||||||
await notifyFailures(ctx, failedClients, myOptions);
|
await notifyFailures(ctx, failedClients, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
// Print invoices PDF
|
// Print invoices PDF
|
||||||
for (let invoiceId of invoicesIds)
|
for (let invoiceId of invoicesIds)
|
||||||
await Self.createPdf(ctx, invoiceId);
|
await Self.createPdf(ctx, invoiceId);
|
||||||
|
|
||||||
return invoicesIds;
|
return invoicesIds;
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getNegativeBase(options) {
|
async function getNegativeBase(options) {
|
||||||
|
|
|
@ -38,6 +38,8 @@ module.exports = function(Self) {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let serial;
|
||||||
|
let invoiceId;
|
||||||
try {
|
try {
|
||||||
const tickets = await models.Ticket.find({
|
const tickets = await models.Ticket.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -68,7 +70,7 @@ module.exports = function(Self) {
|
||||||
companyId,
|
companyId,
|
||||||
'R'
|
'R'
|
||||||
], myOptions);
|
], myOptions);
|
||||||
const serial = result.serial;
|
serial = result.serial;
|
||||||
|
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
|
DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
|
||||||
|
@ -83,7 +85,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);
|
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);
|
||||||
|
|
||||||
const invoiceId = resultInvoice.id;
|
invoiceId = resultInvoice.id;
|
||||||
|
|
||||||
for (let ticket of tickets) {
|
for (let ticket of tickets) {
|
||||||
const ticketInvoice = await models.Ticket.findById(ticket.id, {
|
const ticketInvoice = await models.Ticket.findById(ticket.id, {
|
||||||
|
@ -104,14 +106,14 @@ module.exports = function(Self) {
|
||||||
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions);
|
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
if (serial != 'R' && invoiceId)
|
if (serial != 'R' && invoiceId)
|
||||||
await models.InvoiceOut.createPdf(ctx, invoiceId);
|
await models.InvoiceOut.createPdf(ctx, invoiceId);
|
||||||
|
|
||||||
return {invoiceFk: invoiceId, serial: serial};
|
return {invoiceFk: invoiceId, serial: serial};
|
||||||
} catch (e) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue