<?php
include"initialize_page.php";
include"systemfunctions.php";	
?>
<?php include('resources/header.php') ?>
	<title>Payment</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
<?php include('resources/css-file.php') ?>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
<?php include('resources/navigation.php') ?> 
<!-- Dashboard wrapper starts -->
<div class="dashboard-wrapper">
	<div class="main-container">				
		<div class="row">
			<div class="col-sm-12 ac-summ">
				<!--<h2>Account Summary</h2>-->
				<h3>
					Payment
				</h3>
                
			</div>
			
		</div>
		</br>
		<div class="row gutter">
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
				<ul class="boxli">
					<li>
						<h3>Due Installment</h3>
						<div class="table-responsive">
							<table class="table table-bordered no-margin">
								<thead>
									<tr>
										<th>No</th>
										<th>Due Date</th>
										<th>Monthly Payment</th>
									</tr>
								</thead>
								<tbody>
												
						<?php 
									$main_acccurrency = main_account_currency($user_id);
									 $date = date('Y-m-d', strtotime('+1 months'));
									 //$loan_id = $_SESSION['loan_id'];
									$select_query = "select * from x_loanstatement where x_loanid = '$loan_id' and x_duedate <= '$date' and x_status='N' ";
									$select_result = mysqli_query($con,$select_query);
									$num = mysqli_num_rows($select_result);
									
									$due_total = 0;
								
									$i=0;
									if($num >0)
									{
										$cur_date = date("Y-m-d"); 
										while($row = mysqli_fetch_array($select_result))
										{	
											 $due_pay = $row['x_duepay'];
											 $due_pay =  number_format($due_pay,2);
											 $due_total +=$due_pay;
											 $due_total =  number_format($due_total,2);
											 //$rem_bal = $row['x_rembalance'];
											 $due_date = $row['x_duedate'];
											
											 
											 
											 $i++;
											 
	
								?>					
									
													<tr>
														<td><?php echo $i ;?></td>
														<td><?php echo  $due_date;?></td>
														<td><?php echo $main_acccurrency?><?php echo  $due_pay;?></td>
														
													</tr>
													
													
									<?php } }
								 ?>					
								<tr>
														<td>Total</td>
														<td></td>
														<td><?php echo $main_acccurrency?><?php echo  $due_total;?></td>
														</tr>
										</tbody>
							</table>
						</div>
					</li>
					<li>
						<h3>Loan Paymrnt</h3>
						<form  method="post" action="" id="addcustom">
								<div class="form-group">
										<input type="hidden" name="q" value="loan_payment" class="form-control">
									</div>
									<div class="form-group">
										<input type="hidden" class="form-control" name="tot" id="tot" value=<?php echo $due_total; ?>>
									</div>
									
									
                                  <div class="form-group">
									<label>Accounts</label>
									<select class="form-control" name="account" id= "account"required>
									<option value = "" selected
									>Select Account</option>
									<?php 

									$select_query = "select * from x_anotheracc where x_userid = '$user_id' and x_status ='Y'";
									$select_result = mysqli_query($con,$select_query);
									$num = mysqli_num_rows($select_result);
									

									
									if($num > 0)
									{
										
										while($row = mysqli_fetch_array($select_result))
										{	
											  $account_no = $row['x_time'];
											  $account_type = $row['x_actype'];
											  $account_id = $row['x_id']; 
							
											
											 
	
								?>	
										<option value = "<?php echo $account_id;?>" ><?php echo  $account_no;?>(<?php echo $account_type; ?>)</option>
										
									<?php }}?>
									</select>
									<label id="converted_value"></label>
								  </div>
								  <div class="form-group">
									<input type="submit" class="btn btn-info"  value="Pay Now" name="addloantype">
								  </div>
								  </form>
					</li>
				</ul>
							
							
			</div>	
		</div>
	</div>		
	</br>
	</div>
	<!-- Main container ends -->
<!-- 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 Select Account...");
	}
	if(data == 'lessbal')
	{
		alert("Insufficent Balance...");
	}
	if(data == 'nodue')
	{
		alert("No Due Installment...");
	}
	
	if(data=="done")
	{
		alert("Successfully Payment..");
		window.location.href='<?php   echo website_settingdata('x_weburl');   ?>user/view_loan_detail.php';
	}
}
});
}));
});
	
</script>

<script type="text/javascript">
  $(document).ready(function() {
         //test amount on fill
		 
		 $("#account").on('change', function(e){   
                
				var account = $("#account option:selected").val();
				
		       if(account!="")
			     {
					var total = $("#tot").val();
					
				       $.post("controller.php", { q:"get_converted_amount", total:total,accid:account }, function(data)
					     {
							//alert(data); 
							$("#converted_value").text("Converted Amount  "+data);
							 
						 }
					   ); 
					 
				 }
           });
		
		 
});

</script>





