浏览代码

小数位设置

laiguoran 3 年之前
父节点
当前提交
efa907efd9

+ 40 - 5
app/controller/material_controller.js

@@ -358,8 +358,8 @@ module.exports = app => {
 
                 // 取当前期截止上期含税金额
                 renderData.material.m_tax_tp = renderData.material.m_tax_tp ? renderData.material.m_tax_tp : renderData.material.m_tp;
-                renderData.pre_tp_hs = await ctx.service.material.getPreTpHs(ctx.tender.id, ctx.material.order);
-                renderData.ex_pre_tp_hs = await ctx.service.material.getExPreTpHs(ctx.tender.id, ctx.material.order);
+                renderData.pre_tp_hs = await ctx.service.material.getPreTpHs(ctx.tender.id, ctx.material.order, ctx.material.decimal.tp);
+                renderData.ex_pre_tp_hs = await ctx.service.material.getExPreTpHs(ctx.tender.id, ctx.material.order, ctx.material.decimal.tp);
                 // renderData.tax_pre_tp_hs = await ctx.service.material.getTaxPreTpHs(ctx.tender.id, ctx.material.order);
 
                 renderData.months = ctx.material.months ? ctx.material.months.split(',') : [];
@@ -502,8 +502,8 @@ module.exports = app => {
                 }
 
                 // 取当前期截止上期含税金额
-                renderData.pre_tp_hs = await ctx.service.material.getPreTpHs(ctx.tender.id, ctx.material.order);
-                renderData.ex_pre_tp_hs = await ctx.service.material.getExPreTpHs(ctx.tender.id, ctx.material.order);
+                renderData.pre_tp_hs = await ctx.service.material.getPreTpHs(ctx.tender.id, ctx.material.order, ctx.material.decimal.tp);
+                renderData.ex_pre_tp_hs = await ctx.service.material.getExPreTpHs(ctx.tender.id, ctx.material.order, ctx.material.decimal.tp);
                 renderData.materialType = materialConst;
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.material.exponent);
                 // 判断之前期有无调用过材料税
