Просмотр исходного кода

Merge branch '1.0.0_online' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost into 1.0.0_online

zhongzewei 7 лет назад
Родитель
Сommit
3c939d195e

+ 2 - 1
modules/main/controllers/ration_controller.js

@@ -59,13 +59,14 @@ let controller = {
         let applyTasks = [
             ration_facade.addMultiRation(data.rations.create,req.session.sessionCompilation),//先生成新定额
             bill_facade.createNewBills(data.bills.create),
+            ration_facade.deleteMultiRation(data.rations.delete)
         ];
         //整理更新的数据,调用一个方法更新
         updateDatas.push(data.ration_template);
         if(data.rations.update.length > 0)  prepareUpdateNodes(data.rations.update,updateDatas,"ration");
         if(data.bills.update.length > 0)  prepareUpdateNodes(data.bills.update,updateDatas,"bills");
         applyTasks.push(project_facade.updateNodes(updateDatas));
-        let [rationResult,billsResult,updates] = await Promise.all(applyTasks);
+        let [rationResult,billsResult,deleteResult,updates] = await Promise.all(applyTasks);
         return {rationResult:rationResult,billsResult:billsResult,updateDatas:updateDatas};
     },
     //更新辅助定额

+ 12 - 9
modules/main/facade/project_facade.js

@@ -1,6 +1,17 @@
 /**
  * Created by zhang on 2018/1/26.
  */
+
+module.exports = {
+    markUpdateProject:markUpdateProject,
+    removeProjectMark:removeProjectMark,
+    updateNodes:updateNodes,
+    calcInstallationFee:calcInstallationFee,
+    saveProperty: saveProperty,
+    getDefaultColSetting: getDefaultColSetting,
+    markProjectsToChange:markProjectsToChange
+};
+
 let mongoose = require('mongoose');
 let logger = require("../../../logs/log_helper").logger;
 let  projectsModel = mongoose.model('projects');
@@ -18,15 +29,7 @@ const uuidV1 = require('uuid/v1');
 const gljUtil = require('../../../public/gljUtil');
 let stdColSettingModel = mongoose.model('std_main_col_lib');
 
