浏览代码

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

laiguoran 4 年之前
父节点
当前提交
aa4ded0963

+ 3 - 0
app/controller/deal_bills_controller.js

@@ -133,6 +133,9 @@ module.exports = app => {
                     if (file === '签约清单导入格式.xls') {
                         fileName = this.app.baseDir + '/app/public/deal_bills/签约清单导入格式.xls';
                         ctx.body = await fs.readFileSync(fileName);
+                    } else if (file === '签约清单转换格式.xls') {
+                        fileName = this.app.baseDir + '/app/public/deal_bills/转换格式.xls';
+                        ctx.body = await fs.readFileSync(fileName);
                     } else if (file === '签约清单.xlsx') {
                         const create_time = Date.parse(new Date()) / 1000;
                         fileName = this.app.baseDir + '/app/public/deal_bills/downloads/' + ctx.tender.id + '-' + create_time + '.xlsx';

+ 31 - 0
app/lib/sum_load.js

@@ -84,6 +84,33 @@ class loadGclBaseTree {
 
     gather(source, parent) {}
     getUpdateData() {}
+
+    recursiveCalculate(dealBills, node) {
+        if (node.children && node.children.length > 0) {
+            for (const child of node.children) {
+                this.recursiveCalculate(dealBills, child);
+            }
+        } else {
+            const p = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, node.unit);
+            node.sgfh_qty = this.ctx.helper.round(node.sgfh_qty, p.value);
+            node.sjcl_qty = this.ctx.helper.round(node.sjcl_qty, p.value);
+            node.qtcl_qty = this.ctx.helper.round(node.qtcl_qty, p.value);
+            node.quantity = this.ctx.helper.round(node.quantity, p.value);
+
+            if (!node.unit_price) {
+                const db = dealBills.find(x => { return x.b_code === node.b_code && x.name === node.name && x.unit === node.unit });
+                if (!db) return;
+                node.unit_price = db.unit_price;
+            }
+            node.sgfh_tp = this.ctx.helper.mul(node.sgfh_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
+            node.sjcl_tp = this.ctx.helper.mul(node.sjcl_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
+            node.qtcl_tp = this.ctx.helper.mul(node.qtcl_qty, node.unit_price, this.ctx.tender.info.decimal.tp);
+            node.total_price = this.ctx.helper.mul(node.quantity, node.unit_price, this.ctx.tender.info.decimal.tp);
+        }
+    }
+    calculateAll(dealBills) {
+        this.recursiveCalculate(dealBills, this.parent);
+    }
 }
 
 class loadLedgerGclTree extends loadGclBaseTree {
@@ -318,6 +345,8 @@ class sumLoad {
                 this.recusiveLoadGatherGcl(top, null);
             }
         }
+        const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({ tid: this.ctx.tender.id });
+        this.loadTree.calculateAll(dealBills);
         return this.loadTree;
     }
 
@@ -345,6 +374,8 @@ class sumLoad {
                 this.recusiveLoadGatherGcl(top, null);
             }
         }
+        const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({ tid: this.ctx.tender.id });
+        this.loadTree.calculateAll(dealBills);
         return this.loadTree;
     }
 

二进制
app/public/deal_bills/转换格式.xls


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

@@ -3698,7 +3698,6 @@ function getNodeList(node) {
   })
 }
 