@@ -542,6 +542,41 @@ module.exports = app => {
         }
 
         /**
+         *  调差操作 (form)
+         * @param ctx
+         * @return {Promise<void>}
+         */
+        async saveDecimal(ctx) {
+            try {
+                const data = ctx.request.body;
+                if (ctx.material.status !== auditConst.status.uncheck && ctx.material.status !== auditConst.status.checkNo) {
+                    throw '当前调差期无法调整小数位数';
+                }
+                const newDecimalUp = parseInt(data.up);
+                const newDecimalTp = parseInt(data.tp);
+                if (newDecimalUp > 6 || newDecimalUp < 0) {
+                    throw '单价小数位数设置不能大于6或小于0';
+                }
+                if (newDecimalTp > 6 || newDecimalTp < 0) {
+                    throw '金额小数位数设置不能大于6或小于0';
+                }
+                if (ctx.material.decimal.up === newDecimalUp && ctx.material.decimal.tp === newDecimalTp) {
+                    throw '小数位数设置未发生变化';
+                }
+                const result = await ctx.service.material.saveDecimal(newDecimalUp, newDecimalTp);
+                if (!result) {
+                    throw '小数位数设置失败';
+                }
+                this.setMessage('设置小数位数成功', this.messageType.SUCCESS);
+            } catch (err) {
+                console.log(err);
+                this.log(err);
+                this.setMessage(err.toString(), this.messageType.ERROR);
+            }
+            ctx.redirect(ctx.request.header.referer);
+        }
+
+        /**
          * 调差清单 - 工料操作 (Ajax)
          * @param ctx
          * @return {Promise<void>}
@@ -672,7 +707,7 @@ module.exports = app => {
                         // 更新quantity值并重新返回计算本期金额,截止本期金额
                         const updateData = {
                             id: data.id,
-                            quantity: quantity !== 0 ? this.ctx.helper.round(quantity, 3) : null,
+                            quantity: quantity !== 0 ? ctx.helper.round(quantity, ctx.material.decimal.qty) : null,
                             expr: data.expr,
                         };
                         responseData.data = await ctx.service.materialBills.updateFYQuantity(updateData);

+ 37 - 45
app/public/js/material.js

@@ -72,15 +72,15 @@ DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle,
 };
 
 function resetTpTable() {
-    $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, 2));
-    $('#tp_set').find('td').eq(2).text(ZhCalc.round(ZhCalc.add(pre_tp, m_tp), 2));
+    $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, materialDecimal.tp));
+    $('#tp_set').find('td').eq(2).text(ZhCalc.round(ZhCalc.add(pre_tp, m_tp), materialDecimal.tp));
     if (materialTax) {
-        $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, 2));
-        $('#tax_rate_set').find('td').eq(2).text(ZhCalc.round(ZhCalc.add(m_tax_pre_tp, m_tax_tp), 2));
+        $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, materialDecimal.tp));
+        $('#tax_rate_set').find('td').eq(2).text(ZhCalc.round(ZhCalc.add(m_tax_pre_tp, m_tax_tp), materialDecimal.tp));
     } else {
         const rate = $('#changeRate').val();
-        const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), 2);
-        const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), 2);
+        const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
+        const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
         $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
         $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
     }
@@ -129,7 +129,7 @@ $(document).ready(() => {
         {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
         {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
         {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
-        {title: '|价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
+        {title: '|价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
     );
     if (materialTax) {
         materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
@@ -209,19 +209,19 @@ $(document).ready(() => {
     const materialCol = {
         getValue: {
             msg_spread: function (data) {
-                return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), 3);
+                return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
             },
             m_spread : function (data) {
                 const msg_spread = materialCol.getValue.msg_spread(data);
                 const cor = msg_spread >= 0 ? ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_up_risk, 100)) : ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_down_risk, 100));
-                return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), 3) : ZhCalc.round(ZhCalc.add(msg_spread, cor), 3)) : 0;
+                return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), materialDecimal.up) : ZhCalc.round(ZhCalc.add(msg_spread, cor), materialDecimal.up)) : 0;
             },
             m_tp: function (data) {
-                return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), 2);
+                return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
             },
             m_tax_tp: function (data) {
-                const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), 2);
-                return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), 2) : m_tp;
+                const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
+                return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
             }
         },
         readOnly: {
@@ -401,12 +401,10 @@ $(document).ready(() => {
                         return;
                     }
                     let num = parseFloat(validText);
-                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
-                        toastr.warning('已保留3位小数');
-                        validText = ZhCalc.round(num, 3);
-                        // toastr.error('请输入大于0并且小于3位小数的浮点数');
-                        // SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                        // return;
+                    const reg = new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$");
+                    if (validText !== null && (num < 0 || !reg.test(num))) {
+                        toastr.warning('已保留'+ materialDecimal.up +'位小数');
+                        validText = ZhCalc.round(num, materialDecimal.up);
                     }
                 }
                 if (col.field === 'msg_tp') {
@@ -416,12 +414,10 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
-                        toastr.warning('已保留3位小数');
-                        validText = ZhCalc.round(num, 3);
-                        // toastr.error('请输入大于0并且小于3位小数的浮点数');
-                        // SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                        // return;
+                    const reg = new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$");
+                    if (validText !== null && (num < 0 || !reg.test(num))) {
+                        toastr.warning('已保留'+ materialDecimal.up +'位小数');
+                        validText = ZhCalc.round(num, materialDecimal.up);
                     }
                 }
                 if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
@@ -512,7 +508,7 @@ $(document).ready(() => {
                 codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
                 riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
-                numberCan: {type: 'warning', msg: '已保留3位小数'},
+                numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
             };
             const range = info.cellRange;
             const sortData = info.sheet.zh_data || [];
@@ -581,11 +577,10 @@ $(document).ready(() => {
                         }
                         const num = parseFloat(validText);
                         if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
-                            if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
+                            const reg = new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$");
+                            if (validText !== null && (num < 0 || !reg.test(num))) {
                                 toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
-                                validText = ZhCalc.round(num, 3);
-                                // bPaste = false;
-                                // continue;
+                                validText = ZhCalc.round(num, materialDecimal.up);
                             }
                         } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
                             if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
@@ -766,7 +761,7 @@ $(document).ready(() => {
                         hadnum++;
                     }
                 }
-                const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), 3) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), 3);
+                const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
                 return average_tp;
             },
         },
@@ -812,12 +807,10 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
-                        // toastr.error('请输入大于0并且小于3位小数的浮点数');
-                        // SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                        // return;
-                        toastr.warning('已保留3位小数');
-                        validText = ZhCalc.round(num, 3);
+                    const reg = new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$");
+                    if (validText !== null && (num < 0 || !reg.test(num))) {
+                        toastr.warning('已保留'+ materialDecimal.up +'位小数');
+                        validText = ZhCalc.round(num, materialDecimal.up);
                     }
                     select[col.field] = validText;
 
@@ -874,7 +867,7 @@ $(document).ready(() => {
             const hint = {
                 cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
-                numberCan: {type: 'warning', msg: '已保留3位小数'},
+                numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
             };
             const range = info.cellRange;
             const sortData = info.sheet.zh_data || [];
@@ -922,11 +915,10 @@ $(document).ready(() => {
                             bPaste = false;
                             continue;
                         }
-                        if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
+                        const reg = new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$");
+                        if (validText !== null && (num < 0 || !reg.test(num))) {
                             toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
-                            validText = ZhCalc.round(num, 3);
-                            // bPaste = false;
-                            // continue;
+                            validText = ZhCalc.round(num, materialDecimal.up);
                         }
                     }
                     materialMonthData[colSetting.field] = validText;
@@ -1021,10 +1013,10 @@ $(document).ready(() => {
         $('#changeRate').change(function () {
             const rate = parseInt($(this).val());
             postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
-                const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), 2);
-                const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
-                const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), 2);
-                const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), 2);
+                const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
+                const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
+                const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
+                const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
                 $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
                 $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
                 $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');

+ 8 - 8
app/public/js/material_exponent.js

@@ -14,10 +14,10 @@ function getPasteHint (str, row = '') {
 }
 function resetExTpTable() {
     const rate = $('#changeRate').val();
-    const bqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
-    const jzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, bqhs), 2);
-    $('#tp_set').find('td').eq(3).text(ZhCalc.round(ex_tp, 2));
-    $('#tp_set').find('td').eq(4).text(ZhCalc.round(ZhCalc.add(ex_pre_tp, ex_tp), 2));
+    const bqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
+    const jzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, bqhs), materialDecimal.tp);
+    $('#tp_set').find('td').eq(3).text(ZhCalc.round(ex_tp, materialDecimal.tp));
+    $('#tp_set').find('td').eq(4).text(ZhCalc.round(ZhCalc.add(ex_pre_tp, ex_tp), materialDecimal.tp));
     $('#rate_set').find('td').eq(3).text(bqhs !== 0 ? bqhs : '');
     $('#rate_set').find('td').eq(4).text(jzbqhs !== 0 ? jzbqhs : '');
     // $('#ex_expr').html(ex_expr);
@@ -527,11 +527,11 @@ $(document).ready(() => {
         $('#changeRate').change(function () {
             const rate = parseInt($(this).val());
             postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
-                const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
-                const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), 2);
+                const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
+                const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
                 if (!materialTax) {
-                    const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), 2);
-                    const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), 2);
+                    const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
+                    const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
                     $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
                     $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
                 }

+ 4 - 4
app/public/js/material_list.js

@@ -49,7 +49,7 @@ function calcOneBQJC(xmj) {
             jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
         }
     }
-    return ZhCalc.round(jiacha, 2);
+    return ZhCalc.round(jiacha, materialDecimal.tp);
 }
 
 function getPasteHint (str, row = '') {
@@ -71,7 +71,7 @@ function calculateJiaCha(data, index) {
             gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
             total_jiacha += jiacha;
         }
-        gcld.total_jiacha = ZhCalc.round(total_jiacha, 2)
+        gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
     } else {
         for(const gcld of data) {
             let total_jiacha = 0;
@@ -80,7 +80,7 @@ function calculateJiaCha(data, index) {
                 gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
                 total_jiacha += jiacha;
             }
-            gcld.total_jiacha = ZhCalc.round(total_jiacha, 2)
+            gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
         }
     }
 }
@@ -160,7 +160,7 @@ $(document).ready(() => {
         if (gcl) {
             for (const [index, xmj] of gcl.leafXmjs.entries()) {
                 const jiacha = calcOneBQJC(xmj);
-                gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, 2) : null;
+                gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
             }
             const leafXmjs = gcl.leafXmjs.filter(item => {
                 return item.qc_qty || item.contract_qty

+ 1 - 0
app/router.js

@@ -453,6 +453,7 @@ module.exports = app => {
     app.post('/tender/:id/measure/material/add', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.add');
     app.post('/tender/:id/measure/material/delete', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.delete');
     app.post('/tender/:id/measure/material/auditors', sessionAuth, tenderCheck, uncheckTenderCheck, 'materialController.materialAuditors');
+    app.post('/tender/:id/measure/material/:order/save/decimal', sessionAuth, tenderCheck, uncheckTenderCheck, materialCheck, 'materialController.saveDecimal');
     // 审批
     app.post('/tender/:id/measure/material/:order/audit/add', sessionAuth, tenderCheck, uncheckTenderCheck, materialCheck, 'materialController.addAudit');
     app.post('/tender/:id/measure/material/:order/audit/delete', sessionAuth, tenderCheck, uncheckTenderCheck, materialCheck, 'materialController.deleteAudit');

+ 28 - 4
app/service/material.js

@@ -10,6 +10,7 @@
 
 const auditConst = require('../const/audit').material;
 const projectLogConst = require('../const/project_log');
+const materialConst = require('../const/material');
 module.exports = app => {
     class Material extends app.BaseService {
         /**
@@ -145,6 +146,7 @@ module.exports = app => {
                 stage_id: data.stage_id.join(','),
                 s_order: data.s_order,
                 material_tax: this.ctx.session.sessionProject.page_show.openMaterialTax,
+                decimal: preMaterial && preMaterial.decimal ? preMaterial.decimal : JSON.stringify(materialConst.decimal),
             };
             const transaction = await this.db.beginTransaction();
             try {
@@ -312,8 +314,8 @@ module.exports = app => {
          * @param {int} order 调差期数
          * @return {Promise<*>}
          */
