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



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

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


<?php $__env->startSection('content'); ?>   
<div class="row">
	<div class="container-fluid">
		<div class="card">
			<div class="card-block">  
			
    <a onclick="addForm()" class="btn btn-success btn-sm"><i class="fa fa-plus-circle"> </i> New DO </a> 			
    <h6 style="text-align:right; margin-top:-20px"><?php echo e(tanggal_indonesia(date('Y-m-d'),false)); ?></h6>

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


<input type="hidden" id="mgr" name ="mgr" value="<?php echo e(Auth::user()->group); ?>"> 

<table class="table table-padding table-striped" id="tblkeluar" width="100%">
<thead>
   <tr class="tblheader">
   
        <th width="100px">No.DO</th>
        <th width="70px">Tanggal</th>
        <th width="250">GDG</th>
        <th width="150px">Tujuan</th>
        <th width="350px">Deskripsi</th>
        <th width="25px">Act</th>
 
	</tr>
</thead>
<tbody></tbody>

</table>
</form>

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

<?php echo $__env->make('keluar.do_create', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('keluar.form_detail', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('keluar.add_detail', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('keluar.liststock', \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 = $('#tblkeluar').DataTable({
        "processing" : true,
        "lengthMenu": [[8, 25, 50, -1], [8, 25, 50, "All"]],       //pilihan jumlah record show
        "order" : [0,'DESC'],
        "ajax" : {
            "url" : "<?php echo e(route('keluar.datakeluar')); ?>",
            "type" : "GET"
        }
    }); 
});   

//submit
$('#form-do').on("submit", function(e) {

    if(!e.isDefaultPrevented()){
		 
		$('#submit-control').html(' Simpan Create ... ');
		$('#submit-control').attr('disabled','disabled');
		  
        var id = $('#id').val();
        if(save_method == "add") url = "<?php echo e(route('keluar.store')); ?>";
        else url = "keluar/"+id;

        $.ajax({
            url : url,
            type : "POST",
            data : $('#form-do').serialize(),
            dataType: 'JSON',		   
            success : function(data){
			    if(data.msg=="error"){
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan data !","error");
					$('#asal').focus().select();
				}else{
					$('#form_do').modal('hide');
					
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');		
					$('#tblkeluar').DataTable().ajax.reload(null, false);
				}   
 		    },
            error : function(){
			    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');
   $('#form_do').modal('show');
   $('#form_do form')[0].reset();            
   $('#asal').removeAttr('disabled');
} 	 

function batal(id){
    
    if($('#mgr').val() != "MANAGER"){ swal("WARNING", " Anda tidak berhak membatalkan !","info"); return false; }
    
    if(confirm("  Apakah yakin Invoice akan dibatalkan ?  ")){
        $.ajax({
            url : "<?php echo e(DIR_APP); ?>sales/"+id+"/batal",
            type : "GET",
            dataType : "JSON",
            success : function(data){
				 if(data.msg=="error-1"){
					swal("WARNING", " Invoice Gagal dibatalkan karena masih ada transaksi !","error");
				 }else{
					swal("SUCCESS", " Pembatalan Invoice berhasil ! ","success");
					table.ajax.reload();	
				 }
            },
            error : function(){
			    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
			}   
        });
        return false;
	}
}

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

    $('input[name=_method]').val('PATCH');
    $('#form_do form')[0].reset();
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>keluar/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            $('#form_do').modal('show');

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

            $('#asal').val(data.gudang_id).attr('disabled', 'disabled');
            $('#tuju').val(data.tujuan);
	        $('#ket').val(data.deskripsi);
	 
	    },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });   
}

function addDetail(id){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#form-detail').modal('show');
   $('#form-detail form')[0].reset();   
   tampilHeader(id);
   tampilDetail(id);
}

function tampilHeader(id){
    $('#id_do').val(id);
    $('#id_do2').val(id);
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>keluar/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            
            $('#asal2').text("Dari: "+data.nama+"  Tujuan: "+data.tujuan);
            $('#nofaktur').text("NO.DO: "+data.out_no);
            $('#keterangan').text("Keterangan: "+data.deskripsi);

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



    tbdetail = $('#tbldetail').DataTable({
        "scrollY": '55vh',
        "scrollCollapse": true,
        "bSort": false,
        "destroy": true,
        "processing" : true,
	    "paging" : false,
	    "dom" : 'bti',
    });
    
    tblproduk = $('.tabel-produk').DataTable({
        "scrollY": '55vh',
        "scrollCollapse": true,
        "bSort": false,
        "destroy": true,
        "processing" : true,
	    "paging" : false,
	    "dom" : 'bfti',
    });
    
function tampilDetail(id){

    tbdetail.ajax.url("<?php echo e(DIR_APP); ?>keluar/"+id+"/datadetail");
	tbdetail.ajax.reload();
}    


function addItem(){
    save_method = "add";
    $('input[name=_method]').val('POST');
    $('#add_detail').modal('show');
    $('#add_detail form')[0].reset();   
    $('#id_do2').val($('#id_do').val());
}


//submit add detail
$('#form-add_detail').on("submit", function(e) {

    if(!e.isDefaultPrevented()){
		 
		$('#submit-add').html(' Simpan data ... ');
		$('#submit-add').attr('disabled','disabled');
		  
        var id = $('#iddetail').val();
        if(save_method == "add") { url = "<?php echo e(DIR_APP); ?>keluar/adddetail"; tipe="POST"; }
        else { url = "<?php echo e(DIR_APP); ?>keluar/"+id+"/simpanedit" ; tipe="GET"; }

        $.ajax({
            url : url,
            type : tipe,
            data : $('#form-add_detail').serialize(),
            dataType: 'JSON',		   
            success : function(data){
			    if(data.msg=="error"){
					$('#submit-detail').html('Save');
					$('#submit-detail').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan data !","error");
					$('#prd2').focus().select();
					return false;
			    }

				if(data.msg=="error1"){
					swal("WARNING", " Stock tidak ada/ Tidak mencukupi !","error");
					$('#prd2').focus().select();
					return false;				    
			
				}else{

					$('#add_detail').modal('hide');
					$('#submit-detail').html('Save');
					$('#submit-detail').removeAttr('disabled');		
					
					$("#tbldetail").DataTable().ajax.reload(null, false);
				}   
 		    },
            error : function(){
			    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
			    $('#submit-detail').html('Save');
			    $('#submit-detail').removeAttr('disabled');			 
            }   
        });
        return false;
	}
});
   
function editDetail(id){
    save_method = "edit";

    $('input[name=_method]').val('PATCH');
    $('#add_detail').modal('show');
    $('#add_detail form')[0].reset();       
    
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>keluar/"+id+"/editdetail",
        type : "GET",
        dataType : "JSON",
        success : function(data){

            $('#iddetail').val(data.id);
	        $('#id_do2').val(data.out_id);
            $('#prd2').val(data.product_id);
            
            $('#produk').val(data.product_name);            
            $('#kms').val(data.satuan.concat(' / ', data.isi));
	        $('#qty').val(data.qty);
	        $('#ket2').val(data.deskripsi);
	 
	    },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });   
}

function posting(){

    swal({
        title: "Anda Yakin ingin memposting DO ?",
        text: "Data tidak bisa diedit lagi jika sudah diposting !",
        icon: "info",
        buttons: [
            'Batal',
            'Posting'
            ],
        dangerMode: true,
        }).then(function(isConfirm) {
        if (isConfirm) {
            swal({
                title: 'Confirm!',
                text: 'Klik OK untuk melanjutkan Posting !',
                icon: 'info'
            }).then(function() {
                postingFtr();
            });
        }else {
            swal("Batal", "Invoice masih bisa diedit :)", "error");
        }
    })
}    

function postingFtr(){
    
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>keluar/posting",
        type : "POST",
        data : $('#form-detaildo').serialize(),
        dataType: 'JSON',		   
        success : function(data){
		    if(data.msg=="error"){
				swal("WARNING", " Gagal posting data !","error");
				
			}else{
                swal("Success", "DO berhasil diposting !", "success");
                location.reload();
			}   
	    },
        error : function(){
		    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
        }   
    });
    return false;
}



