소스 검색

feat: 预付款当前未上报期金额随着小数数位的设置舍入后再存库

lanjianrong 4 년 전
부모
커밋
263ef6b5e3
4개의 변경된 파일34개의 추가작업 그리고 25개의 파일을 삭제
  1. 1 5
      app/controller/advance_controller.js
  2. 2 2
      app/public/js/advance_audit.js
  3. 6 16
      app/service/advance.js
  4. 25 2
      app/service/tender_info.js

+ 1 - 5
app/controller/advance_controller.js

@@ -145,10 +145,7 @@ module.exports = app => {
                 const max_pr = ctx.helper.mul(ctx.helper.div(ctx.helper.sub(advancePayTotal, (prevAdvance && prevAdvance.prev_total_amount || 0)), advancePayTotal, 10), 100);
                 // 特殊处理金额的显示(formatMoney)
                 const s1 = parseFloat(ctx.advance.prev_amount).toString().split('.')[1];
-                let s2 = parseFloat(ctx.advance.prev_total_amount).toString().split('.')[1];
-                if (isEdited) {
-                    s2 = parseFloat(ctx.advance.prev_total_amount.toFixed(this.decimal)).toString().split('.')[1];
-                }
+                const s2 = parseFloat(ctx.advance.prev_total_amount).toString().split('.')[1];
                 const prev_amount = ctx.helper.formatMoney(ctx.advance.prev_amount, ',', s1 && s1.length || 0);
                 const prev_total_amount = ctx.helper.formatMoney(ctx.advance.prev_total_amount, ',', s2 && s2.length || 0);
                 renderData.isEdited = isEdited;
@@ -173,7 +170,6 @@ module.exports = app => {
         async update(ctx) {
             const { id } = ctx.advance;
             const data = JSON.parse(ctx.request.body.data);
-            console.log('data', data);
             try {
                 const result = await ctx.service.advance.updateAdvance(data, id);
                 if (result) {

+ 2 - 2
app/public/js/advance_audit.js

@@ -160,7 +160,7 @@ $(document).ready(function () {
             return toastr.error('请填写本期金额!')
         }
         const prev_amount = prevAdvance && prevAdvance.prev_total_amount || 0
-        const prev_total_amount = parseFloat(ZhCalc.add(cur_amount, prev_amount).toFixed(decimal))
+        const prev_total_amount = ZhCalc.round(ZhCalc.add(cur_amount, prev_amount), decimal)
         const remark = filterText($('#ad-remark').val())
         const data = {pay_ratio, cur_amount, prev_amount, prev_total_amount, remark, status: auditConst.status.checking}
         postData(preUrl + '/audit/start', data, (data) => {
@@ -219,7 +219,7 @@ $(document).ready(function () {
             // 支付比例转化
             $(this).val(fixedToSub(val)) // 重新赋值限制只有两位小数
             const cur_m_input = $(`.pay-input[data-type=${reverse(type)}]`)
-            cur_amount = ZhCalc.mul(advancePayTotal, ZhCalc.div(val, 100))
+            cur_amount = ZhCalc.round(ZhCalc.mul(advancePayTotal, ZhCalc.div(val, 100)), decimal)
             pay_ratio = val
             cur_m_input.val(parseFloat(cur_amount.toFixed(decimal)))
             const total = parseFloat(ZhCalc.add(cur_amount, p_amount).toFixed(decimal)).toString().split('.')[1]

+ 6 - 16
app/service/advance.js

@@ -36,21 +36,12 @@ module.exports = app => {
             const advance = await this.db.query(sql, sqlParam);
             for (const item of advance) {
                 item.pay_ratio = this.ctx.helper.mul(this.ctx.helper.div(item.cur_amount, advancePayTotal), 100, 2) || 0;
-                if (item.status === auditConst.status.uncheck || item.status === auditConst.status.checkNo) {
-                    const s1 = item.cur_amount && parseFloat(item.cur_amount.toFixed(decimal)).toString().split('.')[1];
-                    const s2 = parseFloat(item.prev_amount).toString().split('.')[1];
-                    const s3 = parseFloat(item.prev_total_amount.toFixed(decimal)).toString().split('.')[1];
-                    item.cur_amount = this.ctx.helper.formatMoney(item.cur_amount, ',', s1 && s1.length || 0);
-                    item.prev_amount = this.ctx.helper.formatMoney(item.prev_amount, ',', s2 && s2.length || 0);
-                    item.prev_total_amount = this.ctx.helper.formatMoney(item.prev_total_amount, ',', s3 && s3.length || 0);
-                } else {
-                    const s1 = item.cur_amount.toString().split('.')[1] && item.cur_amount.toString().split('.')[1].length;
-                    const s2 = item.prev_amount.toString().split('.')[1] && item.prev_amount.toString().split('.')[1].length;
-                    const s3 = item.prev_total_amount.toString().split('.')[1] && item.prev_total_amount.toString().split('.')[1].length;
-                    item.cur_amount = this.ctx.helper.formatMoney(item.cur_amount, ',', s1 || 0);
-                    item.prev_amount = this.ctx.helper.formatMoney(item.prev_amount, ',', s2 || 0);
-                    item.prev_total_amount = this.ctx.helper.formatMoney(item.prev_total_amount, ',', s3 || 0);
-                }
+                const s1 = item.cur_amount && item.cur_amount.toString().split('.')[1];
+                const s2 = item.prev_amount.toString().split('.')[1];
+                const s3 = item.prev_total_amount.toString().split('.')[1];
+                item.cur_amount = this.ctx.helper.formatMoney(item.cur_amount, ',', s1 && s1.length || 0);
+                item.prev_amount = this.ctx.helper.formatMoney(item.prev_amount, ',', s2 && s2.length || 0);
+                item.prev_total_amount = this.ctx.helper.formatMoney(item.prev_total_amount, ',', s3 && s3.length || 0);
                 item.curAuditor = await this.ctx.service.advanceAudit.getAuditorByStatus(item.id, item.status, item.times);
                 if (item.status === auditConst.status.checkNoPre) {
                     item.curAuditor2 = await this.ctx.service.advanceAudit.getAuditorByStatus(item.id, auditConst.status.checking);
@@ -184,7 +175,6 @@ module.exports = app => {
             const prevRecord = await this.getPreviousRecord(ctx.tender.id, ctx.advance.type) || { prev_total_amount: 0 };
             const { cur_amount } = payload;
             payload.prev_total_amount = ctx.helper.add(cur_amount, prevRecord.prev_total_amount);
-            console.log(payload);
             return await this.update(payload, {
                 id,
             });

+ 25 - 2
app/service/tender_info.js

@@ -12,7 +12,7 @@ const infoConst = require('../const/tender_info');
 const parseInfo = infoConst.parseInfo;
 const arrayInfo = infoConst.arrayInfo;
 const defaultInfo = infoConst.defaultInfo;
-
+const advanceConst = require('../const/audit').advance;
 module.exports = app => {
 
     class TenderInfo extends app.BaseService {
@@ -202,8 +202,10 @@ module.exports = app => {
 
         async saveDecimal(tenderId, newDecimal, oldDecimal) {
             const changeBills = [],
+                changeAdvanceBills = [],
                 calcUp = newDecimal.up < oldDecimal.up,
-                calcTp = newDecimal.tp !== oldDecimal.tp;
+                calcTp = newDecimal.tp !== oldDecimal.tp,
+                caclPayTp = (newDecimal.pay ? newDecimal.payTp : newDecimal.tp) < (oldDecimal.pay ? oldDecimal.payTp : oldDecimal.tp);
             if (calcUp || calcTp) {
                 const bills = await this.ctx.service.ledger.getAllDataByCondition({
                     columns: ['id', 'unit_price', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'deal_qty', 'quantity'],
@@ -220,12 +222,29 @@ module.exports = app => {
                     changeBills.push(cb);
                 }
             }
+            if (caclPayTp) {
+                // 获取预付款需要修改的相关记录
+                const ad_bills = await this.ctx.service.advance.getAllDataByCondition({
+                    columns: ['id', 'cur_amount', 'prev_amount', 'prev_total_amount'],
+                    where: { status: [advanceConst.status.uncheck, advanceConst.status.checkNo], tid: tenderId },
+                });
+                const decimal = newDecimal.pay ? newDecimal.payTp : newDecimal.tp;
+                // 根据精度重新计算相关金额
+                for (const ad of ad_bills) {
+                    const cb = { id: ad.id };
+                    cb.cur_amount = this.ctx.helper.round(ad.cur_amount, decimal);
+                    cb.prev_total_amount = this.ctx.helper.round(this.ctx.helper.add(ad.cur_amount, ad.prev_amount), decimal);
+                    changeAdvanceBills.push(cb);
+                }
+            }
             if (changeBills.length > 0) {
                 const transaction = await this.db.beginTransaction();
                 try {
                     await transaction.update(this.tableName,
                         { decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
                     await transaction.updateRows(this.ctx.service.ledger.tableName, changeBills);
+
+                    // await transaction.updateRows(this.ctx.service.advance.tableName, changeAdvanceBills);
                     await transaction.commit();
                 } catch (error) {
                     await transaction.rollback();
@@ -235,6 +254,10 @@ module.exports = app => {
                 await this.db.update(this.tableName,
                     { decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
             }
+            // 更新预付款记录
+            if (changeAdvanceBills.length) {
+                await this.db.updateRows(this.ctx.service.advance.tableName, changeAdvanceBills);
+            }
         }
     }