-        async getPreTpHs(tid, order) {
-            const sql = 'SELECT SUM(ROUND(`m_tp`*(1+ `rate`/100),2)) AS `pre_tp_hs` FROM ?? WHERE `tid` = ? AND `material_tax` = ? AND `order` < ?';
+        async getPreTpHs(tid, order, tp) {
+            const sql = 'SELECT SUM(ROUND(`m_tp`*(1+ `rate`/100),' + tp + ')) AS `pre_tp_hs` FROM ?? WHERE `tid` = ? AND `material_tax` = ? AND `order` < ?';
             const sqlParam = [this.tableName, tid, 0, order];
             const result = await this.db.queryOne(sql, sqlParam);
             return result.pre_tp_hs;
@@ -338,8 +340,8 @@ module.exports = app => {
          * @param {int} order 调差期数
          * @return {Promise<*>}
          */
-        async getExPreTpHs(tid, order) {
-            const sql = 'SELECT SUM(ROUND(`ex_tp`*(1+ `rate`/100),2)) AS `ex_pre_tp_hs` FROM ?? WHERE `tid` = ? AND `order` < ?';
+        async getExPreTpHs(tid, order, tp) {
+            const sql = 'SELECT SUM(ROUND(`ex_tp`*(1+ `rate`/100),' + tp + ')) AS `ex_pre_tp_hs` FROM ?? WHERE `tid` = ? AND `order` < ?';
             const sqlParam = [this.tableName, tid, order];
             const result = await this.db.queryOne(sql, sqlParam);
             return result.ex_pre_tp_hs;
@@ -370,6 +372,28 @@ module.exports = app => {
             const result = await this.db.queryOne(sql, sqlParam);
             return result && result.count !== 0;
         }
+
+        async saveDecimal(newUp, newTp) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                await this.ctx.service.materialBills.resetDecimal(transaction, newUp, newTp);
+                this.ctx.material.decimal.up = newUp;
+                this.ctx.material.decimal.tp = newTp;
+                const m_tp = await this.ctx.service.materialBills.calcMaterialMTp(transaction);
+                const [ex_tp, ex_expr] = await this.ctx.service.materialExponent.calcMaterialExTp(transaction);
+                const updateData = {
+                    id: this.ctx.material.id,
+                    decimal: JSON.stringify(this.ctx.material.decimal),
+                };
+                await transaction.update(this.tableName, updateData);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                console.log(err);
+                await transaction.rollback();
+                return false;
+            }
+        }
     }
 
     return Material;

+ 68 - 18
app/service/material_bills.js

@@ -250,8 +250,8 @@ module.exports = app => {
                 const mb_quantity = await transaction.queryOne(sql, sqlParam);
                 console.log(mb_quantity);
                 // 取历史期记录获取截止上期调差金额,并清空本期单价和时间,来源地,重新计算价差和有效价差
-                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, 3);
-                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), 2);
+                const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+                const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, newm_spread), this.ctx.material.decimal.tp);
                 const updateData = {
                     id: mb.id,
                     quantity: newQuantity,
@@ -261,33 +261,33 @@ module.exports = app => {
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), 2) : mb.pre_tp,
-                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), 2) : mb.tax_pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
+                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
-                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), 2) : 0;
-                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2);
+                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(mb_quantity.quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
+                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
                 return [m_tp, m_tax_tp];
             } else if (mb.t_type === materialConst.t_type[1].value) {
                 const quantity = await materialCalculator.calculateExpr(mb.expr);
-                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, 3), newm_spread), 2) : null;
+                const newTp = quantity !== 0 && quantity !== null ? this.ctx.helper.round(this.ctx.helper.mul(this.ctx.helper.round(quantity, this.ctx.material.decimal.qty), newm_spread), this.ctx.material.decimal.tp) : null;
                 const updateData = {
                     id: mb.id,
-                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, 3) : null,
+                    quantity: quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null,
                     msg_tp: null,
                     msg_times: null,
                     msg_spread: newmsg_spread,
                     m_spread: newm_spread,
                     origin: null,
                     m_tp: newTp,
