diff --git a/modules/client/back/methods/client/extendedListFilter.js b/modules/client/back/methods/client/extendedListFilter.js
index 8e02cd413..27bbe2a35 100644
--- a/modules/client/back/methods/client/extendedListFilter.js
+++ b/modules/client/back/methods/client/extendedListFilter.js
@@ -97,7 +97,7 @@ module.exports = Self => {
const stmts = [];
const stmt = new ParameterizedSQL(
- `SELECT
+ `SELECT
c.id,
c.name,
c.socialName,
diff --git a/modules/travel/back/methods/travel/extraCommunityPdf.js b/modules/travel/back/methods/travel/extraCommunityPdf.js
index a68e5cd09..c3577d910 100644
--- a/modules/travel/back/methods/travel/extraCommunityPdf.js
+++ b/modules/travel/back/methods/travel/extraCommunityPdf.js
@@ -11,6 +11,16 @@ module.exports = Self => {
description: 'The recipient id',
required: false
},
+ {
+ arg: 'filter',
+ type: 'object',
+ description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
+ },
+ {
+ arg: 'search',
+ type: 'string',
+ description: 'Searchs the travel by id'
+ },
{
arg: 'landedTo',
type: 'date'
diff --git a/modules/travel/front/extra-community/index.js b/modules/travel/front/extra-community/index.js
index 920339469..2028c9c19 100644
--- a/modules/travel/front/extra-community/index.js
+++ b/modules/travel/front/extra-community/index.js
@@ -141,8 +141,11 @@ class Controller extends Section {
get reportParams() {
const userParams = this.$.model.userParams;
+ const currentFilter = this.$.model.currentFilter;
+
return Object.assign({
- authorization: this.vnToken.token
+ authorization: this.vnToken.token,
+ filter: currentFilter
}, userParams);
}
diff --git a/print/templates/reports/extra-community/extra-community.html b/print/templates/reports/extra-community/extra-community.html
index cd61a4f4d..3153b6b03 100644
--- a/print/templates/reports/extra-community/extra-community.html
+++ b/print/templates/reports/extra-community/extra-community.html
@@ -51,7 +51,7 @@
{{entry.supplierName}} |
{{entry.reference}} |
{{entry.volumeKg | number($i18n.locale)}} |
- {{entry.loadedKg | number($i18n.locale)}} |
+ {{entry.loadedkg | number($i18n.locale)}} |
{{entry.stickers}} |
diff --git a/print/templates/reports/extra-community/extra-community.js b/print/templates/reports/extra-community/extra-community.js
index 9941faa35..5d875d78f 100755
--- a/print/templates/reports/extra-community/extra-community.js
+++ b/print/templates/reports/extra-community/extra-community.js
@@ -1,11 +1,12 @@
const vnReport = require('../../../core/mixins/vn-report.js');
-const db = require(`vn-print/core/database`);
+const app = require('vn-loopback/server/server');
module.exports = {
name: 'extra-community',
mixins: [vnReport],
async serverPrefetch() {
const args = {
+ search: this.search,
landedTo: this.landedEnd,
shippedFrom: this.shippedStart,
continent: this.continent,
@@ -17,76 +18,24 @@ module.exports = {
ref: this.ref,
cargoSupplierFk: this.cargoSupplierFk
};
-
- const travels = await this.fetchTravels(args);
- this.checkMainEntity(travels);
- const travelIds = travels.map(travel => travel.id);
- const entries = await this.rawSqlFromDef('entries', [travelIds]);
-
- const map = new Map();
- for (let travel of travels)
- map.set(travel.id, travel);
-
- for (let entry of entries) {
- const travel = map.get(entry.travelFk);
- if (!travel.entries) travel.entries = [];
- travel.entries.push(entry);
- }
-
- this.travels = travels;
+ const ctx = {args: args};
+ this.travels = await app.models.Travel.extraCommunityFilter(ctx, this.filter);
},
computed: {
landedEnd: function() {
if (!this.landedTo) return;
- return formatDate(this.landedTo, '%Y-%m-%d');
+ return this.formatDate(this.landedTo, '%Y-%m-%d');
},
shippedStart: function() {
if (!this.shippedFrom) return;
- return formatDate(this.shippedFrom, '%Y-%m-%d');
+ return this.formatDate(this.shippedFrom, '%Y-%m-%d');
}
},
methods: {
- fetchTravels(args) {
- const where = db.buildWhere(args, (key, value) => {
- switch (key) {
- case 'shippedFrom':
- return `t.shipped >= ${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 'agencyModeFk':
- 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);
- },
},
props: [
+ 'filter',
+ 'search',
'landedTo',
'shippedFrom',
'continent',
diff --git a/print/templates/reports/extra-community/sql/entries.sql b/print/templates/reports/extra-community/sql/entries.sql
deleted file mode 100644
index 84dc497c0..000000000
--- a/print/templates/reports/extra-community/sql/entries.sql
+++ /dev/null
@@ -1,18 +0,0 @@
-SELECT
- e.id,
- e.travelFk,
- e.reference,
- s.name AS supplierName,
- SUM(b.stickers) AS stickers,
- CAST(SUM(b.weight * b.stickers) as DECIMAL(10,0)) as loadedKg,
- CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) as DECIMAL(10,0)) as volumeKg
- FROM travel t
- JOIN entry e ON e.travelFk = t.id
- JOIN buy b ON b.entryFk = e.id
- JOIN packaging pkg ON pkg.id = b.packageFk
- JOIN item i ON i.id = b.itemFk
- JOIN itemType it ON it.id = i.typeFk
- JOIN supplier s ON s.id = e.supplierFk
- JOIN vn.volumeConfig vc
- WHERE t.id IN(?)
- GROUP BY e.id
diff --git a/print/templates/reports/extra-community/sql/travels.sql b/print/templates/reports/extra-community/sql/travels.sql
deleted file mode 100644
index b0987c330..000000000
--- a/print/templates/reports/extra-community/sql/travels.sql
+++ /dev/null
@@ -1,23 +0,0 @@
-SELECT
- t.id,
- t.ref,
- t.shipped,
- t.landed,
- t.kg,
- am.id AS agencyModeFk,
- SUM(b.stickers) AS stickers,
- CAST(SUM(b.weight * b.stickers) as DECIMAL(10,0)) as loadedKg,
- CAST(SUM(vc.aerealVolumetricDensity * b.stickers * IF(pkg.volume, pkg.volume, pkg.width * pkg.depth * pkg.height) / 1000000) as DECIMAL(10,0)) as volumeKg
-FROM travel t
- JOIN volumeConfig vc
- LEFT JOIN supplier s ON s.id = t.cargoSupplierFk
- LEFT JOIN entry e ON e.travelFk = t.id
- LEFT JOIN buy b ON b.entryFk = e.id
- LEFT JOIN packaging pkg ON pkg.id = b.packageFk
- LEFT JOIN item i ON i.id = b.itemFk
- LEFT JOIN itemType it ON it.id = i.typeFk
- JOIN warehouse w ON w.id = t.warehouseInFk
- JOIN warehouse wo ON wo.id = t.warehouseOutFk
- JOIN country c ON c.id = wo.countryFk
- LEFT JOIN continent cnt ON cnt.id = c.continentFk
- JOIN agencyMode am ON am.id = t.agencyModeFk
\ No newline at end of file