-module.exports = {
-    markUpdateProject:markUpdateProject,
-    removeProjectMark:removeProjectMark,
-    updateNodes:updateNodes,
-    calcInstallationFee:calcInstallationFee,
-    saveProperty: saveProperty,
-    getDefaultColSetting: getDefaultColSetting,
-    markProjectsToChange:markProjectsToChange
-};
+
 
 async function calcInstallationFee(data) {
     let result={};

+ 57 - 36
modules/main/facade/ration_facade.js

@@ -1,6 +1,20 @@
 /**
  * Created by zhang on 2018/2/9.
  */
+//先导出后require可以解决循环引用问题
+module.exports = {
+    replaceRations: replaceRations,
+    addNewRation:addNewRation,
+    addMultiRation: addMultiRation,
+    deleteMultiRation:deleteMultiRation,
+    getSameSectionRations:getSameSectionRations,
+    getExtendData:getExtendData,
+    getDefaultProgramID:getDefaultProgramID,
+    deleteSubListByQuery:deleteSubListByQuery,
+    updateCoeAdjust:updateCoeAdjust
+};
+
+
 let mongoose = require('mongoose');
 import SearchDao from '../../complementary_ration_lib/models/searchModel';
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
@@ -29,16 +43,6 @@ const projectDao = require('../../pm/models/project_model').project;
 let projectModel = mongoose.model('projects');
 const fs = require('fs');
 
-module.exports = {
-    replaceRations: replaceRations,
-    addNewRation:addNewRation,
-    addMultiRation: addMultiRation,
-    getSameSectionRations:getSameSectionRations,
-    getExtendData:getExtendData,
-    getDefaultProgramID:getDefaultProgramID,
-    deleteSubListByQuery:deleteSubListByQuery,
-    updateCoeAdjust:updateCoeAdjust
-};
 async function addNewRation(data,compilation) {
     let query = data.itemQuery;
     let stdRation = null;
@@ -72,6 +76,14 @@ async function addMultiRation(datas,compilation) {
     return rst;
 }
 
+async function deleteMultiRation(rations) {//这里是只有删除的情况,删除定额的同时删除定额下挂的其它子项目
+    if(rations.length > 0){//删除定额下的
+        let rationIDS = _.map(rations,'ID');
+        await deleteSubListByQuery({projectID:rations[0].projectID,rationID:{"$in": rationIDS}});
+        await ration_model.model.deleteMany({ID:{"$in": rationIDS}});
+    }
+}
+
 async function getSameSectionRations(data,userId,compilationId){
     //let userId
     //要先根据定额获取所属章节的ID
@@ -164,7 +176,7 @@ async function replaceRations(userID,data,compilation) {
     let recodes = [];
     for(let recode of data.nodeInfo){
         let stdRation = await searchDao.getRationItem(userID,compilation._id,data.libIDs,recode.newCode, null);
-        let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity,compilation);
+        let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity,compilation,data.cleanzmhs);
         if(newRecode){
             recodes.push(newRecode);
         }else {
@@ -186,20 +198,20 @@ async function getDefaultProgramID(data) {
     return programID;
 }
 
-async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity,compilation) {
+async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity,compilation,cleanzmhs) {
     if(nodeInfo.newCode == null||nodeInfo.newCode ==""){//说明是删除编号,则要变成一条空定额
         await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
         return await setEmptyRation(projectID,nodeInfo.ID);
     }else if(stdRation){
-        await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
-        let newRation = await updateRation(stdRation,defaultLibID,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
-        return await addRationSubList(stdRation,newRation,nodeInfo.needInstall,compilation);
+        await deleRationSubRecode(projectID,nodeInfo.ID,cleanzmhs);//删除定额下挂的各种数据,如定额工料机等
+        let newRation = await updateRation(stdRation,defaultLibID,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity,cleanzmhs);//生成并插入新的定额
+        return await addRationSubList(stdRation,newRation,nodeInfo.needInstall,compilation,cleanzmhs);
     }else {
         return null;
     }
 }
 
-async function addRationSubList(stdRation,newRation,needInstall,compilation) {
+async function addRationSubList(stdRation,newRation,needInstall,compilation,cleanzmhs=false) {
     let startTime = +new Date();
     let ration_gljs = await addRationGLJ(stdRation,newRation,compilation);
     let addRationGLJTime = +new Date();
@@ -208,13 +220,16 @@ async function addRationSubList(stdRation,newRation,needInstall,compilation) {
     let addRationCoeTime = +new Date();
     console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
     let ration_installations = [];
-    if(needInstall && stdRation.type == 'std'){//只有标准的定额才有安装增加费,补充的定额没有安装增加费
-        ration_installations =  await addRationInstallFee(stdRation,newRation);
+    let ration_template = [];
+    if(cleanzmhs == false){//清除子目换算即cleanzmh==true时 模板子目、安装增加费不用恢复成标准的
+        if(needInstall && stdRation.type == 'std'){//只有标准的定额才有安装增加费,补充的定额没有安装增加费
+            ration_installations =  await addRationInstallFee(stdRation,newRation);
+        }
+        let addRationInstallFeeTime = +new Date();
+        console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
+        //添加定额模板子目
+        ration_template = await addRationTemplate(stdRation,newRation);
     }
-    let addRationInstallFeeTime = +new Date();
-    console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
-    //添加定额模板子目
-    let ration_template = await addRationTemplate(stdRation,newRation);
     return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:ration_template?[ration_template]:[]};
 }
 
@@ -464,18 +479,22 @@ async function addRationGLJ(std,newRation,compilation) {
     return rationGLJShowList;
 }
 
-async function deleRationSubRecode(projectID,rationID) {//删除挂在定额下的数据,如工程量明细,定额工料机等
+async function deleRationSubRecode(projectID,rationID,cleanzmhs=false) {//删除挂在定额下的数据,如工程量明细,定额工料机等
     let delete_query={projectID: projectID, rationID: rationID};
     //删除工程量明细
-    await deleteSubListByQuery(delete_query) ;
+    await deleteSubListByQuery(delete_query,cleanzmhs) ;
 }
 
-async function deleteSubListByQuery(delete_query) {
-    await quantity_detail.deleteByQuery(delete_query) ;//删除工程量明细
+async function deleteSubListByQuery(delete_query,cleanzmhs=false) {
+    if(cleanzmhs == false){//清空子目换算即cleanzmh==true时不需要清空工程量明细、模板关联子目、安装增加费
+        await quantity_detail.deleteByQuery(delete_query) ;//删除工程量明细
+        await rationInstallationModel.deleteMany(delete_query);//删除安装增加费
+        await rationTemplateModel.deleteMany(delete_query);//删除模板关联子目
+    }
+    //to do稳定土也要删除
+
     await ration_coe.deleteMany(delete_query);//删除附注条件
     await ration_glj.deleteMany(delete_query);//删除定额工料机
-    await rationInstallationModel.deleteMany(delete_query);//删除安装增加费
-    await rationTemplateModel.deleteMany(delete_query);//删除模板关联子目
 }
 
 async function updateCoeAdjust(data,compilation) {
@@ -512,7 +531,7 @@ async function updateCoeAdjust(data,compilation) {
 
 
 
-async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {
+async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity,cleanzmh=false) {
     // insertNewRation
     let ration ={};
     ration.code = std.code;
@@ -542,14 +561,16 @@ async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,cal
     else if(std.rationRepId === defaultLibID && ration.from === 'cpt') {
         ration.prefix = '补';
     }
-    if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
-        ration.programID = await getProgramForProject(projectID);
-    }else {
-        ration.programID = std.feeType;
-    }
     ration.rationAssList = createRationAss(std);//生成辅助定额
-    if(calQuantity){
-       await CalculateQuantity(ration,billsItemID,projectID);
+    if(cleanzmh==false){//如果是清空子目换算,即cleanzmh==true 保留定额工程量、工程量表达式、含量(分解系数)、取费专业(取费类别)
+        if(std.feeType == undefined || std.feeType == null || std.feeType ==''){//定额取费专业为空的情况下,取项目属性中的定额取费专业ID
+            ration.programID = await getProgramForProject(projectID);
+        }else {
+            ration.programID = std.feeType;
+        }
+        if(calQuantity){
+            await CalculateQuantity(ration,billsItemID,projectID);
+        }
     }
 
      let unsetObject = {

+ 5 - 1
modules/reports/rpt_component/helper/jpc_helper_common_output.js

@@ -2,7 +2,7 @@ let JV = require('../jpc_value_define');
 let JpcFieldHelper = require('./jpc_helper_field');
 
 let JpcCommonOutputHelper = {
-    createCommonOutputWithoutDecorate: function (node, value) {
+    createCommonOutputWithoutDecorate: function (node, value, forceCombine) {
         let me = this, rst = {};
         //1. font/style/control
         rst[JV.PROP_FONT] = node[[JV.PROP_FONT]];
@@ -14,9 +14,13 @@ let JpcCommonOutputHelper = {
         // innerFormat(node[JV.PROP_FORMAT], rst);
         if (node[JV.PROP_PREFIX] && rst[JV.PROP_VALUE] !== null) {
             rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX] + rst[JV.PROP_VALUE];
+        } else if (node[JV.PROP_PREFIX] && forceCombine) {
+            rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX];
         }
         if (node[JV.PROP_SUFFIX] && rst[JV.PROP_VALUE] !== null) {
             rst[JV.PROP_VALUE] = rst[JV.PROP_VALUE] + node[JV.PROP_SUFFIX];
+        } else if (node[JV.PROP_SUFFIX] && forceCombine) {
+            rst[JV.PROP_VALUE] = node[JV.PROP_SUFFIX];
         }
         return rst;
     },

+ 1 - 1
modules/reports/rpt_component/helper/jpc_helper_discrete.js

@@ -60,7 +60,7 @@ let JpcDiscreteHelper = {
                                 let param = JE.P(df[JV.PROP_PARAM_ID], $CURRENT_RPT);
                                 value = param[JV.PROP_DFT_VALUE];
                             }
-                            let item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, null);
+                            let item = JpcCommonOutputHelper.createCommonOutputWithoutDecorate(df, value, true);
                             //position
                             item[JV.PROP_AREA] = JpcAreaHelper.outputArea(df[JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, multiCols, multiColIdx, false, false);
                             rst.push(item);

+ 1 - 1
public/web/tree_sheet/tree_sheet_helper.js

@@ -170,7 +170,7 @@ var TREE_SHEET_HELPER = {
                         }/*else if(node.sourceType == ModuleNames.bills &&projectObj.ifItemCharHiden(setting)){//清单、并且项目特征列隐藏的时候悬浮提示  这里改成在 计量单位那里提示
                             tag = node.data.itemCharacterText?node.data.itemCharacterText:'';
                         }*/
-                        if(tag!=null&&tag!="") sheet.setTag(iRow, iCol,tag);
+                        if(tag!=null) sheet.setTag(iRow, iCol,tag);
                     }
                     /*if(colSetting.data.field=="name"){ 2018-08-06 改成在编号列悬浮提示
                         let tag = node.data.itemCharacterText?node.data.itemCharacterText:'';

+ 10 - 3
web/building_saas/main/js/models/ration.js

@@ -108,6 +108,13 @@ var Ration = {
             });
             controller.sheet.getCell(selected[0].row,col).value(data[fieldName]);
         };
+        ration.prototype.getContain = function (billNode,quantity) {
+            if(billNode && billNode.data.quantity&&billNode.data.quantity!=0&&billNode.data.quantity!=""){
+                let billQuantity = scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode));
+                return scMathUtil.roundForObj(parseFloat(quantity)/billQuantity,getDecimal("process"));
+            }
+            return 0
+        };
         ration.prototype.getTempRationData = function (id, billsID, serialNo, rType,priceType) {
             let newData = {'ID': id, 'serialNo': serialNo, projectID: this.project.ID()};
             let pEngineer = projectInfoObj.projectInfo.property.projectEngineering;//量价默认使用后台设置的单位工程取费专业
@@ -378,7 +385,7 @@ var Ration = {
                 ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,process_decimal);
             }
         };
-        ration.prototype.updateRationCodes = function (recodes) {
+        ration.prototype.updateRationCodes = function (recodes,cleanzmhs = false) {
             let libID =  rationLibObj.getCurrentStdRationLibID();
             let libIDs = rationLibObj.getStdRationLibIDs();
             let defaultLibID = rationLibObj.getDefaultStdRationLibID();
@@ -397,14 +404,14 @@ var Ration = {
                     needInstall = project.Bills.isFBFX(r.node);
                 }
                 r.value===null||r.value===undefined?"":r.value = r.value.replace(/[\s\r\n]/g, "");//去掉空格回车换行等字符
-                if(r.value != r.node.data.code){
+                if(cleanzmhs  == true||r.value != r.node.data.code){
                     nodeInfo.push({ID:r.node.data.ID,billsItemID:r.node.data.billsItemID,newCode:r.value,needInstall:needInstall});
                     refershNodes.push(r.node);
                 }
             }
             let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
             $.bootstrapLoading.start();
-            CommonAjax.post("/ration/replaceRations",{nodeInfo:nodeInfo,libIDs:libIDs,defaultLibID: defaultLibID,projectID:projectID,calQuantity:calQuantity},function (data) {
+            CommonAjax.post("/ration/replaceRations",{nodeInfo:nodeInfo,libIDs:libIDs,defaultLibID: defaultLibID,projectID:projectID,calQuantity:calQuantity,cleanzmhs:cleanzmhs},function (data) {
                 for(let recode of data){
                    let node =  mainTree.getNodeByID(recode.ration.ID);
                    if(node) {

+ 1 - 1
web/building_saas/main/js/views/glj_col.js

@@ -54,7 +54,7 @@ let gljCol = {
             {headerName: "备注", headerWidth: 100, dataCode: "remark", hAlign: "left", dataType: "String"}
         ],
         view: {
-            lockColumns: [0,1,2,3,4,6,8]
+            lockColumns: ["code","name","specs","unit","short_name","adjustPrice","quantity"]
         },
         frozenCols:4
     },

+ 1 - 1
web/building_saas/main/js/views/main_tree_col.js

@@ -351,7 +351,7 @@ let MainTreeCol = {
             }
 
         },
-        commonTotalFee: function () {
+        commonTotalFee: function (node) {
             let readOnly = projectReadOnly || !calcBaseView.ifEdit('bills', projectObj.project.mainTree.items.indexOf(node));
             return sheetCommonObj.getCusButtonCellType(projectObj.onCommonTotalFeeButtonClick,readOnly) //projectObj.getCommonTotalFeeCellType();
         }

+ 12 - 7
web/building_saas/main/js/views/mbzm_view.js

@@ -146,7 +146,7 @@ let mbzm_obj={
         let selected = projectObj.project.mainTree.selected;
         let template = projectObj.project.ration_template.getTemplateByRationID(selected.data.ID);
         let createLocation = $("#createLocation").val();
-        let rations = {update:[],create:[]},bills={update:[],create:[]};
+        let rations = {update:[],create:[],delete:[]},bills={update:[],create:[]};
         if(this.datas.length <= 0) return;
         for(let d of this.datas){
             if((gljUtil.isDef(d.quantity)&& parseFloat(d.quantity)>0)||(d.coe && d.coe!="0")){
@@ -231,7 +231,7 @@ let mbzm_obj={
         let mainRation = projectObj.project.mainTree.getNodeByID(referenceRationID);
         let billsID="";
         //先检查要更新的定额是否已经存在
-        let ration = this.getExistRation(data,referenceRationID,type);
+        let ration = this.getExistRation(data,referenceRationID,type,rations);
         if(ration) {//如果存在,则比较清耗量、工程量表达式是否一致
             let tem =  this.getRationData(ration,data,quantity);//取更新信息
 
@@ -244,8 +244,7 @@ let mbzm_obj={
         //定额不存在的情况下
         if(type == mbzm_obj.locateMap.AFTERRATION) {//如果是生成在主定额后面的位置
             this.createNewRationAfterMain(data,mainRation,quantity,rations);
-        }
-        if(type == mbzm_obj.locateMap.INMEASURE){//生成在措施项目下
+        }else if(type == mbzm_obj.locateMap.INMEASURE){//生成在措施项目下
             this.createNewRationInMeasure(data,mainRation,quantity,rations,bills);
         }else {
             this.createNewRationInFBFX(data,mainRation,quantity,rations,bills);
@@ -261,6 +260,7 @@ let mbzm_obj={
         if(!_.isEmpty(tem)) {
             tem.projectID = ration.projectID;
             tem.ID = ration.ID;
+            tem.contain = projectObj.project.Ration.getContain(projectObj.project.mainTree.findNode(ration.billsItemID),tem.quantity);
             return tem;
         }
         return null;
@@ -407,6 +407,8 @@ let mbzm_obj={
         newData.referenceRationID = referenceRationID;
         newData.quantity = quantity;
         newData.quantityEXP = gljUtil.isDef(data.coe) && data.coe != "0"?"MBGCL":quantity+"";
+        //这里还要生成根据清单生成含量,父清单如果是刚自动生成的,其工程量为0,含量也为0
+        newData.contain = projectObj.project.Ration.getContain(projectObj.project.mainTree.findNode(billsID),quantity);
         let temRation = this.getDefaultRationCreateData(newData,data.code,libID,isFBFX);
         return temRation;
     },
@@ -436,7 +438,7 @@ let mbzm_obj={
         }
         return quantity;
     },
-    getExistRation:function (data,referenceRationID,type) {
+    getExistRation:function (data,referenceRationID,type,updateRations) {
         let temRation = null;
         //先检查要更新的定额是否已经存在
         let rations =_.filter(projectObj.project.Ration.datas,{'referenceRationID':referenceRationID,'code':data.code});
@@ -470,6 +472,8 @@ let mbzm_obj={
                     }
                 }
             }
+            //如果没有执行到break,则说明这条定额是要被删除的
+            updateRations.delete.push({projectID:r.projectID,ID:r.ID});
         }
         return temRation;
     },
@@ -523,12 +527,13 @@ let mbzm_obj={
                         let t_times = parseInt(rnode.data.unit);
                         t_times = isNaN(t_times)?1:t_times;//工程量要乘以定额单位的倍数
                         rnode.data.quantity = scMathUtil.roundForObj(t_quantity/t_times,getDecimal('ration.quantity'));
-                        if(rnode.parent.data.quantity&&rnode.parent.data.quantity!=0&&rnode.parent.data.quantity!=""){
+                        rnode.data.contain = projectObj.project.Ration.getContain(rnode.parent,rnode.data.quantity);
+                       /* if(rnode.parent.data.quantity&&rnode.parent.data.quantity!=0&&rnode.parent.data.quantity!=""){
                             var billQuantity = scMathUtil.roundForObj(rnode.parent.data.quantity,getDecimal("quantity",node.parent));
                             rnode.data.contain = scMathUtil.roundForObj(rnode.data.quantity/billQuantity,getDecimal("process"));
                         }else {
                             rnode.data.contain=0;
-                        }
+                        }*/
                         rnode.change = true;
                         rationNodes.push(rnode)
                     }

+ 15 - 0
web/building_saas/main/js/views/project_view.js

@@ -1430,6 +1430,21 @@ var projectObj = {
                         return projectObj.project.isInstall();
                     }
                 },
+                "cleanzmhs":{
+                    name:'清空子目换算',
+                    icon: 'fa-remove',
+                    callback: function (key, opt) {
+                        let selected = project.mainTree.selected;
+                        projectObj.project.Ration.updateRationCodes([{'node':selected, value:selected.data.code}],true);
+                    },
+                    visible: function(key, opt){
+                        let selected = project.mainTree.selected;
+                        if (selected && selected.sourceType == ModuleNames.ration) {
+                            return true;
+                        }
+                        return false;
+                    }
+                },
                 "delete": {
                     name: '删除',
                     icon: 'fa-remove',