<?php
 session_start();
 require_once('../connect.php');

if (isset($_POST['btn_action'])) {
    if ($_POST['btn_action'] == 'pending_search') {
        $ordernumber = $_POST['pending'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '0'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '0'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#modalnewnew'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="modalnewnew'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Choose Action</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0"></div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="status_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#status_small_new'.$row_order_new['id'].'" class="btn btn-primary btn-lg btn-block">Status</button>
                              </div>
                              <div class="col-6">
                                <button type="button" id="order_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'" id="view_order_btn_new'.$row_order_new['id'].'" class="btn btn-info btn-lg btn-block">View Order</button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div class="modal" id="status_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Change Status</h5>
                          </div>
                          <form style="margin: 0px;" method="POST" id="myform">
                          <input type="hidden" name="id" value="'.$row_order_new['id'].'">
                          <div class="modal-body pt-2 pb-0">
                            <div class="form-group">
                              <select class="form-control" name="status" id="status" required>
                                <option disabled selected>Select Status</option>
                                <option ';
                                if ($row_order_new['order_status'] == 0) { echo 'selected'; }
                           echo' value="0">Pending</option>
                                <option value="1">Review</option>
                                <option value="2">Accept</option>
                                <option value="5">Cancel</option>
                              </select>
                            </div>
                          </div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="close_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                              </div>
                              <div class="col-6">
                                <button type="submit" name="save" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                              </div>
                            </div>
                          </div>
                          </form>
                        </div>
                      </div>
                    </div>   

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

                    echo "<script type='text/javascript'>
                            $(document).ready(function(){
                              $('#status_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#order_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#close_order_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });

                              $('#close_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });
                            });
                          </script>";
          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No Pending Order.</h6>
                    </div>
                  </center>';
        }
    } 


    if ($_POST['btn_action'] == 'review_search') {
        $ordernumber = $_POST['review'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '1'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '1'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#modalnewnew'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="modalnewnew'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Choose Action</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0"></div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="status_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#status_small_new'.$row_order_new['id'].'" class="btn btn-primary btn-lg btn-block">Status</button>
                              </div>
                              <div class="col-6">
                                <button type="button" id="order_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'" id="view_order_btn_new'.$row_order_new['id'].'" class="btn btn-info btn-lg btn-block">View Order</button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div class="modal" id="status_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Change Status</h5>
                          </div>
                          <form style="margin: 0px;" method="POST" id="myform">
                          <input type="hidden" name="id" value="'.$row_order_new['id'].'">
                          <div class="modal-body pt-2 pb-0">
                            <div class="form-group">
                              <select class="form-control" name="status" id="status" required>
                                <option disabled selected>Select Status</option>
                                <option ';
                                if ($row_order_new['order_status'] == 1) { echo 'selected'; }
                           echo' value="1">Review</option>
                                <option value="2">Accept</option>
                                <option value="5">Cancel</option>
                              </select>
                            </div>
                          </div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="close_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                              </div>
                              <div class="col-6">
                                <button type="submit" name="save" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                              </div>
                            </div>
                          </div>
                          </form>
                        </div>
                      </div>
                    </div>   

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

                    echo "<script type='text/javascript'>
                            $(document).ready(function(){
                              $('#status_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#order_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#close_order_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });

                              $('#close_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });
                            });
                          </script>";
          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No Review Order.</h6>
                    </div>
                  </center>';
        }
    }   

    if ($_POST['btn_action'] == 'toship_search') {
        $ordernumber = $_POST['accept'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '2'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '2'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#modalnewnew'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="modalnewnew'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Choose Action</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0"></div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="status_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#status_small_new'.$row_order_new['id'].'" class="btn btn-primary btn-lg btn-block">Released</button>
                              </div>
                              <div class="col-6">
                                <button type="button" id="order_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'" id="view_order_btn_new'.$row_order_new['id'].'" class="btn btn-info btn-lg btn-block">View Order</button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div class="modal" id="status_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Mark Released</h5>
                          </div>
                          <form style="margin: 0px;" method="POST" id="myform">
                          <input type="hidden" name="id" value="'.$row_order_new['id'].'">
                          <div class="modal-body pt-2 pb-0">
                            <p class="text-muted">Are you sure you want to mark released?</p>
                            <input type="hidden" name="status" value="3"/>
                          </div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="close_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                              </div>
                              <div class="col-6">
                                <button type="submit" name="save" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                              </div>
                            </div>
                          </div>
                          </form>
                        </div>
                      </div>
                    </div>   

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

                    echo "<script type='text/javascript'>
                            $(document).ready(function(){
                              $('#status_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#order_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#close_order_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });

                              $('#close_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });
                            });
                          </script>";
          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No To Ship Order.</h6>
                    </div>
                  </center>';
        }
    }

    if ($_POST['btn_action'] == 'deliver_search') {
        $ordernumber = $_POST['deliver'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '3'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '3'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#modalnewnew'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="modalnewnew'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Choose Action</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0"></div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="status_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#status_small_new'.$row_order_new['id'].'" class="btn btn-primary btn-lg btn-block">Complete</button>
                              </div>
                              <div class="col-6">
                                <button type="button" id="order_btn_new'.$row_order_new['id'].'" data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'" id="view_order_btn_new'.$row_order_new['id'].'" class="btn btn-info btn-lg btn-block">View Order</button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div class="modal" id="status_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Mark Complete</h5>
                          </div>
                          <form style="margin: 0px;" method="POST" id="myform">
                          <input type="hidden" name="id" value="'.$row_order_new['id'].'">
                          <div class="modal-body pt-2 pb-0">
                            <p class="text-muted">Are you sure you want to mark compelete?</p>
                            <input type="hidden" name="status" value="4"/>
                          </div>
                          <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                            <div class="row">
                              <div class="col-6">
                                <button type="button" id="close_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                              </div>
                              <div class="col-6">
                                <button type="submit" name="save" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                              </div>
                            </div>
                          </div>
                          </form>
                        </div>
                      </div>
                    </div>   

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

                    echo "<script type='text/javascript'>
                            $(document).ready(function(){
                              $('#status_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#order_btn_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('hide');
                              });

                              $('#close_order_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });

                              $('#close_new".$row_order_new['id']."').click(function() {
                                $('#modalnewnew".$row_order_new['id']."').modal('show');
                              });
                            });
                          </script>";
          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No To Deliver Order.</h6>
                    </div>
                  </center>';
        }
    }

    if ($_POST['btn_action'] == 'complete_search') {
        $ordernumber = $_POST['complete'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '4'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '4'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No Complete Order.</h6>
                    </div>
                  </center>';
        }
    }

    if ($_POST['btn_action'] == 'canceled_search') {
        $ordernumber = $_POST['canceled'];

        if ($ordernumber == '') {
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_status = '5'";
        }else{
            $sql_order = "SELECT * FROM tbl_user_checkout WHERE order_number LIKE '%$ordernumber%' AND order_status = '5'";
        }
        $result_order = $conn->query($sql_order);
        if ($result_order->num_rows > 0) {
          while($row_order_new = mysqli_fetch_array($result_order)) {
              $ordernumber = $row_order_new['order_number'];
                echo '<a data-toggle="modal" data-target="#order_small_new'.$row_order_new['id'].'">
                        <div class="txn-history font-weight-bold">
                          <p class="txn-list">
                            <span class="text-white">Order ID: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_order_new['order_number'].'</span><br>
                            <span class="text-white">Customer: </span><span class="transaction-amount">'.$row_order_new['completename'].'</span><br>
                            <span class="text-white">Mobile Number: </span><span class="transaction-amount">'.$row_order_new['contactnumber'].'</span><br>
                            <span class="text-white">Address: </span><span class="transaction-amount">'.$row_order_new['complete_address'].'</span><br>
                          </p>
                        </div>
                      </a>

                    <div class="modal" id="order_small_new'.$row_order_new['id'].'">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Order Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div style="display: flex; justify-content: space-between;">
                              <span class="text-white">Total:</span>
                              <span class="text-white" style="font-size: 20px; font-weight: bolder;">&#8369; '.number_format(($row_order_new['order_total'])).'.00</span>
                            </div>';
                            $sql_cart = "SELECT * FROM tbl_user_checkout_details WHERE order_number = '$ordernumber'";
                                $result_cart = $conn->query($sql_cart);
                                  while($row_cart = mysqli_fetch_array($result_cart)) {
                                  $product_id = $row_cart['product_id'];
                                    $sql_product_details = "SELECT * FROM tbl_product WHERE product_id = '$product_id'";
                                    $result_product_details = mysqli_query($conn, $sql_product_details);
                                    $row_product_details = mysqli_fetch_assoc($result_product_details);
                              echo '<div class="txn-history">
                                      <p class="txn-list">
                                        <span class="text-white">QTY: <b>'.$row_cart['quantity'].'x</b></span>
                                        <span class="transaction-amount"><span class="text-white">Item: <b>'.$row_product_details['product_name'].'</span>
                                      </p>
                                    </div>';
                                    }
                   echo' </div>
                          <div class="modal-footer" style="border: 0px">
                            <button type="button" id="close_order_new'.$row_order_new['id'].'" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>';

          }
        }else{
            echo '<center>
                    <div class="text-center error-content p-3">
                        <i class="fas fa-box-open text-warning" style="margin-top: 100px; margin-bottom: 10px; font-size: 80px;"></i>
                        <h6 class="font-weight-bold text-white"> No Complete Order.</h6>
                    </div>
                  </center>';
        }
    }


    if ($_POST['btn_action'] == 'code_search') {
        $code = $_POST['code'];
        if ($code == '') {
          $sql_code = "SELECT * FROM tbl_verification_code WHERE status = '0'";
        }else{
          $sql_code = "SELECT * FROM tbl_verification_code WHERE verification_code LIKE '%$code%' AND status = '0'";
        }

        $result_code = $conn->query($sql_code);
        if ($result_code->num_rows > 0) {
          while($row_code = mysqli_fetch_array($result_code)) {
          echo '<a id="copyToClipboardSmall'.$row_code['id'].'">
                <input type="hidden" id="code_small'.$row_code['id'].'" value="'.$row_code['verification_code'].'">
                  <div class="txn-history ml-2 mr-2">
                    <p class="txn-list">
                      <span class="text-white">Activation Code: </span><span class="transaction-amount" style="color: #ffd700;">'.$row_code['verification_code'].'</span>
                    </p>
                  </div>
                </a>';
          echo "<script type='text/javascript'>
                  $(document).ready(function () {
                    $('#copyToClipboardSmall".$row_code['id']."').click(function() {
                      var textBox = $('#code_small".$row_code['id']."').val();
                      navigator.clipboard.writeText(textBox);
                      $('#alert_show_small').html('COPIED');
                    });
                  });
                </script>";
        } }else{
          echo '<center>
                    <div class="text-center error-content p-3">
                      <i class="fas fa-box-open text-warning" style="margin-top: 30px; margin-bottom: 10px; font-size: 80px;"></i>
                      <h6 class="font-weight-bold text-white"> No Cancel Order.</h6>
                      <br><br>
                  </div>
                </center>';
        }
    }

echo "<script type='text/javascript'>
        $(function () {
          $('.withanimation_submit').click(function() {
              $('.loading').show();
          });
        });
      </script>";

}

?>