|
@@ -6,13 +6,17 @@ const status = require('../app/const/audit').change.status;
|
|
|
const querySql = BaseUtil.querySql;
|
|
|
const ZhCalc = BaseUtil.ZhCalc;
|
|
|
|
|
|
-const checkChange = async function(change) {
|
|
|
+const checkChange = async function(change, decimal) {
|
|
|
const changeBills = await querySql('Select * From zh_change_audit_list where cid = ?', [change.cid]);
|
|
|
let valuation_tp = 0;
|
|
|
let unvaluation_tp = 0;
|
|
|
for (const cb of changeBills) {
|
|
|
- valuation_tp = cb.is_valuation ? ZhCalc.add(valuation_tp, cb.checked_price) : valuation_tp;
|
|
|
- unvaluation_tp = !cb.is_valuation ? ZhCalc.add(unvaluation_tp, cb.checked_price) : unvaluation_tp;
|
|
|
+ cb.tp = ZhCalc.mul(cb.spamount, cb.unit_price, change.tp_decimal || decimal.tp);
|
|
|
+ if (cb.is_valuation) {
|
|
|
+ valuation_tp = ZhCalc.add(valuation_tp, cb.tp);
|
|
|
+ } else {
|
|
|
+ unvaluation_tp = ZhCalc.add(unvaluation_tp, cb.tp);
|
|
|
+ }
|
|
|
}
|
|
|
await querySql('Update zh_change Set valuation_tp = ?, unvaluation_tp = ? Where cid = ?', [valuation_tp, unvaluation_tp, change.cid]);
|
|
|
console.log(`Update Change ${change.cid}`);
|
|
@@ -23,9 +27,12 @@ const doComplete = async function() {
|
|
|
const tender = await querySql('Select * From zh_tender');
|
|
|
for (const t of tender) {
|
|
|
console.log(`Update Tender ${t.id}:`);
|
|
|
- const changes = await querySql('Select * From zh_change where tid = ? AND status = ?', [t.id, status.checked]);
|
|
|
+ const info = await querySql('Select * From zh_tender_info where tid = ?', [t.id]);
|
|
|
+ const decimal = info.length > 0 && info[0].decimal ? JSON.parse(info[0].decimal) : defaultInfo.defaultInfo.decimal;
|
|
|
+
|
|
|
+ const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
|
|
|
for (const c of changes) {
|
|
|
- await checkChange(c);
|
|
|
+ await checkChange(c, decimal);
|
|
|
}
|
|
|
}
|
|
|
} catch (err) {
|
|
@@ -38,9 +45,12 @@ const doCompleteTest = async function(tid) {
|
|
|
const tender = await querySql('Select * From zh_tender where id = ?', [tid]);
|
|
|
for (const t of tender) {
|
|
|
console.log(`Update Tender ${t.id}:`);
|
|
|
- const changes = await querySql('Select * From zh_change where tid = ? AND status = ?', [t.id, status.checked]);
|
|
|
+ const info = await querySql('Select * From zh_tender_info where tid = ?', [t.id]);
|
|
|
+ const decimal = info.length > 0 && info[0].decimal ? JSON.parse(info[0].decimal) : defaultInfo.defaultInfo.decimal;
|
|
|
+
|
|
|
+ const changes = await querySql('Select * From zh_change where tid = ?', [t.id]);
|
|
|
for (const c of changes) {
|
|
|
- await checkChange(c);
|
|
|
+ await checkChange(c, decimal);
|
|
|
}
|
|
|
}
|
|
|
} catch (err) {
|