<?php
include 'config/config.php';
$emi_reference_no=$_REQUEST['emi_reference_no'];
$resSel=mysqli_query($connection,"Select * from tbl_plot_emi_payment where emi_reference_no='$emi_reference_no'");
$rowSel=mysqli_fetch_array($resSel);
$plot_id=$rowSel['plot_id'];
 $entry_date=$rowSel['entry_date'];
$emi_payment_id=$rowSel['emi_payment_id'];
$booking_random_no=$rowSel['booking_random_no'];
 $plot_id=$rowSel['plot_id'];
 $plot_code=$rowSel['plot_code'];
 $member_user_id=$rowSel['member_user_id'];
 $member_name=$rowSel['member_name'];
 $payment_amt=$rowSel['payment_amt'];
 $payment_mode=$rowSel['payment_mode'];
 $bank_name=$rowSel['bank_name'];
 $cheque_no=$rowSel['cheque_no'];
 
 
 $resSp=mysqli_query($connection,"Select * from tbl_memberreg where member_user_id='$member_user_id'");
 $rowSp=mysqli_fetch_array($resSp);
 $sponsor_id=$rowSp['sponcer_id'];
 $sponcer_name=$rowSp['sponcer_name'];



$resTotal=mysqli_query($connection,"Select * from tbl_plot_registry_booking where booking_random_no='$booking_random_no'");
$rowTotal=mysqli_fetch_array($resTotal);
$net_amount=$rowTotal['net_amount'];
$paid_amount=$rowTotal['paid_amount'];
$balance_amt=$rowTotal['balance_amt'];
$project_id=$rowTotal['project_id'];
$cornorType=$rowTotal['cornorType'];
$plot_size=$rowTotal['plot_size'];
$corner_charge=$rowTotal['corner_charge'];

