|
@@ -10,6 +10,7 @@
|
|
|
|
|
|
const auditConst = require('../const/audit').material;
|
|
const auditConst = require('../const/audit').material;
|
|
const materialConst = require('../const/material');
|
|
const materialConst = require('../const/material');
|
|
|
|
+const MaterialCalculator = require('../lib/material_calc');
|
|
|
|
|
|
module.exports = app => {
|
|
module.exports = app => {
|
|
class MaterialBills extends app.BaseService {
|
|
class MaterialBills extends app.BaseService {
|
|
@@ -88,15 +89,8 @@ module.exports = app => {
|
|
// 判断t_type是否为费用
|
|
// 判断t_type是否为费用
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
- if (data.t_type === materialConst.t_type[0].value) {
|
|
|
|
- data.quantity = null;
|
|
|
|
- data.expr = null;
|
|
|
|
- }
|
|
|
|
await transaction.update(this.tableName, data);
|
|
await transaction.update(this.tableName, data);
|
|
- let m_tp = this.ctx.material.m_tp;
|
|
|
|
- if (data.t_type === materialConst.t_type[1].value) {
|
|
|
|
- m_tp = await this.calcMaterialMTp(transaction);
|
|
|
|
- }
|
|
|
|
|
|
+ const m_tp = await this.calcMaterialMTp(transaction);
|
|
await transaction.commit();
|
|
await transaction.commit();
|
|
return m_tp;
|
|
return m_tp;
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -112,11 +106,12 @@ module.exports = app => {
|
|
* @param mid
|
|
* @param mid
|
|
* @returns {Promise<number>}
|
|
* @returns {Promise<number>}
|
|
*/
|
|
*/
|
|
- async updateNewMaterial(transaction, tid, mid) {
|
|
|
|
|
|
+ async updateNewMaterial(transaction, tid, mid, ctx, stage_id) {
|
|
const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
|
|
const materialBillsData = await this.getAllDataByCondition({ where: { tid } });
|
|
let m_tp = 0;
|
|
let m_tp = 0;
|
|
|
|
+ const materialCalculator = new MaterialCalculator(ctx, stage_id, ctx.tender.info);
|
|
for (const mb of materialBillsData) {
|
|
for (const mb of materialBillsData) {
|
|
- const one_tp = await this.calcQuantityByMB(transaction, mid, mb);
|
|
|
|
|
|
+ const one_tp = await this.calcQuantityByMB(transaction, mid, mb, materialCalculator);
|
|
m_tp = this.ctx.helper.add(m_tp, one_tp);
|
|
m_tp = this.ctx.helper.add(m_tp, one_tp);
|
|
}
|
|
}
|
|
return m_tp;
|
|
return m_tp;
|
|
@@ -129,7 +124,7 @@ module.exports = app => {
|
|
* @param mb
|
|
* @param mb
|
|
* @returns {Promise<*>}
|
|
* @returns {Promise<*>}
|
|
*/
|
|
*/
|
|
- async calcQuantityByMB(transaction, mid, mb) {
|
|
|
|
|
|
+ async calcQuantityByMB(transaction, mid, mb, materialCalculator) {
|
|
if (mb.t_type === materialConst.t_type[0].value) {
|
|
if (mb.t_type === materialConst.t_type[0].value) {
|
|
const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
|
|
const sql = 'SELECT SUM(`gather_qty`*`quantity`) as quantity FROM ' + this.ctx.service.materialList.tableName + ' WHERE `mid`=? AND `mb_id`=? AND `is_join`=1';
|
|
const sqlParam = [mid, mb.id];
|
|
const sqlParam = [mid, mb.id];
|
|
@@ -144,12 +139,14 @@ module.exports = app => {
|
|
await transaction.update(this.tableName, updateData);
|
|
await transaction.update(this.tableName, updateData);
|
|
return await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, mb.m_spread), 2);
|
|
return await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, mb.m_spread), 2);
|
|
} else if (mb.t_type === materialConst.t_type[1].value) {
|
|
} else if (mb.t_type === materialConst.t_type[1].value) {
|
|
|
|
+ const quantity = await materialCalculator.calculateExpr(mb.expr);
|
|
const updateData = {
|
|
const updateData = {
|
|
id: mb.id,
|
|
id: mb.id,
|
|
|
|
+ quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, 3) : null,
|
|
pre_tp: mb.quantity && mb.m_spread !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, this.ctx.helper.mul(mb.quantity, mb.m_spread)), 2) : mb.pre_tp,
|
|
pre_tp: mb.quantity && mb.m_spread !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, this.ctx.helper.mul(mb.quantity, mb.m_spread)), 2) : mb.pre_tp,
|
|
};
|
|
};
|
|
await transaction.update(this.tableName, updateData);
|
|
await transaction.update(this.tableName, updateData);
|
|
- return await this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, mb.m_spread), 2);
|
|
|
|
|
|
+ return await this.ctx.helper.round(this.ctx.helper.mul(quantity, mb.m_spread), 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|