filter modified to get the prices of a product

This commit is contained in:
gerard 2018-08-10 16:15:17 +02:00
parent 9b2a2b7a9f
commit 3875f4298c
1 changed files with 23 additions and 3 deletions

View File

@ -25,17 +25,37 @@ module.exports = Self => {
let order = await Self.findById(where.id);
let stmt = `CALL vn2008.bionic_from_type(?, ?, ?, ?);
SELECT bi.*, i.* FROM tmp.bionic_item bi
SELECT bi.*, i.*, w.name AS workerName, w.firstName AS workerFirstName FROM tmp.bionic_item bi
JOIN vn.item i ON i.id = bi.item_id
ORDER BY relevancy DESC, item_id ASC, producer DESC;`;
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.worker w on w.id = it.workerFk
ORDER BY relevancy DESC, item_id ASC, producer DESC;
SELECT pri.*, w.name AS warehouseName FROM tmp.bionic_price pri
JOIN vn.warehouse w ON w.id = pri.warehouse_id;`;
let [rs, items] = await Self.rawSql(stmt, [
let [rs, items, prices] = await Self.rawSql(stmt, [
order.landed,
order.address_id,
order.agency_id,
where.typeFk
]);
if (items) {
items.forEach(item => {
prices.forEach(price => {
if (item.item_id === price.item_id) {
if (item.prices) {
item.prices.push(price);
} else {
item.prices = [price];
}
item.disponible = price.grouping;
}
});
});
}
return items;
};
};