Browse Source

Merge branch 'master' into olym

caiaolin 8 years atrás
parent
commit
7502496be5
39 changed files with 157485 additions and 103936 deletions
  1. 1 1
      modules/main/models/base_model.js
  2. 6 0
      modules/main/models/bills_sub_schemas.js
  3. 2 0
      modules/main/models/project.js
  4. 1 0
      modules/main/models/project_consts.js
  5. 15 2
      modules/main/models/ration.js
  6. 234 0
      modules/ration_glj/facade/glj_calculate_facade.js
  7. 125 0
      modules/ration_glj/facade/ration_ass_facade.js
  8. 175 3
      modules/ration_glj/facade/ration_coe_facade.js
  9. 66 10
      modules/ration_glj/facade/ration_glj_facade.js
  10. 2 2
      modules/ration_glj/models/ration_coe.js
  11. 51 2
      modules/ration_glj/models/ration_glj_temp.js
  12. 13 0
      modules/reports/controllers/rpt_tpl_controller.js
  13. 2 0
      modules/reports/routes/rpt_tpl_router.js
  14. 2 1
      modules/reports/rpt_component/jpc_ex.js
  15. 1 1
      package.json
  16. 5 0
      public/web/number_util.js
  17. 1 0
      public/web/sheet/sheet_common.js
  18. 16 16
      public/web/tree_sheet/tree_sheet_helper.js
  19. 11 0
      server.js
  20. 19 0
      test/public/testLoadDateFormat.js
  21. 65 5
      test/tmp_data/bills_grid_setting.js
  22. 0 62761
      test/tmp_data/data_15690.js
  23. 0 41073
      test/tmp_data/drawing_data_10268.js
  24. 62761 0
      test/tmp_data/test_bills_calc/bills_data_15690.js
  25. 676 0
      test/tmp_data/test_bills_calc/bills_grid_setting_test_calc.js
  26. 92413 0
      test/tmp_data/test_bills_calc/drawing_data_10268.js
  27. 5 0
      web/building_saas/main/html/main.html
  28. 11 0
      web/building_saas/main/js/controllers/project_controller.js
  29. 4 4
      web/building_saas/main/js/models/bills.js
  30. 225 0
      web/building_saas/main/js/models/bills_calc.js
  31. 2 1
      web/building_saas/main/js/models/main_consts.js
  32. 15 2
      web/building_saas/main/js/models/project.js
  33. 15 6
      web/building_saas/main/js/models/ration.js
  34. 126 0
      web/building_saas/main/js/models/ration_ass.js
  35. 49 5
      web/building_saas/main/js/models/ration_coe.js
  36. 35 13
      web/building_saas/main/js/models/ration_glj.js
  37. 295 17
      web/building_saas/main/js/views/glj_view.js
  38. 35 10
      web/building_saas/main/js/views/project_view.js
  39. 5 1
      web/building_saas/main/js/views/sub_view.js

+ 1 - 1
modules/main/models/base_model.js

