瀏覽代碼

bug fixed

zhangweicheng 7 年之前
父節點
當前提交
6751a678f6

+ 8 - 3
modules/complementary_ration_lib/models/searchModel.js

@@ -10,8 +10,8 @@ let stdRationModel = require ('../../ration_repository/models/ration_item').Mode
 
 class SearchDao{
     async getRationItem(userId, rationRepId, code, callback){
+        let ration = null;
         try{
-            let ration = null;
             let stdRation = await stdRationModel.findOne({rationRepId: rationRepId, code: code, $or: [{isDeleted: null}, {isDeleted: false}]});
             if(isDef(stdRation)){
                 ration = stdRation._doc;
@@ -36,11 +36,16 @@ class SearchDao{
                     }
                 }
             }
-            callback(0, ration);
+            if(callback){
+                callback(0, ration);
+            }
         }
         catch(err){
-            callback(err, null);
+            if(callback){
+                callback(err, null);
+            }
         }
+        return ration;
     }
 
     async findRation(userId, rationRepId, keyword, callback){

+ 1 - 1
modules/glj/models/glj_list_model.js

@@ -114,7 +114,7 @@ class GLJListModel extends BaseModel {
             // 整理数据 得到总定额消耗量
             for (let tmp of quantityData) {
                 let tmpNum = parseFloat(tmp.rationQuantity);
-                tmpNum = isNaN(tmpNum) ||tmpNum==0? 1 : tmpNum;
+                tmpNum = isNaN(tmpNum) ||tmpNum==0? 0 : tmpNum;
                 let tmp_con_key = keyMap[tmp.projectGLJID];
 
                 if (quantityList[tmp_con_key] === undefined) {

+ 1 - 1
modules/glj/models/unit_price_model.js

@@ -300,7 +300,7 @@ class UnitPriceModel extends BaseModel {
             let consumption = scMathUtil.roundForObj(mixRatioMap[pk].consumption,quantity_decimal);
             sumPrice +=scMathUtil.roundForObj(price*consumption,price_decimal);
         }
-        sumPrice= scMathUtil.roundForObj(sumPrice,-price_decimal);
+        sumPrice= scMathUtil.roundForObj(sumPrice,price_decimal);
         if(sumPrice<=0){
             return null;
         }

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

@@ -3,6 +3,7 @@
  */
 var rationData = require('../models/ration');
 var ration_glj_facade = require('../../ration_glj/facade/ration_glj_facade');
+var ration_facade = require('../facade/ration_facade');
 let logger = require("../../../logs/log_helper").logger;
 
 //统一回调函数
@@ -42,8 +43,28 @@ module.exports = {
             }
         });
     },
-    insertGLJAsRation:insertGLJAsRation
+    insertGLJAsRation:insertGLJAsRation,
+    replaceRations:replaceRations
 };
