@extends('layouts.app')
<head>
    <style>
        .tblhdr { height:35px; background-color:#6495ED; color: white; font-size: 14px;}
        
        #tblgaji td,tr { font-size:13px; border:0px gray solid; }
        
    </style>
</head>

@section('title')

@endsection

@section('breadcrumb')
   @parent
   <li>proses gaji karyawan</li>
@endsection


@section('content')   
<div class="row">
	<div class="container-fluid">
		<div class="card">
			<div class="card-block">  

<form class="form-horizontal" data-toggle="validator" method="post" id="form-gaji">
{{ csrf_field() }} {{ method_field('POST') }}


<a id="tampil" style="cursor:pointer">Gaji Karyawan</a>

<input type="hidden" id="idtampil" value="1">

<div style="padding:10px 5px;">
    
<section id="header" class="show">

    <div class="col-sm-4">
		<label>Periode Gaji</label>
		<input id="masa" type="text" class="form-control" name="masa" autofocus required autocomplete="off" maxlength="7" minlength="7" value="{{ $prd }}">
        <small class="text-muted">Masa Periode Gaji [ YYYY-MM , contoh : 2023-11 ]</small>
    </div>

	<div class="text-center"> 
		<button type="button" class="btn btn-primary btn-sm pull-right" onclick="prosesgaji()" style=margin-top:20px;><i class="fa fa-table"></i> Proses </button>
		
    </div>
    <br>

</section>
    
    
    <button style="margin-top:-10px;margin-bottom:5px;" id='exportxls' type="button" class="btn btn-success btn-sm pull-right hide" onclick="printgaji()" style=margin-top:20px;><i class="fa fa-table"></i> Print Report </button>

</div>


<table class="table table-striped table-padding table-bordered" id="tblgaji" width="100%">    
<thead>
   <tr class="tblhdr">
   
 	    <th width="8%">Periode</th>
 	    <th width="5%">NIP</th>
 	    <th width="35%">Nama</th>
 	    <th width="5%">Jabatan</th>
 	    <th width="10%" class="text-right">Gaji Pokok</th>
		<th width="8%" class="text-right">Tunjangan</th>
		<th width="8%" class="text-right">Bonus</th>
		<th width="8%" class="text-right">Potongan</th>
		<th width="10%" class="text-right">Total</th>
		<th width="10px"></th>
	</tr>
</thead>
<tbody></tbody>

</table>
</form>

        </div>

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

@include('gaji.form_edit')

@endsection

@section('script')
<script type="text/javascript">
var table, save_method, mgr;


function showdata(){
    
    var prd  = $('#masa').val();

    $(document).ready(function(){
        table = $('#tblgaji').DataTable({
            "processing" : true,
            "bSort": false,
            "destroy": true,
            "dom" : "btip",
            "lengthMenu": [[8, 10, 20, -1], [10, 10, 20, "All"]],
            "order": [0, 'desc'],
            "ajax" : {
                "url" : "{{ DIR_APP }}gaji/"+prd+"/tampildata",
                "type" : "GET"
            }
        })
   }); 
}


function showhide(){
    if($('#idtampil').val()=="1"){
        $('#idtampil').val(0);
        $('#header').removeClass('show').addClass('hide');
    }else{
        $('#idtampil').val(1);
        $('#header').removeClass('hide').addClass('show');        
    }
}


function prosesgaji(){
    
    $.ajax({
        url : "{{ DIR_APP }}gaji/prosesdata",
        type : "POST",
        data : $('#form-gaji').serialize(),
        dataType: 'JSON',		   
        success : function(data){
            if(data.msg=='success'){
                showhide(); 
                showdata();
                $('#exportxls').removeClass('hide').addClass('show');
            }
 	    },
        error : function(){
		    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
        }   
    });    
}

function printgaji(){
    
    $('input[name=_method]').val('POST');
    $('#form-gaji').attr('action', "{{ DIR_APP }}gaji/reportgaji").submit();       //--> open new windows
    
}

function editgaji(id){

   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   
   $.ajax({
     url : "{{ DIR_APP }}gaji/"+id+"/editgaji",
     type : "GET",
     dataType : "JSON",
     success : function(data){
         
	    $('#modal-form_edit').modal('show');
	    $('#modal-form_edit form')[0].reset();           
	
	    $('#id').val(id);
	    $('#nama').val(data.nama);
        $('#jbt').val(data.jabatan);
        $('#nip').val(data.nip);
        $('#tglkerja').val(data.tgl_kerja);
        $('#gp').val(data.gaji_pokok);
        $('#tjg').val(data.tunjangan);
        $('#pot').val(data.potongan);
        $('#bonus').val(data.bonus);
       
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}    

   $('#edit-gaji').validator().on('submit', function(e){
      
        if(!e.isDefaultPrevented()){
            var id = $('#id').val();
            
            url = "{{ DIR_APP }}gaji/"+id+"/simpaneditgaji";
         
            $.ajax({
                url : url,
                type : "GET",
                data : $('#edit-gaji').serialize(),
                dataType: 'JSON',		   
                success : function(data){
                        
                        $('#modal-form_edit').modal('hide');
				        swal("SUCCESS", " Data Gaji berhasil disimpan ! ","success");
                        table.ajax.reload(null, false);
                   
 		        },
                error : function(){
		            swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");	
                }   
            });
            return false;
        }
    });

</script>

@endsection
