refactor: el report llama directamente al filtro de extra-community
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-03-14 09:59:29 +01:00
parent d9f4227ffa
commit 50ccb61728
7 changed files with 24 additions and 103 deletions

View File

@ -97,7 +97,7 @@ module.exports = Self => {
const stmts = [];
const stmt = new ParameterizedSQL(
`SELECT
`SELECT
c.id,
c.name,
c.socialName,

View File

@ -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'

View File

@ -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);
}

View File

@ -51,7 +51,7 @@
<td>{{entry.supplierName}}</td>
<td>{{entry.reference}}</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>
</tr>
<tr v-if="!travel.entries">

View File

@ -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',

View File

@ -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

View File

@ -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