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

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

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

<div class="row">
    <div class="container-fluid">
        <div class="card">
            <div class="card-block"> 
    
    <h6>Edit Harga Pembelian</h6>
    <h6 style="margin-top:-20px;" class="text-right">Yang bisa diedit hanya Harga & Discount</h6>
    
    <table class="table table-striped table-padding table-responsive" id="tblpembelian" width="100%">
        <thead>
            <tr class="tblheader">
                <th>No.Intern</th>
                <th>No.Invoice</th>
                <th width="40px">GDG</th>
        	    <th width="70px">Tgl.Inv</th>
        	    <th width="70px">J.Tempo</th>
                <th width="200">Supplier</th>
        	    <th width="10px">PPN</th>
        	    <th width="20px">Disc</th>
        	    <th width="80px">Total Inv</th>
                <th width="55px">Act</th> 	  
        	</tr>
        
        </thead>
        <tbody></tbody>
    
    </table>

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


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

function editForm(id){
   save_method = "edit";
   $('input[name=_method]').val('PATCH');
   $('#modal-form form')[0].reset();
   $.ajax({
     url : "invoice/"+id+"/edit",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form').modal('show');
       $('.modal-title').text('Edit Invoice');
       
       $('#id').val(data.id_supp);
	   $('#kode').val(data.sup_id).attr('readonly', true);
       $('#nama').val(data.sup_nama);
       $('#alamat').val(data.sup_alamat);
       $('#telpon').val(data.sup_telp);
	   $('#kota').val(data.sup_kota);
       
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });
}
	 

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

   $('input[name=_method]').val('PATCH');
   $('#modal-form form')[0].reset();
   $.ajax({
     url : "invoice/"+id+"/lihat",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form').modal('show');
       $('.modal-title').text('Data Detail');
       
       $('#id').val(data.id_plist);
	   $('#supp').val(data.sup_kode.concat(' - ',data.sup_nama));
  	   $('#nama').val(data.list_sku.concat(' - ',data.sku_name));
	   $('#box').val(data.prc_box).attr('readonly', true);
       $('#pcs').val(data.prc_pcs).attr('readonly', true);
       $('#gross').val(data.prc_hrggross).attr('readonly', true);
	   $('#disc1').val(data.prc_disc1).attr('readonly', true);
	   $('#disc2').val(data.prc_disc2).attr('readonly', true);
	   $('#disc3').val(data.prc_disc3).attr('readonly', true);
	   $('#ppn').val(data.prc_ppn).attr('readonly', true);
	   $('#status').val(data.prc_status).attr('readonly', true);
	   $('#expd').val(data.list_exp).attr('readonly', true);
	                 
     },
     error : function(){
       alert("Tidak dapat menampilkan data!");
     }
   });   
}


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

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

            $('#supl').val(data.supp_id).attr('disabled', 'disabled');
            $('#tuju').val(data.gudang_id);
            $('#inv').val(data.inv_no);
            $('#tglinv').val(data.inv_tgl);
            $('#tgljt').val(data.inv_jt);
	        $('#ppn').val(data.inv_ppn);
	        $('#dis').val(data.inv_disc);
	 
	    },
        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);
   loadSummary();
   
   $('#btndetail').addClass('hide');
   $('#btnposting').addClass('hide');
}

function tampilHeader(id){
    $('#idinv').val(id);
    $('#idinv2').val(id);    
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>invoice/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            $('#sup_id').val(data.supp_id);
            $('#sup').text(data.sup_nama+" - "+data.sup_alamat);
            $('#nofaktur').text("NO.Faktur: "+data.inv_no);
            $('#keterangan').text("Disc Faktur: "+data.inv_disc+"%"+'\xa0\xa0\xa0\xa0\xa0\xa0\xa0'+"PPN: "+data.inv_ppn+"%");

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

function loadSummary(){
    
    var id=$('#idinv').val();
    
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>invoice/"+id+"/loadsummary",
        type : "GET",
        dataType : "JSON",
        success : function(data){

            $('#totalftr').text("Total incl PPN : \xa0\xa0\xa0"+data.totalftr);

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

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

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


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

 	tblproduk = $('.tabel-produk').DataTable({
        "scrollY": '55vh',
        "scrollCollapse": true,
        "bSort": false,
        "destroy": true,
        "processing" : true,
	    "paging" : false,
	    "dom" : 'bfti',
    });
    
    
//submit add detail
$('#form-add_detail').on("submit", function(e) {

    if(!e.isDefaultPrevented()){
		 
		$('#submit-add').html(' Simpan detail ... ');
		$('#submit-add').attr('disabled','disabled');
		  
        var id = $('#iddetail').val();
        
        url = "<?php echo e(DIR_APP); ?>invoice/"+id+"/simpaneditharga" ; 

        $.ajax({
            url : url,
            type : "GET",
            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");
					$('#prd').focus().select();
				}else{
				    //swal("success", 'success', "success");
					$('#add_detail').modal('hide');
					$('#submit-detail').html('Save');
					$('#submit-detail').removeAttr('disabled');		
					loadSummary();					
					$("#tbldetail").DataTable().ajax.reload(null, false);
					$('#tblpembelian').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 editHarga(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); ?>invoice/"+id+"/editdetail",
        type : "GET",
        dataType : "JSON",
        success : function(data){

            $('#iddetail').val(data.id);
	   
	        $('#btnproduk').addClass('hide');
	        
            $('#prd2').val(data.product_id).attr('disabled', 'disabled');
            $('#produk').val(data.product_name);
	        $('#dis1').val(data.disc_1);
	        $('#harga').val(data.harga);
	        $('#qty').val(data.qty).attr('disabled','disabled');
	        $('#kms').val(data.satuan.concat(' / ', data.isi));
	 
	    },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });   
}

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

/* batal invoice  */

function batal(id){

    swal({
        title: "Anda Yakin ingin Batal Invoice ?",
        text: "Coba pastikan lagi !",
        icon: "info",
        buttons: [
            'Cancel',
            'Lanjut Batal'
            ],
        dangerMode: true,
        }).then(function(isConfirm) {
        if (isConfirm) {
            swal({
                title: 'Confirm!',
                text: 'Klik OK untuk melanjutkan Pembatalan !',
                icon: 'info'
            }).then(function() {
                batalInv(id);
            });
        }else {
            swal("Batal", "Invoice masih bisa diedit :)", "error");
        }
    })
}    

function batalInv(id){
    
    $.ajax({
        url : "<?php echo e(DIR_APP); ?>invoice/"+id+"/batal",
        type : "GET",
        dataType: 'JSON',		   
        success : function(data){
		    if(data.msg=="error"){
				swal("WARNING", " Gagal Pemabatalan !","error");
				
			}else{
                swal("Success", "Invoice berhasil dibatalkan !", "success");
                location.reload();
			}   
	    },
        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/invoice/editharga.blade.php ENDPATH**/ ?>