浏览代码

中间计量,新模式

MaiXinRong 5 年之前
父节点
当前提交
616da74360
共有 7 个文件被更改,包括 284 次插入17 次删除
  1. 2 1
      app/const/tender.js
  2. 119 1
      app/lib/stage_im.js
  3. 37 3
      app/public/js/stage.js
  4. 109 5
      app/public/js/stage_im.js
  5. 10 3
      app/view/stage/index.ejs
  6. 3 3
      app/view/stage/modal.ejs
  7. 4 1
      sql/update.sql

+ 2 - 1
app/const/tender.js

@@ -70,7 +70,8 @@ const valuationField = function (mt) {
 const imType = {
     zl: { value: 0, name: '总量控制' },
     tz: { value: 1, name: '0号台账' },
-    bw: { value: 2, name: '计量单元' },
+    bw: { value: 2, name: '清单-计量单元' },
+    bb: { value: 3, name: '计量单元-清单' },
 };
 
 const typeString = [];

+ 119 - 1
app/lib/stage_im.js

@@ -230,6 +230,18 @@ class StageIm {
         }
         return result;
     }
+    _getBwBillsBw(node) {
+        if (node.level < 3) {
+            return '';
+        } else {
+            let parent = node, result = parent.name;
+            while (parent.level > 3 && parent) {
+                parent = this._getNodeByLevel(node, parent.level - 1);
+                result = parent.name + '-' + result;
+            }
+            return result;
+        }
+    }
 
     _checkCustomDetail(im) {
         const self = this;
@@ -422,6 +434,107 @@ class StageIm {
         }
     }
 
