<?php
include("config.php");
if (!loggedin()) {
header("Location: login.php");
exit();
}
?>
<!DOCtype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="Emcan">
        <link rel="shortcut icon" href="assets/images/favicon_1.ico">
        <title> Order Details   </title>
        <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/core.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/components.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/pages.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/responsive.css" rel="stylesheet" type="text/css" />
        <link href="assets/css/custom.css" rel="stylesheet" type="text/css" />
        <!-- HTML5 Shiv and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
        <script src="assets/js/modernizr.min.js"></script>
    </head>
    <style>
        body,html{
            background-color:#FFFFFF;
            direction:ltr;
            text-align:left;
        }
        .content-page {
            margin-top:5px !important;
        }
        .content-page > .content {
            padding: 0px !important;
            margin:0 !important;
        }
        .rightCon {
            display: block;
            float: right;
        }
        .rightCon > h3 {
            display: block;
            font-family: tahoma;
            font-size: 15px;
            font-weight: bold;
            line-height: 16px;
            text-align: right;
        }
        .leftCon {
            display: block;
            text-align: left;
            direction:ltr;
        }
        .leftCon > h3 {
            display: block;
            font-family: tahoma;
            font-size: 15px;
            font-weight: bold;
            line-height: 16px;
            text-align: left;
        }
        h1 {
            color: red;
            display: block;
            font-family: tahoma;
            font-size: 25px;
            font-weight: bold;
            line-height: 46px;
            margin: 30px 0;
            text-align: center;
        }
        h2 {
            font-family: tahoma;
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 30px;
            margin-top: -30px;
            text-align: center;
        }
        table {
            width: 100%;
            text-align:right;
        }
        table,
        th,
        td {
            border: 1px solid black;
            border-collapse: collapse;
            text-align:right;
        }
        th, td {
            border-right: medium none;
            padding: 10px 5px;
            text-align: right;
        }
        button {
            display: block;
            font-size: 20px;
            height: 70px;
            margin: auto;
            text-align: center;
            width: 150px;
            position:absolute;
            bottom:0;
            left:50%;
        }
    </style>
