javascript - code changes the length of array in foreach loop angularjs -
length of array 3 responsed server.changing value of data in below code when comment if condition of b.days part length of $scope.bookingdetails fine when use length of $scope.bookingdetails become 1. please me
thanks
$http.post('bookings/getdetails/', datatosend).then (function (response) { console.log(response); if (response.data.response == 1) { $scope.receivings = response.data.receivings; $scope.bookingdetails = angular.copy(response.data.bookingdetails); angular.foreach($scope.bookingdetails, function (b) { var t = b.arrival.split(/[- :]/); var d = new date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]); b.arrival = d; var t = b.departure.split(/[- :]/); var d = new date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]); b.departure = d; var t = b.checkintime.split(/[- :]/); var d = new date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]); b.checkintime = d; if (b.checkouttime != null) { var t = b.checkouttime.split(/[- :]/); var d = new date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]); b.checkouttime = d; } var tdy = parseint(b.days); if (parseint(b.diffhours) > 1) { tdy = parseint(tdy) + 1; } else if (parseint(b.diffhours) == 0) { if (parseint(b.days) == 0) { tdy = 1; } } var daysamount = parseint(tdy) * parseint(b.amount); console.log('d : ' + daysamount + ' days : ' + tdy + ' amt : ' + b.amount); var extrapersoncharges = 0; if (b.extraperson != 0) { extrapersoncharges = parseint(tdy) * (parseint(b.extrapersoncharges) * parseint(b.extraperson)); } var roomreceivings = 0; var roomservices = 0; angular.foreach($scope.receivings, function (r) { if (r.booking_id == b.booking_id) { roomreceivings = roomreceivings + r.amount; } }); angular.foreach($scope.services, function (s) { if (s.booking_id == b.booking_id) { roomservices = roomservices + (s.amount * s.times); } }); roomreceivings = roomreceivings + b.advance; var finalpayable = parseint(daysamount) + parseint(extrapersoncharges) + parseint(roomservices); if (parseint(roomreceivings) > parseint(finalpayable)) { b.finalrefundable = parseint(roomreceivings) - parseint(finalpayable); b.finalreceivable = 0; } else { b.finalrefundable = 0; b.finalreceivable = parseint(finalpayable) - parseint(roomreceivings); } $scope.globalcharges = parseint($scope.globalcharges) + parseint(finalpayable); $scope.globalreceived = parseint($scope.globalreceived) + parseint(roomreceivings); console.log('print'); }); if ($scope.globalcharges > $scope.globalreceived) { $scope.finalreceivable = parseint($scope.globalcharges) - parseint($scope.globalreceived); } else { $scope.finalreceivable = 0; } $scope.customerdetails = response.data.customerdetails; //$scope.getrooms(); $scope.selectedroom = $scope.globalroom.room_id;//$scope.bookingdetails[0].room_id; $scope.services = response.data.services; } }, function (response) { alert('error loading'); });
Comments
Post a Comment