<?php $__env->startSection('title'); ?>
  Master Rute &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a onclick="addForm()" class="btn btn-success"><i class="fa fa-plus-circle"></i> New Route </a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
   ##parent-placeholder-6e5ce570b4af9c70279294e1a958333ab1037c86##
   <li>Rute</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>     

<form method="POST">
    <?php echo e(csrf_field()); ?>

    
<div class="row">
  <div class="col-xs-12">
    <div class="box">
      <div class="box-body">  
      
		<label  class="col-md-1 control-label">Periode</label>
		<div class="col-md-3">
			<input id="awal" type="date" class="form-control" name="awal" value="<?php echo e(date('Y-m-d', strtotime("-350 day", strtotime(date('Y-m-d'))))); ?>" autofocus required>
		</div>
		<div class="col-md-3">
			<input id="akhir" type="date" class="form-control" name="akhir" value="<?php echo e(date('Y-m-d')); ?>" autofocus required>
		</div>

		<div class="col-md-4"> 
			<button type="button" class="btn btn-primary btn-sm" onclick="showData()"><i class="fa fa-table"></i> View </button>
		</div>

<input type="hidden" id="mgr" name="mgr" value="<?php echo e(Auth::user()->group); ?>">
<input type="hidden" id="tglsekarang" name="tglsekarang" value="<?php echo e($sekarang); ?>">		


<table class="table table-striped table-padding table-bordered" id="tbl-rute"  width="100%">
<thead>
   <tr class="tblheader">     
        <th>Tanggal</th>
        <th>Rute</th>
        <th>Driver</th>
        <th>No.POL</th>
        <th width="90">Opsi</th>
   </tr>
</thead>
<tbody></tbody>
</table>

      </div>
    </div>
  </div>
</div>
</form>

<?php echo $__env->make('rute.form', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('rute.detail', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
<script type="text/javascript">
var table, tbldetail, save_method;


var mgr=$('#mgr').val();

showData();

function showData(){
    
    var tgl1=$("#awal").val();
    var tgl2=$("#akhir").val();    
    
    $(function(){
        table = $('#tbl-rute').DataTable({
            "processing" : true,
            "destroy": true,
            "lengthMenu": [[8, 25, 50, -1], [8, 25, 50, "All"]],      
            "dom": "bftp",
            "ajax" : {
                "url" : "<?php echo e(DIR_APP); ?>rute/"+tgl1+"/"+tgl2+"/data",
                "type" : "GET"
            }
        }); 
    });
}    
   
	tbldetail = $('.tabel-detail').DataTable({
         "bSort": false,
         "processing" : true,
		 "paging" : false,
    	 "dom" : 'bt',
    });	     
   
   $('#modal-form form').validator().on('submit', function(e){
      if(!e.isDefaultPrevented()){
		 $('#submit-control').html(' Data sedang disimpan ... ');
		 $('#submit-control').attr('disabled','disabled');
         var id = $('#id').val();
         if(save_method == "add") url = "<?php echo e(route('rute.store')); ?>";
         else url = "rute/"+id;
         
         $.ajax({
           url : url,
           type : "POST",
           data : $('#modal-form form').serialize(),
           success : function(data){
			 $('#submit-control').html('Save');
			 $('#submit-control').removeAttr('disabled');			   
             $('#modal-form').modal('hide');
             table.ajax.reload();
           },
           error : function(){
			 $('#submit-control').html('Save');
			 $('#submit-control').removeAttr('disabled');				   
             alert(" Tidak dapat menyimpan data! ");
           }   
         });
         return false;
     }
   });
   

function addForm(){
   save_method = "add";
   tg = $('#tglsekarang').val();
   
   $('input[name=_method]').val('POST');
   $('#modal-form').modal('show');
   $('#modal-form form')[0].reset();            
   $('.modal-title').text('New Route');
   
   $('#tgl').val($('#tglsekarang').val());
   
   if(mgr=="MANAGER"){
       $('#tgl').removeAttr('disabled');
   }else{
       $('#tgl').attr('readonly', true);
   }
}

function editForm(id){
   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   $('#modal-form form')[0].reset();
   $.ajax({
     url : "rute/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form').modal('show');
       $('.modal-title').text('Edit Route');
       
       $('#id').val(data.id_route);
       $('#tgl').val(data.tanggal);
       $('#tgl').attr('readonly', true);
	   $('#nama').val(data.route_name);
       $('#sopir').val(data.driver);
       $('#nopol').val(data.no_pol);
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}

function batal(id){
   if(confirm("  Apakah yakin Rute ini akan dibatalkan ?  ")){
     $.ajax({
       url : "/wawan/rute/"+id+"/batal",
       type : "GET",
       dataType : "JSON",
       success : function(data){
            //alert('berhasil dibatalkan ')
				 if(data.msg=="error"){
					swal("WARNING", " Rute Gagal dibatalkan  !","error");
				 }else{
					swal("SUCCESS", " Pembatalan Rute berhasil ! ","success");
					table.ajax.reload();	
				 }
       },
           error : function(){
             //alert("Tidak dapat menyimpan data!");
			 swal("WARNING"," DATA tidak dapat dihapus, harap hubungi IT !","error");
			}   
         });
       return false;
	}
}

function listData(id){
	
    $('#modal-detail').modal('show');
	
    tbldetail.ajax.url("rute/"+id+"/detail");
	tbldetail.ajax.reload();

}


</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/myprojeq/public_html/wawan/resources/views/rute/index.blade.php ENDPATH**/ ?>