zhongzewei 6 years ago
parent
commit
a125219b2f

+ 43 - 1
modules/ration_repository/controllers/ration_repository_controller.js

@@ -16,6 +16,9 @@ const fs = require("fs");
 // excel解析
 const excel = require("node-xlsx");
 const rationItem = require("../models/ration_item");
+const rationLibModel = mongoose.model('std_ration_lib_map');
+const rationItemModel = mongoose.model('std_ration_lib_ration_items');
+import STDGLJListModel from '../../std_glj_lib/models/gljModel';
 
 class RationRepositoryController extends baseController {
     async getRationLibsByCompilation(req, res){
@@ -243,7 +246,46 @@ class RationRepositoryController extends baseController {
         } catch (error) {
             response.end(error);
         }
-
+    }
+    //一键重新计算所有定额数据
+    async reCalcAll(req, res){
+        try{
+            let data = JSON.parse(req.body.data);
+            let rationRepId = data.rationRepId;
+            let rationLib = await rationLibModel.findOne({ID: rationRepId, $or: [{deleted: null},{deleted: false}]});
+            if(!rationLib){
+                throw '不存在此定额库';
+            }
+            let task = [];
+            // 获取标准工料机库数据
+            const stdBillsLibListsModel = new STDGLJListModel();
+            const stdGLJData = await stdBillsLibListsModel.getGljItemsByRepId(rationLib.gljLib);
+            // 整理标准工料机库数据
+            let stdGLJList = {};
+            let stdGLJListByID = {};
+            for (const tmp of stdGLJData) {
+                stdGLJList[tmp.code.toString()] = tmp.ID;
+                stdGLJListByID[tmp.ID] = tmp;
+            }
+            //获取所有的定额
+            let allRations = await rationItemModel.find({rationRepId: rationRepId, $or: [{isDeleted: false}, {isDeleted: null}]});
+            for(let ration of allRations){
+                rationItem.calcForRation(stdGLJListByID, ration);
+                task.push({
+                    updateOne: {
+                        filter: {ID: ration.ID},
+                        update: {$set: {labourPrice: ration.labourPrice, materialPrice: ration.materialPrice, machinePrice: ration.machinePrice, basePrice: ration.basePrice}}
+                    }
+                });
+            }
+            if(task.length > 0){
+                await rationItemModel.bulkWrite(task);
+            }
+            res.json({error: 0, message: 'success', data: null});
+        }
+        catch (err){
+            res.json({error: 1, message: err, data: null});
+        }
     }
 
 }

+ 109 - 9
modules/ration_repository/models/ration_item.js

@@ -320,6 +320,19 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     if(theGlj.gljType > 300 && theGlj.gljType < 400){
                                         gljParentType = 3;
                                     }
+                                    //管理费
+                                    if(theGlj.gljType === 6){
+                                        gljParentType = 6;
+                                    }
+                                    //利润
+                                    if(theGlj.gljType === 7){
+                                        gljParentType = 7;
+                                    }
+                                    //风险费
+                                    if(theGlj.gljType === 8){
+                                        gljParentType = 8;
+                                    }
+                                    if(theGlj)
                                     if(theGlj.ID === adjGljId){
                                         gljArr.push({gljId: theGlj.ID, basePrice: adjBasePrice, gljParentType: gljParentType});
                                     }
@@ -336,7 +349,14 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                 })
                             });
                             //recalculate the price of ration
