浏览代码

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

laiguoran 3 年之前
父节点
当前提交
424ddffac7
共有 4 个文件被更改,包括 78 次插入39 次删除
  1. 55 26
      app/service/report_memory.js
  2. 19 12
      app/service/stage_stash.js
  3. 1 1
      app/view/stage/index.ejs
  4. 3 0
      builder_report_index_define.js

+ 55 - 26
app/service/report_memory.js

@@ -29,6 +29,7 @@ const billsFields = (function () {
     const pre = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
     const end = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
     const final = ['final_tp', 'final_ratio'];
+    const final1 = ['minus_qc_qty', 'pre_minus_qc_qty', 'end_minus_qc_qty', 'final_1_qty', 'final_1_tp', 'final_1_ratio'];
     const stageDgn = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
 
     const stage = cur.concat(pre, end, final);
@@ -36,19 +37,20 @@ const billsFields = (function () {
     const bgl = ['qc_bgl_code'];
     const leafXmj = ['leaf_xmj_id'];
 
-    return {cur, pre, end, final, stageDgn, stage, stageEnd, bgl, leafXmj};
+    return {cur, pre, end, final, final1, stageDgn, stage, stageEnd, bgl, leafXmj};
 })();
 const posFields = (function () {
     const cur = ['contract_qty', 'qc_qty', 'gather_qty', 'postil'];
     const pre = ['pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty'];
     const end = ['end_contract_qty', 'end_qc_qty', 'end_gather_qty'];
     const final = ['final_ratio'];
+    const final1 = ['minus_qc_qty', 'pre_minus_qc_qty', 'end_minus_qc_qty', 'final_1_qty', 'final_1_ratio'];
 
     const stage = cur.concat(pre, end, final);
     const stageEnd = pre.concat(end, final);
     const bgl = ['qc_bgl_code'];
 
-    return {cur, pre, end, final, stage, stageEnd, bgl};
+    return {cur, pre, end, final, final1, stage, stageEnd, bgl};
 })();
 
 module.exports = app => {
@@ -71,10 +73,20 @@ module.exports = app => {
                 updateFields: ['contract_qty', 'qc_qty', 'postil'],
                 calc: function (p) {
                     p.pre_gather_qty = ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty);
+
                     p.gather_qty = ctx.helper.add(p.contract_qty, p.qc_qty);
+
                     p.end_contract_qty = self.ctx.helper.add(p.pre_contract_qty, p.contract_qty);
                     p.end_qc_qty = self.ctx.helper.add(p.pre_qc_qty, p.qc_qty);
                     p.end_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty);
+
+                    p.final_qty = ctx.helper.add(p.end_qc_qty, p.quantity);
+                    p.final_ratio = ctx.helper.mul(ctx.helper.div(p.end_gather_qty, p.final_qty, 4), 100);
+
+                    p.end_minus_qc_qty = ctx.helper.add(p.pre_minus_qc_qty, p.minus_qc_qty);
+                    p.final_1_qty = ctx.helper.add(p.end_minus_qc_qty, p.quantity);
+                    p.end_final_1_qty = ctx.helper.add(p.final_1_qty, p.end_qc_qty);
+                    p.final_1_ratio = ctx.helper.mul(ctx.helper.div(p.end_gather_qty, p.end_final_1_qty, 4), 100);
                 }
             });
             // 需要缓存的数据
@@ -94,14 +106,17 @@ module.exports = app => {
                 rootId: -1,
                 keys: ['id', 'tender_id', 'ledger_id'],
                 stageId: 'id',
-                calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'],
-                calc: function (node, helper) {
+                calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'final_1_tp'],
+                calc: function (node, helper, decimal) {
                     if (node.children && node.children.length === 0) {
                         node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
                         node.gather_qty = helper.add(node.contract_qty, node.qc_qty);
                         node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty);
                         node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty);
                         node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty);
