This commit is contained in:
parent
09dbd29086
commit
8bb8b8cfba
|
@ -24,7 +24,6 @@ module.exports = function(Self) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.makeInvoice = async(ctx, ticketsIds, options) => {
|
Self.makeInvoice = async(ctx, ticketsIds, options) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const date = Date.vnNew();
|
const date = Date.vnNew();
|
||||||
date.setHours(0, 0, 0, 0);
|
date.setHours(0, 0, 0, 0);
|
||||||
|
@ -42,6 +41,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
let serial;
|
let serial;
|
||||||
let invoiceId;
|
let invoiceId;
|
||||||
|
let invoiceOut;
|
||||||
try {
|
try {
|
||||||
const tickets = await models.Ticket.find({
|
const tickets = await models.Ticket.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -92,6 +92,11 @@ module.exports = function(Self) {
|
||||||
if (serial != 'R' && invoiceId)
|
if (serial != 'R' && invoiceId)
|
||||||
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions);
|
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], myOptions);
|
||||||
|
|
||||||
|
invoiceOut = await models.InvoiceOut.findById(invoiceId, {
|
||||||
|
include: {
|
||||||
|
relation: 'client'
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
@ -102,12 +107,6 @@ module.exports = function(Self) {
|
||||||
await models.InvoiceOut.createPdf(ctx, invoiceId);
|
await models.InvoiceOut.createPdf(ctx, invoiceId);
|
||||||
|
|
||||||
if (invoiceId) {
|
if (invoiceId) {
|
||||||
const invoiceOut = await models.InvoiceOut.findById(invoiceId, {
|
|
||||||
include: {
|
|
||||||
relation: 'client'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.args = {
|
ctx.args = {
|
||||||
reference: invoiceOut.ref,
|
reference: invoiceOut.ref,
|
||||||
recipientId: invoiceOut.clientFk,
|
recipientId: invoiceOut.clientFk,
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket makeInvoice()', () => {
|
fdescribe('ticket makeInvoice()', () => {
|
||||||
const userId = 19;
|
const userId = 19;
|
||||||
const ticketId = 11;
|
const ticketId = 11;
|
||||||
const clientId = 1102;
|
const clientId = 1102;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
|
getLocale: () => {
|
||||||
|
return 'en';
|
||||||
|
},
|
||||||
accessToken: {userId: userId},
|
accessToken: {userId: userId},
|
||||||
headers: {origin: 'http://localhost:5000'},
|
headers: {origin: 'http://localhost:5000'},
|
||||||
};
|
};
|
||||||
|
@ -67,6 +70,7 @@ describe('ticket makeInvoice()', () => {
|
||||||
it('should invoice a ticket, then try again to fail', async() => {
|
it('should invoice a ticket, then try again to fail', async() => {
|
||||||
const invoiceOutModel = models.InvoiceOut;
|
const invoiceOutModel = models.InvoiceOut;
|
||||||
spyOn(invoiceOutModel, 'createPdf');
|
spyOn(invoiceOutModel, 'createPdf');
|
||||||
|
spyOn(invoiceOutModel, 'invoiceEmail');
|
||||||
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
@ -90,6 +94,7 @@ describe('ticket makeInvoice()', () => {
|
||||||
it('should success to invoice a ticket', async() => {
|
it('should success to invoice a ticket', async() => {
|
||||||
const invoiceOutModel = models.InvoiceOut;
|
const invoiceOutModel = models.InvoiceOut;
|
||||||
spyOn(invoiceOutModel, 'createPdf');
|
spyOn(invoiceOutModel, 'createPdf');
|
||||||
|
spyOn(invoiceOutModel, 'invoiceEmail');
|
||||||
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue