last day (19 days later) » 

5:32 PM
0
A: how to reset variable after selecting?

Syam PillaiSeems like you want the sum of all the quantity of the table entry. Then you need to change the HTML code also HTML: <tbody> <tr ng-repeat="item in stockReport" ng-if = "item.category_name == stockReport.selectedOption.category_name" ng-init="setTotals(stockReport)">...

 
than it calculates only one row(the last one) each time i pick a category. but yes it resets to -0
 
So for each time you need to call the function twice?? ie., the final total will get after two iteration of the function?? Am I correct?
 
when I enter the page - total = 0:, I pick a category for example ("football") and I get 4 rows with team names and quantity of money each team has. then the total function will calculate how much money they all have. and when I choose another category "basketball", it will count the their money plus the total in the "football" category
 
So you don't want to add money of football with money of basketball. if i'm selecting football, it should show money of football only. like that for basketball also
 
yes exactly!!!! :)
 
5:32 PM
Actually I've already edited my answer before only.
But for (var in ...) should perfectly work. I'm sure
 
ok I will try now
 
@JBNizet Thank you man :) A new information
 
it doesn't work:( no errors
 
@tanyaa Can you please provide your code in a jsFiddle??
 
how ?I don't use jsFiddle
can we use the chat here?
 
5:32 PM
Give more code of your javascript atleast. Basically the $scope.stockReport
 
when I'm trying to debug It it looks like in the controller row "if(item){" it doesn't recognize the item
"use strict";
angular.module('dataSystem').controller('reportsCtrl', function ($scope, $route, $location, $http) {
$http({method:'GET', url:'api/reports-tab/stock-report.php/'})
.then(function(response) {
var arr = JSON.parse(JSON.parse(response.data));
$scope.stockReport = arr;


})

// This will log you the error code and trace, if there is an error.

.catch(function(err) {
console.log('err', err)
})


$scope.setTotals = function(item){
$scope.total = 0;


if (item){
for(var item in totalitem){
"use strict";
angular.module('dataSystem').controller('reportsCtrl', function ($scope, $route, $location, $http) {
$http({method:'GET', url:'api/reports-tab/stock-report.php/'})
.then(function(response) {
var arr = JSON.parse(JSON.parse(response.data));
$scope.stockReport = arr;


})

// This will log you the error code and trace, if there is an error.

.catch(function(err) {
console.log('err', err)
})

// $scope.selectedcategory = null;
// console.log($scope.selectedcategory);
//works!!
// $scope.total = 0;
this is the total code
of my controller
 
Please change `$scope.setTotals = function(item){ ` into `$scope.setTotals = function(TotalItem){ `
Copy my answer correctly both css and javascript
sorry both html and JS
Ohh sorry
1 sec
found error
 
<fieldset>
<legend class ="text-right ">דוח מלאים על פי סוגים</legend>
</fieldset>

<select ng-model="stockReport.selectedOption" ng-change="setTotals(stockReport)" ng-options = "item.category_name for item in stockReport |
unique:'category_name'">

<option value="">בחר קטגוריה</option>
</select>



<div class="table-responsive">
<table class="customer-list table table-striped" >
<thead>
<tr >
<th class="Column-Header">קטגוריה</th>
<th class="Column-Header">קוד מוצר</th>
<th class="Column-Header">שם מוצר</th>
 
change this section
if (item){
for(var item in totalitem){
$scope.total += parseInt(totalitem[item].quantity);
return $scope.total;
}
}

to


for(var item in totalitem){
if (item){
$scope.total += parseInt(totalitem[item].quantity);
return $scope.total;
}
}
 
error?
 
5:39 PM
I will update in answer also. Yes error, but item is undefined outside the for loop
 
everything else is ok?
 
Edited my answer check now
 
thanks!
Ill check now
 
Okay. and lemme know it's working or not
 
now it only counts the first row in the first category I choose
and stays the same every other category
for example: I choose "football" it counts the first row that says 8. I choose then "basketball" it remains 8
 
5:53 PM
$scope.setTotals = function(totalItem){
$scope.total = 0;
for(var item in totalItem){
if (totalItem[item] && (item.category_name == stockReport.selectedOption.category_name)){
$scope.total += parseInt(totalItem[item].quantity);
console.log($scope.total);
return $scope.total;
}
}

}
Try this. hope this should work
 
i have an error saying: stockReport is not defined
 
$scope.stockReport
Working now?
 
no , i think the problem is with item.category_name when i debug it shows on "item"=some number and .category_name - undefined
it doesn't enter $scope.total += parseInt(totalItem[item].quantity);
 
off shit again my mistake, 1 sec
 
lol :)
 
5:58 PM
$scope.setTotals = function(totalItem){
$scope.total = 0;
for(var item in totalItem){
if (totalItem[item] && (totalItem[item].category_name == stockReport.selectedOption.category_name)){
$scope.total += parseInt(totalItem[item].quantity);
console.log($scope.total);
return $scope.total;
}
}

}
try this
 
stockReport is not defined
error
 
$scope.stockReport
lol :)
 
i will add $scope
:)
 
$scope.setTotals = function(totalItem){
$scope.total = 0;
for(var item in totalItem){
if (totalItem[item] && (totalItem[item].category_name == $scope.stockReport.selectedOption.category_name)){
$scope.total += parseInt(totalItem[item].quantity);
console.log($scope.total);
return $scope.total;
}
}

}
 
just calculate for each category just the first row like before :(
 
6:02 PM
Working?
 
no its just each category i choose it calculates his first row only
$scope.setTotals = function(totalItem){
$scope.total = 0;
for(var item in totalItem){
if (totalItem[item] && (totalItem[item].category_name == $scope.stockReport.selectedOption.category_name)){
$scope.total += parseInt(totalItem[item].quantity);

}

}

console.log($scope.total);
return $scope.total;
}
if i try this code - it will calculate all rows - but it will calculate the first row twice. all other things working great
 
remove return $scope.total;
 
still the same
why is it calculates the first row again?
 
console log totalItem[item] and check first row coming twice
 
what to check?
 
6:15 PM
console.log(totalItem[item])
Can you give this output of console log inside for loop
 
it gives me all the objects in the console
 
console.log(totalItem[item]) inside if condition?
 
it gives me 4 objects when there are 3 objects
how to loop -1?
 
change for loop to

for(var item =1; item< totalItem.length; item++){
and remove return $scope.total; also
 
ok! now everything works great except the first specific category
except one specific category*
 
6:27 PM
Can you accept my answer then. I will get back to you if I'm geting more simpler code
 
of course! thanks! in the category list only the first category doesn't calculate the first row
i fixed it!
just needed to change var item = 0
 
okay dude :)
It's late night in india. Need a sleep
 
good night!! thanks a lot :)) you awesome
come visit Israel :)
 
Yeah sure :)
We love that place and people
please accept answer there in the question.
 
i accepted no?
 
6:34 PM
yeah :)
Happy to work with you :) good night
 

  last day (19 days later) »