Selaa lähdekoodia

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang 3 viikkoa sitten
vanhempi
commit
c727dd492e

+ 51 - 0
app/controller/stage_controller.js

@@ -590,6 +590,54 @@ module.exports = app => {
             return checkData.checkResult.error;
         }
 
+        async _checkChangeDetail(ctx) {
+            const errors = [];
+            const checkBills = await this.ctx.service.stageChange.getUsedId(ctx.stage.id);
+            const curBillsData = ctx.stage.readOnly
+                ? await ctx.service.stageBills.getAuditorStageData2(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder)
+                : await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, ctx.stage.id);
+            this.ctx.helper.assignRelaData(checkBills, [
+                { data: curBillsData, fields: ['qc_qty', 'qc_minus_qty'], prefix: '', relaId: 'lid' },
+            ], 'lid');
+            const checkPos = await this.ctx.service.stageChange.getUsedId(ctx.stage.id, false);
+            const curPosData = ctx.stage.readOnly
+                ? await ctx.service.stagePos.getAuditorStageData2(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder)
+                : await ctx.service.stagePos.getLastestStageData2(ctx.tender.id, ctx.stage.id);
+            this.ctx.helper.assignRelaData(checkPos, [
+                { data: curPosData, fields: ['qc_qty', 'qc_minus_qty'], prefix: '', relaId: 'pid' },
+            ], 'pid');
+            const stageChange = ctx.stage.readOnly
+                ? await ctx.service.stageChange.getAuditorAllStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder)
+                : await ctx.service.stageChange.getLastestAllStageData(ctx.tender.id, ctx.stage.id);
+            for (const cb of checkBills) {
+                const useChanges = stageChange.filter(sc => { return sc.lid === cb.lid && sc.pid === '-1'});
+                const checkQcQty = cb.qc_qty || 0, checkQcMinusQty = cb.qc_minus_qty || 0;
+                let qc_qty = 0, qc_minus_qty = 0;
+                for (const uc of useChanges) {
+                    if (uc.no_value) {
+                        qc_minus_qty = this.ctx.helper.add(qc_minus_qty, uc.qty);
+                    } else {
+                        qc_qty = this.ctx.helper.add(qc_qty, uc.qty);
+                    }
+                }
+                if (qc_qty !== checkQcQty || qc_minus_qty !== checkQcMinusQty) errors.push({ lid: cb.lid });
+            }
+            for (const cb of checkPos) {
+                const useChanges = stageChange.filter(sc => { return sc.lid === cb.lid && sc.pid === cb.pid; });
+                const checkQcQty = cb.qc_qty || 0, checkQcMinusQty = cb.qc_minus_qty || 0;
+                let qc_qty = 0, qc_minus_qty = 0;
+                for (const uc of useChanges) {
+                    if (uc.no_value) {
+                        qc_minus_qty = this.ctx.helper.add(qc_minus_qty, uc.qty);
+                    } else {
+                        qc_qty = this.ctx.helper.add(qc_qty, uc.qty);
+                    }
+                }
+                if (qc_qty !== checkQcQty || qc_minus_qty !== checkQcMinusQty) errors.push({ lid: cb.lid, pid: cb.pid });
+            }
+            return errors;
+        }
+
         async stageCheck(ctx) {
             try {
                 if (!ctx.query.type) throw '参数错误';
@@ -603,6 +651,9 @@ module.exports = app => {
                         case 'change_over':
                             result.change_over = await this._checkChangeBillsOver(ctx);
                             break;
+                        case 'change_detail':
+                            result.change_detail = ctx.session.sessionUser.loginStatus ? await this._checkChangeDetail(ctx) : [];
+                            break;
                     }
                 }
                 ctx.body = { err: 0, msg: '', data: result };

+ 2 - 1
app/public/js/ledger_check.js

@@ -33,6 +33,7 @@ const ledgerCheckType = {
     },
     minus_cb: { value: 13, text: '负变更清单漏计', url: window.location.pathname + '/stageCheck?type=minus_cb' },
     change_over: { value: 14, text: '变更令超计', url: window.location.pathname + '/stageCheck?type=change_over'},
+    change_detail: { value: 15, text: '变更统计错误', url: window.location.pathname + '/stageCheck?type=change_detail'},
 };
 const ledgerCheckUtil = {
     checkSibling: function (ledgerTree, ledgerPos, decimal, option) {
@@ -525,7 +526,7 @@ const ledgerCheck2 = async function (setting) {
             if (errors && errors[prop]) {
                 errors[prop].forEach(mcb => {
                     checkData.warning_data.push({
-                        type: checkInfo.value, code: mcb.memo, b_code: mcb.b_code, name: mcb.name, lid: mcb.lid
+                        type: checkInfo.value, code: mcb.memo, b_code: mcb.b_code, name: mcb.name, lid: mcb.lid, pid: mcb.pid,
                     });
                 });
             }

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

@@ -255,6 +255,7 @@ $(document).ready(() => {
         over: { enable: 1, isTz: checkTzMeasureType(), checkInfo: tenderInfo.checkOverInfo },
         limit3f: { enable: 1, checkType: [], status: thirdParty, },
         minus_cb: { enable: hintMinusCb },
+        change_detail: { enable: is_debug },
         // change_over: { enable: 1 },
     };
     if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');

+ 5 - 0
app/service/stage_change.js

@@ -955,6 +955,11 @@ module.exports = app => {
                 }, { where: { id: this._.map(oldSBLists, 'id') } });
             }
         }
+
+        async getUsedId(sid, bills = true) {
+            const sql = `SELECT lid, pid FROM ${this.tableName} WHERE sid = ? and pid ${(bills ? '=' : '<>')} ? GROUP BY lid ${(bills ? '' : ', pid')}`;
+            return await this.db.query(sql, [sid, '-1'])
+        }
     }
 
     return StageChange;

