浏览代码

分摊更新

zhangweicheng 5 年之前
父节点
当前提交
29b5cf2bc3

+ 20 - 2
modules/main/facade/ration_facade.js

@@ -107,10 +107,9 @@ async function updateDivideRation(data,compilation){
         case "add":
             result = await addDivideRation(data,compilation);
             break;
-        case "delete":
-            result = await deleteDivideRation(data);
         case "update":
             result = await modifyDivideRation(data,compilation);
+            break;
     }
     return result;
 }
@@ -177,6 +176,25 @@ async function addDivideRation(data,compilation){
   return{ration:newRation,ration_gljs:ration_gljs,projectGLJList:projectGLJList,ration_coes};
 }
 
+async function modifyDivideRation(data,compilation){//目前只有替换分摊的定额走这个逻辑
+  let [newRation,ration_gljs,projectGLJList,ration_coes] = await getNewMaterialRationDatas(data,compilation,true);
+  newRation.quantity = data.oldData.quantity;
+  newRation.type=1;
+  newRation.itemType = "定额";
+  newRation.programID = data.oldData.programID; 
+  newRation.seq = data.oldData.seq;
+  newRation.ParentID = data.oldData.ParentID;
+  await divideModel.update({ID:data.ID},{$push:{divideList:newRation,ration_gljs:{$each:ration_gljs},ration_coes:{$each:ration_coes}}});
+  await divideModel.update(
+    {ID:data.ID},
+    { 
+      $pull: {divideList:{ID:data.rationID},ration_gljs:{rationID:data.rationID},ration_coes:{rationID:data.rationID}}
+    },
+    { multi: true })
+    return {ration:newRation,ration_gljs:ration_gljs,projectGLJList:projectGLJList,ration_coes}
+}
+
+
 async function getNewMaterialRationDatas(data,compilation,withCoe = false){
     let searchDao = new SearchDao();
     let stdRation = await searchDao.getRationItem(data.userID, compilation._id, data.rationRepIds,data.code);

+ 74 - 1
web/building_saas/main/html/divide.html

@@ -1,6 +1,6 @@
 <div class="toolsbar d-flex px-1 justify-content-between" id="divideToolsBar">
   <div class="form-inline py-1">
-      <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#exe_divide">执行分摊</a>
+      <a class="btn btn-sm ml-1" href="#" id = "exec_divide_btn" >执行分摊</a>
       <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#cancel_divide"> 取消分摊</a></label>
       <a class="btn btn-sm ml-1" href="#" data-toggle="modal" data-target="#cancel_all_divide"> 取消所有分摊</a></label>
   </div>
@@ -118,4 +118,77 @@
         </div>
         </div>
   </div>
+</div>
+
+<!--弹出 执行分摊-->
+<div class="modal fade" id="exec_divide_div" data-backdrop="static">
+  <div class="modal-dialog modal-lg" style="max-width: 1100px" role="document">
+      <div class="modal-content" style="width: 1100px">
+          <div class="modal-header">
+              <h5 class="modal-title">执行分摊</h5>
+              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                  <span aria-hidden="true">&times;</span>
+              </button>
+          </div>
+          <div class="modal-body">
+            <label>混凝土拌合站建设费分摊到:</label>
+              <div class="row" style="height:400px;border-top: 1px solid #ccc;"><!--sjs id设置在这个div-->
+                  <div style="overflow: hidden; width: 100%;" id="billSelectedSheet" > </div>
+              </div>
+              <div class="row" style="height:250px"><!--sjs id设置在这个div-->
+                  <div style="overflow: hidden; width: 100%" id="execBillSheet"></div>
+              </div>
+          </div>
+          <div class="modal-footer" style="justify-content: left;">
+            <div class=" col-10" style="overflow: hidden" id="install_setting">
+              <div >
+                  <!--<div class="setting_title">整个项目统一计取</div>-->
+                  <fieldset class="form-group"  style="border:1px solid #b3b3b3;padding: 15px">
+                      <legend class="legend" >分摊方式:</legend>
+                      <div class=" row" style="margin-left: 10px;">
+                        <div class=" col-6">
+                          <label class="form-check-label">
+                            <input class="form-check-input" name="divide_type" id="divide_by_bills" value="0" type="radio">
+                            按清单金额分摊
+                        </label>
+                        </div>
+                         <div class=" col-6">
+                          <label class="form-check-label">
+                              <input class="form-check-input" name="divide_type" id="divide_by_concrete" value="1" type="radio">
+                              按混凝土用量分摊
+                          </label>
+                        </div>
+                        <div class=" col-6">
+                          <label class="form-check-label">
+                            <input class="form-check-input" name="divide_type" id="divide_by_customer" value="2" type="radio">
+                            自定义分摊比例
+                        </label>
+                        </div>
+                      </div>
+                     <!--  <div class="form-check col-6">
+                          <label class="form-check-label">
+                              <input class="form-check-input" name="install_setting_radios" id="all_project_calc" value="0" type="radio">
+                              整个项目统一计取
+                          </label>
+                      </div>
+                      <div class="form-check col-6">
+                          <label class="form-check-label">
+                              <input class="form-check-input" name="install_setting_radios" id="FB_calc" value="1" type="radio">
+                              每个分部单独计取
+                          </label>
+                      </div>
+                      <div class="form-check col-6">
+                        <label class="form-check-label">
+                            <input class="form-check-input" name="install_setting_radios" id="FB_calc" value="1" type="radio">
+                            每个分部单独计取
+                        </label>
+                    </div> -->
+                  </fieldset>
+              </div>
+          </div>
+              <button  class="btn btn-primary" id="calc_installation_fee_confirm">确定</button>
+              <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+          </div>
+      </div>
+  </div>
 </div>

+ 149 - 9
web/building_saas/main/js/views/divide_view.js

@@ -23,8 +23,36 @@ let divideObj = {
     },
     treeCol:1
   },
