<?php

include 'db_connection.php';

if(isset($_GET['rno'])) {
    // Retrieve and sanitize the value of 'rno' from the URL
    $order_id = htmlspecialchars($_GET['rno']);
    
   
}

$result = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobile_credit_payments,mobilecustomers WHERE mobile_credit_payments.credit_payment_id = '$order_id'"));



		$customer = $result["cname"];
		$amount = $result["amount"];
		$date = $result["added_date"];

$orid = $order_id;



?>

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Invoice</title>
	<style>
	@page {
    size: 10.4cm 10cm landscape;
    font-size: 12px;
}
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 80mm; 
            margin: 0 auto;
            padding: 10px;
            box-sizing: border-box;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th,
        td {
            padding: 5px;
            text-align: left;
			font-size: 10px; 

        }

        img {
            width: 80px; 
            height: auto;
            margin-right: 10px;
        }

        p {
            font-size: 12px; 
            margin: 0;
        }

        .center {
            text-align: center;
        }
    </style>
</head>

<body>
<div class="container">
	<div style="width:100%;">
		<div style="text-align: center;">
				<b>
                    <p style="font-size:24px;">Eat More Resturant  </p>
                    <p style="font-size:14px;">Mirigama/Balangoda</p>
                </b>
                <p style="margin: 0;">Tel : 071 513 2796</p>
		</div>
	</div>
	<hr>
    <div class="container">
		<p>Receipt: <?php echo $order_id; ?></p>
		
		<p>Date: <?php echo $date; ?></p>
		<hr>
        
		<table>
			<thead>
				<tr>
					<th><span style="text-align: center;">Customer</span></th>
					<th><span style="text-align: center;">Amount</span></th>
					<th style="text-align: right;"><span style="text-align: center;">Total</span></th>
				</tr>
			</thead>
			<tbody>
				<?php
				
						echo "<tr>";
						echo "<td>$customer</td>";
						echo "<td>$amount</td>";
						echo "<td style='text-align: right;'>$amount</td>";
						
						
						echo "</tr>";
					
				?>
			</tbody>
			<tfoot>
				
				<tr>
					<td colspan="2">Total Payment:</td>
					
					<td style='text-align: right;'>Rs. <?php echo number_format((float)$amount, 2); ?></td>
				</tr>
				
				
			</tfoot>
		</table>
        </div>
		<center>
		<br>
		<hr>
		<p>Thank You Come Again! </p>
		<p>Developed By Seopro Developer</p>
		</center>
</div>
	<!-- JavaScript to trigger print functionality -->
	<script>
		window.onload = function() {
			window.print();
		};
	</script>
</body>

</html>

<?php
$conn->close();
?>
<script>
    function redirectToPosPanel() {
        window.location.href = "listcredit.php";
    }

    window.onafterprint = redirectToPosPanel;
    window.onload = function() {
        window.print();
        setTimeout(redirectToPosPanel, 2000);
    };
</script>
