Browse Source

Merge branch 'master' of http://192.168.1.12:3000/SmartCost/ConstructionCost

TonyKang 8 years ago
parent
commit
b5517d240c
35 changed files with 157552 additions and 103956 deletions
  1. 1 1
      modules/main/models/base_model.js
  2. 7 2
      modules/main/models/project.js
  3. 2 0
      modules/main/models/project_consts.js
  4. 15 2
      modules/main/models/ration.js
  5. 20 1
      modules/ration_glj/controllers/ration_glj_controller.js
  6. 126 0
      modules/ration_glj/facade/ration_ass_facade.js
  7. 148 0
      modules/ration_glj/facade/ration_coe_facade.js
  8. 171 23
      modules/ration_glj/facade/ration_glj_facade.js
  9. 28 0
      modules/ration_glj/models/ration_coe.js
  10. 4 3
      modules/ration_glj/models/ration_glj.js
  11. 70 2
      modules/ration_glj/models/ration_glj_temp.js
  12. 1 1
      package.json
  13. 1 1
      public/common_util.js
  14. 15 0
      public/web/number_util.js
  15. 26 1
      public/web/sheet/sheet_common.js
  16. 16 16
      public/web/tree_sheet/tree_sheet_helper.js
  17. 65 5
      test/tmp_data/bills_grid_setting.js
  18. 0 62761
      test/tmp_data/data_15690.js
  19. 0 41073
      test/tmp_data/drawing_data_10268.js
  20. 62761 0
      test/tmp_data/test_bills_calc/bills_data_15690.js
  21. 676 0
      test/tmp_data/test_bills_calc/bills_grid_setting_test_calc.js
  22. 92413 0
      test/tmp_data/test_bills_calc/drawing_data_10268.js
  23. 7 0
      web/building_saas/main/html/main.html
  24. 11 0
      web/building_saas/main/js/controllers/project_controller.js
  25. 16 6
      web/building_saas/main/js/models/bills.js
  26. 225 0
      web/building_saas/main/js/models/bills_calc.js
  27. 3 1
      web/building_saas/main/js/models/main_consts.js
  28. 5 1
      web/building_saas/main/js/models/project.js
  29. 7 6
      web/building_saas/main/js/models/ration.js
  30. 126 0
      web/building_saas/main/js/models/ration_ass.js
  31. 136 0
      web/building_saas/main/js/models/ration_coe.js
  32. 85 9
      web/building_saas/main/js/models/ration_glj.js
  33. 320 27
      web/building_saas/main/js/views/glj_view.js
  34. 36 10
      web/building_saas/main/js/views/project_view.js
  35. 9 4
      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();
     };
 

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

@@ -4,7 +4,9 @@
 var billsData = require('./bills');
 var rationData = require('./ration');
 var GLJData = require('./glj');
-var ration_glj_data = require('../../ration_glj/facade/ration_glj_facade')
+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;
@@ -14,10 +16,13 @@ var moduleMap = {};
 
 moduleMap[projectConsts.BILLS] = billsData;
 moduleMap[projectConsts.RATION] = rationData;
-moduleMap[projectConsts.GLJ] = GLJData;
+//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;
 
+
 var Project = function (){};
 
 Project.prototype.datas = [];

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

@@ -6,6 +6,8 @@ var projectConst = {
     RATION: 'ration',
     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];

+ 20 - 1
modules/ration_glj/controllers/ration_glj_controller.js

@@ -2,8 +2,11 @@
  * Created by chen on 2017/6/29.
  */
 let mongoose = require("mongoose")
+let ration_glj_facade = require('../facade/ration_glj_facade')
+
 module.exports={
-    createRationGLJ:createRationGLJ
+    createRationGLJ:createRationGLJ,
+    testGetQuantify:testGetQuantify
 }
 function createRationGLJ() {
     let gls = mongoose.model('ration_glj');
@@ -12,3 +15,19 @@ function createRationGLJ() {
     })
 }
 
+//测试获取消耗量:
+async function testGetQuantify() {
+    var condition = {
+        projectID:99,
+        projectGLJIDList:[60,61,62]
+    }
+
+    try{
+        let result = await ration_glj_facade.getQuantityByProjectGLJ(condition);
+        console.log(result)
+    }catch (err){
+        console.log(err);
+    }
+
+
+}

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

