Browse Source

合同支付,技术计算调整

MaiXinRong 7 months ago
parent
commit
8374748f92

+ 5 - 2
app/controller/pay_controller.js

@@ -91,7 +91,7 @@ module.exports = app => {
 
         async detail(ctx) {
             try {
-                await this.ctx.service.phasePayDetail.calculateSave(ctx.phasePay);
+                // await this.ctx.service.phasePayDetail.calculateSave(ctx.phasePay);
                 const pays = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
                 const calcBase = this.ctx.service.phasePay.getPhasePayCalcBase(ctx.phasePay, ctx.tender.info);
                 const renderData = {
@@ -142,8 +142,11 @@ module.exports = app => {
                         responseData.data.reload = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
                         break;
                     case 'refreshBase':
-                        await this.ctx.service.phasePay.refreshCalcBase();
+                        await this.ctx.service.phasePay.refreshCalcBase(ctx.phasePay);
                         responseData.data.reload = await this.ctx.service.phasePayDetail.getDetailData(ctx.phasePay);
+                        responseData.data.calcBase = this.ctx.service.phasePay.getPhasePayCalcBase(ctx.phasePay, ctx.tender.info);
+                        responseData.data.calcBase.forEach(x => { x.formatValue = ctx.tender.info.display.thousandth ? ctx.helper.formatNum(x.value, '#,##0.######') : x.value; });
+                        responseData.data.addBase = ctx.phasePay.calc_base;
                         break;
                     default:
                         throw '未知操作';

+ 42 - 1
app/public/js/phase_pay_detail.js

@@ -373,6 +373,31 @@ $(document).ready(() => {
                     return 0;
                 }
             }
+            refreshBaseHtml() {
+                const html = [];
+                for (const [i, b] of this.bases.entries()) {
+                    html.push('<tr>');
+                    html.push(`<td>${i+1}</td><td>${b.name}</td><td>${b.code}</td>`);
+                    if (b.code === 'bqyf') {
+                        html.push('<td class="text-right">--</td>');
+                    } else {
+                        html.push(`<td class="text-right">${b.formatValue}</td>`);
+                    }
+                    html.push('</tr>');
+                }
+                $('#base-list').html(html.join(''));
+            }
+            reloadBase(bases, add) {
+                this.bases = bases;
+                this.refreshBaseHtml();
+                this.bases.sort(function (a, b) {
+                    return a.sort - b.sort;
+                });
+                for (const b of this.bases) {
+                    b.reg = new RegExp(b.code, 'igm');
+                }
+                this.addBase = add;
+            }
         }
 
         return new PayCalc(b, a);
@@ -700,6 +725,17 @@ $(document).ready(() => {
                     });
                 }
             },
+            calculateAll: function() {
+                postData('update', { postType: 'calc', postData: {}}, function (result) {
+                    payEvent.reloadPays(result.reload);
+                });
+            },
+            reloadCalcBase: function() {
+                postData('update', { postType: 'refreshBase', postData: {}}, function (result) {
+                    payEvent.reloadPays(result.reload);
+                    payCalc.reloadBase(result.calcBase, result.addBase);
+                });
+            },
             reloadPays: function(datas){
                 payTree.loadDatas(datas);
                 SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Tree, payTree);
@@ -715,7 +751,12 @@ $(document).ready(() => {
             $('a[name="base-opr"]').click(function () {
                 payEvent.baseOpr(this.getAttribute('type'));
             });
-            $('')
+            $('#calc-all').click(function() {
+                payEvent.calculateAll();
+            });
+            $('#reload-calc-base').click(function() {
+                payEvent.reloadCalcBase();
+            });
         }
 
         return { spread, sheet, payTree, loadDatas: payEvent.reloadPays }

+ 58 - 33
app/service/phase_pay.js

@@ -99,7 +99,7 @@ module.exports = app => {
             return result;
         }
 
-        async getNewOrder(tid) {
+        async getMaxOrder(tid) {
             const sql = 'SELECT Max(`phase_order`) As max_order FROM ' + this.tableName + ' Where `tid` = ?';
             const sqlParam = [tid];
             const result = await this.db.queryOne(sql, sqlParam);
@@ -117,7 +117,7 @@ module.exports = app => {
             return false;
         }
 
-        async getCalcBase(relaStage) {
+        async getCalcBase(relaStage, prePhase) {
             const result = {};
             for (const stage of relaStage) {
                 result.contract_tp = this.ctx.helper.add(result.contract_tp, stage.contract_tp);
@@ -125,33 +125,53 @@ module.exports = app => {
                 result.pc_tp = this.ctx.helper.add(result.pc_tp, stage.pc_tp);
 
                 const qdSum = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage);
-                result.qd_contract_tp = qdSum.contract_tp;
-                result.qd_qc_tp = qdSum.qc_tp;
-                result.qd_pc_tp = qdSum.pc_tp;
+                result.qd_contract_tp = qdSum.contract_tp || 0;
+                result.qd_qc_tp = qdSum.qc_tp || 0;
+                result.qd_pc_tp = qdSum.pc_tp || 0;
 
                 const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
                 const sumPc = await this.ctx.service.stageBillsPc.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
                 result.gather_100_tp = this.ctx.helper.sum([sumGcl.contract_tp, sumGcl.qc_tp, sumPc.pc_tp]);
 
                 const bg = await this.ctx.service.stage.getChangeSubtotal(stage);
-                result.common_bg_tp = bg.common;
-                result.more_bg_tp = bg.more;
-                result.great_bg_tp = bg.great;
+                result.common_bg_tp = bg.common || 0;
+                result.more_bg_tp = bg.more || 0;
+                result.great_bg_tp = bg.great || 0;
             }
-            result.gather_tp = this.ctx.helper.sum([result.contract_tp, result.qc_tp, result.pc_tp]);
-            result.qd_gather_tp = this.ctx.helper.sum([result.qd_contract_tp, result.qd_qc_tp, result.qd_pc_tp]);
+            result.gather_tp = this.ctx.helper.sum([result.contract_tp, result.qc_tp, result.pc_tp]) || 0;
+            result.qd_gather_tp = this.ctx.helper.sum([result.qd_contract_tp, result.qd_qc_tp, result.qd_pc_tp]) || 0;
             const bonusSum = await this.ctx.service.stageBonus.getSumTp(relaStage);
-            result.bonus_positive_tp = bonusSum.positive_tp;
-            result.bonus_negative_tp = bonusSum.negative_tp;
-            result.bonus_tp = bonusSum.sum_tp;
+            result.bonus_positive_tp = bonusSum.positive_tp || 0;
+            result.bonus_negative_tp = bonusSum.negative_tp || 0;
+            result.bonus_tp = bonusSum.sum_tp || 0;
             const jgclSum = await this.ctx.service.stageJgcl.getSumTp(relaStage);
-            result.jgcl_tp = jgclSum.sum_tp;
+            result.jgcl_tp = jgclSum.sum_tp || 0;
             const otherSum = await this.ctx.service.stageOther.getSumTp(relaStage);
-            result.other_tp = otherSum.sum_tp;
+            result.other_tp = otherSum.sum_tp || 0;
             const safeProdSum = await this.ctx.service.stageSafeProd.getSumTp(relaStage);
-            result.safe_prod_tp = safeProdSum.sum_tp;
+            result.safe_prod_tp = safeProdSum.sum_tp || 0;
             const tempLandSum = await this.ctx.service.stageTempLand.getSumTp(relaStage);
-            result.temp_land_tp = tempLandSum.sum_tp;
+            result.temp_land_tp = tempLandSum.sum_tp || 0;
+
+            if (prePhase && prePhase.calc_base) {
+                result.pre_contract_tp = this.ctx.helper.add(prePhase.calc_base.contract_tp, prePhase.calc_base.pre_contract_tp);
+                result.pre_qc_tp = this.ctx.helper.add(prePhase.calc_base.qc_tp, prePhase.calc_base.pre_qc_tp);
+                result.pre_pc_tp = this.ctx.helper.add(prePhase.calc_base.pc_tp, prePhase.calc_base.pre_pc_tp);
+                result.pre_gather_tp = this.ctx.helper.add(prePhase.calc_base.gather_tp, prePhase.calc_base.pre_gather_tp);
+
+                result.pre_qd_contract_tp = this.ctx.helper.add(prePhase.calc_base.qd_contract_tp, prePhase.calc_base.pre_qd_contract_tp);
+                result.pre_qd_qc_tp = this.ctx.helper.add(prePhase.calc_base.qd_qc_tp, prePhase.calc_base.pre_qd_qc_tp);
+                result.pre_qd_pc_tp = this.ctx.helper.add(prePhase.calc_base.qd_pc_tp, prePhase.calc_base.pre_qd_pc_tp);
+                result.pre_qd_gather_tp = this.ctx.helper.add(prePhase.calc_base.qd_gather_tp, prePhase.calc_base.pre_qd_gather_tp);
+
+                result.pre_bonus_positive_tp = this.ctx.helper.add(prePhase.calc_base.bonus_positive_tp, prePhase.calc_base.pre_bonus_positive_tp);
+                result.pre_bonus_negative_tp = this.ctx.helper.add(prePhase.calc_base.bonus_negative_tp, prePhase.calc_base.pre_bonus_negative_tp);
+                result.pre_bonus_tp = this.ctx.helper.add(prePhase.calc_base.bonus_tp, prePhase.calc_base.pre_bonus_tp);
+                result.pre_jgcl_tp = this.ctx.helper.add(prePhase.calc_base.jgcl_tp, prePhase.calc_base.pre_jgcl_tp);
+                result.pre_other_tp = this.ctx.helper.add(prePhase.calc_base.other_tp, prePhase.calc_base.pre_other_tp);
+                result.pre_safe_prod_tp = this.ctx.helper.add(prePhase.calc_base.safe_prod_tp, prePhase.calc_base.pre_safe_prod_tp);
+                result.pre_temp_land_tp = this.ctx.helper.add(prePhase.calc_base.temp_land_tp, prePhase.calc_base.pre_temp_land_tp);
+            }
             return result;
         }
 
@@ -188,40 +208,40 @@ module.exports = app => {
                         cb.value = phasePay.calc_base.qc_tp;
                         break;
                     case 'bqqdwc':
-                        cb.value = phasePay.qd_gather_tp;
+                        cb.value = phasePay.calc_base.qd_gather_tp;
                         break;
                     case 'bqqdht':
-                        cb.value = phasePay.qd_contract_tp;
+                        cb.value = phasePay.calc_base.qd_contract_tp;
                         break;
                     case 'bqqdbg':
-                        cb.value = phasePay.qd_qc_tp;
+                        cb.value = phasePay.calc_base.qd_qc_tp;
                         break;
                     case 'ybbqwc':
-                        cb.value = phasePay.gather_100_tp;
+                        cb.value = phasePay.calc_base.gather_100_tp;
                         break;
                     case 'ybbqbg':
-                        cb.value = phasePay.common_bg_tp;
+                        cb.value = phasePay.calc_base.common_bg_tp;
                         break;
                     case 'jdbqbg':
-                        cb.value = phasePay.more_bg_tp;
+                        cb.value = phasePay.calc_base.more_bg_tp;
                         break;
                     case 'zdbqbg':
-                        cb.value = phasePay.great_bg_tp;
+                        cb.value = phasePay.calc_base.great_bg_tp;
                         break;
                     case 'bonus':
-                        cb.value = phasePay.bonus_positive_tp;
+                        cb.value = phasePay.calc_base.bonus_positive_tp;
                         break;
                     case 'fine':
-                        cb.value = phasePay.bonus_negative_tp;
+                        cb.value = phasePay.calc_base.bonus_negative_tp;
                         break;
                     case 'jgcl':
-                        cb.value = phasePay.jgcl_tp;
+                        cb.value = phasePay.calc_base.jgcl_tp;
                         break;
                     case 'aqsc':
-                        cb.value = phasePay.safe_prod_tp;
+                        cb.value = phasePay.calc_base.safe_prod_tp;
                         break;
                     case 'lsyd':
-                        cb.value = phasePay.temp_land_tp;
+                        cb.value = phasePay.calc_base.temp_land_tp;
                         break;
                     default:
                         cb.value = 0;
@@ -234,7 +254,7 @@ module.exports = app => {
             if (!tid) throw '数据错误';
             const user_id = this.ctx.session.sessionUser.accountId;
 
-            const maxOrder = await this.getNewOrder();
+            const maxOrder = await this.getMaxOrder();
             const data = {
                 id: this.uuid.v4(), tid: tid, create_user_id: user_id, update_user_id: user_id,
                 phase_order: maxOrder + 1, phase_date: phaseDate, memo,
@@ -243,7 +263,8 @@ module.exports = app => {
             };
             if (await this._checkRelaStageConflict(relaStage, data)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
 
-            const calcBase = await this.getCalcBase(relaStage);
+            const prePhase = maxOrder > 0 ? await this.getPhasePayByOrder(tid, maxOrder) : null;
+            const calcBase = await this.getCalcBase(relaStage, prePhase);
             data.calc_base = JSON.stringify(calcBase);
             const transaction = await this.db.beginTransaction();
             try {
@@ -260,7 +281,9 @@ module.exports = app => {
         }
 
         async refreshCalcBase(phasePay) {
-            const calcBase = await this.getCalcBase(relaStage);
+            const prePhase = phasePay.phase_order > 1 ? await this.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1) : null;
+            const relaStage = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: phasePay.tid, order: phasePay.rela_stage.map(x => { return x.stage_order; }) } });
+            const calcBase = await this.getCalcBase(relaStage, prePhase);
             const conn = await this.db.beginTransaction();
             try {
                 await conn.update(this.tableName, {
@@ -270,6 +293,7 @@ module.exports = app => {
                 });
                 phasePay.calc_base = calcBase;
                 await this.ctx.service.phasePayDetail.calculateSave(phasePay, conn);
+                await conn.commit();
             } catch(err) {
                 await conn.rollback();
                 throw err;
@@ -277,7 +301,8 @@ module.exports = app => {
         }
         async resetRelaStageId(phasePay, relaStage) {
             if (await this._checkRelaStageConflict(relaStage, phasePay)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
-            const calcBase = await this.getCalcBase(relaStage);
+            const prePhase = prePhase.phase_order > 1 ? await this.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1) : null;
+            const calcBase = await this.getCalcBase(relaStage, prePhase);
             const rela_stage = relaStage.map(s => { return {stage_id: s.id, stage_order: s.order}; });
             const conn = await this.db.beginTransaction();
             try {

+ 4 - 1
app/service/phase_pay_detail.js

@@ -565,13 +565,16 @@ class PhasePayDetail extends TreeService {
             for (const d of data) {
                 const node = orgData.find(x => { return x.id === d.id; });
                 if (!node || masterId !== node[this.setting.mid]) throw '提交数据错误';
-                updateDatas.push(this._filterValidField(node.id, d));
+                const ud = this._filterValidField(node.id, d);
+                ud.update_user_id = ctx.session.sessionUser.accountId;
+                updateDatas.push(ud);
             }
             if (updateDatas.length > 0) await this.db.updateRows(this.tableName, updateDatas);
         } else {
             const node = await this.getDataById(data.id);
             if (!node || masterId !== node[this.setting.mid]) throw '提交数据错误';
             const updateData = this._filterValidField(node.id, data);
+            updateData.update_user_id = ctx.session.sessionUser.accountId;
             await this.db.update(this.tableName, updateData);
         }
     }

+ 9 - 2
app/view/phase_pay/detail.ejs

@@ -20,8 +20,12 @@
                 </div>
             </div>
             <div class="ml-auto">
-                <button class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="计算全部"><i class="fa fa-play"></i></button>
-                <button class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="刷新基数"><i class="fa fa-repeat"></i></button>
+                <% if (!ctx.phasePay.readOnly) { %>
+                <button class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="计算全部" id="calc-all"><i class="fa fa-play"></i></button>
+                <% } %>
+                <% if (!ctx.phasePay.audit_status === auditConst.status.uncheck) { %>
+                <button class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="刷新基数" id="reload-calc-base"><i class="fa fa-repeat"></i></button>
+                <% } %>
             </div>
         </div>
     </div>
@@ -37,6 +41,7 @@
                 <div class="sjs-sh-1">
                     <table class="table table-bordered">
                         <tr><th></th><th>可选基数</th><th>计算代号</th><th>值</th></tr>
+                        <tbody id="base-list">
                         <% for (let iBase = 0; iBase < calcBase.length; iBase++) { %>
                         <tr>
                             <td><%- iBase + 1 %></td>
@@ -49,6 +54,7 @@
                             <% } %>
                         </tr>
                         <% } %>
+                        </tbody>
                     </table>
                 </div>
             </div>
@@ -64,4 +70,5 @@
     const details = JSON.parse('<%- JSON.stringify(pays) %>');
     const calcBase = JSON.parse('<%- JSON.stringify(calcBase) %>');
     const addBase = JSON.parse('<%- JSON.stringify(ctx.phasePay.calc_base) %>');
+    const throusanth = <%- ctx.tender.info.display.thousandth %>;
 </script>