<?php
include"initialize_page.php";
include"systemfunctions.php";
?>
<?php include('resources/header.php') ?>
	<title></title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
<?php include('resources/css-file.php') ?>
<style>
.panel{border-radius:0px;}
.panel-heading{background:#E1E3F2;
padding:3px 10px;
border-radious:none;
}
.mini-widget a{color:#fff;}
</style>
<?php include('resources/navigation.php') ?> 
<!-- Dashboard wrapper starts -->
<div class="dashboard-wrapper">
	<div class="main-container">				
		<div class="row">
			<div class="col-sm-6 ac-summ">
				<h2>Apply For Investment</h2>
			</div>
			<div class="col-sm-6 do-name">
				<ul style="display: inline-flex;float:right;margin:7px auto;">
					<li><a href="<?php  echo website_settingdata('x_weburl'); ?>user/loan_form.php" class="btn">Apply For Loan</a></li>
					<li><a href="<?php  echo website_settingdata('x_weburl'); ?>user/cds_form.php" class="btn">Apply For CDS</a></li>
					<li><a href="<?php  echo website_settingdata('x_weburl'); ?>user/investment_form.php" class="btn btn-success">Apply For Investment</a></li>
				</ul>
			</div>
		</div>
		<div class="row gutter">
			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
				<div class="panel">
					<div class="panel-heading">
						<h4>Apply For Investment</h4>
					</div>
					<div class="panel-body">
						<form  method="post"  id="addcustom">
							<div class="form-group">
								<input type="hidden" class="form-control" name="q" value="apply_for_investment">
							</div>
							<div class="form-group">
								<label>Amount</label>
								<input class="form-control" type="text"  name ="amount" id = "amount" placeholder="Amount" required>
							</div>
							<div class="form-group">
								<label>Fixed Interest</label>
								<input class="form-control" type="text"  name ="interest" id = "interest" placeholder="Interest"  readonly >
							</div>  
							<div class="form-group">
								<label>Period </label>
								<div class="row">
									<div class="col-sm-6">
										<input class="form-control" type="text"  name ="number" id = "number" placeholder="Number" required>
									</div>
									<div class="col-sm-6">
										<select name="period" id="period" class="form-control" required>
										   <!--  <option selected value="">Select </option>-->
										  <!--  <option value="365">Day(s)</option>
											<option value="12">Month(s)</option>-->
											<option value="1">Year(s)</option>
										   
										</select>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label>Frequency </label>
								
								<select name="frequency" id="frequency" class="form-control" required>
									 <option selected value="">Select </option>
									<option value="12">Monthly</option>
									<option value="4">Quarterly</option>
									<option value="2">HalfYearly</option>
								   <option value="1" selected="">Annually</option>
								</select>
							</div>
							<div class="form-group">
								<label>Matured Amount</label>
								<input class="form-control" type="text"  name ="matutredamount" id = "matutredamount" placeholder="Amount" readonly>
	                        </div> 
							<div class="form-group">
								<label>Interest Earned </label>
								<input class="form-control" type="text"  name ="earninterest" id = "earninterest" placeholder="Amount" readonly>
	                        </div> 
							<div class="form-group">
								<input type="submit" class="btn btn-info"  value="Apply" name="applyfor;oan">							
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>	
		</br>
		
	</div>
	<!-- Main container ends -->
</div>
<!-- Dashboard wrapper ends -->
<?php include('resources/footer.php') ?>
<?php include('resources/js-file.php') ?>
<script type="text/javascript">
	 $(document).ready(function() {
    $("#addcustom").on('submit',(function(e) {
e.preventDefault();

$.ajax({
url: "controller.php", // Url to which the request is send
type: "POST",             // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false,       // The content type used when sending data to the server.
cache: false,             // To unable request pages to be cached
processData:false,        // To send DOMDocument or non processed data file it is set to false
success: function(data)   // A function to be called if request succeeds
{
	//alert(data);
	if(data =="empty")
	{
		alert("Please Fill All Fields...");
	}
	if(data == "notnumeric")
	{
	     alert("Please Fill Numbers in Period...");	
	}
	if(data=="done")
	{
		alert("Request Successfully..");
		window.location.href='<?php echo website_settingdata('x_weburl');?>user/start.php';
	}
}
});
}));
});
	
</script> 

<script type="text/javascript">
  $(document).ready(function() {
         
		 
		 $("#number").on('change', function(e){   
                
				
				var number = $("#number").val();
				//alert(number);
				//var frequency = $("#frequency option:selected").val();
				//alert(frequency);
				//alert(period);
		       if(number!="")
			     {
					var period = $("#period option:selected").val();
					
					var amount =$("#amount").val();
					var interest = $("#interest").val();
					interest = interest.replace(" %","");
					interest = interest/100;
					var t = number /period;
					//var day = t*365;
					//var month = t*12.000008;
				    //alert(month);
					var n = 1;//frequency;
					var temp =(1 + interest / n);
					
                    var A = amount * Math.pow(temp,(n*t));
                    var I =A-amount;
					
					
					$("#matutredamount").val(A.toFixed(2));
					$("#earninterest").val(I.toFixed(2));
					//alert(I);
                     
				 }
           });
		
		 
});

</script>

<script type="text/javascript">
   $(document).ready(function() {
         //test amount on fill
		 
		 
		 $('#amount').change(function(e){
		
		  var amount=$("#amount").val();
		     
			    if(amount!="")
				   {
					   
					//alert(amount);
					  $.post("controller.php", {  q:"test_investment_minamount", amount:amount  }, function(data)
					     {
							 //alert(data);
							 if(data == "notnumeric")
							 {
								alert("Amount should be in numeric..");	
							 }
							 if(data == "amount_min")
							 {
								 alert("Minimum Amount For Investment is <?php echo main_account_currency($user_id) ?> <?php echo investment_setting("x_mininvest")?>")
							 }
							 else
							 {     
								 var interest = data;
								 //alert(interest);
								 $("#interest").val(interest+" %");
							 							 
							 }
							 	
							 
						 }
					  );
					
					   
				   }
		
    });
		 
});



</script>