@@ -13,7 +13,7 @@ class baseModel {
      * @param fields
      * @returns {Promise|Array|{index: number, input: string}}
      */
-    getQueryData(query, fields) {
+    getQueryData (query, fields) {
         return this.model.find(query, fields).exec();
     };
 

+ 6 - 0
modules/main/models/bills_sub_schemas.js

@@ -19,4 +19,10 @@ var flagsSchema = new Schema({
     flag: Number
 });
 
+var changesSchema = new Schema({
+    addGLJ: String,
+    modifyGLJ:String,
+    deleteGLJ:String
+});
+
 module.exports = {feesSchema: feesSchema, flagsSchema: flagsSchema};

+ 2 - 0
modules/main/models/project.js

@@ -6,6 +6,7 @@ var rationData = require('./ration');
 var GLJData = require('./glj');
 var ration_glj_data = require('../../ration_glj/facade/ration_glj_facade');
 var ration_coe_data = require('../../ration_glj/facade/ration_coe_facade');
+var ration_ass_data = require('../../ration_glj/facade/ration_ass_facade');
 let projCounter = require('./proj_counter');
 var consts = require('./project_consts');
 var projectConsts = consts.projectConst;
@@ -18,6 +19,7 @@ moduleMap[projectConsts.RATION] = rationData;
 //moduleMap[projectConsts.GLJ] = GLJData;
 moduleMap[projectConsts.RATION_GLJ] = ration_glj_data;
 moduleMap[projectConsts.RATION_COE] = ration_coe_data;
+moduleMap[projectConsts.RATION_ASS] = ration_ass_data;
 moduleMap[projCounter.collectionName] = projCounter;
 
 

+ 1 - 0
modules/main/models/project_consts.js

@@ -7,6 +7,7 @@ var projectConst = {
     GLJ: 'GLJ',
     RATION_GLJ:'ration_glj',
     RATION_COE:'ration_coe',
+    RATION_ASS:'ration_ass',
     PROJECTGLJ: 'projectGLJ',
     GLJLIST: 'GLJList',
     UNITPRICEFILE: 'unitPriceFile',

+ 15 - 2
modules/main/models/ration.js

@@ -12,6 +12,19 @@ let consts = require('./project_consts');
 let projectConsts = consts.projectConst;
 let commonConsts = consts.commonConst;
 
+var rationAssItemSchema = mongoose.Schema({
+    name: String,
+    assistID: Number,
+    assistCode: String,
+    stdValue: Number,
+    actualValue:Number,
+    stepValue: String,
+    decimal: Number,
+    carryBit: String,
+    minValue: String,
+    maxValue: String
+}, { _id: false });
+
 let rationSchema = new Schema({
     ID: Number,
     projectID: Number,
@@ -32,7 +45,8 @@ let rationSchema = new Schema({
     fees: [subSchema.feesSchema],
     // 标记字段
     flags: [subSchema.flagsSchema],
-    deleteInfo: deleteSchema
+    deleteInfo: deleteSchema,
+    rationAssList: [rationAssItemSchema]
 });
 
 let ration = db.model("ration", rationSchema, "ration");
@@ -74,7 +88,6 @@ class rationModel extends baseModel {
             }
         }
 
-        functions
 
         for (let i = 0; i < datas.length; i++){
             data = datas[i];

+ 234 - 0
modules/ration_glj/facade/glj_calculate_facade.js

@@ -0,0 +1,234 @@
+/**
+ * Created by chen on 2017/7/12.
+ */
+
+
+let mongoose = require('mongoose');
+let _=require("lodash");
+let ration_glj = mongoose.model('ration_glj');
+let ration = mongoose.model('ration');
+let ration_coe = mongoose.model('ration_coe');
+let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
+
+module.exports={
+    calculateQuantity:calculateQuantity
+}
+//辅助定额调整、替换工料机、标准附注条件调整、添加工料机、自定义消耗量(包括删除工料机)、自定义乘系数、市场单价调整
+let stateSeq ={
+    ass:1,
+    replase:2,
+    coe:3,
+    add:4,
+    cusQuantity:5,
+    cusCoe:6,
+    adjMak:7
+}
+
+
+async function calculateQuantity(query){
+    try {
+         let  result ={
+             glj_result:[],
+             rationID:query.rationID
+         };
+         let impactRation = await ration.findOne({projectID:query.projectID,ID:query.rationID});
+         let gljList = await ration_glj.find(query)//{projectID:query.projectID,rationID:query.rationID}
+         let coeList = await ration_coe.find({projectID:query.projectID,rationID:query.rationID}).sort('seq').exec();
+         let assList=[];
+         let assRation = null;
+         let adjustState=[];
+         if(impactRation._doc.hasOwnProperty("rationAssList")&&impactRation.rationAssList.length>0){
+             for(let i=0;i<impactRation.rationAssList.length;i++){
+                 let times = calculateTimes(impactRation.rationAssList[i]);
+                 if(times!=0){
+                     assRation = await  std_ration_lib_ration_items.findOne({rationRepId:impactRation.libID,code:impactRation.rationAssList[i].assistCode});
+                     assList.push({times:times,assRation:assRation})
+                     adjustState.push({index:stateSeq.ass,content:"+"+impactRation.rationAssList[i].assistCode+"x"+times});
+                     }
+                 }
+         }
+         for(let i =0;i<gljList.length;i++ ){
+             let r = await calculateQuantityPerGLJ(gljList[i],impactRation,coeList,assList,adjustState);
+             result.glj_result.push(r);
+         }
+         await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
+         adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
+         adjustState=_.map(adjustState, _.property('content'));
+         let adjustStateString = adjustState.join(';');
+         await ration.update({projectID:query.projectID,ID:query.rationID},{adjustState:adjustStateString});
+         result.adjustState=adjustStateString;
+         return result;
+    }catch (err){
+        console.log(err);
+        throw err;
+    }
+}
+
+function generateUpdateTasks(result) {
+    let tasks = [];
+    for(let i =0;i<result.length;i++){
+        let task= {
+            updateOne: {
+                filter: result[i].query,
+                update: result[i].doc
+            }
+        }
+        tasks.push(task);
+    }
+    return tasks;
+}
+
+
+async function calculateQuantityPerGLJ(glj,ration,coeList,assList,adjustState) {
+    let quantity =  glj.quantity;
+    let result={
+        query:{
+            ID:glj.ID,
+            projectID:glj.projectID
+        },
+        doc:{
+            quantity: quantity,
+            customQuantity:glj.customQuantity
+        }
+    };
+    try {
+        //to do 添加/替换工料机调整 内容
+
+        if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null){
+            quantity =glj.rationItemQuantity;
+            quantity =calculateAss(quantity,assList,glj);
+            quantity = calculateQuantityByCoes(quantity,coeList,glj);
+        }else {
+            quantity = glj.customQuantity;
+        }
+        let customerCoe = _.last(coeList);
+        if(customerCoe.isAdjust==1){
+            quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj);
+        }
+        result.doc.quantity =quantity;
+        generateAdjustState(glj,coeList,adjustState);
+        return result;
+    }catch (err){
+        throw err;
+    }
+}
+
+function calculateAss(quantity,assList,glj) {
+    for(let i=0;i<assList.length;i++){
+        let assglj = _.find(assList[i].assRation.rationGljList,function (aglj) {
+            return aglj.gljId == glj.GLJID
+        })
+        if(assglj){
+            let calQuantity = assglj.consumeAmt*assList[i].times;
+            quantity += calQuantity
+        }
+    }
+    return quantity;
+}
+
+function generateAdjustState(glj,coeList,adjustState) {
+   //替换工料机 and  添加工料机
+
+    // to do
+
+  //标准附注条件调整 + 自定义乘系数
+    for(let i=0;i<coeList.length;i++){
+        if(coeList[i].isAdjust==1){
+            if(i==coeList.length-1){
+                adjustState.push({index:stateSeq.cusCoe,content:coeList[i].content});
+            }else {
+                adjustState.push({index:stateSeq.coe,content:coeList[i].content});
+            }
+        }
+    }
+
+ //自定义消耗量
+    if(glj._doc.hasOwnProperty('customQuantity')){
+        if(glj.customQuantity!==null){
+            adjustState.push({index:stateSeq.cusQuantity,content:glj.code+'量'+glj.customQuantity});
+        }
+    }
+    //市场单价调整
+    if(glj._doc.hasOwnProperty('marketPriceAdjust')&&glj.marketPriceAdjust!=0){
+        //0101005价66.00
+        adjustState.push({index:stateSeq.adjMak,content:glj.code+'价'+glj.marketPriceAdjust});
+    }
+
+    return adjustState;
+}
+
+
+function calculateTimes(ass){
+    let times =(ass.actualValue-ass.stdValue)/ass.stepValue;
+
+    if(ass.carryBit=='四舍五入'){
+        times = _.round(times,ass.decimal);
+    }else if (ass.carryBit=='进一'){
+        times =_.ceil(times,ass.decimal);
+    }
+    return times;
+}
+
+function calculateQuantityByCoes(quantity,coeList,glj){
+    let coeQuantity = quantity;
+    if(coeList.length>1){
+        for(let i=0;i<coeList.length-1;i++){
+            coeQuantity = everyCoe(coeQuantity,coeList[i],glj);
+        }
+    }
+    return coeQuantity;
+}
+
+function everyCoe(quantity,coe,glj) {
+    let coeQuantity = quantity;
+    if(coe.isAdjust==1){
+        for(let i=0;i<coe.coes.length;i++){
+            if(coe.coes[i].coeType=='单个'&&coe.coes[i].gljCode==glj.code){
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+            } else if(coe.coes[i].coeType=='定额'){
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+            }else if(coe.coes[i].coeType==glj.gljDistType){
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+            }
+        }
+    }
+    return coeQuantity;
+}
+
+
+function calculateQuantityByCustomerCoes(quantify,coe,glj) {
+    let rationAmount = coe.coes[0].amount;
+    if(_.every(coe.coes,'amount',rationAmount)){
+        return getCalculateResult(quantify, coe.coes[0])
+    }else {
+        for(let i=1;i<coe.coes.length;i++){
+            if(coe.coes[i].coeType.search(glj.gljDistType)!=-1){
+                return getCalculateResult(quantify,coe.coes[i])
+            }
+        }
+    }
+    return quantify
+}
+
+function getCalculateResult(quantify,c) {
+    let q = quantify;
+    switch (c.operator){
+        case '+' :
+            q = q + c.amount;
+            break;
+        case '-' :
+            q = q - c.amount;
+            break;
+        case '*' :
+            q = q * c.amount;
+            break;
+        case '/' :
+            q = q / c.amount;
+            break;
+        case '=' :
+             q = c.amount;
+            break;
+    }
+    return q;
+
+}

+ 125 - 0
modules/ration_glj/facade/ration_ass_facade.js

@@ -0,0 +1,125 @@
+/**
+ * Created by chen on 2017/7/10.
+ */
+let mongoose = require('mongoose');
+let consts = require('../../main/models/project_consts');
+let commonConsts = consts.commonConst;
+let _=require("lodash");
+let async_n = require("async");
+let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
+let rationModel = mongoose.model('ration');
+let ration_glj = mongoose.model('ration_glj');
+let glj_calculate_facade = require('./glj_calculate_facade');
+
+module.exports={
+    save:save,
+    getData:getData
+}
+
+let operationMap={
+    'ut_create':create_ration_ass,
+    'ut_update':update_ration_ass,
+    'ut_delete':delete_ration_ass
+};
+
+function create_ration_ass(user_id,datas) {
+
+};
+
+function update_ration_ass(user_id,datas) {
+    return function (callback) {
+        let editAss = datas.query.editAss;
+        doRationAssAdjust(datas.query.ration,datas.doc).then(function (result) {
+            console.log(result);
+            if(result.err){
+                callback(result.err,'')
+            }else {
+                let newObject = {
+                    moduleName:consts.projectConst.RATION_ASS,
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        doc:datas.doc,
+                        rationID:datas.query.ration.ID,
+                        editIndex:datas.query.editIndex,
+                        actualValue:editAss.actualValue
+                    }
+                };
+                let ration_glj_data ={
+                    moduleName:'ration_glj',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        glj_result:result.cal_result.glj_result
+                    }
+                };
+                let ration_data ={
+                    moduleName:'ration',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        rationID:result.cal_result.rationID,
+                        adjustState:result.cal_result.adjustState
+                    }
+                };
+                callback(null,[newObject,ration_glj_data,ration_data]);
+            }
+        })
+
+    }
+
+};
+
+async function doRationAssAdjust(ration,doc) {
+    let result ={
+        err:null,
+        cal_result:[]
+    }
+    try{
+        await rationModel.update({projectID:ration.projectID,ID:ration.ID},doc);
+        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:ration.projectID,rationID:ration.ID});
+        result.cal_result=cal_result;
+        return result;
+    }catch (err){
+        result.err = err;
+        console.log(err);
+        return result;
+    }
+}
+
+
+
+
+function delete_ration_ass(user_id,datas) {
+
+};
+
+
+
+
+
+
+function getData(projectID, callback) {
+    callback(0, consts.projectConst.RATION_ASS, []);
+}
+
+function save (user_id, datas, callback) {
+    let operations=[];
+    if(_.isArray(datas)){
+        for(let i=0;i<datas.length;i++){
+            operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
+        }
+    }else {
+        operations.push(operationMap[datas.updateType](user_id,datas));
+    }
+    async_n.parallel(operations,function (err,results) {
+        if(err){
+            callback(err,'');
+        }else {
+            if(results.length==1){
+                callback(null,results[0])
+            }else {
+                callback(null,results)
+            }
+        }
+    })
+}

