<?php
include("db/cn.php");
if(isset($_SESSION['user_name']) && isset($_SESSION['user_role'])&& isset($_SESSION['outlet_name'])
&& isset($_SESSION['outlet_address'])) {
    $userName = $_SESSION['user_name'];
    $userRole = $_SESSION['user_role'];
	$outlet_address = $_SESSION['outlet_address'];
	$outlet_name = $_SESSION['outlet_name'];
}

$customer_name = $_GET["customer_name"];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Installment Collection Receipt</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .receipt-border {
            border: 2px solid black;
        }

        .header-row, .footer-row {
            background-color: #f0f0f0;
        }

        .urdu-text {
            font-family: 'Jameel Noori Nastaleeq', serif;
            text-align: right;
        }

        .receipt-image {
            height: 70px;
            width: 70px;
            background-color: lightgray; /* Placeholder for images */
        }
    </style>
</head>
<body>
    <div class="container mt-5 receipt-border p-3">
        <div class="row header-row">
            <div class="col-md-2 text-center">
                <!-- Company logo -->
                <img src="img/united sales corporation 2.png" width="80" height="70">
                <div class="receipt-image">
                    <!-- Placeholder for logo -->
                </div>
                <p></p>
            </div>
            <div class="col-md-6 text-center">
                <h4>UNITED SALES CORPORATION </h4>
                <h5>Installment Collection Receipt</h5>
            </div>
            <div class="col-md-4 text-end">
                <p>Print Date: <strong><?php echo date("Y-m-d");  ?></strong></p>
            </div>
        </div>

        <div class="row mt-3">
            <div class="col-md-8">
                <p>Branch: A &nbsp; UID:  &nbsp; Recovery Officer: </p>
            </div>
            <div class="col-md-4 text-end">
                <p><strong></strong></p>
            </div>
        </div>

        <div class="row mt-3">
            <div class="col-md-2">
                <!-- Placeholder for picture -->
                <div class="receipt-image"></div>
            </div>
            <div class="col-md-2">
                <!-- Placeholder for fingerprint -->
                <div class="receipt-image"></div>
            </div>
            <div class="col-md-8 urdu-text">
                <p>یہ رقم ہمارے پاس تاریخ تنخواہ جمع کرائی گئی تھی...</p>
                <p>معاہدہ کے ختم ہونے کی صورت میں کوئی تجدید نہیں ہوگی۔</p>
            </div>
        </div>

        <div class="row mt-3">
            <div class="col-md-6">
                <p>Receipt No: <strong></strong></p>
                <p>Date: <strong><?php print date("Y-m-d");  ?></strong></p>
                <p>A/C No: <strong></strong></p>
                <p>Customer:  <strong style="text-transform:capitalize;"><?php echo $customer_name;  ?></strong></p>
               <!-- <p>S/O: <strong></strong></p>
                <p>Your Remaining No. of Installments: <strong></strong></p>-->
            </div>
            <div class="col-md-6">
            <?php 
			$sale1 = mysqli_query($connection,"select * from log_user_sales where customer_name = '$customer_name'");
			$sale_n = mysqli_fetch_array($sale1);			
			?>
                <table class="table table-bordered">
                    <tbody>
                        <tr>
                            <td>Inst. Price</td>
                            <td><?php echo $sale_n["per_month"]; ?></td>
                        </tr>
                        <tr>
            <?php 
			$crec = mysqli_query($connection,"select * from creditor_closing where creditor_name = '$customer_name'");
			$crec_n = mysqli_fetch_array($crec);			
			?> 
                            <td>Pre Balance</td>
                            <td><?php echo $crec_n["remain_balance"];
							  
							  $pre = $crec_n["remain_balance"];
							
							 ?>
                            
                            </td>
                        </tr>
            <?php 
			$srec = mysqli_query($connection,"select * from credit_paid where cr_name = '$customer_name'");
			$rec_n = mysqli_fetch_array($srec);			
			?>
                        <tr>
                            <td>Recv Amount</td>
                            <td><?php echo $rec_n["amount"];
							$recv = $rec_n["amount"];
							 ?></td>
                        </tr>
                        <tr>
                            <td>Discount</td>
                            <td>0</td>
                        </tr>
                        <tr>
                            <td>Visit Charges</td>
                            <td>0</td>
                        </tr>
                        <tr>
                            <td>Balance</td>
                            <td>
                            <?php $bal =  $pre - $recv ; 
							   echo $bal;
							 ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="row footer-row mt-3">
            <div class="col-md-12">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Model</th>
                            <th>Item Name</th>
                            <th>Serial No</th>
                            <th>Qty</th>
                            <th>Installment</th>
                            <th>Inst. Price</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $sale = mysqli_query($connection,"select * from log_user_sales where customer_name = '$customer_name'");
					while($sale_fetch = mysqli_fetch_array($sale)){
					
					?>
                        <tr class="text-center">
                            <td><?php echo "";?></td>
                            <td><?php echo $sale_fetch["product_name"]; ?></td>
                            <td><?php echo "";?></td>
                            <td><?php echo $sale_fetch["product_quantity"]; ?></td>
                            <td><?php echo $sale_fetch["term"]." Month"; ?></td>
                            <td><?php echo $sale_fetch["per_month"]; ?></td>
                        </tr>
                        <?php
					}
						?>
                        
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
