refs #6174 feat first approach
This commit is contained in:
parent
199656afb8
commit
831d358e41
|
@ -50,6 +50,7 @@ module.exports = Self => {
|
|||
Self.transferInvoice = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let makePdf = false;
|
||||
const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args;
|
||||
let tx;
|
||||
if (typeof options == 'object')
|
||||
|
@ -63,6 +64,7 @@ module.exports = Self => {
|
|||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
makePdf = true;
|
||||
}
|
||||
try {
|
||||
const filterRef = {where: {refFk: refFk}};
|
||||
|
@ -93,11 +95,9 @@ module.exports = Self => {
|
|||
await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions);
|
||||
const [invoiceId] = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions);
|
||||
|
||||
if (tx) {
|
||||
await tx.commit();
|
||||
await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null);
|
||||
}
|
||||
tx && await tx.commit();
|
||||
|
||||
makePdf && await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null);
|
||||
return invoiceId;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -32,6 +32,7 @@ module.exports = function(Self) {
|
|||
const models = Self.app.models;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
let makePdf = false;
|
||||
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
|
@ -42,6 +43,7 @@ module.exports = function(Self) {
|
|||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
makePdf = true;
|
||||
}
|
||||
|
||||
let invoicesIds = [];
|
||||
|
@ -81,7 +83,7 @@ module.exports = function(Self) {
|
|||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
if (tx) {
|
||||
if (makePdf) {
|
||||
for (const invoiceId of invoicesIds)
|
||||
await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue