zhongzewei %!s(int64=7) %!d(string=hai) anos
pai
achega
64d82c0dc5

+ 4 - 1
modules/complementary_glj_lib/routes/routes.js

@@ -3,10 +3,12 @@
  */
 
 import express from "express";
-import GljController from "../controllers/gljController"
+import GljController from "../controllers/gljController";
+import CompleRationController from '../../complementary_ration_lib/controllers/compleRationController';
 
 let router = express.Router();
 let gljController = new GljController();
+let compleRationController = new CompleRationController();
 
 module.exports = function (app) {
     app.get('/complementaryGlj', gljController.init, gljController.redirectGlj);
@@ -21,6 +23,7 @@ module.exports = function (app) {
     router.post("/getGljItems", gljController.init, gljController.getGljItems);
     router.post("/updateComponent", gljController.init, gljController.updateComponent);
     router.post("/mixUpdateGljItems", gljController.init, gljController.mixUpdateGljItems);
+    router.post("/updateRationBasePrc",compleRationController.init, compleRationController.updateRationBasePrc);//更新定额单价
     //router.post("/getGljItemsByIds", gljController.init, gljController.getGljItemsByIds);
     //router.post("/getGljItemsByCodes", gljController.init, gljController.getGljItemsByCodes);
 

+ 8 - 0
modules/complementary_ration_lib/controllers/compleRationController.js

@@ -26,6 +26,14 @@ class CompleRationController extends BaseController{
         });
     }
 
