浏览代码

关联台账,中间计量相关

MaiXinRong 3 年之前
父节点
当前提交
2c29bf0f24
共有 4 个文件被更改,包括 46 次插入20 次删除
  1. 2 1
      app/controller/stage_rela_controller.js
  2. 9 6
      app/lib/stage_im.js
  3. 8 9
      app/public/js/sr_detail.js
  4. 27 4
      app/public/js/stage_im.js

+ 2 - 1
app/controller/stage_rela_controller.js

@@ -121,6 +121,7 @@ module.exports = app => {
         async _getStageRelaLedgerData(ctx, relaStage) {
             const ledgerData = await ctx.service.ledger.getData(relaStage.rela_tid);
             for (const l of ledgerData) {
+                l.org_unit_price = l.unit_price;
                 delete l.unit_price;
             }
             const dgnData = await ctx.service.stageBillsDgn.getDgnData(relaStage.rela_tid);
@@ -132,7 +133,7 @@ module.exports = app => {
             });
             this.ctx.helper.assignRelaData(ledgerData, [
                 { data: dgnData, fields: ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'], prefix: '', relaId: 'id' },
-                { data: curStageData, fields: ['unit_price', 'contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
+                { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
                 { data: endStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', ], prefix: 'end_', relaId: 'lid' },
             ]);
             return ledgerData;

+ 9 - 6
app/lib/stage_im.js

@@ -63,6 +63,7 @@ class StageIm {
         //
         this.imFields = ['uuid', 'doc_code', 'peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'calc_memo_org', 'calc_img_remark', 'calc_img', 'position', 'jldy'];
         this.splitChar = '-';
+
     }
 
     // 加载数据
@@ -328,7 +329,7 @@ class StageIm {
                         (!im.code || im.code === d.code) &&
                         (!im.name || im.name === d.name) &&
                         (!im.unit || im.unit === d.unit) &&
-                        self.ctx.helper.checkZero(self.ctx.helper.sub(im.unit_price, d.unit_price)) &&
+                        self.ctx.helper.checkZero(self.ctx.helper.sub(im[up_field], d[up_field])) &&
                         (!im.pid || im.pid === d.pid) &&
                         (!im.pos_name || im.pos_name === d.pos_name);
                 });
@@ -339,7 +340,7 @@ class StageIm {
                         (!im.code || im.code === d.code) &&
                         (!im.name || im.name === d.name) &&
                         (!im.unit || im.unit === d.unit) &&
-                        self.ctx.helper.checkZero(self.ctx.helper.sub(im.unit_price, d.unit_price)) &&
+                        self.ctx.helper.checkZero(self.ctx.helper.sub(im[up_field], d[up_field])) &&
                         (!im.pid || im.pid === d.pid) &&
                         (!im.pos_name || im.pos_name === d.pos_name);
                 });
@@ -838,13 +839,13 @@ class StageIm {
             let im = nodeImData.find(function(d) {
                 return d.lid === node.id &&
                     d.code === p.b_code && p.name === d.name && p.unit === d.unit &&
-                    self.ctx.helper.checkZero(self.ctx.helper.sub(p.unit_price, d.unit_price));
+                    self.ctx.helper.checkZero(self.ctx.helper.sub(p[up_field], d[up_field]));
             });
             if (!im) {
                 const peg = this._getPegNode(node);
                 im = {
                     id: this.ImData.length + 1,
-                    lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
+                    lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price,
                     quantity: 0, total_price: 0,
                     jl: 0, contract_jl: 0, qc_jl: 0,
                     pre_jl: 0, pre_contract_jl: 0, pre_qc_jl: 0,
@@ -919,7 +920,7 @@ class StageIm {
                     if (this.ctx.helper.checkZero(pp.contract_qty) && this.ctx.helper.checkZero(pp.qc_qty)) { continue; }
                     const im = {
                         id: this.ImData.length + 1,
-                        lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: pp.id,
+                        lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price, pid: pp.id,
                         quantity: pp.quantity,
                         jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty,
                         pre_jl: pp.pre_gather_qty, pre_contract_jl: pp.pre_contract_qty, pre_qc_jl: pp.pre_qc_qty,
@@ -958,7 +959,7 @@ class StageIm {
 
                 const im = {
                     id: this.ImData.length + 1,
-                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: '',
+                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, org_unit_price: p.org_unit_price, pid: '',
                     quantity: p.quantity, total_price: p.total_price,
                     jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty,
                     pre_jl: p.pre_gather_qty, pre_contract_jl: p.pre_contract_qty, pre_qc_jl: p.pre_qc_qty,
@@ -1015,6 +1016,7 @@ class StageIm {
 
     // 生成中间计量数据
     async buildImData() {
+        this.up_field = 'unit_price';
         const self = this;
         this.stage = this.ctx.stage;
         // 初始化
@@ -1053,6 +1055,7 @@ class StageIm {
     }
 
     buildRelaStageIm(stage, billsTree, pos, details, changes) {
+        this.up_field = 'org_unit_price';
         this.billsTree = billsTree;
         this.pos = pos;
         this.stage = stage;

+ 8 - 9
app/public/js/sr_detail.js

@@ -409,7 +409,7 @@ $(document).ready(() => {
                             spSpread.refresh();
                         }
                         const relaXmj = stageIm.getRelaXmj(leafUsedBills);
-                        const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
+                        const im = stageIm.getRelaImData4Rela(relaXmj, leafUsedBills, usedPos);
                         SpreadJsObj.locateData(detail.sheet, im);
                         detail.spread.refresh();
                         $('#zhongjian .sjs-bottom').height('400px');
@@ -519,15 +519,14 @@ $(document).ready(() => {
     // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
     postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;sumDeal' }, function (result) {
         for (const l of result.ledgerData) {
+            if (!l.is_leaf) continue;
             const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
-            if (sd) {
-                l.unit_price = sd.unit_price;
-                l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
-                l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
-                l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
-                l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
-                l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
-            }
+            l.unit_price = sd ? sd.unit_price : 0;
+            l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
+            l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
+            l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
+            l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
+            l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
         }
         // 加载树结构
         stageTree.loadDatas(result.ledgerData);

+ 27 - 4
app/public/js/stage_im.js

@@ -14,6 +14,7 @@ const stageIm = (function () {
     const splitChar = '-';
     const mergeChar = ';';
     let stage, imType, decimal, details, changes, detailsAtt, ImData, pre, orgImData;
+    let up_field = 'unit_price';
     const gsTreeSetting = {
         id: 'ledger_id',
         pid: 'ledger_pid',
@@ -67,6 +68,7 @@ const stageIm = (function () {
     }
 
     function loadData (ledger, pos, stageDetail, stageChange, stageDetailAtt) {
+        up_field = 'unit_price';
         gsTree.loadDatas(ledger);
         treeCalc.calculateAll(gsTree);
 
@@ -82,6 +84,7 @@ const stageIm = (function () {
     }
 
     function loadData4Rela(ledger, pos, stageDetail, stageChange, stageDetailAtt) {
+        up_field = 'org_unit_price';
         gsTree.loadDatas(ledger);
         treeCalc.calculateAll(gsTree);
 
@@ -807,12 +810,12 @@ const stageIm = (function () {
             if (!checkUsed(p)) { continue; }
             let im = nodeImData.find(function (d) {
                 return d.lid === node.id &&
-                    d.code === p.b_code && p.name === d.name && p.unit === d.unit && checkZero(ZhCalc.sub(p.unit_price, d.unit_price));
+                    d.code === p.b_code && p.name === d.name && p.unit === d.unit && checkZero(ZhCalc.sub(p[up_field], d.unit_price));
             });
             if (!im) {
                 const peg = getPegNode(node);
                 im = {
-                    lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price,
+                    lid: node.id, pid: '', code: p.b_code, name: p.name, unit: p.unit, unit_price: p[up_field],
                     jl: 0, contract_jl: 0, qc_jl: 0,
                     peg: peg ? getPegStr(peg.name) : '',
                     position: '',
@@ -857,7 +860,7 @@ const stageIm = (function () {
                 for (const pp of pPos) {
                     if (checkZero(pp.contract_qty) && checkZero(pp.qc_qty)) { continue }
                     const im = {
-                        lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: pp.id,
+                        lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p[up_field], pid: pp.id,
                         jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty,
                         //im_code: getNewImCode(),
                         bw: bw, jldy: pp.name,
@@ -885,7 +888,7 @@ const stageIm = (function () {
                 if (checkZero(p.gather_qty) && checkZero(p.gather_tp)) { continue }
 
                 const im = {
-                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p.unit_price, pid: '',
+                    lid: node.id, code: p.b_code, name: p.name, unit: p.unit, unit_price: p[up_field], pid: '',
                     jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty,
                     im_code: getNewImCode(),
                     bw: bw,
@@ -1170,6 +1173,25 @@ const stageIm = (function () {
             }
         }
     }
+    function getRelaImData4Rela(relaXmj, bills, pos) {
+        if (stage.im_type === imType.tz.value) {
+            return _.find(ImData, {lid: relaXmj.id});
+        } else if (stage.im_type === imType.zl.value) {
+            return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.org_unit_price});
+        } else if (stage.im_type === imType.bw.value) {
+            if (pos) {
+                return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.org_unit_price, pid: pos.id});
+            } else {
+                return _.find(ImData, {lid: relaXmj.id, code: bills.b_code, name: bills.name, unit: bills.unit, unit_price: bills.org_unit_price, pid: ''});
+            }
+        } else if (stage.im_type === imType.bb.value) {
+            if (pos) {
+                return _.find(ImData, {lid: relaXmj.id, pos_name: pos.name});
+            } else {
+                return _.find(ImData, {lid: relaXmj.id, pos_name: ''});
+            }
+        }
+    }
 
     return {
         init,
@@ -1191,6 +1213,7 @@ const stageIm = (function () {
         getFirstUsed: getFirstUsed,
         getRelaXmj: getRelaXmj,
         getRelaImData: getRelaImData,
+        getRelaImData4Rela: getRelaImData4Rela,
         resetFields,
     }
 })();