@@ -0,0 +1,126 @@
+/**
+ * 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');
+
+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;
+        let times =calculateTimes(editAss);
+        doRationAssAdjust(datas.query.ration,editAss,times,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,
+                        ration_glj_list:result.ration_glj_list,
+                        rationID:datas.query.ration.ID,
+                        editIndex:datas.query.editIndex,
+                        actualValue:editAss.actualValue
+                    }
+                };
+                callback(null,newObject);
+            }
+        })
+
+    }
+
+};
+
+async function doRationAssAdjust(ration,ass,times,doc) {
+    let result ={
+        err:null,
+        ration_glj_list:[]
+    }
+    try{
+        let assRation =await std_ration_lib_ration_items.findOne({rationRepId:ration.libID,code:ass.assistCode});
+        let gljList = assRation.rationGljList;
+        for(let i=0;i<gljList.length;i++){
+            let glj = gljList[i];
+            let calQuantity = glj.consumeAmt*times;
+            let update_ration_glj = await ration_glj.findOne({rationID:ration.ID,projectID:ration.projectID,GLJID:glj.gljId});
+            let newQuantity = update_ration_glj.rationItemQuantity+calQuantity;
+            await ration_glj.update({rationID:ration.ID,projectID:ration.projectID,GLJID:glj.gljId},{quantity:newQuantity});
+            result.ration_glj_list.push({ID:update_ration_glj.ID,quantity:newQuantity,rationID:ration.ID});
+        }
+        await rationModel.update({projectID:ration.projectID,ID:ration.ID},doc);
+        return result;
+    }catch (err){
+        result.err = err;
+        return result;
+    }
+}
+
+
+
+
+function delete_ration_ass(user_id,datas) {
+
+};
+
+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 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)
+            }
+        }
+    })
+}

+ 148 - 0
modules/ration_glj/facade/ration_coe_facade.js

@@ -0,0 +1,148 @@
+/**
+ * Created by chen on 2017/7/6.
+ */
+
+let mongoose = require('mongoose');
+const uuidV1 = require('uuid/v1')
+let consts = require('../../main/models/project_consts');
+let commonConsts = consts.commonConst;
+let _=require("lodash");
+let async_n = require("async");
+let coeMolde = mongoose.model('std_ration_lib_coe_list');
+let ration_coe = mongoose.model('ration_coe');
+
+module.exports={
+    save:save,
+    getData:getData,
+    delete_ration_coe:delete_ration_coe
+}
+let operationMap={
+    'ut_create':create_ration_coe,
+    'ut_update':update_ration_coe,
+    'ut_delete':delete_ration_coe
+};
+
+function create_ration_coe(user_id,datas) {
+    return function (callback) {
+        let ration_coe_list=datas.ration_coe_list;
+        var tasks=[];
+        for(let i=0;i<ration_coe_list.length;i++){
+            ration_coe_list[i].ID = uuidV1();
+            ration_coe_list[i].seq = i;
+            tasks.push(get_lib_coe_info(ration_coe_list[i]));
+        }
+        async_n.parallel(tasks,(err,results)=>{
+            if(err){
+                callback(err,results)
+            }else {
+                ration_coe.insertMany(results,(err,doc)=>{
+                    if(err){
+                        callback(err,null);
+                    }else {
+                        let returndata ={
+                            updateTpye:commonConsts.UT_CREATE,
+                            moduleName:'ration_coe',
+                            data:results
+                        }
+                        callback(null,returndata)
+                    }
+                });
+            }
+        })
+
+    }
+}
+function update_ration_coe(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 delete_ration_coe(data) {
+    return function (callback) {
+        ration_coe.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
+            commonCallback(callback,result,err)
+        });
+    }
+}
+
+
+function get_lib_coe_info(ration_coe) {
+    return function (cb) {
+        if(ration_coe.coeID == -1){//自定义系数
+            cb(null,ration_coe);
+        }else {
+           let query ={
+                "libID": ration_coe.libID,
+                "ID": ration_coe.coeID,
+                "$or": [{"isDeleted": null}, {"isDeleted": false}]
+            };
+            coeMolde.findOne(query,(err,coe)=>{
+                if(err){
+                    cb(err,'')
+                }else {
+                    ration_coe.name = coe.name;
+                    ration_coe.content = coe.content;
+                    ration_coe.isAdjust=0;
+                    ration_coe.coes = coe.coes;
+                    cb(null,ration_coe);
+                }
+            })
+        }
+    }
+}
+
+
+
+function getData(projectID, callback) {
+    ration_coe.find({'projectID':projectID}).sort('seq').exec((err,datas)=>{
+        if(err){
+            callback(1, '', null);
+        }else {
+            callback(0, consts.projectConst.RATION_COE, datas);
+        }
+    })
+}
+
+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)
+            }
+        }
+    })
+}
+
+function commonCallback(callback,result,err) {
+    if(err){
+        callback(err,'');
+    }else {
+        callback(null,result);
+    }
+}