+ 175 - 3
modules/ration_glj/facade/ration_coe_facade.js

@@ -10,6 +10,8 @@ let _=require("lodash");
 let async_n = require("async");
 let coeMolde = mongoose.model('std_ration_lib_coe_list');
 let ration_coe = mongoose.model('ration_coe');
+let glj_calculate_facade = require('./glj_calculate_facade');
+
 
 module.exports={
     save:save,
@@ -21,6 +23,11 @@ let operationMap={
     'ut_update':update_ration_coe,
     'ut_delete':delete_ration_coe
 };
+let updateFunctionMap = {
+    'normalUpdate':normalUpdate,
+    'updateCustomerCoe':updateCustomerCoe,
+    'adjustUpdate':adjustUpdate
+}
 
 function create_ration_coe(user_id,datas) {
     return function (callback) {
@@ -49,12 +56,178 @@ function create_ration_coe(user_id,datas) {
                 });
             }
         })
+    }
+}
+
+function update_ration_coe(user_id,datas) {
+    if(datas.updateFunction){
+        return updateFunctionMap[datas.updateFunction](user_id,datas);
+    }else {
+        return normalUpdate(user_id,datas);
+    }
+}
+
+function normalUpdate(user_id,datas) {
+    return function(callback) {
+        ration_coe.update(datas.query,datas.doc,(err,result)=>{
+            if(err){
+                callback(err,'');
+            }else {
+                let returndata ={
+                    moduleName:'ration_coe',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        query:datas.query,
+                        doc:datas.doc
+                    }
+                }
+                callback(null,returndata);
+            }
+        })
+    }
+}
+
+function updateCustomerCoe(user_id,datas) {
+    return function(callback) {
+        doCustomerCoeUpdateTasks(datas).then((result)=>{
+            if(result.err){
+                callback(result.err,'');
+            }else {
+                let coeReturn = {
+                    moduleName:'ration_coe',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        query:result.coeResult.query,
+                        doc:result.coeResult.doc
+                    }
+                }
+                let ration_glj_data ={
+                    moduleName:'ration_glj',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        glj_result:result.cal_result.glj_result
+                    }
+                };
+                let ration_data ={
+                    moduleName:'ration',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        rationID:result.cal_result.rationID,
+                        adjustState:result.cal_result.adjustState
+                    }
+                };
+                callback(null,[coeReturn,ration_glj_data,ration_data]);
+                console.log('update end');
+            }
+        })
+
+    }
+}
+
+ function adjustUpdate(user_id,datas) {
+    return function(callback) {
+        doAdjustUpdate(datas).then((result)=>{
+            if(result.err){
+                callback(result.err,'');
+            }else {
+                let coeReturn = {
+                    moduleName:'ration_coe',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        query:datas.query,
+                        doc:datas.doc
+                    }
+                }
+                let ration_glj_data ={
+                    moduleName:'ration_glj',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        glj_result:result.cal_result.glj_result
+                    }
+                };
+                let ration_data ={
+                    moduleName:'ration',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        rationID:result.cal_result.rationID,
+                        adjustState:result.cal_result.adjustState
+                    }
+                };
+                callback(null,[coeReturn,ration_glj_data,ration_data]);
+                console.log('update end');
+            }
+        })
+    }
+}
 
+async function doAdjustUpdate (datas){
+    let result = {
+        err:null
+    }
+    try{
+        await ration_coe.update(datas.query,datas.doc);
+        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.query.rationID});
+        result.cal_result =cal_result;
+        console.log(result);
+        return result;
+    }catch (err){
+        result.err = err;
+        console.log(err);
+        return result;
     }
 }
-function update_ration_coe() {
-    
+
+async function doCustomerCoeUpdateTasks(datas) {
+    let result = {
+        err:null
+    }
+    try{
+        let doc =datas.doc;
+        doc.isAdjust = 1;
+        doc.content = generationContent(doc.coes);
+        let query = {
+            ID:datas.query.ID,
+            projectID:datas.query.projectID
+        }
+        await ration_coe.update(query,datas.doc);
+        result.coeResult ={
+                query:query,
+                doc:doc
+        };
+        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.query.rationID});
+        result.cal_result =cal_result;
+        console.log(result);
+        return result;
+    }catch (err){
+        result.err = err;
+        console.log(err);
+        return result;
+    }
 }
+
+function generationContent(coes) {
+    let rationAmount = coes[0].amount;
+    let string ='';
+    if(_.every(coes,'amount',rationAmount)){
+        string = coes[0].coeType + 'x'+rationAmount;
+    }else {
+        for(let i =1;i<coes.length;i++){
+            if(i==1){
+                string = coes[i].coeType + 'x'+coes[i].amount;
+            }else {
+                string +=', '+coes[i].coeType + 'x'+coes[i].amount;
+            }
+        }
+
+    }
+    return string;
+}
+
+
 function delete_ration_coe(data) {
     return function (callback) {
         ration_coe.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
@@ -99,7 +272,6 @@ function getData(projectID, callback) {
             callback(0, consts.projectConst.RATION_COE, datas);
         }
     })
