<?php 
session_start();
include '../db.php';
include("../all_query.php");
error_reporting(0);
 

 
	

  $account_holder_id = $_REQUEST['account_holder_id'];
	   
	   $customerQ = mysqli_query($conn,"select *from `customer` where account_holder_id = '$account_holder_id' ");
	   $customerData = mysqli_fetch_assoc($customerQ);
	   
	   
		$table_fieldsQ= mysqli_query($conn,"select *from `table_fields` where `table_name` = 'leads' ");
		$table_fieldsData = mysqli_fetch_assoc($table_fieldsQ);
		
		 $leadQ=mysqli_query($conn,"select *from leads  where  account_holder_id = $account_holder_id order by id desc ");
		 
		 $total_loan = mysqli_num_rows($leadQ);
		 
		 $total_loan_amount = 0;
		 $total_tos = 0;
		 
		 
		while($leadData = mysqli_fetch_assoc($leadQ))
		{
			$total_loan_amount = $total_loan_amount + $leadData['loan_amount'];
			$total_tos = $total_tos + $leadData['tos'];
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		 
		?>
		
		
 <html>
<head>
<title>Statement</title>
 
</head>

<body>



<style>

@page {
	
	margin: 0px;
	
}


  .section_page
  {
	  height:297mm;
	  width:210mm;
	  margin:auto;
	  
 	 
	  
	  background-size: 100%;
	   
  }
  
  
    .head_title
  {
	  width:100%;text-align:left;font-size:20px;color:#182425;font-weight:bold;
  }
  .dark_title
  {
	  font-size:14px;color:#182425;font-weight:bold;
	  
  }
   .normal_title
  {
	  font-size:12px;color:#182425;font-weight:bold;text-align:left;
	  
  }
  
  
  
  

 .left_td
 {
	 padding:2px !important;
	 color:white;
	 font-weight:bold;
	 text-align:center;
	 font-size:14px;
	 background:#c8c8c8;
	 border:1px solid black;
 }
 
 .right_td
 {
	  padding:8px !important;
	 color:white;
	 font-weight:bold;
	  text-align:center;
	  font-size:14px;
	 background:#182425;
	  border:1px solid white;
 }
 
  .light_td
 {
	  padding:8px;
	 color:#c8c8c8;
	 font-weight:bold;
	  text-align:left;
	  font-size:14px;
	 background:#a3d5d2;
	  border:1px solid white;
	  
 }
 
 
 
    .para
  {
   color: #182425;font-size: 16px;
  }
  
  .color_scaled
  {
	  background:#182425;
	  color:whte;
	  width:100%;
	  margin-bottom: 5px;
      margin-top: 5px;
	  
  }
  
  
  
  table tr th
  {
	text-align:left;  
	padding:3px;
  }
  
   table tr td
  {
	text-align:center;  
  }
  
  


</style>




 <!---  First Section --->
    <div class="section_page" style="padding:20px;">
	
	
	
	 <p style="text-align:center;" ><img   src="../images/zest_logo.png" style="width:300px;text-align:center;" /></p> <br/>
	
	 <h3 style="text-align:center;">Statement</h3> 
	
	<table border="1" style="width:100%;">
	
	 
	<tr><th>Account Holder Id</th><td><?php echo $customerData['account_holder_id']; ?></td></tr>
	<tr><th>Customer name</th><td><?php echo $customerData['name']; ?></td></tr>
	<tr><th>Father Name</th><td><?php echo $customerData['father_name']; ?></td></tr>
	<tr><th>Advisor</th><td><?php echo $customerData['advisor']; ?></td></tr>
	<tr><th>Total Loan</th><td><?php echo $total_loan; ?></td></tr>
	<tr><th>Total Loan Amt</th><td><?php echo number_format($total_loan_amount); ?></td></tr>
	<tr><th>Total Outstanding</th><td><?php echo number_format($total_tos); ?></td></tr>
	
	
	 
	</table>
	
	<br/>
	<br/>
	
	
	<?php
	
	   $headerArray = array('firstduedate','disbursaldate','lastduedatenotpaid','emi','accountid','tenure','merchant_category_group','merchant_category_ed','genericmerchantname','lender','principaldue','interestdue','feesdue','penaltydue','totaldue','noofemismissed','noofemispaid','total_amount_missed','tos','loanamount','email','activationdate','bankname','mandatemode','mandatestatus','city','state','pincode','interestrate','cibilscore','principal_missed','interest_missed','noofemispassed','lastpaidamount','lastpaiddate','single_emi','2_emi','rb_emi','normal_emi');
	
	
			  $leadQ=mysqli_query($conn,"select *from leads  where  account_holder_id = $account_holder_id order by id desc ");
						  
					 
					$i=0;

					while($row=mysqli_fetch_assoc($leadQ))
					 {  
				 
					$lead_data = $row['lead_data'];
					$leadDataArray = json_decode(stripslashes($lead_data),TRUE); 

					 
					 $i++;
					 
					 
					 ?>
					 
					<table border="1" style="width:100%;">
					
					<tr><td colspan="2" style="font-weight:bold;font-size:18px;">Account ID:<?php echo $row['account_id']; ?></td></tr>
					 
					 <?php foreach($headerArray as $key) { ?>
					 
					 <tr><th><?php echo strtoupper($key);  ?></th><td><?php echo  $leadDataArray[$key]; ?></td></tr>
					 
					 <?php } ?>
					 
					 
					 </table>
					 
					 <br/><br/>
	 
	
	
	
					 <?php } ?>
	
	
	
	 
   
   
   </div>









<body>


</html>

 