var app = angular.module('wealthPlanning', ['rzModule', 'ui.bootstrap']);
app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
  
  $scope.Math = window.Math;
 

  $scope.rateofreturn = {
    value: 12,
    options: {
      showSelectionBar: true,
      floor: 5,
      ceil: 20,
      precision:2,
      step:0.5,
      showTicksValues: false,
      ticksTooltip:false,
      hideLimitLabels:true,
      translate: function(value) {
        return value + '%';
      }
    }
  };

  $scope.tenurewealth = {
    value: 15,
    options: {
      showSelectionBar: true,
      floor: 5,
      ceil: 35,
      showTicksValues: false,
      ticksTooltip:false,
      hideLimitLabels:true,
    }
  };

  $scope.inflation ={
    value: 8,
    options: {
      showSelectionBar: true,
      floor: 0,
      ceil: 15,
      precision:2,
      step:0.5,
      showTicksValues: false,
      ticksTooltip:false,
      hideLimitLabels:true,
      translate: function(value) {
        return value + '%';
      }
    }
  };

  $scope.savedMoney ={
    value: 0,
  };

  $scope.pv = {
    value: 0,
  };

  $scope.savedMoneyGrowthRate ={
    value: 12,
  };

  $scope.compounding ={
    value:12
  };

  $scope.crorepati ={
    value: 10000000,
  };

  $scope.value_change_1cr = function(){

    $scope.targetFutureValue = 10000000;
    $scope.factor_1 = (1+ (($scope.rateofreturn.value / 100 ) / $scope.compounding.value));
    $scope.factor_2 = Math.pow($scope.factor_1, $scope.compounding.value * $scope.tenurewealth.value ) - 1;
    $scope.factor_3 = $scope.factor_2 / (($scope.rateofreturn.value / 100 ) / $scope.compounding.value);
    $scope.monthlySavingNeeded = 10000000 / $scope.factor_3;

  };

  $scope.other_dream = function(){

    $scope.test = $scope.rateofreturn.value;
    $scope.savedMoneyFutureValuePartOne = $scope.savedMoney.value * (Math.pow((1+(($scope.rateofreturn.value - $scope.inflation.value)/100)), $scope.tenurewealth.value)); 
    $scope.savedMoneyFutureValuePartTwo = ($scope.savedMoneyFutureValuePartOne * ($scope.rateofreturn.value / 100 ) * $scope.tenurewealth.value) / 100;
    $scope.savedMoneyFutureValue = $scope.savedMoneyFutureValuePartOne + $scope.savedMoneyFutureValuePartTwo;
    
    $scope.targetFutureValue = ($scope.pv.value * (Math.pow((1+($scope.inflation.value/100)), $scope.tenurewealth.value))) - $scope.savedMoneyFutureValue;

   /* $scope.monthlySavingNeeded = $scope.targetFutureValue / (((1+(Math.pow((1+(($scope.rateofreturn.value/100)/12)), $scope.tenurewealth.value*12)))-1) / (($scope.rateofreturn.value/100)/12));*/
	$scope.monthlySavingNeeded = $scope.targetFutureValue / (((Math.pow((1+(($scope.rateofreturn.value/100)/12)), $scope.tenurewealth.value*12))-1) / (($scope.rateofreturn.value/100)/12))

   };

    $scope.change = function(){
    if ( $scope.wealth_dream == 'Crorepati_plan'){
      $scope.value_change_1cr();
    }
    else{
      $scope.other_dream();
    }   
   };

});