-                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), 2) : mb.pre_tp,
-                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2),
-                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), 2) : mb.tax_pre_tp,
+                    pre_tp: mb.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.pre_tp, mb.m_tp), this.ctx.material.decimal.tp) : mb.pre_tp,
+                    m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
+                    tax_pre_tp: mb.m_tax_tp !== null ? this.ctx.helper.round(this.ctx.helper.add(mb.tax_pre_tp, mb.m_tax_tp), this.ctx.material.decimal.tp) : mb.tax_pre_tp,
                 };
                 await transaction.update(this.tableName, updateData);
-                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), 2) : 0;
-                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2);
+                const m_tp = mb.is_summary === 1 ? await this.ctx.helper.round(this.ctx.helper.mul(quantity, newm_spread), this.ctx.material.decimal.tp) : 0;
+                const m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp);
                 return [m_tp, m_tax_tp];
             }
         }
@@ -297,11 +297,11 @@ module.exports = app => {
          * @param data
          * @returns {Promise<void>}
          */
-        async getSpread(data, msg_tp) {
+        async getSpread(data, msg_tp, newDecimalUp = this.ctx.material.decimal.up) {
             data.msg_tp = msg_tp;
-            const msg_spread = this.ctx.helper.round(this.ctx.helper.sub(data.msg_tp, data.basic_price), 3);
+            const msg_spread = this.ctx.helper.round(this.ctx.helper.sub(data.msg_tp, data.basic_price), newDecimalUp);
             const cor = msg_spread >= 0 ? this.ctx.helper.mul(data.basic_price, this.ctx.helper.div(data.m_up_risk, 100)) : this.ctx.helper.mul(data.basic_price, this.ctx.helper.div(data.m_down_risk, 100));
-            const m_spread = Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? this.ctx.helper.round(this.ctx.helper.sub(msg_spread, cor), 3) : this.ctx.helper.round(this.ctx.helper.add(msg_spread, cor), 3)) : 0;
+            const m_spread = Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? this.ctx.helper.round(this.ctx.helper.sub(msg_spread, cor), newDecimalUp) : this.ctx.helper.round(this.ctx.helper.add(msg_spread, cor), newDecimalUp)) : 0;
             return [msg_spread, m_spread];
         }
 
