<?php
session_start();
include 'db_connection.php';
//$user_id = $_SESSION["user_id"];
$receiptno = $_GET['receiptno'];
$orderinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileroombooking,mobileproducts,mobilecustomers WHERE mobileroombooking.room=mobileproducts.prid AND mobilecustomers.coid=mobileroombooking.customer AND mobileroombooking.rbid='$receiptno'"));
$checkindate = $orderinfo['checkindate'];
$checkoutdate = $orderinfo['checkoutdate'];
$cname = $orderinfo['cname'];
$sellprice = $orderinfo['sellprice'];
$advance = $orderinfo['advance'];

$proname = $orderinfo['proname'];
$create_at = $orderinfo['add_date'];


$start = new DateTime($checkindate);
$end = new DateTime($checkoutdate);
$interval = $start->diff($end);
$days = $interval->days;  
?>

<!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;
        }
    </style>
</head>

<body>
    <div class="container">
        <div style="width:100%;">
            <div style="text-align: center;">
                <b>
					<p style="text-align:center;"><img src="images/poslogo.png" alt="#" width="44px"></p>
                    <p style="font-size:24px;">Eat More Resturant   </p>				
                    <p style="font-size:24px;">143/C,Kandewaththa Road,Minuwangoda,Galle</p>
                </b>
                <p style="margin: 0;">Tel : 077 324 1469</p>
            </div>
        </div>
        <hr>
        <p style="font-size:16px;">Receipt: <?php echo $receiptno; ?></p>
        
        <p style="font-size:16px;">Date: <?php echo $create_at; ?></p>
        <p style="font-size:16px;">Customer: <?php
                                                        echo $cname;
                                                
                                                ?>

        </p>
        <p style="font-size:16px;">Check In: <?php echo $checkindate; ?></p>
        <p style="font-size:16px;">Check Out: <?php echo $checkoutdate; ?></p>
        <hr>
        <table>
            <thead>
                <tr>
                    <th ><span style="text-align: center; font-size:17px;">Room</span></th>

                    <th ><span style="text-align: center; font-size:17px;">Price</span></th>
                    <th ><span style="text-align: center; font-size:17px;">Days</span></th>
                   
                    <th style="text-align: center; font-size:17px;"><span style="text-align: center; font-size:17px;">Amount</span></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><?php echo $proname; ?></td>
                    <td><?php echo $sellprice; ?></td>
                    <td><?php echo $days; ?></td>
                    
                    <td><?php echo number_format((float)$sellprice * $days, 2); ?></td>
                </tr>
                <?php
                

                ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="6">
                        <hr>
                    </td>
                </tr>
               
                
                <tr>
                    <td colspan="2" style="font-size: 16px;"><strong>Total Amount:</strong></td>
                    <td style="font-size: 16px;"><strong>Rs.</strong></td>
                    <td style="font-size: 16px; text-align:right;"><strong><?php echo number_format((float)$sellprice * $days, 2); ?></strong></td>
                </tr>
               <?php if($advance!=0){ ?>
                <tr>
                    <td colspan="2" style="font-size: 16px;"><strong>Advance Amount:</strong></td>
                    <td style="font-size: 16px;"><strong>Rs.</strong></td>
                    <td style="font-size: 16px; text-align:right;"><strong><?php echo number_format((float)$advance, 2); ?></strong></td>
                </tr>
                <tr>
                    <td colspan="2" style="font-size: 16px;"><strong>Balance:</strong></td>
                    <td style="font-size: 16px;"><strong>Rs.</strong></td>
                    <td style="font-size: 16px; text-align:right;"><strong><?php echo number_format((float)($sellprice * $days) - $advance, 2); ?></strong></td>
                </tr>
              <?php }?>
                
            </tfoot>
        </table>

        <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.onafterprint = function() {
                
               window.location.href = '/bookinglist.php';
            };
            window.print();
            setTimeout(function() {
                window.onafterprint = null;
            }, 1000);
        };
    </script>
</body>

</html>

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