浏览代码

调价同步

chenshilong 5 年之前
父节点
当前提交
07a3491ed9

+ 2 - 1
modules/all_models/projects.js

@@ -38,7 +38,8 @@ const ProjectSchema = new Schema({
     },
     },
     "changeMark":String,//更新标记  feeRate:费率文件发生了改变,unitFile 单件文件发生了改变
     "changeMark":String,//更新标记  feeRate:费率文件发生了改变,unitFile 单件文件发生了改变
     "remark":String, //备注
     "remark":String, //备注
-    "fileVer": String
+    "fileVer": String,  // 创建时程序版本号
+    "lastFileVer": String  // 最新打开并计算时的程序版本号
 });
 });
 
 
 mongoose.model(collectionName, ProjectSchema, collectionName);
 mongoose.model(collectionName, ProjectSchema, collectionName);

+ 2 - 0
modules/pm/facade/pm_facade.js

@@ -102,6 +102,7 @@ import moment from 'moment-timezone';
 const { fixedFlag, SharePermissionChangeType } = require('../../../public/common_constants');
 const { fixedFlag, SharePermissionChangeType } = require('../../../public/common_constants');
 const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
 const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
 let cipher = require('../../../public/cipher');
 let cipher = require('../../../public/cipher');
+let index = require("../../system_setting/model/index");
 const compilationModel = mongoose.model('compilation');
 const compilationModel = mongoose.model('compilation');
 let qiniu = require("qiniu");
 let qiniu = require("qiniu");
 let fs = require("fs");
 let fs = require("fs");
