<?php $__env->startSection('title'); ?>
	
	<tr><td width="80">Invoice Pembelian &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<?php echo e(tanggal_indonesia(date('Y-m-d'),false)); ?>

	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<a onclick="addForm()" class="btn btn-success"><i class="fa fa-plus-circle"> </i> New Invoice </a> 
	
	</td>
	
	</tr>	
<?php $__env->stopSection(); ?>

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


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

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



<table class="table table-striped table-padding table-bordered table-responsive" id="tblpembelian" style="background: #DCDCDC;">
<thead>
   <tr class="tblheader">
   
 	  <th width="3%">No.</th>	  
      <th width="15%">No.Invoice</th>
	  <th width="10%">Tgl.Invoice</th>
      <th width="25%">Supplier</th>
	  <th width="12%">Total Invoice</th>
	  <th width="25%">Keterangan</th>
      <th width="9%">Opsi</th> 	  
 
	</tr>
</thead>
<tbody></tbody>

</table>
</form>

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

<?php echo $__env->make('invoice.invoice_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;

$(function(){
   table = $('.table').DataTable({
     "processing" : true,
     "ajax" : {
       "url" : "<?php echo e(route('invoice.header')); ?>",
       "type" : "GET"
     }
   }); 
   
//submit
	  $(document).on("submit", function(e) {
      if(!e.isDefaultPrevented()){
		 
		 $('#submit-control').html(' Simapan Invoice ... ');
		 $('#submit-control').attr('disabled','disabled');
		  
         var id = $('#id').val();
         if(save_method == "add") { url = "<?php echo e(route('invoice.store')); ?>"; tipe="POST" ; }
         else { url = "invoice/"+id+"/simpanedit" ; tipe="GET"; }

         $.ajax({
           url : url,
           type : tipe,
           data : $('#modal-form_create form').serialize(),
           dataType: 'JSON',		   
           success : function(data){
			 if(data.msg=="discerror")
			 {
				 swal("WARNING", " Discount Tambahan invalid !","error");
					$('#dis').focus().select();
							$('#submit-control').html('Save');
							$('#submit-control').removeAttr('disabled');
			 }else{
				 if(data.msg=="error"){
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan data !","error");
					$('#supl').focus().select();
				 }else{
					$('#modal-form_create').modal('hide');
					swal("SUCCESS", " PO 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(){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#modal-form_create').modal('show');
   $('#modal-form_create form')[0].reset();            
   $('.modal-title').text('New Invoice');
}
   
function editForm(id){
   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   $('#modal-form_create form')[0].reset();
   $.ajax({
     url : "invoice/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form_create').modal('show');
       $('.modal-title').text('Edit Invoice');
       
       $('#id').val(data.id_invoice);
	   $('#supl').val(data.supp_id).attr('readonly', true);
       $('#inv').val(data.inv_no);
       $('#tglinv').val(data.inv_tgl);
       $('#note').val(data.keterangan);

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

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

   $('input[name=_method]').val('PATCH');
   $('#modal-form form')[0].reset();
   $.ajax({
     url : "invoice/"+id+"/lihat",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form').modal('show');
       $('.modal-title').text('Data Detail');
       
       $('#id').val(data.id_plist);
	   $('#supp').val(data.sup_kode.concat(' - ',data.sup_nama));
  	   $('#nama').val(data.list_sku.concat(' - ',data.sku_name));
	   $('#box').val(data.prc_box).attr('readonly', true);
       $('#pcs').val(data.prc_pcs).attr('readonly', true);
       $('#gross').val(data.prc_hrggross).attr('readonly', true);
	   $('#disc1').val(data.prc_disc1).attr('readonly', true);
	   $('#disc2').val(data.prc_disc2).attr('readonly', true);
	   $('#disc3').val(data.prc_disc3).attr('readonly', true);
	   $('#ppn').val(data.prc_ppn).attr('readonly', true);
	   $('#status').val(data.prc_status).attr('readonly', true);
	   $('#expd').val(data.list_exp).attr('readonly', true);
	                 
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });   
   
}

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



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