+                        node.end_minus_qc_qty = helper.add(node.pre_minus_qc_qty, node.minus_qc_qty);
+                        node.final_1_qty = helper.add(node.quantity, node.end_minus_qc_qty);
+                        node.end_final_1_qty = helper.add(node.final_1_qty, node.end_qc_qty);
                     }
                     node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
                     node.gather_tp = helper.add(node.contract_tp, node.qc_tp);
@@ -111,6 +126,10 @@ module.exports = app => {
 
                     node.final_tp = helper.add(node.total_price, node.end_qc_tp);
                     node.final_ratio = helper.mul(helper.div(node.end_gather_tp, node.final_tp, 4), 100);
+
+                    node.final_1_tp = helper.mul(node.unit_price, node.final_1_qty, decimal.tp);
+                    node.end_final_1_tp = helper.add(node.final_1_tp, node.end_qc_tp);
+                    node.final_1_ratio = helper.mul(helper.div(node.end_gather_tp, node.end_final_1_tp, 4), 100);
                 }
             });
         }
@@ -373,24 +392,29 @@ module.exports = app => {
                         this.ctx.helper._.assignIn(l, d);
                     }
                 }
+                let preStage = [], curStage = [];
                 if (this._checkFieldsExist(fields, billsFields.stage)) {
                     if (this.ctx.stage.readOnly) {
-                        const curStage = await this.ctx.service.stageBills.getAuditorStageData2(this.ctx.tender.id,
+                        curStage = await this.ctx.service.stageBills.getAuditorStageData2(this.ctx.tender.id,
                             this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
-                        this.ctx.helper.assignRelaData(billsData, [
-                            {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
-                        ]);
                     } else {
-                        const curStage = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
-                        this.ctx.helper.assignRelaData(billsData, [
-                            {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
-                        ]);
+                        curStage = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
                     }
                 }
                 if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
-                    const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
-                    this.ctx.helper.assignRelaData(billsData, [
-                        {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
+                    preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
+                }
+                this.ctx.helper.assignRelaData(billsData, [
+                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'},
+                    {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
+                ]);
+                if (this._checkFieldsExist(fields, billsFields.final1)) {
+                    const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(this.ctx.stage.tid, this.ctx.stage.order);
+                    const changeData = await this._getStageChangeData(this.ctx);
+                    const minusChange = changeData.filter(x => { return x.minus });
+                    this.ctx.helper.assignSumRelaData(billsData, 'id', [
+                        {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'lid'},
+                        {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'lid'},
                     ]);
                 }
 
@@ -443,24 +467,29 @@ module.exports = app => {
                 }
 
                 const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
+                let curPosStage = [], prePosStage = [];
                 if (this._checkFieldsExist(fields, posFields.stage)) {
                     if (this.ctx.stage.readOnly) {
-                        const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
+                        curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
                             this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
-                        this.ctx.helper.assignRelaData(posData, [
-                            {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
-                        ]);
                     } else {
-                        const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
-                        this.ctx.helper.assignRelaData(posData, [
-                            {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
-                        ]);
+                        curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
                     }
                 }
                 if (this._checkFieldsExist(fields, posFields.stageEnd)) {
-                    const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
-                    this.ctx.helper.assignRelaData(posData, [
-                        {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
+                    prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
+                }
+                this.ctx.helper.assignRelaData(posData, [
+                    {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'},
+                    {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
+                ]);
+                if (this._checkFieldsExist(fields, posFields.final1)) {
+                    const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(this.ctx.stage.tid, this.ctx.stage.order);
+                    const changeData = await this._getStageChangeData(this.ctx);
+                    const minusChange = changeData.filter(x => { return x.minus });
+                    this.ctx.helper.assignSumRelaData(posData, 'id', [
+                        {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'pid'},
+                        {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'pid'},
                     ]);
                 }
                 this.pos.loadDatas(posData);

+ 19 - 12
app/service/stage_stash.js

@@ -124,20 +124,27 @@ module.exports = app => {
                     nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
                     nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
                 } else {
-                    nbs.contract_qty = this.ctx.helper.round(d.contract_qty, decimal.qty);
-                    nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
-                    nbs.qc_qty = 0;
-                    if (d.change) {
-                        for (const c of d.change) {
-                            if (!c.qty) continue;
-                            const ncs = { tid: stage.tid, sid: stage.id, lid: d.id, pid: -1, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid, minus: c.minus };
-                            const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
-                            ncs.qty = validQty >= c.qty ? c.qty : validQty;
-                            insertChangeData.push(ncs);
-                            if (!ncs.minus) nbs.qc_qty = await this.ctx.helper.add(nbs.qc_qty, ncs.qty);
+                    if (b.is_tp) {
+                        nbs.contract_qty = 0;
+                        nbs.contract_tp = this.ctx.helper.round(d.contract_tp, decimal.tp);
+                        nbs.qc_qty = 0;
+                        nbs.qc_tp = 0;
+                    } else {
+                        nbs.contract_qty = this.ctx.helper.round(d.contract_qty, decimal.qty);
+                        nbs.contract_tp = this.ctx.helper.mul(nbs.contract_qty, b.unit_price, decimal.tp);
+                        nbs.qc_qty = 0;
+                        if (d.change) {
+                            for (const c of d.change) {
+                                if (!c.qty) continue;
+                                const ncs = { tid: stage.tid, sid: stage.id, lid: d.id, pid: -1, stimes: 1, sorder: 0, cid: c.cid, cbid: c.cbid, minus: c.minus };
+                                const validQty = await this.ctx.service.stageChangeFinal.getChangeBillsValidQty(c.cbid);
+                                ncs.qty = validQty >= c.qty ? c.qty : validQty;
+                                insertChangeData.push(ncs);
+                                if (!ncs.minus) nbs.qc_qty = await this.ctx.helper.add(nbs.qc_qty, ncs.qty);
+                            }
                         }
+                        nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
                     }
-                    nbs.qc_tp = this.ctx.helper.mul(nbs.qc_qty, b.unit_price, decimal.tp);
                 }
                 insertBillsData.push(nbs);
             }

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

@@ -34,7 +34,7 @@
                 </div>
                 <div class="d-inline-block ml-3">
                     <a id="exportExcel" class="btn btn-primary btn-sm" href="javascript: void(0)">导出计量台账Excel</a>
-                    <% if (!ctx.stage.readOnly && !ctx.stage.revising && ctx.stage.status === auditConst.status.uncheck) { %>
+                    <% if (ctx.app.config.is_debug && !ctx.stage.readOnly && !ctx.stage.revising && ctx.stage.status === auditConst.status.uncheck) { %>
                     <a id="importExcel" class="btn btn-primary btn-sm" href="javascript: void(0)">导入计量台账Excel</a>
                     <% } %>
                     <a class="btn btn-sm btn-primary" href="javascript: void(0);" id="ledger-check2">数据检查</a>

+ 3 - 0
builder_report_index_define.js

@@ -715,6 +715,8 @@ const stage_bills = {
         { name: '截止本期负变更', field: 'pre_minus_qc_qty', type: dataType.double },
         { name: '1#台账(台账+截止本期负变更)-数量', field: 'final_1_qty', type: dataType.double },
         { name: '1#台账(台账+截止本期负变更)-金额', field: 'final_1_tp', type: dataType.double },
+        { name: '1#台账+截止本期变更-数量', field: 'end_final_1_qty', type: dataType.double },
+        { name: '1#台账+截止本期变更-金额', field: 'end_final_1_tp', type: dataType.double },
         { name: '1#完成率(%)', field: 'final_1_ratio', type: dataType.double },
     ],
 };
@@ -895,6 +897,7 @@ const stage_pos = {
         { name: '截止上期负变更', field: 'pre_minus_qc_qty', type: dataType.double },
         { name: '截止本期负变更', field: 'pre_minus_qc_qty', type: dataType.double },
         { name: '1#台账(台账+截止本期负变更)-数量', field: 'final_1_qty', type: dataType.double },
+        { name: '1#台账+截止本期变更-数量', field: 'end_final_1_qty', type: dataType.double },
         { name: '1#完成率(%)', field: 'final_1_ratio', type: dataType.double },
     ],
 };