This commit is contained in:
parent
6f2de903bc
commit
695444f6ae
|
@ -1,12 +1,17 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getSerial', {
|
||||
description: 'Return invoiceIn serial',
|
||||
accessType: 'READ',
|
||||
accepts: {
|
||||
arg: 'issued',
|
||||
type: 'date',
|
||||
accepts: [{
|
||||
arg: 'daysAgo',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
}, {
|
||||
arg: 'serial',
|
||||
type: 'string'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
|
@ -17,17 +22,25 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.getSerial = async(issued, options) => {
|
||||
const myOptions = {};
|
||||
Self.getSerial = async(daysAgo, serial) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const stmt = [];
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
const issued = Date.vnNew();
|
||||
issued.setDate(issued.getDate() - daysAgo);
|
||||
|
||||
const result = await Self.rawSql(`
|
||||
stmt.push(new ParameterizedSQL(`
|
||||
SELECT i.serial, SUM(IF(i.isBooked, 0,1)) pending, COUNT(*) total
|
||||
FROM vn.invoiceIn i
|
||||
WHERE i.issued >= ?
|
||||
GROUP BY i.serial`, [issued]);
|
||||
WHERE i.issued >= ? `, [issued]));
|
||||
|
||||
if (serial)
|
||||
stmt.push(new ParameterizedSQL(`AND i.serial LIKE ? `, [serial]));
|
||||
|
||||
stmt.push(`GROUP BY i.serial`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmt);
|
||||
const result = await conn.executeStmt(sql);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
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);
|
||||
|
||||
expect(result.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should check that returns with serial param', async() => {
|
||||
const result = await models.InvoiceIn.getSerial(45, 'R');
|
||||
|
||||
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');
|
||||
|
||||
expect(result.length).toEqual(0);
|
||||
});
|
||||
});
|
|
@ -23,3 +23,4 @@ Total stems: Total tallos
|
|||
Show agricultural receipt as PDF: Ver recibo agrícola como PDF
|
||||
Send agricultural receipt as PDF: Enviar recibo agrícola como PDF
|
||||
New InvoiceIn: Nueva Factura
|
||||
Days ago: Últimos días
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
<vn-side-menu side="right">
|
||||
<vn-horizontal class="input">
|
||||
<vn-textfield
|
||||
<vn-input-number
|
||||
label="Days ago"
|
||||
ng-model="$ctrl.filter.search"
|
||||
ng-model="$ctrl.filter.daysAgo"
|
||||
vn-focus
|
||||
ng-keydown="$ctrl.onKeyPress($event)">
|
||||
</vn-textfield>
|
||||
ng-keydown="$ctrl.onKeyPress($event)"
|
||||
required="true"
|
||||
min="0">
|
||||
</vn-input-number>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="input">
|
||||
<vn-textfield
|
||||
label="Serial"
|
||||
ng-model="$ctrl.filter.search"
|
||||
ng-model="$ctrl.filter.serial"
|
||||
ng-keydown="$ctrl.onKeyPress($event)">
|
||||
</vn-textfield>
|
||||
</vn-horizontal>
|
||||
<div class="chips">
|
||||
<vn-chip
|
||||
ng-if="$ctrl.filter.search"
|
||||
ng-if="$ctrl.filter.serial"
|
||||
removable="true"
|
||||
on-remove="$ctrl.removeItemFilter('search')"
|
||||
on-remove="$ctrl.removeItemFilter('serial')"
|
||||
class="colored">
|
||||
<span>Id/Name: {{$ctrl.filter.search}}</span>
|
||||
<span>{{$ctrl.$t('Serial')}}: {{$ctrl.filter.serial}}</span>
|
||||
</vn-chip>
|
||||
</div>
|
||||
</vn-side-menu>
|
||||
|
|
|
@ -5,16 +5,16 @@ import './style.scss';
|
|||
class Controller extends SearchPanel {
|
||||
constructor($element, $) {
|
||||
super($element, $);
|
||||
this.filter = {};
|
||||
const filter = {
|
||||
fields: ['daysAgo']
|
||||
};
|
||||
this.$http.get('InvoiceInConfigs', {filter});
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.filter = {
|
||||
tags: []
|
||||
};
|
||||
this.$http.get('InvoiceInConfigs', {filter}).then(res => {
|
||||
if (res.data) {
|
||||
this.invoiceInConfig = res.data[0];
|
||||
this.addFilters();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
removeItemFilter(param) {
|
||||
|
@ -28,6 +28,9 @@ class Controller extends SearchPanel {
|
|||
}
|
||||
|
||||
addFilters() {
|
||||
if (!this.filter.daysAgo)
|
||||
this.filter.daysAgo = this.invoiceInConfig.daysAgo;
|
||||
|
||||
return this.model.addFilter({}, this.filter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import './index.js';
|
||||
|
||||
describe('InvoiceIn', () => {
|
||||
describe('Component serial-search-panel', () => {
|
||||
let controller;
|
||||
let $scope;
|
||||
|
||||
beforeEach(ngModule('invoiceIn'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope) => {
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-invoice-in-serial-search-panel></vn-invoice-in-serial-search-panel>');
|
||||
controller = $componentController('vnInvoiceInSerialSearchPanel', {$element, $scope});
|
||||
controller.model = {
|
||||
addFilter: jest.fn(),
|
||||
};
|
||||
controller.invoiceInConfig = {
|
||||
daysAgo: 45,
|
||||
};
|
||||
}));
|
||||
|
||||
describe('addFilters()', () => {
|
||||
it('should add default daysAgo if it is not already set', () => {
|
||||
controller.filter = {
|
||||
serial: 'R',
|
||||
};
|
||||
controller.addFilters();
|
||||
|
||||
expect(controller.filter.daysAgo).toEqual(controller.invoiceInConfig.daysAgo);
|
||||
});
|
||||
|
||||
it('should not add default daysAgo if it is already set', () => {
|
||||
controller.filter = {
|
||||
daysAgo: 1,
|
||||
serial: 'R',
|
||||
};
|
||||
controller.addFilters();
|
||||
|
||||
expect(controller.filter.daysAgo).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,9 +1,7 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="InvoiceIns/getSerial"
|
||||
limit="20"
|
||||
auto-load="true"
|
||||
params="{issued: '1900-01-01'}">
|
||||
limit="20">
|
||||
</vn-crud-model>
|
||||
<vn-portal slot="topbar">
|
||||
</vn-portal>
|
||||
|
@ -30,7 +28,7 @@
|
|||
<vn-td>{{::invoiceIn.total}}</vn-td>
|
||||
<vn-td shrink>
|
||||
<vn-icon-button
|
||||
vn-click-stop="$ctrl.$state.go('invoiceIn.index')"
|
||||
vn-click-stop="$ctrl.goToIndex(model.userParams.daysAgo)"
|
||||
vn-tooltip="Go to InvoiceIn"
|
||||
icon="icon-invoice-in">
|
||||
</vn-icon-button>
|
||||
|
|
|
@ -6,24 +6,10 @@ export default class Controller extends Section {
|
|||
super($element, $);
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
switch (param) {
|
||||
case 'issued':
|
||||
return {'ii.issued': {
|
||||
between: this.dateRange(value)}
|
||||
};
|
||||
case 'serial':
|
||||
return {[`ii.${param}`]: value};
|
||||
}
|
||||
}
|
||||
|
||||
dateRange(value) {
|
||||
const minHour = new Date(value);
|
||||
minHour.setHours(0, 0, 0, 0);
|
||||
const maxHour = new Date(value);
|
||||
maxHour.setHours(23, 59, 59, 59);
|
||||
|
||||
return [minHour, maxHour];
|
||||
goToIndex(daysAgo) {
|
||||
const issued = Date.vnNew();
|
||||
issued.setDate(issued.getDate() - daysAgo);
|
||||
this.$state.go('invoiceIn.index', {q: `{"isBooked": true, "from": ${issued.getTime()}}`});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue