2023-01-23 12:15:30 +00:00
|
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
2022-09-26 11:33:27 +00:00
|
|
|
const db = require(`vn-print/core/database`);
|
2021-01-18 07:33:20 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'extra-community',
|
2023-01-23 12:15:30 +00:00
|
|
|
mixins: [vnReport],
|
2021-01-18 07:33:20 +00:00
|
|
|
async serverPrefetch() {
|
|
|
|
const args = {
|
|
|
|
landedTo: this.landedEnd,
|
|
|
|
shippedFrom: this.shippedStart,
|
2022-03-28 09:57:19 +00:00
|
|
|
continent: this.continent,
|
2022-03-28 11:24:26 +00:00
|
|
|
id: this.id,
|
2022-07-14 05:33:32 +00:00
|
|
|
agencyModeFk: this.agencyModeFk,
|
2022-03-28 11:24:26 +00:00
|
|
|
warehouseInFk: this.warehouseInFk,
|
|
|
|
warehouseOutFk: this.warehouseOutFk,
|
|
|
|
totalEntries: this.totalEntries,
|
|
|
|
ref: this.ref,
|
|
|
|
cargoSupplierFk: this.cargoSupplierFk
|
2021-01-18 07:33:20 +00:00
|
|
|
};
|
|
|
|
|
2021-06-16 11:04:54 +00:00
|
|
|
const travels = await this.fetchTravels(args);
|
2023-01-23 12:15:30 +00:00
|
|
|
this.checkMainEntity(travels);
|
2021-06-16 11:14:13 +00:00
|
|
|
const travelIds = travels.map(travel => travel.id);
|
2023-01-23 12:15:30 +00:00
|
|
|
const entries = await this.rawSqlFromDef('entries', [travelIds]);
|
2021-01-18 07:33:20 +00:00
|
|
|
|
|
|
|
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: {
|
|
|
|
landedEnd: function() {
|
|
|
|
if (!this.landedTo) return;
|
2023-01-23 12:15:30 +00:00
|
|
|
return formatDate(this.landedTo, '%Y-%m-%d');
|
2021-01-18 07:33:20 +00:00
|
|
|
},
|
|
|
|
shippedStart: function() {
|
|
|
|
if (!this.shippedFrom) return;
|
2023-01-23 12:15:30 +00:00
|
|
|
return formatDate(this.shippedFrom, '%Y-%m-%d');
|
2021-01-18 07:33:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-06-16 11:04:54 +00:00
|
|
|
fetchTravels(args) {
|
2021-01-18 07:33:20 +00:00
|
|
|
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}`;
|
2022-03-28 11:24:26 +00:00
|
|
|
case 'ref':
|
|
|
|
return {'t.ref': {like: `%${value}%`}};
|
|
|
|
case 'id':
|
|
|
|
return `t.id = ${value}`;
|
2022-07-14 05:33:32 +00:00
|
|
|
case 'agencyModeFk':
|
2022-03-28 11:24:26 +00:00
|
|
|
return `am.id = ${value}`;
|
2022-03-28 09:57:19 +00:00
|
|
|
case 'warehouseOutFk':
|
|
|
|
return `wo.id = ${value}`;
|
2022-03-28 11:24:26 +00:00
|
|
|
case 'warehouseInFk':
|
|
|
|
return `w.id = ${value}`;
|
|
|
|
case 'cargoSupplierFk':
|
|
|
|
return `s.id = ${value}`;
|
2021-01-18 07:33:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let query = this.getSqlFromDef('travels');
|
|
|
|
query = db.merge(query, where);
|
|
|
|
query = db.merge(query, 'GROUP BY t.id');
|
2022-09-26 11:33:27 +00:00
|
|
|
query = db.merge(query, `
|
2023-01-23 12:15:30 +00:00
|
|
|
ORDER BY
|
|
|
|
shipped ASC,
|
|
|
|
landed ASC,
|
|
|
|
travelFk,
|
|
|
|
loadPriority,
|
|
|
|
agencyModeFk,
|
2022-09-26 11:33:27 +00:00
|
|
|
evaNotes
|
|
|
|
`);
|
2021-01-18 07:33:20 +00:00
|
|
|
|
2021-06-16 11:04:54 +00:00
|
|
|
return this.rawSql(query);
|
2021-01-18 07:33:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
props: [
|
|
|
|
'landedTo',
|
|
|
|
'shippedFrom',
|
2022-03-28 09:57:19 +00:00
|
|
|
'continent',
|
2022-09-29 05:35:20 +00:00
|
|
|
'reference',
|
2022-03-28 11:24:26 +00:00
|
|
|
'id',
|
2022-07-14 05:33:32 +00:00
|
|
|
'agencyModeFk',
|
2022-03-28 11:24:26 +00:00
|
|
|
'warehouseOutFk',
|
|
|
|
'warehouseInFk',
|
|
|
|
'totalEntries',
|
|
|
|
'cargoSupplierFk'
|
2021-01-18 07:33:20 +00:00
|
|
|
]
|
|
|
|
};
|