diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index 38e49120a..fa22dab1e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -75,7 +75,13 @@ module.exports = Self => { } const invoiceType = 'G'; - const invoiceId = await models.Ticket.makeInvoice(ctx, invoiceType, args.companyFk, options); + const invoiceId = await models.Ticket.makeInvoice( + ctx, + invoiceType, + args.companyFk, + args.invoiceDate, + options + ); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js index 262ee6c5a..f53bcd80d 100644 --- a/modules/ticket/back/methods/ticket/invoiceTickets.js +++ b/modules/ticket/back/methods/ticket/invoiceTickets.js @@ -98,7 +98,7 @@ module.exports = function(Self) { ${address ? `AND addressFk = ${address}` : ''} `, [ticketsIds], myOptions); - const invoiceId = await models.Ticket.makeInvoice(ctx, 'R', companyId, myOptions); + const invoiceId = await models.Ticket.makeInvoice(ctx, 'R', companyId, null, myOptions); invoicesIds.push(invoiceId); } }; diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index c4eef30c8..16d7ffc5f 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -6,7 +6,7 @@ module.exports = function(Self) { accessType: 'WRITE', accepts: [ { - arg: 'type', + arg: 'invoiceType', description: 'The invoice type', type: 'string', required: true @@ -16,6 +16,11 @@ module.exports = function(Self) { description: 'The company id', type: 'string', required: true + }, + { + arg: 'invoiceDate', + description: 'The invoice date', + type: 'date' } ], returns: { @@ -28,10 +33,9 @@ module.exports = function(Self) { } }); - Self.makeInvoice = async(ctx, type, companyFk, options) => { + Self.makeInvoice = async(ctx, invoiceType, companyFk, invoiceDate = Date.vnNew(), options) => { const models = Self.app.models; - const date = Date.vnNew(); - date.setHours(0, 0, 0, 0); + invoiceDate.setHours(0, 0, 0, 0); const myOptions = {userId: ctx.req.accessToken.userId}; let tx; @@ -45,7 +49,6 @@ module.exports = function(Self) { } let serial; - let invoiceId; try { const ticketToInvoice = await Self.rawSql(` SELECT id @@ -71,18 +74,18 @@ module.exports = function(Self) { const [result] = await Self.rawSql(query, [ clientId, companyFk, - type, + invoiceType, ], myOptions); serial = result.serial; - await Self.rawSql('CALL invoiceOut_new(?, ?, null, @invoiceId)', [serial, date], myOptions); + await Self.rawSql('CALL invoiceOut_new(?, ?, null, @invoiceId)', [serial, invoiceDate], myOptions); const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions); if (!resultInvoice) throw new UserError('No tickets to invoice', 'notInvoiced'); if (serial != 'R' && resultInvoice.id) - await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions); + await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions); if (tx) await tx.commit();