// 计算调差建筑税金额 const materialConst = require('../app/const/material'); const BaseUtil = require('./baseUtils'); const querySql = BaseUtil.querySql; const ZhCalc = BaseUtil.ZhCalc; const checkMaterial = async function(material, ex_tax_tp, ex_tax_pre_tp) { // if (!material.is_new_exponent) { await querySql('Update zh_material Set ex_tax_tp = ?, ex_tax_pre_tp = ? Where id = ?', [ex_tax_tp, ex_tax_pre_tp, material.id]); // } console.log(`Update Material ${material.id}`); }; const doComplete = async function() { try { const tender = await querySql('Select * From zh_tender'); for (const t of tender) { console.log(`Update Tender ${t.id}:`); const materials = await querySql('Select * From zh_material where tid = ? order by id asc', [t.id]); let total_ex_tax_tp = 0; for (const m of materials) { m.decimal = m.decimal ? JSON.parse(m.decimal) : materialConst.decimal; const ex_tax_tp = !m.is_new_exponent ? ZhCalc.round(ZhCalc.mul(m.ex_tp, 1 + m.exponent_rate / 100), m.decimal.tp) : m.ex_tax_tp; await checkMaterial(m, ex_tax_tp, total_ex_tax_tp); total_ex_tax_tp = ZhCalc.add(total_ex_tax_tp, ex_tax_tp); } } } catch (err) { console.log(err); } BaseUtil.closePool(); }; const doCompleteTest = async function(tid) { try { const tender = await querySql('Select * From zh_tender where id = ?', [tid]); for (const t of tender) { console.log(`Update Tender ${t.id}:`); const materials = await querySql('Select * From zh_material where tid = ?', [t.id]); for (const m of materials) { await checkMaterial(m); } } } catch (err) { console.log(err); } BaseUtil.closePool(); }; const tenderId = process.argv[3]; if (tenderId) { doCompleteTest(tenderId); } else { doComplete(); }