$plotStr=mysqli_query($connection,"Select * from tbl_prject_master where project_id='$project_id'");
$rowPlot=mysqli_fetch_array($plotStr);
$project_name=$rowPlot['project_name'];
?>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>Invoice Receipt || <?php echo $emi_reference_no; ?></title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="assets/css/bootstrap.min.css" rel="stylesheet">
      <style type="text/css">
         .receipt-content .logo a:hover {
         text-decoration: none;
         color: #7793C4; 
         }
         .receipt-content .invoice-wrapper {
         background: #FFF;
         border: 1px solid #CDD3E2;
         box-shadow: 0px 0px 1px #CCC;
         padding: 10px 40px 20px;
         margin-top: 20px;
         border-radius: 4px; 
         }
         .receipt-content .invoice-wrapper .payment-details span {
         color: #A9B0BB;
         display: block; 
         }
         .receipt-content .invoice-wrapper .payment-details a {
         display: inline-block;
         margin-top: 5px; 
         }
         .receipt-content .invoice-wrapper .line-items .print a {
         display: inline-block;
         border: 1px solid #9CB5D6;
         padding: 13px 13px;
         border-radius: 5px;
         color: #708DC0;
         font-size: 13px;
         -webkit-transition: all 0.2s linear;
         -moz-transition: all 0.2s linear;
         -ms-transition: all 0.2s linear;
         -o-transition: all 0.2s linear;
         transition: all 0.2s linear; 
         }
         .receipt-content .invoice-wrapper .line-items .print a:hover {
         text-decoration: none;
         border-color: #333;
         color: #333; 
         }
         .receipt-content {
         background: #ECEEF4; 
         }
         @media (min-width: 1200px) {
         .receipt-content .container {width: 900px; } 
         }
         .receipt-content .logo {
         text-align: center;
         margin-top: 50px; 
         }
         .receipt-content .logo a {
         font-family: Myriad Pro, Lato, Helvetica Neue, Arial;
         font-size: 36px;
         letter-spacing: .1px;
         color: #555;
         font-weight: 300;
         -webkit-transition: all 0.2s linear;
         -moz-transition: all 0.2s linear;
         -ms-transition: all 0.2s linear;
         -o-transition: all 0.2s linear;
         transition: all 0.2s linear; 
         }
         .receipt-content .invoice-wrapper .intro {
         line-height: 25px;
         color: #444; 
         }
         .receipt-content .invoice-wrapper .payment-info {
         margin-top: 25px;
         padding-top: 15px; 
         }
         .receipt-content .invoice-wrapper .payment-info span {
         color: #A9B0BB; 
         }
         .receipt-content .invoice-wrapper .payment-info strong {
         display: block;
         color: #444;
         margin-top: 3px; 
         }
         @media (max-width: 767px) {
         .receipt-content .invoice-wrapper .payment-info .text-right {
         text-align: left;
         margin-top: 20px; } 
         }
         .receipt-content .invoice-wrapper .payment-details {
         border-top: 2px solid #EBECEE;
         margin-top: 10px;
         padding-top: 20px;
         line-height: 22px; 
         }
         @media (max-width: 767px) {
         .receipt-content .invoice-wrapper .payment-details .text-right {
         text-align: left;
         margin-top: 20px; } 
         }
         .receipt-content .invoice-wrapper .line-items {
         margin-top: 20px; 
         }
         .receipt-content .invoice-wrapper .line-items .headers {
         color: #A9B0BB;
         font-size: 13px;
         letter-spacing: .3px;
         border-bottom: 2px solid #EBECEE;
         padding-bottom: 4px; 
         }
         .receipt-content .invoice-wrapper .line-items .items {
         margin-top: 8px;
         border-bottom: 2px solid #EBECEE;
         padding-bottom: 8px; 
         }
         .receipt-content .invoice-wrapper .line-items .items .item {
         padding: 0px 0;
         color: #696969;
         font-size: 15px; 
         }
         @media (max-width: 767px) {
         .receipt-content .invoice-wrapper .line-items .items .item {
         font-size: 13px; } 
         }
         .receipt-content .invoice-wrapper .line-items .items .item .amount {
         letter-spacing: 0.1px;
         color: #84868A;
         font-size: 16px;
         }
         @media (max-width: 767px) {
         .receipt-content .invoice-wrapper .line-items .items .item .amount {
         font-size: 13px; } 
         }
         .receipt-content .invoice-wrapper .line-items .total {
         margin-top: 30px; 
         }
         .receipt-content .invoice-wrapper .line-items .total .extra-notes {
         float: left;
         width: 40%;
         text-align: left;
         font-size: 13px;
         color: #7A7A7A;
         line-height: 20px; 
         }
         @media (max-width: 767px) {
         .receipt-content .invoice-wrapper .line-items .total .extra-notes {
         width: 100%;
         margin-bottom: 30px;
         float: none; } 
         }
         .receipt-content .invoice-wrapper .line-items .total .extra-notes strong {
         display: block;
         margin-bottom: 5px;
         color: #454545; 
         }
         .receipt-content .invoice-wrapper .line-items .total .field {
         margin-bottom: 7px;
         font-size: 14px;
         color: #555; 
         }
         .receipt-content .invoice-wrapper .line-items .total .field.grand-total {
         margin-top: 10px;
         font-size: 16px;
         font-weight: 500; 
         }
         .receipt-content .invoice-wrapper .line-items .total .field.grand-total span {
         color: #20A720;
         font-size: 16px; 
         }
         .receipt-content .invoice-wrapper .line-items .total .field span {
         display: inline-block;
         margin-left: 20px;
         min-width: 85px;
         color: #84868A;
         font-size: 15px; 
         }
         .receipt-content .invoice-wrapper .line-items .print {
         margin-top: 50px;
         text-align: center; 
         }
         .receipt-content .invoice-wrapper .line-items .print a i {
         margin-right: 3px;
         font-size: 14px; 
         }
         .receipt-content .footer {
         margin-top: 40px;
         margin-bottom: 110px;
         text-align: center;
         font-size: 12px;
         color: #969CAD; 
         }  
         @media print {
         .noPrint{
         display:none;
         }
         }
      </style>
   </head>
   <body>
      <div class="receipt-content">
         <div class="container bootstrap snippets bootdey">
            <div class="row">
               <div class="col-md-12">
                  <div class="invoice-wrapper">
                     <div class="intro">
                       <img src="header.png" height="150" width="800">
                     </div>
                     <br>
                   	<div class="table-responsive">
					<table class="table table-stripped" >
					    <tr >
					        <td> Receipt No : <?php echo $emi_reference_no; ?></td>
					        <td> Payment Date: <?php echo date("d-M-Y",strtotime($rowSel['entry_date'])); ?></td>
					    </tr>
					    <tr>
					        <td> Plot No : <?php echo $plot_code; ?>-<?php echo $project_name; ?></td>
					        <td>Plot Size : <?php echo $plot_size; ?>  Sq.</td>
					    </tr>
					    
					    <tr>
					        <td>Customer Id : <?php echo $member_user_id; ?></td>
					        <td> Reference Id : <?php echo $sponsor_id; ?></td>
					    </tr>
					    <tr>
					        <td>Customer Name : <?php echo $member_name; ?></td>
					        <td> Reference By : <?php echo $sponcer_name; ?> </td>
					    </tr>
					    <tr>
					        <table  width="100%" class="table table-stripped">
					            <tr>
					                <td width="33%" style="text-align: center">Total Plot Amount  <br> Rs. <?php echo $net_amount; ?></td>
					                <td width="33%" style="text-align: center">Total Paid Amount  <br> Rs. <?php echo $paid_amount; ?></td>
					                <td width="33%" style="text-align: center">Balance Amt  <br> Rs. <?php echo $balance_amt; ?></td>
					                </tr>
					            </table>
					    </tr>
					    <tr>
				        <table  width="100%" class="table table-stripped">
				            <tr>
				                <td width="10%">#</td>
				                <td width="25%">Payment Mode</td>
				                <td width="25%">Bank Name</td>
				                <td width="20%">Cheque No</td>
				                <td width="20%">Amount</td>
				                </tr>
				                <tr>
				                <td width="10%">1</td>
				                <td width="25%"><?php echo $payment_mode; ?> </td>
				                <td width="25%"><?php echo $bank_name; ?></td>
				                <td width="20%"><?php echo $cheque_no; ?></td>
				                <td width="20%"> Rs. <?php echo $payment_amt; ?>.00 </td>
				                </tr>
				        </table>
					    </tr>
					     <tr>
				        <table  width="100%" class="table table-stripped">
				            <tr>
				                <td width="50%">Amount In World : <?php echo strtoupper(getIndianCurrency($payment_amt)); ?>.</td>
				                <td width="50%" style="text-align: right;">Total <span style="margin-right:40px"><?php echo $payment_amt; ?>.00 </span></td>
				                </tr>
				                <tr><td style="border-top: 0px solid #ddd;"></td><td style="border-top: 0px solid #ddd;"></td></tr>
				            <tr>
				                <td width="50%" height="100" style="border-top: 0px solid #ddd;">Customer Signature</td>
				                <td width="50%" height="100" style="border-top: 0px solid #ddd;">Authorised Signature</td>
				                </tr>
				        </table>
					    </tr>
					    </table>
					     <div class="row item">
                           <div class="col-xs-12 text-center">
                        <div class="print noPrint" >
                           <a href="javascript:void()" onClick="window.print();" style="display: inline-block;
  border: 1px solid #9CB5D6;  padding: 13px 13px; border-radius: 5px;color: #708DC0;font-size: 13px;">
                           <i class="fa fa-print"></i>
                           Print this receipt
                           </a>
                        </div></div>
                     </div>
					    </div>
                  </div>
         
               </div>
            </div>
         </div>
      </div>
      <script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script><script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
      <script src="https://netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
      <script type="text/javascript"></script>
   </body>
</html>
<?php
function getIndianCurrency(float $number)
{
    $decimal = round($number - ($no = floor($number)), 2) * 100;
    $hundred = null;
    $digits_length = strlen($no);
    $i = 0;
    $str = array();
    $words = array(0 => '', 1 => 'one', 2 => 'two',
        3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
        7 => 'seven', 8 => 'eight', 9 => 'nine',
        10 => 'ten', 11 => 'eleven', 12 => 'twelve',
        13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
        16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
        19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
        40 => 'forty', 50 => 'fifty', 60 => 'sixty',
        70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
    $digits = array('', 'hundred','thousand','lakh', 'crore');
    while( $i < $digits_length ) {
        $divider = ($i == 2) ? 10 : 100;
        $number = floor($no % $divider);
        $no = floor($no / $divider);
        $i += $divider == 10 ? 1 : 2;
        if ($number) {
            $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
            $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
            $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
        } else $str[] = null;
    }
    $Rupees = implode('', array_reverse($str));
    $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
    return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise;
}
?>