+  billsSelectedSetting:{
+    header: [
+      {headerName: "选择", headerWidth: 50, dataCode: "selected", hAlign:'left',cellType:'checkBox'},
+      {headerName: "清单编号", headerWidth: 160, dataCode: "code", hAlign:'left', dataType: "String"},
+      {headerName: "名称", headerWidth: 300, dataCode: "name", dataType: "String"},
+      {headerName: "单位", headerWidth: 60, dataCode: "unit", hAlign:'center'},
+      {headerName: "工程量", headerWidth: 100, dataCode: "quantity", dataType: "Number",validator:"number"},
+      {headerName: "单价", headerWidth: 100, dataCode: "unitFee", dataType: "Number",validator:"number"},
+      {headerName: "金额", headerWidth: 100, dataCode: "totalFee", dataType: "Number",validator:"number"},
+      {headerName: "不可分摊", headerWidth: 80, dataCode: "unDivide", dataType: "Number",cellType:'checkBox'}
+    ],
+    view:{ 
+      lockColumns: [0,1,2,3,4,5,6],
+      colHeaderHeight:30
+    },
+    treeCol:1
+  },
+  execBillsSetting:{
+    header: [
+      {headerName: "清单编号", headerWidth: 180, dataCode: "code", hAlign:'left', dataType: "String"},
+      {headerName: "名称", headerWidth: 260, dataCode: "name", dataType: "String"},
+      {headerName: "分摊比例", headerWidth: 100, dataCode: "divideRate", dataType: "Number",validator:"number"}
+    ],
+    view:{ 
+      lockColumns: [0,1,2],
+      colHeaderHeight:30
+    }
+  },
   billsSetting:{
-    header: [//“编号”、“名称”、“分摊比例”、“分摊金额”、“原始金额”、“合计”、“金额”。
+    header: [
       {headerName: "编号", headerWidth: 130, dataCode: "code", hAlign:'left', dataType: "String"},
       {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
       {headerName: "分摊比例", headerWidth: 80, dataCode: "divideRate", dataType: "Number",validator:"number"},
@@ -53,10 +81,31 @@ let divideObj = {
       disableSpread(this.billsSpread);
     }
   },
+  initExecSpread:function(){
+    if(this.billsSelectedSpread) return;
+    this.billsSelectedSpread = SheetDataHelper.createNewSpread($("#billSelectedSheet")[0]);
+    sheetCommonObj.spreadDefaultStyle(this.billsSelectedSpread);
+    this.billsSelectedSheet = this.billsSelectedSpread.getSheet(0);
+    sheetCommonObj.initSheet(this.billsSelectedSheet, this.billsSelectedSetting);
+    // this.billsSelectedSheet.bind(GC.Spread.Sheets.Events.EditStarting,this.onDivideEditStarting);
+    // this.billsSelectedSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onDivideValueChange)
+    // this.billsSelectedSheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onDivideSelectionChange);  
+    this.execBillsSpread = SheetDataHelper.createNewSpread($("#execBillSheet")[0]);
+    sheetCommonObj.spreadDefaultStyle(this.execBillsSpread);
+    this.execBillsSheet = this.execBillsSpread.getSheet(0);
+    sheetCommonObj.initSheet(this.execBillsSheet, this.execBillsSetting);
+
+    SheetDataHelper.protectdSheet(this.billsSelectedSheet);
+    SheetDataHelper.protectdSheet(this.execBillsSheet);
+  },
   showDatas:function(){
     this.showDivideDatas();
     this.showBillsDatas();
     this.showRationGLJDatas();
+    this.showCalcProgramDatas();
+  },
+  showExecDatas:function(){
+    this.showSelectedBillsDatas();
   },
   refreshViews:function(){
     if(!$('#divide_main').is(':visible')) return;
@@ -115,9 +164,55 @@ let divideObj = {
   showCalcProgramDatas:function(){
     if(!$('#divede_calc_nav').hasClass('active')) return;
     this.divideSubSpread.setActiveSheetIndex(1);
-    //this.rationGLJDatas = getTreeRationGLJDatas();
+    let selected = divideObj.getSelectedItem();
+    if(selected.itemType == "分摊项"){
+      selected = this.calcBills(selected);
+    }else{
+      projectObj.project.calcProgram.innerCalcRation({data:selected, sourceType:"ration", calcType: 1, updateData:[]});
+    }
+    let datas = selected.calcTemplate ? selected.calcTemplate.calcItems : [];
+    sheetCommonObj.initSheet(this.calcProgramSheet, calcProgramObj.setting, datas.length);
+    sheetCommonObj.showData(this.calcProgramSheet, calcProgramObj.setting, datas);
+    customRowHeader(this.calcProgramSheet, datas.length);
   },
+  showSelectedBillsDatas:function(){
+    
+    this.selectedBillsDatas = getSelectedBillsDatas();
+    this.billsSelectedSheet.setRowCount(this.selectedBillsDatas.length);
+    sheetCommonObj.showTreeData(this.billsSelectedSheet, this.billsSelectedSetting,this.selectedBillsDatas);
+
+    function getSelectedBillsDatas(){
+      let datas = [];
+      for(let n of projectObj.project.mainTree.roots){
+        getDatas(n)
+      }
+      return datas;
+      function getDatas(node){
+        if(node.sourceType == "ration") return;
+        let d = node.data;
+        let t = {
+          selected:0,
+          ID:d.ID,
+          code:d.code,
+          name:d.name,
+          unit:d.unit,
+          quantity:d.quantity,
+          unitFee:d.feesIndex && d.feesIndex.common && d.feesIndex.common.unitFee > 0?d.feesIndex.common.unitFee:"",
+          totalFee:d.feesIndex && d.feesIndex.common && d.feesIndex.common.totalFee>0?d.feesIndex.common.totalFee:"",
+          ParentID:d.ParentID,
+          unDivide:0,
+          collapsed:false
+        };
+        datas.push(t);
+        if(!node.children) return;
+        for(let c of node.children){
+          getDatas(c);
+        }
+
+      }
 
+    }
+  },
   showRationGLJDatas:function(){
     if(!$('#divide_glj_nav').hasClass('active')) return;
     this.divideSubSpread.setActiveSheetIndex(0);
@@ -426,11 +521,13 @@ let divideObj = {
     let sel = this.divideSheet.getSelections()[0];
     await this.updateDivideRation(data);
     this.divideSheet.setSelection(sel.row+1,sel.col,sel.rowCount,sel.colCount);
+    this.showRationGLJDatas();
+    this.showCalcProgramDatas();
 
   },
   updateDivideRation:async function(data){
     let divideSetting =  projectObj.project.divide_setting.datas;
-    let newRation = data;
+    let newRation = null;
     try {
       $.bootstrapLoading.start();
       let result = await ajaxPost("/ration/updateDivideRation",data)
@@ -441,13 +538,22 @@ let divideObj = {
         if(result.projectGLJList) projectObj.project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);   
         if(result.ration_gljs) divideSetting.ration_gljs = divideSetting.ration_gljs.concat(result.ration_gljs);
         if(result.ration_coes) divideSetting.ration_coes = divideSetting.ration_coes.concat(result.ration_coes);
-      } 
-      await this.calcDivideItem(newRation);
+      }else if(data.type == "update"){//这里只有替换定额用到
+        newRation = result.ration;
+        divideSetting.divideList.push(newRation);
+        if(result.projectGLJList) projectObj.project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);   
+        if(result.ration_gljs) divideSetting.ration_gljs = divideSetting.ration_gljs.concat(result.ration_gljs);
+        if(result.ration_coes) divideSetting.ration_coes = divideSetting.ration_coes.concat(result.ration_coes);
+        _.remove(divideSetting.divideList,{'ID':data.rationID});
+        _.remove(divideSetting.ration_gljs,{'rationID':data.rationID});
+        _.remove(divideSetting.ration_coes,{'rationID':data.rationID});
+      }
+      await this.calcDivideItem(newRation);   
     } catch (error) {
       console.log(error)
+      this.showDatas();
     }
     $.bootstrapLoading.end();
-    //this.showDatas();
   },
   calcDivideItem:async function(divide){
     let updateDatas = [];
@@ -519,7 +625,7 @@ let divideObj = {
     let me = divideObj,row = info.row, col = info.col;
     let setting = me.divideSetting;
     let dataCode = setting.header[col].dataCode;
-    let recode = me.divideDatas[row];
+    let record = me.divideDatas[row];
     let value = info.newValue;
     if(info.newValue === undefined ){
       return;
@@ -528,9 +634,31 @@ let divideObj = {
         alert('输入的数据类型不对,请重新输入!');
         return me.showDatas();
     }
-    await me.updateItem([me.getDivideUpdateData(recode,dataCode,value)]);
-    await me.calcDivideItem(recode);
+    if(record.itemType=="定额" && dataCode == "code"){//替换定额
+      await me.replaceDivideRation(value,record);
+      return;
+    }  
+    await me.updateItem([me.getDivideUpdateData(record,dataCode,value)]);
+    await me.calcDivideItem(record);
   },
+  replaceDivideRation:async function(code,record){
+    let divideSetting =  projectObj.project.divide_setting.datas;
+    let data = {ID:divideSetting.ID,type:"update",rationID:record.ID,code:code};
+    let libIDs = rationLibObj.getStdRationLibIDs();
+    let defaultLibID = rationLibObj.getDefaultStdRationLibID();
+    let selectedLib =  sessionStorage.getItem("stdRationLib");
+    selectedLib&&selectedLib!='undefined'?libIDs.unshift(selectedLib):libIDs.unshift(defaultLibID);
+    data.userID = userID;
+    data.defaultLibID = defaultLibID;
+    data.rationRepIds = libIDs;
+    data.quantityDecimal = getDecimal("ration.quantity");
+    data.projectID = projectObj.project.ID();
+    data.oldData = record;
+    await this.updateDivideRation(data);
+
+  },
+
+
   onDivideSelectionChange:function(sender,args){
     let me = divideObj;
     let newSel = args.newSelections[0];
@@ -538,6 +666,7 @@ let divideObj = {
     if(newSel.row != oldSel.row){
       me.initNavItem();
       me.showRationGLJDatas();
+      me.showCalcProgramDatas();
     }
     args.sheet.repaint();
   },
@@ -938,7 +1067,18 @@ $('#divide_zmhs_toogle').bind('click',function (){
    $("#divide_zmhs_toogle").hide();
 });
 
+$('#exec_divide_btn').bind('click',function (){
+   if(projectReadOnly) return;
+  $("#exec_divide_div").modal('show');
+});
+
+
 $('#divideBottom ul li a').on('shown.bs.tab',function () {
   divideObj.showRationGLJDatas();
   divideObj.showCalcProgramDatas();
+});
+
+$('#exec_divide_div').on('shown.bs.modal',function () {
+  divideObj.initExecSpread();
+  divideObj.showExecDatas();
 });