|
@@ -142,31 +142,25 @@ module.exports = app => {
|
|
|
const materialStageBillsList = await this.getAllDataByCondition({ where: { ms_id, mb_id: this._.map(bills, 'id') } });
|
|
|
const updateDatas = [];
|
|
|
let needUpdateTp = false;
|
|
|
- const updateBillsDatas = [];
|
|
|
+ const updateBillIds = [];
|
|
|
for (const m of materialStageBillsList) {
|
|
|
const oneBill = this._.find(bills, { id: m.mb_id });
|
|
|
const oneData = this._.find(datas, function(item) {
|
|
|
- return item.code.toString() === oneBill.code.toString() && item.name === oneBill.name && item.unit === oneBill.unit && (!includeSpec || (includeSpec && item.spec === oneBill.spec));
|
|
|
+ return item.code.toString() === oneBill.code.toString() && item.name === oneBill.name && item.unit === oneBill.unit &&
|
|
|
+ (!includeSpec || (includeSpec && (item.spec === null ? '' : item.spec).toString() === (oneBill.spec === null ? '' : oneBill.spec).toString()));
|
|
|
});
|
|
|
const upd = { id: m.id };
|
|
|
if (oneData.msg_tp !== m.msg_tp) {
|
|
|
needUpdateTp = true;
|
|
|
upd.msg_tp = oneData.msg_tp;
|
|
|
- const [newmsg_spread, newm_spread] = await this.getSpread(m, oneData.msg_tp);
|
|
|
+ const [newmsg_spread, newm_spread] = await this.getSpread(oneBill, oneData.msg_tp);
|
|
|
upd.msg_spread = newmsg_spread;
|
|
|
upd.m_spread = newm_spread;
|
|
|
const newTp = this.ctx.helper.round(this.ctx.helper.mul(m.quantity, newm_spread), this.ctx.material.decimal.tp);
|
|
|
upd.m_tp = newTp;
|
|
|
upd.m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(oneBill.m_tax, 100))), this.ctx.material.decimal.tp);
|
|
|
- // 金额发生变化,返回重新计算本期这条工料的金额
|
|
|
- const sql = 'SELECT SUM(`m_tp`) as total_price, SUM(IF(`m_tax_tp` is null, `m_tp`, `m_tax_tp`)) as tax_total_price' +
|
|
|
- ' FROM ' + this.tableName + ' WHERE `tid` = ? AND `mid` = ? AND `mb_id` = ? AND `is_summary` = 1';
|
|
|
- const sqlParam = [this.ctx.tender.id, this.ctx.material.id, m.id];
|
|
|
- const tp = await transaction.queryOne(sql, sqlParam);
|
|
|
- updateBillsDatas.push({
|
|
|
- id: m.id,
|
|
|
- m_tp: tp.total_price,
|
|
|
- m_tax_tp: tp.tax_total_price,
|
|
|
+ updateBillIds.push({
|
|
|
+ id: oneBill.id,
|
|
|
});
|
|
|
}
|
|
|
if (oneData.msg_times !== m.msg_times) {
|
|
@@ -174,16 +168,29 @@ module.exports = app => {
|
|
|
}
|
|
|
if (!this._.isEqual(upd, { id: m.id })) updateDatas.push(upd);
|
|
|
}
|
|
|
+ const updateNum = updateDatas.length;
|
|
|
if (updateDatas.length !== 0) {
|
|
|
await transaction.updateRows(this.tableName, updateDatas);
|
|
|
if (needUpdateTp) {
|
|
|
// 更新到materialStage金额
|
|
|
await this.ctx.service.materialStage.updateMtp(transaction, ms_id);
|
|
|
// 更新到materialBills金额
|
|
|
- await transaction.updateRows(this.ctx.service.materialBills.tableName, updateBillsDatas);
|
|
|
+ const updateBillsDatas = [];
|
|
|
+ for (const bill of updateBillIds) {
|
|
|
+ const sql = 'SELECT SUM(`m_tp`) as total_price, SUM(IF(`m_tax_tp` is null, `m_tp`, `m_tax_tp`)) as tax_total_price' +
|
|
|
+ ' FROM ' + this.tableName + ' WHERE `tid` = ? AND `mid` = ? AND `mb_id` = ? AND `is_summary` = 1';
|
|
|
+ const sqlParam = [this.ctx.tender.id, this.ctx.material.id, bill.id];
|
|
|
+ const tp = await transaction.queryOne(sql, sqlParam);
|
|
|
+ updateBillsDatas.push({
|
|
|
+ id: bill.id,
|
|
|
+ m_tp: tp.total_price,
|
|
|
+ m_tax_tp: tp.tax_total_price,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (updateBillsDatas.length > 0) await transaction.updateRows(this.ctx.service.materialBills.tableName, updateBillsDatas);
|
|
|
}
|
|
|
}
|
|
|
- return needUpdateTp;
|
|
|
+ return [needUpdateTp, updateNum];
|
|
|
}
|
|
|
|
|
|
// 单个修改工料时同步修改
|