Sfoglia il codice sorgente

计量台账,公式

MaiXinRong 5 anni fa
parent
commit
b02fcc4fc2

+ 2 - 2
app/controller/stage_controller.js

@@ -234,7 +234,7 @@ module.exports = app => {
                 preStageData = [];
             }
             this.ctx.helper.assignRelaData(ledgerData, [
-                {data: curStageData, fields: ['contract_qty', '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: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid',}
             ]);
             return ledgerData;
@@ -269,7 +269,7 @@ module.exports = app => {
             //console.log('cur: ' + curStageData.length);
             //console.log('pre: ' + preStageData.length);
             this.ctx.helper.assignRelaData(posData, [
-                {data: curStageData, fields: ['contract_qty', 'qc_qty', 'postil'], prefix: '', relaId: 'pid'},
+                {data: curStageData, fields: ['contract_qty', 'contract_expr', 'qc_qty', 'postil'], prefix: '', relaId: 'pid'},
                 {data: preStageData, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
             ]);
             return posData;

+ 65 - 12
app/public/js/stage.js

@@ -15,6 +15,15 @@ function checkTzMeasureType () {
 function transExpr(expr) {
     return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
 }
+function getExprInfo (field) {
+    const exprField = [
+        {qty: 'sgfh_qty', expr: 'sgfh_expr'},
+        {qty: 'sjcl_qty', expr: 'sjcl_expr'},
+        {qty: 'qtcl_qty', expr: 'qtcl_expr'},
+        {qty: 'contract_qty', expr: 'contract_expr'},
+    ];
+    return _.find(exprField, {qty: field});
+}
 
 /**
  * 从cookie中读取缓存的列显示设置,没有则取默认
@@ -136,7 +145,7 @@ $(document).ready(() => {
         stageId: 'id',
     };
     // 台账树结构计算相关设置
-    stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used'];
+    stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
     stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
         'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
     stageTreeSetting.calcFun = function (node) {
@@ -160,7 +169,7 @@ $(document).ready(() => {
     // 初始化 计量单元 数据结构
     const stagePosSetting = {
         id: 'id', ledgerId: 'lid',
-        updateFields: ['contract_qty', 'qc_qty', 'postil'],
+        updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
     };
     stagePosSetting.calcFun = function (pos) {
         pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
@@ -536,7 +545,9 @@ $(document).ready(() => {
                 if (nodePos && nodePos.length > 0) {
                     $('#bills-expr').val('').attr('readOnly', true);
                 } else {
-                    $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
+                    const exprInfo = getExprInfo(col.field);
+                    const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
+                    $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
                     if (col.field.indexOf('tp') >= 0) {
                         $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
                     } else {
@@ -618,6 +629,10 @@ $(document).ready(() => {
                         lid: node.id
                     };
                     updateData.stage[col.field] = newValue;
+                    const exprInfo = getExprInfo(col.field);
+                    if (exprInfo) {
+                        updateData.stage[exprInfo.expr] = trimInvalidChar(info.editingText);
+                    }
                 }
 
                 postData(window.location.href + '/update', {bills: updateData}, function (data) {
@@ -687,6 +702,10 @@ $(document).ready(() => {
                                 filterMain = false;
                             } else {
                                 data[colSetting.field] = null;
+                                const exprInfo = getExprInfo(colSetting.field);
+                                if (exprInfo) {
+                                    data[exprInfo.expr] = '';
+                                }
                                 filter = false;
                             }
                         }
@@ -708,6 +727,7 @@ $(document).ready(() => {
                         } else {
                             stageIm.loadUpdateLedgerData(result);
                         }
+                        stageTreeSpreadObj.loadExprToInput(sheet);
                     });
                 }
             }
@@ -786,6 +806,10 @@ $(document).ready(() => {
                                 } else {
                                     try {
                                         data[col.field] = math.evaluate(transExpr(text));
+                                        const exprInfo = getExprInfo(col.field);
+                                        if (exprInfo) {
+                                            data[exprInfo.expr] = text;
+                                        }
                                         filter = false;
                                     } catch(err) {
                                         if (!bHint) {
@@ -820,6 +844,7 @@ $(document).ready(() => {
                         } else {
                             stageIm.loadUpdateLedgerData(data);
                         }
+                        stageTreeSpreadObj.loadExprToInput(sheet);
                     }, function () {
                         // todo
                         //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
@@ -990,12 +1015,15 @@ $(document).ready(() => {
                     lid: select.id
                 };
                 updateData.stage[field] = newValue;
+                const exprInfo = getExprInfo(field);
+                if (exprInfo) {
+                    updateData.stage[exprInfo.expr] = expr.val();
+                }
             }
 
             // 更新至服务器
             postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
                 const nodes = stageTree.loadPostStageData(result);
-                expr.val(select[field]);
                 stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
             });
         });
@@ -1011,7 +1039,9 @@ $(document).ready(() => {
             if (col && col.type === 'Number') {
                 const data = SpreadJsObj.getSelectObject(sheet);
                 if (data) {
-                    $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
+                    const exprInfo = getExprInfo(col.field);
+                    const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
+                    $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
                         .attr('row', sel.row).attr('readOnly', readOnly || cell.locked());
                 } else {
                     $('#pos-expr').val('').attr('readOnly', true);
@@ -1108,6 +1138,10 @@ $(document).ready(() => {
                         } else {
                             try {
                                 data.updateData[col.field] = math.evaluate(transExpr(newText));
+                                const exprInfo = getExprInfo(col.field);
+                                if (exprInfo) {
+                                    data.updateData[exprInfo.expr] = newText;
+                                }
                             } catch(err) {
                                 toastr.error('输入的表达式非法');
                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -1199,14 +1233,18 @@ $(document).ready(() => {
                             const colSetting = info.sheet.zh_setting.cols[curCol];
                             if (!colSetting) continue;
 
-                            newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
+                            const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
                             if (colSetting.type === 'Number') {
-                                const num = _.toNumber(newData[colSetting.field]);
+                                const num = _.toNumber(newValue);
                                 if (num) {
                                     newData[colSetting.field] = num;
                                 } else {
                                     try {
-                                        newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
+                                        newData[colSetting.field] = math.evaluate(transExpr(newValue));
+                                        const exprInfo = getExprInfo(colSetting.field);
+                                        if (exprInfo) {
+                                            newData[exprInfo.expr] = newValue;
+                                        }
                                     } catch(err) {
                                         toastr.error('输入的表达式非法');
                                         stagePosSpreadObj.loadCurPosData();
@@ -1214,6 +1252,8 @@ $(document).ready(() => {
 
                                     }
                                 }
+                            } else {
+                                newData[colSetting.field] = newValue;
                             }
                         }
                         data.updateData.push(newData);
@@ -1228,20 +1268,26 @@ $(document).ready(() => {
                             for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                                 const curCol = info.cellRange.col + iCol;
                                 const colSetting = info.sheet.zh_setting.cols[curCol];
-                                newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
+                                const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
                                 if (colSetting.type === 'Number') {
-                                    const num = _.toNumber(newData[colSetting.field]);
+                                    const num = _.toNumber(newValue);
                                     if (num) {
                                         newData[colSetting.field] = num;
                                     } else {
                                         try {
-                                            newData[colSetting.field] = math.evaluate(transExpr(newData[colSetting.field]));
+                                            newData[colSetting.field] = math.evaluate(transExpr(newValue));
+                                            const exprInfo = getExprInfo(colSetting.field);
+                                            if (exprInfo) {
+                                                newData[exprInfo.expr] = newValue;
+                                            }
                                         } catch(err) {
                                             toastr.error('输入的表达式非法');
                                             stagePosSpreadObj.loadCurPosData();
                                             return;
                                         }
                                     }
+                                } else {
+                                    newData[colSetting.field] = newValue;
                                 }
                             }
                             data.updateData.push(newData);
@@ -1293,6 +1339,10 @@ $(document).ready(() => {
                                 return;
                             }
                             data[colSetting.field] = null;
+                            const exprInfo = getExprInfo(colSetting.field);
+                            if (exprInfo) {
+                                data[exprInfo.expr] = '';
+                            }
                         }
                         datas.push(data);
                         posSelects.push(node);
@@ -1419,6 +1469,10 @@ $(document).ready(() => {
             } else {
                 try {
                     data[field] = math.evaluate(transExpr(newValue));
+                    const exprInfo = getExprInfo(field);
+                    if (exprInfo) {
+                        data[exprInfo.expr] = newValue;
+                    }
                 } catch (err) {
                     toastr.error('输入的表达式非法');
                     return;
@@ -1430,7 +1484,6 @@ $(document).ready(() => {
                 if (result.pos) {
                     stagePos.updateDatas(result.pos.pos);
                     stagePos.loadCurStageData(result.pos.curStageData);
-                    expr.val(select[field]);
                     SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
                 }
                 const refreshData = stageTree.loadPostStageData(result.ledger);

+ 2 - 0
app/service/stage_bills.js

@@ -218,6 +218,7 @@ module.exports = app => {
                 d.contract_qty = this.round(insertData.contract_qty, precision.value);
                 d.contract_tp = this.ctx.helper.mul(d.contract_qty, ledgerData.unit_price, info.decimal.tp);
             }
+            if (insertData.contract_expr !== undefined) d.contract_expr = insertData.contract_expr;
             if (insertData.qc_qty !== undefined) {
                 d.qc_qty = this.round(insertData.qc_qty, precision.value);
                 d.qc_tp = this.ctx.helper.mul(d.qc_qty, ledgerData.unit_price, info.decimal.tp);
@@ -247,6 +248,7 @@ module.exports = app => {
                         await this._insertStageBillsData(transaction, d, stageBills, ledgerBills);
                     } else {
                         d.id = stageBills.id;
+                        console.log(d);
                         this._calcStageBillsData(d, stageBills, ledgerBills);
                         await transaction.update(this.tableName, d);
                     }

+ 13 - 4
app/service/stage_pos.js

@@ -54,7 +54,7 @@ module.exports = app => {
          */
         async getLastestStageData(tid, sid, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT Pos.id, Pos.tid, Pos.sid, Pos.lid, Pos.pid, Pos.contract_qty, Pos.qc_qty, Pos.postil, Pos.times, Pos.order FROM ' +
+            const sql = 'SELECT Pos.id, Pos.tid, Pos.sid, Pos.lid, Pos.pid, Pos.contract_qty, Pos.qc_qty, Pos.postil, Pos.times, Pos.order, Pos.contract_expr FROM ' +
                 '  (SELECT * FROM ' + this.tableName + ' WHERE tid = ? And sid = ?) As Pos ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `tid`, `sid`, `pid` From ' + this.tableName +
@@ -76,7 +76,7 @@ module.exports = app => {
          */
         async getAuditorStageData(tid, sid, times, order, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT Pos.id, Pos.tid, Pos.sid, Pos.pid, Pos.lid, Pos.contract_qty, Pos.qc_qty, Pos.postil, Pos.times, Pos.order FROM ' +
+            const sql = 'SELECT Pos.id, Pos.tid, Pos.sid, Pos.pid, Pos.lid, Pos.contract_qty, Pos.qc_qty, Pos.postil, Pos.times, Pos.order, Pos.contract_expr FROM ' +
                 '  (SELECT * FROM '+ this.tableName + ' WHERE tid = ? And sid = ?) As Pos ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `pid`, `sid` From ' + this.tableName +
@@ -107,7 +107,7 @@ module.exports = app => {
         }
         async getLastestStageData2(tid, sid, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`, `contract_expr`' +
                 '  FROM ' + this.tableName +
                 '  WHERE tid = ? And sid = ? ' + filterSql;
             const sqlParam = [tid, sid];
@@ -116,7 +116,7 @@ module.exports = app => {
         }
         async getAuditorStageData2(tid, sid, times, order, where) {
             const filterSql = this._getPosFilterSql(where);
-            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
+            const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`, `contract_expr`' +
                 '  FROM ' + this.tableName +
                 '  WHERE tid = ? And sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
             const sqlParam = [tid, sid, times, times, order];
@@ -171,6 +171,9 @@ module.exports = app => {
                     if (d.sgfh_qty!== undefined) p.sgfh_qty = this.round(d.sgfh_qty, precision.value);
                     if (d.sjcl_qty!== undefined) p.sjcl_qty = this.round(d.sjcl_qty, precision.value);
                     if (d.qtcl_qty!== undefined) p.qtcl_qty = this.round(d.qtcl_qty, precision.value);
+                    if (d.sgfh_expr) p.sgfh_expr = d.sgfh_expr;
+                    if (d.sjcl_expr) p.sjcl_expr = d.sjcl_expr;
+                    if (d.qtcl_expr) p.qtcl_expr = d.qtcl_expr;
                     p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
                     if (!updateBills) updateBills = {id: bills.id, sgfh_qty: bills.sgfh_qty, sjcl_qty: bills.sjcl_qty, qtcl_qty: bills.qtcl_qty};
                 }
@@ -188,6 +191,7 @@ module.exports = app => {
                         order: this.ctx.stage.curOrder,
                     };
                     if (d.contract_qty !== undefined) ps.contract_qty = this.round(d.contract_qty, precision.value);
+                    if (d.contract_expr) p.contract_expr = d.contract_expr;
                     if (d.qc_qty!== undefined) ps.qc_qty = this.round(d.qc_qty, precision.value);
                     if (d.postil!== undefined) ps.postil = d.postil;
                     insertPosStage.push(ps);
@@ -274,6 +278,9 @@ module.exports = app => {
                         p.sgfh_qty = d.sgfh_qty !== undefined ? d.sgfh_qty : op.sgfh_qty;
                         p.sjcl_qty = d.sjcl_qty !== undefined ? d.sjcl_qty : op.sjcl_qty;
                         p.qtcl_qty = d.qtcl_qty !== undefined ? d.qtcl_qty : op.qtcl_qty;
+                        if (d.sgfh_expr) p.sgfh_expr = d.sgfh_expr;
+                        if (d.sjcl_expr) p.sjcl_expr = d.sjcl_expr;
+                        if (d.qtcl_expr) p.qtcl_expr = d.qtcl_expr;
                         p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
                         if (!updateBills) updateBills = {id: bills.id};
                     }
@@ -288,6 +295,7 @@ module.exports = app => {
                         if (d.contract_qty !== undefined) {
                             sp.contract_qty = this.ctx.helper.round(d.contract_qty, precision.value);
                         }
+                        if (d.contract_expr) sp.contract_expr = d.contract_expr;
                         if (d.qc_qty !== undefined) {
                             sp.qc_qty = this.ctx.helper.round(d.qc_qty, precision.value);
                         }
@@ -307,6 +315,7 @@ module.exports = app => {
                                 ? osp.contract_qty
                                 : this.ctx.helper.round(d.contract_qty, precision.value);
                         }
+                        if (d.contract_expr) sp.contract_expr = d.contract_expr;
                         if (d.qc_qty || osp) {
                             sp.qc_qty = d.qc_qty === undefined && osp
                                 ? osp.qc_qty

+ 6 - 0
sql/update.sql

@@ -42,4 +42,10 @@ ADD COLUMN `sgfh_expr`  varchar(255) CHARACTER SET ascii COLLATE ascii_general_c
 ADD COLUMN `sjcl_expr`  varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT '' COMMENT '设计错漏-公式' AFTER `sgfh_expr`,
 ADD COLUMN `qtcl_expr`  varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT '' COMMENT '其他错漏-公式' AFTER `sjcl_expr`;
 
+ALTER TABLE `zh_stage_bills`
+ADD COLUMN `contract_expr`  varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT '' COMMENT '合同计量-公式' AFTER `lid`;
+
+ALTER TABLE `zh_stage_pos`
+ADD COLUMN `contract_expr`  varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT '' COMMENT '合同计量-公式' AFTER `postil`;
+
 ALTER TABLE `zh_project_account` ADD `backdoor_password` VARCHAR(255) NULL DEFAULT NULL COMMENT '副密码' AFTER `password`;