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


<?php $__env->startSection('title'); ?>
	Master Product&nbsp;&nbsp;&nbsp;
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
   ##parent-placeholder-6e5ce570b4af9c70279294e1a958333ab1037c86##
   <li>product</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 Product </a>
            <a onclick="printmaster()" class="btn btn-success btn-sm"><i class="fa fa-print"></i> Print Master</a>
        </div>
        
<table class="table table-bordered table-striped table-hover" id="produk" width="100%">
<!--table class="table table-striped table-padding table-hover" id="produk" width="100%"-->
    <thead>
        <tr class="tblheader">
            <th>Nama Barang</th>
            <th width="70px">Cat</th>
            <th width="50px">Kemasan</th>
            <th width="70px">Harga</th>
            <th width="200px">Deskripsi</th>
            <th width="30px">Inv</th>
            <th width="10px">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">
        <h6>Form Product</h6>
        <br>
	    <input type="hidden" id="id" name="id">
 
    <div class="row">
        <div class="container" style="padding: 0px 30px; 0px 0px ">
            
            <div class="col-md-5 col-sm-5 col-xs-12">
 
                <div class="form-group">
                    <label>NAMA BARANG</label>
                    <input id="nama" type="text" class="form-control" name="nama" autofocus required autocomplete="off">
                </div>
               
                <div class="form-group">
                    <label for="cat">CATEGORY</label>
                    <select id="cat" type="text" class="form-control" name="cat" autofocus required>
                        <option value="">Pilih Category</option>
                        <?php $__currentLoopData = $category; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($list->id_cat); ?>"><?php echo e($list->cat_name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="form-group">
                    <label for="stk">Inventory</label>
                    <select id="stock" type="text" class="form-control" name="stock" autofocus required>
                        <option value="1">YA</option>
                        <option value="0">TIDAK</option>
                    </select>
                </div>     
                <div class="form-group">
                    <label>HARGA</label>
                    <input type="number" id="harga" name="harga" required autofocus class="form-control">
                </div>
                <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 type="button" onclick="tutupForm()" class="btn btn-outline-warning"><i class="fa fa-times"></i> Cancel </button>
                </div>                
            
            </div>
            
            <div class="col-sm-1 col-md-1"></div>
            
            <div class="col-sm-6 col-md-6">
                <div class="form-group">
                    <label>SATUAN BARANG/KEMASAN</label>
                    <input id="stn" type="text" class="form-control" name="stn" value="PCS" autofocus required autocomplete="off">
                </div>
                <div class="form-group">
                    <label>ISI KEMASAN</label>
                    <input id="isi" type="number" class="form-control" name="isi" value="1" autofocus required autocomplete="off">
                </div>
            

                
                <div class="form-group">
                    <label for="desk">DESKRIPSI</label>
                    <textarea  class="form-control" rows="7" name = "desk" id="desk" autocomplete="off" autofocus></textarea>
                    <small class="text-muted">ketrangan detail tentang produk [optional]</small>
                </div>      
            </div>
        
        </div>
    </div>
</div>
</div>

</form>
</section>


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


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

<script type="text/javascript">
var tbldetail; var save_method;

$(document).ready(function() {
    table = $('#produk').DataTable({
        "processing" : true,
        "lengthMenu": [[8, 15, 50, -1], [8, 15, 50, "All"]],       //pilihan jumlah record show
        "ajax" : {
            "url" : "<?php echo e(route('product.getdata')); ?>",
            "type" : "GET"
        }
    });     
   
	tbldetail = $('.tabel-detail').DataTable({
	    "dom" : 'bt',
        "bSort" : false,
        "destroy": true,
	    "retrieve" : true,	 
        "processing" : true
    });	
		 
		 
    //submit
    $('#form-input').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 : $('#form-input').serialize(),
                dataType: 'JSON',		   
                success : function(data){
                    $('#submit-control').html('<i class="fa fa-floppy-o"></i> Save');
                    $('#submit-control').removeAttr('disabled');
                    if(data.msg=="error"){
                   	    swal("WARNING", " Gagal menyimpan data !","error");
                        $('#nama').focus().select();
                    }else{
                        tutupForm();
                        $('#produk').DataTable().ajax.reload(null, false);
                    }   
     		    },
                error : function(){
                    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");	
                    $('#submit-control').html('<i class="fa fa-floppy-o"></i> Save');
                    $('#submit-control').removeAttr('disabled');			 
                }   
            });
            return false;
    	}
    });
});


function editForm(id){
    save_method = "edit";
    $('input[name=_method]').val('PATCH');
    $.ajax({
        url : "product/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
        
            bukaForm();
       
            $('#id').val(data.id);
	        $('#stock').val(data.is_stock);
            $('#nama').val(data.nama_brg);
            $('#cat').val(data.cat_id);
            $('#sup').val(data.supp_id);
            $('#desk').val(data.deskripsi);
            $('#stn').val(data.satuan);
            $('#isi').val(data.isi);
            $('#harga').val(data.harga);
        
        },
        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();
	$('#kode').attr('readonly', false);
}


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 addDetail(id){
    tampilProduct(id)
    bukaDetail();
    save_method="add";
    $('input[name=_method]').val('POST');
	
}

function tampilProduct(id){
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>product/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            $('#id2').val(id);
            $('#kode2').val(data.kode_brg);
            $('#nama2').val(data.nama_brg);
        }
    });    
}

function editDetail(id){
   save_method = "edit";
 
   $.ajax({
     url : "productsub/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
        
        bukaDetail();
        $('input[name=_method]').val('PATCH');
        
        $('#kode2').val(data.kode_brg);
        $('#nama2').val(data.nama_brg);
        $('#inv').val(data.is_invoice);            
        $('#id2').val(data.id);
	    $('#kemas').val(data.satuan);
        $('#isi').val(data.volume);
        $('#harga').val(data.harga);
        $('#harga2').val(data.harga_2);
        $('#hpp').val(data.hpp);
        },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}

function tutupDetail(){
  
	$('#sesi-detail').addClass("hide");
	$('#tbl-data').removeClass("hide");
	$('#tbl-data').addClass("show");	

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

function bukaDetail(){

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


function formatAngka(x) {
    x = x.toString();
    var pattern = /(-?\d+)(\d{3})/;
    while (pattern.test(x))
        x = x.replace(pattern, "$1,$2");
    return x;
}

function removeImage(id){
	
	$.ajax({
		url : "<?php echo e(DIR_APP); ?>product/"+id+"/removeimage",
		type : "GET",
		dataType : "JSON",
		success : function(data){    
			tbldetail.ajax.reload();
			}
		});		

}

function printmaster(){

    window.location="<?php echo e(DIR_APP); ?>product/printmaster";
    
}


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