</head>
<body>
    <div class="content-page" style="margin-right:15px;">

        <!--<button id="btnPrint" type="button" class="btn btn-default btnPrint"> Print Details </button>-->

        <!-- Start content -->
        <div class="content" id="printThis">

            <?php
            $order_id = $_GET['order_id'];
            $query_select = $con->query("SELECT * FROM `orders` WHERE `order_id`='" . $order_id . "' ORDER BY `order_id` DESC");
            $row_select = mysqli_fetch_array($query_select);


            $cart_id = $row_select['cart_id'];
            $order_id = $row_select['order_id'];
            $client_id = $row_select['client_id'];
            $client_address_id = $row_select['client_address_id'];
            $charge_cost = $row_select['charge_cost'];
            $deliver_id = $row_select['deliver_id'];
            $payment = $row_select['payment'];
            $vat = $row_select['vat_added'];
            $get_client_address = get_client_address($client_address_id);


            $charge_cost = $row_select['charge_cost'];
            $net_price = $row_select['net_price'];
            $discount_percentage = $row_select['discount_percentage'];
            $country_id = $get_client_address['country_id'];
            $searchComma = ',';

            $cart_id = explode(",", $cart_id);
            $result = count($cart_id);
            $index = 1;
            ?>
            <div class="getOrder">
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>Image </th>
                            <th>Product Name </th>
                            <th>Price </th>
                            <th>Quantity</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        foreach ($cart_id as $one) {
                        $query_select = $con->query("SELECT * FROM `cart` WHERE `cart_id`=$one  ORDER BY `cart_id` LIMIT 1");
                        $row_select = mysqli_fetch_array($query_select);
                        $sub_category_id = $row_select['sub_category_id'];
                        $note = $row_select['note'];
                        $size_id = $row_select['size_id'];
                        $additions_id = $row_select['addition_id'];
                        $quantity = number_format($row_select['quantity'], 2, '.', ' ');

                        $price = number_format($row_select['price'], $curr_decimal, '.', ' ');
                        $removes_id = $row_select['remove_id'];

                        $query_select_two = $con->query("SELECT * FROM `sub_categories` WHERE `sub_category_id`='" . $sub_category_id . "' ORDER BY `sub_category_id` DESC");
                        $row_select_two = mysqli_fetch_assoc($query_select_two);
                        $sub_category_name = $row_select_two['sub_category_name'];
                        $sub_category_image = $row_select_two['sub_category_image'];

                        $query_select_three = $con->query("SELECT * FROM `sub_categories_size_prices` WHERE `sub_category_size_price_id`='" . $size_id . "' ORDER BY `sub_category_size_price_id` DESC");
                        $row_select_three = mysqli_fetch_assoc($query_select_three);
                        $sub_category_size_name = $row_select_three['sub_category_size_name'];
                        $sub_category_size_price = number_format($row_select_three['sub_category_size_price'], $curr_decimal, '.', ' ');
                        
                        ?>

                        <tr>
                            <td><div  class="gal-detail thumb getImage" style="float:none !important;">
                                    <img style="text-align: center;
                                         width: 50px!important;
                                         height: 50px!important;float:none !important;
                                         margin: auto;" src="<?php echo $sub_category_image; ?>" class="thumb-img" alt="">
                                </div>
                            <td><?php echo $sub_category_name; ?></td>

                            </td>
                            <td style="direction:ltr;"><?php echo number_format((float) ($sub_category_size_price), 3, '.', ''); ?> BD</td>
                            <td><?php echo $quantity; ?></td>
                            <td style="direction:ltr;"><?php echo number_format((float) ($total_price), 3, '.', ''); ?> BD</td>
                        </tr>		
                        <?php
                        $index++;
                        }
                        ?>
                    </tbody>
                </table>
            </div>
            <div class="getAddress">
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>Order Id </th>
                            <th>Client Name </th>
                            <th>Client Phone </th>
                            <th>Region Name</th>
                            <th>Block</th>
                            <th>Road</th>
                            <th>Building</th>
                            <th>Flat</th>
                            <th>Notes</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php echo $order_id; ?></td>
                            <td><?php echo get_client_name_by_id($client_id); ?></td>
                            <td><?php echo get_client_phone_by_id($client_id); ?></td>
                            <td><?php echo get_region($get_client_address['region'])['region_name_en']; ?></td>
                            <td><?php echo $get_client_address['block']; ?></td>
                            <td><?php echo $get_client_address['road']; ?></td>
                            <td><?php echo $get_client_address['building']; ?></td>
                            <td><?php echo $get_client_address['flat_number']; ?> </td>
                            <td><?php echo $get_client_address['note']; ?> </td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div>
                <table class="table table-striped ">
                    <thead>
                        <tr>
                            <th>Price Before Discount  </th>
                            <th> Discount Percentage</th>
                            <th>Price After Discount  </th>
                            <th>Charge Cost </th>
                            <th> Vat </th>
                            <th>Payment Method</th>
                            <th>Total</th>
                            <th style="text-align:center;">Deliver Method  </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td style="text-align:center;"><?php echo number_format((float) (totalPrice($order_id)), 3, '.', ''); ?> BD</td>
                            <td style="direction:ltr;"><?php echo $discount_percentage; ?> %</td>
                            <td style="direction:ltr;"><?php echo number_format((float) ( $net_price - $charge_cost - $vat), 3, '.', ''); ?> BD</td>
                            <td style="direction:ltr;"><?php echo number_format((float) ($charge_cost), 3, '.', ''); ?> BD</td>
                            <td style="direction:ltr;"><?php echo number_format((float) ($vat), 3, '.', ''); ?> BD</td>

                            <td style="text-align:center;"><?php
                                if ($payment == "cash") {
                                    echo "Cash";
                                } elseif ($payment == "credit") {
                                    echo "Online-Credit";
                                } elseif ($payment == "debit") {
                                    echo "Online-Deibt";
                                }
                                ?> </td>
                            <td style="direction:ltr;"><?php echo number_format((float) ($net_price), 3, '.', ''); ?> BD</td>
                            <td style="text-align:center;"><?php echo get_deliver_name($deliver_id); ?> </td>
                        </tr>				
                    </tbody>
                </table>
            </div>


        </div>
    </div>	
    <script src="assets/js/jquery.min.js"></script>
    <script>


        document.getElementById("btnPrint").onclick = function () {
            printElement(document.getElementById("printThis"));
        }

        function printElement(elem) {
            var domClone = elem.cloneNode(true);
            var $printSection = document.getElementById("printSection");
            if (!$printSection) {
                var $printSection = document.createElement("div");
                $printSection.id = "printSection";
                document.body.appendChild($printSection);
            }

            $printSection.innerHTML = "";
            $printSection.appendChild(domClone);
            window.print();
        }


    </script>

    <style type="text/css" >

        @media screen {
            #printSection {
                display: none;
            }
        }

        @media print {

            body{
                width: 21cm;
                height: 29.7cm;
                margin: 30mm 45mm 30mm 45mm; 
                /* change the margins as you want them to be. */
            } 

            body * {
                visibility:hidden;
            }

            #printSection, #printSection * {
                visibility:visible;
            }

            #btnPrint {
                display :  none;
            }

            #closeButton {
                display :  none;
            }

            #printSection {
                position:absolute;
                left:0;
                top:0;
                width:100%;
                height:100%;
            }
        }




    </style>


</body>
</html>