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

    <meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
	<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>

	<script type="text/javascript" src="public/adminLTE/dist/css/sweetalert.min.js"></script>

</head>
-->

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

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




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


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


<table class="table table-striped table-padding table-bordered" id="produk" width="100%">
<thead>
   <tr class="tblheader">
        <th width="25%">Description</th>
        <th width="20%">Category</th>
        <th width="15%">Type</th>
	    <th width="17%">Supl</th>
	    <th width="10%">Harga@</th>
        <th width="10%">Opsi</th>
   </tr>
</thead>
<tbody></tbody>
</table>
</form>

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


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

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

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

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

<script type="text/javascript">
var tbldetail;
//$(document).ready(function() {
//	var table = $('#produk').DataTable ({
//        "processing": true,
//        "serverSide": true,
//        "ajax": "<?php echo e(route('product.getdata')); ?>",
//        "columns":[
//            { "data": "nama_brg" },
 
//			{ 
//			"data": "cat_name",
//			"sClass": "text",
//			"orderable":true,
//			"searchable":false
//			},
			
//            { "data": "type", "searchable": false },	
            
//			{
//				"data": "deskripsi",
//				"width": "0%",
//				"searchable": true
//			},
//			{ "data" : "sup_nama", "searchable": false },
//			{ "data" : "harga_jual" },
//			{
//                "data": "id",
//                "sClass": "text-center",
//                "orderable": false,
//                "mRender": function (data) {
//                           return '<a onclick="editForm('+data+')" class="btn btn-success btn-sm"><i class="fa fa-pencil"></i></a> ' +
//						    '<a onclick="showDetail('+data+')" class="btn btn-primary btn-sm"><i class="fa fa-eye"></i></a>'
//                         }
//            }
  			
//        ]
//     });

$(function(){
   table = $('#produk').DataTable({
     "processing" : true,
     "ajax" : {
       "url" : "<?php echo e(route('product.data')); ?>",
       "type" : "GET"
     }
   });      

	tbldetail = $('.tabel-detail').DataTable({
	    "dom" : 'bt',
        "bSort" : false,
        "paging" : false,
	    "retrieve" : true,	 
        "processing" : true,
	 
    });	
		 
		 
//submit
	  $(document).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('product.store')); ?>";
         else url = "product/"+id;

         $.ajax({
           url : url,
           type : "POST",
           data : $('#modal-form_add form').serialize(),
           dataType: 'JSON',		   
           success : function(data){
			 $('#submit-control').html('Save');
			 $('#submit-control').removeAttr('disabled');
             if(data.msg=="error"){
               	swal("WARNING", " Gagal menyimpan data !","error");
                $('#nama').focus().select();
             }else{
                $('#modal-form_add').modal('hide');
				swal("SUCCESS", " Master Barang baru berhasil disimpan ! ","success");
                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 showDetail(id){
	
    $('#modal-detail').modal('show');
	
    tbldetail.ajax.url("product/"+id+"/lihat");
	tbldetail.ajax.reload();

}

function addForm(){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#modal-form_add').modal('show');
   $('#modal-form_add form')[0].reset();            
   $('.modal-title').text('New Product');
}


function editForm(id){
   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   $('#modal-form_add form')[0].reset();
   $.ajax({
     url : "product/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form_add').modal('show');
       $('.modal-title').text('Edit Product');
       
       $('#id').val(data.id);
	  
       $('#nama').val(data.nama_brg);
       $('#cat').val(data.cat_id);
       $('#tipe').val(data.type_brg);
       $('#asal').val(data.child_to);
       $('#supl').val(data.supplier);
	   $('#desk').val(data.deskripsi);
	   $('#harga').val(data.harga_jual);
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}

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