@@ -317,7 +317,8 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 const mbInfo = await this.getDataById(data.id);
-                data.m_tp = this.ctx.helper.round(this.ctx.helper.mul(data.quantity, mbInfo.m_spread), 2);
+                data.m_tp = this.ctx.helper.round(this.ctx.helper.mul(data.quantity, mbInfo.m_spread), this.ctx.material.decimal.tp);
+                data.m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(data.m_tp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp);
                 await transaction.update(this.tableName, data);
                 let m_tp = this.ctx.material.m_tp;
                 if (mbInfo.quantity !== data.quantity) {
@@ -353,6 +354,55 @@ module.exports = app => {
             await transaction.update(this.ctx.service.material.tableName, updateData2);
             return tp.total_price;
         }
+
+        // 小数位变化更新单价和金额
+        async resetDecimal(transaction, newDecimalUp, newDecimalTp) {
+            const mbList = await transaction.select(this.tableName, { where: { tid: this.ctx.tender.id }, orders: [['order', 'asc']] });
+            const updateList = [];
+            const material_month = this.ctx.material.months ? this.ctx.material.months.split(',') : [];
+            const updateMonthList = [];
+            for (const mb of mbList) {
+                const updateData = {
+                    id: mb.id,
+                };
+                if (newDecimalUp !== this.ctx.material.decimal.up) {
+                    let newmsg_tp = this.ctx.helper.round(mb.msg_tp, newDecimalUp);
+                    mb.msg_tp = newmsg_tp;
+                    // 判断是否有月信息价,如果有则msg_tp值由月信息价的平均单价获得,并更新月信息价单价
+                    if (material_month.length > 0) {
+                        const monthList = await transaction.select(this.ctx.service.materialMonth.tableName, { where: { mb_id: mb.id, mid: this.ctx.material.id } });
+                        if (monthList.length !== 0) {
+                            for (const m of monthList) {
+                                // 更新月信息单价小数位
+                                const newMonthMsgTP = this.ctx.helper.round(m.msg_tp, newDecimalUp);
+                                if (m.msg_tp && newMonthMsgTP !== m.msg_tp) {
+                                    m.msg_tp = newMonthMsgTP;
+                                    updateMonthList.push({ id: m.id, msg_tp: m.msg_tp });
+                                }
+                            }
+                            const mb_msg_tp_sum = this._.sumBy(monthList, 'msg_tp');
+                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(monthList, 'msg_tp'), [null, '', 0]);
+                            newmsg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), newDecimalUp) : null;
+                            mb.msg_tp = newmsg_tp;
+                        }
+                    }
+                    const newbasic_price = this.ctx.helper.round(mb.basic_price, newDecimalUp);
+                    mb.basic_price = newbasic_price;
+                    const [newmsg_spread, newm_spread] = await this.getSpread(mb, mb.msg_tp, newDecimalUp);
+                    mb.m_spread = newm_spread;
+                    updateData.basic_price = newbasic_price;
+                    updateData.msg_tp = newmsg_tp;
+                    updateData.msg_spread = newmsg_spread;
+                    updateData.m_spread = newm_spread;
+                }
+                const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, mb.m_spread), newDecimalTp);
+                updateData.m_tp = newTp;
+                updateData.m_tax_tp = this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), newDecimalTp);
+                updateList.push(updateData);
+            }
+            if (updateMonthList.length > 0) await transaction.updateRows(this.ctx.service.materialMonth.tableName, updateMonthList);
+            if (updateList.length > 0) await transaction.updateRows(this.tableName, updateList);
+        }
     }
 
     return MaterialBills;

+ 1 - 1
app/service/material_exponent.js

@@ -213,7 +213,7 @@ module.exports = app => {
             }
             expr += '-1]';
             expr = constant !== 0 ? expr : null;
-            const ex_tp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basic_calc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), 2) : null;
+            const ex_tp = constant !== 0 ? this.ctx.helper.round(this.ctx.helper.mul(basic_calc, this.ctx.helper.sub(this.ctx.helper.add(constant, sumByChange), 1)), this.ctx.material.decimal.tp) : null;
             await transaction.update(this.ctx.service.material.tableName, {
                 id: mid ? mid : this.ctx.material.id,
                 ex_tp,

+ 4 - 4
app/service/material_list.js

@@ -216,13 +216,13 @@ module.exports = app => {
             const sqlParam = [this.ctx.material.id, mb_id];
             const mb_quantity = await transaction.queryOne(sql, sqlParam);
             console.log(mb_quantity);
-            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, 3);
-            const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, mbInfo.m_spread), 2);
+            const newQuantity = this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty);
+            const newTp = this.ctx.helper.round(this.ctx.helper.mul(newQuantity, mbInfo.m_spread), this.ctx.material.decimal.tp);
             const updateData = {
                 id: mb_id,
-                quantity: this.ctx.helper.round(mb_quantity.quantity, 3),
+                quantity: this.ctx.helper.round(mb_quantity.quantity, this.ctx.material.decimal.qty),
                 m_tp: newTp,
-                m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), 2),
+                m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
             };
             await transaction.update(this.ctx.service.materialBills.tableName, updateData);
             // 计算本期总金额

+ 12 - 12
app/service/material_month.js

@@ -61,16 +61,16 @@ module.exports = app => {
                         if (monthList.length !== 0) {
                             const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
                             const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), one_month.msg_tp), [null, '', 0]);
-                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, one_month.msg_tp), month_num), 3);
+                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, one_month.msg_tp), month_num), this.ctx.material.decimal.up);
                             const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
-                            const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), 2);
+                            const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), this.ctx.material.decimal.tp);
                             updateArray.push({
                                 id: mb.id,
                                 msg_tp: new_msg_tp,
                                 msg_spread: newmsg_spread,
                                 m_spread: newm_spread,
                                 m_tp: newTp,
-                                m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2),
+                                m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
                             });
                         }
                     }
@@ -111,16 +111,16 @@ module.exports = app => {
                         });
                         const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
                         const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), [null, '', 0]);
-                        const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
+                        const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), this.ctx.material.decimal.up) : null;
                         const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
-                        const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), 2);
+                        const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), this.ctx.material.decimal.tp);
                         updateArray.push({
                             id: mb.id,
                             msg_tp: new_msg_tp,
                             msg_spread: newmsg_spread,
                             m_spread: newm_spread,
                             m_tp: newTp,
-                            m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2),
+                            m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
                         });
                     }
                     if (updateArray.length !== 0) await transaction.updateRows(this.ctx.service.materialBills.tableName, updateArray);
@@ -153,16 +153,16 @@ module.exports = app => {
                 if (monthList.length !== 0) {
                     const mb_msg_tp_sum = this._.sumBy(monthList, 'msg_tp');
                     const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(monthList, 'msg_tp'), [null, '', 0]);
-                    const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
+                    const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), this.ctx.material.decimal.up) : null;
                     const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mbInfo, new_msg_tp);
-                    const newTp = this.ctx.helper.round(this.ctx.helper.mul(mbInfo.quantity, newm_spread), 2);
+                    const newTp = this.ctx.helper.round(this.ctx.helper.mul(mbInfo.quantity, newm_spread), this.ctx.material.decimal.tp);
                     await transaction.update(this.ctx.service.materialBills.tableName, {
                         id: mbInfo.id,
                         msg_tp: new_msg_tp,
                         msg_spread: newmsg_spread,
                         m_spread: newm_spread,
                         m_tp: newTp,
-                        m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), 2),
+                        m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
                     });
                 }
                 const m_tp = await this.ctx.service.materialBills.calcMaterialMTp(transaction);
