<?php include "common/user_log.php"; ?>

  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Sampathbay.</title>
    <!-- Place favicon.ico in the root directory -->
   <link rel="shortcut icon" type="image/x-icon" href="../img/S_favicon.ico">   
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="dist/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="dist/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
     folder instead of downloading all of them to reduce the load. -->
     <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
     <link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
     <!-- combo -->
     <style type="text/css">
      #form1 p {
      }
      #apDiv1 {
        position:absolute;
        width:200px;
        height:23px;
        z-index:1;
        left: 164px;
        top: 420px;
      }
    </style>


    <!--GET SUBCATAGORIES FROM A CATAGORY-->
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

      <header class="main-header">
        <!-- Logo -->
        <a href="home.php" class="logo">
          <!-- mini logo for sidebar mini 50x50 pixels -->
          <span class="logo-mini"><img src="img/logo_mini.png" width="50"></span>
          <!-- logo for regular state and mobile devices -->
          <span class="logo-lg"><b><img src="img/logo.png" width="200"></b></span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
          <!-- Sidebar toggle button-->
          <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="logo-lg">
             &nbsp;&nbsp;<font face="Lucida Sans Unicode, Lucida Grande, sans-serif">Sampathbay </font></span>
           </a>

           <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">

              <!-- User Account: style can be found in dropdown.less -->
              <li class="dropdown user user-menu">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <img src="dist/img/user2-160x160.png" class="user-image" alt="User Image">
                  <span class="hidden-xs"><?php echo $name; ?></span>
                </a>
                <ul class="dropdown-menu">
                  <!-- User image -->
                  <li class="user-header">
                    <img src="dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                    <p>
                     Sampathbay

                   </p>
                 </li>
                 <!-- Menu Body -->
                 
                 <!-- Menu Footer-->
                 <li class="user-footer">
                  <div class="pull-left">

                  </div>
                  <div class="pull-right">
                    <a href="distroy.php" class="btn btn-default btn-flat">Sign out</a>
                  </div>
                </li>
              </ul>
            </li>
            <!-- Control Sidebar Toggle Button -->
            <li>
              <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
            </li>
          </ul>
        </div>
      </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
      <!-- sidebar: style can be found in sidebar.less -->
      <section class="sidebar">
        <!-- Sidebar user panel -->

        <?php include "common/sidebar.php"; ?> 
        
      </section>
      <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          Rejected Orders
          <small>Preview</small>
        </h1>

        <ol class="breadcrumb">
          <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">

        <!-- ************************************************* -->








        <!-- /.table -->
        
        <div class="box box-info"> 
          <div class="box-header"> 
            <h3 class="box-title">Rejected Order Details</h3>
          </div>
          <!-- /.box-header -->
          <div class="box-body" style="overflow-x:auto"> 
            <table id="example1" class="table table-bordered table-striped" >
              <thead>
                <tr> 
                  <th>Invoice ID</th>
                  <th>Order Date</th>
                  <th>Delivery Date</th>
                  <th>Customer Name</th>
                  <th>Customer Address</th>
                  <th>Phone No</th>
                  <th>Special Instructions</th>
                  <th>Senders Information</th>
                  <th>Payment Status</th>
                  <th>Order Details</th>
                  <th>Accept / Reject</th>
                </tr>
              </thead>
              <tbody id="details_tbody">
                <?php 
                $sql = "SELECT  * FROM order_details WHERE order_status = '2'" ;
                $result=mysqli_query($conn, $sql);

                $xx=0;
                while ($row = mysqli_fetch_array($result)){ $xx=$xx+1 ?>
                  <tr id="<?php echo $row['id']; ?>">
                    <td><?php echo $row['inv_id']; ?></td>
                    <td><?php echo $row['date']; ?></td>
                    <td><?php echo $row['date_holder']; ?></td>
                    <td><?php echo $row['name']; ?></td>
                    <td><?php echo $row['address']; ?></td>
                    <td><?php echo $row['phone']; ?></td>
                    <td><?php echo $row['s_instructions']; ?></td>
                    <td><?php 
                    if ($row['s_anonymous'] == 1) {
                      echo '<span class="label label-danger">Anonymous Sender</span>';
                    }else{
                      echo $row['sender_name'].' <br>'.$row['sender_email'];
                    }
                    ?></td>

                    <td><?php 
                    if ($row['payment_status'] == 1) {
                      echo '<span class="label label-success">Paid</span><br>';
                    }else{
                      echo '<span class="label label-danger">Pending</span><br>';
                    }
                    if ($row['payment_type'] == 1) {
                      echo '<span class="label label-info">On-line</span>';
                    }elseif ($row['payment_type'] == 2){
                      echo '<span class="label label-info">Bank Deposit</span>';
                    }
                    ?></td>

                    <td><a class="btn btn-xs btn-info btn_det" row_id="<?php echo $row['id']; ?>" data-toggle="modal" data-u_id="<?php echo $row['user_id']; ?>" data-inv_id="<?php echo $row['inv_id']; ?>" data-target="#myModal">View Details</a></td>

                    <td><div><a  class="btn btn-success btn-sm btn_accept" row_id="<?php echo $row['id']; ?>"><span class="glyphicon glyphicon-ok" style="margin-right:2px;"></span>Accept</a></a> <a row_id="<?php echo $row['id']; ?>" class="btn btn-danger btn-sm btn_reject"><span class="glyphicon glyphicon-remove"></span> Reject </a></div></td>
                  </tr>
                <?php } ?>
              </tbody>
            </table>
          </div>
          <!-- /.box-body -->
        </div>

      </section>

    </div>
    <!-- /.End table -->
    <!-- ************************************************* -->

    <!-- /.col -->
  </div><!-- /.row -->
