diff --git a/modules/account/back/methods/account/sync.js b/modules/account/back/methods/account/sync.js index 1026c5020..b38e4dd37 100644 --- a/modules/account/back/methods/account/sync.js +++ b/modules/account/back/methods/account/sync.js @@ -29,14 +29,14 @@ module.exports = Self => { const models = Self.app.models; const myOptions = {}; let tx; - + if (typeof options == 'object') Object.assign(myOptions, options); if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; - }; + } try { const user = await models.VnUser.findOne({ diff --git a/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js b/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js index dcc1fa6e8..493f19aa7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js +++ b/modules/invoiceOut/back/methods/invoiceOut/getInvoiceDate.js @@ -7,7 +7,12 @@ module.exports = Self => { arg: 'companyFk', type: 'number', required: true - } + }, + { + arg: 'serialType', + type: 'string', + required: true + }, ], returns: { type: ['object'], @@ -19,16 +24,16 @@ module.exports = Self => { } }); - Self.getInvoiceDate = async companyFk => { + Self.getInvoiceDate = async(companyFk, serialType) => { const models = Self.app.models; const [invoiceDate] = await models.InvoiceOut.rawSql( `SELECT MAX(io.issued) issued FROM invoiceOut io JOIN invoiceOutSerial ios ON ios.code = io.serial - WHERE ios.type = 'global' - AND io.issued + WHERE ios.type = ? + AND io.issued AND io.companyFk = ?`, - [companyFk] + [serialType, companyFk] ); return invoiceDate; }; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js new file mode 100644 index 000000000..830402250 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/getInvoiceDate.spec.js @@ -0,0 +1,39 @@ +const models = require('vn-loopback/server/server').models; +const moment = require('moment'); + +describe('getInvoiceDate()', () => { + const companyFk = 442; + let tx; + let options; + + beforeEach(async() => { + tx = await models.InvoiceOut.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should return a correct date for serialType "global"', async() => { + const serialType = 'global'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2000-12-01'); + }); + + it('should return null for serialType "multiple"', async() => { + const serialType = 'multiple'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(result.issued).toBeNull(); + }); + + it('should return correct date for serialType "quick"', async() => { + const serialType = 'quick'; + const result = await models.InvoiceOut.getInvoiceDate(companyFk, serialType, options); + + expect(moment(result.issued).format('YYYY-MM-DD')).toEqual('2001-01-01'); + }); +}); +