@@ -207,16 +207,16 @@ module.exports = app => {
                     for (const mb of mbList) {
                         const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
                         const month_num = material_month.length - this.ctx.helper.arrayCount(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), [null, '', 0]);
-                        const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), 3) : null;
+                        const new_msg_tp = month_num !== 0 ? this.ctx.helper.round(this.ctx.helper.div(mb_msg_tp_sum, month_num), this.ctx.material.decimal.up) : null;
                         const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
-                        const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), 2);
+                        const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), this.ctx.material.decimal.tp);
                         mbUpdateArray.push({
                             id: mb.id,
                             msg_tp: new_msg_tp,
                             msg_spread: newmsg_spread,
                             m_spread: newm_spread,
                             m_tp: newTp,
-                            m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), 2),
+                            m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(newTp, (1 + this.ctx.helper.div(mb.m_tax, 100))), this.ctx.material.decimal.tp),
                         });
                     }
                     if (mbUpdateArray.length !== 0) await transaction.updateRows(this.ctx.service.materialBills.tableName, mbUpdateArray);

+ 51 - 39
app/view/material/audit_modal.ejs

@@ -682,6 +682,46 @@
         </div>
     <% } %>
 <% } %>
+<!--材料调差-小数位数-->
+<div class="modal fade" id="cc-digits" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <form action="/tender/<%- ctx.tender.id %>/measure/material/<%- ctx.material.order %>/save/decimal" method="post" onsubmit="return checkSetDecimal();" class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">小数位数</h5>
+            </div>
+            <div class="modal-body">
+                <div class="form-group">
+
+                    <div class="row">
+                        <div class="col-4">
+                            <div class="input-group input-group-sm">
+                                <div class="input-group-prepend">
+                                    <span class="input-group-text">单价</span>
+                                </div>
+                                <input type="number" step="1" min="0" max="6" id="decimal_up" name="up" class="form-control" value="<%- material.decimal.up %>" <% if (!((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id)) { %>disabled<% } %>>
+                            </div>
+                        </div>
+                        <div class="col-4">
+                            <div class="input-group input-group-sm">
+                                <div class="input-group-prepend">
+                                    <span class="input-group-text">金额</span>
+                                </div>
+                                <input type="number" step="1" min="0" max="6" id="decimal_tp" name="tp" class="form-control" value="<%- material.decimal.tp %>" <% if (!((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id)) { %>disabled<% } %>>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <input type="hidden" name="_csrf_j" value="<%= ctx.csrf %>" />
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                <% if ((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id) { %>
+                    <button type="submit" class="btn btn-sm btn-primary">确认修改</button>
+                <% } %>
+            </div>
+        </form>
+    </div>
+</div>
 <% if (ctx.session.sessionUser.accountId === ctx.material.user_id && (ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo)) { %>
     <script>
         const accountGroup = JSON.parse(unescape('<%- escape(JSON.stringify(accountGroup)) %>'));
@@ -736,43 +776,15 @@
             $('.modal-title').text('重新上报')
         }
     });
+    // 小数位设置
+    function checkSetDecimal() {
+        const up = parseInt($('#decimal_up').val());
+        const tp = parseInt($('#decimal_tp').val());
+        if(up > 6 || up < 0) {
+            toastr.error('单价小数位数设置不能大于6或小于0');
+        }
+        if(tp > 6 || tp < 0) {
+            toastr.error('金额小数位数设置不能大于6或小于0');
+        }
+    }
 </script>
-<!--材料调差-小数位数-->
-<div class="modal fade" id="cc-digits" 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">
-
-                    <div class="row">
-                        <div class="col-4">
-                            <div class="input-group input-group-sm">
-                                <div class="input-group-prepend">
-                                    <span class="input-group-text">数量</span>
-                                </div>
-                                <input type="number" class="form-control" value="<%- material.decimal.qty %>" <% if (!((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id)) { %>disabled<% } %>>
-                            </div>
-                        </div>
-                        <div class="col-4">
-                            <div class="input-group input-group-sm">
-                                <div class="input-group-prepend">
-                                    <span class="input-group-text">金额</span>
-                                </div>
-                                <input type="number" class="form-control" value="<%- material.decimal.tp %>" <% if (!((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id)) { %>disabled<% } %>>
-                            </div>
-                        </div>
-                    </div>
-                </div>
-            </div>
-            <div class="modal-footer">
-                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
-                <% if ((material.status === auditConst.status.uncheck || material.status === auditConst.status.checkNo) && ctx.session.sessionUser.accountId === material.user_id) { %>
-                    <button type="button" class="btn btn-sm btn-primary">确认修改</button>
-                <% } %>
-            </div>
-        </div>
-    </div>
-</div>

+ 19 - 18
app/view/material/exponent.ejs

@@ -18,7 +18,7 @@
                 <!--</div>-->
             </div>
             <div class="ml-auto">
-                <!--<a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>-->
+                <a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>
             </div>
         </div>
     </div>
@@ -59,16 +59,16 @@
                                             <a href="javascript:void(0);" id="ex_expr" data-toggle="tooltip" data-placement="bottom" title="本期价差:<%- material.ex_expr ? material.ex_expr : '' %>"><i class="fa fa-question-circle-o"></i></a></th>
                                         <th>截止本期金额</th></tr>
                                     <tr id="tp_set"><td>材料价差费用</td>
-                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, 2) : null %></td>
-                                        <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), 2) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), material.decimal.tp) : null %></td>
                                     </tr>
                                     <tr id="rate_set"><td>材料价差费用(含建筑税)</td>
