diff --git a/back/models/warehouse.json b/back/models/warehouse.json index f12b5e86e..76c80cb9a 100644 --- a/back/models/warehouse.json +++ b/back/models/warehouse.json @@ -9,24 +9,24 @@ }, "properties": { "id": { - "id": true, - "type": "number", - "forceId": false + "id": true, + "type": "number", + "forceId": false }, "name": { - "type": "string" + "type": "string" }, "code": { - "type": "string" + "type": "string" }, "isInventory": { - "type": "number" + "type": "number" }, - "isManaged":{ - "type": "boolean" + "isManaged": { + "type": "boolean" }, "countryFk": { - "type": "number" + "type": "number" } }, "relations": { @@ -36,6 +36,13 @@ "foreignKey": "countryFk" } }, + "relations": { + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" + } + }, "acls": [ { "accessType": "READ", @@ -44,5 +51,11 @@ "permission": "ALLOW" } ], - "scope" : {"where": {"isForTicket": {"neq": 0}}} -} + "scope": { + "where": { + "isForTicket": { + "neq": 0 + } + } + } +} \ No newline at end of file diff --git a/db/versions/11081-wheatRaphis/00-firstScript.sql b/db/versions/11081-wheatRaphis/00-firstScript.sql new file mode 100644 index 000000000..70bbaabdb --- /dev/null +++ b/db/versions/11081-wheatRaphis/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.roadmap ADD kmStart mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD kmEnd mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD started DATETIME NULL; +ALTER TABLE vn.roadmap ADD finished DATETIME NULL; diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js new file mode 100644 index 000000000..828dbb689 --- /dev/null +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -0,0 +1,62 @@ +module.exports = Self => { + Self.remoteMethod('getPalletMatchState', { + description: 'Get list of pallet from truckFk with true or false if state is matched', + accessType: 'WRITE', + accepts: [{ + arg: 'truckFk', + type: 'number', + required: true, + description: 'The truckFk id' + }, + { + arg: 'state', + type: 'string', + required: true, + description: 'State code' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getPalletMatchState`, + verb: 'GET' + } + }); + + Self.getPalletMatchState = async(truckFk, state, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const result = await Self.rawSql(` + WITH tPallet AS( + SELECT ep.id pallet, e.id expedition, e.stateTypeFk + FROM vn.expeditionPallet ep + JOIN vn.expeditionScan es ON es.palletFk = ep.id + JOIN expedition e ON e.id = es.expeditionFk + WHERE ep.truckFk = ? + ),totalPalletExpedition AS( + SELECT t.*, COUNT(expedition) totalPalletExpedition + FROM tPallet t + GROUP BY expedition + ),totalPalletExpeditionCode AS( + SELECT t.*, COUNT(expedition) totalPalletExpeditionCode + FROM tPallet t + JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk + WHERE code = ? + GROUP BY expedition + ) + SELECT t.pallet, + tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode + FROM tPallet t + LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition + LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition + GROUP BY t.pallet;`, + [truckFk, state], + myOptions); + + return result; + }; +}; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js new file mode 100644 index 000000000..4a79b589e --- /dev/null +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -0,0 +1,12 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('roadMapStop getPalletMatchState()', () => { + it('should return list of pallet with true or false if state is matched', async() => { + const truckFk = 1; + const state = 'ON DELIVERY'; + const result = await models.RoadmapStop.getPalletMatchState(truckFk, state); + + expect(result[0].hasMatchStateCode).toBe(1); + }); +}); diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index 01572d718..5321af7c3 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmap" + "table": "roadmap" } }, "properties": { @@ -41,10 +41,22 @@ }, "driverName": { "type": "string" + }, + "kmStart": { + "type": "number" + }, + "kmEnd": { + "type": "number" + }, + "started": { + "type": "date" + }, + "finished": { + "type": "date" } }, - "relations": { - "worker": { + "relations": { + "worker": { "type": "belongsTo", "model": "Worker", "foreignKey": "id" @@ -57,7 +69,7 @@ "roadmapStop": { "type": "hasMany", "model": "RoadmapStop", - "foreignKey": "roadmapFk" + "foreignKey": "roadMapFk" } - } -} + } +} \ No newline at end of file diff --git a/modules/route/back/models/roadmapStop.js b/modules/route/back/models/roadmapStop.js new file mode 100644 index 000000000..9e286776d --- /dev/null +++ b/modules/route/back/models/roadmapStop.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/roadmapStop/getPalletMatchState')(Self); +}; diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 74b02cd7a..93eae0113 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmapStop" + "table": "roadmapStop" } }, "properties": { @@ -28,16 +28,16 @@ "type": "number" } }, - "relations": { - "roadmap": { + "relations": { + "roadmap": { "type": "belongsTo", "model": "Roadmap", "foreignKey": "roadmapFk" }, "address": { "type": "belongsTo", - "model": "Address", + "model": "RoadmapAddress", "foreignKey": "addressFk" } - } -} + } +} \ No newline at end of file