Procházet zdrojové kódy

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

zhangweicheng před 7 roky
rodič
revize
660c1f5a52

+ 45 - 0
modules/common/const/bills_fixed.js

@@ -0,0 +1,45 @@
+/**
+ * Created by Zhong on 2017/12/18.
+ */
+const fixedFlag = {
+    // 分部分项工程
+    SUB_ENGINERRING: 1,
+    // 措施项目
+    MEASURE: 2,
+    // 施工技术措施项目
+    CONSTRUCTION_TECH: 3,
+    // 安全文明施工按实计算费用
+    SAFETY_CONSTRUCTION_ACTUAL: 4,
+    // 施工组织措施专项费用
+    CONSTRUCTION_ORGANIZATION: 5,
+    // 安全文明施工专项费用
+    SAFETY_CONSTRUCTION: 6,
+    // 其他项目
+    OTHER: 7,
+    // 暂列金额
+    PROVISIONAL: 8,
+    // 暂估价
+    ESTIMATE: 9,
+    // 材料(工程设备)暂估价
+    MATERIAL_PROVISIONAL: 10,
+    // 专业工程暂估价
+    ENGINEERING_ESITIMATE: 11,
+    // 计日工
+    DAYWORK: 12,
+    // 总承包服务费
+    TURN_KEY_CONTRACT: 13,
+    // 索赔与现场签证
+    CLAIM_VISA: 14,
+    // 规费
+    CHARGE: 15,
+    // 社会保险费及住房公积金 Social insurance fee and housing accumulation fund
+    SOCIAL_INSURANCE_HOUSING_FUND: 16,
+    // 工程排污费 charges for disposing pollutants
+    POLLUTANTS: 17,
+    // 税金
+    TAX: 18,
+    //工程造价
+    ENGINEERINGCOST: 19
+};
+
+export default fixedFlag;

+ 3 - 3
modules/main/controllers/labour_coe_controller.js

