2956 - Fix for extra community report #659

Merged
carlosjr merged 2 commits from 2956-extraCommunity_hotfix into master 2021-06-16 11:16:10 +00:00
4 changed files with 45 additions and 60 deletions

View File

@ -24,7 +24,7 @@ module.exports = {
*
* @return {Object} - Pool connection
*/
getConnection(name) {
getConnection(name = 'default') {
let pool = this.pool;
return new Promise((resolve, reject) => {
pool.getConnection(name, function(error, connection) {

View File

@ -15,22 +15,11 @@ module.exports = {
continent: this.continent
};
const connection = await db.pool.getConnection();
await this.fetchTravels(args, connection);
const travels = await this.rawSql(`
SELECT * FROM tmp.travel`, connection);
const entries = await this.fetchEntries(connection);
await this.rawSql(`
DROP TEMPORARY TABLE
tmp.travel`, connection);
await connection.release();
const travels = await this.fetchTravels(args);
const travelIds = travels.map(travel => travel.id);
const entries = await this.fetchEntries(travelIds);
const map = new Map();
for (let travel of travels)
map.set(travel.id, travel);
@ -71,7 +60,7 @@ module.exports = {
}
},
methods: {
fetchTravels(args, connection) {
fetchTravels(args) {
const where = db.buildWhere(args, (key, value) => {
switch (key) {
case 'shippedFrom':
@ -91,14 +80,11 @@ module.exports = {
query = db.merge(query, where);
query = db.merge(query, 'GROUP BY t.id');
return this.rawSql(query, connection);
return this.rawSql(query);
},
fetchEntries(connection) {
let query = this.getSqlFromDef('entries');
query = db.merge(query, 'GROUP BY e.id');
return this.rawSql(query, connection);
fetchEntries(travelIds) {
return this.rawSqlFromDef('entries', [travelIds]);
}
},
components: {

View File

@ -6,10 +6,12 @@ SELECT
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
FROM tmp.travel t
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
WHERE t.id IN(?)
GROUP BY e.id

View File

@ -1,7 +1,4 @@
CREATE TEMPORARY TABLE tmp.travel
(INDEX (id))
ENGINE = MEMORY
SELECT
SELECT
t.id,
t.ref,
t.shipped,
@ -10,7 +7,7 @@ CREATE TEMPORARY TABLE tmp.travel
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
FROM travel t
FROM travel t
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