+async function replaceRations(req,res) {
+    let result={
+        error:0
+    }
+    try {
+        let data = req.body.data;
+        data = JSON.parse(data);
+        let userID = req.session.sessionUser.ssoId;
+        console.log(data);
+        await ration_facade.replaceRations(userID,data);
+        result.data={};
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+    }
+    res.json(result);
+};
+
 
 async function insertGLJAsRation(req, res){
     let result={

+ 182 - 0
modules/main/facade/ration_facade.js

@@ -0,0 +1,182 @@
+/**
+ * Created by zhang on 2018/2/9.
+ */
+let mongoose = require('mongoose');
+import SearchDao from '../../complementary_ration_lib/models/searchModel';
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
+let ration_glj_facade = require("../../ration_glj/facade/ration_glj_facade")
+let quantity_detail = require("../facade/quantity_detail_facade");
+let ration_glj = mongoose.model('ration_glj');
+let ration_coe = mongoose.model('ration_coe');
+let ration_model = require('../models/ration');
+var bill_model = require('../models/bills');
+let decimal_facade = require('./decimal_facade');
+const uuidV1 = require('uuid/v1');
+let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
+
+module.exports = {
+    replaceRations: replaceRations
+};
+
+async function replaceRations(uerID,data) {
+    let searchDao = new SearchDao();
+    let recodes = [];
+    for(let recode of data.nodeInfo){
+        let stdRation = await searchDao.getRationItem(uerID,data.libID,recode.newCode);
+        let newRecode = await replaceRation(recode,stdRation,data.projectID,data.calQuantity);
+        if(newRecode){
+            recodes.push(newRecode);
+        }else {
+            break;
+        }
+    }
+    return recodes;
+}
+
+async function replaceRation(nodeInfo,stdRation,projectID,calQuantity) {
+    if(stdRation){
+        await deleRationSubRecode(projectID,nodeInfo.ID);
+        let newRation = await updateRation(stdRation,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
+        let ration_gljs = await addRationGLJ(stdRation,newRation);
+        //console.log(newRation);
+        //ration_model.model.bulkWrite(rationTask);//删除定额
+        console.log(newRation);
+        return newRation;
+    }else {
+        return null;
+    }
+}
+
+async function addRationCoe(std,newRation) {
+    let ration_coe_list = [];
+    if(std.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
+
+    }
+
+
+    var criteria= {};
+    criteria.ration_coe_list = [];
+    var dataLength = 0;
+    if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
+        dataLength = data.rationCoeList.length
+    }
+    for(var i=0;i<=dataLength;i++){;
+        var newCoe = {
+            libID :data.rationRepId,
+            rationID:newRation.ID,
+            projectID :  newRation.projectID
+        }
+        if(i==dataLength){
+            newCoe.coeID=-1;
+            newCoe.name = '自定义系数';
+            newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
+            newCoe.isAdjust=0;
+            newCoe.coes = this.getCustomerCoeData();
+        }else {
+            newCoe.coeID= data.rationCoeList[i].ID;
+        }
+        criteria.ration_coe_list.push(newCoe);
+    }
+}
+
+
+async function addRationGLJ(std,newRation) {
+    let newRationGLJList = [];
+    let rationGLJShowList = [];
+    if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
+        for(let sub of std.rationGljList){
+            let newGLJ = {};
+            newGLJ.ID = uuidV1();
+            newGLJ.projectID = newRation.projectID;
+            newGLJ.GLJID = sub.gljId;
+            newGLJ.rationID = newRation.ID;
+            newGLJ.billsItemID = newRation.billsItemID,
+            newGLJ.rationItemQuantity = sub.consumeAmt;
+            newGLJ.quantity = sub.consumeAmt;
+            newGLJ.glj_repository_id = std.rationRepId;
+            let std_glj = await std_glj_lib_gljList_model.findOne({'ID': ration_glj.GLJID});
+            if(std_glj){
+                newGLJ.name = std_glj.name;
+                newGLJ.code = std_glj.code;
+                newGLJ.original_code = std_glj.code;
+                newGLJ.unit = std_glj.unit;
+                newGLJ.specs = std_glj.specs;
+                newGLJ.basePrice = std_glj.basePrice;
+                newGLJ.shortName = std_glj.shortName;
+                newGLJ.type = std_glj.gljType;
+                newGLJ.repositoryId = std_glj.repositoryId;
+                newGLJ.adjCoe = std_glj.adjCoe;
+               let info = await  ration_glj_facade.getInfoFromProjectGLJ(newGLJ);
+                newGLJ = ration_glj_facade.createNewRecord(info);
+                newRationGLJList.push(newGLJ);
+                rationGLJShowList.push(info);
+            }
+        }
+    }
+    if(newRationGLJList.length>0){
+        await ration_glj.insertMany(newRationGLJList);
+    }
+    return rationGLJShowList;
+}
+
+async function deleRationSubRecode(projectID,rationID) {//删除挂在定额下的数据,如工程量明细,定额工料机等
+    let delete_query={projectID: projectID, rationID: rationID};
+    //删除工程量明细
+    await quantity_detail.deleteByQuery(delete_query) ;
+    await ration_coe.deleteMany(delete_query);//删除附注条件
+    await ration_glj.deleteMany(delete_query);//删除定额工料机
+    //todo 删除安装
+
+}
+
+async function  updateRation(std,rationID,billsItemID,projectID,calQuantity) {
+    // insertNewRation
+    let ration ={};
+    ration.code = std.code;
+    ration.name = std.name;
+    ration.caption = std.caption;
+    ration.unit = std.unit;
+    ration.libID = std.rationRepId;
+    ration.content = std.jobContent;
+    ration.adjustState = '';
+    if (std.chapter) {
+        ration.comments = std.chapter.explanation;
+        ration.ruleText = std.chapter.ruleText;
+    }
+    ration.from = std.type === 'complementary' ? 'cpt' : 'std';
+    ration.programID = std.feeType;
+    ration.rationAssList = [];//生成辅助定额
+    if(std.hasOwnProperty('rationAssList')&&std.rationAssList.length>0){
+        for(var i=0;i<std.rationAssList.length;i++){
+            var ass = std.rationAssList[i];
+            ass.actualValue = ass.stdValue;
+            ration.rationAssList.push(ass);
+        }
+    }
+    if(calQuantity){
+       await CalculateQuantity(ration,billsItemID,projectID);
+    }
+    let newRation = await ration_model.model.findOneAndUpdate({ID:rationID,projectID:projectID},ration,{new: true});
+    return newRation;
+}
+async function CalculateQuantity (ration,billsItemID,projectID) {
+    // calculate ration Quantity
+    let decimalObject =await decimal_facade.getProjectDecimal(projectID);
+    let quantity_decimal = (decimalObject&&decimalObject.ration&&decimalObject.ration.quantity)?decimalObject.ration.quantity:3;
+    let pbill = await bill_model.model.findOne({projectID:projectID,ID:billsItemID});
+    let billsQuantity = pbill.quantity ? pbill.quantity : 0;
+    let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit);
+    billsQuantity=scMathUtil.roundForObj(billsQuantity,bill_decimal);
+    ration.quantityEXP="QDL";
+    ration.quantity = scMathUtil.roundForObj(billsQuantity / FilterNumberFromUnit(ration.unit),quantity_decimal);//不管是否打勾都做转换
+    ration.contain =  scMathUtil.roundForObj(ration.quantity/billsQuantity,6);
+};
+
+function FilterNumberFromUnit (unit) {
+    let reg = new RegExp('^[0-9]+');
+    if (reg.test(unit)) {
+        return parseInt(unit.match(reg)[0]);
+    } else {
+        return 1;
+    }
+};

