This commit is contained in:
parent
695444f6ae
commit
69be91b964
|
@ -1127,6 +1127,15 @@ export default {
|
|||
saveButton: 'vn-invoice-in-tax vn-submit',
|
||||
|
||||
},
|
||||
invoiceInIndex: {
|
||||
topbarSearchParams: 'vn-searchbar div.search-params > span',
|
||||
},
|
||||
invoiceInSerial: {
|
||||
daysAgo: 'vn-invoice-in-serial-search-panel vn-input-number[ng-model="$ctrl.filter.daysAgo"]',
|
||||
serial: 'vn-invoice-in-serial-search-panel vn-textfield[ng-model="$ctrl.filter.serial"]',
|
||||
chip: 'vn-chip > vn-icon',
|
||||
goToIndex: 'vn-invoice-in-serial vn-icon-button[icon="icon-invoice-in"]',
|
||||
},
|
||||
travelIndex: {
|
||||
anySearchResult: 'vn-travel-index vn-tbody > a',
|
||||
firstSearchResult: 'vn-travel-index vn-tbody > a:nth-child(1)',
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
import selectors from '../../helpers/selectors.js';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('InvoiceIn serial path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
let httpRequest;
|
||||
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('administrative', 'invoiceIn');
|
||||
await page.accessToSection('invoiceIn.serial');
|
||||
page.on('request', req => {
|
||||
if (req.url().includes(`InvoiceIns/getSerial`))
|
||||
httpRequest = req.url();
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
it('should check that passes the correct params to back', async() => {
|
||||
await page.overwrite(selectors.invoiceInSerial.daysAgo, '30');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
expect(httpRequest).toContain('daysAgo=30');
|
||||
|
||||
await page.overwrite(selectors.invoiceInSerial.serial, 'R');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
expect(httpRequest).toContain('serial=R');
|
||||
await page.click(selectors.invoiceInSerial.chip);
|
||||
});
|
||||
|
||||
it('should go to index and check if the search-panel has the correct params', async() => {
|
||||
await page.click(selectors.invoiceInSerial.goToIndex);
|
||||
const params = await page.$$(selectors.invoiceInIndex.topbarSearchParams);
|
||||
const serial = await params[0].getProperty('title');
|
||||
const isBooked = await params[1].getProperty('title');
|
||||
const from = await params[2].getProperty('title');
|
||||
|
||||
expect(await serial.jsonValue()).toContain('serial');
|
||||
expect(await isBooked.jsonValue()).toContain('not isBooked');
|
||||
expect(await from.jsonValue()).toContain('from');
|
||||
});
|
||||
});
|
|
@ -1,10 +1,15 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getSerial', {
|
||||
Self.remoteMethodCtx('getSerial', {
|
||||
description: 'Return invoiceIn serial',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'object'
|
||||
}, {
|
||||
arg: 'daysAgo',
|
||||
type: 'number',
|
||||
required: true
|
||||
|
@ -22,26 +27,43 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.getSerial = async(daysAgo, serial) => {
|
||||
Self.getSerial = async(ctx, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const stmt = [];
|
||||
const args = ctx.args;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const where = buildFilter(args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'serial':
|
||||
return {'f.serial': {like: `%${value}%`}};
|
||||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(args.filter, {where});
|
||||
const issued = Date.vnNew();
|
||||
issued.setDate(issued.getDate() - daysAgo);
|
||||
issued.setDate(issued.getDate() - args.daysAgo);
|
||||
|
||||
stmt.push(new ParameterizedSQL(`
|
||||
SELECT i.serial, SUM(IF(i.isBooked, 0,1)) pending, COUNT(*) total
|
||||
FROM vn.invoiceIn i
|
||||
WHERE i.issued >= ? `, [issued]));
|
||||
const stmts = [];
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT i.serial, SUM(IF(i.isBooked, 0,1)) pending, COUNT(*) total
|
||||
FROM vn.invoiceIn i
|
||||
WHERE i.issued >= ?
|
||||
GROUP BY i.serial) f`
|
||||
, [issued]);
|
||||
|
||||
if (serial)
|
||||
stmt.push(new ParameterizedSQL(`AND i.serial LIKE ? `, [serial]));
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
|
||||
stmt.push(`GROUP BY i.serial`);
|
||||
const invoiceInIndex = stmts.push(stmt) - 1;
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmt);
|
||||
const result = await conn.executeStmt(sql);
|
||||
|
||||
return result;
|
||||
return invoiceInIndex === 0 ? result : result[invoiceInIndex];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,19 +2,22 @@ const models = require('vn-loopback/server/server').models;
|
|||
|
||||
describe('invoiceIn getSerial()', () => {
|
||||
it('should check that returns without serial param', async() => {
|
||||
const result = await models.InvoiceIn.getSerial(45);
|
||||
const ctx = {args: {daysAgo: 45}};
|
||||
const result = await models.InvoiceIn.getSerial(ctx);
|
||||
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check that returns with serial param', async() => {
|
||||
const result = await models.InvoiceIn.getSerial(45, 'R');
|
||||
const ctx = {args: {daysAgo: 45, serial: 'R'}};
|
||||
const result = await models.InvoiceIn.getSerial(ctx);
|
||||
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check that returns with non exist serial param', async() => {
|
||||
const result = await models.InvoiceIn.getSerial(45, 'Mock serial');
|
||||
const ctx = {args: {daysAgo: 45, serial: 'Mock serial'}};
|
||||
const result = await models.InvoiceIn.getSerial(ctx);
|
||||
|
||||
expect(result.length).toEqual(0);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
ng-model="$ctrl.filter.daysAgo"
|
||||
vn-focus
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
required="true"
|
||||
min="0">
|
||||
</vn-input-number>
|
||||
</vn-horizontal>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<vn-td>{{::invoiceIn.total}}</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-icon-button
|
||||
vn-click-stop="$ctrl.goToIndex(model.userParams.daysAgo)"
|
||||
vn-click-stop="$ctrl.goToIndex(model.userParams.daysAgo, invoiceIn.serial)"
|
||||
vn-tooltip="Go to InvoiceIn"
|
||||
icon="icon-invoice-in">
|
||||
</vn-icon-button>
|
||||
|
|
|
@ -6,10 +6,11 @@ export default class Controller extends Section {
|
|||
super($element, $);
|
||||
}
|
||||
|
||||
goToIndex(daysAgo) {
|
||||
goToIndex(daysAgo, serial) {
|
||||
const issued = Date.vnNew();
|
||||
issued.setDate(issued.getDate() - daysAgo);
|
||||
this.$state.go('invoiceIn.index', {q: `{"isBooked": true, "from": ${issued.getTime()}}`});
|
||||
this.$state.go('invoiceIn.index',
|
||||
{q: `{"serial": "${serial}", "isBooked": false, "from": ${issued.getTime()}}`});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue