<?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>
            Delivered 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">Delivered Order Details</h3>
      </div>
      <!-- /.box-header -->
      <div class="box-body"> 
        <table id="example2" class="table table-bordered table-striped">
          <thead>
            <tr>
              <th>Invoice ID</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>View Cart</th>
              <th>Accept</th>
            </tr>
          </thead>
          <tbody id="details_tbody">
            
          </tbody>
        </table>
        <script type="text/javascript">
          function cart_data_load() {//get values which comes from view
            var tableData;

            $.post('function/delivered_fun.php', {'cart_details_load': 'data'}, function (e) {
            if (e === undefined || e.length === 0 || e === null) {//check values which comes from model
                tableData = '<tr><td colspan="7" > <h4>No Items In Your Cart</h4> </td></tr>';
                $('#cart_tbody').html('').append(tableData);//data append to data table each coloums
            } else {
                var x=1;
                $.each(e, function (index, data) {
                    tableData += '<tr id="'+data.id+'">';
                    // tableData += '<td>' + data.did + '</td>';
                    //tableData += '<td>' + data.dealer_id + '</td>';
                    tableData += '<td>'+ data.inv_id +'</td>';

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

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

                    tableData += '<td>'+ data.address +' , '+ data.city +'</td>';

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

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

                    if (data.s_anonymous === '1') {
                      tableData += '<td class="cart_avail"><span class="label label-danger">Anonymous Sender</span></td>';
                    }else{
                      tableData += '<td class="cart_avail">'+data.s_name+' <br>'+data.s_email+'</span></td>';
                    }

                    if (data.payment_status === '1') {
                      tableData += '<td class="cart_avail"><span class="label label-success">Payed</span></td>';
                    }else{
                      tableData += '<td class="cart_avail"><span class="label label-danger">Pending</span></td>';
                    }

                    tableData += '<td><a href="cart.php?u_id='+data.user_id+'&inv_id='+data.inv_id+'"><u>View Cart</u></a></td>';

                    tableData += '<td><div><a  class="btn btn-success btn-sm btn_finish" row_id="'+data.id+'" data-toggle="modal" data-target="#myModal3" ><span class="glyphicon glyphicon-check" style="margin-right:2px;"></span>Finish</a> <a row_id="'+data.id+'" class="btn btn-danger btn-sm btn_reject"><span class="glyphicon glyphicon-remove"></span> Reject </a></div></td>';

                    tableData += '</tr>';

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

                $('.btn_accept').click(function(){
                  var row_id = $(this).attr('row_id');
                  $.post('function/delivered_fun.php', {'deliver_order': 'data' , row_id : row_id}, function (e) {
                    if (e.status == "ok") {
                      swal({
                        title: "Delivered!",
                        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_finish').click(function(){
                  $('#id_holder').val($(this).attr('row_id'));
                  //alert();
                });

                /*$('.btn_reject').click(function(){
                  var row_id = $(this).attr('row_id');
                  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/accepted_fun.php', {'reject_order': 'data' , row_id : row_id}, function (e) {
                      if (e.status == "ok") {
                        swal({
                          title: "Accepted!",
                          text: "Successfully Accepted Order!",
                          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");
                  });
                  
                });
                
            }
            }, "json");
          }
        </script>
      </div>
      <!-- /.box-body -->
    </div>
    
    </section>
    
      </div>
	      <!-- /.End table -->
<!-- ************************************************* -->
      
           <!-- /.col -->
              </div><!-- /.row -->
            </div><!-- /.box-body -->
            
          

          <div class="row">
            
    
    
      </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 -->



    <!-- Modal -->
  <!-- <div class="modal fade" id="myModal3" role="dialog">
    <div class="modal-dialog">
    
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Customer</h4>
        </div>
        <div class="modal-body">
          <form action="javascript:void(0);" method="post" id="form_finish">
              <div class="form-group">
                <input type="radio" name="reasons" value="a" checked> Accepted
              </div>
              <div class="form-group">
                <input type="radio" name="reasons" value="b"> Rejected
              </div>
              <div class="form-group">
                <input type="radio" name="reasons" value="c"> Not Reachable
              </div>
              <div class="form-group" style="display: none;">
                <input type="text" id="id_holder" autocomplete="off" class="form-control" name="id_r" placeholder="Enter..." required>
              </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-success btn-sm float-right "><i class="fa fa-check"></i> Finish </button>
        </form>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div> -->


    <!-- Modal -->
    <div id="myModal3" class="modal fade" 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">Modal Header</h4>
          </div>
          <div class="modal-body">
            <form action="javascript:void(0);" method="post" id="form_finish">
              <div class="form-group">
                <input type="radio" name="reasons" value="4" checked> Accepted
              </div>
              <div class="form-group">
                <input type="radio" name="reasons" value="6"> Rejected
              </div>
              <div class="form-group">
                <input type="radio" name="reasons" value="5"> Not Reachable
              </div>
              <div class="form-group" style="display: none;">
                <input type="text" id="id_holder" autocomplete="off" class="form-control" name="id_r" placeholder="Enter..." required>
              </div>
              <button type="submit" class="btn btn-success btn-sm float-right"><i class="fa fa-check"></i> Finish </button>
            </form>
          </div>
        </div>

      </div>
    </div>



    <!-- 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();

          var validate_both = true;
            $("#form_finish").on('submit',(function(e) {

              if (validate_both) {
                /*for (instance in CKEDITOR.instances) {
                    CKEDITOR.instances[instance].updateElement();
                }*/ //$("#loading").fadeIn();
                e.preventDefault();
                $.ajax({
                url: "function/delivered_fun.php",
                type: "POST",
                data:  new FormData(this),
                contentType: false,
                    cache: false,
                processData:false,
                beforeSend : function()
                {
                  //$("#preview").fadeOut();
                  //$("#err").fadeOut();
                },
                success: function(data)
                  {
                  if(data.status != 'err')
                  {
                    $("#loading").fadeOut();
                    swal({
                      title: "Added!",
                      text: "Successfully Added!",
                      type: "success",
                      confirmButtonText: "OK"
                        },
                        function (isConfirm) {
                      if (isConfirm) {
                          window.location.href = "delivered.php";
                      }
                    });
                  }
                  else
                  {
                    swal("Oops...", "Something went wrong!", "warning");
                  }
                  
                  },
                  error: function(e) 
                  {
                    alert("err2");
                  }
               });
              }
            //alert("Done");
            }));


      });

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