-
 }
 
 function save (user_id, datas, callback) {

+ 66 - 10
modules/ration_glj/facade/ration_glj_facade.js

@@ -14,6 +14,17 @@ let std_ration_lib_glj_list_model = mongoose.model('std_ration_lib_glj_list');
 let async_n = require("async");
 let ration = mongoose.model('ration');
 let ration_coe_facade = require('./ration_coe_facade');
+let ration_coe = mongoose.model('ration_coe');
+let std_ration_lib_ration_items = mongoose.model('std_ration_lib_ration_items');
+let glj_calculate_facade = require('./glj_calculate_facade');
+
+
+module.exports={
+    save:save,
+    getData:getData,
+    deleteByRation:deleteByRation,
+    getQuantityByProjectGLJ:getQuantityByProjectGLJ
+}
 
 let operationMap={
     'ut_create':create_ration_glj,
@@ -22,15 +33,11 @@ let operationMap={
 };
 let updateFunctionMap = {
     'normalUpdate':normalUpdate,
-    'marketPriceAdjustUpdate':marketPriceAdjustUpdate
-}
+    'marketPriceAdjustUpdate':marketPriceAdjustUpdate,
+    'customQuantityUpdate':customQuantityUpdate
+};
+
 
-module.exports={
-    save:save,
-    getData:getData,
-    deleteByRation:deleteByRation,
-    getQuantityByProjectGLJ:getQuantityByProjectGLJ
-}
 
 
 /**
@@ -165,7 +172,6 @@ function update_ration_glj(user_id,datas) {
     }else {
         return normalUpdate(user_id,datas);
     }
-
 }
 
 function normalUpdate(user_id,datas){
@@ -188,6 +194,56 @@ function normalUpdate(user_id,datas){
     }
 }
 
+function customQuantityUpdate(user_id,datas){
+    return function(callback) {
+        doCustomQuantityUpdate(datas).then((result)=>{
+            if(result.err){
+                callback(result.err,'');
+            }else {
+                // cal_result ={
+              //  glj_result:[],
+                //    rationID:query.rationID
+
+                let ration_glj_data ={
+                    moduleName:'ration_glj',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        glj_result:result.cal_result.glj_result
+                    }
+                };
+                let ration_data ={
+                    moduleName:'ration',
+                    data:{
+                        updateTpye:commonConsts.UT_UPDATE,
+                        quantityRefresh:true,
+                        rationID:result.cal_result.rationID,
+                        adjustState:result.cal_result.adjustState
+                    }
+                };
+                callback(null,[ration_glj_data,ration_data]);
+            }
+        })
+    }
+}
+
+async function doCustomQuantityUpdate(datas){
+    let result = {
+        err:null
+    }
+    try{
+        await ration_glj.update(datas.query,datas.doc);
+        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:datas.query.projectID,rationID:datas.query.rationID});
+        result.cal_result =cal_result;
+        console.log(result);
+        return result;
+    }catch (err){
+        result.err = err;
+        console.log(err);
+        return result;
+    }
+}
+
 
 function marketPriceAdjustUpdate(user_id,datas) {
     return function (callback) {
@@ -401,4 +457,4 @@ function commonCallback(callback,result,err) {
     }else {
         callback(null,result);
     }
-}
+}

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

@@ -6,9 +6,9 @@ var mongoose = require('mongoose'),
 
 var coeSchema = mongoose.Schema({
     coeType: String,                // 系数类型,指作用范围:// 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
-    gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
+    gljCode: String,                  // 要调整的工料机ID(当coeType=0时有效)
     operator: String,               // 运算符(*、+、-、=)
-    amount: String,                 // 调整的量
+    amount: Number,                 // 调整的量
     _id: false
 });
 

+ 51 - 2
modules/ration_glj/models/ration_glj_temp.js

@@ -8,6 +8,20 @@ var mongoose = require('mongoose'),
     Schema = mongoose.Schema;
 //下面是临时代码,以后删除
 
+var rationAssItemSchema = mongoose.Schema({
+    name: String,
+    assistID: Number,
+    assistCode: String,
+    stdValue: Number,
+    actualValue:Number,
+    stepValue: String,
+    decimal: Number,
+    carryBit: String,
+    minValue: String,
+    maxValue: String
+}, { _id: false });
+
+
 var gljSchema =new Schema({
     repositoryId: Number,
     ID:Number,
@@ -43,7 +57,8 @@ let rationSchema = new Schema({
     fees: [subSchema.feesSchema],
     // 标记字段
     flags: [subSchema.flagsSchema],
-    deleteInfo: deleteSchema
+    deleteInfo: deleteSchema,
+    rationAssList: [rationAssItemSchema]
 });
 
 mongoose.model("ration", rationSchema, "ration");
@@ -65,4 +80,38 @@ var coeListSchema = mongoose.Schema({
     coes: [coeSchema]
 }, {versionKey: false});
 
- mongoose.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list");
+ mongoose.model("std_ration_lib_coe_list",coeListSchema, "std_ration_lib_coe_list");
+
+var rationGljItemSchema = mongoose.Schema({
+    gljId: Number,
+    consumeAmt: Number,
+    proportion: Number //配合比,暂时无需使用,默认0
+}, { _id: false });
+
+var rationAssItemSchema = mongoose.Schema({
+    name: String,
+    assistID: Number,
+    assistCode: String,
+    stdValue: String,
+    stepValue: String,
+    decimal: Number,
+    carryBit: String,
+    minValue: String,
+    maxValue: String
+}, { _id: false });
+
+var rationItemSchema = mongoose.Schema({
+    ID:Number,
+    code: String,
+    name: String,
+    unit: String,
+    basePrice: Number,
+    sectionId: Number,
+    rationRepId: Number,
+    caption: String,
+    feeType: Number,
+    rationGljList: [rationGljItemSchema],
+    rationCoeList: Array,
+    rationAssList: [rationAssItemSchema]
+});
+mongoose.model("std_ration_lib_ration_items",rationItemSchema, "std_ration_lib_ration_items")

+ 13 - 0
modules/reports/controllers/rpt_tpl_controller.js

@@ -9,6 +9,7 @@ let RptTplModel = require('../models/rpt_template');
 let TreeNodeModel = require('../models/tpl_tree_node');
 let rptTplDef = require("../../../public/rpt_tpl_def").getUtil();
 let stringUtil = require("../../../public/stringUtil");
+let JV = require('../rpt_component/jpc_value_define');
 
 //let test_glj_type_util = require("../../../public/cache/std_glj_type_util");
 
@@ -145,5 +146,17 @@ module.exports = {
                 callback(req, res, 'The report template was not found!', null);
             }
         })
+    },
+    updateRptTpl: function (req, res) {
+        let params = JSON.parse(req.body.params),
+            rptTpl = JSON.parse(params.rptTpl);
+        let filter = {"ID": parseInt(rptTpl[JV.PROP_ID])};
+        RptTplModel.update(filter, rptTpl, function (err, rst) {
+            if (err) {
+                callback(req, res, true, 'The report template was updated failed!', false);
+            } else {
+                callback(req, res, false, 'The report template was updated successfully!', true);
+            }
+        });
     }
 }

+ 2 - 0
modules/reports/routes/rpt_tpl_router.js

@@ -9,7 +9,9 @@ rptTplRouter.post('/updateRptTplNodes', reportTplController.updateTreeNodes);
 rptTplRouter.post('/deleteRptTplNodes', reportTplController.deleteRptTplNodes);
 rptTplRouter.post('/createDftRptTpl', reportTplController.createDftRptTpl);
 rptTplRouter.post('/getRefRptTpl', reportTplController.getRefRptTpl);
+rptTplRouter.post('/updateRptTpl', reportTplController.updateRptTpl);
 
 rptTplRouter.post('/getUserRptCfg', reportCfgController.getReportUserCfg);
+rptTplRouter.post('/getMappingFields', reportCfgController.getAllMappingFields);
 
 module.exports = rptTplRouter;

+ 2 - 1
modules/reports/rpt_component/jpc_ex.js

@@ -8,7 +8,7 @@ let JpcParam = require('./jpc_param');
 let JpcFunc = require('./jpc_function');
 let JpcData = require('./jpc_data');
 let JpcCommonHelper = require('./helper/jpc_helper_common');
-let JE = require('./jpc_rte'); //Important: for self-define function execution purpose
+let $JE = require('./jpc_rte'); //Important: for self-define function execution purpose
 
 let JpcExSrv = function(){};
 JpcExSrv.prototype.createNew = function(){
@@ -144,6 +144,7 @@ JpcExSrv.prototype.createNew = function(){
             if (me.formulas[i][JV.PROP_RUN_TYPE] === runType) {
                 let expression = me.formulas[i][JV.PROP_EXPRESSION];
                 if (expression) {
+                    let $ME = me.formulas[i];
                     eval(expression);
                 }
             }

+ 1 - 1
package.json

@@ -28,6 +28,6 @@
     "uuid": "^3.1.0"
   },
   "scripts": {
-    "start": "nodemon server.js"
+    "start": "C:\\Users\\mai\\AppData\\Roaming\\npm\\babel-node.cmd server.js"
   }
 }

+ 5 - 0
public/web/number_util.js

@@ -1,6 +1,11 @@
 /**
  * Created by chen on 2017/7/5.
  */
+
+Number.prototype.toDecimal = function (ADigit) {
+    return parseFloat(this.toFixed(ADigit));
+};
+
 var  number_util = {
     isNumber : function (obj) {
         return obj === +obj;

+ 1 - 0
public/web/sheet/sheet_common.js

@@ -129,6 +129,7 @@ var sheetCommonObj = {
                 sheet.setValue(row, col, val, ch);
             }
         }
+        this.lockCells(sheet,setting);
         sheet.resumeEvent();
         sheet.resumePaint();
         //me.shieldAllCells(sheet);

+ 16 - 16
public/web/tree_sheet/tree_sheet_helper.js

@@ -68,21 +68,21 @@ var TREE_SHEET_HELPER = {
                 var iRow = node.serialNo();
                 var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
 
-                var getFieldText = function () {
-                    var fields = colSetting.data.field.split('.');
-                    var validField = fields.reduce(function (field1, field2) {
-                        if (eval('node.data.' + field1)) {
-                            return field1 + '.' + field2
-                        } else {
-                            return field1;
-                        }
-                    });
-                    if (eval('node.data.' + validField)) {
-                        return eval('node.data.' + validField);
-                    } else {
-                        return '';
-                    }
-                };
+                // var getFieldText = function () {
+                //     var fields = colSetting.data.field.split('.');
+                //     var validField = fields.reduce(function (field1, field2) {
+                //         if (eval('node.data.' + field1)) {
+                //             return field1 + '.' + field2
+                //         } else {
+                //             return field1;
+                //         }
+                //     });
+                //     if (eval('node.data.' + validField)) {
+                //         return eval('node.data.' + validField);
+                //     } else {
+                //         return '';
+                //     }
+                // };
                 var getFieldText2 = function () {
                     var fields = colSetting.data.field.split('.'), iField, data = node.data;
                     for (iField = 0; iField < fields.length; iField++) {
@@ -261,4 +261,4 @@ var TREE_SHEET_HELPER = {
             TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, sheet, true);
         });
     }
-};
+};