-                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2) : null %></td>
-                                        <td class="text-center"><%= material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2)), 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2)), 2) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
                                     </tr>
                                 </table>
                             </div>
@@ -83,22 +83,22 @@
                                             <a href="javascript:void(0);" id="ex_expr" data-toggle="tooltip" data-placement="bottom" title="本期价差:<%- material.ex_expr ? material.ex_expr : '' %>"><i class="fa fa-question-circle-o"></i></a></th>
                                         <th>截止本期金额</th></tr>
                                     <tr id="tp_set"><td>材料价差费用</td>
-                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, 2) : null %></td>
-                                        <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), 2) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), material.decimal.tp) : null %></td>
                                     </tr>
                                     <tr><td>材料价差费用(含材料税)</td>
                                         <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null ? material.m_tax_tp : null) : '-' %></td>
-                                        <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null || material.m_tax_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.m_tax_pre_tp, material.m_tax_tp), 2) : null) : material.m_tax_pre_tp %></td>
+                                        <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null || material.m_tax_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.m_tax_pre_tp, material.m_tax_tp), material.decimal.tp) : null) : material.m_tax_pre_tp %></td>
                                         <td class="text-center">-</td>
                                         <td class="text-center">-</td>
                                     </tr>
                                     <tr id="rate_set"><td>材料价差费用(含建筑税)</td>
-                                        <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2) : null) : '-' %></td>
-                                        <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2)), 2) : null) : pre_tp_hs !== null ? pre_tp_hs : '-' %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2) : null %></td>
-                                        <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2)), 2) : null %></td>
+                                        <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp) : null) : '-' %></td>
+                                        <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null) : pre_tp_hs !== null ? pre_tp_hs : '-' %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                        <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
                                     </tr>
                                 </table>
                             </div>
@@ -148,6 +148,7 @@
     const materialID = <%- material.id %>;
     const materialTax = <%- material.material_tax %>;
     const materialOrder = <%- material.order %>;
+    const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
     const decimal = JSON.parse('<%- JSON.stringify(ctx.tender.info.decimal) %>');
     let m_tp = <%= material.m_tp !== null ? material.m_tp : 0 %>;
     let ex_tp = <%= material.ex_tp !== null ? material.ex_tp : 0 %>;

+ 2 - 1
app/view/material/file.ejs

@@ -35,7 +35,7 @@
           <!--</span>-->
         <!--</div>-->
       <div class="ml-auto">
-        <!--<a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>-->
+        <a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>
       </div>
     </div>
   </div>
@@ -124,6 +124,7 @@
   const tid = '<%- ctx.tender.id %>';
   const mid = '<%- ctx.material.id %>';
   const order = '<%- ctx.material.order %>';
+  const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
   const fileList = JSON.parse(unescape('<%- escape(JSON.stringify(fileList)) %>'));
   const tender = JSON.parse(unescape('<%- escape(JSON.stringify(tender)) %>'));
   const whiteList = JSON.parse('<%- JSON.stringify(whiteList) %>');

+ 6 - 6
app/view/material/index.ejs

@@ -48,14 +48,14 @@
                             </td>
                             <td class="text-center"><%= moment(m.in_time).format('YYYY-MM-DD') %></td>
                             <td class="text-center">第 <%= m.s_order %> 期</td>
-                            <td class="text-right"><%= m.m_tp !== null ? ctx.helper.round(m.m_tp, 2) : null %></td>
+                            <td class="text-right"><%= m.m_tp !== null ? ctx.helper.round(m.m_tp, m.decimal.tp) : null %></td>
                             <% if (openMaterialTax) { %><td class="text-right"><% if (m.material_tax) { %><% if (m.m_tax_tp) { %><%- m.m_tax_tp %><% } else { %><%- m.m_tp %><% } %><% } %></td><% } %>
-                            <% if ((openMaterialTax && !allMaterialTax) || !openMaterialTax) { %><td class="text-right"><% if (!m.material_tax) { %><%= m.m_tp !== null ? ctx.helper.round(ctx.helper.mul(m.m_tp, 1+m.rate/100), 2) : null %><% } %></td><% } %>
-                            <td class="text-right"><%= m.ex_tp !== null ? ctx.helper.round(m.ex_tp, 2) : null %></td>
-                            <td class="text-right"><%= m.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), 2) : null %></td>
-                            <td class="text-right"><%= ctx.helper.add(ctx.helper.round(m.ex_tp, 2), ctx.helper.round(m.m_tp, 2)) %></td>
+                            <% if ((openMaterialTax && !allMaterialTax) || !openMaterialTax) { %><td class="text-right"><% if (!m.material_tax) { %><%= m.m_tp !== null ? ctx.helper.round(ctx.helper.mul(m.m_tp, 1+m.rate/100), m.decimal.tp) : null %><% } %></td><% } %>
+                            <td class="text-right"><%= m.ex_tp !== null ? ctx.helper.round(m.ex_tp, m.decimal.tp) : null %></td>
+                            <td class="text-right"><%= m.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), m.decimal.tp) : null %></td>
+                            <td class="text-right"><%= ctx.helper.add(ctx.helper.round(m.ex_tp, m.decimal.tp), ctx.helper.round(m.m_tp, m.decimal.tp)) %></td>
                             <% if (openMaterialTax) { %><td class="text-right"><% if (m.material_tax) { %><% if (m.m_tax_tp) { %><%- m.m_tax_tp %><% } else { %><%- m.m_tp %><% } %><% } %></td><% } %>
