diff --git a/modules/travel/back/methods/travel/extraCommunityFilter.js b/modules/travel/back/methods/travel/extraCommunityFilter.js index f4132c631..af6e1ec0a 100644 --- a/modules/travel/back/methods/travel/extraCommunityFilter.js +++ b/modules/travel/back/methods/travel/extraCommunityFilter.js @@ -28,16 +28,6 @@ module.exports = Self => { type: 'date', description: 'The shipped from date filter' }, - { - arg: 'shippedTo', - type: 'date', - description: 'The shipped to date filter' - }, - { - arg: 'landedFrom', - type: 'date', - description: 'The landed from date filter' - }, { arg: 'landedTo', type: 'date', @@ -101,10 +91,6 @@ module.exports = Self => { return {'t.ref': {like: `%${value}%`}}; case 'shippedFrom': return {'t.shipped': {gte: value}}; - case 'shippedTo': - return {'t.shipped': {lte: value}}; - case 'landedFrom': - return {'t.landed': {gte: value}}; case 'landedTo': return {'t.landed': {lte: value}}; case 'continent': @@ -162,6 +148,7 @@ module.exports = Self => { stmt.merge(conn.makeWhere(filter.where)); stmt.merge(conn.makeGroupBy('t.id')); + stmt.merge(conn.makeOrderBy(filter.order)); stmt.merge(conn.makeLimit(filter)); stmts.push(stmt); diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 7f42eb5f0..b74160efe 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -46,15 +46,64 @@ describe('Travel extraCommunityFilter()', () => { expect(result.length).toEqual(3); }); - it('should return the routes matching "landed from" and "landed to"', async() => { - const from = new Date(); - const to = new Date(); - from.setHours(0, 0, 0, 0); - to.setHours(23, 59, 59, 999); - to.setDate(to.getDate() + 14); + it('should return the travel matching "warehouse in"', async() => { const ctx = { args: { - landedFrom: from, + warehouseInFk: 1 + } + }; + + const result = await app.models.Travel.extraCommunityFilter(ctx, filter); + + expect(result.length).toEqual(4); + }); + + it('should return the travel matching "continent"', async() => { + const ctx = { + args: { + continent: 'AM' + } + }; + + const result = await app.models.Travel.extraCommunityFilter(ctx, filter); + + expect(result.length).toEqual(3); + }); + + it('should return the travel matching "agencyFk"', async() => { + const ctx = { + args: { + agencyFk: 1 + } + }; + + const result = await app.models.Travel.extraCommunityFilter(ctx, filter); + + expect(result.length).toEqual(8); + }); + + it('should return the travel matching "cargoSupplierFk"', async() => { + const ctx = { + args: { + cargoSupplierFk: 1 + } + }; + + const result = await app.models.Travel.extraCommunityFilter(ctx, filter); + + expect(result.length).toEqual(4); + }); + + it('should return the routes matching "shipped from" and "landed to"', async() => { + const from = new Date(); + from.setDate(from.getDate() - 2); + from.setHours(0, 0, 0, 0); + const to = new Date(); + to.setHours(23, 59, 59, 999); + to.setDate(to.getDate() + 7); + const ctx = { + args: { + shippedFrom: from, landedTo: to } }; diff --git a/modules/travel/front/extra-community-search-panel/index.html b/modules/travel/front/extra-community-search-panel/index.html index 55b1f87b1..8e51acc15 100644 --- a/modules/travel/front/extra-community-search-panel/index.html +++ b/modules/travel/front/extra-community-search-panel/index.html @@ -47,17 +47,6 @@ ng-model="$ctrl.landedTo"> - - - - - diff --git a/modules/travel/front/extra-community/index.js b/modules/travel/front/extra-community/index.js index 44527d45e..a380c1ed8 100644 --- a/modules/travel/front/extra-community/index.js +++ b/modules/travel/front/extra-community/index.js @@ -17,16 +17,18 @@ class Controller extends Section { this.draggableElement = 'a[draggable]'; this.droppableElement = 'vn-tbody[vn-droppable]'; - const scopeDays = 14; - const landedFrom = new Date(); - landedFrom.setHours(0, 0, 0, 0); + const twoDays = 2; + const shippedFrom = new Date(); + shippedFrom.setDate(shippedFrom.getDate() - twoDays); + shippedFrom.setHours(0, 0, 0, 0); + const sevenDays = 7; const landedTo = new Date(); - landedTo.setDate(landedTo.getDate() + scopeDays); + landedTo.setDate(landedTo.getDate() + sevenDays); landedTo.setHours(23, 59, 59, 59); this.defaultFilter = { - landedFrom: landedFrom, + shippedFrom: shippedFrom, landedTo: landedTo, continent: 'AM' }; @@ -34,10 +36,12 @@ class Controller extends Section { get hasDateRange() { const userParams = this.$.model.userParams; - const hasLanded = userParams.landedFrom || userParams.landedTo; - const hasShipped = userParams.shippedFrom || userParams.shippedTo; + const hasLanded = userParams.landedTo; + const hasShipped = userParams.shippedFrom; + const hasContinent = userParams.continent; + const hasWarehouseOut = userParams.warehouseOutFk; - return hasLanded || hasShipped; + return hasLanded || hasShipped || hasContinent || hasWarehouseOut; } findDraggable($event) { diff --git a/modules/travel/front/extra-community/style.scss b/modules/travel/front/extra-community/style.scss index 41544242d..f903f94ea 100644 --- a/modules/travel/front/extra-community/style.scss +++ b/modules/travel/front/extra-community/style.scss @@ -9,8 +9,8 @@ vn-travel-extra-community { padding-bottom: 7px; padding-bottom: 4px; font-weight: lighter; - background-color: #fde6ca; - color: $color-font-light; + background-color: $color-bg; + color: white; border-bottom: 1px solid #f7931e; white-space: nowrap; overflow: hidden; diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js index c9d2fb2f3..9843d6bb7 100755 --- a/print/templates/reports/extra-community/extra-community.js +++ b/print/templates/reports/extra-community/extra-community.js @@ -8,11 +8,16 @@ module.exports = { async serverPrefetch() { this.filters = this.$options.filters; const args = { - landedFrom: this.landedStart, landedTo: this.landedEnd, shippedFrom: this.shippedStart, - shippedTo: this.shippedEnd, - continent: this.continent + continent: this.continent, + id: this.id, + agencyFk: this.agencyFk, + warehouseInFk: this.warehouseInFk, + warehouseOutFk: this.warehouseOutFk, + totalEntries: this.totalEntries, + ref: this.ref, + cargoSupplierFk: this.cargoSupplierFk }; const travels = await this.fetchTravels(args); @@ -38,11 +43,6 @@ module.exports = { dated: function() { return this.filters.date(new Date(), '%d-%m-%Y'); }, - landedStart: function() { - if (!this.landedFrom) return; - - return this.filters.date(this.landedFrom, '%Y-%m-%d'); - }, landedEnd: function() { if (!this.landedTo) return; @@ -52,11 +52,6 @@ module.exports = { if (!this.shippedFrom) return; return this.filters.date(this.shippedFrom, '%Y-%m-%d'); - }, - shippedEnd: function() { - if (!this.shippedTo) return; - - return this.filters.date(this.shippedTo, '%Y-%m-%d'); } }, methods: { @@ -65,20 +60,29 @@ module.exports = { switch (key) { case 'shippedFrom': return `t.shipped >= ${value}`; - case 'shippedTo': - return `t.shipped <= ${value}`; - case 'landedFrom': - return `t.landed >= ${value}`; case 'landedTo': return `t.landed <= ${value}`; case 'continent': return `cnt.code = ${value}`; + case 'ref': + return {'t.ref': {like: `%${value}%`}}; + case 'id': + return `t.id = ${value}`; + case 'agencyFk': + return `am.id = ${value}`; + case 'warehouseOutFk': + return `wo.id = ${value}`; + case 'warehouseInFk': + return `w.id = ${value}`; + case 'cargoSupplierFk': + return `s.id = ${value}`; } }); let query = this.getSqlFromDef('travels'); query = db.merge(query, where); query = db.merge(query, 'GROUP BY t.id'); + query = db.merge(query, 'ORDER BY `shipped` ASC, `landed` ASC, `travelFk`, `loadPriority`, `agencyModeFk`, `evaNotes`'); return this.rawSql(query); }, @@ -92,10 +96,15 @@ module.exports = { 'report-footer': reportFooter.build() }, props: [ - 'landedFrom', 'landedTo', 'shippedFrom', - 'shippedTo', - 'continent' + 'continent', + 'ref', + 'id', + 'agencyFk', + 'warehouseOutFk', + 'warehouseInFk', + 'totalEntries', + 'cargoSupplierFk' ] }; diff --git a/print/templates/reports/extra-community/sql/travels.sql b/print/templates/reports/extra-community/sql/travels.sql index 022767608..167c8b1f8 100644 --- a/print/templates/reports/extra-community/sql/travels.sql +++ b/print/templates/reports/extra-community/sql/travels.sql @@ -4,6 +4,7 @@ SELECT t.shipped, t.landed, t.kg, + am.id AS agencyModeFk, SUM(b.stickers) AS stickers, CAST(SUM(i.density * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as loadedKg, CAST(SUM(167.5 * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000 ) as DECIMAL(10,0)) as volumeKg