Browse Source

calculate adjust price

zhangweicheng 7 years ago
parent
commit
06a5778ec2

+ 1 - 0
modules/complementary_glj_lib/models/schemas.js

@@ -52,6 +52,7 @@ let stdGljSchema = new Schema({
     gljType: Number,
     shortName: String,
     unit: String,
+    adjCoe: Number,
     component: [stdGjlComponentSchema]
 },{versionKey: false});
 

+ 3 - 2
modules/glj/models/glj_list_model.js

@@ -243,7 +243,7 @@ class GLJListModel extends BaseModel {
         glj.unit_price.base_price = glj_basePrice;
         glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
         // 计算调整基价
-        switch (glj.unit_price.type + '') {
+     /*   switch (glj.unit_price.type + '') {
             // 人工: 调整基价=基价单价*调整系数
             case GLJTypeConst.LABOUR:
                 glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj_basePrice), -2);
@@ -255,7 +255,7 @@ class GLJListModel extends BaseModel {
             // 材料、主材、设备
             default:
                 glj.adjust_price = glj.unit_price.base_price;
-        }
+        }*/
     }
 
     /**
@@ -611,6 +611,7 @@ class GLJListModel extends BaseModel {
                 specs: tmp.specs,
                 unit: tmp.unit === undefined ? '' : tmp.unit,
                 type: tmp.gljType,
+                adjCoe:tmp.adjCoe,
                 original_code:tmp.code
             };
             gljInsertData.push(gljData);

+ 2 - 5
modules/glj/models/schemas/glj.js

@@ -62,11 +62,8 @@ let modelSchema = {
         type: Number,
         default: 0
     },
-    // 调整系数
-    adjustment: {
-        type: Number,
-        default: 1
-    },
+    // 调整系数ID
+    adjCoe: Number,
 
     // 规格型号
     specs: {

+ 2 - 0
modules/ration_glj/facade/ration_glj_facade.js

@@ -125,6 +125,7 @@ function get_lib_glj_info(ration_glj) {
                 ration_glj.shortName = glj.shortName;
                 ration_glj.type = glj.gljType;
                 ration_glj.repositoryId = glj.repositoryId;
+                ration_glj.adjCoe = glj.adjCoe;
                 getInfoFromProjectGLJ(ration_glj).then(function (info) {
                     if(info){
                         let tem={};
@@ -555,6 +556,7 @@ function getGLJSearchInfo(ration_glj) {
         base_price: ration_glj.basePrice,
         market_price: ration_glj.basePrice,
         repositoryId:ration_glj.repositoryId,
+        adjCoe:ration_glj.adjCoe,
         from:ration_glj.from?ration_glj.from:'std'//std:标准工料机库, cpt:补充工料机库
     };
      if(data.from=='cpt'){//从补充工料机来的数据即为新增数据

+ 2 - 0
modules/ration_glj/models/ration_glj.js

@@ -24,6 +24,8 @@ var ration_glj = new Schema({
     shortName:String,
     billsItemID: Number,
     type:Number,
+    // 调整系数ID
+    adjCoe: Number,
     quantity:String,
     customQuantity:String,
     rationItemQuantity:String,

+ 13 - 0
public/web/scMathUtil.js

@@ -84,6 +84,19 @@ let scMathUtil = {
     roundTo: function(num, digit){
         let me = this;
         return me.innerRoundTo(me.binToFloat(me.incMantissa(me.floatToBin(num))), digit);
+    },
+    isNumber : function (obj) {
+        return obj === +obj;
+    },
+    roundToString:function(obj,decimal){
+        let me = this;
+        let value;
+        if(me.isNumber(obj)){
+            value = me.roundTo(obj,-decimal)
+        }else {
+            value = me.roundTo(Number(obj),-decimal);
+        }
+        return value.toFixed(decimal);
     }
 };
 

+ 5 - 3
public/web/sheet/sheet_common.js

@@ -126,10 +126,12 @@ var sheetCommonObj = {
                 //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
                 var val = data[row][setting.header[col].dataCode];
                 if(val&&setting.header[col].dataType === "Number"){
-                    if(setting.header[col].hasOwnProperty('tofix')){
-                        val =parseFloat(val).toFixed(setting.header[col].tofix);
+                    if(setting.header[col].hasOwnProperty('decimalField')){
+                        var decimal = getDecimal(setting.header[col].decimalField);
+                        val =scMathUtil.roundToString(val,decimal);
+                        sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
                     }else {
-                        val =parseFloat(val).toFixed(2);
+                        val =scMathUtil.roundToString(val,2);
                     }
                 }
                 if(val!=null&&setting.header[col].cellType === "checkBox"){

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

@@ -246,6 +246,7 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
     // 获取列号
     let isEvaluateColumn = this.sheetObj.getFieldColumn('is_evaluate');
     let marketPriceColumn = this.sheetObj.getFieldColumn('unit_price.market_price');
+    let adjustPriceColumn = this.sheetObj.getFieldColumn("adjust_price");
     let connectCodeColumn = this.sheetObj.getFieldColumn('connect_code');
     let consumptionColumn = this.sheetObj.getFieldColumn('consumption');
     let supplyColumn = this.sheetObj.getFieldColumn('supply');
@@ -306,7 +307,8 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             activeSheet.setValue(rowCounter, connectCodeColumn, connectCodeString);
             activeSheet.setValue(rowCounter, consumptionColumn, consumptionString);
         }
-
+        data.adjust_price = projectObj.project.projectGLJ.getAdjustPrice(data);
+        activeSheet.setValue(rowCounter,adjustPriceColumn,data.adjust_price);
         rowCounter++;
     }
 };

+ 15 - 1
web/building_saas/main/js/models/project_glj.js

@@ -212,7 +212,8 @@ ProjectGLJ.prototype.setAdjustPrice=function(glj){
     switch (glj.unit_price.type + '') {
         // 人工: 调整基价=基价单价*调整系数
         case GLJTypeConst.LABOUR:
-            glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
+        case GLJTypeConst.MACHINE_LABOUR:
+            glj.adjust_price = this.getAdjustPrice(glj);
             break;
         // 机械类型的算法
         case GLJTypeConst.MACHINE:
@@ -222,4 +223,17 @@ ProjectGLJ.prototype.setAdjustPrice=function(glj){
         default:
             glj.adjust_price = glj.unit_price.base_price;
     }
+}
+
+ProjectGLJ.prototype.getAdjustPrice = function (glj) {
+    GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
+    if(glj.unit_price.type==GLJTypeConst.LABOUR||glj.unit_price.type==GLJTypeConst.MACHINE_LABOUR){
+        let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
+        let coe = labour&&labour.coe?labour.coe:1;
+        let decimal = getDecimal("glj.unitPrice");
+        return scMathUtil.roundTo(parseFloat(coe*glj.unit_price.base_price),-decimal);
+    }else {
+        return glj.unit_price.base_price
+    }
+
 }

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

@@ -360,6 +360,7 @@ var ration_glj = {
                   basePrice:glj.basePrice,
                   shortName:glj.shortName,
                   type:glj.gljType,
+                  adjCoe:glj.adjCoe,
                   createType:'add',
                   repositoryId:glj.repositoryId
               }

+ 28 - 10
web/building_saas/main/js/views/glj_view.js

@@ -29,12 +29,12 @@ var gljOprObj = {
             {headerName: "规格型号", headerWidth: 120, dataCode: "specs", dataType: "String", hAlign: "left"},
             {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
             {headerName: "类型", headerWidth: 45, dataCode: "shortName", dataType: "String", hAlign: "center"},
-            {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right",formatter:"0.000",tofix:3},    // dataType: "Number", formatter: "0.00"
-            {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "Number", hAlign: "right",formatter:"0.000",tofix:3},
-            {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "Number", hAlign: "right",formatter:"0.000",tofix:3},
-            {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
-            {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
-            {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "Number", hAlign: "right",formatter:"0.00"},
+            {headerName: "定额消耗量", headerWidth: 80, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right",decimalField:"glj.quantity"},    // dataType: "Number", formatter: "0.00"
+            {headerName: "自定义消耗量", headerWidth: 80, dataCode: "customQuantity", dataType: "Number", hAlign: "right",decimalField:"glj.quantity"},
+            {headerName: "消耗量", headerWidth: 80, dataCode: "quantity", dataType: "Number", hAlign: "right",decimalField:"glj.quantity"},
+            {headerName: "基价单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", hAlign: "right",decimalField:"glj.unitPrice"},
+            {headerName: "调整基价", headerWidth: 80, dataCode: "adjustPrice", dataType: "Number", hAlign: "right",decimalField:"glj.unitPrice"},
+            {headerName: "市场单价", headerWidth: 80, dataCode: "marketPrice", dataType: "Number", hAlign: "right",decimalField:"glj.unitPrice"},
             {headerName: "是否暂估", headerWidth: 65, dataCode: "isEstimate", dataType: "String", hAlign: "center",vAlign:"center",cellType:"checkBox"}
         ],
         view: {
@@ -605,9 +605,10 @@ var gljOprObj = {
                 if(glj){
                     ration_gljs[i].basePrice=glj.unit_price.base_price;
                     ration_gljs[i].marketPrice=glj.unit_price.market_price;
-                    ration_gljs[i].adjustPrice=glj.adjust_price;
+                    //ration_gljs[i].adjustPrice=glj.adjust_price;
                     ration_gljs[i].isEstimate=glj.is_evaluate;
                     ration_gljs[i].isAdd=glj.unit_price.is_add;
+                    ration_gljs[i].adjustPrice=projectObj.project.projectGLJ.getAdjustPrice(glj);
                     var connect_index = this.getIndex(glj,['code','name','specs','unit','type'])
                     if(mixRatioMap.hasOwnProperty(connect_index)){
                         var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index],projectGljs);
@@ -1240,9 +1241,26 @@ $(function(){
         data.addItems = items;
         return data;
     }
-
-
 })
 
+function getDecimal(fieldID,node) {
+    if(node){
+        return decimalObj.decimal(fieldID,node);
+    }else if(fieldID.indexOf(".")){
+        var keyArray = fieldID.split(".");
+        return decimalObj[keyArray[0]][keyArray[1]];
+    }else {
+        return decimalObj.decimal(fieldID);
+    }
+}
 
-
+function getFormatter(decimal) {
+    var pre = "0.";
+    if(decimal<=0){
+        return "0";
+    }
+    for(i=0;i<decimal;i++){
+        pre += "0"
+    }
+    return pre;
+}