+ 28 - 0
modules/main/models/ration_installation.js

@@ -0,0 +1,28 @@
+/**
+ * Created by zhang on 2018/2/8.
+ */
+
+var mongoose = require('mongoose'),
+    Schema = mongoose.Schema;
+
+var ration_installation = new Schema({
+    ID:String,
+    libID:Number,
+    projectID: Number,
+    rationID:String,
+    sectionId: String, //分册章节id
+    feeItemId:String,
+    ruleId:String,
+    itemName:String,
+    code: String,
+    rule: String,
+    base: String,
+    feeRate: Number,
+    labour: Number,
+    material: Number,
+    machine: Number,
+    position: String,//记取位置
+    billID:String//记取位置对应的清单ID
+},{versionKey:false});
+
+mongoose.model('ration_installation', ration_installation);

+ 1 - 1
modules/main/routes/ration_route.js

@@ -10,7 +10,7 @@ module.exports = function (app) {
     rationRouter.post('/getItemTemplate', rationController.getItemTemplate);
     rationRouter.post('/allocIDs', rationController.allocIDs);
     rationRouter.post('/insertGLJAsRation', rationController.insertGLJAsRation);
-
+    rationRouter.post('/replaceRations', rationController.replaceRations);
 
     app.use('/ration', rationRouter);
 };

