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