<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  @include('title')
  <!-- 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.7 -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/bootstrap/dist/css/bootstrap.min.css')}}">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/font-awesome/css/font-awesome.min.css')}}">
  <!-- Ionicons -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/Ionicons/css/ionicons.min.css')}}">
  <!-- bootstrap datepicker -->
  <link rel="stylesheet" href="{{asset('lte/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css')}}">
  <!-- Theme style -->
  <link rel="stylesheet" href="{{asset('lte/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="{{asset('lte/dist/css/skins/_all-skins.min.css')}}">

  <!-- HTML5 Shim 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/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  <style>
  * {
    box-sizing: border-box;
  }

  /* Create three equal columns that floats next to each other */
  .column {
    float: left;
    width: 15%;
    padding: 0px;
  }

  /* Clear floats after the columns */
  .row:after {
    content: "";
    display: table;
    clear: both;
  }
  
  /*.row-div {*/
  /*      float: left; */
  /*      width: 14%; */
  /*      height: 50px; */
  /*      border: 1px solid #000000;*/
  /*      padding: 10px;*/
  /*      font-size: 18px;*/
  /*  }*/
    
  table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
    height: 50px;
    text-align: left;
    padding: 8px;
  }
  
  tr:nth-child(even) {
      background-color:#69696959;
  }

  /*.row-div {
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
  }*/
  </style>
</head>
<!-- ADD THE CLASS layout-top-nav TO REMOVE THE SIDEBAR. -->
<body class="hold-transition skin-blue layout-top-nav">
<div class="wrapper">
  @include('topheader')
  
  <!-- Full Width Column -->
  <div class="content-wrapper">
    <div class="container">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          Cash Sale Orders
          <small>{{$location}}</small>
          <input type="text" placeholder="Search" id="search_key" name="search_key">
          <select name='user_id' id="user_id">
              <option value="" @if($_GET['print'] == 1) href="{{route('pos.cash.sale.orders')}}?print=1&user_id=" @else href="{{route('pos.cash.sale.orders')}}?print=0&user_id=" @endif>--select user---</option>
              @foreach($users as $user)
              <option value="{{$user->id}}" @if($_GET['print'] == 1) href="{{route('pos.cash.sale.orders')}}?print=1&user_id="  @else href="{{route('pos.cash.sale.orders')}}?print=0&user_id=" @endif @if($_GET['user_id'] == $user->id) selected @endif>{{$user->name}}</option>
              @endforeach
          </select>
        </h1>
        <ol class="breadcrumb">
        <form id="date_filter_pos">
          @if($_GET['print'] == 1)
          <a href="{{route('pos.cash.sale.orders')}}?print=0&user_id=" class="btn btn-success">Not Processed</a>
          @else
          <a href="{{route('pos.cash.sale.orders')}}?print=1&user_id=" class="btn btn-success">Processed</a>
          @endif
          <input type="text" class="form-control pull-right datepicker" name="from_date" id="from" value="{{date('d-m-Y', strtotime($date))}}" style="display: none;" onchange="document.getElementById('date_filter_pos').submit();" required="">
        </form>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">
      
      <table id="cash_orders">
          <thead>
              <tr>
                  <th style="width:10%">Order ID</th>
                  <th style="width:10%">Date</th>
                  <th style="width:30%">Additional Info</th>
                  <th style="width:30%">Mobile Number</th>
                  <th style="width:10%">User</th>
                  <th style="width:10%">Amount</th>
                  <th style="width:10%">Print</th>
                  <th style="width:10%">Status</th>
                  <th style="width:10%">Delivery Boy</th>
              </tr>
          </thead>
          <tbody>
        @foreach($list as $l)
              <tr>
                  <td>{{$l->prefix ?? ''}}{{$l->request_no}}</td>
                  <td>{{date('d-m-Y',strtotime($l->request_date))}}</td>
                  <td>{{$l->customer_name}}</td>
                  <td>{{$l->customer_mobile}}</td>
                  <td>{{$l->entered->name}}</td>
                  <td>{{$mr_product->amount($l->id)}}</td>
                  <td><button class="cprint" btn-id="{{$l->id}}" id="print" style="padding-bottom: 1px; height: 100%; width: 100%; background-color: #00a65a;">Print</button></td>
                  <td>
                      @if($l->print == 1) 
                      <i class="fa fa-print">Processed</i> 
                      @else
                      <i class="fa fa-print status{{$l->id}}">Not Processed</i>
                      @endif
                  </td>
                  <td></td>
              </tr>
        @endforeach
          </tbody>
      </table>
      <!-- /.box -->
      </section>
      <!-- /.content -->
    </div>
    <!-- /.container -->
  </div>
  <!-- /.content-wrapper -->
  @include('footertag')
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="{{asset('lte/bower_components/jquery/dist/jquery.min.js')}}"></script>
<!-- Bootstrap 3.3.7 -->
<script src="{{asset('lte/bower_components/bootstrap/dist/js/bootstrap.min.js')}}"></script>
<!-- bootstrap datepicker -->
<script src="{{asset('lte/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js')}}"></script>
<!-- SlimScroll -->
<script src="{{asset('lte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js')}}"></script>
<!-- FastClick -->
<script src="{{asset('lte/bower_components/fastclick/lib/fastclick.js')}}"></script>
<!-- AdminLTE App -->
<script src="{{asset('lte/dist/js/adminlte.min.js')}}"></script>
<!-- AdminLTE for demo purposes -->
<script src="{{asset('lte/dist/js/demo.js')}}"></script>
<script type="text/javascript">
  $('.datepicker').datepicker({
      autoclose: true,
      format: 'dd-mm-yyyy',
      orientation: "bottom"
  })
</script>  
<script>
    $(document).ready(function(){
      setTimeout(function() {
        location.reload();
      }, 30000);
      $(document).on("click",".cprint",function(){
        var url = "{{url('')}}"+"/pos/cash/sales/order/print/"+$(this).attr("btn-id");
        var mr_id = $(this).attr("btn-id");
        $.get("{{url('cash/sale/print')}}", {option: mr_id}, function(mode_data){
           $('div[div-id='+mr_id+']').remove(); 
        });
        // window.open(url);
        // '', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0'
        var winPrint = window.open(url);
         // $(this).closest('div').parent().removeClass('callout-danger');
         // $(this).closest('div').parent().addClass('callout-info');
         // $(this).closest('div').parent().find('.status'+$(this).attr("btn-id")).text('Printed');
         //$(this).closest('div').parent().remove();
        // winPrint.document.close();
        // winPrint.focus();
        // winPrint.print();
        // winPrint.close();
      });
      $(document).on("keyup","#search_key", function(){
          var value = $("#search_key").val().toLowerCase();
          //$("#user_id option:selected").text().toLowerCase();
          // alert(value);
          if("--select user---" != value) {
            $("#cash_orders tbody tr").filter(function(){
              $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
            });
          }
          
      });
      $(document).on("change","#user_id", function(){
        window.location.href = $("#user_id option:selected").attr("href")+$(this).val();
        // alert();
      }); 
    });
</script>
</body>
</html>
