refs #5874 fix: global invoicing
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
97ef30404d
commit
8c18cd8217
|
@ -75,7 +75,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceType = 'G';
|
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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ module.exports = function(Self) {
|
||||||
${address ? `AND addressFk = ${address}` : ''}
|
${address ? `AND addressFk = ${address}` : ''}
|
||||||
`, [ticketsIds], myOptions);
|
`, [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);
|
invoicesIds.push(invoiceId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = function(Self) {
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'type',
|
arg: 'invoiceType',
|
||||||
description: 'The invoice type',
|
description: 'The invoice type',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
|
@ -16,6 +16,11 @@ module.exports = function(Self) {
|
||||||
description: 'The company id',
|
description: 'The company id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'invoiceDate',
|
||||||
|
description: 'The invoice date',
|
||||||
|
type: 'date'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
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 models = Self.app.models;
|
||||||
const date = Date.vnNew();
|
invoiceDate.setHours(0, 0, 0, 0);
|
||||||
date.setHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -45,7 +49,6 @@ module.exports = function(Self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let serial;
|
let serial;
|
||||||
let invoiceId;
|
|
||||||
try {
|
try {
|
||||||
const ticketToInvoice = await Self.rawSql(`
|
const ticketToInvoice = await Self.rawSql(`
|
||||||
SELECT id
|
SELECT id
|
||||||
|
@ -71,18 +74,18 @@ module.exports = function(Self) {
|
||||||
const [result] = await Self.rawSql(query, [
|
const [result] = await Self.rawSql(query, [
|
||||||
clientId,
|
clientId,
|
||||||
companyFk,
|
companyFk,
|
||||||
type,
|
invoiceType,
|
||||||
], myOptions);
|
], myOptions);
|
||||||
serial = result.serial;
|
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);
|
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);
|
||||||
if (!resultInvoice)
|
if (!resultInvoice)
|
||||||
throw new UserError('No tickets to invoice', 'notInvoiced');
|
throw new UserError('No tickets to invoice', 'notInvoiced');
|
||||||
|
|
||||||
if (serial != 'R' && resultInvoice.id)
|
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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue