فهرست منبع

实时更新tp_data

ellisran 1 سال پیش
والد
کامیت
4a6bd523a0
4فایلهای تغییر یافته به همراه38 افزوده شده و 7 حذف شده
  1. 3 0
      app/service/material.js
  2. 7 7
      app/service/material_audit.js
  3. 13 0
      app/service/material_bills.js
  4. 15 0
      app/service/material_exponent.js

+ 3 - 0
app/service/material.js

@@ -221,11 +221,14 @@ module.exports = app => {
                     // 修改现行价格指数,并返回调差基数json
                     const ex_calc = await this.ctx.service.materialExponent.updateNewMaterial(transaction, newMaterial.id, this.ctx, newMaterial.stage_id, preMaterial.ex_calc, JSON.parse(newMaterial.decimal));
                     // 计算得出本期总金额
+                    // 找出当前人并更新tp_data
+                    const tp_data = await this.ctx.service.materialAudit.getTpData(transaction, newMaterial.id, JSON.parse(newMaterial.decimal));
                     const updateMaterialData = {
                         id: newMaterial.id,
                         m_tp,
                         m_tax_tp,
                         ex_calc: JSON.stringify(ex_calc),
+                        tp_data: JSON.stringify(tp_data),
                     };
                     await transaction.update(this.tableName, updateMaterialData);
                     // 删除material_list表冗余数据,减少表数据量

+ 7 - 7
app/service/material_audit.js

@@ -204,14 +204,14 @@ module.exports = app => {
             return true;
         }
 
-        async getTpData(transaction, materialId) {
+        async getTpData(transaction, materialId, decimal = (this.ctx.material.decimal ? this.ctx.material.decimal : materialConst.decimal)) {
             const materialInfo = await transaction.get(this.ctx.service.material.tableName, { id: materialId });
             const tp_data = {
-                m_tp: materialInfo.m_tp !== null ? this.ctx.helper.round(materialInfo.m_tp, this.ctx.material.decimal.tp) : null,
+                m_tp: materialInfo.m_tp !== null ? this.ctx.helper.round(materialInfo.m_tp, decimal.tp) : null,
                 tax_tp: materialInfo.material_tax ? (materialInfo.m_tax_tp ? materialInfo.m_tax_tp : materialInfo.m_tp) :
-                    (materialInfo.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), this.ctx.material.decimal.tp) : null),
-                ex_tp: materialInfo.ex_tp !== null ? this.ctx.helper.round(materialInfo.ex_tp, this.ctx.material.decimal.tp) : null,
-                ex_tax_tp: materialInfo.ex_tp !== null ? this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.exponent_rate/100), this.ctx.material.decimal.tp) : null,
+                    (materialInfo.m_tp !== null ? this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), decimal.tp) : null),
+                ex_tp: materialInfo.ex_tp !== null ? this.ctx.helper.round(materialInfo.ex_tp, decimal.tp) : null,
+                ex_tax_tp: materialInfo.ex_tp !== null ? this.ctx.helper.round(this.ctx.helper.mul(materialInfo.ex_tp, 1+materialInfo.exponent_rate/100), decimal.tp) : null,
             }
             tp_data.total_tp = this.ctx.helper.add(tp_data.m_tp, tp_data.ex_tp);
             tp_data.total_tax_tp = !materialInfo.material_tax ? this.ctx.helper.add(tp_data.tax_tp, tp_data.ex_tax_tp) : tp_data.ex_tax_tp;
@@ -223,8 +223,8 @@ module.exports = app => {
                         id: ms.id,
                         sid: ms.sid,
                         order: ms.order,
-                        m_tp: this.ctx.helper.round(ms.m_tp, this.ctx.material.decimal.tp),
-                        m_tax_tp: this.ctx.helper.round(ms.m_tax_tp, this.ctx.material.decimal.tp),
+                        m_tp: this.ctx.helper.round(ms.m_tp, decimal.tp),
+                        m_tax_tp: this.ctx.helper.round(ms.m_tax_tp, decimal.tp),
                     });
                 }
                 tp_data.stage_tp = stage_tp;

+ 13 - 0
app/service/material_bills.js

@@ -775,6 +775,19 @@ module.exports = app => {
             //     updateData2.m_tax_tp = tp.tax_total_price;
             // }
             await transaction.update(this.ctx.service.material.tableName, updateData2);
+            // 找出当前人并更新tp_data
+            const tp_data = await this.ctx.service.materialAudit.getTpData(transaction, this.ctx.material.id);
+            if (this.ctx.material.status === auditConst.status.uncheck || this.ctx.material.status === auditConst.status.checkNo) {
+                await transaction.update(this.ctx.service.material.tableName, {
+                    id: this.ctx.material.id,
+                    tp_data: JSON.stringify(tp_data),
+                });
+            } else if (this.ctx.material.curAuditor) {
+                await transaction.update(this.ctx.service.materialAudit.tableName, {
+                    id: this.ctx.material.curAuditor.id,
+                    tp_data: JSON.stringify(tp_data),
+                });
+            }
             return tp.total_price;
         }
 

+ 15 - 0
app/service/material_exponent.js

@@ -220,6 +220,21 @@ module.exports = app => {
                 ex_expr: expr,
             });
             console.log(ex_tp, expr);
+            if (!mid) {
+                // 找出当前人并更新tp_data
+                const tp_data = await this.ctx.service.materialAudit.getTpData(transaction, this.ctx.material.id);
+                if (this.ctx.material.status === auditConst.status.uncheck || this.ctx.material.status === auditConst.status.checkNo) {
+                    await transaction.update(this.ctx.service.material.tableName, {
+                        id: this.ctx.material.id,
+                        tp_data: JSON.stringify(tp_data),
+                    });
+                } else if (this.ctx.material.curAuditor) {
+                    await transaction.update(this.ctx.service.materialAudit.tableName, {
+                        id: this.ctx.material.curAuditor.id,
+                        tp_data: JSON.stringify(tp_data),
+                    });
+                }
+            }
             return [ex_tp, expr];
         }