소스 검색

修改高原取费时,自动计算所有材料

zhangweicheng 5 년 전
부모
커밋
e663a67042
3개의 변경된 파일33개의 추가작업 그리고 14개의 파일을 삭제
  1. 2 1
      web/building_saas/main/js/models/fee_rate.js
  2. 27 9
      web/building_saas/main/js/models/project_glj.js
  3. 4 4
      web/building_saas/main/js/views/fee_rate_view.js

+ 2 - 1
web/building_saas/main/js/models/fee_rate.js

@@ -213,7 +213,7 @@ var FeeRate = {
            this.onFeeRatesChange([{rateID:rateID,value:value}]);
            this.onFeeRatesChange([{rateID:rateID,value:value}]);
         };
         };
 
 
-        FeeRate.prototype.onFeeRatesChange = function (infos) {//{rateID:'AAAA',value:23}
+        FeeRate.prototype.onFeeRatesChange =async function (infos) {//{rateID:'AAAA',value:23}
             let node = project.mainTree.selected;
             let node = project.mainTree.selected;
             let me = this;
             let me = this;
             let rateMap = {};
             let rateMap = {};
@@ -227,6 +227,7 @@ var FeeRate = {
                     calcProgramObj.refreshCalcProgram(node, 3);
                     calcProgramObj.refreshCalcProgram(node, 3);
                 }
                 }
             }
             }