+ 171 - 23
modules/ration_glj/facade/ration_glj_facade.js

@@ -8,42 +8,127 @@ let consts = require('../../main/models/project_consts')
 let commonConsts = consts.commonConst;
 let _=require("lodash");
 let ration_glj = mongoose.model('ration_glj');
+import GLJListModel from '../../glj/models/glj_list_model';
 //let std_ration_lib_glj_list_model = require('../../ration_repository/models/glj_repository');
 let std_ration_lib_glj_list_model = mongoose.model('std_ration_lib_glj_list');
-let async = require("async");
+let async_n = require("async");
 let ration = mongoose.model('ration');
+let ration_coe_facade = require('./ration_coe_facade');
 
 let operationMap={
     'ut_create':create_ration_glj,
     'ut_update':update_ration_glj,
     'ut_delete':delete_ration_glj
+};
+let updateFunctionMap = {
+    'normalUpdate':normalUpdate,
+    'marketPriceAdjustUpdate':marketPriceAdjustUpdate
 }
 
-
 module.exports={
     save:save,
     getData:getData,
-    deleteByRation:deleteByRation
+    deleteByRation:deleteByRation,
+    getQuantityByProjectGLJ:getQuantityByProjectGLJ
+}
+
+
+/**
+ * 根据项目工料机ID和项目ID取消耗量
+ *
+ * @param {object} condition
+ * @return Array
+ */
+async function getQuantityByProjectGLJ(condition) {
+    let query ={
+        $and:[
+            {'projectID':condition.projectID},
+            {'projectGLJID':{$in:condition.projectGLJIDList}}
+        ]
+    }
+
+
+    let results = await   ration_glj.find(query,['projectGLJID','quantity']);
+    return combineQuantity(results);
+}
+
+function combineQuantity(results) {
+    var resultMap = {};
+    _.forEach(results,function (data) {
+        if(resultMap.hasOwnProperty(data.projectGLJID)){
+            resultMap[data.projectGLJID] += data.quantity;
+        }else {
+            resultMap[data.projectGLJID] = data.quantity;
+        }
+    })
+
+    var resultList =[];
+    for(let key in resultMap){
+       let newObject = {
+            'projectGLJID':key,
+            'quantity':resultMap[key]
+        }
+        resultList.push(newObject)
+    }
+    return resultList;
 }
 