-                            let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
+                            let labourPrc = [],
+                                materialPrc = [],
+                                machinePrc = [],
+                                managePrc = [],
+                                profitPrc = [],
+                                riskPrc = [],
+                                singlePrc,
+                                updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0, basePrice: 0};
                             gljArr.forEach(function (gljItem) {
                                 if(gljItem.gljParentType !== -1){
                                     singlePrc = scMathUtil.roundTo(gljItem.basePrice * gljItem.consumeAmt, -3);
@@ -346,9 +366,18 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                     else if(gljItem.gljParentType ===2){
                                         materialPrc.push(singlePrc);
                                     }
-                                    else{
+                                    else if(gljItem.gljParentType === 3){
                                         machinePrc.push(singlePrc);
                                     }
+                                    else if(gljItem.gljParentType === 6){
+                                        managePrc.push(singlePrc);
+                                    }
+                                    else if(gljItem.gljParentType === 7){
+                                        profitPrc.push(singlePrc);
+                                    }
+                                    else if(gljItem.gljParentType === 8){
+                                        riskPrc.push(singlePrc);
+                                    }
                                 }
                             });
                             if(labourPrc.length > 0){
@@ -372,7 +401,29 @@ rationItemDAO.prototype.updateRationBasePrc = function (basePrcArr, callback) {
                                 }
                                 updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
                             }
-                            updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
+                            if(managePrc.length > 0){
+                                let sumMgP = 0;
+                                for(let i =0; i< managePrc.length; i++){
+                                    sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
+                                }
+                                updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
+                            }
+                            if(profitPrc.length > 0){
+                                let sumPfP = 0;
+                                for(let i =0; i< profitPrc.length; i++){
+                                    sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
+                                }
+                                updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
+                            }
+                            if(riskPrc.length > 0){
+                                let sumRkP = 0;
+                                for(let i =0; i< riskPrc.length; i++){
+                                    sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
+                                }
+                                updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
+                            }
+                            updatePrc.basePrice = scMathUtil.roundTo(
+                                updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
                             let task = {
                                 updateOne: {
                                     filter: {
@@ -525,8 +576,14 @@ rationItemDAO.prototype.updateAnnotation = function (lastOpr, repId, updateArr,
 rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
     const processDecimal = -6;
     //根据工料机类型划分价格
-    const labour = [1],  material = [201, 202, 203, 204, 205, 206], machine = [301, 302, 303];
-    let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
+    const labour = [1],
+        material = [201, 202, 203, 204, 205, 206],
+        machine = [301, 302, 303],
+        manage = [6],
+        profit = [7],
+        risk = [8];
+    let labourPrc = [], materialPrc = [], machinePrc = [], managePrc = [], profitPrc = [], riskPrc = [],
+        singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0};
     let rationGljList = ration.rationGljList;
     for(let rationGlj of rationGljList){
         let glj = stdGljList[rationGlj.gljId];
@@ -542,6 +599,15 @@ rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
             else if(prcType === 'machine'){
                 machinePrc.push(singlePrc);
             }
+            else if(prcType === 'manage'){
+                managePrc.push(singlePrc);
+            }
+            else if(prcType === 'profit'){
+                profitPrc.push(singlePrc);
+            }
+            else if(prcType === 'risk'){
+                riskPrc.push(singlePrc);
+            }
         }
     }
     //计算人工费
@@ -568,8 +634,33 @@ rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
         }
         updatePrc.machinePrice = scMathUtil.roundTo(sumMaP, -2);
     }
+    //管理费
+    if(managePrc.length > 0){
+        let sumMgP = 0;
+        for(let i = 0, len  = managePrc.length; i < len; i++){
+            sumMgP = scMathUtil.roundTo(sumMgP + managePrc[i], processDecimal);
+        }
+        updatePrc.managePrice = scMathUtil.roundTo(sumMgP, -2);
+    }
+    //利润
+    if(profitPrc.length > 0){
+        let sumPfP = 0;
+        for(let i = 0, len  = profitPrc.length; i < len; i++){
+            sumPfP = scMathUtil.roundTo(sumPfP + profitPrc[i], processDecimal);
+        }
+        updatePrc.profitPrice = scMathUtil.roundTo(sumPfP, -2);
+    }
+    //风险费
+    if(riskPrc.length > 0){
+        let sumRkP = 0;
+        for(let i = 0, len  = riskPrc.length; i < len; i++){
+            sumRkP = scMathUtil.roundTo(sumRkP + riskPrc[i], processDecimal);
+        }
+        updatePrc.riskPrice = scMathUtil.roundTo(sumRkP, -2);
+    }
     //基价
-    updatePrc.basePrice = scMathUtil.roundTo(updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice, -2);
+    updatePrc.basePrice = scMathUtil.roundTo(
+        updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice + updatePrc.managePrice + updatePrc.profitPrice + updatePrc.riskPrice, -2);
     //更新定额数据
     ration.labourPrice = updatePrc.labourPrice.toString();
     ration.materialPrice = updatePrc.materialPrice.toString();
@@ -581,15 +672,24 @@ rationItemDAO.prototype.calcForRation = function (stdGljList, ration) {
     }
     //是否属于人工、材料、机械类型
     function getParentType(type){
-        if(labour.indexOf(type) !== -1){
+        if(labour.includes(type)){
             return 'labour';
         }
-        if(material.indexOf(type) !== -1){
+        if(material.includes(type)){
             return 'material';
         }
-        if(machine.indexOf(type) !== -1){
+        if(machine.includes(type)){
             return 'machine';
         }
+        if(manage.includes(type)){
+            return 'manage';
+        }
+        if(profit.includes(type)){
+            return 'profit';
+        }
+        if(risk.includes(type)){
+            return 'risk'
+        }
         return null;
     }
 

+ 1 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -84,6 +84,7 @@ module.exports =  function (app) {
     apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
     apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);
 
+    apiRouter.post('/reCalcAll', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.reCalcAll);
     // 导入导出定额库相关
     apiRouter.post('/upload', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.uploadSourceData);
     apiRouter.get('/export', rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.exportRationData);

+ 21 - 2
web/maintain/ration_repository/js/main.js

@@ -101,7 +101,25 @@ $(function () {
                 $('#del').modal('hide');
             }
         });
-
+        //全部计算
+        $("#showArea").on("click", "[data-target = '#reCalcAll']", function(){
+            let recalcId = $(this).parent().parent().attr("id");
+            $("#reCalcConfirm").attr("recalcId", recalcId);
+        });
+        $("#reCalcConfirm").click(function(){
+            $('#reCalcConfirm').addClass('disabled');
+            $.bootstrapLoading.start();
+            let recalcId = $(this).attr("recalcId");
+            CommonAjax.post('/rationRepository/api/reCalcAll', {rationRepId: recalcId}, function (rstData) {
+                $.bootstrapLoading.end();
+                $('#reCalcAll').modal('hide');
+                $('#reCalcConfirm').removeClass('disabled');
+            }, function () {
+                $.bootstrapLoading.end();
+                $('#reCalcAll').modal('hide');
+                $('#reCalcConfirm').removeClass('disabled')
+            });
+        });
 
     });
     getCompilationList();
@@ -223,7 +241,8 @@ function getAllRationLib(callback){
                         "<td>"+createDate+" </td>" +
                         "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
                         "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
-                        "<i class='fa fa-remove'></i></a></td>" +
+                        "<i class='fa fa-remove'></i></a>" +
+                        " <a href='javascript:void(0);' data-toggle='modal' data-target='#reCalcAll' title='全部计算'><i class='fa fa-calculator'></i></a></td>"+
                         "<td><a class='btn btn-secondary btn-sm import-source' href='javacript:void(0);' data-id='"+ id +"' title='导入原始数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +
                         "<td><a class='btn btn-success btn-sm export' href='javacript:void(0);' data-toggle='modal' data-id='"+ id +"' data-target='#emport' title='导出内部数据'><i class='fa fa-sign-out fa-rotate-270'></i>导出</a> " +
                         "<a class='btn btn-secondary btn-sm import-data' href='javacript:void(0);' data-id='"+ id +"' title='导入内部数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +

+ 33 - 1
web/maintain/ration_repository/js/ration_glj.js

@@ -514,7 +514,9 @@ var rationGLJOprObj = {
     },
     rationCal: function () {
         let me = rationGLJOprObj;
-        let price = {gljType1: [], gljType2: [], gljType3: []}, rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0}, rationBasePrc = 0;
+        let price = {gljType1: [], gljType2: [], gljType3: [], gljType6: [], gljType7: [], gljType8: []},
+            rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0, managePrice: 0, profitPrice: 0, riskPrice: 0},
+            rationBasePrc = 0;
         if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
             let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
             cacheArr.forEach(function (gljData) {
@@ -526,6 +528,9 @@ var rationGLJOprObj = {
                     if(!parent && gljData.gljType <= 3){
                         price['gljType' + gljData.gljType].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
                     }
+                    if([6, 7, 8].includes(gljData.gljType)){
+                        price['gljType' + gljData.gljType].push(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
+                    }
                 }
             });
             if(price.gljType1.length > 0){
@@ -555,6 +560,33 @@ var rationGLJOprObj = {
                 rst.machinePrice = roundPrice;
                 rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
             }
+            if(price.gljType6.length > 0){
+                let managePrice = 0;
+                price.gljType6.forEach(function (singlePrc) {
+                    managePrice = scMathUtil.roundTo(managePrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(managePrice, -2);
+                rst.managePrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+            }
+            if(price.gljType7.length > 0){
+                let profitPrice = 0;
+                price.gljType7.forEach(function (singlePrc) {
+                    profitPrice = scMathUtil.roundTo(profitPrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(profitPrice, -2);
+                rst.profitPrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+            }
+            if(price.gljType8.length > 0){
+                let riskPrice = 0;
+                price.gljType8.forEach(function (singlePrc) {
+                    riskPrice = scMathUtil.roundTo(riskPrice + singlePrc, me.processDecimal);
+                });
+                let roundPrice = scMathUtil.roundTo(riskPrice, -2);
+                rst.riskPrice = roundPrice;
+                rationBasePrc = scMathUtil.roundTo(rationBasePrc + roundPrice, -2);
+            }
             rst.rationBasePrc = rationBasePrc;
         }
         return rst;

+ 21 - 0
web/maintain/ration_repository/main.html

@@ -151,6 +151,27 @@
             </div>
         </div>
     </div>
+    <!--全部计算-->
+    <div class="modal fade" id="reCalcAll" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <!--<input type="hidden" id="did" value="123">-->
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">全部计算</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">×</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <h5>确认重算所有定额数据?</h5>
+                </div>
+                <div class="modal-footer">
+                    <a id="reCalcConfirm" href="javascript: void(0);" class="btn btn-primary">确认</a>
+                    <button id="reCalcCancel" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                </div>
+            </div>
+        </div>
+    </div>
     <!--弹出导入原始数据-->
     <div class="modal fade" id="import" data-backdrop="static" style="display: none;" aria-hidden="true">
         <div class="modal-dialog" role="document">