-                            <td class="text-right"><% if (m.material_tax) { %><%= m.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), 2) : null %><% } else { %><%= ctx.helper.add(ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), 2), ctx.helper.round(ctx.helper.mul(m.m_tp, 1+m.rate/100), 2)) %><% } %></td>
+                            <td class="text-right"><% if (m.material_tax) { %><%= m.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), m.decimal.tp) : null %><% } else { %><%= ctx.helper.add(ctx.helper.round(ctx.helper.mul(m.ex_tp, 1+m.rate/100), m.decimal.tp), ctx.helper.round(ctx.helper.mul(m.m_tp, 1+m.rate/100), m.decimal.tp)) %><% } %></td>
                             <td class="<%- auditConst.auditProgressClass[m.status] %>">
                                 <% if (m.curAuditor) { %>
                                     <a href="#sp-list" data-toggle="modal" data-target="#sp-list" m-order="<%- m.order %>"><%- m.curAuditor.name %><%if (m.curAuditor.role !== '' && m.curAuditor.role !== null) { %>-<%- m.curAuditor.role %><% } %></a>

+ 19 - 18
app/view/material/info.ejs

@@ -22,7 +22,7 @@
                 </div>
             </div>
             <div class="ml-auto">
-                <!--<a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>-->
+                <a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>
             </div>
         </div>
     </div>
@@ -64,16 +64,16 @@
                                         <a href="javascript:void(0);" id="ex_expr" data-toggle="tooltip" data-placement="bottom" title="本期价差:<%- material.ex_expr ? material.ex_expr : '' %>"><i class="fa fa-question-circle-o"></i></a></th>
                                     <th>截止本期金额</th></tr>
                                 <tr id="tp_set"><td>材料价差费用</td>
-                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, 2) : null %></td>
-                                    <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), 2) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), material.decimal.tp) : null %></td>
                                 </tr>
                                 <tr id="rate_set"><td>材料价差费用(含建筑税)</td>
-                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2) : null %></td>
-                                    <td class="text-center"><%= material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2)), 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2)), 2) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
                                 </tr>
                             </table>
                         </div>
@@ -88,22 +88,22 @@
                                         <a href="javascript:void(0);" id="ex_expr" data-toggle="tooltip" data-placement="bottom" title="本期价差:<%- material.ex_expr ? material.ex_expr : '' %>"><i class="fa fa-question-circle-o"></i></a></th>
                                     <th>截止本期金额</th></tr>
                                 <tr id="tp_set"><td>材料价差费用</td>
-                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, 2) : null %></td>
-                                    <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), 2) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null ? ctx.helper.round(material.m_tp, material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.m_tp !== null || material.pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.pre_tp, material.m_tp), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(material.ex_tp, material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null || material.ex_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.ex_pre_tp, material.ex_tp), material.decimal.tp) : null %></td>
                                 </tr>
                                 <tr id="tax_rate_set"><td>材料价差费用(含材料税)</td>
                                     <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null ? material.m_tax_tp : null) : '-' %></td>
-                                    <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null || material.m_tax_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.m_tax_pre_tp, material.m_tax_tp), 2) : null) : material.m_tax_pre_tp %></td>
+                                    <td class="text-center"><%= material.material_tax ? (material.m_tax_tp !== null || material.m_tax_pre_tp !== null ? ctx.helper.round(ctx.helper.add(material.m_tax_pre_tp, material.m_tax_tp), material.decimal.tp) : null) : material.m_tax_pre_tp %></td>
                                     <td class="text-center">-</td>
                                     <td class="text-center">-</td>
                                 </tr>
                                 <tr id="rate_set"><td>材料价差费用(含建筑税)</td>
-                                    <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2) : null) : '-' %></td>
-                                    <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), 2)), 2) : null) : pre_tp_hs !== null ? pre_tp_hs : '-' %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2) : null %></td>
-                                    <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), 2)), 2) : null %></td>
+                                    <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null ? ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp) : null) : '-' %></td>
+                                    <td class="text-center"><%= !material.material_tax ? (material.m_tp !== null || pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.m_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null) : pre_tp_hs !== null ? pre_tp_hs : '-' %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null ? ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp) : null %></td>
+                                    <td class="text-center"><%= material.ex_tp !== null || ex_pre_tp_hs !== null ? ctx.helper.round(ctx.helper.add(ex_pre_tp_hs, ctx.helper.round(ctx.helper.mul(material.ex_tp, 1+material.rate/100), material.decimal.tp)), material.decimal.tp) : null %></td>
                                 </tr>
                             </table>
                         </div>
@@ -153,6 +153,7 @@
     const readOnly = <%- material.readOnly %>;
     const materialID = <%- material.id %>;
     const materialTax = <%- material.material_tax %>;
+    const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
     let m_tp = <%= material.m_tp !== null ? material.m_tp : 0 %>;
     let ex_tp = <%= material.ex_tp !== null ? material.ex_tp : 0 %>;
     const pre_tp = <%= material.pre_tp !== null ? material.pre_tp : 0 %>;

+ 2 - 1
app/view/material/list.ejs

@@ -17,7 +17,7 @@
                 </div>
             </div>
             <div class="ml-auto">
-                <!--<a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>-->
+                <a href="#cc-digits" class="btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#cc-digits" data-placement="bottom" title="" >小数位数</a>
             </div>
         </div>
     </div>
@@ -76,5 +76,6 @@
     const readOnly = <%- material.readOnly %>;
     const stage_order = <%- material.order %>;
     const materialID = <%- material.id %>;
+    const materialDecimal = JSON.parse(unescape('<%- escape(JSON.stringify(material.decimal)) %>'));
     let materialListData, notJoinList, ledger, curLedgerData, pos, curPosData, gclGatherData;
 </script>