<!DOCTYPE html>
<html>



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

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


<?php $__env->startSection('content'); ?>   
<section id="tbl-data" class="show">

<div class="row">
  <div class="col-xs-12">
    <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 Salesman </a>
      </div>

<table class="table table-bordered table-hover" id="sales" width="100%">
  <thead>
    <tr class="tblheader">      
        <th>KODE</th>
        <th>Nama Sales</th>
        <th>Area</th>
        <!--th>Target</th-->
        <th width="5%">Aksi</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" style="width:100%; margin:auto;">
     <div class="card-block">

  
<div class="row">
  <div class="col-md-9 col-sm-9 col-xs-12">
    <h5>Form Salesman</h5>
    <br></br>      
    
	<div class="container" style="padding: 0px 50px; 0px 0px ">

    <input type="hidden" id="id" name="id">
    
        <div class="form-group">
            <label for="kode">KODE SALES</label>
            <input id="kode" type="text" class="form-control" name="kode" maxlength="3" minlength="3" required autofocus autocomplete="off">
            <small class="text-muted">Kode Sales (3 karakter)</small>
        </div>     
        
        <div class="form-group">
            <label for="nama">Nama Sales</label>
            <input id="nama" type="text" class="form-control" name="nama" required autofocus autocomplete="off">
            <small class="text-muted">Nama Lengkap Salesman</small>            
        </div>

        <div class="form-group">
            <label for="area">AREA/ZONA</label>
            <select id="area" type="text" class="form-control" name="area" autofocus required>
              <option value=""> -- Pilih Area -- </option>
              <?php $__currentLoopData = $area; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($list->id); ?>"><?php echo e($list->area_name); ?></option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
    
        <!--div class="form-group">
            <label for="target">TARGET</label>
            <input id="target" type="number" class="form-control" name="target" value="0" autofocus autocomplete="off">
            <small class="text-muted">Target yang harus dicapai (optional)</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> Simpan </button>
    		 <button id="tutup" type="button" onclick="tutupForm()" class="btn btn-outline-warning"><i class="fa fa-times"></i> Close</button>
        </div>
    
          </div>
        </div>
       </div>
     </div>
    </div>
    
</form>

</section>

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

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

$(function(){
   var table = $('#sales').DataTable({
     "processing" : true,
     "ajax" : {
       "url" : "<?php echo e(route('salesman.getdata')); ?>",
       "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('salesman.store')); ?>";
          else url = "salesman/"+id;
             
          $.ajax({
              url : url,
              type : "POST",
              data : $('#form-input').serialize(),
              success : function(data){
    
              if(data.msg =="error"){  
                  swal("WARNING", " Sales gagal disimpan ! ","error"); 
              }else{
                  swal("SUCCESS", " Sales berhasil disimpan ! ","success");
    			  $('#submit-control').html('<i class="fa fa-floppy-o"></i> Save');
    			  $('#submit-control').removeAttr('disabled');	
                  tutupForm();
                  $('#sales').DataTable().ajax.reload();
                }
              },
              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 editForm(id){
   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   $.ajax({
     url : "<?php echo e(DIR_APP); ?>salesman/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){

       bukaForm();
       
       $('#id').val(data.id);
       
       $('#nama').val(data.sales_name);
       $('#area').val(data.sales_area);
       $('#kode').val(data.sales_kode);
       //$('#target').val(data.sales_target);
       //$('#nama').attr('disabled', true);
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}

/* versi baru */

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

    //$('#burger').click();
	$('#tbl-data').addClass("hide");
	$('#form-data').removeClass("hide");
	$('#form-data').addClass("show");
	document.getElementById("form-input").reset();
	$('#nama').removeAttr('disabled', 'disabled');
}


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

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

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

</script>
<?php $__env->stopSection(); ?>
</html>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/myprojeq/public_html/sriayu/resources/views/salesman/index.blade.php ENDPATH**/ ?>