+ 3 - 1
modules/ration_glj/facade/ration_glj_facade.js

@@ -39,7 +39,9 @@ module.exports = {
     updateRationGLJByEdit: updateRationGLJByEdit,
     getGLJClass: getGLJClass,
     insertGLJAsRation: insertGLJAsRation,
-    getRationTypeGLJQuantity:getRationTypeGLJQuantity
+    getRationTypeGLJQuantity:getRationTypeGLJQuantity,
+    getInfoFromProjectGLJ:getInfoFromProjectGLJ,
+    createNewRecord:createNewRecord
 }
 
 let operationMap = {

+ 8 - 3
web/building_saas/main/js/models/quantity_detail.js

@@ -527,6 +527,11 @@ var quantity_detail = {
                     }else {//如果表达式是一个计算式,则要加一个括号
                         node.data.quantityEXP = "("+EXPString+") * "+times;
                     }
+                    if(node.data.contain!=0){
+                       let billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
+                       let temValue = scMathUtil.roundForObj(value*times,getDecimal("quantity",node));
+                        node.data.contain = scMathUtil.roundForObj(temValue/billQuantity,getDecimal("process"));
+                    }
                 }
             }
             return value;
@@ -611,15 +616,15 @@ var quantity_detail = {
         quantity_detail.prototype.updateRationQuantity=function(value,node,quantityEXP,editingText){
             node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
             value = scMathUtil.roundForObj(value,getDecimal("ration.quantity"));
+            value = project.quantity_detail.autoTransformQuantity(value,node);
+            value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node))
+            node.data.quantity=value;
             if(node.parent.data.quantity&&node.parent.data.quantity!=0&&node.parent.data.quantity!=""){
                 var billQuantity = scMathUtil.roundForObj(node.parent.data.quantity,getDecimal("quantity",node.parent));
                 node.data.contain = scMathUtil.roundForObj(value/billQuantity,getDecimal("process"));
             }else {
                 node.data.contain=0;
             }
-            value = project.quantity_detail.autoTransformQuantity(value,node);
-            value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node))
-            node.data.quantity=value;
             node.changed = true;
             project.calcProgram.calcAndSave(node);
             projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机总消耗量

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

