diff --git a/modules/invoiceOut/back/methods/invoiceOut/filter.js b/modules/invoiceOut/back/methods/invoiceOut/filter.js
new file mode 100644
index 0000000000..e9f60473a6
--- /dev/null
+++ b/modules/invoiceOut/back/methods/invoiceOut/filter.js
@@ -0,0 +1,128 @@
+
+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.remoteMethodCtx('filter', {
+ description: 'Find all instances of the model matched by filter from the data source.',
+ accessType: 'READ',
+ accepts: [
+ {
+ arg: 'filter',
+ type: 'Object',
+ description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
+ http: {source: 'query'}
+ },
+ {
+ arg: 'search',
+ type: 'String',
+ description: 'Searchs the invoiceOut by id',
+ http: {source: 'query'}
+ }, {
+ arg: 'clientFk',
+ type: 'Integer',
+ description: 'The client id',
+ http: {source: 'query'}
+ }, {
+ arg: 'hasPdf',
+ type: 'Boolean',
+ description: 'Whether the the invoiceOut has PDF or not',
+ http: {source: 'query'}
+ }, {
+ arg: 'amount',
+ type: 'Number',
+ description: 'The amount filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'min',
+ type: 'Number',
+ description: 'The minimun amount flter',
+ http: {source: 'query'}
+ }, {
+ arg: 'max',
+ type: 'Number',
+ description: 'The maximun amount flter',
+ http: {source: 'query'}
+ }, {
+ arg: 'issued',
+ type: 'Date',
+ description: 'The issued date filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'created',
+ type: 'Date',
+ description: 'The created date filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'dued',
+ type: 'Date',
+ description: 'The due date filter',
+ http: {source: 'query'}
+ }
+ ],
+ returns: {
+ type: ['Object'],
+ root: true
+ },
+ http: {
+ path: `/filter`,
+ verb: 'GET'
+ }
+ });
+
+ Self.filter = async(ctx, filter) => {
+ let conn = Self.dataSource.connector;
+
+ let where = buildFilter(ctx.args, (param, value) => {
+ switch (param) {
+ case 'search':
+ return {ref: {like: `%${value}%`}};
+ case 'min':
+ return {amount: {gte: value}};
+ case 'max':
+ return {amount: {lte: value}};
+ case 'hasPdf':
+ return {'i.pdf': value};
+ case 'created':
+ return {'i.created': value};
+ case 'amount':
+ case 'clientFk':
+ case 'companyFk':
+ case 'issued':
+ case 'dued':
+ return {[param]: value};
+ }
+ });
+
+ filter = mergeFilters(ctx.args.filter, {where});
+
+ let stmts = [];
+ let stmt;
+
+ stmt = new ParameterizedSQL(
+ `SELECT
+ i.id,
+ i.ref,
+ i.issued,
+ i.amount,
+ i.created,
+ i.dued,
+ i.clientFk,
+ i.pdf AS hasPdf,
+ c.socialName AS clientSocialName,
+ co.code AS companyCode
+ FROM invoiceOut i
+ LEFT JOIN client c ON c.id = i.clientFk
+ LEFT JOIN company co ON co.id = i.companyFk`
+ );
+
+ stmt.merge(conn.makeSuffix(filter));
+ let itemsIndex = stmts.push(stmt) - 1;
+
+ let sql = ParameterizedSQL.join(stmts, ';');
+ let result = await conn.executeStmt(sql);
+ return itemsIndex === 0 ? result : result[itemsIndex];
+ };
+};
+
diff --git a/modules/invoiceOut/back/models/invoiceOut.js b/modules/invoiceOut/back/models/invoiceOut.js
index a3edaa28fd..2d7c691fcc 100644
--- a/modules/invoiceOut/back/models/invoiceOut.js
+++ b/modules/invoiceOut/back/models/invoiceOut.js
@@ -1,4 +1,5 @@
module.exports = Self => {
+ require('../methods/invoiceOut/filter')(Self);
require('../methods/invoiceOut/summary')(Self);
require('../methods/invoiceOut/download')(Self);
};
diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html
index 98c286dbcd..8a7db4f25e 100644
--- a/modules/invoiceOut/front/index/index.html
+++ b/modules/invoiceOut/front/index/index.html
@@ -1,20 +1,16 @@
+ data="invoiceOuts"
+ order="issued DESC">
@@ -36,7 +32,7 @@
-
{{::invoiceOut.ref | dashIfEmpty}}
@@ -46,11 +42,11 @@
- {{::invoiceOut.client.name | dashIfEmpty}}
+ {{::invoiceOut.clientSocialName | dashIfEmpty}}
{{::invoiceOut.created | dateTime:'dd/MM/yyyy' | dashIfEmpty}}
- {{::invoiceOut.company.code | dashIfEmpty}}
+ {{::invoiceOut.companyCode | dashIfEmpty}}
{{::invoiceOut.dued | dateTime:'dd/MM/yyyy' | dashIfEmpty}}
+ Desglose impositivo
- Desglose impositivo
Type
Taxable base
diff --git a/modules/invoiceOut/front/summary/locale/es.yml b/modules/invoiceOut/front/summary/locale/es.yml
index 4444939c79..d1b4a24067 100644
--- a/modules/invoiceOut/front/summary/locale/es.yml
+++ b/modules/invoiceOut/front/summary/locale/es.yml
@@ -1,11 +1,3 @@
-Driver: Conductor
-Vehicle: VehĂculo
-Packages: Bultos
-Starting time: H. Inicio
-Finishing time: H. Fin
-Km Start: Km de inicio
-Km End: Km de fin
-PC: CP
Date: Fecha
Created: Creada
Due: Vencimiento
diff --git a/modules/invoiceOut/front/summary/style.scss b/modules/invoiceOut/front/summary/style.scss
index aef44fbf92..f2cf533810 100644
--- a/modules/invoiceOut/front/summary/style.scss
+++ b/modules/invoiceOut/front/summary/style.scss
@@ -1,7 +1,7 @@
@import "variables";
-vn-route-summary .summary {
+vn-invoice-out-summary .summary {
max-width: $width-large;
vn-icon[icon=insert_drive_file]{
diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js
index 0da463ad4a..d1ad0aab78 100644
--- a/modules/item/back/methods/item/filter.js
+++ b/modules/item/back/methods/item/filter.js
@@ -41,7 +41,7 @@ module.exports = Self => {
}, {
arg: 'hasVisible',
type: 'Boolean',
- description: 'Whether the the item has o not visible',
+ description: 'Whether the the item has visible or not',
http: {source: 'query'}
}, {
arg: 'isActive',
diff --git a/modules/route/back/methods/route/filter.js b/modules/route/back/methods/route/filter.js
new file mode 100644
index 0000000000..b456806424
--- /dev/null
+++ b/modules/route/back/methods/route/filter.js
@@ -0,0 +1,131 @@
+
+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.remoteMethodCtx('filter', {
+ description: 'Find all instances of the model matched by filter from the data source.',
+ accessType: 'READ',
+ accepts: [
+ {
+ arg: 'filter',
+ type: 'Object',
+ description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
+ http: {source: 'query'}
+ }, {
+ arg: 'search',
+ type: 'String',
+ description: 'Searchs the route by id',
+ http: {source: 'query'}
+ }, {
+ arg: 'workerFk',
+ type: 'Integer',
+ description: 'The worker id',
+ http: {source: 'query'}
+ }, {
+ arg: 'agencyModeFk',
+ type: 'Integer',
+ description: 'The agencyMode id',
+ http: {source: 'query'}
+ }, {
+ arg: 'to',
+ type: 'Date',
+ description: 'The to date filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'from',
+ type: 'Date',
+ description: 'The to date filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'vehicleFk',
+ type: 'Integer',
+ description: 'The vehicle id',
+ http: {source: 'query'}
+ }, {
+ arg: 'm3',
+ type: 'Number',
+ description: 'The m3 filter',
+ http: {source: 'query'}
+ }, {
+ arg: 'description',
+ type: 'String',
+ description: 'The description filter',
+ http: {source: 'query'}
+ }
+ ],
+ returns: {
+ type: ['Object'],
+ root: true
+ },
+ http: {
+ path: `/filter`,
+ verb: 'GET'
+ }
+ });
+
+ Self.filter = async(ctx, filter) => {
+ let conn = Self.dataSource.connector;
+
+ let where = buildFilter(ctx.args, (param, value) => {
+ switch (param) {
+ case 'search':
+ return {'r.id': value};
+ case 'from':
+ return {'r.created': {gte: value}};
+ case 'to':
+ return {'r.created': {lte: value}};
+ case 'm3':
+ return {'r.m3': value};
+ case 'description':
+ return {'r.description': {like: `%${value}%`}};
+ case 'workerFk':
+ case 'vehicleFk':
+ case 'agencyModeFk':
+ return {[param]: value};
+ }
+ });
+
+ filter = mergeFilters(ctx.args.filter, {where});
+
+ let stmts = [];
+ let stmt;
+
+ stmt = new ParameterizedSQL(
+ `SELECT
+ r.id,
+ r.workerFk,
+ r.created,
+ r.vehicleFk,
+ r.agencyModeFk,
+ r.time,
+ r.isOk,
+ r.kmStart,
+ r.kmEnd,
+ r.started,
+ r.finished,
+ r.gestdocFk,
+ r.cost,
+ r.m3,
+ r.description,
+ am.name agencyName,
+ u.nickname AS workerNickname,
+ v.numberPlate AS vehiclePlateNumber
+ FROM route r
+ LEFT JOIN agencyMode am ON am.id = r.agencyModeFk
+ LEFT JOIN vehicle v ON v.id = r.vehicleFk
+ LEFT JOIN worker w ON w.id = r.workerFk
+ LEFT JOIN account.user u ON u.id = w.userFk`
+ );
+
+
+ stmt.merge(conn.makeSuffix(filter));
+ let itemsIndex = stmts.push(stmt) - 1;
+
+ let sql = ParameterizedSQL.join(stmts, ';');
+ let result = await conn.executeStmt(sql);
+ return itemsIndex === 0 ? result : result[itemsIndex];
+ };
+};
+
diff --git a/modules/route/back/models/route.js b/modules/route/back/models/route.js
index e3ebabb686..bd637822f4 100644
--- a/modules/route/back/models/route.js
+++ b/modules/route/back/models/route.js
@@ -1,4 +1,5 @@
module.exports = Self => {
+ require('../methods/route/filter')(Self);
require('../methods/route/summary')(Self);
require('../methods/route/getTickets')(Self);
require('../methods/route/guessPriority')(Self);
diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html
index 43238fd4d3..b9935ba455 100644
--- a/modules/route/front/index/index.html
+++ b/modules/route/front/index/index.html
@@ -1,7 +1,6 @@
@@ -11,9 +10,7 @@
@@ -41,12 +38,12 @@
- {{::route.worker.user.nickname}}
+ ng-click="$ctrl.showWorkerDescriptor($event, route.workerFk)">
+ {{::route.workerNickname}}
- {{::route.agencyMode.name | dashIfEmpty}}
- {{::route.vehicle.numberPlate | dashIfEmpty}}
+ {{::route.agencyName | dashIfEmpty}}
+ {{::route.vehiclePlateNumber | dashIfEmpty}}
{{::route.created | dateTime:'dd/MM/yyyy' | dashIfEmpty}}
{{::route.m3 | dashIfEmpty}}
{{::route.description | dashIfEmpty}}
@@ -72,7 +69,7 @@
+ worker-fk="$ctrl.selectedWorker">
diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js
index 0fa102c4d3..4b0536fd01 100644
--- a/modules/route/front/index/index.js
+++ b/modules/route/front/index/index.js
@@ -4,61 +4,15 @@ export default class Controller {
constructor($scope, vnToken) {
this.accessToken = vnToken.token;
this.$ = $scope;
-
- this.filter = {
- include: [
- {
- relation: 'agencyMode',
- scope: {
- fields: ['name']
- }
- },
- {
- relation: 'vehicle',
- scope: {
- fields: ['numberPlate']
- }
- },
- {
- relation: 'worker',
- scope: {
- fields: ['userFk'],
- include: {
- relation: 'user',
- scope: {
- fields: ['nickname']
- }
- }
- }
- },
- ]
- };
}
- exprBuilder(param, value) {
- switch (param) {
- case 'search':
- return {id: value};
- case 'from':
- return {created: {gte: value}};
- case 'to':
- return {created: {lte: value}};
- case 'workerFk':
- case 'vehicleFk':
- case 'agencyModeFk':
- case 'm3':
- case 'description':
- return {[param]: value};
- }
- }
-
- showWorkerDescriptor(event, userId) {
+ showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
event.preventDefault();
- event.stopPropagation();
+ event.stopImmediatePropagation();
- this.selectedWorker = userId;
+ this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
@@ -69,6 +23,13 @@ export default class Controller {
event.preventDefault();
event.stopImmediatePropagation();
}
+
+ onSearch(params) {
+ if (params)
+ this.$.model.applyFilter(null, params);
+ else
+ this.$.model.clear();
+ }
}
Controller.$inject = ['$scope', 'vnToken'];