@@ -44,12 +44,12 @@ async function getStdLabourCoe(req, res) {
 function save(req, res) {
     let result = {error: 0, message: '', data: null};
 
-    labourCoeFacade.save(req.body.data, function (err, message, data) {
-        if (err == 0){
+    labourCoeFacade.save(req.body.data, function (err, data) {
+        if (err == ''){
             result.data = data;
         }else{
             result.error = 1;
-            result.message = message;
+            result.message = err;
         }
     });
 

+ 4 - 3
modules/main/facade/labour_coe_facade.js

@@ -112,9 +112,10 @@ function save (data, callback) {
     projectLabourCoesModel.bulkWrite(updateArr)
         .then(function(){
             logger.info(`Project LabourCoe saved successful : ${data.projectID}`);
-            callback(0, '', null);
+            callback('', null);
         })
         .catch(function (err) {
-            logger.err(err);
-            callback(1, err, null)});
+            logger.err('labourCoe save error: ' + err);
+            callback(err, null)
+        });
 }

+ 29 - 13
modules/pm/controllers/pm_controller.js

@@ -12,6 +12,7 @@ let fee_rate_facade = require("../../fee_rates/facade/fee_rates_facade");
 let billsModel = require('../../main/models/bills').model;
 let rationsModel = require('../../main/models/ration').model;
 let projectModel = require("../models/project_schema");
+let asyncTool = require('async');
 
 //统一回调函数
 let callback = function(req, res, err, message, data){
@@ -43,8 +44,8 @@ module.exports = {
             callback(false);
         });
     },
-    getProjects: function(req, res){
-        ProjectsData.getUserProjects(req.session.sessionUser.ssoId, req.session.sessionCompilation._id, function(err, message, projects){
+    getProjects: async function(req, res){
+         await ProjectsData.getUserProjects(req.session.sessionUser.ssoId, req.session.sessionCompilation._id, function(err, message, projects){
             if (projects) {
                 callback(req, res, err, message, projects);
             } else {
@@ -64,40 +65,55 @@ module.exports = {
     },
     // CSL, 2017-12-14 该方法用于项目属性:提交保存混合型数据,这些数据来自不同的表,包括projects.property、ration、bills、labour_coes.
     updateMixDatas: function(req, res){
-        let callBackInner = function (err, message, data) {
-            if (err === 0) {
-                res.json({error: err, message: message, data: data});
-            } else {
-                res.json({error: err, message: message, data: null});
+        let datas = JSON.parse(req.body.data).mixDataArr;
+        let functions = [];
+
+        function updateFunc(model, cod, doc) {
+            return function (cb) {
+                model.update(cod, doc, cb);
             }
         };
 
-        let datas = JSON.parse(req.body.data).mixDataArr;
+        function updateLC(){
+            return function (cb) {
+                datas.labourCoes.updateData.projectID = datas.projectID;
+                labourCoe.save(datas.labourCoes.updateData, cb);
+            }
+        };
 
         // 项目属性
         if (Object.keys(datas.properties).length > 0){
-            projectModel.update({ID: datas.projectID}, datas.properties, callBackInner);
+            functions.push(updateFunc(projectModel, {ID: datas.projectID}, datas.properties));
         };
 
         // 人工系数
         if (datas.labourCoes.updateData){
-            datas.labourCoes.updateData.projectID = datas.projectID;
-            labourCoe.save(datas.labourCoes.updateData, callBackInner);
+            functions.push(updateLC());
         };
 
         // 清单:每文档doc只存储一条清单,每条清单都必须定位一次文档,无法合并处理
         if (datas.bills.length > 0){
             for (let bill of datas.bills){
-                billsModel.update({projectID: datas.projectID, ID: bill.ID, deleteInfo: null}, bill, callBackInner);
+                functions.push(updateFunc(billsModel, {projectID: datas.projectID, ID: bill.ID, deleteInfo: null}, bill));
             };
         };
 
         // 定额:每文档doc只存储一条定额,每条定额都必须定位一次文档,无法合并处理
         if (datas.rations.length > 0){
             for (let ration of datas.rations){
-                rationsModel.update({projectID: datas.projectID, ID: ration.ID, deleteInfo: null}, ration, callBackInner);
+                functions.push(updateFunc(rationsModel, {projectID: datas.projectID, ID: ration.ID, deleteInfo: null}, ration));
             };
         };
+
+        asyncTool.parallel(functions, function(err, result){
+            {
+                if (!err) {
+                    res.json({error: 0, message: err, data: result});
+                } else {
+                    res.json({error: 1, message: err, data: null});
+                }
+            }
+        });
     },
     updateFiles: async function(req, res){
         let data = JSON.parse(req.body.data);

+ 18 - 7
modules/pm/models/project_model.js

@@ -6,6 +6,7 @@ import async_c from 'async';
 import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
 import UnitPriceFiles from '../../glj/models/schemas/unit_price_file';
 import {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting} from './project_property_template';
+import fixedFlag from '../../common/const/bills_fixed';
 let FeeRateFiles = mongoose.model('fee_rate_file');
 let counter = require("../../../public/counter/counter.js");
 
@@ -15,6 +16,7 @@ let feeRateFacade = require('../../fee_rates/facade/fee_rates_facade');
 let labourCoeFacade = require('../../main/facade/labour_coe_facade');
 let calcProgramFacade = require('../../main/facade/calc_program_facade');
 let logger = require("../../../logs/log_helper").logger;
+let BillsModel = require("../../main/models/bills").model;
 
 let Projects = require("./project_schema");
 let projectType = {
@@ -30,14 +32,19 @@ let fileType = {
 
 let ProjectsDAO = function(){};
 
-ProjectsDAO.prototype.getUserProjects = function(userId, compilation, callback){
-    Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id', function(err, templates){
-        if (err) {
-            callback(1, 'Error', null);
-        } else {
-            callback(0, '', templates);
+ProjectsDAO.prototype.getUserProjects = async function(userId, compilation, callback){
+    try {
+        let projects = await Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id');
+        for(let i = 0 , len = projects.length; i < len; i++){
+            let proj = projects[i];
+            let engineeringCost = await BillsModel.find({projectID: proj.ID, 'flags.flag': fixedFlag.ENGINEERINGCOST, 'fees.totalFee': {$exists:  true}});
+            proj._doc.engineeringCost = engineeringCost.length > 0 ? engineeringCost[0].fees[0].totalFee : 0;
         }
-    });
+        callback(0, '', projects);
+    }
+    catch (err){
+        callback(1, 'Error', null);
+    }
 };
 
 ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
@@ -276,6 +283,10 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
 
 ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback){
     try {
+        console.log("------------------------------------");
+        console.log(userId) ;
+        console.log("------------------------------------");
+        console.log(compilationId) ;
         if (data.id === undefined || data.id === '') {
             throw '数据错误!';
         }

+ 32 - 0
modules/reports/util/rpt_construct_data_util.js

@@ -601,6 +601,7 @@ function setupFunc(obj, prop, ownRawObj) {
     obj[prop].getFee = ext_getFee;
     obj[prop].getPropertyByForeignId = ext_getPropertyByForeignId;
     obj[prop].getArrayItemByKey = ext_getArrayItemByKey;
+    obj[prop].getPropertyByFlag = ext_getPropertyByFlag;
     if (prop === projectConst.CALC_PROGRAM) obj[prop].getCalcProperty = ext_getCalcProperty;
     if (prop === projectConst.FEERATE) obj[prop].getFeeRate = ext_getFeeRate;
 }
@@ -859,7 +860,38 @@ function ext_getArrayItemByKey(arrayKey, itemKey, itemKeyValue, itemRstKey){
             private_getItemValue(arr, itemKeyValue);
         }
     }
+}
 
+function ext_getPropertyByFlag(flagVal, rstKey, dftValIfEmpty) {
+    let rst = [], parentObj = this;
+    let dtObj = parentObj["myOwnRawDataObj"];
+    if (flagVal && rstKey && dtObj) {
+        let isArr = (flagVal instanceof Array);
+        for (let dItem of dtObj.data) {
+            let doc = (dItem._doc === null || dItem._doc === undefined)?dItem:dItem._doc;
+            if (doc.hasOwnProperty("flags")) {
+                let bFlag = false;
+                for (let flagItem of doc.flags) {
+                    if (isArr) {
+                        bFlag = (flagVal.indexOf(flagItem.flag) >= 0);
+                    } else {
+                        if (flagItem.flag === flagVal) {
+                            bFlag = true;
+                        }
+                    }
+                    if (bFlag) break;
+                }
+                if (bFlag) {
+                    rst.push(doc[rstKey]);
+                    break;
+                }
+            }
+        }
+    }
+    if (rst.length === 0 && dftValIfEmpty) {
+        rst.push(dftValIfEmpty);
+    }
+    return rst;
 }
 
 function ext_getPropertyByForeignId(foreignIdVal, adHocIdKey, propKey, dftValIfNotFound) {

+ 55 - 27
public/stringUtil.js

@@ -145,36 +145,64 @@ module.exports = {
     rightTrim: function(rst) {
         return str.replace(/(\s*$)/g,"");
     },
-    convertNumToChinese : function(num, isCurrency) {
-        if (!/^\d*(\.\d*)?$/.test(num)) { return "Number is wrong!"; }
-        let AA, BB;
-        if (isCurrency) {
-            AA = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
-            BB = ["", "拾", "佰", "仟", "萬", "億", "点", ""];
-        } else {
-            AA = ['零','一','二','三','四','五','六','七','八','九'];
-            BB = ["", "十", "百", "千", "万", "亿", "点", ""];
-        }
-        //let AA = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
-        //let BB = new Array("", "拾", "佰", "仟", "萬", "億", "点", "");
-        let a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
-        for (let i = a[0].length - 1; i >= 0; i--) {
-            switch (k) {
-                case 0: re = BB[7] + re; break;
-                case 4: if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
-                    re = BB[4] + re; break;
-                case 8: re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
+    replaceAll: function (targetStr, FindText, RepText) {
+        let regExp = new RegExp(FindText, "gm");
+        return targetStr.replace(regExp, RepText);
+    },
+    convertToCaptionNum: function(num, isCurrency, isTraditionalCap) {
+        let me = this, rst = "";
+        if (/^\d*(\.\d*)?$/.test(num)) {
+            let capChars, unitChars;
+            if (isTraditionalCap) {
+                capChars = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
+                unitChars = ["" , "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "萬"];
+            } else {
+                capChars = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
+                unitChars = ["" , "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万"];
             }
-            if (k % 4 === 2 && a[0].charAt(i + 2) !== 0 && a[0].charAt(i + 1) === 0) re = AA[0] + re;
-            if (a[0].charAt(i) !== 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re; k++;
-        }
 
-        if (a.length > 1) //加上小数部分(如果有小数部分)
-        {
-            re += BB[6];
-            for (let i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)];
+            let numSplitArr = ("" + num).replace(/(^0*)/g, "").split(".");
+            if (numSplitArr[0] === "") numSplitArr[0] = "0";
+            let len = numSplitArr[0].length;
+            let intPartArr = [];
+            if (len <= 13) {
+                for (let idx = 0; idx < len; idx++) {
+                    intPartArr.push(capChars[ parseInt(numSplitArr[0].charAt(idx) )] + unitChars[len - idx - 1]);
+                }
+                rst = intPartArr.join('');
+                rst = me.replaceAll(rst, capChars[0] + unitChars[3], capChars[0]); //零千 -> 零
+                rst = me.replaceAll(rst, capChars[0] + unitChars[2], capChars[0]); //零百 -> 零
+                rst = me.replaceAll(rst, capChars[0] + unitChars[1], capChars[0]); //零十 -> 零
+                //
+                rst = me.replaceAll(me.replaceAll(rst, "零零", "零"), "零零", "零");
+                rst = me.replaceAll(rst, capChars[0] + unitChars[8], unitChars[8]); //零亿 -> 亿
+                rst = me.replaceAll(rst, capChars[0] + unitChars[4], unitChars[4]); //零万 -> 万
+                //
+                rst = me.replaceAll(rst, unitChars[8] + unitChars[4], unitChars[8] + capChars[0]); //亿万 -> 亿零
+                if (num === 0) {
+                    rst = "零";
+                } else if (rst.length > 1 && rst.charAt(rst.length - 1) === '零') {
+                    rst = rst.slice(0, rst.length - 1);
+                }
+                //小数部分处理
+                if (numSplitArr.length > 1) {
+                    len = numSplitArr[1].length;
+                    if (isCurrency && len > 2) len = 2;
+                    let fractionStr = [];
+                    for (let idx = 0; idx < len; idx++) {
+                        fractionStr.push(capChars[ parseInt(numSplitArr[1].charAt(idx))]+ (isCurrency?((idx === 0)?"角":"分"):""));
+                    }
+                    rst = rst + (isCurrency?"元":"点") + fractionStr.join("");
+                } else {
+                    rst = rst + (isCurrency?"元整":"");
+                }
+            } else {
+                rst = "Number is too big!";
+            }
+        } else {
+            rst = "Number is wrong!";
         }
-        return re;
+        return rst;
     },
     convertStrToBoolean: function(str) {
         let rst = false, me = this;

+ 3 - 1
web/building_saas/main/js/models/calc_base.js

@@ -38,7 +38,9 @@ const fixedFlag = {
     // 工程排污费 charges for disposing pollutants
     POLLUTANTS: 17,
     // 税金
-    TAX: 18
+    TAX: 18,
+    //工程造价
+    ENGINEERINGCOST: 19
 };
 
 let cbTools = {

+ 1 - 0
web/building_saas/main/js/views/calc_base_view.js

@@ -138,6 +138,7 @@ let calcBaseView = {
         }
         me.buildSheet();
         let baseObj = projectObj.project.calcBase.getBaseByClass(node);
+        console.log(baseObj);
         me.showData(me.toViewData(baseObj));
 
     },

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

@@ -818,7 +818,7 @@ $('#property_ok').click(function () {
                 for (let node of changedNodes){delete node.changed};
             };
             if (mixDatas.labourCoes.updateData) labourCoeView.refresh(mixDatas.labourCoes.updateData);*/
-            // window.location.href = '/main?project=' + projectID;
+            window.location.href = '/main?project=' + projectID;
         });
     }
 });

+ 2 - 1
web/building_saas/pm/js/pm_main.js

@@ -101,7 +101,7 @@ let ProjTreeSetting = {
             event: {
                 getText: function (html, node, text) {
                     if(node.data.projType === projectType.tender){
-                        html.push('0');
+                        let engineeringCostText = node.data.engineeringCost ? node.data.engineeringCost : 0;
                     }
                 }
             }
@@ -1443,6 +1443,7 @@ function GetNewProjectId(count, callback) {
  * @return {void}
  */
 function RenameProject(projectId, newName, parentID, callback) {
+    console.log(parentID);
     $.ajax({
         type: "POST",
         url: '/pm/api/renameProject',