@@ -356,14 +356,28 @@ var Ration = {
                 let billsNode = this.project.Bills.tree.findNode(ration[this.project.masterField.ration]);
                 let billsQuantity = billsNode.data.quantity ? billsNode.data.quantity : 0;
                 billsQuantity=scMathUtil.roundForObj(billsQuantity,quantity_decimal);
-                ration.contain = 1;
                 ration.quantityEXP="QDL";
-                if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit')) {
+               /* if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit')) {
                     ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);
                 } else {
                     ration.quantity = billsQuantity.toDecimal(quantity_decimal);
-                }
+                }*/
+                ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);//改成不管是否打勾都做转换
+                ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,process_decimal);
+            }
+        };
+        ration.prototype.updateRationCodes = function (recodes) {
+            let libID = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
+            let projectID = projectInfoObj.projectInfo.ID;
+            let nodeInfo =[];
+            for(let r of recodes){
+                nodeInfo.push({ID:r.node.data.ID,billsItemID:r.node.data.billsItemID,newCode:r.value});
             }
+            let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
+            CommonAjax.post("/ration/replaceRations",{nodeInfo:nodeInfo,libID:libID,projectID:projectID,calQuantity:calQuantity},function (data) {
+                console.log(data);
+            })
+
         };
 
         ration.prototype.replaceRation = function (ration, std) {

+ 2 - 2
web/building_saas/main/js/views/glj_view.js

@@ -820,7 +820,7 @@ var gljOprObj = {
             node = node ? node : projectObj.project.mainTree.selected;
             let ration = node.data;
             let quantity = ration.quantity;
-            quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
+            quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
             for (let glj of this.sheetData) {
                 glj.totalQuantity= this.getTotalQuantity(glj,ration);
             }
@@ -830,7 +830,7 @@ var gljOprObj = {
         ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
         if(ration){
             let quantity = ration.quantity;
-            quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
+            quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
             if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
                 return;
             }

+ 26 - 2
web/building_saas/main/js/views/installation_fee_view.js

@@ -3,6 +3,23 @@
  */
 let installationFeeObj={
     rationInstallSheet:null,
+    rationInstallData:null,
+    rationInstallSetting:{
+   /*     header: [
+            {headerName: "分册章节", headerWidth: 150, dataCode: "name", dataType: "String"},
+            {headerName: "费用规则", headerWidth: 220, dataCode: "rule", hAlign: "left", dataType: "String",getText:'forRule'},
+            {headerName: "编码", headerWidth: 70, dataCode: "code", hAlign: "left", dataType: "String"},
+            {headerName: "基数", headerWidth: 80, dataCode: "base", hAlign: "left", dataType: "String",cellType:'comboBox',options:installSectionBase},
+            {headerName: "费率(%)", headerWidth: 80, dataCode: "feeRate", hAlign: "right", dataType: "String"},
+            {headerName: "其中人工(%)", headerWidth: 100, dataCode: "labour", hAlign: "right", dataType: "String"},
+            {headerName: "其中材料(%)", headerWidth: 100, dataCode: "material", hAlign: "right", dataType: "String"},
+            {headerName: "其中机械(%)", headerWidth: 100, dataCode: "machine", hAlign: "right", dataType: "String"},
+            {headerName: "记取位置", headerWidth: 100, dataCode: "position", hAlign: "left", dataType: "String",cellType:'selectButton'}
+        ],
+        view: {
+            lockColumns: [0, 2]
+        }*/
+    },
     feeItemSpread:null,
     feeItemSheet:null,
     feeItemData:null,
@@ -437,7 +454,7 @@ let installationFeeObj={
         this.moreFeeRuleSheet.name('moreFeeRuleSheet');
     },
     onFeeRuleDoubleClick:function (e,info) {
-        if(info.row){
+        if(info.row!=undefined||info!=null){
             installationFeeObj.updateFeeRuleToSection(info.row);
         }else {
             return;
@@ -711,7 +728,14 @@ let installationFeeObj={
                 $("#more_feeRule").modal({show:true});
                 return;
             }
-            updateData = me.getDetailUpdateData(feeDetail,{"feeRuleId":info.newValue},'installSection');
+            if(info.newValue == null){
+                me.refreshFeeDetailRow(info.row);
+            }else if(info.newValue == feeDetail.ruleName){
+                return;
+            }else {
+                updateData = me.getDetailUpdateData(feeDetail,{"feeRuleId":info.newValue},'installSection');
+            }
+
         }else if(fieldID == 'base'){
             if(info.newValue == null){//如果基数为空,重新刷新显示
                 me.refreshFeeDetailRow(info.row);

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

@@ -398,15 +398,23 @@ var projectObj = {
     },
     mainSpreadRangeChanged: function (sender, info) {
         let project = projectObj.project, setting = projectObj.mainController.setting;
+        let updateRationCodes = [];//更新定额编码时要用同步的方式
         if (info.changedCells.length > 0) {
             for (let changedCell of info.changedCells) {
                 let cell = info.sheet.getCell(changedCell.row, changedCell.col);
                 let node = project.mainTree.items[changedCell.row];
                 let colSetting = setting.cols[changedCell.col];
                 let value = projectObj.checkSpreadEditingText(cell.text(), colSetting);
-
-                projectObj.updateCellValue(node, value, colSetting);
+                if(colSetting.data.field=='code'&& node.sourceType == project.Ration.getSourceType() ){//如果是更新定额的编码
+                    updateRationCodes.push({'node':node,value:value});
+                }else {
+                    projectObj.updateCellValue(node, value, colSetting,cell.text());
+                }
             }
+            if(updateRationCodes.length>0){
+                project.Ration.updateRationCodes(updateRationCodes)
+            }
+
         }
     },
     checkMainSpread: function () {