Browse Source

安全生产费,小数位数相关

MaiXinRong 1 year ago
parent
commit
b5e6bb4c90

+ 10 - 0
app/controller/payment_controller.js

@@ -1327,6 +1327,16 @@ module.exports = app => {
                 ctx.body = this.ajaxErrorBody(err, '数据错误');
             }
         }
+        async safeDecimal(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const result = await this.ctx.service.paymentSafeBills.setDecimal(data.decimal);
+                ctx.body = { err: 0, msg: '', data: result };
+            } catch (err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '设置小数位数错误');
+            }
+        }
     }
 
     return PaymentController;

+ 4 - 4
app/lib/analysis_excel.js

@@ -439,8 +439,8 @@ class ImportStd18Tree extends ImportBaseTree {
      * @returns {*}
      */
     findXmjParent(code) {
-        //if (aeUtils.check18MainCode(code)) {
-        if (code.match(mainReg)) {
+        if (aeUtils.check18MainCode(code)) {
+        //if (code.match(mainReg)) {
             if (!this.cacheMainXmjNode) throw '主表项目节找不到父项';
             return this.findMainXmjParent(code);
         } else if (code.match(subReg)) {
@@ -456,8 +456,8 @@ class ImportStd18Tree extends ImportBaseTree {
     defineCacheData(node) {
         super.defineCacheData(node);
         if (node.code) {
-            //if (aeUtils.check18MainCode(node.code)) {
-            if (node.code.match(mainReg)) {
+            if (aeUtils.check18MainCode(node.code)) {
+            //if (node.code.match(mainReg)) {
                 node.is_main = true;
                 this.cacheMainXmjNode = node;
                 this.cacheSubXmjNode = null;

+ 1 - 0
app/middleware/payment_detail_check.js

@@ -31,6 +31,7 @@ module.exports = options => {
             if (!detail) {
                 throw '支付审批表单不存在';
             }
+            detail.decimal = detail.decimal ? JSON.parse(detail.decimal) : { qty: 3, tp: 2, up: 2};
             const trInfo = yield this.service.paymentTenderRpt.getDataById(detail.tr_id);
             if (!trInfo) {
                 throw '支付审批报表不存在';

+ 19 - 0
app/public/js/payment_safe.js

@@ -575,6 +575,25 @@ $(document).ready(function() {
                 return !(valid && first && sameParent && !(first.tree_level === 1) && !nodeUsed);
             }
         };
+        $('#psb-decimal').on('show.bs.modal', () => {
+            const decimalObjs = [$('#psb-qty'), $('#psb-up'), $('#psb-tp')];
+            for (const obj of decimalObjs) {
+                obj.val(obj.attr('org'));
+            }
+        });
+        $('#psb-decimal-ok').click(() => {
+            const decimal = { qty: parseInt($('#psb-qty').val()), up: parseInt($('#psb-up').val()), tp: parseInt($('#psb-tp').val()) };
+            postData('decimal', { decimal }, function(result) {
+                if (result.calc) {
+                    const refreshNode = billsObj.tree.loadPostData(result);
+                    billsObj.refreshTree(refreshNode);
+                }
+                $('#psb-qty').attr('org', decimal.qty);
+                $('#psb-up').attr('org', decimal.up);
+                $('#psb-tp').attr('org', decimal.tp);
+                $('#psb-decimal').modal('hide');
+            });
+        });
     }
 
     class AttObj {

+ 1 - 0
app/router.js

@@ -798,6 +798,7 @@ module.exports = app => {
     app.get('/payment/:id/safe/:did/compare', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.safeCompare');
     app.post('/payment/:id/safe/:did/load', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.safeLoad');
     app.post('/payment/:id/safe/:did/update', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.safeUpdate');
+    app.post('/payment/:id/safe/:did/decimal', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.safeDecimal');
     app.post('/payment/:id/safe/:did/file/upload', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.uploadDetailFile');
     app.post('/payment/:id/safe/:did/file/delete', sessionAuth, paymentTenderCheck, paymentDetailCheck, 'paymentController.deleteDetailFile');
 

+ 3 - 2
app/service/payment_detail.js

@@ -11,7 +11,7 @@ module.exports = app => {
 
         async getValidDetails(tr_id) {
             const details = await this.db.select(this.tableName, {
-                column: ['id', 'in_time', 'tr_id', 'uid', 'status', 'order', 'times', 'code', 's_time'],
+                column: ['id', 'in_time', 'tr_id', 'uid', 'status', 'order', 'times', 'code', 's_time', 'decimal'],
                 where: { tr_id },
                 orders: [['order', 'desc']],
             });
@@ -36,7 +36,7 @@ module.exports = app => {
 
         async getDetail(id) {
             const details = await this.db.select(this.tableName, {
-                column: ['id', 'in_time', 'tr_id', 'uid', 'status', 'order', 'times', 'code', 's_time'],
+                column: ['id', 'in_time', 'tr_id', 'uid', 'status', 'order', 'times', 'code', 's_time', 'decimal'],
                 where: { id },
                 orders: [['order', 'desc']],
             });
@@ -91,6 +91,7 @@ module.exports = app => {
                     report_json: JSON.stringify(pageRst),
                     in_time: new Date(),
                 };
+                if (preDetail) newDetail.decimal = preDetail.decimal;
                 const result = await transaction.insert(this.tableName, newDetail);
                 if (result.affectedRows === 1) {
                     newDetail.id = result.insertId;

+ 0 - 1
app/service/payment_detail_audit.js

@@ -87,7 +87,6 @@ module.exports = app => {
             for (const i in result) {
                 result[i].max_sort = count.num;
             }
-            console.log(result);
             return result;
         }
 

+ 39 - 2
app/service/payment_safe_bills.js

@@ -21,6 +21,8 @@ SafeBillsFields.readQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFi
 SafeBillsFields.compareQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'unit_price', 'cur_his', 'cur_qty', 'cur_tp'];
 SafeBillsFields.preQueryFields = [...SafeBillsFields.treeFields, ...SafeBillsFields.textFields, 'tender_id', 'unit_price', 'end_qty', 'end_tp', 'add_user_id', 'add_time', 'update_user_id', 'update_time'];
 
+const auditConst = require('../const/audit').stage;
+
 module.exports = app => {
 
     class PaymentSafeBills extends app.BaseTreeService {
@@ -284,7 +286,7 @@ module.exports = app => {
             if (!targetData) throw '粘贴数据错误';
 
             const newParentPath = targetData.full_path.replace(targetData.ledger_id, '');
-            const tpDecimal = this.decimal;
+            const tpDecimal = this.ctx.detail && this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
 
             const pasteBillsData = [], leafBillsId = [];
             let maxId = await this._getMaxLid(this.ctx.paymentTender.id);
@@ -463,7 +465,7 @@ module.exports = app => {
 
         async updateCalc(detail, data) {
             const helper = this.ctx.helper;
-            const decimal = this.decimal;
+            const decimal = this.ctx.detail && this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
             // 简单验证数据
             if (!detail) throw '安全生产费不存在';
             if (!data) throw '提交数据错误';
@@ -511,6 +513,41 @@ module.exports = app => {
             }
             if (updateData.length > 0) await transaction.updateRows(this.tableName, updateData);
         }
+
+        async setDecimal(decimal) {
+            if (!this.ctx.detail) throw '读取数据错误';
+            if (this.ctx.detail.order !== this.ctx.detail.highOrder) throw '往期不可修改小数位数';
+            if (this.ctx.detail.status !== auditConst.status.uncheck && this.ctx.detail.status !== auditConst.status.checkNo) throw '仅原报可修改小数位数';
+            const orgDecimal = this.ctx.detail.decimal ? this.ctx.detail.decimal : this.decimal;
+
+            const calcQty = decimal.qty < orgDecimal.qty;
+            const calcUp = decimal.up < orgDecimal.up;
+            const calcTp = decimal.tp < orgDecimal.tp;
+            this.ctx.detail.decimal = { up: decimal.up, tp: decimal.tp, qty: decimal.qty };
+
+            const updateData = [];
+            if (calcQty || calcUp || calcTp) {
+                const calcData = await this.getAllDataByCondition({ where: {detail_id: this.ctx.detail.id, tree_is_leaf: 1 } });
+                for (const cd of calcData) {
+                    const nd = { id: cd.id, tree_id: cd.tree_id };
+                    nd.unit_price = calcUp ? this.ctx.helper.round(cd.unit_price, decimal.up) : cd.unit_price;
+                    nd.cur_qty = calcQty ? this.ctx.helper.round(cd.cur_qty, decimal.qty) : cd.cur_qty;
+                    nd.cur_tp = this.ctx.helper.mul(nd.unit_price, nd.cur_qty, decimal.tp);
+                    nd.end_qty = this.ctx.helper.add(nd.pre_qty, nd.cur_qty);
+                    nd.end_tp = this.ctx.helper.add(nd.pre_tp, nd.cur_tp);
+                    updateData.push(nd);
+                }
+            }
+            const conn = await this.db.beginTransaction();
+            try {
+                await conn.update(this.ctx.service.paymentDetail.tableName, { id: this.ctx.detail.id, decimal: JSON.stringify(this.ctx.detail.decimal)});
+                if (updateData.length > 0) await conn.update(this.tableName, updateData);
+                await conn.commit();
+            } catch(err) {
+                await conn.rollback();
+            }
+            return { calc: calcQty || calcUp || calcTp, update: updateData };
+        }
     }
 
     return PaymentSafeBills;

+ 3 - 0
app/view/payment_safe/index.ejs

@@ -27,6 +27,9 @@
                     <a href="javascript: void(0);" name="base-opr" type="down-move" class="btn btn-sm btn-light text-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="下移"><i class="fa fa-arrow-down" aria-hidden="true"></i></a>
                     <a href="javascript: void(0);" name="base-opr" type="up-move" class="btn btn-sm btn-light text-primary" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="上移"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
                 </div>
+                <div class="d-inline-block">
+                    <a href="" class="btn btn-sm btn-light text-primary" data-toggle="modal" data-placement="bottom" title="设置" data-target="#psb-decimal"><i class="fa fa-cog" aria-hidden="true"></i></a>
+                </div>
                 <% } %>
             </div>
             <div class="ml-auto">

+ 46 - 0
app/view/payment_safe/modal.ejs

@@ -18,4 +18,50 @@
             </div>
         </div>
     </div>
+</div>
+<div class="modal fade show" id="psb-decimal" 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 mb-3">
+                    <h5>小数位数</h5>
+                    <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" id="psb-up" class="form-control" value="<%- ctx.detail.decimal.up %>" org="<%- ctx.detail.decimal.up %>" min="0" max="6" <% if (ctx.detail.readOnly) { %>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" id="psb-qty" class="form-control" value="<%- ctx.detail.decimal.qty %>" org="<%- ctx.detail.decimal.qty %>" min="0" max="6" <% if (ctx.detail.readOnly) { %>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" id="psb-tp" class="form-control" value="<%- ctx.detail.decimal.tp %>" org="<%- ctx.detail.decimal.tp %>" min="0" max="6" <% if (ctx.detail.readOnly) { %>disabled<% } %>>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                <% if (!ctx.detail.readOnly) { %>
+                <button type="button" class="btn btn-sm btn-primary" id="psb-decimal-ok">确认</button>
+                <% } %>
+            </div>
+        </div>
+    </div>
 </div>

+ 3 - 0
sql/update.sql

@@ -8,3 +8,6 @@ ALTER TABLE `zh_sub_project_info`
 ADD COLUMN `reply_land`  varchar(20) NOT NULL DEFAULT '' COMMENT '批复用地' AFTER `quake_peak_value`,
 ADD COLUMN `occupy_land`  varchar(20) NOT NULL DEFAULT '' COMMENT '永久占用土地' AFTER `reply_land`,
 ADD COLUMN `demolish_building`  varchar(20) NOT NULL DEFAULT '' COMMENT '实际拆迁房屋' AFTER `occupy_land`;
+
+ALTER TABLE `zh_payment_detail`
+ADD COLUMN `decimal`  varchar(100) NOT NULL DEFAULT '{"tp":2, "up": 2, "qty": 3}' COMMENT '小数位数' AFTER `in_time`;