-
 // 生成所有附件列表
 function getAllList(currPageNum = 1) {
   // 每页最多几个附件

+ 138 - 0
app/public/js/shares/db2full_code.js

@@ -0,0 +1,138 @@
+'use strict';
+
+/**
+ * 需要 export_excel.js
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const dbFullCode = {
+    loadSheet: function (rows) {
+        this.dealBills = [];
+        let iCode = -1, iName = -1, iUnit = -1, iUp = -1, iQty = -1, iTp = -1, bCheckCol = false;
+        for (let iRow = 0; iRow < rows.length; iRow++) {
+            const row = rows[iRow];
+            if (!bCheckCol) {
+                for (let iCol = 0; iCol < row.length; iCol++) {
+                    let value = row[iCol];
+                    if (typeof value !== "string") { continue }
+                    value = _.trim(value);
+                    if (value === '子目号' || value === '清单编号') iCode = iCol;
+                    if (value.indexOf('名称') >= 0) iName = iCol;
+                    if (value.indexOf('单位') >= 0) iUnit = iCol;
+                    if (value.indexOf('单价') >= 0) iUp = iCol;
+                    if (value.indexOf('数量') >= 0) iQty = iCol;
+                    if (value.indexOf('金额') >= 0 || value.indexOf('合价') >= 0) iTp = iCol;
+                }
+                bCheckCol = (iCode >= 0 && iName >= 0 && iUnit >= 0 && iUp >= 0 && iQty >= 0 && iTp >= 0);
+                if (!bCheckCol) {
+                    iCode = -1;
+                    iName = -1;
+                    iUnit = -1;
+                    iUp = -1;
+                    iQty = -1;
+                    iTp = -1;
+                }
+            } else {
+                const code = cleanSymbols(_.trim(row[iCode]));
+                if (!code) continue;
+                this.dealBills.push({
+                    code: code,
+                    org_code: row[iCode],
+                    name: cleanSymbols(row[iName]),
+                    unit: cleanSymbols(row[iUnit]),
+                    unit_price: row[iUp],
+                    quantity: row[iQty],
+                    total_price: row[iTp],
+                });
+            }
+        }
+        if (!bCheckCol) {
+            throw '导入的Excel表头定义有误,请下载示例检查';
+        }
+    },
+    loadXlsx: function () {
+        const dbfile = $('#db-full-code-file')[0];
+        xlsxUtils.import(dbfile.files[0], () => {
+            try {
+                dbFullCode.loadSheet(xlsxUtils.getSheetByIndex(0, {header: 1}));
+                document.getElementById('db-full-code-change').disabled = false;
+            } catch (err) {
+                console.log(err);
+                if (err.stack) {
+                    toastr.error('该文件不支持转换,请选择其他文件');
+                } else {
+                    toastr.warning(err);
+                }
+            }
+        });
+    },
+    clear: function () {
+        const file = document.getElementById('db-full-code-file');
+        file.outerHTML = file.outerHTML;
+        document.getElementById('db-full-code-change').disabled = true;
+        $('#db-full-code-file').change(dbFullCode.loadXlsx);
+    },
+    change: function () {
+        const regChar = /^-[a-zA-Z]$/, regNum = /^-[0-9]{1,2}$/, regCode = /^[0-9]{3,4}((-[0-9]{1,2})|(-[a-zA-Z]))*$/;
+        let invalid = 0;
+        for (const [i, db] of this.dealBills.entries()) {
+            if (regCode.test(db.code)) {
+                db.tag = 0;
+                db.full_code = db.code;
+            } else if (regNum.test(db.code)) {
+                db.tag = 1;
+                for (let j = i-1; j >= 0; j--) {
+                    if (this.dealBills[j].tag !== db.tag) {
+                        db.full_code = this.dealBills[j].full_code + db.code;
+                    }
+                }
+            } else if (regChar.test(db.code)) {
+                db.tag = 2;
+                for (let j = i-1; j >= 0; j--) {
+                    if (this.dealBills[j].tag !== db.tag) {
+                        db.full_code = this.dealBills[j].full_code + db.code;
+                    }
+                }
+            } else {
+                db.tag = -1;
+                invalid += 1;
+            }
+        }
+        if (invalid > 0) toastr.warning(`存在${invalid}条清单编号非法,请仔细对照原编号检查`);
+    },
+    save() {
+        const setting = {
+            cols: [
+                {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'full_code', hAlign: 0, width: 100, formatter: '@'},
+                {title: '原编号', colSpan: '1', rowSpan: '1', field: 'org_code', hAlign: 0, width: 60, formatter: '@'},
+                {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
+                {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
+                {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
+                {title: '数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
+                {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
+            ],
+            headRows: 1,
+            headRowHeight: [32],
+            defaultRowHeight: 21,
+            headerFont: 'bold 10px 微软雅黑',
+            font: '10px 微软雅黑'
+        };
+        const orgFileName = $('#db-full-code-file')[0].files[0].name;
+        const pointIndex = orgFileName.lastIndexOf('.');
+        SpreadExcelObj.exportSimpleXlsxSheet(setting, this.dealBills, orgFileName.substring(0, pointIndex) + "-长编号.xlsx");
+    },
+    changeAndSave() {
+        dbFullCode.change();
+        dbFullCode.save();
+    }
+};
+
+$(document).ready(() => {
+    $('#db-full-code').on('show.bs.modal', () => {
+        dbFullCode.clear();
+    });
+    $('#db-full-code-change').click(dbFullCode.changeAndSave);
+});

+ 1 - 0
app/view/ledger/explode.ejs

@@ -144,6 +144,7 @@
                                 <% } else { %>
                                 <a href="javascript: void(0);" class="btn btn-sm btn-primary disabled">上传签约清单</a>
                                 <% } %>
+                                <a href="#db-full-code" data-toggle="modal" data-target="#db-full-code" class="btn btn-sm btn-primary">转换长编号</a>
                                 <a href="/tender/<%- ctx.tender.id %>/deal/download/签约清单.xlsx" class="btn btn-sm btn-primary" style="display: none">下载签约清单</a>
                             </div>
                         </div>

+ 1 - 0
app/view/ledger/explode_modal.ejs

@@ -427,3 +427,4 @@
 <% include ../shares/check_modal2.ejs %>
 <% include ../shares/new_tag_modal.ejs %>
 <% include ../shares/tender_select_modal.ejs %>
+<% include ../shares/db2full_code.ejs %>

+ 24 - 0
app/view/shares/db2full_code.ejs

@@ -0,0 +1,24 @@
+<!--转换长编号-->
+<div class="modal fade" id="db-full-code" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">转换长编号</h5>
+            </div>
+            <div class="modal-body">
+                <div class="form-group">
+                    <label for="exampleFormControlFile1">Excel模板</label>
+                    <div class="form-control form-control-plaintext"><a id="downloadDealTemplate" href="/tender/<%- ctx.tender.id %>/deal/download/签约清单转换格式.xls" class="btn btn-sm btn-link">下载示例</a></div>
+                </div>
+                <div class="form-group">
+                    <label for="exampleFormControlFile1">选择签约清单Excel文件</label>
+                    <input type="file" class="form-control-file" id="db-full-code-file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">关闭</button>
+                <button type="button" class="btn btn-primary btn-sm" id="db-full-code-change">转换</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 1 - 0
config/web.js

@@ -154,6 +154,7 @@ const JsFiles = {
                     '/public/js/ledger_check.js',
                     '/public/js/shares/tenders2tree.js',
                     '/public/js/shares/tender_select.js',
+                    '/public/js/shares/db2full_code.js',
                     '/public/js/ledger.js',
                 ],
                 mergeFile: 'explode',