<!DOCTYPE html>
<html>
<head>
  @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')}}">
  <!-- 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')}}">
  
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="{{asset('lte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.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">

  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="{{asset('lte/plugins/iCheck/all.css')}}">
  
</head>
<body class="hold-transition skin-blue fixed sidebar-mini">
<div class="wrapper">
  
  @include('headertag')
  <!-- Left side column. contains the logo and sidebar -->
  @include('leftside')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
      <h1>
          Supplier Wise PR
        </h1>
        <ol class="breadcrumb">
          <li><a href="#"><i class="fa fa-dashboard"></i>Supplier Wise PR</a></li>
          <li class="active">list</li>
        </ol>
      </section>

      <br>

      <div class="box-header with-border">
        @if(Session::has('message'))
        <div class="alert alert-success alert-dismissible">
          <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
          Product Updated...!!
        </div>
       @endif
     
      </div>

           <!-- Main content -->
      <section class="content">
        
        <!-- Main row -->
        <div class="row">
          <!-- Left col -->
          <section class="col-lg-12 connectedSortable">
            <!-- Custom tabs (Charts with tabs)-->
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">Supplier Wise PR List</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped pr_table">
                <thead>
                <tr>
                  <th>Sl No.</th>
                  <th>PR No</th>
                  <th>Supplier</th>
                  <th>PR date</th>
                  <th>Approve</th>
                  <th>Product List</th>
                  <th>ETA</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                 <?php $c = 1; ?>
                 @if($pr_lists != NULL)
                 @foreach($pr_lists as $list)
                <tr> 
                  <td>{{$c++}}</td>
                  <td>{{$list->request_no}}</td>
                  <td>{{$list->name}}</td>
                  <td>{{date('d-m-Y', strtotime($list->request_date))}}</td>
                  <td class="center">@if($list->status == 'A')<b class="apr{{$list->pid}}{{$list->id}}" style="color: #27f227;">Approved</b>@else<a class="apr{{$list->pid}}{{$list->id}}" onclick="jsApprovePr({{$list->id}},{{$list->pid}})"><i class="fa fa-fw fa-check apr" style="color: #27f227;"></i></a>@endif</td>
                  <?php $id = $list->id.'-'.$list->pid; ?>
                  <td class="center">@if($list->status != 'A')<a class="pdt{{$list->pid}}{{$list->id}}" href="{{route('supplier.wise.pr.product',$id)}}"><i class="fa fa-fw fa-list-alt"></i>PR List</a>@else<a  href="{{route('supplier.wise.product.list',[$list->id,$list->pid])}}"><i class="fa fa-fw fa-shopping-cart"></i></a> @endif</td> 
                  <td><button type="button" class="btn btn-default pr_eta" onclick="jsEtaPr({{$list->id}},{{$list->pid}})" data-toggle="modal" id="" data-target="#modal-default"><i class="fa fa-fw fa-plus" style="color: blue;"></i> </button></td> 
                  <td class="center">@if($list->status == 'C')<b class="c{{$list->pid}}{{$list->id}}" style='color:red;'>Cancelled</b>@else<a class="cnl{{$list->pid}}{{$list->id}}" onclick="jsCancelPr({{$list->id}},{{$list->pid}})"><i class="fa fa-fw fa-close" style="color: red;"></i></a>@endif</td> 
                </tr>
                @endforeach
                @endif
              </tbody>
              </table>
            </div>
          </div>
            <!-- /.nav-tabs-custom -->
            <button type="button" class="btn btn-success po" value="C" title="Add">Create PO </button>
            
            <!-- Chat box -->
            
            <!-- /.box (chat box) -->

            
            <!-- quick email widget -->
          </section>
          <!-- /.Left col -->
          
        </div>
        <!-- /.row (main row) -->

         <div class="modal fade" id="modal-default">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">ETA</h4>
              </div>
              
              <div class="modal-body">
                <div class="form-group">
                 <input type="hidden" name="sup_id" id="sup_id">
                 <input type="hidden" name="pr_id" id="pr_id"> 
               
                  <label for="inputattribute" class="col-sm-2 control-label">ETA<font color="red">*</font></label>
                   <div class="col-sm-4">
                    <input type="date" class="form-control" id="eta" name="eta" value="" placeholder="Enter" required="">
                  </div>
                </div><br><br>

              </div>
               
              <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
                 <button type="button" class="btn btn-primary add_eta" data-dismiss="modal">Add</button>
              </div>
            </div>
            <!-- /.modal-content -->
          </div>
          <!-- /.modal-dialog -->
        </div>

      </section>
      <!-- /.content -->
    </div>
  <!-- /.content-wrapper -->
  
  @include('footertag')

  <!-- Control Sidebar -->
  @include('rightside')
  <!-- /.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 3 -->
  <script src="{{asset('lte/bower_components/jquery/dist/jquery.min.js')}}"></script>
  <!-- jQuery UI 1.11.4 -->
  <script src="{{asset('lte/bower_components/jquery-ui/jquery-ui.min.js')}}"></script>
  <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
  <script>
    $.widget.bridge('uibutton', $.ui.button);
  </script>
  <!-- Bootstrap 3.3.7 -->
  <script src="{{asset('lte/bower_components/bootstrap/dist/js/bootstrap.min.js')}}"></script>
  
  <!-- Sparkline -->
  <script src="{{asset('lte/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js')}}"></script>
  
  <!-- Bootstrap WYSIHTML5 -->
  <script src="{{asset('lte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.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">
   
  $(document).on("click",".po", function() {
    var status =  $(this).val();
    $.get("{{ url('supplier/create/po')}}", 
        { option: status }, 
          function(data) {
            console.log(data);
            window.location.href = "{{url('supplier/wise/pr/index')}}";
        });  

  });

  function jsCancelPr(sup_id,p_id)
  {
    if(confirm("Do you want to Cancel this Request?") == true){
     var apr = 'apr'+ sup_id +p_id;
    $.get("{{ url('supplier/cancel/pr')}}", 
        { sup_id: sup_id, p_id :p_id }, 
          function(data) {
          window.location.href = "{{url('supplier/wise/pr/index')}}";
          $('.cnl'+p_id+sup_id).replaceWith("<b style='color:red;'>Cancelled</b>");
          $('.apr'+p_id+sup_id).replaceWith("<a class='"+apr+"' onclick='jsApprovePr("+sup_id+","+p_id+")'><i class='fa fa-fw fa-check apr' style='color: #27f227;'></i></a>");
          
        });
    }      
  }

  function jsApprovePr(sup_id,p_id)
  {
    if(confirm("Do you want to Approve this Request?") == true){
     var cnl = 'cnl'+ sup_id;
    $.get("{{ url('supplier/approve/pr')}}", 
        { sup_id: sup_id, p_id :p_id }, 
          function(data) {
          var id = sup_id;   
          var url = "{{url('')}}"+"/supplier/wise/product/list/"+sup_id+"/"+p_id; 
            
          
          $('.apr'+p_id+sup_id).replaceWith("<b style='color: #27f227;'>Approved</b>");
          $('.c'+p_id+sup_id).replaceWith("<a class='"+cnl+"' onclick='jsCancelPr("+sup_id+","+p_id+")'><i class='fa fa-fw fa-close' style='color: red;'></i></a>");
          $('.pdt'+p_id+sup_id).replaceWith("<a  href='"+url+"'><i class='fa fa-fw fa-shopping-cart'></i></a>");
         
        });
    }      
  }

  function jsEtaPr(sup_id,p_id)
  {
     $("#sup_id").val(sup_id);
     $("#pr_id").val(p_id);
     $.get("{{ url('get/supplier/pr/eta')}}", 
        { sup_id: sup_id, pr_id :p_id}, 
          function(data) {
            $('#eta').val(data.eta);
        });    
  }

  $(document).on("click",".add_eta", function() {
    var sup_id = $("#sup_id").val();
    var pr_id = $("#pr_id").val();
    var eta = $('#eta').val();
    $.get("{{ url('supplier/pr/eta')}}", 
        { sup_id: sup_id, pr_id :pr_id , eta:eta}, 
          function(data) {
        });
  });

 </script>

  <!-- iCheck 1.0.1 -->
<script src="{{asset('lte/plugins/iCheck/icheck.min.js')}}"></script>

</body>

</html>
