2016-10-03 2 views
0

Я использую стек MEAN в своем приложении с AngularJS как мой интерфейс. Как суммировать сумму двух значений в angularjs, на самом деле у нас есть две таблицы, первая таблица фильтруется с помощью filter:{raised: 'false'}, а вторая таблица фильтруется с filter:{raised: 'true'}, и мы получили общие значения сумм для обеих таблиц в commision, тогда я ожидаю рассчитать commision итоговые значения как A + B как 45 + 19 answer = 64 ... My Plunker.Как вычислить две таблицы Totalsum Value в Angularjs?

  • У нас есть две таблицы, поэтому я хочу, чтобы вычислить первую таблицу commision общее значение суммы и второй таблице commision значение totalsum.

  • обе таблицы фильтруются со значением нг-модуля , например: - первая таблица фильтруется с filter:{raised: 'false'} и вторая таблица фильтруется с filter:{raised: 'true'}

  • Ожидание exmaple: - Fisrt таблица комиссионной является 45, и вторая таблица составляет 19, нам нужно рассчитать их значение в третьей таблице, как A + B Ответ должен быть 64.

  • Я дал плункер в качестве ссылки plunker, пожалуйста, любой знает, что решение поможет нам.

Мой контроллер: - Commision totalsum фильтр -

.filter('totalSumCV', function() { 
    return function (data, key1, key2) {   
     if (angular.isUndefined(data) && angular.isUndefined(key1) && angular.isUndefined(key2)) 
      return 0; 

     var sum = 0; 
     angular.forEach(data,function(v,k){ 
      sum = sum + (parseFloat(v[key1]) * parseFloat(v[key2])/100); 
     }); 
     return sum.toFixed(2); 
    } 
}) 

Мой Html: -

<tr ng-repeat="mani in resultValue=(sryarndebitnote | filter:{raised: 'false'})"> 

    <td>A = {{resultValue | totalSumCV:'invoice_value_fob':'percentage_commission'}}</td> 

</tr> 


    <tr ng-repeat="mani in resultValue=(sryarndebitnote | filter:{raised: 'true'})"> 

    <td>B = {{resultValue | totalSumCV:'invoice_value_fob':'percentage_commission'}}</td> 

</tr> 

Я попытался вычислить как таблицу комиссионной totalsum значение как: -

<td >C = {{((resultValue | totalSumCV:'invoice_value_fob':'percentage_commission') * 1) + ((resultValue | totalSumCV:'invoice_value_fob':'percentage_commission')*1)}}</td> 

ответ

0

Вы должны принять различные переменные для результирующего набора для достижения этой цели,

Вот вам требуется ответ,

var app = angular.module('plunker', []); 
 

 

 
app.filter('sumOfValue', function() { 
 
    return function (data, key) { 
 
     debugger; 
 
     if (angular.isUndefined(data) && angular.isUndefined(key)) 
 
      return 0;   
 
     var sum = 0; 
 
     
 
     angular.forEach(data,function(v,k){ 
 
      sum = sum + parseFloat(v[key]); 
 
     });   
 
     return sum.toFixed(2); 
 
    } 
 
}).filter('totalSumCV', function() { 
 
    return function (data, key1, key2) {   
 
     if (angular.isUndefined(data) && angular.isUndefined(key1) && angular.isUndefined(key2)) 
 
      return 0; 
 
     
 
     var sum = 0; 
 
     angular.forEach(data,function(v,k){ 
 
      sum = sum + (parseFloat(v[key1]) * parseFloat(v[key2])/100); 
 
     }); 
 
     return sum.toFixed(2); 
 
    } 
 
}).controller('MainCtrl', function($scope) { 
 
    $scope.sryarndebitnote = [ 
 
{ 
 
"_id": "57ecb2861365a8150a34c660", 
 
"user": { 
 
"_id": "57400c32bd07906c1308e2cf", 
 
"displayName": "mani selvam" 
 
}, 
 
"__v": 0, 
 
"created": "2016-09-29T06:19:50.046Z", 
 
"shipment_id": "57dc0ad6a752016f1638c6bc", 
 
"raised": false, 
 
"conversion_rate": "62", 
 
"percentage_tds": "10", 
 
"percentage_servicetax": "15", 
 
"percentage_commission": "3", 
 
"invoice_value_fob": "300", 
 
"invoice_value_cif": "50", 
 
"invoice_quantity": "40", 
 
"supplier_name": "asd", 
 
"buyer_name": "Rohit" 
 
}, 
 

 

 
{ 
 
"_id": "57ecb2861365a8150a34c660", 
 
"user": { 
 
"_id": "57400c32bd07906c1308e2cf", 
 
"displayName": "mani selvam" 
 
}, 
 
"__v": 0, 
 
"created": "2016-09-29T06:19:50.046Z", 
 
"shipment_id": "57dc0ad6a752016f1638c6bc", 
 
"raised": false, 
 
"conversion_rate": "62", 
 
"percentage_tds": "10", 
 
"percentage_servicetax": "15", 
 
"percentage_commission": "6", 
 
"invoice_value_fob": "600", 
 
"invoice_value_cif": "50", 
 
"invoice_quantity": "40", 
 
"supplier_name": "asd", 
 
"buyer_name": "Rohit" 
 
}, 
 

 
{ 
 
"_id": "57ecb2861365a8150a34c660", 
 
"user": { 
 
"_id": "57400c32bd07906c1308e2cf", 
 
"displayName": "mani selvam" 
 
}, 
 
"__v": 0, 
 
"created": "2016-09-29T06:19:50.046Z", 
 
"shipment_id": "57dc0ad6a752016f1638c6bc", 
 
"raised": true, 
 
"conversion_rate": "62", 
 
"percentage_tds": "10", 
 
"percentage_servicetax": "15", 
 
"percentage_commission": "4", 
 
"invoice_value_fob": "400", 
 
"invoice_value_cif": "50", 
 
"invoice_quantity": "40", 
 
"supplier_name": "asd", 
 
"buyer_name": "Rohit" 
 
}, 
 

 
{ 
 
"_id": "57ecb2861365a8150a34c660", 
 
"user": { 
 
"_id": "57400c32bd07906c1308e2cf", 
 
"displayName": "mani selvam" 
 
}, 
 
"__v": 0, 
 
"created": "2016-09-29T06:19:50.046Z", 
 
"shipment_id": "57dc0ad6a752016f1638c6bc", 
 
"raised": true, 
 
"conversion_rate": "62", 
 
"percentage_tds": "10", 
 
"percentage_servicetax": "15", 
 
"percentage_commission": "3", 
 
"invoice_value_fob": "100", 
 
"invoice_value_cif": "50", 
 
"invoice_quantity": "40", 
 
"supplier_name": "asd", 
 
"buyer_name": "Rohit" 
 
},] 
 

 
});
/* Put your css in here */ 
 

 
body { 
 
    font-size: 14px; 
 
} 
 

 
table 
 
