Selaa lähdekoodia

计算分部分项和技术施工项目总消耗量

zhangweicheng 7 vuotta sitten
vanhempi
commit
c69cf291a3

+ 1 - 0
modules/main/models/bills.js

@@ -23,6 +23,7 @@ let billsSchema = new Schema({
     chapterID: Number,
     code: String,
     fullCode: String,
+    type:Number,
     name: String,
     unit: String,
     quantity: String, // Decimal

+ 1 - 0
web/building_saas/glj/js/project_glj.js

@@ -417,6 +417,7 @@ function filterProjectGLJ(jsonData) {
     return jsonData;
 }
 
+
 function sortProjectGLJ(jsonData) {
     if (jsonData.length > 0) {
         jsonData = _.sortByAll(jsonData, [function (item) {

+ 3 - 0
web/building_saas/glj/js/project_glj_spread.js

@@ -48,6 +48,9 @@ ProjectGLJSpread.prototype.init = function () {
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
         {name: '总消耗量', field: 'quantity', visible: true,width:100,decimalField:'glj.quantity'},
+        {name: '总消耗量', field: 'quantity', visible: true,width:100,decimalField:'glj.quantity'},
+        {name: '分部分项总消耗量', field: 'subdivisionQuantity', visible: true,width:100,decimalField:'glj.quantity'},
+        {name: '技术措施项目总消耗量', field: 'techQuantity', visible: true,width:100,decimalField:'glj.quantity'},
         {name: '定额价', field: "base_price", visible: true,width:70,decimalField:"glj.unitPrice",validator: 'number'},//这里feiedID设置是为了在计不计取价差的时候做显示用
         {name: '调整价', field: 'adjust_price', visible: true,width:70,decimalField:"glj.unitPrice"},
         {name: '市场价', field: "unit_price.market_price", visible: true, validator: 'number',width:70,decimalField:"glj.unitPrice"},

+ 12 - 1
web/building_saas/main/js/controllers/project_controller.js

@@ -23,7 +23,6 @@ ProjectController = {
     },
     addBills: function (project, sheetController, std) {
         if (!project || !sheetController) { return null; }
-
         let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
         let newSource = null, newNode = null, parentID, nextSiblingID;
         if (target) {
@@ -54,6 +53,18 @@ ProjectController = {
             this.syncDisplayNewNode(sheetController, newNode);
         }
     },
+    addRootBill:function (project, sheetController) {//添加大项费用
+        let newSource = null, newNode = null
+        newSource = project.Bills.insertBills(-1, project.mainTree.selected.source.getNextSiblingID(),true);
+        newNode = project.mainTree.insert(-1, project.mainTree.selected.getNextSiblingID());
+        if (newNode) {
+            newNode.source = newSource;
+            newNode.sourceType = project.Bills.getSourceType();
+            newNode.data = newSource.data;
+            this.syncDisplayNewNode(sheetController, newNode);
+        }
+
+    },
     addRation: function (project, sheetController, rationType, std) {
         if (!project || !sheetController) { return; }
 

+ 56 - 3
web/building_saas/main/js/models/bills.js

@@ -151,11 +151,14 @@ var Bills = {
             return updateData;
         };
 
-        bills.prototype.insertBills = function (parentId, nextSiblingId) {
+        bills.prototype.insertBills = function (parentId, nextSiblingId,isUserAdd) {//是否是用户新增的
             var insertData = this.tree.getInsertData(parentId, nextSiblingId);
             var that = this, newData = null;
             insertData.forEach(function (data) {
                 if (data.type === idTree.updateType.new) {
+                    if(isUserAdd==true){//如果是用户新增的,类型为1
+                        data.data.type = 1;
+                    }
                     newData = data.data;
                 }
             });
@@ -328,7 +331,6 @@ var Bills = {
             this.project.pushNow('replaceBills', this.getSourceType(), updateData);
             return node;            
         };
-
         bills.prototype.sameStdCodeBillsData = function (stdCode) {
             let reg = new RegExp('^' + stdCode);
             for (let data of this.datas) {
@@ -337,8 +339,59 @@ var Bills = {
                 }
             }
             return null;            
-        }
+        };
+
+        bills.prototype.getSubdivisionProjectLeavesID=function () {//取所有分部分项工程清单叶子节点ID
+            let roots = projectObj.project.mainTree.roots;//所有根节点
+            let subdivisionNode = null;
+            for(let r of roots){
+               if(isFlag(r.data)&&r.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING) {
+                   subdivisionNode = r;
+                   break;
+               }
+            }
+            let nodes = this.getLeavesBillNodes(subdivisionNode);
+            return  _.map(nodes,"data.ID");
+        };
+
+
+        bills.prototype.getTechLeavesID=function () {//取所有分计算技术措施项目清单叶子节点ID
+            let items = projectObj.project.mainTree.roots;//所有节点;
+            let techNode = null;
+            for(let item of items){
+                if(isFlag(item.data)&&item.data.flagsIndex.fixed.flag==fixedFlag.CONSTRUCTION_TECH){
+                    techNode = item;
+                    break;
+                }
+            }
+            let nodes = this.getLeavesBillNodes(techNode);
+            return  _.map(nodes,"data.ID");
+        };
 
+        bills.prototype.getLeavesBillNodes = function (rnode) {//取该节点下的所有清单叶子节点
+            let leaves = [];
+            getLeaves(rnode,leaves);
+            return leaves;
+
+            function  getLeaves(node,children) {
+                if(node){
+                    if(node.source.children.length>0){
+                        for(let c of node.children){
+                            getLeaves(c,children)
+                        }
+                    }else {
+                        children.push(node);
+                    }
+                }
+            }
+        };
         return new bills(project);
     }
 };
+function isDef(v) {
+    return v !== undefined && v !== null;
+}
+
+function isFlag(v) {
+    return this.isDef(v.flagsIndex) && this.isDef(v.flagsIndex.fixed);
+}

+ 0 - 1
web/building_saas/main/js/models/cache_tree.js

@@ -380,7 +380,6 @@ var cacheTree = {
             }
             return success;
         };
-
         return new Tree(owner);
     }
 };

+ 1 - 41
web/building_saas/main/js/models/calc_base.js

@@ -1,47 +1,7 @@
 /**
  * Created by Zhong on 2017/11/28.
  */
-//清单固定行
-const fixedFlag = {
-    // 分部分项工程
-    SUB_ENGINERRING: 1,
-    // 措施项目
-    MEASURE: 2,
-    // 施工技术措施项目
-    CONSTRUCTION_TECH: 3,
-    // 安全文明施工按实计算费用
-    SAFETY_CONSTRUCTION_ACTUAL: 4,
-    // 施工组织措施专项费用
-    CONSTRUCTION_ORGANIZATION: 5,
-    // 安全文明施工专项费用
-    SAFETY_CONSTRUCTION: 6,
-    // 其他项目
-    OTHER: 7,
-    // 暂列金额
-    PROVISIONAL: 8,
-    // 暂估价
-    ESTIMATE: 9,
-    // 材料(工程设备)暂估价
-    MATERIAL_PROVISIONAL: 10,
-    // 专业工程暂估价
-    ENGINEERING_ESITIMATE: 11,
-    // 计日工
-    DAYWORK: 12,
-    // 总承包服务费
-    TURN_KEY_CONTRACT: 13,
-    // 索赔与现场签证
-    CLAIM_VISA: 14,
-    // 规费
-    CHARGE: 15,
-    // 社会保险费及住房公积金 Social insurance fee and housing accumulation fund
-    SOCIAL_INSURANCE_HOUSING_FUND: 16,
-    // 工程排污费 charges for disposing pollutants
-    POLLUTANTS: 17,
-    // 税金
-    TAX: 18,
-    //工程造价
-    ENGINEERINGCOST: 19
-};
+
 
 let cbTools = {
     isDef: function (v) {

+ 43 - 1
web/building_saas/main/js/models/main_consts.js

@@ -133,5 +133,47 @@ const zanguCalcType = {
     gatherMaterial: 1
 };
 
+//清单固定行
+const fixedFlag = {
+    // 分部分项工程
+    SUB_ENGINERRING: 1,
+    // 措施项目
+    MEASURE: 2,
+    // 施工技术措施项目
+    CONSTRUCTION_TECH: 3,
+    // 安全文明施工按实计算费用
+    SAFETY_CONSTRUCTION_ACTUAL: 4,
+    // 施工组织措施专项费用
+    CONSTRUCTION_ORGANIZATION: 5,
+    // 安全文明施工专项费用
+    SAFETY_CONSTRUCTION: 6,
+    // 其他项目
+    OTHER: 7,
+    // 暂列金额
+    PROVISIONAL: 8,
+    // 暂估价
+    ESTIMATE: 9,
+    // 材料(工程设备)暂估价
+    MATERIAL_PROVISIONAL: 10,
+    // 专业工程暂估价
+    ENGINEERING_ESITIMATE: 11,
+    // 计日工
+    DAYWORK: 12,
+    // 总承包服务费
+    TURN_KEY_CONTRACT: 13,
+    // 索赔与现场签证
+    CLAIM_VISA: 14,
+    // 规费
+    CHARGE: 15,
+    // 社会保险费及住房公积金 Social insurance fee and housing accumulation fund
+    SOCIAL_INSURANCE_HOUSING_FUND: 16,
+    // 工程排污费 charges for disposing pollutants
+    POLLUTANTS: 17,
+    // 税金
+    TAX: 18,
+    //工程造价
+    ENGINEERINGCOST: 19
+};
+
 const gljKeyArray =['code','name','specs','unit','type'];
-const gljLibKeyArray =['code', 'name', 'specs', 'unit', 'gljType']
+const gljLibKeyArray =['code', 'name', 'specs', 'unit', 'gljType'];

+ 91 - 0
web/building_saas/main/js/models/project_glj.js

@@ -41,6 +41,7 @@ ProjectGLJ.prototype.loadData = function (callback = null) {
                 return false;
             }
             self.datas = response.data;
+            self.calcQuantity();
             // 回调函数
             if (callback !== null) {
                 callback(response.data);
@@ -396,3 +397,93 @@ ProjectGLJ.prototype.getShortNameByID = function (ID) {
     let gljTypeMap = this.datas.constData.gljTypeMap;
     return gljTypeMap["typeId" + ID].shortName;
 }
+
+ProjectGLJ.prototype.calcQuantity  = function (){
+    let project_gljs = this.datas.gljList;
+    let mixRatioConnectData = this.datas.mixRatioConnectData;
+    let mixRatioSubdivisionMap = {};
+    let mixRatioTechMap={};
+    for(let pglj of project_gljs ){
+        if(pglj.quantity !== 0 && pglj.quantity !== '0'){
+            let result = this.getQuantityPerGLJ(pglj,mixRatioSubdivisionMap,mixRatioTechMap);
+            pglj.subdivisionQuantity = result.subdivisionQuantity;
+            pglj.techQuantity = result.techQuantity;
+        }
+    }
+    //计算做为组成物的消耗量
+    for(let pg of project_gljs ){
+        if(pg.quantity !== 0 && pg.quantity !== '0'){
+            let pg_index = gljOprObj.getIndex(pg,gljKeyArray);
+            if(mixRatioConnectData[pg_index]){
+                if(mixRatioSubdivisionMap[pg_index]){
+                    pg.subdivisionQuantity = scMathUtil.roundForObj(mixRatioSubdivisionMap[pg_index]+pg.subdivisionQuantity,getDecimal("glj.quantity"));
+                }
+                if(mixRatioTechMap[pg_index]){
+                    pg.techQuantity = scMathUtil.roundForObj(mixRatioTechMap[pg_index]+pg.techQuantity,getDecimal("glj.quantity"));
+                }
+            }
+        }
+    }
+
+}
+
+ProjectGLJ.prototype.getQuantityPerGLJ =function (pglj,mixRatioSubdivisionMap,mixRatioTechMap) {
+    let billIDs =   projectObj.project.Bills.getSubdivisionProjectLeavesID();//取分部分项上的所有叶子清单ID
+    let tech_billIDS =  projectObj.project.Bills.getTechLeavesID();//取所有技术措施项目叶子清单ID
+    let ration_glj_list = projectObj.project.ration_glj.datas;
+    let mixRatioMap = this.datas.mixRatioMap;
+    let rations = projectObj.project.Ration.datas;
+    let q_decimal = getDecimal("glj.quantity");
+    let result={};
+    let sum = 0;
+    let tech_sum = 0;
+    for(let rg of ration_glj_list){
+        if(rg.projectGLJID==pglj.id){
+            if(_.includes(billIDs,rg.billsItemID)){//计算分部分项
+               let total = calcQuantity(rg,mixRatioSubdivisionMap);
+               sum = scMathUtil.roundForObj(sum+total,q_decimal);
+            }
+            if(_.includes(tech_billIDS,rg.billsItemID)){//计算技术措施项目消耗量
+                let tech_total = calcQuantity(rg,mixRatioTechMap);
+                tech_sum = scMathUtil.roundForObj(tech_sum+tech_total,q_decimal);
+            }
+        }
+
+    }
+    for(let ra of rations){//计算定额类型工料机的消耗量
+        if(ra.type == rationType.gljRation&&ra.projectGLJID===pglj.id){
+            let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
+            r_quantity = r_quantity?r_quantity:0;
+            if(_.includes(billIDs,ra.billsItemID)){//计算分部分项
+                sum = scMathUtil.roundForObj(sum+r_quantity,q_decimal);
+            }
+            if(_.includes(tech_billIDS,ra.billsItemID)){//计算技术措施项目消耗量
+                tech_sum = scMathUtil.roundForObj(tech_sum+r_quantity,q_decimal);
+            }
+        }
+
+    }
+    result.subdivisionQuantity = sum;
+    result.techQuantity = tech_sum;
+    return result;
+
+    function calcQuantity(rg,quantityMap) { //计算工料机在所属定额下的总消耗量
+        let tem_ration = _.find(rations,{"ID":rg.rationID});
+        let total = parseFloat(gljOprObj.getTotalQuantity(rg,tem_ration));
+        let r_index = gljOprObj.getIndex(rg,gljKeyArray);
+        if(mixRatioMap.hasOwnProperty(r_index)){
+            let mixRatioList = mixRatioMap[r_index];
+            for(let m of mixRatioList){
+                let m_index = gljOprObj.getIndex(m,gljKeyArray);
+                let m_quantity = scMathUtil.roundForObj(total*m.consumption,q_decimal);
+                if(quantityMap[m_index]){
+                    quantityMap[m_index] = scMathUtil.roundForObj(quantityMap[m_index]+m_quantity,q_decimal);
+                }else {
+                    quantityMap[m_index] = m_quantity;
+                }
+            }
+        }
+        return total;
+    }
+
+} 

+ 8 - 7
web/building_saas/main/js/models/ration_glj.js

@@ -118,12 +118,13 @@ var ration_glj = {
             //add to mainTree;
             me.addToMainTree(neRecodes);
             let node = project.mainTree.selected;
-            project.calcProgram.calculate(node);
-            project.calcProgram.saveNode(node);
-            if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
-                calcProgramObj.showData(node, false);
-            }
-            ;
+            project.projectGLJ.loadData(function () {
+                project.calcProgram.calculate(node);
+                project.calcProgram.saveNode(node);
+                if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
+                    calcProgramObj.showData(node, false);
+                };
+            });
         };
         ration_glj.prototype.addToMainTree = function (datas) {
             datas = sortRationGLJ(datas);
@@ -367,8 +368,8 @@ var ration_glj = {
                 if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
                     gljOprObj.showRationGLJSheetData();
                 }
-                me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
                 projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
+                    me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
                     if (initShow == true) {
                         gljOprObj.refreshView();
                     }

+ 15 - 12
web/building_saas/main/js/views/glj_view.js

@@ -1234,11 +1234,12 @@ var gljOprObj = {
                     gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
                     gljOprObj.showRationGLJSheetData();
                     project.ration_glj.addToMainTree(result.showData);
-                    project.projectGLJ.loadData();
-                    project.calcProgram.calculate(selected);
-                    project.calcProgram.saveNode(selected);
-                    projectObj.mainController.refreshTreeNode([selected]);
-                    $.bootstrapLoading.end();
+                    project.projectGLJ.loadData(function () {
+                        project.calcProgram.calculate(selected);
+                        project.calcProgram.saveNode(selected);
+                        projectObj.mainController.refreshTreeNode([selected]);
+                        $.bootstrapLoading.end();
+                    });
                 }
             });//doc.rationID=selected.data.ID;
         } else {
@@ -1274,11 +1275,12 @@ var gljOprObj = {
                     node ? nodes.push(node) : "";
                 }
                 //project.ration_glj.addToMainTree(data);
-                project.projectGLJ.loadData();
                 selected.data.adjustState = result.adjustState;
-                projectObj.mainController.refreshTreeNode(nodes);
-                project.calcProgram.calculate(selected);
-                project.calcProgram.saveNode(selected);
+                project.projectGLJ.loadData(function () {//加载完项目工料机再计算
+                    projectObj.mainController.refreshTreeNode(nodes);
+                    project.calcProgram.calculate(selected);
+                    project.calcProgram.saveNode(selected);
+                });
             }
             $.bootstrapLoading.end();
         })
@@ -1306,10 +1308,11 @@ var gljOprObj = {
                 }
             })
             me.showRationGLJSheetData();
-            project.projectGLJ.loadData();
             var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
-            project.calcProgram.calcRationsAndSave(rationNodes);
-            $.bootstrapLoading.end();
+            project.projectGLJ.loadData(function () {
+                project.calcProgram.calcRationsAndSave(rationNodes);
+                $.bootstrapLoading.end();
+            });
         })
     },
     updateProperty: function (obj, doc) {

+ 10 - 6
web/building_saas/main/js/views/project_view.js

@@ -210,11 +210,11 @@ var projectObj = {
                 });
             }
         }