@@ -464,6 +465,7 @@ async function copyExample(userID, compilation, projIDs,nameMap){
         data.createDateTime = newDate;
         data.createDateTime = newDate;
         data.userID = userID;
         data.userID = userID;
         data.compilation = compilation;
         data.compilation = compilation;
+        data.fileVer = await index.getVersion();
         data.shareInfo = [];
         data.shareInfo = [];
         if (data.projType !== projectType.tender) {
         if (data.projType !== projectType.tender) {
             let newData = _.cloneDeep(data);
             let newData = _.cloneDeep(data);

+ 4 - 4
modules/pm/models/project_model.js

@@ -47,6 +47,8 @@ let gljFacade = require('../../glj/facade/glj_facade');
 let logger = require("../../../logs/log_helper").logger;
 let logger = require("../../../logs/log_helper").logger;
 let BillsModel = require("../../main/models/bills").model;
 let BillsModel = require("../../main/models/bills").model;
 let _ = require('lodash');
 let _ = require('lodash');
+let index = require("../../system_setting/model/index");
+
 
 
 let Projects = mongoose.model('projects');
 let Projects = mongoose.model('projects');
 let mainColLibModel = mongoose.model('std_main_col_lib');
 let mainColLibModel = mongoose.model('std_main_col_lib');
@@ -56,8 +58,6 @@ let optionModel = mongoose.model('options');
 function ProjectsDAO() {
 function ProjectsDAO() {
 }
 }
 
 
-let G_FILE_VER = '1.0.1';
-
 ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, callback) {
 ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, callback) {
     try {//
     try {//
         let projects = await Projects.find({
         let projects = await Projects.find({
@@ -144,7 +144,7 @@ ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId
                 data.updateData['userID'] = userId;
                 data.updateData['userID'] = userId;
                 data.updateData['compilation'] = compilationId;
                 data.updateData['compilation'] = compilationId;
                 data.updateData['createDateTime'] = new Date();
                 data.updateData['createDateTime'] = new Date();
-                data.updateData['fileVer'] = G_FILE_VER;
+                data.updateData['fileVer'] = await index.getVersion();
                 if(data.updateData.projType === projectType.project){
                 if(data.updateData.projType === projectType.project){
                     //设置建设项目基本信息,多个单位工程共用
                     //设置建设项目基本信息,多个单位工程共用
                     data.updateData.property = {basicInformation: basicInformation};
                     data.updateData.property = {basicInformation: basicInformation};
@@ -368,7 +368,7 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, compilationId, datas,
                 data.updateData['userID'] = userId;
                 data.updateData['userID'] = userId;
                 data.updateData['compilation'] = compilationId;
                 data.updateData['compilation'] = compilationId;
                 data.updateData['createDateTime'] = new Date();
                 data.updateData['createDateTime'] = new Date();
-                data.updateData['fileVer'] = G_FILE_VER;
+                data.updateData['fileVer'] = index.getVersion();
                 let newProject = new Projects(data.updateData);
                 let newProject = new Projects(data.updateData);
                 newProject['srcProjectId'] = data.srcProjectId;
                 newProject['srcProjectId'] = data.srcProjectId;
                 newProject.save(function (err, result) {
                 newProject.save(function (err, result) {

+ 86 - 41
public/web/gljUtil.js

@@ -4,7 +4,7 @@
 
 
 
 
 let gljUtil = {
 let gljUtil = {
-    calcProjectGLJQuantity:function (projectGLJDatas,rationGLJDatas,rationDatas,billsDatas,q_decimal,_,scMathUtil,isTender) {
+    calcProjectGLJQuantity:function (projectGLJDatas,rationGLJDatas,rationDatas,billsDatas,q_decimal,_,scMathUtil,isReport) {
         let project_gljs = projectGLJDatas.gljList, mixRatioMap = projectGLJDatas.mixRatioMap, com_electrovalence = projectGLJDatas.com_electrovalence;
         let project_gljs = projectGLJDatas.gljList, mixRatioMap = projectGLJDatas.mixRatioMap, com_electrovalence = projectGLJDatas.com_electrovalence;
         let rations = rationDatas;
         let rations = rationDatas;
         let rationMap = _.indexBy(rations,'ID');
         let rationMap = _.indexBy(rations,'ID');
@@ -15,7 +15,7 @@ let gljUtil = {
         let materialCalcMap={};
         let materialCalcMap={};
         //养护没有分部分项消耗量这一说的所以不用管
         //养护没有分部分项消耗量这一说的所以不用管
 
 
-        let qField = isTender==true?"tenderQuantity":"quantity";
+        let qField = "quantity";
         let mField = "materialQuantity"; //材料计算的工料机消耗量
         let mField = "materialQuantity"; //材料计算的工料机消耗量
 
 
         let elecIndex = "";//记住电的标识
         let elecIndex = "";//记住电的标识
@@ -26,8 +26,9 @@ let gljUtil = {
             pglj[qField] = 0;
             pglj[qField] = 0;
             pglj[mField] = 0;
             pglj[mField] = 0;
             let gljGroup = rationGljGroup[pglj.id]?rationGljGroup[pglj.id]:[];//定额工料机没有,有可能是定额类型的工料机
             let gljGroup = rationGljGroup[pglj.id]?rationGljGroup[pglj.id]:[];//定额工料机没有,有可能是定额类型的工料机
-            let result = this.getQuantityPerGLJ(gljGroup,rations,rationMap,pglj,billIDs,tech_billIDS,q_decimal,_,scMathUtil,isTender);
+            let result = this.getQuantityPerGLJ(gljGroup,rations,rationMap,pglj,billIDs,tech_billIDS,q_decimal,_,scMathUtil);
             pglj[qField] = result.quantity;
             pglj[qField] = result.quantity;
+            pglj.tenderQuantity = result.tenderQuantity;
             quantityMap[pg_index] = pglj;
             quantityMap[pg_index] = pglj;
             if(pglj.code == gljUtil.getElecCode() && pglj.name == '电' && pglj.unit == "kW·h") elecIndex = pg_index;
             if(pglj.code == gljUtil.getElecCode() && pglj.name == '电' && pglj.unit == "kW·h") elecIndex = pg_index;
             if(pglj.unit_price.calcMaterial == 1) materialCalcMap[pg_index] = true;
             if(pglj.unit_price.calcMaterial == 1) materialCalcMap[pg_index] = true;
@@ -41,7 +42,9 @@ let gljUtil = {
                 let p_glj = quantityMap[pkey];
                 let p_glj = quantityMap[pkey];
                 if(m_glj&&p_glj&&!gljUtil.isConcreteType(p_glj.type) ){//混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去
                 if(m_glj&&p_glj&&!gljUtil.isConcreteType(p_glj.type) ){//混凝土、砂浆、配合比组成物的消耗量在定额下已经有体现了,不用再计算进去
                     let quantity = scMathUtil.roundForObj(parseFloat(p_glj[qField])*parseFloat(m.consumption),q_decimal);
                     let quantity = scMathUtil.roundForObj(parseFloat(p_glj[qField])*parseFloat(m.consumption),q_decimal);
+                    let tenderQuantity = scMathUtil.roundForObj(parseFloat(p_glj.tenderQuantity)*parseFloat(m.consumption),q_decimal);
                     m_glj[qField] =  scMathUtil.roundForObj(parseFloat(m_glj[qField])+quantity,q_decimal);
                     m_glj[qField] =  scMathUtil.roundForObj(parseFloat(m_glj[qField])+quantity,q_decimal);
+                    m_glj.tenderQuantity =  scMathUtil.roundForObj(parseFloat(m_glj.tenderQuantity)+tenderQuantity,q_decimal);
                 }
                 }
             }
             }
         }
         }
@@ -53,17 +56,21 @@ let gljUtil = {
           offSiteTransportLossRate = offSiteTransportLossRate/100;
           offSiteTransportLossRate = offSiteTransportLossRate/100;
           pglj.transportLossQuantity =  scMathUtil.roundForObj(pglj.quantity*offSiteTransportLossRate,q_decimal);
           pglj.transportLossQuantity =  scMathUtil.roundForObj(pglj.quantity*offSiteTransportLossRate,q_decimal);
           pglj.quantity = scMathUtil.roundForObj(pglj.quantity +  pglj.transportLossQuantity ,q_decimal);
           pglj.quantity = scMathUtil.roundForObj(pglj.quantity +  pglj.transportLossQuantity ,q_decimal);
+          pglj.tenderTransportLossQuantity =  scMathUtil.roundForObj(pglj.tenderQuantity*offSiteTransportLossRate,q_decimal);
+          pglj.tenderQuantity = scMathUtil.roundForObj(pglj.tenderQuantity +  pglj.tenderTransportLossQuantity ,q_decimal);
+	      if (isReport)
+	          pglj.quantity = pglj.tenderQuantity;
         }
         }
         //材料计算中,工料机的消耗量
         //材料计算中,工料机的消耗量
 
 
         //材料计算中,有可能A包含B,B包含C。。。。。等情况,为避免循环计算,只多计算一次,不做再深的嵌套处理
         //材料计算中,有可能A包含B,B包含C。。。。。等情况,为避免循环计算,只多计算一次,不做再深的嵌套处理
         // 1.先计算做为父工料机的材料计算消耗量
         // 1.先计算做为父工料机的材料计算消耗量
-        if(projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,true,projectGLJDatas.freightList,q_decimal,_,scMathUtil,isTender); //运费计算中工料机的消耗量
-        if(projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,true,projectGLJDatas.originalList,q_decimal,_,scMathUtil,isTender);//原价计算中工料机的消耗量
+        if(projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,true,projectGLJDatas.freightList,q_decimal,_,scMathUtil); //运费计算中工料机的消耗量
+        if(projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,true,projectGLJDatas.originalList,q_decimal,_,scMathUtil);//原价计算中工料机的消耗量
 
 
         // 2.再计算做为子工料机的材料计算消耗量
         // 2.再计算做为子工料机的材料计算消耗量
-        if(projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,false,projectGLJDatas.freightList,q_decimal,_,scMathUtil,isTender); //运费计算中工料机的消耗量
-        if(projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,false,projectGLJDatas.originalList,q_decimal,_,scMathUtil,isTender);//原价计算中工料机的消耗量
+        if(projectGLJDatas.freightList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,false,projectGLJDatas.freightList,q_decimal,_,scMathUtil); //运费计算中工料机的消耗量
+        if(projectGLJDatas.originalList) this.setMaterialCalcQuantity(quantityMap,materialCalcMap,false,projectGLJDatas.originalList,q_decimal,_,scMathUtil);//原价计算中工料机的消耗量
 
 
 
 
         //因为材料计算里自采材料产生的消耗量和进行材料计算的父工料机的消耗量有关,所以材料计算中的组成物的消耗量要在上一步的组成物计算完后,再计算自采材料里组成物的消耗量,所认两个组成物计算不能合并,而且乘的值也不同
         //因为材料计算里自采材料产生的消耗量和进行材料计算的父工料机的消耗量有关,所以材料计算中的组成物的消耗量要在上一步的组成物计算完后,再计算自采材料里组成物的消耗量,所认两个组成物计算不能合并,而且乘的值也不同
@@ -110,8 +117,9 @@ let gljUtil = {
         }
         }
         
         
     },
     },
-    setMaterialCalcQuantity:function (quantityMap,materialCalcMap,isParent,calcList,q_decimal,_,scMathUtil,isTender) {
-        let qField = isTender==true?"tenderQuantity":"quantity";
+    setMaterialCalcQuantity:function (quantityMap,materialCalcMap,isParent,calcList,q_decimal,_,scMathUtil) {
+        let qField = "quantity";
+        // let qField = isTender==true?"tenderQuantity":"quantity";
         for(let t of calcList){
         for(let t of calcList){
             if(quantityMap[t.connect_key] && quantityMap[t.connect_key][qField] > 0){
             if(quantityMap[t.connect_key] && quantityMap[t.connect_key][qField] > 0){
                 let rationIDMap = _.indexBy(t.rations,"ID");
                 let rationIDMap = _.indexBy(t.rations,"ID");
@@ -158,34 +166,42 @@ let gljUtil = {
        // 场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率%
        // 场外运输损耗率%+(装卸总次数-1)*每增加一次装卸损耗率%
         return (offSiteTransportLossRate + (totalLoadingTimes - 1) * handlingLossRate);
         return (offSiteTransportLossRate + (totalLoadingTimes - 1) * handlingLossRate);
     },
     },
-    getQuantityPerGLJ : function (ration_glj_list,rations,rationMap,pglj,billIDs,tech_billIDS,q_decimal,_,scMathUtil,isTender) {
+    getQuantityPerGLJ : function (ration_glj_list,rations,rationMap,pglj,billIDs,tech_billIDS,q_decimal,_,scMathUtil) {
         let result={};
         let result={};
         let quantity_sum=0;//工料机汇总消耗量
         let quantity_sum=0;//工料机汇总消耗量
+        let tender_qantity_sum = 0;
         for(let rg of ration_glj_list){
         for(let rg of ration_glj_list){
             let tem_ration = rationMap[rg.rationID];
             let tem_ration = rationMap[rg.rationID];
             let r_quantity = tem_ration?scMathUtil.roundForObj(tem_ration.quantity,q_decimal):0;
             let r_quantity = tem_ration?scMathUtil.roundForObj(tem_ration.quantity,q_decimal):0;
             let glj_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal);
             let glj_quantity = scMathUtil.roundForObj(rg.quantity, q_decimal);
+            let tender_r_quantity = r_quantity;
+            let tender_glj_quantity = glj_quantity;
             if(!r_quantity){
             if(!r_quantity){
                 continue;
                 continue;
             }
             }
-            if(isTender == true){
-                glj_quantity = this.getRationGLJTenderQuantity(rg,tem_ration,q_decimal,scMathUtil);
-                r_quantity = this.getRationTenderQuantity(tem_ration,q_decimal,scMathUtil);
+            if(!pglj.is_adjust_price){
+                tender_glj_quantity = this.getRationGLJTenderQuantity(rg,tem_ration,q_decimal,scMathUtil);
+                tender_r_quantity = this.getRationTenderQuantity(tem_ration,q_decimal,scMathUtil);
             }
             }
             let total = scMathUtil.roundForObj(glj_quantity*r_quantity, q_decimal);
             let total = scMathUtil.roundForObj(glj_quantity*r_quantity, q_decimal);
+            let tender_total = scMathUtil.roundForObj(tender_glj_quantity*tender_r_quantity, q_decimal);
             quantity_sum = scMathUtil.roundForObj(quantity_sum+total,q_decimal);
             quantity_sum = scMathUtil.roundForObj(quantity_sum+total,q_decimal);
+            tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum+tender_total,q_decimal);
         }
         }
         for(let ra of rations){//计算定额类型工料机的消耗量
         for(let ra of rations){//计算定额类型工料机的消耗量
             if(ra.type == this.rationType.gljRation&&ra.projectGLJID===pglj.id){
             if(ra.type == this.rationType.gljRation&&ra.projectGLJID===pglj.id){
                 let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
                 let r_quantity = scMathUtil.roundForObj(ra.quantity,q_decimal);
                 r_quantity = r_quantity?r_quantity:0;
                 r_quantity = r_quantity?r_quantity:0;
-                if(isTender == true){
-                    r_quantity = this.getRationTenderQuantity(ra,q_decimal,scMathUtil);
+                let tender_r_quantity = r_quantity;
+                if(!pglj.is_adjust_price){
+                  tender_r_quantity = this.getRationTenderQuantity(ra,q_decimal,scMathUtil);
                 }
                 }
                 quantity_sum = scMathUtil.roundForObj(quantity_sum+r_quantity,q_decimal);
                 quantity_sum = scMathUtil.roundForObj(quantity_sum+r_quantity,q_decimal);
+                tender_qantity_sum = scMathUtil.roundForObj(tender_qantity_sum+tender_r_quantity,q_decimal);
             }
             }
         }
         }
         result.quantity = quantity_sum;
         result.quantity = quantity_sum;
+        result.tenderQuantity = tender_qantity_sum;
         return result;
         return result;
     },
     },
     getRationGLJTenderQuantity:function (ration_glj,ration,q_decimal,scMathUtil) {
     getRationGLJTenderQuantity:function (ration_glj,ration,q_decimal,scMathUtil) {
@@ -199,18 +215,22 @@ let gljUtil = {
         let typeString = ration_glj.type +"";
         let typeString = ration_glj.type +"";
         let coeField = "";
         let coeField = "";
         for(let key in coeMap){
         for(let key in coeMap){
-            if(typeString.indexOf(key)!= -1){
-                coeField = coeMap[key];
+            if(typeString.indexOf(key) == 0){
+              coeField = coeMap[key];
+              break;
             }
             }
         }
         }
-        let coe = ration.quantityCoe&&this.isNotEmpty(ration.quantityCoe[coeField])?ration.quantityCoe[coeField]:1;
+        let coe = 1;
+        coe = ration.quantityCoe&&this.isNotEmpty(ration.quantityCoe[coeField])?ration.quantityCoe[coeField]:1;
         coe = parseFloat(coe);
         coe = parseFloat(coe);
+        if (coe == 0) coe = 1;
         let glj_quantity = scMathUtil.roundForObj(ration_glj.quantity, q_decimal);
         let glj_quantity = scMathUtil.roundForObj(ration_glj.quantity, q_decimal);
         return scMathUtil.roundForObj(glj_quantity * coe,q_decimal);
         return scMathUtil.roundForObj(glj_quantity * coe,q_decimal);
     },
     },
     getRationTenderQuantity:function (ration,q_decimal,scMathUtil) {
     getRationTenderQuantity:function (ration,q_decimal,scMathUtil) {
         let rationQuantityCoe = this.isNotEmpty(ration.rationQuantityCoe)?ration.rationQuantityCoe:1;
         let rationQuantityCoe = this.isNotEmpty(ration.rationQuantityCoe)?ration.rationQuantityCoe:1;
         rationQuantityCoe = parseFloat(rationQuantityCoe);
         rationQuantityCoe = parseFloat(rationQuantityCoe);
+        if (rationQuantityCoe == 0) rationQuantityCoe = 1;
         let r_quantity = ration?scMathUtil.roundForObj(ration.quantity,q_decimal):0;
         let r_quantity = ration?scMathUtil.roundForObj(ration.quantity,q_decimal):0;
         return scMathUtil.roundForObj(r_quantity * rationQuantityCoe,q_decimal);
         return scMathUtil.roundForObj(r_quantity * rationQuantityCoe,q_decimal);
     },
     },
@@ -258,9 +278,14 @@ let gljUtil = {
     getFlag:function (b) {
     getFlag:function (b) {
         return _.find(b.flags,{"fieldName":"fixed"});
         return _.find(b.flags,{"fieldName":"fixed"});
     },
     },
-    getGLJPrice:function (glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,ext) {
+    getGLJPrice:function (glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,ext,tenderCoe, isReport) {
         let result = {};
         let result = {};
-        result.marketPrice = this.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,null,ext);
+        if(isReport){
+            result.marketPrice = this.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe,ext);
+        }else {
+            result.marketPrice = this.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
+            result.tenderPrice = this.getMarketPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil,tenderCoe);
+        }
         if(this.calcPriceDiff(glj,calcOptions)==true){//计取价差
         if(this.calcPriceDiff(glj,calcOptions)==true){//计取价差
             result.basePrice = this.getBasePrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
             result.basePrice = this.getBasePrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
             result.adjustPrice = this.getAdjustPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
             result.adjustPrice = this.getAdjustPrice(glj,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
@@ -277,6 +302,8 @@ let gljUtil = {
         let quantity_decimal = decimalObj.glj.quantity;
         let quantity_decimal = decimalObj.glj.quantity;
         let process_decimal = decimalObj.process;
         let process_decimal = decimalObj.process;
         let priceCoe = this.isDef(tenderCoe)?tenderCoe:1;
         let priceCoe = this.isDef(tenderCoe)?tenderCoe:1;
+        if (priceCoe == '0' || priceCoe == 0) priceCoe = 1;   // 这里加个保护
+        if (['GLF', 'LR', 'FXF'].includes(glj.code)) priceCoe = 1; // 类型是“企业管理费”、“利润”、“一般风险费”的,不应调整单价。
         if (!this.isConcreteType(glj.unit_price.type)&& this.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于机械台班等有组成物的材料,价格需根据组成物计算得出(排除混凝土、配合比、砂浆这几个类型直接为0)。
         if (!this.isConcreteType(glj.unit_price.type)&& this.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于机械台班等有组成物的材料,价格需根据组成物计算得出(排除混凝土、配合比、砂浆这几个类型直接为0)。
             let p =0;
             let p =0;
             for(let ratio of glj.ratio_data){
             for(let ratio of glj.ratio_data){
@@ -285,12 +312,15 @@ let gljUtil = {
                   return rIndex == gljUtil.getIndex(item);
                   return rIndex == gljUtil.getIndex(item);
                 });
                 });
                 if(tem){
                 if(tem){
-                    let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
+		            let tem_marketPrice = this.getMarketPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
                     if(ext && ext[tem.id] && this.isDef(ext[tem.id].marketPrice)){//在修改组成物的价格或消耗量时,影响了父工料机的价格,这时以父工料机的价格应当用组成物的新值来记算
                     if(ext && ext[tem.id] && this.isDef(ext[tem.id].marketPrice)){//在修改组成物的价格或消耗量时,影响了父工料机的价格,这时以父工料机的价格应当用组成物的新值来记算
-                        priceData.marketPrice = ext[tem.id].marketPrice;
-                    }
-                    let temP = scMathUtil.roundForObj(priceData.marketPrice* priceCoe * scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
-                    p = scMathUtil.roundForObj(temP + p,process_decimal);
+                        tem_marketPrice = ext[tem.id].marketPrice;
+                    };
+
+		            let temP = scMathUtil.roundForObj(
+                        scMathUtil.roundForObj(tem_marketPrice * priceCoe, price_decimal) *
+                        scMathUtil.roundForObj(ratio.consumption,quantity_decimal), process_decimal);
+                    p = scMathUtil.roundForObj(temP + p, process_decimal);
                 }
                 }
             }
             }
             return scMathUtil.roundForObj(p,price_hasM_decimal);
             return scMathUtil.roundForObj(p,price_hasM_decimal);
@@ -308,22 +338,22 @@ let gljUtil = {
 
 
         if (this.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
         if (this.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0) {//对于混凝土、配合比、砂浆、机械台班等有组成物的材料,价格需根据组成物计算得出。
             //2018-09-07 需求修改,定额价不按组成物的量和价实时计算出来,直接取单价文件中的定额价
             //2018-09-07 需求修改,定额价不按组成物的量和价实时计算出来,直接取单价文件中的定额价
-            /*     let p =0;
-             for(let ratio of glj.ratio_data){
-             let tem =  _.find( projectGLJDatas.gljList,{
-             'code': ratio.code,
-             'name': ratio.name,
-             'specs':ratio.specs,
-             'type': ratio.type,
-             'unit': ratio.unit
-             });
-             if(tem){
-             let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
-             let temP = scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
-             p = scMathUtil.roundForObj(temP + p,process_decimal);
-             }
-             }
-             return scMathUtil.roundForObj(p,price_hasM_decimal);*/
+       /*     let p =0;
+            for(let ratio of glj.ratio_data){
+                let tem =  _.find( projectGLJDatas.gljList,{
+                    'code': ratio.code,
+                    'name': ratio.name,
+                    'specs':ratio.specs,
+                    'type': ratio.type,
+                    'unit': ratio.unit
+                });
+                if(tem){
+                    let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
+                    let temP = scMathUtil.roundForObj(priceData.basePrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
+                    p = scMathUtil.roundForObj(temP + p,process_decimal);
+                }
+            }
+            return scMathUtil.roundForObj(p,price_hasM_decimal);*/
 
 
             return scMathUtil.roundForObj(glj.unit_price.base_price,price_hasM_decimal);
             return scMathUtil.roundForObj(glj.unit_price.base_price,price_hasM_decimal);
         }else {
         }else {
@@ -468,6 +498,8 @@ let gljUtil = {
             quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
             quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
             quantity = scMathUtil.roundForObj(quantity, rd);//计算前进行4舍5入
             quantity = scMathUtil.roundForObj(quantity, rd);//计算前进行4舍5入
             glj.quantity = scMathUtil.roundForObj(glj.quantity, gd);
             glj.quantity = scMathUtil.roundForObj(glj.quantity, gd);
+            glj.tenderQuantity = this.getRationGLJTenderQuantity(glj, ration, gd, scMathUtil);
+
             return scMathUtil.roundToString(quantity * glj.quantity, gd);
             return scMathUtil.roundToString(quantity * glj.quantity, gd);
         }
         }
     },
     },
@@ -517,6 +549,19 @@ let gljUtil = {
     getElecCode:function () {
     getElecCode:function () {
         return '3005002';
         return '3005002';
     },
     },
+    getTenderPriceCoe : function(glj,tproperty){
+        let tenderCoe = 1;
+        let property = tproperty?tproperty:projectObj.project.property;
+        if (!glj.is_adjust_price&&property.tenderSetting && isDef(property.tenderSetting.gljPriceTenderCoe) ){
+            tenderCoe = parseFloat(property.tenderSetting.gljPriceTenderCoe);
+            if (tenderCoe == 0) tenderCoe = 1;
+        }
+        return tenderCoe;
+
+        function isDef (v) {
+            return v !== undefined && v !== null;
+        }
+    },
     setProperty:function(Obj,updateData) {
     setProperty:function(Obj,updateData) {
         for(let ukey in updateData){
         for(let ukey in updateData){
             if(_.isObject(updateData[ukey]) && _.isObject(Obj[ukey])&&!_.isArray(updateData[ukey])){
             if(_.isObject(updateData[ukey]) && _.isObject(Obj[ukey])&&!_.isArray(updateData[ukey])){

+ 18 - 8
web/building_saas/main/js/models/calc_program.js

@@ -342,17 +342,13 @@ let calcTools = {
         let price = 0, temp = 0, temp2 = 0;
         let price = 0, temp = 0, temp2 = 0;
         for (let glj of treeNode.data.gljList) {
         for (let glj of treeNode.data.gljList) {
             if (gljTypes.indexOf(glj.type) >= 0) {
             if (gljTypes.indexOf(glj.type) >= 0) {
-                if (isTender){
-                    calcTools.calcGLJTenderPrice(glj);
-                    calcTools.calcGLJTenderQty(treeNode, glj);
-                };
 
 
                 let gljQ = isTender ? me.uiGLJQty(glj["tenderQuantity"]) : me.uiGLJQty(glj["quantity"]);
                 let gljQ = isTender ? me.uiGLJQty(glj["tenderQuantity"]) : me.uiGLJQty(glj["quantity"]);
-                let mprice = isTender ? me.uiGLJPrice(glj["tenderPrice"], glj) : me.uiGLJPrice(glj["marketPrice"], glj);
-                let aprice = calcTools.hasAdjustPrice() ? me.uiGLJPrice(glj["adjustPrice"], glj) : me.uiGLJPrice(glj["basePrice"], glj);
+                let mprice = isTender ? glj["tenderPrice"] : glj["marketPrice"];
+                let aprice = calcTools.hasAdjustPrice() ? glj["adjustPrice"] : glj["basePrice"];
 
 
-                        // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
-                        if (priceType == priceTypes.ptBasePrice){ price = glj["basePrice"];}
+                // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
+                if (priceType == priceTypes.ptBasePrice){ price = glj["basePrice"];}
                 else if (priceType == priceTypes.ptAdjustPrice){price = aprice;}
                 else if (priceType == priceTypes.ptAdjustPrice){price = aprice;}
                 else if (priceType == priceTypes.ptMarketPrice){price = mprice;}
                 else if (priceType == priceTypes.ptMarketPrice){price = mprice;}
 
 
@@ -2031,6 +2027,16 @@ class CalcProgram {
             $.bootstrapLoading.end();
             $.bootstrapLoading.end();
             return;
             return;
         };
         };
+
+        if (projectObj.project.projectInfo.lastFileVer != VERSION){
+            let data = {
+                ID: projectObj.project.ID(),
+                lastFileVer: VERSION
+            };
+            let newData = {'type': 'project', 'data': data};
+            dataArr.push(newData);
+        };
+
         $.bootstrapLoading.start();
         $.bootstrapLoading.start();
         me.project.updateNodes(dataArr, function (data) {
         me.project.updateNodes(dataArr, function (data) {
             for (let node of treeNodes){
             for (let node of treeNodes){
@@ -2045,6 +2051,7 @@ class CalcProgram {
             };
             };
             projectObj.mainController.refreshTreeNode(treeNodes,false,false);
             projectObj.mainController.refreshTreeNode(treeNodes,false,false);
             // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
             // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
+            projectObj.project.projectInfo.lastFileVer = VERSION;
             if (activeSubSheetIsCalcProgram())
             if (activeSubSheetIsCalcProgram())
                 calcProgramObj.refreshCalcProgram(projectObj.project.mainTree.selected, 2);
                 calcProgramObj.refreshCalcProgram(projectObj.project.mainTree.selected, 2);
             projectInfoObj.refreshTotalPriceSpan();
             projectInfoObj.refreshTotalPriceSpan();
@@ -2517,6 +2524,9 @@ class CalcProgram {
         else if (sOption =='priceBase_ZM')
         else if (sOption =='priceBase_ZM')
             tender = tenderTypes.ttReverseRation;
             tender = tenderTypes.ttReverseRation;
         if (tender == tenderTypes.ttReverseGLJ || tender == tenderTypes.ttReverseRation){
         if (tender == tenderTypes.ttReverseGLJ || tender == tenderTypes.ttReverseRation){
+            if (!tender_obj.tenderTree)
+                tender_obj.createTree();
+
             this.initReverseTenderDatas();
             this.initReverseTenderDatas();
             this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
             this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
             this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);
             this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);

+ 2 - 1
web/building_saas/main/js/views/project_view.js

@@ -989,7 +989,8 @@ var projectObj = {
                 if(projectReadOnly){
                 if(projectReadOnly){
                     disableSpread(that.mainSpread);
                     disableSpread(that.mainSpread);
                 }
                 }
-                projectObj.project.calcProgram.doTenderCalc();  // 打开标段后,进行一次全部计算,包括调价计算。
+                if (projectObj.project.projectInfo.lastFileVer != VERSION)
+                    projectObj.project.calcProgram.doTenderCalc();  // 打开标段后,进行一次全部计算,包括调价计算。
                 $.bootstrapLoading.end();
                 $.bootstrapLoading.end();
             }
             }
             else {
             else {

+ 33 - 28
web/building_saas/main/js/views/tender_price_view.js

@@ -40,17 +40,44 @@ let tender_obj={
         "headRowHeight" : [21],
         "headRowHeight" : [21],
         "cols" : []
         "cols" : []
     },
     },
+    createTree:function () {
+        let me = this;
+        if (me.tenderTree) return;
+        me.tenderTree = cacheTree.createNew(this);
+        me.tenderTreeSetting = me.createTenderTreeSetting();
+        TREE_SHEET_HELPER.initSetting($('#tenderSpread')[0], me.tenderTreeSetting );
+        me.tenderTreeSetting.setAutoFitRow = MainTreeCol.getEvent("setAutoFitRow");
+        let mainTree = projectObj.project.mainTree;
+        me.tenderTree.nodes={},me.tenderTree.selected = null,me.tenderTree.roots = [],me.tenderTree.items=[];
+
+        function createTenderNode(mainNode,parent,next) {
+            if(mainNode.sourceType != ModuleNames.ration_glj){//主材、设备的工料机不用显示
+                let newNode = me.tenderTree.addNode(parent, next, mainNode.data.ID);
+                newNode.data = mainNode.data;
+                newNode.source =  mainNode.source;
+                newNode.sourceType = mainNode.sourceType;
+                newNode.mainNode = mainNode;
+                if(mainNode.children.length > 0){
+                    for(let c of mainNode.children){
+                        createTenderNode(c,newNode,null);
+                    }
+                }
+                return newNode;
+            }
+        };
+
+        for(r of mainTree.roots){
+            createTenderNode(r,null,null);
+        };
+        me.tenderTree.sortTreeItems();
+    },
     initTenderSpread:function () {
     initTenderSpread:function () {
+        this.createTree();
         if(!this.tenderSpread){
         if(!this.tenderSpread){
             this.tenderSpread = SheetDataHelper.createNewSpread($("#tenderSpread")[0]);
             this.tenderSpread = SheetDataHelper.createNewSpread($("#tenderSpread")[0]);
             sheetCommonObj.spreadDefaultStyle(this.tenderSpread);
             sheetCommonObj.spreadDefaultStyle(this.tenderSpread);
-        }
+        };
         this.tenderSheet = this.tenderSpread.getSheet(0);
         this.tenderSheet = this.tenderSpread.getSheet(0);
-        this.tenderTree = cacheTree.createNew(this);
-        this.tenderTreeSetting = this.createTenderTreeSetting();
-        // console.log(this.tenderTreeSetting);
-        TREE_SHEET_HELPER.initSetting($('#tenderSpread')[0], this.tenderTreeSetting );
-        this.tenderTreeSetting.setAutoFitRow = MainTreeCol.getEvent("setAutoFitRow");
         this.tenderController = TREE_SHEET_CONTROLLER.createNew(this.tenderTree, this.tenderSheet, this.tenderTreeSetting);
         this.tenderController = TREE_SHEET_CONTROLLER.createNew(this.tenderTree, this.tenderSheet, this.tenderTreeSetting);
         this.tenderSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSheetValueChange);
         this.tenderSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSheetValueChange);
         this.tenderSheet.bind(GC.Spread.Sheets.Events.EnterCell, this.onEnterCell);
         this.tenderSheet.bind(GC.Spread.Sheets.Events.EnterCell, this.onEnterCell);
@@ -69,30 +96,8 @@ let tender_obj={
     },
     },
     showTenderData:function () {
     showTenderData:function () {
         let me = this;
         let me = this;
-        let mainTree = projectObj.project.mainTree;
-        this.tenderTree.nodes={},this.tenderTree.selected = null,this.tenderTree.roots = [],this.tenderTree.items=[];
-        for(r of mainTree.roots){
-            createTenderNode(r,null,null);
-        }
-        me.tenderTree.sortTreeItems();
         this.tenderSheet.setRowCount(0);
         this.tenderSheet.setRowCount(0);
         me.tenderController.showTreeData();
         me.tenderController.showTreeData();
-
-        function createTenderNode(mainNode,parent,next) {
-            if(mainNode.sourceType != ModuleNames.ration_glj){//主材、设备的工料机不用显示
-                let newNode = me.tenderTree.addNode(parent, next, mainNode.data.ID);
-                newNode.data = mainNode.data;
-                newNode.source =  mainNode.source;
-                newNode.sourceType = mainNode.sourceType;
-                newNode.mainNode = mainNode;
-                if(mainNode.children.length > 0){
-                    for(let c of mainNode.children){
-                        createTenderNode(c,newNode,null);
-                    }
-                }
-                return newNode;
-            }
-        }
     },
     },
     onTenderRangeChange:function (sender,info) {
     onTenderRangeChange:function (sender,info) {
         let me = tender_obj;
         let me = tender_obj;