+ 11 - 0
server.js

@@ -12,6 +12,7 @@ cfgCacheUtil.setupDftCache();
 let path = require('path');
 let session = require('express-session');
 let DBStore = require('connect-mongo')(session);
+let fs = require('fs');
 
 let URL = require('url');
 
@@ -183,6 +184,16 @@ app.use(function(err, req, res, next) {
     console.error(err.stack);
     res.status(500).send('500 Error');
 });
+
+//设置Date Format函数
+fs.readFile(__dirname + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
+    eval(data);
+    // let dt = new Date();
+    // console.log(dt.Format('yyyy-M-dd'));
+    // console.log(dt.Format('yyyy 年 M 月 dd 日'));
+    // console.log(dt.Format('yyyy 年 M 月 20 日'));
+});
+
 app.listen(6060, function(){
     console.log('server started!');
 });

+ 19 - 0
test/public/testLoadDateFormat.js

@@ -0,0 +1,19 @@
+/**
+ * Created by Tony on 2017/7/13.
+ */
+let test = require('tape');
+let fs = require("fs");
+
+test('std glj types test1', function(t){
+    //console.log(__dirname.slice(0, __dirname.length - 12) + '/public/web/date_util.js');
+    fs.readFile(__dirname.slice(0, __dirname.length - 12) + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
+        eval(data);
+        let dt = new Date();
+        //dt.setMonth(dt.getMonth() + 3);
+        t.equal(dt.Format('yyyy-M-dd'), "2017-7-13");
+        t.equal(dt.Format('yyyy年M月dd日'), "2017年7月13日");
+        t.equal(dt.Format('yyyy年M月20日'), "2017年7月20日");
+        t.end();
+    });
+});
+

+ 65 - 5
test/tmp_data/bills_grid_setting.js

@@ -4,12 +4,72 @@
 var BillsGridSetting ={
     "emptyRows":3,
     "headRows":1,
-    "treeCol": 0,
+    "treeCol": 2,
     "headRowHeight":[
         47
     ],
     "cols":[
         {
+            "width":50,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "ID"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Comic Sans MS"
+                ]
+            },
+            "data":{
+                "field":"ID",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":50,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "serialNo"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Comic Sans MS"
+                ]
+            },
+            "data":{
+                "field":"serialNo",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
             "width":150,
             "readOnly":false,
             "head":{
@@ -456,7 +516,7 @@ var BillsGridSetting ={
                 ]
             },
             "data":{
-                "field":"feeIndex.common.unitFee",
+                "field":"feesIndex.common.unitFee",
                 "vAlign":1,
                 "hAlign":2,
                 "font":"Arial"
@@ -486,7 +546,7 @@ var BillsGridSetting ={
                 ]
             },
             "data":{
-                "field":"feeIndex.common.totalFee",
+                "field":"feesIndex.common.totalFee",
                 "vAlign":1,
                 "hAlign":2,
                 "font":"Arial"
@@ -516,7 +576,7 @@ var BillsGridSetting ={
                 ]
             },
             "data":{
-                "field":"feeIndex.zangu.unitFee",
+                "field":"feesIndex.zangu.unitFee",
                 "vAlign":1,
                 "hAlign":2,
                 "font":"Arial"
@@ -546,7 +606,7 @@ var BillsGridSetting ={
                 ]
             },
             "data":{
-                "field":"feeIndex.zangu.totalFee",
+                "field":"feesIndex.zangu.totalFee",
                 "vAlign":1,
                 "hAlign":2,
                 "font":"Arial"

File diff suppressed because it is too large
+ 0 - 62761
test/tmp_data/data_15690.js


File diff suppressed because it is too large
+ 0 - 41073
test/tmp_data/drawing_data_10268.js


File diff suppressed because it is too large
+ 62761 - 0
test/tmp_data/test_bills_calc/bills_data_15690.js


+ 676 - 0
test/tmp_data/test_bills_calc/bills_grid_setting_test_calc.js

@@ -0,0 +1,676 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var BillsGridSetting ={
+    "emptyRows":3,
+    "headRows":1,
+    "treeCol": 1,
+    "headRowHeight":[
+        47
+    ],
+    "cols":[
+        {
+            "width":50,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "ID"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Comic Sans MS"
+                ]
+            },
+            "data":{
+                "field":"ID",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":300,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "项目编码"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Comic Sans MS"
+                ]
+            },
+            "data":{
+                "field":"code",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":50,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "类别"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"type",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":200,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "项目名称"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"name",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":40,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "计量\n单位"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ],
+                "wordWrap":[
+                    true
+                ]
+            },
+            "data":{
+                "field":"unit",
+                "vAlign":1,
+                "hAlign":1,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "取费专业"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":120,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "工程量计算规则"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"programID",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "工程量"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"quantity",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "含量"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":120,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "计算基数"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "费率(%)"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "综合单价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.common.unitFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "综合合价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.common.totalFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "人工单价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.labour.unitFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "人工合价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.labour.totalFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "机械费单价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.machine.unitFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "机械费合价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.machine.totalFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "材料费单价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.material.unitFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "材料费合价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.material.totalFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "暂估单价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.zangu.unitFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":80,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "暂估合价"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"feesIndex.zangu.totalFee",
+                "vAlign":1,
+                "hAlign":2,
+                "font":"Arial"
+            }
+        },
+        {
+            "width":120,
+            "readOnly":false,
+            "head":{
+                "titleNames":[
+                    "备注"
+                ],
+                "spanCols":[
+                    1
+                ],
+                "spanRows":[
+                    1
+                ],
+                "vAlign":[
+                    1
+                ],
+                "hAlign":[
+                    1
+                ],
+                "font":[
+                    "Arial"
+                ]
+            },
+            "data":{
+                "field":"",
+                "vAlign":1,
+                "hAlign":0,
+                "font":"Arial"
+            }
+        }
+    ]
+};

File diff suppressed because it is too large
+ 92413 - 0
test/tmp_data/test_bills_calc/drawing_data_10268.js


+ 5 - 0
web/building_saas/main/html/main.html

@@ -486,15 +486,20 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/fee_rate.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/ration_coe.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/ration_ass.js"></script>
 
     <script type="text/javascript" src="/public/web/id_tree.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/cache_tree.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/models/bills_calc.js"></script>
     <!-- Controller -->
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_controller.js"></script>
     <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_data_helper.js"></script>
     <!-- Test Data -->
     <script type="text/javascript" src="/test/tmp_data/bills_grid_setting.js"></script>
+    <!--<script type="text/javascript" src="/test/tmp_data/test_bills_calc/bills_grid_setting_test_calc.js"></script>
+    <script type="text/javascript" src="/test/tmp_data/test_bills_calc/bills_data_15690.js"></script>
+    <script type="text/javascript" src="/test/tmp_data/test_bills_calc/drawing_data_10268.js"></script>-->
     <!-- view -->
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_info.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_view.js"></script>

+ 11 - 0
web/building_saas/main/js/controllers/project_controller.js

@@ -67,5 +67,16 @@ ProjectController = {
 
             this.syncDisplayNewNode(sheetController, newNode);
         }
+    },
+    calculateAll: function (project, sheetController, CalcType) {
+        let date1 = new Date();
+        let calc = new BillsCalc(project, CalcType);
+        calc.calcAll();
+        calc = null;
+        let date2 = new Date();
+        console.log(date2 - date1);
+        sheetController.showTreeData();
+        let date3 = new Date();
+        console.log(date3 - date1);
     }
 }

+ 4 - 4
web/building_saas/main/js/models/bills.js