-        if (value.length === 9 && /^[\d]+$/.test(value)) {
+        if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
             stdMatchCode = value;
             formatCode = project.Bills.newFormatCode(stdMatchCode);
             searchStdBillsAndUpdate(stdMatchCode, formatCode);
-        } else if (value.length === 12 && /^[\d]+$/.test(value)) {
+        } else if (value&&value.length === 12 && /^[\d]+$/.test(value)) {
             stdMatchCode = value.substr(0, 9);
             matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
             if (matchs.indexOf(value) === -1) {
@@ -383,9 +383,11 @@ var projectObj = {
     loadProjectData: function () {
         var that = this;
         this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
+        let startTime = +new Date();
+        console.log("开始加载-----"+startTime);
         this.project.loadDatas(function (err) {
-
             if (!err) {
+                that.project.projectGLJ.calcQuantity();//计算分部分项和技术措施项目消耗量;
                 that.project.property = projectInfoObj.projectInfo.property;
                 //that.project.calcProgram.compileAllTemps();
                 that.project.calcBase.init(that.project);
@@ -460,6 +462,8 @@ var projectObj = {
                 that.mainSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, that.amountAreaNumber);
                 that.loadMainSpreadContextMenu();
                 that.loadFocusLocation();
+                let endTime = +new Date();
+                console.log("加载完成-----"+endTime);
             }
             else {
 
@@ -478,16 +482,16 @@ var projectObj = {
             },
             items: {
                 "insertRootBill": {
-                    name: "插入大项",
+                    name: "插入大项费用",
                     icon: 'fa-sign-in',
                     disabled: function () {
                         //return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
                     },
                     callback: function (key, opt) {
-                        //ProjectController.addBills(project, controller);
+                        ProjectController.addRootBill(project, controller);
                     },
                     visible: function(key, opt){
-                        return false;
+                        return false;//project.mainTree.selected&&project.mainTree.selected.parent ==null;;
                     }
                 },
                 "insertBills": {