浏览代码

独立单价调差公式区分出来单独设置

laiguoran 2 年之前
父节点
当前提交
60f1aa1f3d
共有 4 个文件被更改,包括 52 次插入24 次删除
  1. 4 3
      app/public/js/material.js
  2. 41 21
      app/service/material_bills.js
  3. 2 0
      app/service/material_stage_bills.js
  4. 5 0
      sql/update.sql

+ 4 - 3
app/public/js/material.js

@@ -1326,7 +1326,7 @@ $(document).ready(() => {
                 toastr.error(msg);
                 return false;
             }
-            postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr }, function (result) {
+            postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
                 m_tp = result.m_tp;
                 if (materialTax) {
                     m_tax_tp = result.m_tax_tp;
@@ -1334,13 +1334,14 @@ $(document).ready(() => {
 
                 const sheet = materialSpread.getActiveSheet();
                 const select = SpreadJsObj.getSelectObject(sheet);
+                delete select.waitingLoading;
                 const index = materialBillsData.indexOf(select);
-                console.log(select, index, result.info);
+                // console.log(materialBillsData, select, index, result.info);
                 let newIndex = index;
                 if (isStageSelf) {
                     materialSpreadObj.updateMaterialData(result);
                     result.info = materialSpreadObj.updateOneMaterialBill(result.info);
-                    console.log(result.info);
+                    // console.log(result.info);
                 }
                 if($('#bills0_list').is(':checked')) {
                     const newMaterialBillsData = _.filter(materialBillsData, function (item) {

+ 41 - 21
app/service/material_bills.js

@@ -525,30 +525,50 @@ module.exports = app => {
                 const returnData = {};
                 returnData.m_tp = this.ctx.material.m_tp;
                 if (this.ctx.material.is_stage_self) {
+                    if (!data.ms_id) throw '参数有误';
                     const mbInfo = await this.getDataById(data.id);
-                    let all_m_tp = 0;
-                    let all_tax_tp = 0;
-                    for (const sid of this.ctx.material.stage_id.split(',')) {
-                        const materialCalculator = new MaterialCalculator(this.ctx, sid, this.ctx.tender.info);
-                        const quantity = await materialCalculator.calculateExpr(data.expr);
-                        const msInfo = await this.ctx.service.materialStage.getDataByCondition({ mid: this.ctx.material.id, sid });
-                        const msbInfo = await this.ctx.service.materialStageBills.getDataByCondition({ mid: this.ctx.material.id, mb_id: data.id, ms_id: msInfo.id });
-                        const newQuantity = quantity !== 0 ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null;
-                        const m_tp = newQuantity ? this.ctx.helper.round(this.ctx.helper.mul(newQuantity, msbInfo.m_spread), this.ctx.material.decimal.tp) : null;
-                        const updateData = {
-                            id: data.id,
-                            quantity: newQuantity,
-                            m_tp,
-                            m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
-                        };
-                        const [one_bill_m_tp, one_bill_tax_tp] = await this.ctx.service.materialStageBills.update(transaction, updateData, msInfo.id);
-                        await this.ctx.service.materialStage.updateMtp(transaction, msInfo.id);
-                        all_m_tp = this.ctx.helper.round(one_bill_m_tp, this.ctx.material.decimal.tp);
-                        all_tax_tp = this.ctx.helper.round(one_bill_tax_tp, this.ctx.material.decimal.tp);
-                    }
-                    const updateBillsData = {
+                    const msInfo = await this.ctx.service.materialStage.getDataById(data.ms_id);
+                    const msbInfo = await this.ctx.service.materialStageBills.getDataByCondition({ mid: this.ctx.material.id, mb_id: data.id, ms_id: data.ms_id });
+                    // let all_m_tp = 0;
+                    // let all_tax_tp = 0;
+                    const materialCalculator = new MaterialCalculator(this.ctx, msInfo.sid, this.ctx.tender.info);
+                    const quantity = await materialCalculator.calculateExpr(data.expr);
+                    const newQuantity = quantity !== 0 ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null;
+                    const m_tp = newQuantity ? this.ctx.helper.round(this.ctx.helper.mul(newQuantity, msbInfo.m_spread), this.ctx.material.decimal.tp) : null;
+                    const updateData = {
                         id: data.id,
+                        quantity: newQuantity,
                         expr: data.expr,
+                        m_tp,
+                        m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
+                    };
+                    const [one_bill_m_tp, one_bill_tax_tp] = await this.ctx.service.materialStageBills.update(transaction, updateData, msInfo.id);
+                    await this.ctx.service.materialStage.updateMtp(transaction, msInfo.id);
+                    const all_m_tp = this.ctx.helper.round(one_bill_m_tp, this.ctx.material.decimal.tp);
+                    const all_tax_tp = this.ctx.helper.round(one_bill_tax_tp, this.ctx.material.decimal.tp);
+
+                    // for (const sid of this.ctx.material.stage_id.split(',')) {
+                    //     const materialCalculator = new MaterialCalculator(this.ctx, sid, this.ctx.tender.info);
+                    //     const quantity = await materialCalculator.calculateExpr(data.expr);
+                    //     const msInfo = await this.ctx.service.materialStage.getDataByCondition({ mid: this.ctx.material.id, sid });
+                    //     const msbInfo = await this.ctx.service.materialStageBills.getDataByCondition({ mid: this.ctx.material.id, mb_id: data.id, ms_id: msInfo.id });
+                    //     const newQuantity = quantity !== 0 ? this.ctx.helper.round(quantity, this.ctx.material.decimal.qty) : null;
+                    //     const m_tp = newQuantity ? this.ctx.helper.round(this.ctx.helper.mul(newQuantity, msbInfo.m_spread), this.ctx.material.decimal.tp) : null;
+                    //     const updateData = {
+                    //         id: data.id,
+                    //         quantity: newQuantity,
+                    //         m_tp,
+                    //         m_tax_tp: this.ctx.helper.round(this.ctx.helper.mul(m_tp, (1 + this.ctx.helper.div(mbInfo.m_tax, 100))), this.ctx.material.decimal.tp),
+                    //     };
+                    //     const [one_bill_m_tp, one_bill_tax_tp] = await this.ctx.service.materialStageBills.update(transaction, updateData, msInfo.id);
+                    //     await this.ctx.service.materialStage.updateMtp(transaction, msInfo.id);
+                    //     all_m_tp = this.ctx.helper.round(one_bill_m_tp, this.ctx.material.decimal.tp);
+                    //     all_tax_tp = this.ctx.helper.round(one_bill_tax_tp, this.ctx.material.decimal.tp);
+                    // }
+
+                    const updateBillsData = {
+                        id: data.id,
+                        // expr: data.expr,
                         m_tp: all_m_tp ? all_m_tp : null,
                         m_tax_tp: all_tax_tp ? all_tax_tp : null,
                     };

+ 2 - 0
app/service/material_stage_bills.js

@@ -59,6 +59,7 @@ module.exports = app => {
                     const oneBillsData = {
                         id: mb.id,
                         quantity: null,
+                        expr: null,
                         msg_tp: null,
                         msg_times: null,
                         msg_spread: newmsg_spread,
@@ -168,6 +169,7 @@ module.exports = app => {
                 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, decimal.qty), newm_spread), decimal.tp) : null;
                 msb.quantity = quantity !== 0 && quantity !== null ? this.ctx.helper.round(quantity, decimal.qty) : null;
+                msb.expr = mb.expr;
                 msb.msg_spread = newmsg_spread;
                 msb.m_spread = newm_spread;
                 msb.m_tp = newTp;

+ 5 - 0
sql/update.sql

@@ -0,0 +1,5 @@
+ALTER TABLE `zh_material_stage_bills` ADD `expr` VARCHAR(1000) NULL DEFAULT NULL COMMENT '表达式' AFTER `quantity`;
+-- 同步旧数据
+UPDATE `zh_material_stage_bills` a, `zh_material_bills` b SET a.`expr`= b.`expr` WHERE a.`mb_id` = b.`id`;
+
+UPDATE `zh_material_bills` a, `zh_material` b SET a.`expr`= null WHERE a.`mid` = b.`id` AND t_type = 2 AND b.`is_stage_self` = 1;