瀏覽代碼

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhangweicheng 7 年之前
父節點
當前提交
ec1af86a63

+ 39 - 53
web/building_saas/main/js/models/calc_program.js

@@ -382,12 +382,12 @@ let executeObj = {
                 };
                 return result;
             };
-            // 量价。没有具体的工料机类型,但仍然要用定额的计算程序,所以要给计算基数直接指定
-            function volumePriceFee() {
+            // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数
+            function marketPriceToBase() {
                 let result = 0;
                 if (
                     ( me.treeNode.data.subType === gljType.LABOUR && base.dispName === '定额基价人工费') ||
-                    ( me.treeNode.data.subType === gljType.GENERAL_MATERIAL && base.dispName === '定额基价材料费') ||
+                    ( baseMaterialTypes.includes(me.treeNode.data.subType) && base.dispName === '定额基价材料费') ||
                     ( me.treeNode.data.subType === gljType.GENERAL_MACHINE && base.dispName === '定额基价机械费') ||
                     ( me.treeNode.data.subType === gljType.MAIN_MATERIAL && base.dispName === '主材费') ||
                     ( me.treeNode.data.subType === gljType.EQUIPMENT && base.dispName === '设备费')
@@ -397,7 +397,7 @@ let executeObj = {
             };
 
             if (me.treeNode.data.type == rationType.volumePrice || me.treeNode.data.type == rationType.gljRation){
-                rst = volumePriceFee();
+                rst = marketPriceToBase();
             }
             else{
                 if (isSubset(base.gljTypes, [gljType.MACHINE_LABOUR]))
@@ -412,7 +412,7 @@ let executeObj = {
     HJ: function () {
         let me = this;
         let p = me.treeNode.data.calcBaseValue ? me.treeNode.data.calcBaseValue : 0;
-        let q = me.treeNode.data.quantity ? me.treeNode.data.quantity : 1;
+        let q = treeNodeTools.uiQuantity(me.treeNode) ? treeNodeTools.uiQuantity(me.treeNode) : 1;
         let u = (p / q).toDecimal(decimalObj.decimal('unitPrice', me.treeNode));
         return u;
     }
@@ -527,6 +527,9 @@ let treeNodeTools = {
         else {
             return treeNodeCalcType.ctRationCalcProgram;
         };
+    },
+    uiQuantity(treeNode){
+        return parseFloatPlus(treeNode.data.quantity).toDecimal(decimalObj.decimal("quantity", treeNode));
     }
 };
 
@@ -819,22 +822,15 @@ class CalcProgram {
             }
             else{
                 if (!treeNode.data.gljList) return;
-
-                let eTypes = [
-                    gljType.GENERAL_MATERIAL, gljType.MAIN_MATERIAL, gljType.EQUIPMENT,
-                    gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO,
-                    gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR];
-                let eDetailTypes = [gljType.MAIN_MATERIAL, gljType.CONCRETE, gljType.MORTAR, gljType.MIX_RATIO];
-
                 let GLJObjs = [];
                 for (let glj of treeNode.data.gljList) {
-                    if (eTypes.indexOf(glj.type) >= 0) {
+                    if (allMaterialTypes.indexOf(glj.type) >= 0) {
                         if (glj.isEstimate){
                             GLJObjs.push({code: glj.code, name: glj.name, specs: glj.specs, unit: glj.unit, type: glj.type,
                                 quantity: glj.quantity, marketPrice: glj.marketPrice});
                         }
                         else{   // 组成物
-                            if (eDetailTypes.indexOf(glj.type) >= 0){
+                            if (compositionTypes.indexOf(glj.type) >= 0){
                                 let mds = projectObj.project.composition.getCompositionByGLJ(glj);
                                 if (!mds) mds = [];
                                 for (let md of mds){
@@ -850,7 +846,8 @@ class CalcProgram {
                                             }
                                         };
                                         if (!isExist)
-                                            GLJObjs.push({code: md.code, quantity: mdQ, marketPrice: md.marketPrice});
+                                            GLJObjs.push({code: md.code, name: md.name, specs: md.specs, unit: md.unit, type: md.type,
+                                                quantity: mdQ, marketPrice: md.marketPrice});
                                     }
                                 }
                             }
@@ -868,7 +865,7 @@ class CalcProgram {
                 };
                 sumU = sumU.toDecimal(decimalObj.bills.unitPrice);
                 if (projectObj.project.property.zanguCalcMode == zanguCalcType.common){
-                    sumT = (parseFloatPlus(treeNode.data.quantity) * sumU).toDecimal(decimalObj.bills.totalPrice);
+                    sumT = (treeNodeTools.uiQuantity(treeNode) * sumU).toDecimal(decimalObj.bills.totalPrice);
                 }
                 else if (projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial){
                     sumT = sumT.toDecimal(decimalObj.bills.totalPrice);
@@ -905,13 +902,11 @@ class CalcProgram {
             };
         };
 
-        // 父清单汇总子项(定额或子清单)的费用类别
-        if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees ||
-            treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
+        // 父清单汇总子项(子清单或定额)的费用类别
+        if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees || treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){
             treeNode.data.programID = null;
             treeNodeTools.initFees(treeNode);
-
-            let objsArr = (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees) ? me.project.Ration.getRationsByNode(treeNode) : treeNode.children;
+            let nodes = (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees) ? treeNode.children : me.project.Ration.getRationNodes(treeNode);
             let rst = [];
             for (let ft of cpFeeTypes) {
                 let ftObj = {};
@@ -920,45 +915,42 @@ class CalcProgram {
                 let buf = 0, btf = 0, btuf = 0, bttf = 0;
 
                 if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees){
-                    for (let item of objsArr) {
-                        let data = item.data;
-                        if (data.feesIndex && data.feesIndex[ft.type]) {
-                            buf = (buf + parseFloatPlus(data.feesIndex[ft.type].unitFee)).toDecimal(decimalObj.process);
-                            btf = (btf + parseFloatPlus(data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
-                            btuf = (btuf + parseFloatPlus(data.feesIndex[ft.type].tenderUnitFee)).toDecimal(decimalObj.process);
-                            bttf = (bttf + parseFloatPlus(data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
+                    for (let node of nodes) {
+                        if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
+                            buf = (buf + parseFloatPlus(node.data.feesIndex[ft.type].unitFee)).toDecimal(decimalObj.process);
+                            btf = (btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
+                            btuf = (btuf + parseFloatPlus(node.data.feesIndex[ft.type].tenderUnitFee)).toDecimal(decimalObj.process);
+                            bttf = (bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
                         };
                     };
                 }
                 else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees){     // 这里的算法要配合冷姐姐的神图才能看懂^_^
                     let sum_rtf = 0, sum_rttf = 0;
-                    let bq = parseFloat(treeNode.data.quantity ? treeNode.data.quantity : 1);
-
-                    for (let data of objsArr) {
-                        let rq = parseFloat(data.quantity ? data.quantity : 0);
-
+                    let bq = treeNodeTools.uiQuantity(treeNode) ? treeNodeTools.uiQuantity(treeNode) : 1;
+                    for (let node of nodes) {
+                        let rq = treeNodeTools.uiQuantity(node) ? treeNodeTools.uiQuantity(node) : 0;
                         let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
-                        if (data.feesIndex && data.feesIndex[ft.type]) {
-                            ruf = parseFloat(data.feesIndex[ft.type].unitFee);
-                            rtuf = parseFloat(data.feesIndex[ft.type].tenderUnitFee);
-                            rtf = parseFloat(data.feesIndex[ft.type].totalFee);
-                            rttf = parseFloat(data.feesIndex[ft.type].tenderTotalFee);
+                        if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
+                            ruf = parseFloat(node.data.feesIndex[ft.type].unitFee);
+                            rtuf = parseFloat(node.data.feesIndex[ft.type].tenderUnitFee);
+                            rtf = parseFloat(node.data.feesIndex[ft.type].totalFee);
+                            rttf = parseFloat(node.data.feesIndex[ft.type].tenderTotalFee);
                         };
-
                         if (me.project.property.billsCalcMode === leafBillGetFeeType.rationContent) {
                             buf = (buf + (ruf * rq / bq).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
                             btuf = (btuf + (rtuf * rq / bq).toDecimal(decimalObj.process)).toDecimal(decimalObj.process);
                         };
-
                         sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
                         sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
                     };
 
-                    if (me.project.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse || me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice) {
+                    if (me.project.property.billsCalcMode == leafBillGetFeeType.rationPriceConverse ||
+                        me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice) {
                         buf = (sum_rtf / bq).toDecimal(decimalObj.process);
                         btuf = (sum_rttf / bq).toDecimal(decimalObj.process);
                     };
-                    if (isBaseFeeType(ft.type) || (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
+                    if (isBaseFeeType(ft.type) ||
+                        (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")){
                         btf = sum_rtf;
                         bttf = sum_rttf;
                     }
@@ -1015,8 +1007,7 @@ class CalcProgram {
             }
 
             let f = treeNode.data.feeRate ? treeNode.data.feeRate : 100;
-            if (!treeNode.data.quantity) treeNode.data.quantity = 1;
-            let q = treeNode.data.quantity;
+            let q = treeNodeTools.uiQuantity(treeNode) ? treeNodeTools.uiQuantity(treeNode) : 1;
             let b = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
             let uf = (b * f * q / 100).toDecimal(decimalObj.bills.unitPrice);
             let tuf = uf;
@@ -1047,7 +1038,7 @@ class CalcProgram {
                 if (treeNode.data.type == rationType.volumePrice){
                     delete treeNode.data.gljList;
                     let muf = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
-                    let q = treeNode.data.quantity ? treeNode.data.quantity : 0;
+                    let q = treeNodeTools.uiQuantity(treeNode) ? treeNodeTools.uiQuantity(treeNode) : 0;
                     treeNode.data.marketTotalFee = (muf * q).toDecimal(decimalObj.ration.totalPrice);
                 }
                 else if (treeNode.data.type == rationType.gljRation){
@@ -1090,16 +1081,11 @@ class CalcProgram {
 
                 for (let idx of template.compiledSeq) {
                     let calcItem = template.calcItems[idx];
-
-                    let feeRate = calcItem.feeRate;
-                    if (!feeRate) feeRate = 100;    // 100%
-                    feeRate = feeRate.toDecimal(decimalObj.feeRate);
+                    let feeRate = parseFloatPlus(calcItem.feeRate) ? parseFloatPlus(calcItem.feeRate).toDecimal(decimalObj.feeRate) : 100;  // 100%
                     calcItem.unitFee = (eval(calcItem.compiledExpr) * feeRate * 0.01).toDecimal(decimalObj.decimal('unitPrice', treeNode));   // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
 
-                    let quantity = treeNode.data.quantity;
-                    if (!quantity) quantity = 0
-                    else quantity = parseFloat(quantity).toDecimal(decimalObj.decimal('quantity', treeNode));
-                    calcItem.totalFee = (calcItem.unitFee * quantity).toDecimal(decimalObj.decimal('totalPrice', treeNode));
+                    let q = treeNodeTools.uiQuantity(treeNode) ? treeNodeTools.uiQuantity(treeNode) : 0;
+                    calcItem.totalFee = (calcItem.unitFee * q).toDecimal(decimalObj.decimal('totalPrice', treeNode));
 
                     if (calcItem.fieldName) {
                         fnArr.push(calcItem.fieldName);

+ 29 - 0
web/building_saas/main/js/models/main_consts.js

@@ -46,6 +46,35 @@ const gljType = {
     EQUIPMENT: 5
 };
 
+// 计算基数 [定额基价材料费] 要用到的材料类型。
+const baseMaterialTypes = [
+    gljType.GENERAL_MATERIAL,
+    gljType.CONCRETE,
+    gljType.MORTAR,
+    gljType.MIX_RATIO,
+    gljType.COMMERCIAL_CONCRETE,
+    gljType.COMMERCIAL_MORTAR
+];
+
+// 全部材料类型。用于暂估等 (多了主材和设备)
+const allMaterialTypes = [
+    gljType.GENERAL_MATERIAL,
+    gljType.CONCRETE,
+    gljType.MORTAR,
+    gljType.MIX_RATIO,
+    gljType.COMMERCIAL_CONCRETE,
+    gljType.COMMERCIAL_MORTAR,
+    gljType.MAIN_MATERIAL,
+    gljType.EQUIPMENT
+];
+
+// 会有组成物的材料
+const compositionTypes = [
+    gljType.MAIN_MATERIAL,
+    gljType.CONCRETE,
+    gljType.MORTAR,
+    gljType.MIX_RATIO];
+
 const notEditType = [
     gljType.CONCRETE,
     gljType.MORTAR,

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

@@ -542,6 +542,7 @@ var quantity_detail = {
                     if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
                         node.data.isFromDetail=0;
                         project.quantity_detail.cleanQuantityDetail(node,true);
+                        $.bootstrapLoading.start();
                         if(node.sourceType === project.Bills.getSourceType()){
                             me.updateBillQuantity(value,node,null,editingText);
                         }else {

+ 12 - 6
web/building_saas/main/js/models/ration.js

@@ -124,12 +124,11 @@ var Ration = {
         };
 
         // CSL, 2017-11-13 取任何清单(父清单、叶子清单)下的所有定额
-        ration.prototype.getRationsByNode = function (billNode) {
-            let rations = [];
-            let sBills = 'bills';
-            if (billNode.sourceType != sBills) return rations;
+        ration.prototype.getRationNodes = function (billNode) {
+            if (billNode.sourceType != ModuleNames.bills) return [];
+
+            let rations = [], IDs = [];
 
-            let IDs = [];
             function getSubBillsIDs(node) {
                 if (!node) return;
                 if (node.sourceType != sBills) return;
@@ -151,10 +150,17 @@ var Ration = {
                 });
                 rations.push(...subRations);
             };
+
             rations.sort(function (x, y) {
                 return x.serialNo - y.serialNo;
             });
-            return rations;
+
+            let rationNodes = [];
+            for (let ration of rations){
+                  rationNodes.push(projectObj.project.mainTree.nodes['id_' + ration.ID]);
+            };
+
+            return rationNodes;
         };
 
         ration.prototype.getInsertRationData = function (billsID, preRation, rationType) {

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

@@ -25,7 +25,7 @@ let MainTreeCol = {
           if(node.sourceType === projectObj.project.ration_glj.getSourceType()){
               return gljOprObj.getTotalQuantity(node.data);
           }else {
-              return parseFloatPlus(node.data["quantity"]).toDecimal(decimalObj.decimal("quantity", node));
+              return treeNodeTools.uiQuantity(node)?treeNodeTools.uiQuantity(node):null;
           }
         },
         // CSL, 2017-11-28

+ 18 - 14
web/building_saas/main/js/views/project_view.js

@@ -311,24 +311,27 @@ var projectObj = {
         let project = projectObj.project, fieldName = colSetting.data.field;
         if(node.sourceType==project.ration_glj.getSourceType()){
             project.ration_glj.updateFromMainSpread(value,node,fieldName);
-        }else if(treeNodeTools.isGljRation(node)){
+        }
+        else if(treeNodeTools.isGljRation(node)){
             gljOprObj.updateRationTypeGLJ(value,node,fieldName);
-        } else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
+        }
+        else if (value !== calcFees.getFee(node.data, fieldName)||fieldName == 'quantity') {//工程量需要进行转换,所以做特殊处理
             if (fieldName === 'code' && !treeNodeTools.isVolumePrice(node)) {
                 projectObj.updateCode(node, value);
             }
             else if(fieldName ==='feeRate'){
                 project.FeeRate.updateFeeRateFromBills(value,node,fieldName);
-            }else if(fieldName ==='contain'){//编辑含量
+            }
+            else if(fieldName ==='contain'){//编辑含量
                 project.Ration.updateContain(value,node);
             }
             else if (fieldName === 'quantity' || fieldName === 'marketUnitFee' || fieldName === 'programID' ||
-                fieldName === 'subType' || fieldName === 'calcBase' || fieldName === 'feesIndex.common.unitFee'){
+                fieldName === 'subType' || fieldName === 'calcBase'){
                 if (fieldName === 'quantity') {
                     project.quantity_detail.editMainTreeNodeQuantity(value,node,fieldName,editingText);
                     return;
                 }
-                else if (fieldName === 'marketUnitFee' || fieldName === 'feesIndex.common.unitFee') {
+                else if (fieldName === 'marketUnitFee') {
                     if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("unitPrice", node))};
                 }
                 else if (fieldName === 'calcBase') {
@@ -345,17 +348,16 @@ var projectObj = {
                     }
                     // if (value) {value = parseFloat(value).toDecimal(decimalObj.decimal("totalPrice", node))};
                 };
-                node.changed = true;
-                if (fieldName == 'feesIndex.common.unitFee'){
-                    treeNodeTools.initFeeField(node, 'common');
-                    node.data.feesIndex.common.unitFee = value;
-                }
-                else if(fieldName !== 'calcBase'){
+
+                if(fieldName !== 'calcBase'){
                     node.data[fieldName] = value;
+                    node.changed = true;
                 }
+
                 project.calcProgram.calcAndSave(node);
                 gljOprObj.showRationGLJSheetData();
-            } else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
+            }
+            else if (node.sourceType === project.Bills.getSourceType()&&fieldName === 'unit'){//修改清单单位的时候清单工程量要重新4舍5入
                 node.data[fieldName] = value;
                 node.changed = true;
                 if(node.data.quantity){
@@ -376,9 +378,11 @@ var projectObj = {
                 }
                 projectObj.mainController.refreshTreeNode([node]);
             }
-        } else if(value==null && fieldName ==='feeRate'){
+        }
+        else if(value==null && fieldName ==='feeRate'){
             project.FeeRate.cleanFeeRateID(node);
-        } else {
+        }
+        else {
             projectObj.mainController.refreshTreeNode([node], false);
         }
     },