فهرست منبع

反算本期合同金额

MaiXinRong 1 ماه پیش
والد
کامیت
ede2df9a2b

+ 1 - 0
app/const/sp_page_show.js

@@ -107,6 +107,7 @@ const defaultSetting = {
     openChangeWhiteList: 0,
     openChangeState: 0,
     openInfo: 1,
+    correctCalcContractTp: 0,
 };
 
 module.exports = {

+ 1 - 1
app/controller/stage_controller.js

@@ -536,7 +536,7 @@ module.exports = app => {
                 if (projRela.banOver && ctx.tender.info.ledger_check.over) {
                     checkData.checkOverRange(ctx.tender.info.checkOverInfo);
                 }
-                if (this.ctx.tender.info.calc_type === 'up') {
+                if (this.ctx.tender.info.calc_type === 'up' && this.ctx.subProject.page_show.correctCalcContractTp) {
                     checkData.checkBillsTp([
                         { qty: 'contract_qty', tp: 'contract_tp' }, { qty: 'qc_qty', tp: 'qc_tp' },
                     ], this.ctx.tender.info.decimal, x => { return x.is_tp; });

+ 1 - 0
app/controller/sub_proj_setting_controller.js

@@ -391,6 +391,7 @@ module.exports = app => {
                 this.ctx.subProject.page_show.openStageStart = data.openStageStart ? 1 : 0;
                 this.ctx.subProject.page_show.openMaterialStageRepeat = data.openMaterialStageRepeat ? 1 : 0;
                 this.ctx.subProject.page_show.openContractExpr = data.openContractExpr ? 1 : 0;
+                this.ctx.subProject.page_show.correctCalcContractTp = data.correctCalcContractTp ? 1 : 0;
                 this.ctx.subProject.page_show.close1stStageCheckDealParam = data.close1stStageCheckDealParam ? 1 : 0;
                 this.ctx.subProject.page_show.openMultiStageCalc = data.openMultiStageCalc ? 1 : 0;
                 this.ctx.subProject.page_show.closeWapYfSf = data.closeWapYfSf ? 1 : 0;

+ 12 - 2
app/lib/bills_pos_convert.js

@@ -81,6 +81,7 @@ class BillsPosConvert {
     }
     _calcContractTp(node, data) {
         const info = this.ctx.tender.info;
+        const correct = this.ctx.subProject.page_show.correctCalcContractTp;
         if (info.calc_type === 'tp') {
             let activeQty = this.ctx.helper.add(data.quantity, data.qc_minus_qty);
             let end_contract_qty = data.contract_qty;
@@ -88,8 +89,17 @@ class BillsPosConvert {
             end_contract_qty = this.ctx.helper.add(end_contract_qty, data.pre_contract_qty);
             const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), data.total_price, info.decimal.tp);
             return this.ctx.helper.sub(end_contract_tp, data.pre_contract_tp);
-        } else {
-            return this.ctx.helper.mul(node.unit_price, data.contract_qty, info.decimal.tp);
+        } else if (info.calc_type === 'up') {
+            if (correct) {
+                let activeQty = this.ctx.helper.add(data.quantity, data.qc_minus_qty);
+                let end_contract_qty = data.contract_qty;
+                activeQty = this.ctx.helper.add(activeQty, data.pre_qc_minus_qty);
+                end_contract_qty = this.ctx.helper.add(end_contract_qty, data.pre_contract_qty);
+                const end_contract_tp = this.ctx.helper.mul(end_contract_qty, data.total_price, info.decimal.tp);
+                return activeQty === end_contract_qty ? this.ctx.helper.sub(end_contract_tp, data.pre_contract_tp) : this.ctx.helper.mul(node.unit_price, data.contract_qty, info.decimal.tp);
+            } else {
+                return this.ctx.helper.mul(node.unit_price, data.contract_qty, info.decimal.tp);
+            }
         }
     }
     // v2

+ 11 - 1
app/lib/sum_load.js

@@ -403,6 +403,7 @@ class gatherStageGclTree extends loadGclBaseTree {
         }
     }
     calcContractTp(info, node) {
+        const correct = this.ctx.subProject.page_show.correctCalcContractTp;
         if (info.calc_type === 'tp') {
             let activeQty = this.ctx.helper.add(node.quantity, node.qc_minus_qty);
             let end_contract_qty = node.contract_qty;
@@ -411,7 +412,16 @@ class gatherStageGclTree extends loadGclBaseTree {
             const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), node.total_price, decimal.tp);
             return this.ctx.helper.sub(end_contract_tp, node.pre_contract_tp);
         } else if (info.calc_type === 'up') {
-            return this.ctx.helper.mul(node.unit_price, node.contract_qty, info.decimal.tp);
+            if (correct) {
+                let activeQty = this.ctx.helper.add(node.quantity, node.qc_minus_qty);
+                let end_contract_qty = node.contract_qty;
+                activeQty = this.ctx.helper.add(activeQty, node.pre_qc_minus_qty);
+                end_contract_qty = this.ctx.helper.add(end_contract_qty, node.pre_contract_qty);
+                const end_contract_tp = this.ctx.helper.mul(end_contract_qty, node.total_price, decimal.tp);
+                return activeQty === end_contract_qty ? this.ctx.helper.sub(end_contract_tp, node.pre_contract_tp) : this.ctx.helper.mul(node.unit_price, node.contract_qty, info.decimal.tp);
+            } else {
+                return this.ctx.helper.mul(node.unit_price, node.contract_qty, info.decimal.tp);
+            }
         }
     }
     gather(source, parent) {

+ 1 - 1
app/public/js/stage.js

@@ -233,7 +233,7 @@ $(document).ready(() => {
     };
     let detail, searchLedger, checkedChanges;
     const tpCalcFields = [{qty: 'qc_qty', tp: 'qc_tp'}];
-    if (tenderInfo.calc_type === 'up') tpCalcFields.shift({qty: 'contract_qty', tp: 'contract_tp'});
+    if (tenderInfo.calc_type === 'up' && correctCalcContractTp) tpCalcFields.shift({qty: 'contract_qty', tp: 'contract_tp'});
     const checkOption = {
         sibling: { enable: 0 },
         empty_code: { enable: 0 },

+ 17 - 1
app/service/stage_bills.js

@@ -181,12 +181,28 @@ module.exports = app => {
             const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), bills.total_price, decimal.tp);
             return preStageBills ? this.ctx.helper.sub(end_contract_tp, preStageBills.contract_tp) : end_contract_tp;
         }
+        _calcContractTpByCorrect(bills,preStageBills, stageBills, decimal) {
+            let activeQty = this.ctx.helper.add(bills.quantity, stageBills.qc_minus_qty);
+            let end_contract_qty = stageBills.contract_qty;
+            if (preStageBills) {
+                activeQty = this.ctx.helper.add(activeQty, preStageBills.qc_minus_qty);
+                end_contract_qty = this.ctx.helper.add(end_contract_qty, preStageBills.contract_qty);
+            }
+            const end_contract_tp = this.ctx.helper.mul(end_contract_qty, bills.unit_price, decimal.tp);
+            return activeQty === end_contract_qty ? this.ctx.helper.sub(end_contract_tp, preStageBills.contract_tp) : this.ctx.helper.mul(stageBills.contract_qty, bills.unit_price, info.decimal.tp);
+        }
         async calcContractTp(info, stage, bills, stageBills) {
+            const correct = this.ctx.subProject.page_show.correctCalcContractTp;
             if (info.calc_type === 'tp') {
                 const preStageBills = await this.ctx.service.stageBillsFinal.getDataByCondition({ tid: stage.tid, sorder: stage.order - 1, lid: bills.id });
                 return this._calcContractTpByTp(bills, preStageBills, stageBills, info.decimal);
             } else if (info.calc_type === 'up') {
-                return this.ctx.helper.mul(stageBills.contract_qty, bills.unit_price, info.decimal.tp);
+                if (correct) {
+                    const preStageBills = await this.ctx.service.stageBillsFinal.getDataByCondition({ tid: stage.tid, sorder: stage.order - 1, lid: bills.id });
+                    return this._calcContractTpByCorrect(bills, preStageBills, stageBills, info.decimal);
+                } else {
+                    return this.ctx.helper.mul(stageBills.contract_qty, bills.unit_price, info.decimal.tp);
+                }
             }
         }
         async _calcStageBillsData(data, orgData, ledgerData) {

+ 32 - 15
app/service/stage_change.js

@@ -14,8 +14,9 @@ const timesLen = audit.stage.timesLen;
 const changeConst = require('../const/change');
 
 class autoUseChange {
-    constructor(helper, info, settleStatus) {
-        this.helper = helper;
+    constructor(ctx, info, settleStatus) {
+        this.helper = ctx.helper;
+        this.correct = ctx.subProject.page_show.correctCalcContractTp;
         this.info = info;
         this.precision = info.precision;
         this.decimal = info.decimal;
@@ -156,16 +157,32 @@ class autoUseChange {
             this._calculateQty(cb, minus, bills);
         }
     }
-    calcContractTp(bills, contract_qty, qc_minus_qty) {
-        const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
-        let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
-        let end_contract_qty = contract_qty;
-        if (preSb) {
-            activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
-            end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
-        }
-        const end_contract_tp = this.helper.mul(this.helper.div(end_contract_qty, activeQty), bills.total_price, this.decimal.tp);
-        return preSb ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
+    calcContractTp(info, bills, contract_qty, qc_minus_qty) {
+        if (info.calc_type === 'tp') {
+            const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
+            let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
+            let end_contract_qty = contract_qty;
+            if (preSb) {
+                activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
+                end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
+            }
+            const end_contract_tp = this.helper.mul(this.helper.div(end_contract_qty, activeQty), bills.total_price, this.decimal.tp);
+            return preSb ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
+        } else if (info.calc_type === 'up') {
+            if (this.correct) {
+                const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
+                let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
+                let end_contract_qty = contract_qty;
+                if (preSb) {
+                    activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
+                    end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
+                }
+                const end_contract_tp = this.helper.mul(end_contract_qty, bills.unit_price, this.decimal.tp);
+                return activeQty === end_contract_qty ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : this.helper.mul(contract_qty, bills.unit_price, this.decimal.tp);
+            } else {
+                return this.helper.mul(contract_qty, bills.unit_price, this.decimal.tp);
+            }
+        }
     }
     calculateAll() {
         for (const cd of this.changeDetail) {
@@ -232,7 +249,7 @@ class autoUseChange {
             const sb = this.stageBills.find(x => {return x.lid === lid});
 
             if (sb) {
-                const contract_tp = qc_minus_qty && this.info.calc_type === 'tp' && sb.contract_qty ? this.calcContractTp(cb.bills, sb.contract_qty, qc_minus_qty) : 0;
+                const contract_tp = qc_minus_qty && sb.contract_qty ? this.calcContractTp(this.info, cb.bills, sb.contract_qty, qc_minus_qty) : 0;
                 this.updateBills.push({ id: sb.id, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, qc_minus_qty, contract_tp });
             } else {
                 this.insertBills.push({
@@ -845,7 +862,7 @@ module.exports = app => {
             const stageChange = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, lid }});
             const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, stage.preCheckedStage.order) : [];
 
-            const useModal = new autoUseChange(this.ctx.helper, tender.info);
+            const useModal = new autoUseChange(this.ctx, tender.info);
             const projectFunInfo = this.ctx.subProject.fun_rela;
             const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
             useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
@@ -895,7 +912,7 @@ module.exports = app => {
             const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
             const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
             const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, stage.preCheckedStage.order) : [];
-            const useModal = new autoUseChange(this.ctx.helper, tender.info, this.ctx.service.settle.settleStatus);
+            const useModal = new autoUseChange(this.ctx, tender.info, this.ctx.service.settle.settleStatus);
             const projectFunInfo = this.ctx.subProject.fun_rela;
             const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
             useModal.use({ledgerData, posData, stageBills, stagePos, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);

+ 25 - 2
app/service/stage_stash.js

@@ -63,6 +63,7 @@ class loadStageExcelTree {
         });
     }
     calcContractTp(node, contract_qty, qc_minus_qty) {
+        const correct = this.ctx.subProject.page_show.correctCalcContractTp;
         if (this.info.calc_type === 'tp') {
             const preSb = this.preStageBills.find(x => { return x.lid === node.id; });
             let activeQty = this.ctx.helper.add(node.quantity, qc_minus_qty);
@@ -74,7 +75,19 @@ class loadStageExcelTree {
             const end_contract_tp = this.ctx.helper.mul(this.ctx.helper.div(end_contract_qty, activeQty), node.total_price, this.decimal.tp);
             return preSb ? this.ctx.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
         } else if (this.info.calc_type === 'up') {
-            return this.ctx.helper.mul(contract_qty, node.unit_price, this.decimal.tp);
+            if (correct) {
+                const preSb = this.preStageBills.find(x => { return x.lid === node.id; });
+                let activeQty = this.ctx.helper.add(node.quantity, qc_minus_qty);
+                let end_contract_qty = contract_qty;
+                if (preSb) {
+                    activeQty = this.ctx.helper.add(activeQty, preSb.qc_minus_qty);
+                    end_contract_qty = this.ctx.helper.add(end_contract_qty, preSb.contract_qty);
+                }
+                const end_contract_tp = this.ctx.helper.mul(end_contract_qty, node.unit_price, this.decimal.tp);
+                return activeQty === end_contract_qty ? this.ctx.helper.sub(end_contract_tp, preSb.pre_contract_tp) : this.ctx.helper.mul(contract_qty, node.unit_price, this.decimal.tp);
+            } else {
+                return this.ctx.helper.mul(contract_qty, node.unit_price, this.decimal.tp);
+            }
         }
     }
     loadLeaf(node, source) {
@@ -269,6 +282,7 @@ module.exports = app => {
 
 
         async reCalcStashData(stage, data) {
+            const correct = this.ctx.subProject.page_show.correctCalcContractTp;
             const calcContractTp = function(helper, info, stageBills, bills) {
                 if (info.calc_type === 'tp') {
                     let activeQty = helper.add(bills.quantity, stageBills.qc_minus_qty);
@@ -278,7 +292,16 @@ module.exports = app => {
                     const end_contract_tp = helper.mul(helper.div(end_contract_qty, activeQty), bills.total_price, decimal.tp);
                     return helper.sub(end_contract_tp, bills.pre_contract_tp);
                 } else if (info.calc_type === 'up') {
-                    return helper.mul(bills.unit_price, stageBills.contract_qty, info.decimal.tp);
+                    if (correct) {
+                        let activeQty = helper.add(bills.quantity, stageBills.qc_minus_qty);
+                        let end_contract_qty = stageBills.contract_qty;
+                        activeQty = helper.add(activeQty, bills.pre_qc_minus_qty);
+                        end_contract_qty = helper.add(end_contract_qty, bills.pre_contract_qty);
+                        const end_contract_tp = helper.mul(end_contract_qty, bills.unit_price, decimal.tp);
+                        return activeQty === end_contract_qty ? helper.sub(end_contract_tp, bills.pre_contract_tp) : helper.mul(bills.unit_price, stageBills.contract_qty, info.decimal.tp);
+                    } else {
+                        return helper.mul(bills.unit_price, stageBills.contract_qty, info.decimal.tp);
+                    }
                 }
             };
             const decimal = this.ctx.tender.info.decimal;

+ 8 - 0
app/view/sp_setting/fun.ejs

@@ -217,6 +217,13 @@
                                                 <label class="form-check-label" for="openMultiStageCalc">开启「待上报时,允许新增下一期」功能</label>
                                             </div>
                                         </div>
+                                        <div class="form-group mb-1">
+                                            <div class="form-check form-check-inline">
+                                                <input class="form-check-input" type="checkbox" id="correctCalcContractTp" <% if (ctx.subProject.page_show.correctCalcContractTp) { %>checked<% } %> onchange="updateSetting();">
+                                                <label class="form-check-label" for="correctCalcContractTp">开启「反算本期合同计量」功能</label>
+                                                <a href="" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="开启此选项,清单最后一次合同计量,将重算本期合同计量金额"><i class="fa fa-question-circle "></i></a>
+                                            </div>
+                                        </div>
                                     </div>
                                 </div>
                             </div>
@@ -617,6 +624,7 @@
             openMaterialStageRepeat: $('#openMaterialStageRepeat')[0].checked,
             openStageStart: $('#openStageStart')[0].checked,
             openContractExpr: $('#openContractExpr')[0].checked,
+            correctCalcContractTp: $('#correctCalcContractTp')[0].checked,
             close1stStageCheckDealParam: $('#close1stStageCheckDealParam')[0].checked,
             openMultiStageCalc: $('#openMultiStageCalc')[0].checked,
             closeWapYfSf: $('#closeWapYfSf')[0].checked,

+ 1 - 0
app/view/stage/index.ejs

@@ -580,6 +580,7 @@
     const contractExpr = <%- !!ctx.subProject.page_show.openContractExpr %>;
     const deleteFilePermission = <%- deleteFilePermission %>;
     const limits = JSON.parse('<%- JSON.stringify(limits) %>');
+    const correctCalcContractTp = <%- !!ctx.subProject.page_show.correctCalcContractTp %>;
 </script>
 <style>
 

+ 5 - 1
app/view/stage/modal.ejs

@@ -657,13 +657,17 @@
                 <h5 class="modal-title">帮助</h5>
             </div>
             <div class="modal-body">
-                <div class="modal-height-150">
+                <div class="modal-height-250">
                     <label for="">1、本期补差计算公式</label>
                     <div class="in-2">
                         <label for="">本期补差=本期合同补差+本期变更补差。</label>
                         <label>本期合同补差:新单价*截止上期合同数量-截止上期合同计量金额。</label>
                         <label for="">本期变更补差:新单价*截止上期变更数量-截止上期变更计量金额。</label>
                     </div>
+                    <label for=""> 2、重算本期合同计量金额</label>
+                    <div class="in-2">
+                        <label for="">开启此选项,清单最后一次合同计量时,本期合同计量金额=截止本期合同数量*单价-截止上期合同计量金额。</label>
+                    </div>
                 </div>
             </div>
             <div class="modal-footer">