+    //更新补充定额价格
+    updateRationBasePrc(req, res){
+        let data = JSON.parse(req.body.data);
+        compleRationDao.updateRationBasePrc(req.session.sessionUser.ssoId, data.basePrcArr, function (err, data) {
+            callback(req, res, err, '', data);
+        });
+    }
+
     mixUpdateRationItems(req, res){
         let data = JSON.parse(req.body.data);
         compleRationDao.mixUpdateRationItems(req.session.sessionUser.ssoId, req.session.sessionCompilation._id,

+ 159 - 5
modules/complementary_ration_lib/models/compleRationModel.js

@@ -7,6 +7,7 @@ import {complementaryGljModel, stdGljModel} from '../../complementary_glj_lib/mo
 import async from 'async';
 let stdRationModel = require ('../../ration_repository/models/ration_item').Model;
 let counter = require('../../../public/counter/counter');
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
 
 class CompleRatoinDao {
     async updateRation(userID, compilationId, updateData, callback){
@@ -112,9 +113,6 @@ class CompleRatoinDao {
 
     async getGljItemsByCodes(userID, compilationId, rationRepId, codes, callback){
         try{
-            console.log(userID);
-            console.log(compilationId);
-            console.log(codes);
             let rst = [];
             for(let i = 0, len = codes.length; i < len; i++){
                 let stdGlj = await stdGljModel.find({repositoryId: rationRepId, code: codes[i]});
@@ -123,9 +121,7 @@ class CompleRatoinDao {
                     rst.push(stdGlj[0]);
                 }
                 else {
-                    console.log(codes[i]);
                     let compleGlj = await complementaryGljModel.find({userId: userID, compilationId: compilationId, code: codes[i]});
-                    console.log(compleGlj);
                     if(compleGlj.length > 0){
                         compleGlj[0]._doc.type = 'complementary';
                         rst.push(compleGlj[0]);
@@ -139,6 +135,164 @@ class CompleRatoinDao {
         }
     }
 
+    updateRationBasePrc(userID, basePrcArr, callback){
+        let me  = this;
+        async.each(basePrcArr, function (basePrcObj, finalCb) {
+            let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
+            async.waterfall([
+                function (cb) {
+                    if(typeof basePrcObj.delete !== 'undefined' && basePrcObj.delete === 1){
+                        //补充定额
+                        compleRationModel.find({'rationGljList.gljId': adjGljId},{ID: 1, rationGljList: 1}, function (err, compleRst) {
+                            if(err){
+                                cb(err);
+                            }
+                            else {
+                                compleRationModel.update({'rationGljList.gljId': adjGljId}, {$pull: {rationGljList: {gljId: adjGljId}}}, {multi: true}, function (err) {
+                                    if(err){
+                                        cb(err);
+                                    }
+                                    else {
+                                        cb(null, compleRst);
+                                    }
+                                });
+                            }
+                        });
+
+                    }
+                    else{
+                        compleRationModel.find({'rationGljList.gljId': adjGljId}, function (err, compleRst) {
+                            if(err){
+                                cb(err);
+                            }
+                            else {
+                                cb(null, compleRst);
+                            }
+                        });
+                    }
+                },
+                function (result, cb) {
+                    async.each(result, function (rationItem, ecb) {
+                        let rationGljList = rationItem.rationGljList,
+                            gljIds = [];
+                        rationGljList.forEach(function (rationGlj) {
+                            let idObj = Object.create(null);
+                            idObj.id = rationGlj.gljId;
+                            idObj.type = rationGlj.type;
+                            gljIds.push(idObj);
+                        });
+                        me.getGljItemsByIds(userID, gljIds, function(err, gljItems){
+                            if(err){
+                                ecb(err);
+                            }
+                            else{
+                                let gljArr = [];
+                                for(let i=0; i<gljItems.length; i++){
+                                    let gljParentType = -1;
+                                    if(gljItems[i].ID === adjGljId){
+                                        gljItems[i].gljType = adjGljType;
+                                    }
+                                    if(gljItems[i].gljType <= 3){
+                                        gljParentType = gljItems[i].gljType;
+                                    }
+                                    if(gljItems[i].gljType > 200 && gljItems[i].gljType < 300){
+                                        gljParentType = 2;
+                                    }
+                                    if(gljItems[i].gljType > 300 && gljItems[i].gljType < 400){
+                                        gljParentType = 3;
+                                    }
+                                    if(gljItems[i].ID === adjGljId){
+                                        gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
+                                    }
+                                    else {
+                                        gljArr.push({gljId: gljItems[i].ID, basePrice: parseFloat(gljItems[i].basePrice), gljParentType: gljParentType});
+                                    }
+                                }
+                                gljArr.forEach(function (gljItem) {
+                                    rationGljList.forEach(function (rationGlj) {
+                                        if(gljItem.gljId === rationGlj.gljId){
+                                            gljItem.consumeAmt = parseFloat(rationGlj.consumeAmt);
+                                        }
+                                    })
+                                });
+                                //recalculate the price of ration
+                                let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
+                                gljArr.forEach(function (gljItem) {
+                                    if(gljItem.gljParentType !== -1){
+                                        singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
+                                        if(gljItem.gljParentType === 1){
+                                            labourPrc.push(singlePrc);
+                                        }
+                                        else if(gljItem.gljParentType ===2){
+                                            materialPrc.push(singlePrc);
+                                        }
+                                        else{
+                                            machinePrc.push(singlePrc);
+                                        }
+                                    }
+                                });
+                                if(labourPrc.length > 0){
+                                    let sumLaP = 0;
+                                    for(let i=0; i<labourPrc.length; i++){
+                                        sumLaP += labourPrc[i];
+                                    }
+                                    updatePrc.labourPrice = scMathUtil.roundTo(sumLaP, -2);
+                                }
+                                if(materialPrc.length > 0){
+                                    let sumMtP = 0;
+                                    for(let i= 0; i<materialPrc.length; i++){
+                                        sumMtP += materialPrc[i];
+                                    }
+                                    updatePrc.materialPrice = scMathUtil.roundTo(sumMtP, -2);
+                                }
+                                if(machinePrc.length > 0){
+                                    let sumMaP = 0;
+                                    for(let i =0; i< machinePrc.length; i++){
+                                        sumMaP += machinePrc[i];
+                                    }
+                                    updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
+                                }
+                                updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
+                                //updateDataBase
+                                compleRationModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice.toString(), materialPrice: updatePrc.materialPrice.toString(),
+                                        machinePrice: updatePrc.machinePrice.toString(), basePrice: updatePrc.basePrice.toString()}},
+                                    function (err, result) {
+                                        if(err){
+                                            ecb(err);
+                                        }
+                                        else {
+                                            ecb(null);
+                                        }
+                                    });
+                            }
+                        });
+                    }, function(err){
+                        if(err){
+                            cb(err);
+                        }
+                        else {
+                            cb(null);
+                        }
+                    });
+                },
+            ], function (err) {
+                if(err){
+                    finalCb(err);
+                }
+                else{
+                    finalCb(null);
+                }
+            });
+        }, function (err) {
+            if(err){
+                callback(err, 'Error');
+            }
+            else{
+                callback(0, '');
+            }
+        });
+    }
+
     mixUpdateRationItems (userID, compilationId, rationLibId, sectionId, updateItems, addItems, rIds, callback){
         let me = this;
         if (updateItems.length == 0 && rIds.length == 0) {

+ 24 - 35
web/building_saas/complementary_glj_lib/js/glj.js

@@ -447,7 +447,7 @@ let repositoryGljObj = {
             //--------------------------------------
             if(me.currentEditingGlj.basePrice !== rObj.basePrice){
                 //update basePrice of ration when editting basePrice of glj
-               /* let gljType = -1;
+                let gljType = -1;
                 let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
                 if(gljTypeParent && gljTypeParent.data.ID <=3){
                     gljType = gljTypeParent.data.ID;
@@ -458,18 +458,14 @@ let repositoryGljObj = {
                 let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
                 if(gljBasePrcObj.gljType !== -1){
                     updateBasePrcArr.push(gljBasePrcObj);
-                    if(me.rationLibs.length > 0){//重算定额单价
-                        me.updateRationBasePrcRq(updateBasePrcArr);
-                    }
-                }*/
+                    me.updateRationBasePrcRq(updateBasePrcArr);
+                }
             }
             //update basePrice of ration when editting gljType of glj
             if(me.currentEditingGlj.gljType !== rObj.gljType){
-                /*let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
+                let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
                 updateBasePrcArr.push(gljTypeObj);
-                if(me.rationLibs.length > 0){
-                    me.updateRationBasePrcRq(updateBasePrcArr);
-                }*/
+                me.updateRationBasePrcRq(updateBasePrcArr);
             }
             //-----------------------------------------------------------
         }
@@ -783,7 +779,7 @@ let repositoryGljObj = {
         }
     },
     onClipboardPasted: function(e, info) {
-        if(info.pasteData.text.trim().length > 0){
+      //  if(info.pasteData.text.trim().length > 0){
             let me = repositoryGljObj;
             let updateArr = [], addArr = [];
             let items = sheetOpr.analyzePasteData(me.setting, info);
@@ -795,11 +791,12 @@ let repositoryGljObj = {
                 //updateItems = items;
                 for(let i = 0; i < items.length; i++){
                     let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
-                    if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
-                        updateArr = updateObj.updateGlj;
-                        /*if(typeof updateObj.updateBasePrcArr !== 'undefined'){
-                         updateBasePrcArr = updateObj.updateBasePrcArr;
-                         }*/
+                    if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
+                        //updateArr = updateObj.updateGlj;
+                        updateArr = updateArr.concat(updateObj.updateGlj);
+                        if(typeof updateObj.updateBasePrcArr !== 'undefined'){
+                            updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
+                         }
                     }
                     else{
                         resumeArr.push(info.cellRange.row + i);
@@ -811,10 +808,11 @@ let repositoryGljObj = {
                 for(let i = 0; i < updateCount; i++){
                     let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
                     if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
-                        updateArr = updateObj.updateGlj;
-                        /* if(typeof updateObj.updateBasePrcArr !== 'undefined'){
-                         updateBasePrcArr = updateObj.updateBasePrcArr;
-                         }*/
+                        //updateArr = updateObj.updateGlj;
+                        updateArr = updateArr.concat(updateObj.updateGlj);
+                        if(typeof updateObj.updateBasePrcArr !== 'undefined'){
+                            updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
+                        }
                     }
                     else{
                         resumeArr.push(info.cellRange.row + i);
@@ -889,29 +887,20 @@ let repositoryGljObj = {
             if (updateArr.length > 0 || addArr.length > 0) {
                 me.mixUpdateRequest(updateArr, addArr, []);
             }
-            /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
-             me.updateRationBasePrcRq(updateBasePrcArr);
-             }*/
-        }
-        else{//解决bug: 从原本的sheet复制一行数据,会两次调用粘贴事件函数..,todo:找出原因
+            if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
+                me.updateRationBasePrcRq(updateBasePrcArr);
+            }
+       // }
+      /*  else{//解决bug: 从原本的sheet复制一行数据,会两次调用粘贴事件函数..,todo:找出原因
             for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
                 for(let col = 0; col < 6; col++){
                     info.sheet.setValue(info.cellRange.row + i, col, '');
                 }
             }
-        }
+        }*/
     },
     updateRationBasePrcRq: function (basePrcArr) {
-        $.ajax({
-            type: 'post',
-            url: 'complementartGlj/api/updateRationBasePrc',
-            data:{basePrcArr: JSON.stringify(basePrcArr)},
-            dataType: 'json',
-            success: function (result) {
-                if(result.error){
-                    alert("计算定额基价失败");
-                }
-            }
+        CommonAjax.post('complementartGlj/api/updateRationBasePrc', {basePrcArr: basePrcArr}, function (rstData) {
         });
     },
   /*  getRationGljIds: function (repId) {

+ 1 - 0
web/building_saas/complementary_glj_lib/js/sheetOpr.js

@@ -49,6 +49,7 @@ let sheetOpr = {
         //Set rowHeader count and columnHeader count.
         sheet.setRowCount(1, spreadNS.SheetArea.colHeader);
         sheet.setColumnCount(setting.header.length, spreadNS.SheetArea.viewport);
+        sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
         sheet.options.colHeaderAutoTextIndex = 1;
         sheet.options.colHeaderAutoText = spreadNS.HeaderAutoText.numbers;
         sheet.options.protectionOptions = {

+ 6 - 2
web/building_saas/main/js/models/calc_base.js

@@ -573,7 +573,7 @@ let calcBase = {
     getBaseBill: function (node) {
         return cbTools.getBaseBill(node);
     },
-    calculate: function (node) {
+    calculate: function (node, reCalc) {
         let me = calcBase,
             $CBA = cbAnalyzer,
             $CBP = cbParser,
@@ -582,7 +582,11 @@ let calcBase = {
             me.success = false;
             me.errMsg = '表达式不正确';
             //分析输入式合法性
-            let exp = $CBA.legalExp(node);
+            let exp = reCalc
+                ? cbTools.isDef(node.data.calcBase)
+                    ? node.data.calcBase
+                    : ''
+                : $CBA.legalExp(node);
             if(!cbTools.isDef(exp)){
                 throw '表达式不正确';
             }