function printFaktur(){
    var id = $('#id_do').val();
    window.location="<?php echo e(DIR_APP); ?>keluar/"+id+"/printfaktur";
}


function printDO(){
    $('#modal-form_do').modal('show');
    $('#modal-form_do form')[0].reset();            
    //$('.modal-title').text('Print DO Keluar');
}


/* bonus */
function bonus(){
    save_method = "add";
    $('input[name=_method]').val('POST');
    $('#add_bonus').modal('show');
    $('#add_bonus form')[0].reset();   
}

//submit add bonus
$('#form-add_bonus').on("submit", function(e) {
    
    //alert('simpan bonus'); return false;

    if(!e.isDefaultPrevented()){
		 
		$('#submit-bonus').html(' Simpan data ... ');
		$('#submit-bonus').attr('disabled','disabled');

        url = "<?php echo e(DIR_APP); ?>sales/addbonus"; 
        

        $.ajax({
            url : url,
            type : 'POST',
            data : $('#form-add_bonus').serialize(),
            dataType: 'JSON',		   
            success : function(data){
			    if(data.msg=="error"){
					$('#submit-bonus').html('Save');
					$('#submit-bonus').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan bonus !","error");
					
					return false;
			
				}else{

					$('#add_bonus').modal('hide');
					$('#submit-bonus').html('Save');
					$('#submit-bonus').removeAttr('disabled');		
			
					$("#tbldetail").DataTable().ajax.reload(null, false);

				}   
 		    },
            error : function(){
			    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
			    $('#submit-bonus').html('Save');
			    $('#submit-bonus').removeAttr('disabled');			 
            }   
        });
        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/keluar/index.blade.php ENDPATH**/ ?>