+ 34 - 17
app/service/stage_pos.js

@@ -282,26 +282,24 @@ module.exports = app => {
                             said: this.ctx.session.sessionUser.accountId,
                             times: this.ctx.stage.curTimes, order: this.ctx.stage.curOrder
                         };
-                        if (d.contract_qty !== undefined || osp) {
-                            sp.contract_qty = d.contract_qty === undefined && osp
-                                ? osp.contract_qty
-                                : this.ctx.helper.round(d.contract_qty, precision.value);
+                        if (d.contract_qty !== undefined) {
+                            sp.contract_qty = this.ctx.helper.round(d.contract_qty, precision.value) || 0;
+                        } else {
+                            sp.contract_qty = osp ? osp.contract_qty || 0 : 0;
                         }
                         if (d.contract_expr !== undefined) sp.contract_expr = d.contract_expr;
-                        if (d.qc_qty || osp) {
-                            sp.qc_qty = d.qc_qty === undefined && osp
-                                ? osp.qc_qty
-                                : this.ctx.helper.round(d.qc_qty, precision.value);
-                        }
                         if (d.postil || osp) {
                             sp.postil = d.postil === undefined && osp ? osp.postil : d.postil;
                         }
-                        if (d.ex_stage_qty1 || osp) {
-                            sp.ex_stage_qty1 = d.ex_stage_qty1 === undefined && osp ? osp.ex_stage_qty1 : d.ex_stage_qty1;
+                        if (d.ex_stage_qty1 !== undefined) {
+                            sp.ex_stage_qty1 = this.ctx.helper.round(d.ex_stage_qty1, precision.value) || 0;
+                        } else {
+                            sp.ex_stage_qty1 = osp ? osp.ex_stage_qty1 || 0 : 0;
                         }
-                        sp.qc_minus_qty = osp ? osp.qc_minus_qty : 0;
-                        sp.positive_qc_qty = osp ? osp.positive_qc_qty : 0;
-                        sp.negative_qc_qty = osp ? osp.negative_qc_qty : 0;
+                        sp.qc_qty = osp ? osp.qc_qty || 0 : 0;
+                        sp.qc_minus_qty = osp ? osp.qc_minus_qty || 0 : 0;
+                        sp.positive_qc_qty = osp ? osp.positive_qc_qty || 0 : 0;
+                        sp.negative_qc_qty = osp ? osp.negative_qc_qty || 0 : 0;
                         insertPosStage.push(sp);
                     }
                 }
@@ -390,6 +388,13 @@ module.exports = app => {
                             ? osp.contract_qty
                             : this.ctx.helper.round(d.contract_qty, b.precision.value);
                         sp.contract_expr = d.contract_expr;
+                        if (osp) {
+                            sp.qc_qty = osp.qc_qty || 0;
+                            sp.qc_minus_qty = osp.qc_minus_qty || 0;
+                            sp.positive_qc_qty = osp.positive_qc_qty || 0;
+                            sp.negative_qc_qty = osp.positive_qc_qty || 0;
+                            sp.ex_stage_qty1 = osp.ex_stage_qty1 || 0;
+                        }
                     }
                     insertPosStage.push(sp);
                 }
@@ -422,15 +427,27 @@ module.exports = app => {
                     });
                 } else {
                     const contract_tp = await this.ctx.service.stageBills.calcContractTp(this.ctx.tender.info, this.ctx.stage, b, { contract_qty, qc_minus_qty: 0 });
-                    insertBillsStage.push({
+                    const ibs = {
                         tid: this.ctx.tender.id,
                         lid: b.id,
                         sid: this.ctx.stage.id,
                         times: this.ctx.stage.curTimes,
                         order: this.ctx.stage.curOrder,
                         said: this.ctx.session.sessionUser.accountId,
-                        contract_qty: contract_qty, contract_tp
-                    })
+                        contract_qty: contract_qty, contract_tp,
+                    };
+                    if (stageBills) {
+                        ibs.qc_qty = stageBills.qc_qty || 0;
+                        ibs.qc_tp = stageBills.qc_tp || 0;
+                        ibs.qc_minus_qty = stageBills.qc_minus_qty || 0;
+                        ibs.positive_qc_qty = stageBills.positive_qc_qty || 0;
+                        ibs.positive_qc_tp = stageBills.positive_qc_tp || 0;
+                        ibs.negative_qc_qty = stageBills.negative_qc_qty || 0;
+                        ibs.negative_qc_tp = stageBills.negative_qc_tp || 0;
+                        ibs.ex_stage_qty1 = stageBills.ex_stage_qty1 || 0;
+                        ibs.ex_stage_tp1 = stageBills.ex_stage_tp1 || 0;
+                    }
+                    insertBillsStage.push(ibs);
                 }
             }