<head>
    <style>
        #tbl-supplier th, td, tr { border-bottom: 1px black solid; }
    </style>
</head>



<?php $__env->startSection('title'); ?>
  Master Supplier
<?php $__env->stopSection(); ?>

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

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

<section id="tbl-data" class="show">
<div class="row">
  <div class="container-fluid">
    <div class="card">
      <div class="card-block">     

      <div class="text-left">
        <a onclick="addForm()" class="btn btn-outline-info btn-sm"><i class="fa fa-plus-circle" ></i> New Supplier</a>
      </div>

    <table class="table table-striped table-padding table-hover" id="tbl-supplier" width="100%">
        <thead>
        
           <tr class="tblheader">
              <th>Nama Supplier</th>
              <th>Alamat</th>
              <th>Telpon</th>
              <th>Kontak</th>
              <th>Kerdit</th>
              <th width="50px">Act</th>
           </tr>
        </thead>
        <tbody></tbody>
    </table>

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

<!-------------------------------------------------form input -------------------> 
<section id="form-data" class="hide">

<form class="form-horizontal" data-toggle="validator" method="post" id="form-input">
    <?php echo e(csrf_field()); ?> <?php echo e(method_field('POST')); ?>


 
    <div class="card">
        <div class="card-block">
            <h5>Form Supplier</h5>
    <br>

    <div class="Container" style="padding:5px 35px;">    
        <input type="hidden" id="id" name="id">

    <div class="row">
       
        <div class="col-md-7 col-sm-7">
            <div class="form-group">
                <label for="nama" >Nama Supplier</label>
                    <input id="nama" type="text" class="form-control" name="nama" autofocus required autocomplete="off">
                <span class="help-block with-errors"></span>
            </div>
    
            <div class="form-group">
                <label for="alamat">Alamat</label>
                    <input id="alamat" type="text" class="form-control" name="alamat" required autocomplete="off">
                    <span class="help-block with-errors"></span>
            </div>
    
            <div class="form-group">
                <label for="kota">Kota</label>
                <select id="kota" type="text" class="form-control" name="kota" autofocus required>
                    <option value=""> -- Pilih Kota -- </option>
                    <?php $__currentLoopData = $kota; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($list->city_id); ?>"><?php echo e($list->city_name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="form-group">
                <label>Status PKP</label>
                <select id="pkp" type ="text" class="form-control" name="pkp" autofocus required>
                    <option value="0">Non PKP</option>
                    <option value="1">PKP</option>
                </select>
            </div> 
        </div>
        
        <div class="col-sm-1 col-md-1"></div>
        
        <div class="col-md-4 col-sm-4">

            <div class="form-group">
                <label for="telpon">Telpon</label>
                <input id="telpon" type="text" class="form-control" name="telpon" autofocus autocomplete="off">
                <span class="help-block with-errors"></span>
            </div>  
            
            <div class="form-group">
                <label>Kontak Person</label>
                <input id="kontak" type="text" class="form-control" name="kontak" autofocus autocomplete="off">
                <small class="text-muted">Nama orang yang bisa dihubungi</small>
            </div>  
      
            <div class="form-group">
                <label>Lama Kredit {hari]</label>
                <input id="kredit" type="number" class="form-control" name="kredit" value="1" autofocus required>
                <small class="text-muted">Lama Kredit yang diberikan Principle/Pabrik</small>
            </div> 
            
            <br>
            <div class="form-group">
                <button id="submit-control" type="submit" class="btn btn-outline-success"><i class="fa fa-floppy-o"></i> Save </button>
                <button id=tutup onclick="tutupForm()" type="button" class="btn btn-outline-warning"><i class="fa fa-arrow-circle-left"></i> Cancel</button>
            </div>
        </div>
        
        </div>
        </div>    
    </div>   
</form>

</section>

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

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

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

$(function(){
   table = $('#tbl-supplier').DataTable({
     "processing" : true,
     "ajax" : {
       "url" : "<?php echo e(route('supplier.data')); ?>",
       "type" : "GET"
     }
   }); 
});   
  
$('#form-input').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('supplier.store')); ?>";
        else url = "<?php echo e(DIR_APP); ?>supplier/"+id;
         
        $.ajax({
            url : url,
            type : "POST",
            dataType: "JSON",
            data : $('#form-input').serialize(),
            success : function(data){
             
                if(data.msg =="error"){  
                    swal("WARNING", " Data gagal disimpan ! ","error"); 
                }else{
                    //swal("SUCCESS", " Supplier berhasil disimpan ! ","success");
    			    $('#submit-control').html('<i class="fa fa-floppy-o"></i> Save');
    			    $('#submit-control').removeAttr('disabled');	
                    tutupForm();
                    $('#tbl-supplier').DataTable().ajax.reload(null, false);
                }
            },
          
            error : function(){
                $('#submit-control').html('<i class="fa fa-floppy-o"></i> Save');
			    $('#submit-control').removeAttr('disabled');
                alert("Tidak dapat menyimpan data!");
            }   
        });
        return false;
    }
});


