Browse Source

删除bug修复和计算总额调整

laiguoran 3 years ago
parent
commit
9e24d4c165
3 changed files with 29 additions and 18 deletions
  1. 24 10
      app/service/change_audit_list.js
  2. 4 7
      app/service/change_ledger.js
  3. 1 1
      app/service/change_pos.js

+ 24 - 10
app/service/change_audit_list.js

@@ -429,12 +429,12 @@ module.exports = app => {
                         if (d.id) {
                             const changePosNum = await transaction.count(this.ctx.service.changePos.tableName, { lid: d.id });
                             const updateCol = {};
-                            if (column === 'gcl_id' && d.b_code !== undefined) updateCol.code = d.b_code;
-                            if (column === 'gcl_id' && d.sgfh_qty !== undefined && changePosNum === 0) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
+                            if (column === 'gcl_id' && d.b_code) updateCol.code = d.b_code;
+                            if (column === 'gcl_id' && d.quantity !== undefined && changePosNum === 0) updateCol.oamount = d.quantity ? d.quantity : 0;
                             if (column === 'gcl_id' && d.unit_price !== undefined) updateCol.unit_price = d.unit_price ? d.unit_price : 0;
                             if (column === 'gcl_id' && d.unit !== undefined) updateCol.unit = d.unit;
                             if (column === 'gcl_id' && d.name !== undefined) updateCol.name = d.name;
-                            if (d.code !== undefined && d.b_code === null) {
+                            if (d.b_code !== undefined && d.b_code === null) {
                                 // 清单升级成了项目节,故删除变更已有的此清单,并找出需要重新计算的变更令
                                 const sql = 'SELECT `cid` FROM ?? WHERE `tid` = ? AND ' + column + ' = ? GROUP BY `cid`';
                                 const params = [this.tableName, tid, d.id];
@@ -670,8 +670,9 @@ module.exports = app => {
                         if (d.id) {
                             const updateCol = {};
                             if (column === 'mx_id' && d.name !== undefined) updateCol.bwmx = d.name;
-                            if (column === 'mx_id' && d.sgfh_qty !== undefined) updateCol.oamount = d.sgfh_qty ? d.sgfh_qty : 0;
-                            if (column === 'mx_id' && d.sgfh_qty === undefined && d.sgfh_expr === '') updateCol.oamount = 0;
+                            if (column === 'mx_id' && d.quantity !== undefined) updateCol.oamount = d.quantity ? d.quantity : 0;
+                            if (column === 'mx_id' && d.quantity === undefined &&
+                                ((d.sgfh_expr && d.sgfh_expr === '') || (d.sjcl_expr && d.sjcl_expr === '') || (d.qtcl_expr && d.qtcl_expr === ''))) updateCol.oamount = 0;
                             const options = {
                                 row: {},
                                 where: {},
@@ -682,7 +683,6 @@ module.exports = app => {
                             if (!this._.isEmpty(options.row)) updateArr.push(options);
                         }
                     }
-                    console.log(updateArr);
                     if (updateArr.length > 0) await transaction.updateRows(this.tableName, updateArr);
                 }
             }
@@ -745,16 +745,22 @@ module.exports = app => {
                     if (this._.indexOf(changeLedgerGclIdList, data.lid) === -1) {
                         const info = this._.find(needUpdateLedgerList, { id: data.lid });
                         if (info) {
+                            info.sgfh_qty = this.ctx.helper.add(info.sgfh_qty, data.sgfh_qty);
+                            info.sjcl_qty = this.ctx.helper.add(info.sjcl_qty, data.sjcl_qty);
+                            info.qtcl_qty = this.ctx.helper.add(info.qtcl_qty, data.qtcl_qty);
                             info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
                         } else {
-                            needUpdateLedgerList.push({ id: data.lid, quantity: data.quantity });
+                            needUpdateLedgerList.push({ id: data.lid, sgfh_qty: data.sgfh_qty, sjcl_qty: data.sjcl_qty, qtcl_qty: data.qtcl_qty, quantity: data.quantity });
                         }
                     } else {
                         const info = this._.find(needUpdateChangeLedgerList, { id: data.lid });
                         if (info) {
+                            info.sgfh_qty = this.ctx.helper.add(info.sgfh_qty, data.sgfh_qty);
+                            info.sjcl_qty = this.ctx.helper.add(info.sjcl_qty, data.sjcl_qty);
+                            info.qtcl_qty = this.ctx.helper.add(info.qtcl_qty, data.qtcl_qty);
                             info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
                         } else {
-                            needUpdateChangeLedgerList.push({ id: data.lid, quantity: data.quantity });
+                            needUpdateChangeLedgerList.push({ id: data.lid, sgfh_qty: data.sgfh_qty, sjcl_qty: data.sjcl_qty, qtcl_qty: data.qtcl_qty, quantity: data.quantity });
                         }
                     }
                 }
@@ -762,9 +768,13 @@ module.exports = app => {
                 if (needUpdateChangeLedgerList.length > 0) {
                     for (const nucl of needUpdateChangeLedgerList) {
                         const now = this._.find(result, { id: nucl.id });
+                        now.sgfh_qty = nucl.sgfh_qty;
+                        now.sjcl_qty = nucl.sjcl_qty;
+                        now.qtcl_qty = nucl.qtcl_qty;
                         now.quantity = nucl.quantity;
-                        now.sgfh_qty = nucl.quantity;
                         now.sgfh_tp = this.ctx.helper.mul(now.sgfh_qty, now.unit_price, tpDecimal);
+                        now.sjcl_tp = this.ctx.helper.mul(now.sjcl_qty, now.unit_price, tpDecimal);
+                        now.qtcl_tp = this.ctx.helper.mul(now.qtcl_qty, now.unit_price, tpDecimal);
                         now.total_price = this.ctx.helper.mul(now.quantity, now.unit_price, tpDecimal);
                     }
                 }
@@ -772,9 +782,13 @@ module.exports = app => {
                 if (needUpdateLedgerList.length > 0) {
                     for (const nul of needUpdateLedgerList) {
                         const ledgerInfo = await this.ctx.service.ledger.getDataById(nul.id);
+                        ledgerInfo.sgfh_qty = this.ctx.helper.add(ledgerInfo.sgfh_qty, nul.sgfh_qty);
+                        ledgerInfo.sjcl_qty = this.ctx.helper.add(ledgerInfo.sjcl_qty, nul.sjcl_qty);
+                        ledgerInfo.qtcl_qty = this.ctx.helper.add(ledgerInfo.qtcl_qty, nul.qtcl_qty);
                         ledgerInfo.quantity = this.ctx.helper.add(ledgerInfo.quantity, nul.quantity);
-                        ledgerInfo.sgfh_qty = this.ctx.helper.add(ledgerInfo.sgfh_qty, nul.quantity);
                         ledgerInfo.sgfh_tp = this.ctx.helper.mul(ledgerInfo.sgfh_qty, ledgerInfo.unit_price, tpDecimal);
+                        ledgerInfo.sjcl_tp = this.ctx.helper.mul(ledgerInfo.sjcl_qty, ledgerInfo.unit_price, tpDecimal);
+                        ledgerInfo.qtcl_tp = this.ctx.helper.mul(ledgerInfo.qtcl_qty, ledgerInfo.unit_price, tpDecimal);
                         ledgerInfo.total_price = this.ctx.helper.mul(ledgerInfo.quantity, ledgerInfo.unit_price, tpDecimal);
                         await transaction.update(this.ctx.service.ledger.tableName, ledgerInfo);
                     }

+ 4 - 7
app/service/change_ledger.js

@@ -1613,7 +1613,7 @@ module.exports = app => {
 
             this.transaction = await this.db.beginTransaction();
             try {
-                // const updateDatas = [];
+                const updateDatas = [];
                 for (const row of datas) {
                     const updateNode = await this.getDataById(row.id);
                     if (!updateNode || tenderId !== updateNode.tender_id || row.ledger_id !== updateNode.ledger_id) {
@@ -1638,7 +1638,7 @@ module.exports = app => {
                     if (row.code) row.b_code = null;
 
                     if (this._checkCalcField(row)) {
-                        let calcData = JSON.parse(JSON.stringify(row));
+                        const calcData = JSON.parse(JSON.stringify(row));
                         calcData.check_calc = 1;
                         const precision = helper.findPrecision(info.precision, row.unit ? row.unit : updateNode.unit);
                         // 数量保留小数位数
@@ -1684,14 +1684,11 @@ module.exports = app => {
                     }
                     await this.transaction.update(this.tableName, updateData);
                     // 如非子节点,需要更新底下所有已选清单的分部分项等数据
-                    // updateDatas.push(updateData);
+                    updateDatas.push(updateData);
                 }
                 // console.log(updateDatas);
                 // 如果是子节点 更新了单位或单价,则更新数据并重算变更令总金额
-                await this.ctx.service.changeAuditList.updateDataByReviseLedger(this.transaction, tenderId, datas);
-                // if (data) {
-                //     throw '阻断';
-                // }
+                await this.ctx.service.changeAuditList.updateDataByReviseLedger(this.transaction, tenderId, updateDatas);
                 await this.transaction.commit();
                 this.transaction = null;
             } catch (err) {

+ 1 - 1
app/service/change_pos.js

@@ -253,7 +253,6 @@ module.exports = app => {
             // const bills = await this.ctx.service.reviseBills.getDataById(pos[0].lid);
             // const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
             const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
-            updateBills.cid = cid;
             for (const bp of billsPos) {
                 if (data.indexOf(bp.id) >= 0) continue;
                 updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
@@ -274,6 +273,7 @@ module.exports = app => {
                 await this.ctx.service.changeAuditList.deleteDataByRevise(transaction, tid, data, 'mx_id');
                 await transaction.commit();
                 updateBills.ledger_id = bills.ledger_id;
+                updateBills.cid = cid;
                 return {
                     ledger: { update: [updateBills] },
                     pos: data,