</div><!-- /.box-body -->


<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" id="test_id" style="display: inline-block;">Order Details</h4>
        <a class="btn btn-danger btn-sm float-left" style="position: absolute; right: 35px;" onclick="jQuery('#example3').print()">Print</a>
      </div>
      <div class="modal-body">
        <table id="example3" class="table table-bordered table-striped" >
          <thead>
            <tr> 
              <th width="30%">Title</th>
              <th>Details</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Order Type</td>
              <td id="order_status"></td>
            </tr>
            <tr>
              <td>Recipient's Name</td>
              <td id="rec_name"></td>
            </tr>
            <tr>
              <td>Recipient's Phone</td>
              <td id="rec_phone"></td>
            </tr>
            <tr>
              <td>Recipient's Address</td>
              <td id="rec_add"></td>
            </tr>
            <tr>
              <td>Location Type</td>
              <td id="loc_type"></td>
            </tr>
            <tr>
              <td>Land Mark</td>
              <td id="land_mark"></td>
            </tr>
            <tr>
              <td>Delivery Date</td>
              <td id="d_date"></td>
            </tr>
            <tr>
              <td>Delivery Time</td>
              <td id="d_time"></td>
            </tr>
            <tr>
              <td>Special Instructions</td>
              <td id="s_instructions"></td>
            </tr>
            <tr>
              <td>Personal Message</td>
              <td id="p_massage"></td>
            </tr>
            <tr>
              <td colspan="2">Senders Information (From)</td>
            </tr>
            <tr>
              <td>Name</td>
              <td id="sender_name"></td>
            </tr>
            <tr>
              <td>E-mail Address</td>
              <td id="sender_email"></td>
            </tr>
            <tr>
              <td>Phone Number</td>
              <td id="sender_phone"></td>
            </tr>
            <tr>
              <td>Address</td>
              <td id="sender_add"></td>
            </tr>
            <tr>
              <td>Country</td>
              <td id="sender_country"></td>
            </tr>
          </tbody>
        </table>
        <table id="example1" class="table table-bordered table-striped">
          <thead>
            <tr> 
              <th>ID</th>
              <th>Product</th>
              <th>Item Code</th>
              <th>Availability</th>
              <th>Unit Price</th>
              <th>Qty</th>
              <th>Total</th>
            </tr>
          </thead>

          <tbody id="cart_tbody">

          </tbody>
        </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
