Merge pull request '4980-travel.extra-community_filterToReport' (!1391) from 4980-travel.extra-community_filterToReport into dev
Reviewed-on: #1391 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
e911f7a127
|
@ -97,7 +97,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT
|
`SELECT
|
||||||
c.id,
|
c.id,
|
||||||
c.name,
|
c.name,
|
||||||
c.socialName,
|
c.socialName,
|
||||||
|
|
|
@ -9,6 +9,16 @@ module.exports = Self => {
|
||||||
description: 'The recipient id',
|
description: 'The recipient id',
|
||||||
required: false
|
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',
|
arg: 'landedTo',
|
||||||
type: 'date'
|
type: 'date'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="Travels/extraCommunityFilter"
|
url="Travels/extraCommunityFilter"
|
||||||
filter="::$ctrl.filter"
|
user-params="::$ctrl.defaultFilter"
|
||||||
data="travels"
|
data="travels"
|
||||||
order="shipped ASC, landed ASC, travelFk, loadPriority, agencyModeFk, evaNotes"
|
order="shipped ASC, landed ASC, travelFk, loadPriority, agencyModeFk, evaNotes"
|
||||||
limit="20"
|
limit="20"
|
||||||
|
|
|
@ -141,8 +141,11 @@ class Controller extends Section {
|
||||||
|
|
||||||
get reportParams() {
|
get reportParams() {
|
||||||
const userParams = this.$.model.userParams;
|
const userParams = this.$.model.userParams;
|
||||||
|
const currentFilter = this.$.model.currentFilter;
|
||||||
|
|
||||||
return Object.assign({
|
return Object.assign({
|
||||||
authorization: this.vnToken.token
|
authorization: this.vnToken.token,
|
||||||
|
filter: currentFilter
|
||||||
}, userParams);
|
}, userParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
<td>{{entry.supplierName}}</td>
|
<td>{{entry.supplierName}}</td>
|
||||||
<td>{{entry.reference}}</td>
|
<td>{{entry.reference}}</td>
|
||||||
<td class="number">{{entry.volumeKg | number($i18n.locale)}}</td>
|
<td class="number">{{entry.volumeKg | number($i18n.locale)}}</td>
|
||||||
<td class="number">{{entry.loadedKg | number($i18n.locale)}}</td>
|
<td class="number">{{entry.loadedkg | number($i18n.locale)}}</td>
|
||||||
<td class="number">{{entry.stickers}}</td>
|
<td class="number">{{entry.stickers}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="!travel.entries">
|
<tr v-if="!travel.entries">
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
const vnReport = require('../../../core/mixins/vn-report.js');
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
||||||
const db = require(`vn-print/core/database`);
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'extra-community',
|
name: 'extra-community',
|
||||||
mixins: [vnReport],
|
mixins: [vnReport],
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
const args = {
|
const args = {
|
||||||
|
search: this.search,
|
||||||
landedTo: this.landedEnd,
|
landedTo: this.landedEnd,
|
||||||
shippedFrom: this.shippedStart,
|
shippedFrom: this.shippedStart,
|
||||||
continent: this.continent,
|
continent: this.continent,
|
||||||
|
@ -17,76 +18,24 @@ module.exports = {
|
||||||
ref: this.ref,
|
ref: this.ref,
|
||||||
cargoSupplierFk: this.cargoSupplierFk
|
cargoSupplierFk: this.cargoSupplierFk
|
||||||
};
|
};
|
||||||
|
const ctx = {args: args};
|
||||||
const travels = await this.fetchTravels(args);
|
this.travels = await app.models.Travel.extraCommunityFilter(ctx, this.filter);
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
landedEnd: function() {
|
landedEnd: function() {
|
||||||
if (!this.landedTo) return;
|
if (!this.landedTo) return;
|
||||||
return formatDate(this.landedTo, '%Y-%m-%d');
|
return this.formatDate(this.landedTo, '%Y-%m-%d');
|
||||||
},
|
},
|
||||||
shippedStart: function() {
|
shippedStart: function() {
|
||||||
if (!this.shippedFrom) return;
|
if (!this.shippedFrom) return;
|
||||||
return formatDate(this.shippedFrom, '%Y-%m-%d');
|
return this.formatDate(this.shippedFrom, '%Y-%m-%d');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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: [
|
props: [
|
||||||
|
'filter',
|
||||||
|
'search',
|
||||||
'landedTo',
|
'landedTo',
|
||||||
'shippedFrom',
|
'shippedFrom',
|
||||||
'continent',
|
'continent',
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
Loading…
Reference in New Issue