Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2985-invoiceOut_manual

This commit is contained in:
Carlos Jimenez Ruiz 2021-08-06 13:30:14 +02:00
commit a9b2e45683
1 changed files with 39 additions and 12 deletions

View File

@ -28,30 +28,57 @@ module.exports = Self => {
});
Self.getItemTypeAvailable = async(orderId, itemCategoryId) => {
let stmts = [];
const stmts = [];
let stmt;
let order = await app.models.Order.findById(orderId);
const order = await app.models.Order.findById(orderId);
stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [
order.landed,
order.addressFk,
order.agencyModeFk
]);
stmts.push(stmt);
stmt = new ParameterizedSQL(`
SELECT it.id, it.name, ic.name categoryName
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item');
stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.item
(PRIMARY KEY (itemFk)) ENGINE = MEMORY
SELECT DISTINCT
i.id AS itemFk,
it.id AS typeFk,
it.name,
ic.name AS categoryName
FROM tmp.availableCalc ac
JOIN cache.available a ON a.calc_id = ac.calcFk
JOIN item i ON i.id = a.item_id
JOIN itemType it ON it.id = i.typeFk
JOIN itemCategory ic ON ic.id = it.categoryFk
WHERE it.categoryFk = ?
GROUP BY it.id`, [itemCategoryId]
JOIN vn.item i ON i.id = a.item_id
JOIN vn.itemType it ON it.id = i.typeFk
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
WHERE it.categoryFk = ?`, [itemCategoryId]
);
let categoriesIndex = stmts.push(stmt) - 1;
stmts.push(stmt);
let sql = ParameterizedSQL.join(stmts, ';');
let result = await Self.rawStmt(sql);
stmt = new ParameterizedSQL(
'CALL vn.catalog_calculate(?, ?, ?)', [
order.landed,
order.addressFk,
order.agencyModeFk,
]
);
stmts.push(stmt);
stmt = new ParameterizedSQL(`
SELECT i.typeFk AS id, i.name, i.categoryName
FROM tmp.item i
JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.itemFk
GROUP BY i.typeFk`
);
const categoriesIndex = stmts.push(stmt) - 1;
stmts.push('DROP TEMPORARY TABLE tmp.item');
const sql = ParameterizedSQL.join(stmts, ';');
const result = await Self.rawStmt(sql);
return result[categoriesIndex];
};