<?php 
  if( !hasPermission($_SESSION['user_detail']['role_id'], 'lr_list') ) {
    echo '<script>window.location.href="index.php?page=no_permission.php"</script>';
    die();
  }
?> 
<section class="content-header">
  <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
        <h3 class="capital font15 padding5 bold">VIEW LR DETAILS</h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
        <h3>
          <?php if( hasPermission($_SESSION['user_detail']['role_id'], 'lr_add') ) { ?>
          <a href="index.php?page=lr/add.php" class="btn btn-danger capital bottom10 custome-btn">Add New LR</a>
        <?php } ?>
        </h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="hitz-top-header">
  <div class="card bottom40">
    <div class="card-body table-responsive">
      <table id="example1" class="table table-bordered table-striped list_data width100">
        <thead>
          <tr>
            <th width="10">SR.NO</th>
            <th width="50">LR NO</th>
            <th width="50">DATE</th>
            <th width="70">TRUCK NO</th>
            <th width="60">FROM</th>
            <th width="60">TO</th>
            <th width="150">CONSIGNOR</th>
            <th width="150">CONSIGNEE</th>
            <th width="130">AGENT</th>
            <th width="50">WEIGHT</th>
            <th width="50">FRIGHT</th>
            <th width="90">CREATED BY</th>
            <th width="290">ACTION</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td colspan="13" class="text-center"><?php echo "NO RECORD FOUND"; ?></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</section>
<script type="text/javascript">
    jQuery(document).ready(function() {
      loadDataTable();
    });

    
    function loadDataTable(){
        if(typeof dTable!='undefined'){dTable.fnDestroy();}
    
        dTable=jQuery('.list_data').dataTable({
            "bProcessing"       : true,
            "order"             : [ [1, 'desc'] ],
            "aLengthMenu"       : [ [5, 10, 15, 20, 25, 50, 100], [5, 10, 15, 20, 25, 50, 100] ],
            'iDisplayLength'    : 50,
            "aoColumns"         : [
                {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"} , {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"sClass": "text-center"}, {"bSortable": false, "sClass": "text-center"}
            ],
            "bServerSide"       : true,
            "sAjaxSource"       : 'lr/fetch.php',
        });
    }
    
    function confirmDelete(e) {
      var $i = $(e).attr("id");
      console.log($i);
      swal({
          title: "Are you sure?",
          text: "You will not be able to recover this imaginary file!",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "Yes, delete it!",
          closeOnConfirm: false
      }, function (isConfirm) {
          if (!isConfirm) return;
          $.ajax({
              url: "lr/delete.php",
              type: "POST",
              data: 'delete='+$i,
              dataType: "json",
              success: function () {
                swal({title: "Deleted!", text: "Data successfully Deleted!", type: "success"},
                  function(){ 
                    location.reload();
                  }
                );
              },

              error: function (xhr, ajaxOptions, thrownError) {
                swal("Error deleting!", "Please try again", "error");
              }
          });
      });
    } 

    function CancleFlag(e) {
      var $i = $(e).attr("id");
      swal({
          title: "Are you sure?",
          text: "You will not be able to recover this imaginary file!",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "Yes, Cancel it!",
          closeOnConfirm: false
      }, function (isConfirm) {
          if (!isConfirm) return;
          $.ajax({
              url: "lr/cancel_flag.php",
              type: "POST",
              data: 'delete='+$i,
              dataType: "json",
              Error: function () {
                swal("Error canceling!", "Please try again", "error");
              },

              success: function (xhr, ajaxOptions, thrownError) {
                swal({title: "Canceled!", text: "Data successfully Canceled!", type: "success"},
                  function(){ 
                    location.reload();
                  }
                );
              }
          });
      });
    }

    function viewData(e) {
      var $i = $(e).attr("id");
      $.ajax({  
        url:"lr/view.php",  
        method:"post",  
        data:{lr_no:$i},  
        success:function(data){  
          $('#employee_detail').html(data);  
          $('#dataModal').modal("show");  
        }  
      });
    }
    
    function LrPrint(e){
  var $i = $(e).attr("id");
  $.ajax({  
    url:"lr/print_modal.php",  
    method:"post",  
    data:{id:$i},  
    success:function(data){  
      jQuery('#bill_print').html(data);  
      jQuery('#bill_print_model').modal("show");  
    }  
  });
}
    function LrPrint_ins(e){
  var $i = $(e).attr("id");
  $.ajax({  
    url:"lr/print_modal_ins.php",  
    method:"post",  
    data:{id:$i},  
    success:function(data){  
      jQuery('#bill_print').html(data);  
      jQuery('#bill_print_model').modal("show");  
    }  
  });
}
  </script>
