<?php


include 'db.php';
include 'config.php';
if (isset($_GET['tracking_number']) && $_GET['tracking_number'] != "") {
    $tracking_number = mysqli_real_escape_string($link, $_GET['tracking_number']);
    $result = mysqli_query($link, "SELECT * FROM tracking WHERE tracking_number = '$tracking_number' ");
    if (mysqli_num_rows($result) > 0) {
        // session_start();
        $row = mysqli_fetch_assoc($result);
        $current_location = mysqli_real_escape_string($link, $row['current_location']);

        $result1 = mysqli_query($link, "SELECT * FROM track_update WHERE track_num = '$tracking_number' AND current_location='$current_location' ORDER BY id DESC LIMIT 1 ");

        if (mysqli_num_rows($result1) > 0) {
            $row1 = mysqli_fetch_assoc($result1);
        }

        $ordn = "1234567890";
        $ordn = str_shuffle($ordn);
        $ordn = substr($ordn, 0, 5);

?>


        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">



        <head>


            <meta charset="utf-8">


            <!-- CSS here -->
            <link rel="stylesheet" href="css/bootstrap.min.css">
            <link rel="stylesheet" href="css/root.css?v=<?php echo uniqid(); ?>">

        </head>

        <body>


            <!-- main-area -->
            <main class="receipt">
                <div class="watermark-container">
                    <img src="uploads/<?php echo $site_logo; ?>" alt="" class="watermark-image">
                </div>
                <div class="top-section">
                    <table style="width:100%;">
                        <tbody>
                            <tr>
                                <td>
                                    <div class="logo-container">
                                        <img src="uploads/<?php echo $site_logo; ?>" alt="" class="logo">
                                    </div>
                                    <div class="address">
                                        <?php echo $address; ?>
                                    </div>
                                    <br>
                                    <h6>Invoiced to:</h6>
                                    <div><?php echo $row['receiver_name']; ?></div>
                                    <br>
                                    <h6>Address:</h6>
                                    <div> <?php echo $row['receiver_contact']; ?></div>
                                    <div><?php echo $row['receiver_email']; ?></div>
                                    <div><?php echo $row['receiver_address']; ?></div>
                                </td>
                                <td>
                                    <h4>INVOICE</h4>
                                    <div class="invoice-summary-container">
                                        <div class="box">
                                            <div class="left">Invoice #</div>
                                            <div class="right"><?php echo $ordn; ?></div>
                                        </div>
                                        <div class="box">
                                            <div class="left">Date</div>
                                            <div class="right"> <?php echo date('F d, Y'); ?></div>
                                        </div>
                                        <div class="box" style="border-bottom:none;">
                                            <div class="left">Total Charge</div>
                                            <div class="right">$<?php echo $row1['total_charge']; ?></div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </tbody>

                    </table>

                </div>


                <div>
                    <table>
                        <thead>
                            <th>Image</th>
                            <th>Description</th>
                            <th>Total Charge</th>
                            <th>Quantity</th>
                            <th>Charges</th>
                        </thead> 
                        <tbody>
                            <tr>
                                <td><img src="uploads/<?php echo $row['image']; ?>" style="width:150px;height:auto;" alt=""></td>
                                <td><?php echo $row['pdesc']; ?></td>
                                <td>$<?php echo $row1['delivery_charge']; ?></td>
                                <td><?php echo $row['quantity']; ?></td>
                                <td>$<?php echo $row1['total_charge']; ?></td>
                            </tr>
                            <tr>
                                <td colspan="2"></td>
                                <td colspan="3" class="summary">Charge: &nbsp; $<?php echo $row1['total_charge']; ?> </td>
                            </tr>
                            <tr>
                                <td colspan="2"></td>
                                <td colspan="3" class="summary total-charge">Total Charge: &nbsp; $<?php echo $row1['delivery_charge']; ?> </td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div>
                    <table>
                        <tbody>
                            <tr>
                                <td>
                                    <a class="go-back-btn" onclick="goBack()">Go Back</a>
                                </td>
                                <td style="display:flex;justify-content:flex-end">
                                    <img id="barcode" style="width:150px;">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <!-- JS here -->
                <script src="js/JsBarcode.all.min.js"></script>
                <script>
                    JsBarcode("#barcode", "<?php echo $tracking_number; ?>");
                </script>

                <script>
                    window.print();



                    function goBack() {
                        window.history.back();
                    }
                </script>

        </body>



        </html>
<?php
    }
}
?>