+            await project.projectGLJ.calcAllWhenFeeRateChange();
             project.calcProgram.calcAllNodesAndSave(calcAllType.catAll,function () {
             project.calcProgram.calcAllNodesAndSave(calcAllType.catAll,function () {
                 $.bootstrapLoading.start();
                 $.bootstrapLoading.start();
                 project.markUpdateProject({projectID:project.ID(),feeRateID:me.getActivateFeeRateFileID()},"feeRate",function () {
                 project.markUpdateProject({projectID:project.ID(),feeRateID:me.getActivateFeeRateFileID()},"feeRate",function () {

+ 27 - 9
web/building_saas/main/js/models/project_glj.js

@@ -336,7 +336,7 @@ ProjectGLJ.prototype.updateCalcMaterial =async function (projectGLJ,updateField,
     }
     }
 };
 };
 
 
-ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生改变时重算所有计算材料的价格
+ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs,isFromFeeRate) {//当材料发生改变时重算所有计算材料的价格
     let priceMap = {};
     let priceMap = {};
     for(let unitPrice of unitPriecs){
     for(let unitPrice of unitPriecs){
         if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
         if(unitPrice && gljUtil.isDef(unitPrice.doc.market_price)) priceMap[unitPrice.projectGLJID] = unitPrice.doc.market_price;
@@ -347,6 +347,9 @@ ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生
     let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
     let sumOriginalUpdateMap = {};//存放所有材料下的原价更新信息;
 
 
     for(let g of this.datas.gljList){
     for(let g of this.datas.gljList){
+        if(g.code == "2001001"){
+          console.log("calcMat")
+        }
         if(g.quantity !== 0 && g.quantity !== '0'  && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
         if(g.quantity !== 0 && g.quantity !== '0'  && g.unit_price.calcMaterial == 1&&!priceMap[g.id]){//工料机本身不包含在要计算的列表内
             //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
             //先判断要不要重算,只有包含相关工料机的定额的材料,才需要重新计算
             let fOrPDataMap = {};
             let fOrPDataMap = {};
@@ -371,7 +374,7 @@ ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生
             if(originalListMap[tIndex]){ //运费重算
             if(originalListMap[tIndex]){ //运费重算
                 let originalUpdateMap = {};
                 let originalUpdateMap = {};
                 for(let o of originalListMap[tIndex]){
                 for(let o of originalListMap[tIndex]){
-                    let calo = ifNeedReCalc(o,priceMap);
+                    let calo = ifNeedReCalc(o,priceMap,isFromFeeRate);
                     if(calo){
                     if(calo){
                         let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
                         let o_task = this.calcEachFreightOrPrice(o,"price",priceMap);
                         if(o_task){
                         if(o_task){
@@ -402,8 +405,9 @@ ProjectGLJ.prototype.calcAllMaterial = function (unitPriecs) {//当材料发生
     return [unitPriecs,sumUpdateMap];
     return [unitPriecs,sumUpdateMap];
 
 
 
 
-    function ifNeedReCalc(obj,IDMap) {
+    function ifNeedReCalc(obj,IDMap,isFromFeeRate = false) {
         let calcf = false;
         let calcf = false;
+        if(isFromFeeRate == true) return true;//如果是从费率过来的,默认自动计算
         if(obj.ration_gljs){
         if(obj.ration_gljs){
             for(let rg of  obj.ration_gljs){
             for(let rg of  obj.ration_gljs){
                 if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
                 if(IDMap[rg.projectGLJID]){//判断是否关联了该项目工料机
@@ -569,14 +573,14 @@ ProjectGLJ.prototype.priceCalc = function (glj,dataMap,tpriceList) {
 };
 };
 
 
 
 
-ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
+ProjectGLJ.prototype.m_updateUnitPrice = function (datas,isFromFeeRate) {//批量更新
     let me = this;
     let me = this;
     let gljList = [];
     let gljList = [];
     for(let d of datas){
     for(let d of datas){
         let g = updateUnit(d.projectGLJID,d);
         let g = updateUnit(d.projectGLJID,d);
         if(g) gljList.push(g);
         if(g) gljList.push(g);
     }
     }
-    this.calcQuantity();
+    if(isFromFeeRate == false)this.calcQuantity();
     //刷新项目工料机表显示
     //刷新项目工料机表显示
     projectGljObject.refreshDataSheet();
     projectGljObject.refreshDataSheet();
     //重新计算相关节点
     //重新计算相关节点
@@ -591,7 +595,7 @@ ProjectGLJ.prototype.m_updateUnitPrice = function (datas) {//批量更新
     //刷新定额工料机
     //刷新定额工料机
     gljOprObj.refreshView();
     gljOprObj.refreshView();
     //socket推送更新信息
     //socket推送更新信息
-    projectGljObject.onUnitFileChange(true);
+    projectGljObject.onUnitFileChange(isFromFeeRate?false:true);//如果是从更新费率过来的,不用在项目属性上做标记,费率那里已经自动计算所有节点了
 
 
 
 
     function updateUnit(id,unitPrice) {
     function updateUnit(id,unitPrice) {
@@ -724,14 +728,14 @@ ProjectGLJ.prototype.refreshEctrovalenceCache = function (updateMap) {
 };
 };
 
 
 
 
-ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap){
+ProjectGLJ.prototype.refreshMaterialCalcCache = function (updateMap,isFromFeeRate = false){//从费率计算过来的时候,费率那里已经做了自动计算所有节点了
    if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
    if(updateMap["freight"]) updateList(this.datas.freightList,updateMap["freight"]);
    if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
    if(updateMap["price"]) updateList(this.datas.originalList,updateMap["price"]);
    if(updateMap["unitPrice"]) {
    if(updateMap["unitPrice"]) {
       if(Array.isArray(updateMap["unitPrice"])){
       if(Array.isArray(updateMap["unitPrice"])){
-          this.m_updateUnitPrice(updateMap["unitPrice"]);
+          this.m_updateUnitPrice(updateMap["unitPrice"],isFromFeeRate);
       }else {
       }else {
-          this.m_updateUnitPrice([updateMap["unitPrice"]]);
+          this.m_updateUnitPrice([updateMap["unitPrice"]],isFromFeeRate);
       }
       }
    }
    }
 
 
@@ -811,6 +815,20 @@ ProjectGLJ.prototype.changeAssistProductionFeeRate = async function (newFeeRate)
     }
     }
 };
 };
 
 
+ProjectGLJ.prototype.calcAllWhenFeeRateChange = async function(){//当高原相关费率改变时,重新计算所有材料
+  try {
+    let [unitPrices,sumMap] = this.calcAllMaterial([],true);
+    if(unitPrices.length > 0){
+      sumMap["unitPrice"] = unitPrices;
+      let result = await ajaxPost('/glj/updateMaterialCalcTasks',sumMap);
+      this.refreshMaterialCalcCache(sumMap,true);
+      materialCalcObj.showDatas();
+    }
+}catch (err){
+    console.log(err);
+}
+}
+
 ProjectGLJ.prototype.loadFreightAndOriginalData = function(originalList,freightList){
 ProjectGLJ.prototype.loadFreightAndOriginalData = function(originalList,freightList){
   if(freightList) this.datas.freightList = freightList;
   if(freightList) this.datas.freightList = freightList;
   if(originalList) this.datas.originalList = originalList;
   if(originalList) this.datas.originalList = originalList;

+ 4 - 4
web/building_saas/main/js/views/fee_rate_view.js

@@ -528,7 +528,7 @@ var feeRateObject={
         }
         }
         if(updateDatas.length > 0){
         if(updateDatas.length > 0){
             $.bootstrapLoading.start();
             $.bootstrapLoading.start();
-            feeRate.updateFeeRatesByIDs(updateDatas,function () {
+            feeRate.updateFeeRatesByIDs(updateDatas,async function () {
                 let feerateInfo = [];
                 let feerateInfo = [];
                 for(let u of updateDatas){
                 for(let u of updateDatas){
                     let row = _.findIndex(me.mainFeeRateData,{'ID':u.rateID})
                     let row = _.findIndex(me.mainFeeRateData,{'ID':u.rateID})
@@ -540,7 +540,7 @@ var feeRateObject={
                         }
                         }
                     }
                     }
                 }
                 }
-                feerateInfo.length > 0 ?feeRate.onFeeRatesChange(feerateInfo):'';
+                feerateInfo.length > 0 ?await feeRate.onFeeRatesChange(feerateInfo):'';
                 $.bootstrapLoading.end();
                 $.bootstrapLoading.end();
             })
             })
         }
         }
@@ -638,7 +638,7 @@ var feeRateObject={
          }
          }
         if(updateDatas.length > 0){
         if(updateDatas.length > 0){
             $.bootstrapLoading.start();
             $.bootstrapLoading.start();
-            feeRate.updateFeeRatesByIDs(updateDatas,function () {
+            feeRate.updateFeeRatesByIDs(updateDatas,async function () {
                 let feerateInfo = [];
                 let feerateInfo = [];
                 for(let u of updateDatas){
                 for(let u of updateDatas){
                     feerateInfo.push({rateID:u.rateID,value:u.doc["rate"]});
                     feerateInfo.push({rateID:u.rateID,value:u.doc["rate"]});
@@ -646,7 +646,7 @@ var feeRateObject={
                 subRateObject.showSubRateData();
                 subRateObject.showSubRateData();
                 me.showMainFeeRateData();
                 me.showMainFeeRateData();
                 if(feerateInfo.length > 0){
                 if(feerateInfo.length > 0){
-                    feeRate.onFeeRatesChange(feerateInfo);
+                    await feeRate.onFeeRatesChange(feerateInfo);
                 }else {
                 }else {
                     $.bootstrapLoading.end();
                     $.bootstrapLoading.end();
                 }
                 }