<!-- /.col (right) -->


</div>
<footer class="main-footer"> 
  <div class="pull-right hidden-xs">

  </div>  <strong>Copyright &copy; Sampathbay..</strong> All rights reserved.
</footer>

<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
  <!-- Create the tabs -->
  <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
    <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
    <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
  </ul>
  <!-- Tab panes -->
  <div class="tab-content">
    <!-- Home tab content -->
    <div class="tab-pane" id="control-sidebar-home-tab">





    </div><!-- /.tab-pane -->


  </div><!-- /.tab-pane -->
</div>
</aside><!-- /.control-sidebar -->
      <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
       <div class="control-sidebar-bg"></div>
     </div><!-- ./wrapper -->

     <!-- jQuery 2.1.4 -->
     <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
     <!-- Bootstrap 3.3.5 -->
     <script src="bootstrap/js/bootstrap.min.js"></script>
     <!-- Select2 -->
     <script src="plugins/select2/select2.full.min.js"></script>
     <!-- DataTables -->
     <script src="plugins/datatables/jquery.dataTables.min.js"></script>
     <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
     <!-- InputMask -->
     <script src="plugins/input-mask/jquery.inputmask.js"></script>
     <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
     <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
     <!-- date-range-picker -->
     <script src="plugins/daterangepicker/moment.min.js"></script>
     <script src="plugins/daterangepicker/daterangepicker.js"></script>
     <!-- bootstrap color picker -->
     <script src="plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
     <!-- bootstrap time picker -->
     <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
     <!-- SlimScroll 1.3.0 -->
     <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
     <!-- iCheck 1.0.1 -->
     <script src="plugins/iCheck/icheck.min.js"></script>
     <!-- FastClick -->
     <script src="plugins/fastclick/fastclick.min.js"></script>
     <!-- AdminLTE App -->
     <script src="dist/js/app.min.js"></script>
     <!-- AdminLTE for demo purposes -->
     <script src="dist/js/demo.js"></script>
     <script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
     <script src="input-mask/input-mask.min.js"></script>
     <!-- Page script -->

     <script>

      $(document).ready(function(){
        cart_data_load();
      });

      $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": false,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
      });

      $('.btn_accept').click(function(){
        var row_id = $(this).attr('row_id');
        $.post('function/rejectrd_fun.php', {'accept_order': 'data' , row_id : row_id}, function (e) {
          if (e.status == "ok") {
            swal({
              title: "Accepted!",
              text: "Successfully added record to the database!",
              type: "success",
              confirmButtonText: "OK"
            },
            function (isConfirm) {
              cart_data_load();
              
            });
          //cart_data_load();
        }else{
          swal("Oops...", "Something went wrong!", "warning");
        }
      }, "json");
      });

      $('.btn_reject').click(function(){
        var row_id = $(this).attr('row_id');
        swal({
          title: "Authentication Required!",
          text: "Enter Administrator Password:",
          type: "input",
          inputType: "password",
          showCancelButton: true,
          closeOnConfirm: false,
          inputPlaceholder: "Password......"
        }, function (inputValue) {

          if (inputValue === false) return false;

          if (inputValue != "") {
          //alert(inputValue);
          $.post('function/cart_details_fun.php', {'select_pwd': 'data' , pwd : inputValue}, function (e){

            //alert(e.status);
            if(e.status == 'ok'){
              swal({
                title: "Are you sure?",
                text: "Your may not be able to recover!",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                confirmButtonText: "Yes, Reject it!",
                closeOnConfirm: false
              },
              function () {
                $.post('function/cart_details_fun.php', {'reject_order': 'data' , row_id : row_id}, function (e) {
                  if (e.status == "ok") {
                    swal({
                      title: "Rejected!",
                      text: "Successfully Rejected Order!",
                      type: "success",
                      confirmButtonText: "OK"
                    },
                    function (isConfirm) {
                      cart_data_load();

                    });
                  }else{
                    swal("Oops...", "Something went wrong!", "warning");
                  }
                }, "json");
              }
              );
            }else{
              swal("Unauthorized Access", "Your username and password don't match. try again", "warning");
            }
          }, "json");
        }

        if (inputValue === "") {
          swal.showInputError("You need to write something!");
          return false
        }
        //swal("Nice!", "You wrote: " + inputValue, "success");
      });

      });

      function cart_data_load(u_id,inv_id) {

        var u_id = u_id;
        var inv_id = inv_id;
        var tableData = '';

        $.post('function/admin_cart_fun.php', {'cart_details_load': 'data' , u_id : u_id , inv_id : inv_id}, function (e) {

          console.log(e);

          if (e === undefined || e.length === 0 || e === null) {
            tableData = '<tr><td colspan="7" > <h4>No Items In Your Cart</h4> </td></tr>';
            $('#cart_tbody').html('').append(tableData);
          } else {
            var x=1;
            $.each(e, function (index, data) {
              tableData += '<tr id="'+data.id+'">';
              tableData += '<td>'+ x++ +'</td>';

              tableData += '<td>'+data.Item+'</td>';

              tableData += '<td>'+ data.Item_Code+'</td>';

              tableData += '<td class="cart_avail"><span class="label label-success">In stock</span></td>';

              tableData += '<td style = "text-align:right">'+ data.price+'</td>';

              tableData += '<td style = "text-align:center">'+ data.Qty+'</td>';

              tableData += '<td style = "text-align:right">'+ data.Qty*data.price +'.00</td>';

              tableData += '</tr>';

              $('#cart_tbody').html('').append(tableData);
            });

          }
        }, "json");
      }
      $('.btn_det').click(function(){

        var row_id = $(this).attr('row_id');
        var u_id = $(this).attr("data-u_id");
        var inv_id = $(this).attr("data-inv_id");

        cart_data_load(u_id,inv_id);

        $.post( "function/cart_details_fun.php", {'cart_details_load': "data", id : row_id}, function( e ) {

          $.each(e, function (index, data) {
            if (data.gift_type==1) {
              $("#order_status").text('This is a Gift');
            }else{
              $("#order_status").text('This is for my self');
            }

            $("#rec_name").text(data.title_recip+' '+data.name);
            $("#rec_phone").text(data.phone);
            $("#rec_add").text(data.address);
            $("#loc_type").text(data.type);
            $("#land_mark").text(data.land_mark);
            $("#d_date").text(data.date_holder);

            if (data.delivery_type==1) {
              $("#d_time").text('Within The Day (Between 9 am to 5 pm) ');
            }else if (data.delivery_type==2){
              $("#d_time").text('Early Morning Delivery (6am - 9am)');
            }else if (data.delivery_type==3){
              $("#d_time").text('Morning Delivery (9am - 12pm)');
            }else if (data.delivery_type==4){
              $("#d_time").text('Afternoon Delivery (12pm - 6pm)');
            }else if (data.delivery_type==5){
              $("#d_time").text('Late Evening Delivery (6pm - 9pm)');
            }else if (data.delivery_type==6){
              $("#d_time").text('Midnight Delivery (9pm - 12am)');
            }

            $("#s_instructions").text(data.s_instructions);
            $("#p_massage").text(data.msg);
            $("#sender_name").text(data.title_sender+" "+data.sender_name);
            $("#sender_email").text(data.sender_email);
            $("#sender_phone").text(data.sender_tp);
            $("#sender_add").text(data.sender_address);
            $("#sender_country").text(data.country);
          });

        }, "json");

      });
    </script>
  </body>
  </html>