function addList(id){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#modal-product').modal('show');
   $('#modal-product form')[0].reset();            
   $('.modal-title').text('Product List');
   tampilHeader(id);
   tampilDetail(id);
}

function tampilHeader(id){
    $('#idsup').val(id);
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>supplier/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            $('.modal-title').text(data.sup_nama);
            $('#supl').text(data.sup_nama);
	    },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });   
}

function tampilDetail(id){

    tbldetail.ajax.url("<?php echo e(DIR_APP); ?>supplier/"+id+"/listproduct");
	tbldetail.ajax.reload();
} 

tbldetail = $('#tbldetail').DataTable({
    "paging": true,
    "processing" : true,
    "destroy" : true,
    //"iDisplayLength" : 15,
    "sort": false,
    "lengthMenu": [[ 10, 25, 50, -1], [ 10, 25, 50, "All"]],
	"dom" : 'btp',
 });

function addItem(){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#modal-list').modal('show');
   $('.modal-title').text('Product List');
   tampilProduct();
}
 
tblproduct = $('.tabel-list').DataTable({
    "paging": true,
    "processing" : true,
    "destroy" : true,
    "sort": false,
    "lengthMenu": [[ 10, 25, 50, -1], [ 10, 25, 50, "All"]],
	"dom" : 'bftp',
 });
 
function tampilProduct(){
    var sup=$('#idsup').val();
    tblproduct.ajax.url("<?php echo e(DIR_APP); ?>supplier/"+sup+"/productsup");
	tblproduct.ajax.reload();
}

function addProduct(id){
    
    var idsup    = $('#supl').val();
    
    $.ajax({
        
        url : "<?php echo e(DIR_APP); ?>supplier/"+id+"/simpanproduct",
        type : "GET",
        data : $('#form-list').serialize(),
        success : function(data)
		{
		    if(data.msg=="error")
			{
		    	swal("WARNING", " Product sudah terdaftar !","error");
				
			}else{

				$('#tbldetail').DataTable().ajax.reload(null, false);
			}
		},
		    error : function(){
		    swal("DANGER", " Data Gagal disimpan, HUB. IT !","error");
		}
	});
    
    return false;
}

function selectItem(id){
	$('#modal-list').modal('hide');
	addProduct(id);
}

function editForm(id){
    save_method = "edit";
    $('input[name=_method]').val('PATCH');
    $.ajax({
        url : "supplier/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){

            bukaForm();
 
            $('#id').val(data.id);

            $('#nama').val(data.sup_nama);
            $('#alamat').val(data.sup_alamat);
            $('#telpon').val(data.sup_telp);
	        $('#kota').val(data.sup_kota);
	        $('#pkp').val(data.is_pkp);
	        $('#kredit').val(data.lama_kredit);
	        $('#kontak').val(data.sup_kontak);
       
        },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });
}

/* versi baru */

function addForm(){
	save_method="add";
    $('input[name=_method]').val('POST');

	$('#tbl-data').addClass("hide");
	$('#form-data').removeClass("hide");
	$('#form-data').addClass("show");
	document.getElementById("form-input").reset();
}


function tutupForm(){
 
	$('#form-data').addClass("hide");
	$('#tbl-data').removeClass("hide");
	$('#tbl-data').addClass("show");	

    document.getElementById("form-input").reset();
}

function bukaForm(){
 
    $('#tbl-data').addClass("hide");
	$('#form-data').removeClass("hide");
	$('#form-data').addClass("show");
	document.getElementById("form-input").reset();
}

function delproduct(id){
    
    //if($('#mgr').val() != "MANAGER"){ swal("WARNING", " Anda tidak berhak membatalkan !","info"); return false; }
    
    if(confirm("  Apakah yakin product ini akan dihapus ?  ")){
        $.ajax({
            url : "<?php echo e(DIR_APP); ?>supplier/"+id+"/delproduct",
            type : "GET",
            dataType : "JSON",
            success : function(data){
				 if(data.msg=="error-1"){
					swal("WARNING", " Product gagal dihapus !","error");
				 }else{
					$('#tbldetail').DataTable().ajax.reload(null, false);	
					//$('.tabel-list').DataTable().ajax.reload(null, false);
				 }
            },
            error : function(){
			    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/u345793601/domains/my-projeq.com/public_html/swa/resources/views/supplier/index.blade.php ENDPATH**/ ?>