diff --git a/client/ticket/src/search-panel/index.html b/client/ticket/src/search-panel/index.html index f65aabae5..d1492ba1c 100644 --- a/client/ticket/src/search-panel/index.html +++ b/client/ticket/src/search-panel/index.html @@ -78,9 +78,16 @@ field="filter.stateFk" url="/api/States"> + + + + diff --git a/client/ticket/src/search-panel/locale/es.yml b/client/ticket/src/search-panel/locale/es.yml index 20ef1ee23..f63f2baf9 100644 --- a/client/ticket/src/search-panel/locale/es.yml +++ b/client/ticket/src/search-panel/locale/es.yml @@ -8,4 +8,4 @@ Warehouse: Almacén Sales person: Comercial Province: Provincia My team: Mi equipo -My tickets: Mis tickets \ No newline at end of file +Order id: Id pedido \ No newline at end of file diff --git a/services/loopback/common/methods/ticket/filter.js b/services/loopback/common/methods/ticket/filter.js index 7dfc955d7..413b31a0f 100644 --- a/services/loopback/common/methods/ticket/filter.js +++ b/services/loopback/common/methods/ticket/filter.js @@ -63,6 +63,10 @@ module.exports = Self => { arg: 'myTeam', type: 'Boolean', description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)` + }, { + arg: 'orderFk', + type: 'Number', + description: `The order id filter` } ], returns: { @@ -79,10 +83,18 @@ module.exports = Self => { let conn = Self.dataSource.connector; let worker = await Self.app.models.Worker.findOne({ - fields: ['id'], - where: {userFk: ctx.req.accessToken.userId} + where: {userFk: ctx.req.accessToken.userId}, + include: [ + {relation: 'collegues'} + ] }); - let teamIds = [worker && worker.id]; + + let teamIds = []; + worker.collegues().forEach(collegue => { + teamIds.push(collegue.collegueFk); + }); + console.log(teamIds); + let where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -102,6 +114,8 @@ module.exports = Self => { return {'a.provinceFk': value}; case 'stateFk': return {'ts.stateFk': value}; + case 'orderFk': + return {'ot.orderFk': value}; case 'myTeam': return {'c.salesPersonFk': {inq: teamIds}}; case 'id': @@ -136,7 +150,8 @@ module.exports = Self => { w.name AS warehouse, am.name AS agencyMode, st.name AS state, - wk.name AS salesPerson + wk.name AS salesPerson, + ot.orderFk AS orderFk FROM ticket t LEFT JOIN address a ON a.id = t.addressFk LEFT JOIN province p ON p.id = a.provinceFk @@ -145,8 +160,11 @@ module.exports = Self => { LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk`); - stmt.merge(conn.makeSuffix(filter)); + LEFT JOIN worker wk ON wk.id = c.salesPersonFk + LEFT JOIN orderTicket ot ON ot.ticketFk = t.id`); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge('GROUP BY t.id'); + stmt.merge(conn.makePagination(filter)); stmts.push(stmt); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems'); diff --git a/services/loopback/common/models/worker-team-collegues.json b/services/loopback/common/models/worker-team-collegues.json new file mode 100644 index 000000000..2e4a0a4f8 --- /dev/null +++ b/services/loopback/common/models/worker-team-collegues.json @@ -0,0 +1,26 @@ +{ + "name": "WorkerTeamCollegues", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerTeamCollegues" + } + }, + "properties": { + "workerFk": { + "id": true, + "type": "Number" + }, + "collegueFk": { + "id": true, + "type": "Number" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} \ No newline at end of file diff --git a/services/loopback/common/models/worker.json b/services/loopback/common/models/worker.json index 81807e6f6..6b382a16c 100644 --- a/services/loopback/common/models/worker.json +++ b/services/loopback/common/models/worker.json @@ -31,6 +31,11 @@ "type": "belongsTo", "model": "Account", "foreignKey": "userFk" + }, + "collegues": { + "type": "hasMany", + "model": "WorkerTeamCollegues", + "foreignKey": "workerFk" } } } \ No newline at end of file diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index 6532f6bf9..b41bad50b 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -165,6 +165,9 @@ "WorkerTeam": { "dataSource": "vn" }, + "WorkerTeamCollegues": { + "dataSource": "vn" + }, "TicketRequest": { "dataSource": "vn" },