<?php
session_start();
include 'db_connection.php';
//$user_id = $_SESSION["user_id"];
$receiptno = $_GET['receiptno'];
$orderinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileorders WHERE order_id='$receiptno'"));
$userid = $orderinfo['user_id'];
$customer = $orderinfo['customer'];
$pay_option = $orderinfo['pay_option'];

$userinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileusers WHERE user_id='$userid'"));
$sql = "SELECT * FROM mobileorders WHERE order_id = '$receiptno'";

$result = $conn->query($sql);
$tltdiscount=0;
$discount = 0;
$dis_type = 0;
$paid_amount = 0;
if ($result->num_rows > 0) {

    while ($row = $result->fetch_assoc()) {
        $paid_amount = $row["paid_amount"];
        $orid = $row["orid"];
        $create_at = $row["create_at"];
        $pay_option = $row["pay_option"];
        $amount = $row["amount"];
		$tltdiscount = $row["discount"];
        $discount = $row["discount"];
        $dis_type = $row["dis_type"];
    }
}

$sql = "SELECT * FROM mobiletemporarycart WHERE orderid = '$receiptno'";
$result = $conn->query($sql);

?>

<!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: 15px;
        }

        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }

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

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

        tbody {
            td {
                font-size: 15px;
            }
        }

        tfoot {
            td {
                font-size: 15px;
            }
        }

        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;
        }
        td,th{
            padding-top: 2px;
            padding-bottom: 2px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div style="width:100%;">
            <div style="text-align: center;">
                <b>
					<p style="text-align:center;"><img src="logoab.png" alt="#"></p>
                    <p style="font-size:20px;">Payroll</p>
                    <p style="font-size:14px;">Pasyala Road,Mirigama</p>
					<p style="margin: 0;font-size:14px;">Tel : 071 513 2796</p>
					
                </b>
                
            </div>
        </div>
		<hr>
		<p style="font-size:17px;text-align:center;">Installment Receipt</p>
        <br>
		<p style="font-size:15px;">Date: <?php echo $create_at; ?></p>
		<hr>
		<table>
            <tbody>
			
				<tr>
                    <td colspan="5" style='font-size:16px;'>Route : </td>
                    <td style='font-size:16px;'>Negombo</td>
                </tr>
                <tr>
                    <td colspan="5" style='font-size:16px;'>Loan No : </td>
                    <td style='font-size:16px;'>101</td>
                </tr>
                <tr>
                    <td colspan="5" style='font-size:16px;'>Customer : </td>
                    <td style='font-size:16px;'>Kasun Gamage</td>
                </tr>
                <tr>
                    <td colspan="5" style='font-size:16px;'>Loan Amount : </td>
                    <td style='font-size:16px;'>Rs.15,000</td>
                </tr>
               <tr>
                    <td colspan="5" style='font-size:16px;'>Rental : </td>
                    <td style='font-size:16px;'>Rs.500</td>
                </tr>
               
				<tr>
                    <td colspan="6">
                        <hr>
                    </td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Duration : </td>
                    <td style='font-size:16px;'>60</td>
                </tr>
                <tr>
                    <td colspan="5" style='font-size:16px;'>Start Date : </td>
                    <td style='font-size:16px;'>2024-12-28</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>End Date : </td>
                    <td style='font-size:16px;'>2025-02-28</td>
                </tr>
				<tr>
                    <td colspan="6">
                        <hr>
                    </td>
                </tr>
                <tr>
                    <td colspan="5" style='font-size:16px;'>Total Paid : </td>
                    <td style='font-size:16px;'>Rs.17,945</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Total Due : </td>
                    <td style='font-size:16px;'>Rs.13,055</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Today Paid : </td>
                    <td style='font-size:16px;'>Rs.1,000</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Today Paid Rental : </td>
                    <td style='font-size:16px;'>Rs.1,000</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Paid Penalty : </td>
                    <td style='font-size:16px;'>0</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Paid Due Interest : </td>
                    <td style='font-size:16px;'>0</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Brought Forward : </td>
                    <td style='font-size:16px;'>Rs.12,055</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Arrears : </td>
                    <td style='font-size:16px;'>Rs.2,555</td>
                </tr>
				<tr>
                    <td colspan="6">
                        <hr>
                    </td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Closing Balance : </td>
                    <td style='font-size:16px;'>Rs.12,055</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Outstading Penalty : </td>
                    <td style='font-size:16px;'>0</td>
                </tr>
				<tr>
                    <td colspan="5" style='font-size:16px;'>Outstading Due Interest : </td>
                    <td style='font-size:16px;'>0</td>
                </tr>
            </tbody>
        </table>
		
		<hr>

        <center>
            <p>Thank You Come Again!</p>
            <p>Developed By Seopro Developer</p>
        </center>
    </div>
    <!-- JavaScript to trigger print functionality -->
    <script>
       window.onload = function() {
            window.onafterprint = function() {
                
              window.location.href = '/pos-panel.php';
            };
            window.print();
            setTimeout(function() {
                window.onafterprint = null;
            }, 1000);
        };
    </script>
</body>

</html>

<?php
$conn->close();
?>