<?php
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");
include($path_to_root . "/includes/ui.inc");
//include($path_to_root . "/includes/current_user.inc");
include_once($path_to_root . "/includes/db/connect_db.inc");

	/*echo "Payment Method = ".$_POST['paymeth']."<br/>";
	echo "Fee = ".$_POST['fee']."<br/>";
	echo "Reg Fee = ".$_POST['regFee']."<br/>";
	echo "Duration = ".$_POST['duration']."<br/>";
	echo "Discount = ".$_POST['cDiscount']."<br/>";*/
	
	
	$arr = array();
	
	$perYear = 0;
	$final = 0;
	
	$res = get_calcAmount_for_paymeth($_POST['paymeth'],$_POST['fee'],$_POST['duration'],$_POST['cDiscount'],$_POST['regFee']);
	//print_r($res);
	
	$arr[0] = $res;
	
	echo json_encode($res);
	exit();

	function get_calcAmount_for_paymeth($paymth,$amount,$years,$dis,$regFee)
	{
	  $final = 0;
	  $amount = $amount + $regFee;
	  //echo "amount = ".$amount;
	  
	  if($dis == 0)
	  {
	      $perYear = $amount/$years;
	  }
	  else
	  {
		  $dis = $dis/100;
		  $disAmount =  $amount * $dis;
	  	  $amount =  $amount - $disAmount;
		  //echo "amount after discount = ".$amount;
		  $perYear = $amount/$years;
	  }
	  
	  
	  if($paymth=="Annualy")
	  {
		  //$final = number_format2($perYear,2);
		  return number_format2($perYear,2);
	  }
	  elseif($paymth=="Monthly")
	  {
		  //$final = number_format2($perYear/12,2);
		  return number_format2($perYear/12,2);
	  }
	  elseif($paymth=="Semesterly")
	  {
		  //$final =  number_format2($perYear/2,2);
		  return number_format2($perYear/2,2);
	  }
	  elseif($paymth=="Total")
	  {
		  //$final =  number_format2($amount,2);
		  return number_format2($amount,2);
	  }
	  return $final;

	  //echo "Final Fee= ".$final;
	}
	
	

?>