{ 
 
    border-collapse:collapse; 
 
} 
 
table, td, th 
 
{ 
 
    border:1px solid black; 
 
} 
 
td{ 
 
    padding: 2px; 
 
} 
 
.servicetaxinclusivetrue:before{ 
 
    color: green!important; 
 
    content: "\f00c"; 
 
} 
 
.servicetaxinclusivefalse:before{ 
 
    color: red!important; 
 
    content: "\f00d"; 
 
} 
 
.servicetaxexclusivetrue:before{ 
 
    color: green!important; 
 
    content: "\f00c"; 
 
} 
 
.servicetaxexclusivefalse:before{ 
 
    color: red!important; 
 
    content: "\f00d"; 
 
} 
 
.margin{ 
 
     margin-top: 20px; 
 
}
<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    
 
    
 
    <table ng-table="tableParams" class="table table-bordered "> 
 
     <thead> 
 
     <tr> 
 
      
 
      <th rowspan="2"> S.No </th> 
 
      <th rowspan="2"> fob </th> 
 
      <th rowspan="2"> Commision </th> 
 
      <th rowspan="2">Quantity</th> 
 
      </tr> 
 
    </thead> 
 
     <tr ng-repeat="mani in resultValue=(sryarndebitnote | filter:{raised: 'false'})"> 
 
      <td >{{$index + 1}}</td> 
 
      <td >{{mani.invoice_value_fob}}</td> 
 
       <td >{{(mani.invoice_value_fob * (mani.percentage_commission/100)) | number:2}}</td> 
 
       <td >{{mani.invoice_quantity}}</td> 
 
      </tr> 
 
       <tr> 
 
       <td>sum</td> 
 
       <td>{{resultValue | sumOfValue:'invoice_value_fob'}}</td> 
 
       <td>A = {{resultValue | totalSumCV:'invoice_value_fob':'percentage_commission'}}</td> 
 
       <td></td> 
 
       </tr> 
 
     </table> 
 
       
 
    <table ng-table="tableParams" class="margin table table-bordered "> 
 
     <thead> 
 
     <tr> 
 
      
 
      <th rowspan="2"> S.No </th> 
 
      <th rowspan="2"> fob </th> 
 
      <th rowspan="2"> Commision </th> 
 
      <th rowspan="2">Quantity</th> 
 
      </tr> 
 
    </thead> 
 
     <tr ng-repeat="mani in resultValue2=(sryarndebitnote | filter:{raised: 'true'})"> 
 
     <td >{{$index + 1}}</td> 
 
      <td >{{mani.invoice_value_fob}}</td> 
 
      <td >{{(mani.invoice_value_fob * (mani.percentage_commission/100)) | number:2}}</td> 
 
       <td >{{mani.invoice_quantity}}</td> 
 
       
 
      </tr> 
 
       <tr> 
 
       <td>sum</td> 
 
       <td>{{resultValue2 | sumOfValue:'invoice_value_fob'}}</td> 
 
       <td>B = {{resultValue2 | totalSumCV:'invoice_value_fob':'percentage_commission'}}</td> 
 
       <td></td> 
 
       </tr> 
 
     </table> 
 
       
 
    <table ng-table="tableParams" class="margin table table-bordered "> 
 
     <thead> 
 
     <tr> 
 
      
 
      <th rowspan="2"> S.No </th> 
 
      <th rowspan="2"> A + B </th> 
 
      </tr> 
 
    </thead> 
 
       
 
      <td >{{resultValue2 | totalSumCV:'invoice_value_fob':'percentage_commission'}}</td> 
 
       <td >C = {{((resultValue | totalSumCV:'invoice_value_fob':'percentage_commission') * 1) + ((resultValue2 | totalSumCV:'invoice_value_fob':'percentage_commission')*1)}}</td> 
 
       
 
      </table> 
 
    </body> 
 

 
</html>

Pls запустить код.

Here is the plunker

+0

Здравствуйте @mani, вы пробовали это? – Sravan