+
 function get_lib_glj_info(ration_glj) {
     return function (cb) {
-        std_ration_lib_glj_list_model.findOne({'ID':ration_glj.GLJID},(err,glj)=>{
+        std_ration_lib_glj_list_model.findOne({'ID':ration_glj.GLJID,'repositoryId':ration_glj.glj_repository_id},(err,glj)=>{
             if(err){
                 cb(err,'')
-            }else {
+            }else if(glj){
                 ration_glj.name = glj.name;
                 ration_glj.code = glj.code;
                 ration_glj.unit = glj.unit;
                 ration_glj.specs = glj.specs;
                 ration_glj.basePrice = glj.basePrice;
                 ration_glj.gljDistType = glj.gljDistType;
-                cb(null,ration_glj)
+                ration_glj.type = glj.gljType;
+                getInfoFromProjectGLJ(ration_glj).then(function (result) {
+                    if(result){
+                        cb(null,result);
+                    }else {
+                        cb(new Error('get project glj error'),null);
+                    }
+                });
+            }else {
+                cb(null,null);
             }
         })
     }
 }
 
+async function getInfoFromProjectGLJ(ration_glj) {
+     let data = {
+         glj_repository_id: ration_glj.glj_repository_id,
+         project_id: ration_glj.projectID,
+         code: ration_glj.code,
+         name: ration_glj.name,
+         specs: ration_glj.specs,
+         unit: ration_glj.unit,
+         type: ration_glj.type,
+         type_of_work: ration_glj.type,
+         base_price: ration_glj.basePrice,
+         market_price: ration_glj.basePrice
+     };
+     try {
+         let projectGljModel = new GLJListModel();
+         let result = await projectGljModel.addList(data);
+         ration_glj.marketPrice=result.unit_price.market_price;
+         ration_glj.adjustPrice=result.adjust_price;
+         ration_glj.projectGLJID=result.id;
+         ration_glj.isEstimate=result.is_evaluate;
+         return ration_glj;
+     } catch (err) {
+         console.log(err);
+         return null;
+     }
+
+ }
+
 function create_ration_glj(user_id,datas) {
     return function (callback) {
         let ration_glj_list=datas.ration_glj_list;
@@ -52,7 +137,7 @@ function create_ration_glj(user_id,datas) {
             ration_glj_list[i].ID = uuidV1();
             tasks.push(get_lib_glj_info(ration_glj_list[i]))
         }
-        async.parallel(tasks,(err,results)=>{
+        async_n.parallel(tasks,(err,results)=>{
             if(err){
                 callback(err,results)
             }else {
@@ -75,7 +160,16 @@ function create_ration_glj(user_id,datas) {
 }
 
 function update_ration_glj(user_id,datas) {
-    return function (callback) {
+    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_glj.update(datas.query,datas.doc,(err,result)=>{
             if(err){
                 callback(err,'');
@@ -90,11 +184,49 @@ function update_ration_glj(user_id,datas) {
                 }
                 callback(null,returndata)
             }
+        })
+    }
+}
 
+
+function marketPriceAdjustUpdate(user_id,datas) {
+    return function (callback) {
+        updateprojectGljAndRationGLJ(datas.query,datas.doc).then((result)=>{
+            let returndata ={
+                moduleName:'ration_glj',
+                data:{
+                    updateTpye:commonConsts.UT_UPDATE,
+                    query:datas.query,
+                    doc:result
+                }
+            }
+            callback(null,returndata)
         })
+
     }
 }
 
+async function updateprojectGljAndRationGLJ(query,doc) {
+    try {
+        let gljListModel = new GLJListModel();
+        let result = await gljListModel.modifyMarketPrice(doc);
+        let updateDoc ={
+            marketPrice:result.unit_price.market_price,
+            marketPriceAdjust:doc.market_price,
+            projectGLJID:result.id,
+            isEstimate:result.is_evaluate,
+            name : result.name,
+            code:result.code
+        };
+        let updateresult = await ration_glj.findOneAndUpdate(query, updateDoc)
+        return updateDoc;
+
+        } catch (error) {
+            console.log(error);
+         }
+}
+
+
 function delete_ration_glj(user_id,datas) {
     return function (callback) {
         if(datas.deleteType=="RATION"){
@@ -109,16 +241,30 @@ function delete_ration_glj(user_id,datas) {
 
 function deleteByRation(datas,callback) {
     let data = datas.updateData;
-    ration_glj.deleteMany({projectID: data.projectID, rationID: data.ID},callback);
+    let tasks=[];
+    tasks.push(deleteGLJList(data));
+    tasks.push(ration_coe_facade.delete_ration_coe(data))
+    async_n.parallel(tasks,function (err,result) {
+        commonCallback(callback,result,err)
+    })
+}
+
+function  deleteGLJList(data) {
+    return function (callback) {
+        ration_glj.deleteMany({projectID: data.projectID, rationID: data.ID},(err,result)=>{
+            commonCallback(callback,result,err)
+        });
+    }
 }
 
+
 function deleteByBill(user_id,datas,callback) {
     let tasks = [];
     tasks.push(startingTask("deleteByBill"));
     tasks.push(getRationsByBill(datas));
     tasks.push(deleteRationsbyBill(user_id,datas));
     tasks.push(deleteByMultiRations(datas));
-    async.waterfall(tasks,function (err,results) {
+    async_n.waterfall(tasks,function (err,results) {
         if(err){
             callback(err,'');
         }else {
@@ -189,19 +335,16 @@ function deleteByMultiRations(datas) {
         var deleteOne=function (ration) {
             return function (callback) {
                 ration_glj.deleteMany({projectID: ration.projectID, rationID: ration.ID},function (err,result) {
-                    if(err){
-                        callback(err,'');
-                    }else {
-                        callback(null,result);
-                    }
+                    commonCallback(callback,result,err)
                 });
             }
         }
         let rations = results.rations;
         for(let i=0;i<rations.length;i++){
             delete_tasks.push(deleteOne(rations[i]._doc));
+            delete_tasks.push(ration_coe_facade.delete_ration_coe(rations[i]._doc));
         }
-        async.parallel(delete_tasks,(err,results)=>{
+        async_n.parallel(delete_tasks,(err,results)=>{
             if (err){
                 deleteCallBack(err,'')
             }else {
@@ -221,15 +364,15 @@ function  deleteByRation(doc) {
 */
 
 function save (user_id, datas, callback) {
-    let perations=[];
+    let operations=[];
     if(_.isArray(datas)){
         for(let i=0;i<datas.length;i++){
-            perations.push(operationMap[datas[i].updateType](user_id,datas[i]));
+            operations.push(operationMap[datas[i].updateType](user_id,datas[i]));
         }
     }else {
-        perations.push(operationMap[datas.updateType](user_id,datas));
+        operations.push(operationMap[datas.updateType](user_id,datas));
     }
-    async.parallel(perations,function (err,results) {
+    async_n.parallel(operations,function (err,results) {
         if(err){
             callback(err,'');
         }else {
@@ -243,7 +386,6 @@ function save (user_id, datas, callback) {
 }
 
 function getData(projectID, callback) {
-    console.log("ration_glj getData function");
     ration_glj.find({'projectID':projectID},(err,datas)=>{
         if(err){
             callback(1, '', null);
@@ -251,6 +393,12 @@ function getData(projectID, callback) {
             callback(0, consts.projectConst.RATION_GLJ, datas);
         }
     })
+}
 
-
-}
+function commonCallback(callback,result,err) {
+    if(err){
+        callback(err,'');
+    }else {
+        callback(null,result);
+    }
+}

+ 28 - 0
modules/ration_glj/models/ration_coe.js

@@ -0,0 +1,28 @@
+/**
+ * Created by chen on 2017/6/29.
+ */
+var mongoose = require('mongoose'),
+    Schema = mongoose.Schema;
+
+var coeSchema = mongoose.Schema({
+    coeType: String,                // 系数类型,指作用范围:// 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
+    gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
+    operator: String,               // 运算符(*、+、-、=)
+    amount: String,                 // 调整的量
+    _id: false
+});
+
+var coeListSchema = mongoose.Schema({
+    libID: Number,                      // 所属定额库ID
+    ID: String,                         // 系数ID(流水号ID)
+    name: String,                       // 名称
+    content: String,                    // 说明
+    rationID:Number,
+    projectID:Number,
+    coeID:Number,
+    isAdjust:Number, //0不调整,1调整
+    seq:Number,//序数,排序用
+    coes: [coeSchema]
+}, {versionKey: false});
+
+mongoose.model('ration_coe', coeListSchema);

+ 4 - 3
modules/ration_glj/models/ration_glj.js

@@ -9,20 +9,21 @@ var ration_glj = new Schema({
     GLJID:Number,
     projectID: Number,
     rationID:Number,
+    projectGLJID:Number,
     name:String,
     code:String,
     specs:String,
     unit:String,
     basePrice:Number,
     gljDistType:String,
-    gljType:Number,
+    type:Number,
     quantity:Number,
     customQuantity:Number,
     rationItemQuantity:Number,
     marketPrice:Number,
     adjustPrice:Number,
-    marketPriceAdjest:Number,
-    isEstimate:Boolean
+    marketPriceAdjust:Number,
+    isEstimate:Number
 },{versionKey:false});
 
 mongoose.model('ration_glj', ration_glj);

+ 70 - 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,61 @@ let rationSchema = new Schema({
     fees: [subSchema.feesSchema],
     // 标记字段
     flags: [subSchema.flagsSchema],
-    deleteInfo: deleteSchema
+    deleteInfo: deleteSchema,
+    rationAssList: [rationAssItemSchema]
 });
 
-mongoose.model("ration", rationSchema, "ration");
+mongoose.model("ration", rationSchema, "ration");
+
+var coeSchema = mongoose.Schema({
+    coeType: String,                // 系数类型,指作用范围:
+                                    // 单个(如:111量0.001)、人工类、材料类、机械类、全部(如:定额×0.925)。
+    gljID: Number,                  // 要调整的工料机ID(当coeType=0时有效)
+    operator: String,               // 运算符(*、+、-、=)
+    amount: String,                 // 调整的量
+    _id: false
+});
+
+var coeListSchema = mongoose.Schema({
+    libID: Number,                      // 所属定额定ID
+    ID: Number,                         // 系数ID(流水号ID)
+    name: String,                       // 名称
+    content: String,                    // 说明
+    coes: [coeSchema]
+}, {versionKey: false});
+
+ 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")

+ 1 - 1
package.json

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

+ 1 - 1
public/common_util.js

@@ -17,4 +17,4 @@ function deleteEmptyObject(arr) {
             i = i - 1;
         };
     };
-};
+};

+ 15 - 0
public/web/number_util.js

@@ -0,0 +1,15 @@
+/**
+ * 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;
+    },
+
+
+}

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

@@ -92,6 +92,8 @@ var sheetCommonObj = {
         var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
         sheet.suspendPaint();
         sheet.suspendEvent();
+        //sheet.addRows(row, 1);
+
         sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
         for (var col = 0; col < setting.header.length; col++) {
             var hAlign = "left", vAlign = "center";
@@ -108,11 +110,26 @@ var sheetCommonObj = {
                 //sheet.setStyle(row,col,style,GC.Spread.Sheets.SheetArea.viewport);
                 sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
             }
+            if(setting.header[col].cellType === "checkBox"){//clear and reset
+                var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
+                sheet.deleteColumns(col,1);
+                sheet.addColumns(col, 1);
+                sheet.setValue(0, col, setting.header[col].headerName, header);
+                sheet.setColumnWidth(col, setting.header[col].headerWidth?setting.header[col].headerWidth:100);
+            }
             for (var row = 0; row < data.length; row++) {
                 //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
-                sheet.setValue(row, col, data[row][setting.header[col].dataCode], ch);
+                var val = data[row][setting.header[col].dataCode];
+                if(val&&setting.header[col].dataType === "Number"){
+                    val =parseFloat(val).toFixed(2);
+                }
+                if(val!=null&&setting.header[col].cellType === "checkBox"){
+                    this.setCheckBoxCell(row,col,sheet,val)
+                 }
+                sheet.setValue(row, col, val, ch);
             }
         }
+        this.lockCells(sheet,setting);
         sheet.resumeEvent();
         sheet.resumePaint();
         //me.shieldAllCells(sheet);
@@ -165,6 +182,14 @@ var sheetCommonObj = {
             }
         }
     },
+    setCheckBoxCell(row,col,sheet,val){
+        var c = new GC.Spread.Sheets.CellTypes.CheckBox();
+        c.isThreeState(false);
+        sheet.setCellType(row, col,c,GC.Spread.Sheets.SheetArea.viewport);
+        sheet.getCell(row, col).value(val);
+        sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
+
+    },
     chkIfEmpty: function(rObj, setting) {
         var rst = true;
         if (rObj) {

+ 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);
         });
     }
-};
+};

+ 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


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

@@ -469,6 +469,7 @@
     <!-- Common -->
     <script type="text/javascript" src="/public/web/common_ajax.js"></script>
     <script type="text/javascript" src="/public/web/url_util.js"></script>
+    <script type="text/javascript" src="/public/web/number_util.js"></script>
     <script type="text/javascript" src="/public/web/sheet/sheet_common.js"></script>
     <!--报表 zTree -->
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
@@ -484,15 +485,21 @@
     <script type="text/javascript" src="/web/building_saas/main/js/models/glj.js"></script>
     <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);
     }
 }

+ 16 - 6
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;
                     });
                 }
             });
@@ -147,12 +147,22 @@ var Bills = {
             //project.endUpdate();
             var moudles =[ModuleNames.bills,ModuleNames.ration_glj];
             var deleteDatas=[tools.coverseTreeUpdateData(deleteData, this.project.ID()),ration_glj.getDeleteDataByBills(deleteData)];
-           // project.ration.getDeleteDataByBill(node);
+            project.ration_glj.deleteByBills(deleteData);
             project.pushNow('deleteBILL', moudles, deleteDatas);
-
+            this.delete(deleteData);
 
            // return this.tree.delete(node);
         };
+        bills.prototype.delete=function(deleteData){
+            for(var i=0;i<deleteData.length;i++){
+                var billID = deleteData[i].data.ID;
+                 this.datas =_.filter(this.datas,(bill)=>{
+                    return bill.ID!=billID;
+                });
+            }
+        }
+
+
         bills.prototype.upMoveBills = function (node) {
             var upMoveData = node.getUpMoveData();
             project.pushNow('upMoveBills', this.getSourceType(), tools.coverseTreeUpdateData(upMoveData, this.project.ID()));

+ 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('.');
+        }
+    }
+}

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

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

+ 5 - 1
web/building_saas/main/js/models/project.js

@@ -58,7 +58,9 @@ var PROJECT = {
             this.Bills = Bills.createNew(this);
             this.Ration = Ration.createNew(this);
             this.GLJ = GLJ.createNew(this);
-            this.ration_glj = ration_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'};
@@ -150,6 +152,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);

+ 7 - 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,7 +54,7 @@ var Ration = {
             this.maxRationID(ID);
         }
 
-        // 提交数据后的错误处理方法
+        // 提交数据后更新前端缓存
         ration.prototype.doAfterUpdate = function(err, data){
             // to do
         };
@@ -102,7 +102,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 +124,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);
+    }
+
+
+
+};

+ 136 - 0
web/building_saas/main/js/models/ration_coe.js

@@ -0,0 +1,136 @@
+/**
+ * Created by Mai on 2017/4/1.
+ */
+var ration_coe = {
+    createNew: function (project) {
+        // 用户定义private方法
+        var tools = {};
+
+        // 所有通过this访问的属性,都不应在此单元外部进行写入操作
+        var ration_coe = function (proj) {
+            this.gljTree = cacheTree.createNew(this);
+           // this.project = proj;
+            this.datas = [];
+
+            var sourceType = ModuleNames.ration_coe;
+            this.getSourceType = function () {
+                return sourceType;
+            }
+            proj.registerModule(ModuleNames.ration_coe, this);
+        };
+
+        // prototype用于定义public方法
+        ration_coe.prototype.loadData = function (datas) {
+            this.datas = datas;
+        };
+
+        // 提交数据后返回数据处理
+        ration_coe.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_coe.prototype.refreshAfterSave=function(data){
+            if(projectObj.project.ration_coe.datas&&Array.isArray(projectObj.project.ration_coe.datas)){
+                projectObj.project.ration_coe.datas = projectObj.project.ration_coe.datas.concat(data);
+            }else {
+                projectObj.project.ration_coe.datas = data;
+            }
+            sheetCommonObj.showData(gljOprObj.coeSheet,gljOprObj.coeSetting,data);
+            gljOprObj.coeSheetData=data;
+            // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
+        };
+        ration_coe.prototype.refreshAfterUpdate=function(data){
+            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) {
+                coe_list[coe_index][key] = n;
+            });
+
+            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);
+        };
+        ration_coe.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_coe.prototype.getRationCoedata=function(newRation,data){
+            var criteria= {};
+            criteria.ration_coe_list = [];
+            var dataLength = 0;
+            if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
+                dataLength = data.rationCoeList.length
+            }
+            for(var i=0;i<=dataLength;i++){;
+                var newCoe = {
+                    libID :data.rationRepId,
+                    rationID:newRation.ID,
+                    projectID :  newRation.projectID
+                }
+                if(i==dataLength){
+                    newCoe.coeID=-1;
+                    newCoe.name = '自定义系数';
+                    newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
+                    newCoe.isAdjust=0;
+                }else {
+                    newCoe.coeID= data.rationCoeList[i];
+                }
+                criteria.ration_coe_list.push(newCoe);
+            }
+            criteria.updateType = 'ut_create';
+            return criteria;
+        };
+        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
+            };
+            var doc ={
+                isAdjust:newval,
+            };
+            var updateData = this.getUpdateData('ut_update',query,doc);
+            project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
+        };
+
+        ration_coe.prototype.deleteByRation = function(ration){
+            var coe_list = projectObj.project.ration_coe.datas;
+            var newList =_.filter(coe_list,(coe)=>{
+                return coe.rationID!=ration.ID;
+            });
+            if(newList!=undefined){
+                projectObj.project.ration_coe.datas = newList;
+            }
+        };
+        return new ration_coe(project);
+    }
+
+
+
+};

+ 85 - 9
web/building_saas/main/js/models/ration_glj.js

@@ -60,6 +60,7 @@ var ration_glj = {
                 projectObj.project.ration_glj.datas = data;
             }
             sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,data);
+            gljOprObj.sheetData=data;
             // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
         };
         ration_glj.prototype.refreshAfterUpdate=function(data){
@@ -67,8 +68,9 @@ var ration_glj = {
             var glj_index= _.findIndex(glj_list,(glj)=>{
                 return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
             })
-            glj_list[glj_index].customQuantity=data.doc.customQuantity;
-            glj_list[glj_index].quantity=data.doc.quantity;
+            _.forEach(data.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;
@@ -117,6 +119,8 @@ var ration_glj = {
         };
 
         ration_glj.prototype.addRationGLJ = function (newRation,data) {
+            var souceTypeList=[];
+            var criteriaDataList = [];
             if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){
                 let criteria= {};
                 criteria.ration_glj_list = [];
@@ -128,12 +132,21 @@ var ration_glj = {
                     newGLJ.rationID = newRation.ID;
                     newGLJ.rationItemQuantity= temdata.consumeAmt;
                     newGLJ.quantity=temdata.consumeAmt;
-                    criteria.ration_glj_list.push(newGLJ)
+                    newGLJ.glj_repository_id=data.rationRepId;
+                    criteria.ration_glj_list.push(newGLJ);
                 }
                 criteria.updateType = 'ut_create';
-                project.pushNow('addRationGLJ',[this.getSourceType()],[criteria]);
+                souceTypeList.push(this.getSourceType());
+                criteriaDataList.push(criteria);
             }
+            var ration_coe = projectObj.project.ration_coe;
+            var rationCoeData = ration_coe.getRationCoedata(newRation,data);
+            souceTypeList.push(ration_coe.getSourceType());
+            criteriaDataList.push(rationCoeData);
+            project.pushNow('addRationGLJAndRationCoe',souceTypeList,criteriaDataList);
+
         };
+
         ration_glj.prototype.getDeleteDataByRation=function(rationData){
             var updateData = [];
             updateData.push({'deleteType':'RATION','updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}});
@@ -156,16 +169,79 @@ var ration_glj = {
                 projectObj.project.ration_glj.datas = newList;
             }
         };
+        ration_glj.prototype.deleteByBills=function(deleteData){
+            var rationList = projectObj.project.Ration.datas;
+            var deleteRationList = [];
+            for(var i=0;i<deleteData.length;i++){
+                var billID = deleteData[i].data.ID;
+                var raList =_.filter(rationList,(ration)=>{
+                    return ration.billsItemID==billID;
+                });
+                deleteRationList = deleteRationList.concat(raList);
+            }
+            for(var i=0;i<deleteRationList.length;i++){
+                this.deleteByRation(deleteRationList[i]);
+                projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
+                projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
+            }
+        }
+
+
         ration_glj.prototype.updataOrdelete=function(row){
-            var updateData = [];
+            var updateData = null;
             if(row.rationItemQuantity==0){
-                updateData.push({'updateType': 'ut_delete', 'query': {'ID': row.ID, 'projectID': row.projectID}});
+                updateData=this.getUpdateData('ut_delete',{'ID': row.ID, 'projectID': row.projectID});
             }else {
-                updateData.push({'updateType': 'ut_update','query': {'ID': row.ID, 'projectID': row.projectID},'doc':{'quantity':0,'customQuantity':0}});
+                updateData= this.getUpdateData('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
             }
-            project.pushNow('addRationGLJ',[this.getSourceType()],updateData)
-        }
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData)
+        };
+        ration_glj.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_glj.prototype.customQuantityUpdate = function(recode,newVal){
+            var query = {
+                'ID':recode.ID,
+                'projectID': recode.projectID
+            };
+            var doc ={
+                customQuantity:newVal,
+                quantity:newVal
+            };
+            var updateData = this.getUpdateData('ut_update',query,doc);
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
 
+        };
+        ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal) {
+            var query = {
+                'ID':recode.ID,
+                'projectID': recode.projectID
+            };
+            var doc ={
+                market_price:newVal,
+                code:recode.code,
+                name:recode.name,
+                project_id:recode.projectID
+            };
+         /*   code: '01010101',
+                market_price: '40',
+                name: '水泥',
+                project_id: projectId*/
+            var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
+            project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
+        };
 
         return new ration_glj(project);
     }

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


+ 36 - 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);
                     }
                 }
             }
@@ -158,6 +184,7 @@ $('#delete').click(function () {
         } else if (selected.sourceType === project.Ration.getSourceType()) {
             project.Ration.delete(selected.source);
             project.ration_glj.deleteByRation(selected.source);
+            project.ration_coe.deleteByRation(selected.source);
             controller.delete();
         };
     }
@@ -183,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 () {
@@ -207,4 +234,3 @@ $('#downMove').click(function () {
         }
     }
 });
-

+ 9 - 4
web/building_saas/main/js/views/sub_view.js

@@ -8,29 +8,34 @@ var subSpread = sheetCommonObj.createSpread($("#subSpread")[0], 7);
 
 // 工料机
 gljOprObj.initSheet(subSpread.getSheet(0));
-sheetCommonObj.shieldAllCells(subSpread.getSheet(0), gljOprObj.setting);
+//sheetCommonObj.shieldAllCells(subSpread.getSheet(0), gljOprObj.setting);
 
 // assistOprObj.initSheet(subSpread.getSheet(1));
 // sheetCommonObj.shieldAllCells(subSpread.getSheet(1), assistOprObj.setting);
+//附注条件
+gljOprObj.initCoeSheet(subSpread.getSheet(2));
 
+//辅助定额
 
+gljOprObj.initAssSheet(subSpread.getSheet(1));
 
 $("#linkGLJ").click(function(){
     subSpread.setActiveSheetIndex(0);
+
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "工料机");
+    //subSpread.getActiveSheet().setValue(0, 0, "工料机");
 });
 
 $("#linkFZDE").click(function(){
     subSpread.setActiveSheetIndex(1);
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "辅助定额");
+  //  subSpread.getActiveSheet().setValue(0, 0, "辅助定额");
 });
 
 $("#linkFZTJ").click(function(){
     subSpread.setActiveSheetIndex(2);
     // for test
-    subSpread.getActiveSheet().setValue(0, 0, "附注条件");
+    //subSpread.getActiveSheet().setValue(0, 0, "附注条件");
 });
 
 $("#linkGCLMX").click(function(){