<?php $__env->startSection('title'); ?>
	
	<tr><td width="80">Pelunasan Piutang &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo e(tanggal_indonesia(date('Y-m-d'),false)); ?></td>
    	&nbsp;&nbsp;&nbsp;
    	<a onclick="addForm()" class="btn btn-success"><i class="fa fa-plus-circle"> </i> New Transaksi </a> 
    	
    	<!-- <a onclick="window.location='<?php echo e(route('home')); ?>'" class="btn btn-primary"><i class="fa fa-home"></i> Home </a>
     	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	<?php echo e(tanggal_indonesia(date('Y-m-d'),false)); ?></td> -->
	</tr>	
<?php $__env->stopSection(); ?>

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

<!--
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<meta name="viewport" content="width=device-width, initial-scale=1">
	
	<script src="<?php echo e(asset('public/adminLTE/plugins/jQuery/jquery-2.2.3.min.js')); ?>"></script>
	<script src="<?php echo e(asset('public/adminLTE/bootstrap/js/bootstrap.min.js')); ?>"></script> 
	<script src="<?php echo e(asset('public/adminLTE/plugins/datatables/jquery.dataTables.min.js')); ?>"></script>
	<script src="<?php echo e(asset('public/adminLTE/plugins/datatables/dataTables.bootstrap.min.js')); ?>"></script>

</head>
-->

<?php $__env->startSection('content'); ?>   
<div class="row">
	<div class="col-sm-12">
		<div class="box">
			<div class="box-body">  

<form method="post" id="form-penjualan">
<?php echo e(csrf_field()); ?>


<input type="hidden" id="tglunas" name="tglunas" value="<?php echo e(date('Y-m-d')); ?>">
<input type="hidden" id="mgr" name ="mgr" value="<?php echo e(Auth::user()->group); ?>">

<table class="table table-striped table-padding table-bordered" id="tblpiutang" width="100%">
<thead>
   <tr class="tblheader">
   
 	    <th width="10%">Tanggal</th>
 	    <th width="20%">Customer</th>
        <th width="12%">BAYAR</th>
		<th width="12%">Tl.Invoice</th>
		<th width="8%">Pembulatan</th>
		<th width="5%">TYPE</th>
		<th width="15%">Keterangan</th>
		<th width="5%">STATUS</th>
		<th width="5%">User</th>
        <th width="3%"></th>  	  
 
	</tr>
</thead>
<tbody></tbody>

</table>
</form>


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

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

<?php $__env->stopSection(); ?>

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

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

$(function(){
   table = $('.table').DataTable({
     "processing" : true,
     "lengthMenu": [[5, 10, 20, -1], [5, 10, 20, "All"]],
     "order": [0, 'desc'],
     "ajax" : {
       "url" : "<?php echo e(route('piutang.header')); ?>",
       "type" : "GET"
     }
   }); 
   
//submit
	$(document).on("submit", function(e) {
	    

     if($('#kontankredit').val()=="A"){ alert("Type Pelunasan harus dipilih !"); return false; }
     

      if(!e.isDefaultPrevented()){
		 
		 $('#submit-control').html(' Simpan Create ... ');
		 $('#submit-control').attr('disabled','disabled');
		  
         var id = $('#id').val();
         if(save_method == "add") url = "<?php echo e(route('piutang.store')); ?>";
         else url = "piutang/"+id;

         $.ajax({
           url : url,
           type : "POST",
           data : $('#modal-form_create form').serialize(),
           dataType: 'JSON',		   
           success : function(data){
				 if(data.msg=="error"){
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan data !","error");
					$('#cus').focus().select();
				 }else{
					$('#modal-form_create').modal('hide');
					swal("SUCCESS", " Transfer baru berhasil dicreate ! ","success");
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');					
					table.ajax.reload();
				 }   
 		   },
           error : function(){
             //alert("Tidak dapat menyimpan data!");
			 swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
			 $('#submit-control').html('Save');
			 $('#submit-control').removeAttr('disabled');			 
           }   
         });
         return false;
	 }
   });
   
  
})  
/*-------------------------------------------------*/

function addForm(){
    
    var tglunas = $('#tglunas').val();
    
    save_method = "add";
    $('input[name=_method]').val('POST');
    $('#modal-form_create').modal('show');
    $('#modal-form_create form')[0].reset();        
    $('.modal-title').text('Pelunasan');

    $('#tgltrx').val(tglunas);
    $('#cus').removeAttr('disabled');
    $('#tp').removeAttr('disabled');
    
   if(mgr=="MANAGER")
   {
       $('#tgltrx').removeAttr('readonly','disabled');  
   }else{
       $('#tgltrx').attr('readonly', true);  
   }    
} 	 

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


function editHeader(id){
   save_method = "edit";

   $('input[name=_method]').val('PATCH');
   $('#modal-form_create form')[0].reset();
   $.ajax({
     url : "/wawan/piutang/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form_create').modal('show');
       $('.modal-title').text('Edit Header');
       
       $('#id').val(data.id_piutang);
	   $('#tgltrx').val(data.lunas_tgl);
       $('#cus').val(data.cust_id).attr('disabled', 'disabled');
       $('#tp').val(data.lunas_type);	   
	   $('#ket').val(data.lunas_notes);
	   $('#ttl').val(data.total_bayar);
	   $('#bulat').val(data.pembulatan);
	   
	   if(data.is_kontan==1){
	       $('#kontan').prop('checked', true);
	       $('#kontankredit').val(1); 
	   }else{
	       $('#kredit').prop('checked', true);
	       $('#kontankredit').val(0); 
	   }
	   
	   if(mgr=="MANAGER")
       {
           $('#tgltrx').removeAttr('readonly','disabled');  
       }else{
           $('#tgltrx').attr('readonly', true);  
       }  

     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });   
}

$('#kontan').on('change', function(){
    if($('#kontan').is(':checked')) { $('#kontankredit').val(1); }
})

$('#kredit').on('change', function(){
    if($('#kredit').is(':checked')) { $('#kontankredit').val(0); }
})

function test(){
    if($('#kontan').is(':checked')) { kontan=1; }else{ kontan=0; }
    if($('#kredit').is(':checked')) { kredit=1; }else{ kredit=0; }
    alert(kontan+' - '+kredit);
}

</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/piutang/index.blade.php ENDPATH**/ ?>