refs #5874 fix: global invoicing
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-07-07 08:54:55 +02:00
parent 97ef30404d
commit 8c18cd8217
3 changed files with 19 additions and 10 deletions

View File

@ -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();

View File

@ -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);
}
};

View File

@ -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();