+    _getBwBillsIm(node, peg, index, bw) {
+        const im = {
+            lid: node.id, pid: '', code: node.code, name: node.name, pos_name: '',
+            peg: peg ? this._getPegStr(peg.name) : '',
+            drawing_code: this._getDrawingCode(node),
+            position: '',
+            lIndex: index,
+            bw: bw, jldy: node.name,
+            changes: [], gclBills: [],
+        };
+        this._checkCustomDetail(im);
+        return im;
+    }
+    _getBwBillsPosIm(imArr, node, peg, index, bw, posName) {
+        let im = imArr.find(function (d) {
+            return d.lid === node.id && d.pos_name === posName;
+        });
+        if (!im) {
+            im = {
+                lid: node.id, pid: '',
+                code: node.code + '-' + (imArr.length + 1), name: node.name, pos_name: posName,
+                peg: this._checkPeg(posName) ? posName : (peg ? this._getPegStr(peg.name) : ''),
+                drawing_code: [], position: [],
+                lIndex: index,
+                bw: bw, jldy: posName,
+                changes: [], gclBills: [],
+            };
+            imArr.push(im);
+            this._checkCustomDetail(im);
+        }
+        return im;
+    }
+    _generateBwBillsImData (node) {
+        if (!node.gather_tp && !node.contract_tp && !node.qc_tp) return;
+
+        const nodeIndex = gsTree.getNodeIndex(node);
+        const peg = this._getPegNode(node);
+        const nodeImData = [], posterity = gsTree.getPosterity(node);
+        const bw = this._getBwBillsBw(node);
+        const imDefault = this._getBwBillsIm(node, peg, nodeIndex, bw);
+        for (const p of posterity) {
+            if (p.children && p.children.length > 0) continue;
+            if (!p.b_code || p.b_code === '') continue;
+            if (!p.gather_tp || p.gather_tp === 0) continue;
+
+            const pPos = this.pos.getLedgerPos(p.id);
+            if (pPos && pPos.length > 0) {
+                for (const pp of pPos) {
+                    if (!pp.gather_qty || !pp.contract_qty || !pp.qc_qty) continue;
+
+                    const im = this._getBwBillsPosIm(nodeImData, node, peg, nodeIndex, bw, pp.name);
+
+                    for (const c of changes) {
+                        if (c.lid === p.id && c.pid == pp.id && c.qty && c.qty !== 0) {
+                            imDefault.changes.push(c);
+                        }
+                    }
+
+                    const jl = ZhCalc.mul(pp.gather_qty p.unit_price, decimal.tp);
+                    const contract_jl = ZhCalc.mul(pp.contract_qty, p.unit_price, decimal.tp);
+                    const qc_jl = ZhCalc.mul(pp.qc_qty, p.unit_price, decimal.tp);
+                    im.jl = ZhCalc.add(im.jl, jl);
+                    im.contract_jl = ZhCalc.add(im.contract_jl, contract_jl);
+                    im.qc_jl = ZhCalc.add(im.qc_jl, qc_jl);
+                    if (pp.drawing_code) im.drawing_code.push(pp.drawing_code);
+                    if (pp.position) im.position.push(pp.position);
+
+                    im.gclBills.push({
+                        bid: p.id,
+                        b_code: p.b_code, name: p.name, unit: p.unit,
+                        jl: jl, contract_jl: contract_jl, qc_jl: qc_jl
+                    });
+                }
+            } else {
+                for (const c of changes) {
+                    if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
+                        imDefault.changes.push(c);
+                    }
+                }
+
+                imDefault.jl = ZhCalc.add(imDefault.jl, p.gather_qty);
+                imDefault.contract_jl = ZhCalc.add(imDefault.contract_jl, p.contract_qty);
+                imDefault.qc_jl = ZhCalc.add(imDefault.qc_jl, p.qc_qty);
+
+                imDefault.gclBills.push({
+                    bid: p.id,
+                    b_code: p.b_code, name: p.name, unit: p.unit,
+                    jl: p.gather_tp, contract_jl: p.contract_tp, qc_jl: p.qc_tp
+                });
+            }
+        }
+        if (imDefault.jl) {
+            ImData.push(imDefault);
+        }
+        for (const im of nodeImData) {
+            im.drawing_code = im.drawing_code.join('');
+            im.position = im.position.join('');
+            ImData.push(im);
+        }
+    }
+
     _generateZlPosData(node, lx) {
         if (!lx.pos) {
             lx.pos = [];
@@ -658,15 +771,20 @@ class StageIm {
      * @param {Array} nodes
      */
     _recursiveBuildImData(nodes) {
+        const stage = this.ctx.stage;
         if (!nodes || nodes.length === 0) { return; }
         for (const node of nodes) {
-            if (this.billsTree.isLeafXmj(node) || (this.ctx.stage.im_type !== imType.bw.value && this.ctx.stage.im_gather && node.check)) {
+            if (this.billsTree.isLeafXmj(node) ||
+                ((stage.im_type !== imType.bw.value && stage.im_type !== imType.bb.value) && stage.im_gather && node.check)
+            ) {
                 if (this.ctx.stage.im_type === imType.tz.value) {
                     this._generateTzImData(node);
                 } else if (this.ctx.stage.im_type === imType.zl.value) {
                     this._generateZlImData(node);
                 } else if (this.ctx.stage.im_type === imType.bw.value) {
                     this._generateBwImData(node);
+                } else if (this.ctx.stage.im_type === imType.bb.value) {
+                    this._generateBwBillsImData(node);
                 }
             } else {
                 this._recursiveBuildImData(node.children);

+ 37 - 3
app/public/js/stage.js

@@ -1391,7 +1391,7 @@ $(document).ready(() => {
         stagePosSpreadObj.loadCurPosData();
         SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
         // 加载中间计量
-        stageIm.init(stage, imType);
+        stageIm.init(stage, imType, tenderInfo.decimal);
         stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
         errorList.loadHisErrorData();
     }, null, true);
@@ -1937,24 +1937,43 @@ $(document).ready(() => {
             };
             this.gsTree = stageIm.getGsTree();
 
-            if (stage.im_type === imType.tz.value) {
+            if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
+                const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
+                jlCol.title = '本期计量金额';
+                SpreadJsObj.reLoadSheetHeader(self.sheet);
                 $('#type-title-contract').text('本期合同计量金额');
                 $('#type-title-qc').text('本期变更计量金额');
             } else {
+                const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
+                jlCol.title = '本期计量数量';
+                SpreadJsObj.reLoadSheetHeader(self.sheet);
                 $('#type-title-contract').text('本期合同计量数量');
                 $('#type-title-qc').text('本期变更计量数量');
             }
+            if (stage.im_type === imType.bb.value) {
+                $('#show-jldy').parent().show();
+                $('#jldy').parent().show();
+                $('#show-xm-name').parent().hide();
+                $('#xm-name').parent().hide();
+            } else {
+                $('#show-jldy').parent().hide();
+                $('#jldy').parent().hide();
+                $('#show-xm-name').parent().show();
+                $('#xm-name').parent().show();
+            }
 
             // 选择中间计量模式
             $('div[name="im-type"]').click(function () {
                 function chooseType(obj) {
                     obj.style.cursor = 'default';
                     $(obj).children().addClass('text-primary');
+                    $(obj).addClass('border-primary');
                     $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
                 }
                 function validType(obj) {
                     obj.style.cursor = 'pointer';
                     $(obj).children().removeClass('text-primary');
+                    $(obj).removeClass('border-primary');
                     $('i', obj).remove();
                 }
                 if (this.style.cursor === 'pointer') {
@@ -2002,7 +2021,7 @@ $(document).ready(() => {
                 postData(window.location.pathname + '/detail/build', data, function (result) {
                     stage.im_type = data.im_type;
                     stage.im_pre = data.im_pre;
-                    if (stage.im_type === imType.tz.value) {
+                    if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
                         const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
                         jlCol.title = '本期计量金额';
                         SpreadJsObj.reLoadSheetHeader(self.sheet);
@@ -2015,6 +2034,17 @@ $(document).ready(() => {
                         $('#type-title-contract').text('本期合同计量数量');
                         $('#type-title-qc').text('本期变更计量数量');
                     }
+                    if (stage.im_type === imType.bb.value) {
+                        $('#show-jldy').parent().show();
+                        $('#jldy').parent().show();
+                        $('#show-xm-name').parent().hide();
+                        $('#xm-name').parent().hide();
+                    } else {
+                        $('#show-jldy').parent().hide();
+                        $('#jldy').parent().hide();
+                        $('#show-xm-name').parent().show();
+                        $('#xm-name').parent().show();
+                    }
                     // 加载生成数据
                     self.reBuildImData();
                     $('#choose').modal('hide');
@@ -2435,6 +2465,10 @@ $(document).ready(() => {
             $('#show-xm-name').text(xmName);
             $('#xm-name').val(xmName);
 
+            const jldy = data && data.jldy ? data.jldy: '';
+            $('#show-jldy').text(jldy);
+            $('#jldy').val(jldy);
+
             const drawingCode = data && data.drawing_code ? data.drawing_code: '';
             $('#show-drawing-code').text(drawingCode);
             $('#drawing-code').val(drawingCode);

+ 109 - 5
app/public/js/stage_im.js

@@ -12,7 +12,7 @@ const stageIm = (function () {
     const imFields = ['uuid', 'doc_code', 'peg', 'bw', 'xm', 'drawing_code', 'calc_memo', 'calc_img', 'position'];
     const splitChar = '-';
     const mergeChar = ';';
-    let stage, imType, details, changes, ImData, pre;
+    let stage, imType, decimal, details, changes, ImData, pre;
     const gsTreeSetting = {
         id: 'ledger_id',
         pid: 'ledger_pid',
@@ -52,9 +52,10 @@ const stageIm = (function () {
     };
     const gsPos = new StagePosData(gsPosSetting);
 
-    function init (s, i) {
+    function init (s, i, d) {
         stage = s;
         imType = i;
+        decimal = d;
     }
 
     function initCheck () {
@@ -62,7 +63,6 @@ const stageIm = (function () {
         for (const node of gsTree.datas) {
             node.check = gatherNodes.indexOf(node.id) !== -1;
         }
-
     }
 
     function loadData (ledger, pos, stageDetail, stageChange) {
@@ -241,6 +241,19 @@ const stageIm = (function () {
         }
     }
 
+    function getBwBillsBw(node) {
+        if (node.level < 3) {
+            return '';
+        } else {
+            let parent = node, result = parent.name;
+            while (parent.level > 3 && parent) {
+                parent = getNodeByLevel(node, parent.level - 1);
+                result = parent.name + '-' + result;
+            }
+            return result;
+        }
+    }
+
     function checkCustomDetail(im) {
         const cd = _.find(details, function (d) {
             return im.lid === d.lid &&
@@ -248,7 +261,8 @@ const stageIm = (function () {
                 (!im.name || im.name === d.name) &&
                 (!im.unit || im.unit === d.unit) &&
                 checkZero(ZhCalc.sub(im.unit_price, d.unit_price)) &&
-                (!im.pid || im.pid === d.pid);
+                (!im.pid || im.pid === d.pid) &&
+                (!im.pos_name || im.pos_name === d.pos_name);
         });
         if (cd) {
             _.assignInWith(im, cd, function (oV, sV, key) {
@@ -431,6 +445,94 @@ const stageIm = (function () {
         }
     }
 
+    function generateBwBillsImData (node) {
+        if (node.gather_tp) {
+            const nodeIndex = gsTree.getNodeIndex(node);
+            const peg = getPegNode(node);
+            const nodeImData = [], posterity = gsTree.getPosterity(node);
+            const bw = getBwBillsBw(node);
+            const imDefault = {
+                lid: node.id, pid: '', code: node.code, name: node.name, pos_name: '',
+                peg: peg ? getPegStr(peg.name) : '',
+                drawing_code: getDrawingCode(node),
+                position: '',
+                lIndex: nodeIndex,
+                bw: bw, jldy: node.name,
+                changes: [], gclBills: [],
+            };
+            checkCustomDetail(imDefault);
+            for (const p of posterity) {
+                if (p.children && p.children.length > 0) continue;
+                if (!p.b_code || p.b_code === '') continue;
+                if (!p.gather_tp || p.gather_tp === 0) continue;
+                const pPos = gsPos.getLedgerPos(p.id);
+                if (pPos && pPos.length > 0) {
+                    for (const pp of pPos) {
+                        if (!pp.gather_qty || !pp.contract_qty || !pp.qc_qty) continue;
+                        let im = nodeImData.find(function (d) {
+                            return d.lid === node.id && d.pos_name === pp.name;
+                        });
+                        if (!im) {
+                            im = {
+                                lid: node.id, pid: '',
+                                code: node.code + '-' + (nodeImData.length + 1), name: node.name, pos_name: pp.name,
+                                peg: CheckPeg(pp.name) ? pp.name : (peg ? getPegStr(peg.name) : ''),
+                                drawing_code: [], position: [],
+                                lIndex: nodeIndex,
+                                bw: bw, jldy: pp.name,
+                                changes: [], gclBills: [],
+                            };
+                            nodeImData.push(im);
+                            checkCustomDetail(im);
+                        }
+
+                        for (const c of changes) {
+                            if (c.lid === p.id && c.pid == pp.id && c.qty && c.qty !== 0) {
+                                imDefault.changes.push(c);
+                            }
+                        }
+
+                        im.jl = ZhCalc.add(im.jl, ZhCalc.mul(pp.gather_qty, p.unit_price, decimal.tp));
+                        im.contract_jl = ZhCalc.add(im.contract_jl, ZhCalc.mul(pp.contract_qty, p.unit_price, decimal.tp));
+                        im.qc_jl = ZhCalc.add(im.qc_jl, ZhCalc.mul(pp.qc_qty, p.unit_price, decimal.tp));
+                        if (pp.drawing_code) im.drawing_code.push(pp.drawing_code);
+                        if (pp.position) im.position.push(pp.position);
+
+                        im.gclBills.push({
+                            bid: p.id,
+                            b_code: p.b_code, name: p.name, unit: p.unit,
+                            jl: pp.gather_qty, contract_jl: pp.contract_qty, qc_jl: pp.qc_qty
+                        })
+                    }
+                } else {
+                    for (const c of changes) {
+                        if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
+                            imDefault.changes.push(c);
+                        }
+                    }
+
+                    imDefault.jl = ZhCalc.add(imDefault.jl, p.gather_qty);
+                    imDefault.contract_jl = ZhCalc.add(imDefault.contract_jl, p.contract_qty);
+                    imDefault.qc_jl = ZhCalc.add(imDefault.qc_jl, p.qc_qty);
+
+                    imDefault.gclBills.push({
+                        bid: p.id,
+                        b_code: p.b_code, name: p.name, unit: p.unit,
+                        jl: p.gather_qty, contract_jl: p.contract_qty, qc_jl: p.qc_qty
+                    });
+                }
+            }
+            if (imDefault.jl) {
+                ImData.push(imDefault);
+            }
+            for (const im of nodeImData) {
+                im.drawing_code = im.drawing_code.join('');
+                im.position = im.position.join('');
+                ImData.push(im);
+            }
+        }
+    }
+
     function generateZlPosData(node, lx) {
         if (!lx.pos) {
             lx.pos = [];
@@ -614,13 +716,15 @@ const stageIm = (function () {
     function recursiveBuildImData (nodes) {
         if (!nodes || nodes.length === 0) { return; }
         for (const node of nodes) {
-            if (gsTree.isLeafXmj(node) || (stage.im_type !== imType.bw.value && stage.im_gather && node.check)) {
+            if (gsTree.isLeafXmj(node) || ((stage.im_type !== imType.bw.value && stage.im_type !== imType.bb.value) && stage.im_gather && node.check)) {
                 if (stage.im_type === imType.tz.value) {
                     generateTzImData(node);
                 } else if (stage.im_type === imType.zl.value) {
                     generateZlImData(node);
                 } else if (stage.im_type === imType.bw.value) {
                     generateBwImData(node);
+                } else if (stage.im_type === imType.bb.value) {
+                    generateBwBillsImData(node);
                 }
             } else {
                 recursiveBuildImData(node.children);

+ 10 - 3
app/view/stage/index.ejs

@@ -131,6 +131,7 @@
                                 <tr><th>起止桩号</th><td id="show-peg"></td></tr>
                                 <tr><th>细目</th><td id="show-xm-name"></td></tr>
                                 <tr><th>位置</th><td id="show-position"></td></tr>
+                                <tr><th>计量单元</th><td id="show-jldy"></td></tr>
                                 <tr><th>图册号</th><td id="show-drawing-code"></td></tr>
                                 <tr><th colspan="2">计算式说明</th></tr>
                                 <tr><td colspan="2" id="show-calc-memo" style="word-wrap:break-word"></td></tr>
@@ -166,7 +167,7 @@
                                 </div>
                                 <div class="input-group input-group-sm mb-2">
                                     <div class="input-group-prepend">
-                                        <span class="input-group-text"style="width: 66px">部位</span>
+                                        <span class="input-group-text" style="width: 66px">部位</span>
                                     </div>
                                     <input type="text" class="form-control" value="" id="bw-name">
                                 </div>
@@ -178,18 +179,24 @@
                                 </div>
                                 <div class="input-group input-group-sm mb-2">
                                     <div class="input-group-prepend">
-                                        <span class="input-group-text"style="width: 66px">细目</span>
+                                        <span class="input-group-text" style="width: 66px">细目</span>
                                     </div>
                                     <input type="text" class="form-control" value="" id="xm-name">
                                 </div>
                                 <div class="input-group input-group-sm mb-2">
                                     <div class="input-group-prepend">
-                                        <span class="input-group-text"style="width: 66px">位置</span>
+                                        <span class="input-group-text" style="width: 66px">位置</span>
                                     </div>
                                     <input type="text" class="form-control" value="" id="position">
                                 </div>
                                 <div class="input-group input-group-sm mb-2">
                                     <div class="input-group-prepend">
+                                        <span class="input-group-text" style="width: 66px">计量单元</span>
+                                    </div>
+                                    <input type="text" class="form-control" value="" id="jldy">
+                                </div>
+                                <div class="input-group input-group-sm mb-2">
+                                    <div class="input-group-prepend">
                                         <span class="input-group-text" style="width: 66px">图册号</span>
                                     </div>
                                     <input type="text" class="form-control" value="" id="drawing-code">

+ 3 - 3
app/view/stage/modal.ejs

@@ -250,9 +250,9 @@
                     <label>中间计量模式 <a href="/public/images/example/jiliangmoshi.png" target="_blank" data-toggle="tooltip" data-placement="bottom" data-original-title="点击查看相关报表"><i class="fa fa-question-circle-o"></i></a></label>
                     <div class="row" id="im-type">
                         <% for (const i in imType) { %>
-                        <div class="col-4">
-                            <div class="card border-primary" name="im-type" im-type="<%- imType[i].value %>" <% if (ctx.stage.im_type !== imType[i].value) { %>style="cursor:pointer;"<% } %>>
-                                <div class="card-body<% if (ctx.stage.im_type === imType[i].value) { %> text-primary<% } %>">
+                        <div class="col-6 mt-3 p-0">
+                            <div class="card mx-3 <% if (ctx.stage.im_type === imType[i].value) { %> border-primary<% } %>" name="im-type" im-type="<%- imType[i].value %>" <% if (ctx.stage.im_type !== imType[i].value) { %>style="cursor:pointer;"<% } %>>
+                                <div class="card-body p-2 <% if (ctx.stage.im_type === imType[i].value) { %> text-primary<% } %>">
                                     <h5 class="card-title mb-0" im-type="<%- imType[i].value %>">
                                         <% if (ctx.stage.im_type === imType[i].value) { %><i class="fa fa-check pull-right"></i><% } %>
                                         <%- imType[i].name %>

+ 4 - 1
sql/update.sql

@@ -2,4 +2,7 @@ UPDATE `zh_stage_pay` sp
   LEFT JOIN `zh_stage` s ON sp.sid = s.id
   LEFT JOIN `zh_pay` p ON sp.pid = p.id
   SET sp.`pre_used` = 1
-  WHERE (sp.`start_stage_order` < s.`order` OR ((not IsNULL(sp.pre_tp)) AND sp.pre_tp) AND sp.`pre_used` = 0 AND p.`ptype` = 1;
+  WHERE (sp.`start_stage_order` < s.`order` OR ((not IsNULL(sp.pre_tp)) AND sp.pre_tp) AND sp.`pre_used` = 0 AND p.`ptype` = 1;
+
+ALTER TABLE `zh_stage_detail`
+ADD COLUMN `pos_name`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '计量单元名称' AFTER `position`;