@@ -71,16 +71,16 @@ var Bills = {
             this.datas = datas;
             // generate Fees & Flags Index, For View & Calculate
             this.datas.forEach(function (data) {
-                data.FeesIndex = {};
+                data.feesIndex = {};
                 if (data.fees) {
                     data.fees.forEach(function (fee) {
-                        data.FeesIndex[fee.fieldName] = fee;
+                        data.feesIndex[fee.fieldName] = fee;
                     });
                 }
-                data.FlagsIndex = {};
+                data.flagsIndex = {};
                 if (data.flags) {
                     data.flags.forEach(function (flag) {
-                        data.FlagsIndex[flag.fieldName] = flag;
+                        data.flagsIndex[flag.fieldName] = flag;
                     });
                 }
             });

+ 225 - 0
web/building_saas/main/js/models/bills_calc.js

@@ -0,0 +1,225 @@
+/**
+ * Created by Mai on 2017/7/5.
+ */
+
+const rationContent = 0, rationPrice = 1, rationPriceConverse = 2, billsPrice = 3;
+
+const sumTotalFeeFlag = 0, totalFeeFlag = 1;
+const rationContentUnitFeeFlag = 0, averageQtyUnitFeeFlag = 1, billsPriceUnitFeeFlag = 2;
+
+let rationContentCalcFields = [
+    {'type': 'common', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
+    {'type': 'labour', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'material', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'machine', 'unitFeeFlag': rationContentUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+];
+let rationPriceCalcFields = [
+    {'type': 'common', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
+    {'type': 'labour', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'material', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'machine', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+];
+let rationPriceConverseCalcFields = [
+    {'type': 'common', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'labour', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'material', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'machine', 'unitFeeFlag': averageQtyUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+];
+let billsPriceCalcFields = [
+    {'type': 'common', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': totalFeeFlag},
+    {'type': 'labour', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'material', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+    {'type': 'machine', 'unitFeeFlag': billsPriceUnitFeeFlag, 'totalFeeFlag': sumTotalFeeFlag},
+];
+
+Number.prototype.toDecimal = function (ADigit) {
+    return parseFloat(this.toFixed(ADigit));
+};
+
+let nodeCalcObj = {
+    node: null,
+    digit: 2,
+    field: null,
+    findFee: function (fieldName) {
+        if (!this.node.data.fees) {
+            this.node.data.fees = [];
+        }
+        for (let fee of this.node.data.fees) {
+            if (fee.fieldName === fieldName) {
+                return fee;
+            }
+        }
+        return null;
+    },
+    AddFee: function (fieldName) {
+        let fee = {
+            'fieldName': fieldName,
+            'unitFee': 0,
+            'totalFee': 0,
+            'tenderUnitFee': 0,
+            'tenderTotalFee': 0
+        };
+        this.node.data.fees.push(fee);
+        this.node.data.feesIndex[fieldName] = fee;
+    },
+    checkFields: function (fields) {
+        for (let field of fields) {
+            if (!this.findFee(field.type)) {
+                this.AddFee(field.type);
+            }
+        }
+    },
+    getFee: function (data, fullField) {
+        let fields = fullField.split('.'), value = data;
+        for (let field of fields) {
+            if (value[field]) {
+                value = value[field];
+            } else {
+                return 0;
+            }
+        }
+        return value;
+    },
+    getFeeSplit: function (data, fullFields) {
+        let value = data;
+        for (let field of fullFields) {
+            if (value[field]) {
+                value = value[field];
+            } else {
+                return 0;
+            }
+        }
+        return value;
+    },
+    sumTotalFee: function() {
+        let result = 0, child;
+        for (child of this.node.children) {
+            result += this.getFee(child.data, this.field.totalFee);
+            //result += child.data.feesIndex[this.field.type].totalFee;
+            //result += this.getFeeSplit(child.data, this.field.totalFeeSplit);
+        }
+        return result;
+    },
+    averageQty: function() {
+        let result = 0, child, qty;
+        result = this.sumTotalFee(this.field);
+        qty = this.getFee(this.node.data, 'quantity');
+        if (qty !== 0) {
+            result = result / qty;
+        }
+        return result;
+    },
+    totalFee: function () {
+        return this.getFee(this.node.data, this.field.unitFee) * this.getFee(this.node.data, 'quantity');
+        //return this.node.data.feesIndex[this.field.type].unitFee * this.node.data.quantity;
+        //return this.getFeeSplit(this.node.data, this.field.unitFeeSplit) * this.getFee(this.node.data, 'quantity');
+    },
+    rationContentUnitFee: function () {
+        let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
+        if (qty === 0) {
+            qty = 1;
+        }
+        for (child of this.node.children) {
+            result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
+            //result += (child.data.feesIndex[this.field.type].unitFee * child.data.quantity / qty).toDecimal(this.digit);
+            //result += (this.getFeeSplit(child.data, this.field.unitFeeSplit) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
+        }
+        return result;
+    }
+};
+
+class BillsCalc {
+    constructor (project, CalcFlag) {
+        this.project = project;
+        this.CalcFlag = CalcFlag;
+        this.digit = 2;
+        switch (this.CalcFlag) {
+            case rationContent:
+                this.calcFieldName = rationContentCalcFields;
+                break;
+            case rationPrice:
+                this.calcFieldName = rationPriceCalcFields;
+                break;
+            case rationPriceConverse:
+                this.calcFieldName = rationPriceConverseCalcFields;
+                break;
+            case billsPrice:
+                this.calcFieldName = billsPriceCalcFields;
+                break;
+            default:
+                this.calcFieldName = [];
+        }
+        this.InitFields(this.calcFieldName);
+    };
+
+    calcLeaf (node, fields) {
+        nodeCalcObj.node = node;
+        nodeCalcObj.digit = this.digit;
+        nodeCalcObj.checkFields(fields);
+        let nodeCalc = nodeCalcObj;
+        for (let field of fields) {
+            nodeCalcObj.field = field;
+            switch (field.unitFeeFlag) {
+                case rationContentUnitFeeFlag:
+                    node.data.feesIndex[field.type].unitFee = nodeCalcObj.rationContentUnitFee().toDecimal(this.digit);
+                    break;
+                case averageQtyUnitFeeFlag:
+                    node.data.feesIndex[field.type].unitFee = nodeCalcObj.averageQty().toDecimal(this.digit);
+                    break;
+                // to do billsPriceUnitFeeFlag(套用定额计算程序)
+                // case billsPriceUnitFeeFlag:
+                //     break;
+                default:
+                    node.data.feesIndex[field.type].unitFee = 0;
+            }
+            switch (field.totalFeeFlag) {
+                case sumTotalFeeFlag:
+                    node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.digit);
+                    break;
+                case totalFeeFlag:
+                    node.data.feesIndex[field.type].totalFee = nodeCalcObj.totalFee().toDecimal(this.digit);
+                    break;
+                default:
+                    node.data.feesIndex[field.type].totalFee = 0;
+            }
+        }
+    };
+    calcParent (node, fields) {
+        nodeCalcObj.node = node;
+        nodeCalcObj.checkFields(fields);
+        for (let field of fields) {
+            nodeCalcObj.field = field;
+            node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.digit);
+        }
+    };
+    calcNodes (nodes) {
+        for (let node of nodes) {
+            if (node.sourceType !== this.project.Bills.getSourceType()) {
+                return;
+            }
+
+            if (node.source.children.length > 0) {
+                this.calcNodes(node.children);
+                this.calcParent(node, this.calcFieldName);
+            } else {
+                this.calcLeaf(node, this.calcFieldName);
+            }
+        }
+    };
+    calcAll () {
+        this.calcNodes(this.project.mainTree.roots);
+    };
+    InitFields (fields) {
+        for (let field of fields) {
+            if (field.unitFee) return;
+            field.unitFee = 'feesIndex.' + field.type + '.unitFee';
+            field.unitFeeSplit = field.unitFee.split('.');
+            field.totalFee = 'feesIndex.' + field.type + '.totalFee';
+            field.totalFeeSplit = field.totalFee.split('.');
+            field.tenderUnitFee = 'feesIndex.'+ field.type + '.tenderUnitFee';
+            field.tenderUnitFeeSplit = field.tenderUnitFee.split('.');
+            field.tenderTotalFee = 'feesIndex.' + field.type + '.tenderTotalFee';
+            field.tenderTotalFeeSplit = field.tenderTotalFee.split('.');
+        }
+    }
+}

+ 2 - 1
web/building_saas/main/js/models/main_consts.js

@@ -8,5 +8,6 @@ const ModuleNames = {
     feeRate: 'feeRate',
     projectGLJ: 'projectGLJ',
     ration_glj:'ration_glj',
-    ration_coe:'ration_coe'
+    ration_coe:'ration_coe',
+    ration_ass:'ration_ass'
 };

+ 15 - 2
web/building_saas/main/js/models/project.js

@@ -19,8 +19,12 @@ var PROJECT = {
         tools.doAfterUpdate = function(result){
             if (!result) { return }
             result.forEach(function(item){
-                if (me.modules[item.moduleName]){
-                    me.modules[item.moduleName].doAfterUpdate(item.err, item.data);
+                if(_.isArray(item)){
+                    item.forEach(function (e) {
+                        me.eachItem(e);
+                    })
+                }else {
+                    me.eachItem(item)
                 }
             });
         };
@@ -42,6 +46,12 @@ var PROJECT = {
             //me.test(result[0].data[0]);
             callback(0);
         };
+        tools.eachItem=function(item){
+            if (me.modules[item.moduleName]){
+                me.modules[item.moduleName].doAfterUpdate(item.err, item.data);
+            }
+        };
+
         /*tools.test = function(data){
             me._project.beginUpdate('修改名称');
             data.name = 'test';
@@ -60,6 +70,7 @@ var PROJECT = {
             this.GLJ = GLJ.createNew(this);
             this.ration_glj = ration_glj.createNew(this);
             this.ration_coe = ration_coe.createNew(this);
+            this.ration_ass = ration_ass.createNew(this);
             this.FeeRate = FeeRate.createNew(this);
 
             this.masterField = {ration: 'billsItemID'};
@@ -151,6 +162,8 @@ var PROJECT = {
                 success: function (result) {
                     if (!result.error) {
                         tools.doAfterLoad(result.data, callback);
+                        // for test calc
+                        //tools.doAfterLoad([{moduleName: 'bills', data: BillsData}, {'moduleName': 'ration', data: DrawingData}], callback);
                     } else {
                         alert('error: ' + result.message);
                         callback(result.error);

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

@@ -38,13 +38,13 @@ var Ration = {
             this.datas = datas;
             // generate Fees & Flags Index,For View & Calculate
             this.datas.forEach(function (data) {
-                data.FeesIndex = {};
+                data.feesIndex = {};
                 data.fees.forEach(function (fee) {
-                    data.FeesIndex[fee.fieldName] = fee;
+                    data.feesIndex[fee.fieldName] = fee;
                 });
-                data.FlagsIndex = {};
+                data.flagsIndex = {};
                 data.flags.forEach(function (flag) {
-                    data.FlagsIndex[flag.fieldName] = flag;
+                    data.flagsIndex[flag.fieldName] = flag;
                 });
                 that.maxRationID(data.ID);
             });
@@ -54,9 +54,17 @@ var Ration = {
             this.maxRationID(ID);
         }
 
-        // 提交数据后的错误处理方法
+        // refresh after update
         ration.prototype.doAfterUpdate = function(err, data){
+            var controller = projectObj.mainController, project = projectObj.project;
+            //var selected = projectObj.mainController.tree.selected;
+            console.log(controller.sheet.getSelections());
+
             // to do
+            console.log(controller.sheet.getCell(8, 9).value());
+            var selected = projectObj.project.mainTree.selected;
+            console.log(data);
+
         };
 
         ration.prototype.getTempRationData = function (id, billsID, serialNo) {
@@ -102,7 +110,6 @@ var Ration = {
             var br = this.getBillsSortRation(billsID);
             this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()],
                 [this.getInsertRationData(billsID, preRation), this.getCounterData()]);
-            //this.project.pushNow('insertRation', [this.getSourceType()], [this.getInsertRationData(billsID, preRation)]);
 
             var newRation = null;
             if (preRation) {
@@ -125,6 +132,8 @@ var Ration = {
                     data.updateData.code = std.code;
                     data.updateData.name = std.name;
                     data.updateData.unit = std.unit;
+                    data.updateData.libID = std.rationRepId;
+                    data.updateData.rationAssList =  projectObj.project.ration_ass.CreateNewAss(std);
                     newRation = data.updateData;
                 }
             });

+ 126 - 0
web/building_saas/main/js/models/ration_ass.js

@@ -0,0 +1,126 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var ration_ass = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var ration_ass = function (proj) {
+            this.gljTree = cacheTree.createNew(this);
+           // this.project = proj;
+            this.datas = [];
+
+            var sourceType = ModuleNames.ration_ass;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.ration_ass, this);
+        };
+
+        // prototype用于定义public方法
+        ration_ass.prototype.loadData = function (datas) {
+            this.datas = datas;
+        };
+
+        // 提交数据后返回数据处理
+        ration_ass.prototype.doAfterUpdate = function(err, data){
+            if(!err){
+                if(data.updateTpye=='ut_update'){
+                    this.refreshAfterUpdate(data);
+                }else if(data.updateTpye=='ut_delete'){
+                    this.refreshAfterDelete(data);
+                } else {
+                    this.refreshAfterSave(data);
+                }
+            }
+        };
+        ration_ass.prototype.refreshAfterSave=function(data){
+
+        };
+        ration_ass.prototype.refreshAfterUpdate=function(data){
+            console.log(data)
+            this.updateRation(data.rationID,data.doc);
+            //this.updateRationGLJ(data.ration_glj_list);
+            gljOprObj.assSheetData[data.editIndex].actualValue = data.actualValue;
+            sheetCommonObj.showData(gljOprObj.assSheet,gljOprObj.assSetting,gljOprObj.assSheetData);
+        };
+
+        ration_ass.prototype.updateRation = function (rationID,doc) {
+            var index =  _.findIndex(projectObj.project.Ration.datas,(ration)=>{
+                return ration.ID==rationID;
+            })
+            projectObj.project.Ration.datas[index].rationAssList = doc.rationAssList
+        };
+
+        ration_ass.prototype.updateRationGLJ = function (updateList) {
+            for(var i=0;i<updateList.length;i++){
+                var index =  _.findIndex(projectObj.project.ration_glj.datas,(glj)=>{
+                    return glj.ID==updateList[i].ID;
+                })
+                projectObj.project.ration_glj.datas[index].quantity=updateList[i].quantity;
+
+                var showIndex =  _.findIndex(gljOprObj.sheetData,(shglj)=>{
+                    return shglj.ID==updateList[i].ID;
+                })
+                gljOprObj.sheetData[showIndex].quantity=updateList[i].quantity;
+            }
+            sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,gljOprObj.sheetData);
+        };
+
+        ration_ass.prototype.refreshAfterDelete=function(data){
+            var glj_list = projectObj.project.ration_coe.datas;
+            _.remove(glj_list,data.query);
+            _.remove(gljOprObj.sheetData,data.query);
+            sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,gljOprObj.sheetData);
+        };
+        ration_ass.prototype.CreateNewAss = function (std) {
+            var newAssList = []
+            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;
+                    newAssList.push(ass);
+                }
+            }
+            return newAssList;
+        };
+        ration_ass.prototype.getUpdateData=function(type,query,doc,callfunction){
+            var updateData = [];
+            var newobj = {
+                'updateType': type,
+                'query': query,
+            }
+            if(doc){
+                newobj['doc']=doc;
+            }
+            if(callfunction){
+                newobj['updateFunction']=callfunction;
+            }
+            updateData.push(newobj);
+            return updateData;
+        };
+        ration_ass.prototype.updateActualValue=function(assList,index,newVal){
+            var selected = projectObj.project.mainTree.selected;
+            assList[index].actualValue=newVal;
+            var query = {
+                'ration':selected.data,
+                'editAss':assList[index],
+                'editIndex':index
+            };
+            var doc ={
+                rationAssList:assList,
+            };
+
+            var updateData = this.getUpdateData('ut_update',query,doc);
+
+            project.pushNow('updateRationAss',[this.getSourceType()],updateData);
+
+        };
+        return new ration_ass(project);
+    }
+
+
+
+};

+ 49 - 5
web/building_saas/main/js/models/ration_coe.js

@@ -47,15 +47,15 @@ var ration_coe = {
             // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
         };
         ration_coe.prototype.refreshAfterUpdate=function(data){
-            var glj_list = projectObj.project.ration_coe.datas;
-            var glj_index= _.findIndex(glj_list,(glj)=>{
-                return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
+            var coe_list = projectObj.project.ration_coe.datas;
+            var coe_index= _.findIndex(coe_list,(coe)=>{
+                return coe.ID==data.query.ID&&coe.projectID==data.query.projectID;
             })
             _.forEach(data.doc, function(n, key) {
-                glj_list[glj_index][key] = n;
+                coe_list[coe_index][key] = n;
             });
 
-            var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
+            var showList = _.filter(coe_list,{'projectID':data.query.projectID,'rationID':coe_list[coe_index].rationID});
             gljOprObj.coeSheetData=showList;
            sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,showList);
         };
@@ -84,6 +84,7 @@ var ration_coe = {
                     newCoe.name = '自定义系数';
                     newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
                     newCoe.isAdjust=0;
+                    newCoe.coes = this.getCustomerCoeData();
                 }else {
                     newCoe.coeID= data.rationCoeList[i];
                 }
@@ -92,6 +93,49 @@ var ration_coe = {
             criteria.updateType = 'ut_create';
             return criteria;
         };
+        ration_coe.prototype.getCustomerCoeData = function () {
+            var coeList = [];
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
+            coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
+            return coeList;
+        };
+
+        ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
+            var updateData = [];
+            var newobj = {
+                'updateType': type,
+                'query': query,
+            }
+            if(doc){
+                newobj['doc']=doc;
+            }
+            if(callfunction){
+                newobj['updateFunction']=callfunction;
+            }
+            updateData.push(newobj);
+            return updateData;
+        };
+        ration_coe.prototype.adjustCoeClick = function(recode,newval){
+            var query = {
+                'ID':recode.ID,
+                'projectID': recode.projectID,
+                'rationID':recode.rationID
+            };
+            var doc ={
+                isAdjust:newval,
+            };
+            var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
+            project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
+        };
+
+        ration_coe.prototype.updateCustomerCoe = function (data) {
+            var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
+            project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
+        };
         ration_coe.prototype.deleteByRation = function(ration){
             var coe_list = projectObj.project.ration_coe.datas;
             var newList =_.filter(coe_list,(coe)=>{

+ 35 - 13
web/building_saas/main/js/models/ration_glj.js

@@ -64,17 +64,29 @@ var ration_glj = {
             // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
         };
         ration_glj.prototype.refreshAfterUpdate=function(data){
+            console.log(data);
+            var rationID =0;
+            var me = this;
+            if(data.quantityRefresh){
+                data.glj_result.forEach(function (item) {
+                    rationID= me.refreshEachItme(item.doc,item.query);
+                })
+            }else {
+                rationID= me.refreshEachItme(data.doc,data.query);
+            }
+            var showList = _.filter(projectObj.project.ration_glj.datas,{'rationID':rationID});
+            gljOprObj.sheetData=showList;
+            sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList);
+        };
+        ration_glj.prototype.refreshEachItme = function (doc,query) {
             var glj_list = projectObj.project.ration_glj.datas;
             var glj_index= _.findIndex(glj_list,(glj)=>{
-                return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
+                return glj.ID==query.ID&&glj.projectID==query.projectID;
             })
-            _.forEach(data.doc, function(n, key) {
+            _.forEach(doc, function(n, key) {
                 glj_list[glj_index][key] = n;
             });
-
-            var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
-            gljOprObj.sheetData=showList;
-           sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList);
+            return glj_list[glj_index].rationID;
         };
         ration_glj.prototype.refreshAfterDelete=function(data){
             var glj_list = projectObj.project.ration_glj.datas;
@@ -211,16 +223,26 @@ var ration_glj = {
             updateData.push(newobj);
             return updateData;
         };
-        ration_glj.prototype.customQuantityUpdate = function(recode,newVal){
+        ration_glj.prototype.customQuantityUpdate = function(recode,newVal,text){
             var query = {
                 'ID':recode.ID,
-                'projectID': recode.projectID
+                'projectID': recode.projectID,
+                'rationID':recode.rationID
             };
-            var doc ={
-                customQuantity:newVal,
-                quantity:newVal
-            };
-            var updateData = this.getUpdateData('ut_update',query,doc);
+            var doc;
+            if(text===null){
+                doc ={
+                    customQuantity:null
+                };
+            }else {
+                doc ={
+                    customQuantity:newVal,
+                    quantity:newVal
+                };
+            }
+
+
+            var updateData = this.getUpdateData('ut_update',query,doc,'customQuantityUpdate');
             project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
 
         };

File diff suppressed because it is too large
+ 295 - 17
web/building_saas/main/js/views/glj_view.js


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

@@ -23,6 +23,9 @@ var projectObj = {
         this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
         this.project.loadDatas(function (err) {
             if (!err) {
+                BillsGridSetting.cols.forEach(function (col) {
+                    col.data.splitFields = col.data.field.split('.');
+                });
                 that.mainController = TREE_SHEET_CONTROLLER.createNew(that.project.mainTree, that.mainSpread.getActiveSheet(), BillsGridSetting);
                 that.mainController.showTreeData();
                 that.mainController.bind('refreshBaseActn', function (tree) {
@@ -47,7 +50,6 @@ var projectObj = {
 
 
                 that.mainController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
-                    console.log(projectObj.project);
                     gljOprObj.showDataIfRationSelect(node);
                 });
 
@@ -129,7 +131,31 @@ var projectObj = {
                                 controller.delete();
                             };
                         }
-
+                    }
+                },
+                "spr2":'--------',
+                "calculateAll_RationContent": {
+                    name: '造价计算(子目含量取费)',
+                    callback: function () {
+                        ProjectController.calculateAll(project, controller, rationContent);
+                    }
+                },
+                "calculateAll_RationPrice": {
+                    name: '造价计算(子目单价取费)',
+                    callback: function () {
+                        ProjectController.calculateAll(project, controller, rationPrice);
+                    }
+                },
+                "calculateAll_RationPriceConverse": {
+                    name: '造价计算(子目单价取费-反算)',
+                    callback: function () {
+                        ProjectController.calculateAll(project, controller, rationPriceConverse);
+                    }
+                },
+                "calculateAll_BillsPrice": {
+                    name: '造价计算(清单单价取费)',
+                    callback: function () {
+                        ProjectController.calculateAll(project, controller, billsPrice);
                     }
                 }
             }
@@ -184,14 +210,14 @@ $('#upMove').click(function () {
     var controller = projectObj.mainController, project = projectObj.project;
     var selected = controller.tree.selected, pre, preSerialNo;
 
+    if (selected.sourceType === project.Bills.getSourceType()) {
+        project.Bills.upMoveBills(selected.source);
+        controller.upMove();
+    } else if (selected.sourceType === project.Ration.getSourceType()) {
+        project.Ration.changePos(selected.source, selected.preSibling.source);
+        controller.upMove();
+    }
     if (selected) {
-        if (selected.sourceType === project.Bills.getSourceType()) {
-            project.Bills.upMoveBills(selected.source);
-            controller.upMove();
-        } else if (selected.sourceType === project.Ration.getSourceType()) {
-            project.Ration.changePos(selected.source, selected.preSibling.source);
-            controller.upMove();
-        }
     }
 });
 $('#downMove').click(function () {
@@ -208,4 +234,3 @@ $('#downMove').click(function () {
         }
     }
 });
-

+ 5 - 1
web/building_saas/main/js/views/sub_view.js

@@ -15,6 +15,10 @@ gljOprObj.initSheet(subSpread.getSheet(0));
 //附注条件
 gljOprObj.initCoeSheet(subSpread.getSheet(2));
 
+//辅助定额
+
+gljOprObj.initAssSheet(subSpread.getSheet(1));
+
 $("#linkGLJ").click(function(){
     subSpread.setActiveSheetIndex(0);
 
@@ -25,7 +29,7 @@ $("#linkGLJ").click(function(){
 $("#linkFZDE").click(function(){
     subSpread.setActiveSheetIndex(1);
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "辅助定额");
+  //  subSpread.getActiveSheet().setValue(0, 0, "辅助定额");
 });
 
 $("#linkFZTJ").click(function(){