<!-- page menampilkan form detail input invoice -->




<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
	
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
   
  	<script type="text/javascript" src="<?php echo e(DIR_APP); ?>public/adminLTE/dist/css/sweetalert.min.js"></script> 


</head>

<?php $__env->startSection('title'); ?>
<form class="form form-horizontal form-produk" method="post" id="form-header" style="margin-bottom:-10px;">
    <?php echo e(csrf_field()); ?>

 <table>

    <tr><td width="120"><b>Customer </b></td><td width="600"><b><?php echo e($customer->cus_name.' - '.$customer->cus_address); ?></b></td></tr>
	<tr><td width="120"><b>Tgl. Invoice</b></td><td><b><?php echo e(tanggal_indonesia($m_sale->sale_tgl, false)); ?></b></td></tr>

	<tr><td width="120"><b>No. Invoice</b></td><td><b><?php echo e($m_sale->sale_no); ?></b></td>
	
    <td></td><td>
        <button id="submit-control" type="submit" class="btn btn-danger btn-flat simpan"><i class="fa fa-floppy-o"> </i> Posting </button>
    </td>
    </tr>

</table>
</form>

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

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

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

<div class="row">
  <div class="col-xs-12">
      <div class="box">
   
<div class="box-body">

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

  
  <input type="hidden" name="idtrx" value="<?php echo e($idtrx); ?>">
    <div class="text-right">
	    <a href="/wawan/penjualandetail/<?php echo e($idtrx); ?>/cetak" class="btn btn-primary cetak"><i class="fa fa-print"> </i> Cetak Invoice </a>
		<button type="button" class="btn btn-warning" onclick="window.history.back()"><i class="fa fa-times-circle"></i> Close </button> 
    </div>
        
    <div class="text-left" style="margin-top:-35px;">
        <input id="kode" type="hidden" class="form-control" name="kode" autofocus required readonly="true">
        <button onclick="showProduct()" type="button" class="btn btn-info"> + Barang Satuan </button>

        <input id="kode2" type="hidden" class="form-control" name="kode2" autofocus required readonly="true">
        <button onclick="showProduct2()" type="button" class="btn btn-success"> + Barang Kemasan </button>
    </div>

</form>


<form class="form-detail">
<?php echo e(csrf_field()); ?> <?php echo e(method_field('PATCH')); ?>


<div class="row">
    
<!-- <div style="height:400px; overflow-y: scroll;">  -->

<table class="table table-fixed table-striped table-bordered tabel-trfdetail" id="trfdetail">

<thead>
              
   <tr class="tblheader">
      <th width="20">No</th>
      <th>Deskripsi</th>
      <th>TYPE</th>
      <th>QTY</th>
	  <th>ISI</th>
      <th>Hg.Satuan</th>
      <th>Disc</th>
      <th>Jumlah</th>
      <th width="50">Opsi</th>
   </tr>
</thead>


<tbody></tbody>
</table>

</div>

</form>

<div class="box-footer">
    <div class="col-md-8" align="right">
    	<label>Total QTY &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;</label><br>
    	<label>Total Rp &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;</label><br>
    </div>
    <div class="col-md-3">
    	<div id="total-qty"	style="background: DarkSlateGray; color: #fff; font-size: 20px; text-align: right; height: 26px"></div>
    	<div id="total-rp" style="background: DarkCyan; color: #fff; font-size: 20px; text-align: right; height: 26px"></div>
    </div>          
	<div class="col-md-3">
		<form class="form form-horizontal form-rekaptrx" method="GET" action="/wawan/penjualan/<?php echo e($idtrx); ?>/posting">
			<?php echo e(csrf_field()); ?>

			<input type="hidden" name="idtrx" value="<?php echo e($idtrx); ?>">
		</form>
	</div>          

</div>

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

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

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

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

<!------------------------------------------------- javascript -------------------------------->

<script type="text/javascript">
var table, save_method;
var id_trx=$('#idtrx').val();

//detail kemasan
tblproduk = $('.tabel-produk').DataTable({
      "bSort": true,
      "processing" : true,
		  "paging" : true,
    	"dom" : 'bftp',
    });	

tblproduk2 = $('.tabel-produk2').DataTable({
      "bSort": true,
      "processing" : true,
		  "paging" : true,
    	"dom" : 'bftp',
    });	


$(function(){
  $('.tabel-produk').DataTable();
  $('.tabel-produk2').DataTable();
  
  table = $('.tabel-trfdetail').DataTable({
     "scrollY": '58vh',
     "scrollCollapse": true,
     "paging": false,
     "processing" : true,
	   "dom" : 'bt',
     "ajax" : {
     "url" : "<?php echo e(route('penjualandetail.data')); ?>",
     "type" : "GET"
	}


 }).on('draw.dt', function(){
   loadSummary();
 });


  $('.form-produk').on('submit', function(e){
      return false;
   });

   $('#kode').change(function(){
      addItem();
   });
   
    $('#kode2').change(function(){
      addItem2();
   });

});


/* simpan edit detail */
$('#modal-form form').validator().on('submit', function(e){
      if(!e.isDefaultPrevented()){
		 
         var id  = $('#id').val();
		 url = "/wawan/penjualandetail/"+id+"/update";
         $.ajax({
           url : url,
           type : "GET",
           data : $('#modal-form form').serialize(),
           success : function(data){
             $('#modal-form').modal('hide');
             table.ajax.reload();
           },
           error : function(){
			 return false;
          }   
        });
        return false;
    }
    
}); 

///////////////////////////////////////

/* simpan data ke ms_sale dan posting->stock , cetak  ---> purchase.update */

$('.simpan').click(function(){
    document.querySelector('#form-header').addEventListener('submit', function(e) {       
    var form = this;

    e.preventDefault(); // -- prevent form from submitting

    swal({
        title: "Anda Yakin ingin memposting Invoice ?",
        text: "Data Invoice akan diposting ke Stock & tidak bisa diedit lagi jika sudah diposting !",
        icon: "info",
        buttons: [
            'Posting',
            'Batal'
            ],
        dangerMode: true,
            }).then(function(isConfirm) {
            if (!isConfirm) {
            swal({
                title: 'Confirm!',
                text: 'Klik OK untuk melanjutkan Posting !',
                icon: 'info'
                }).then(function() {
            $('.form-rekaptrx').submit(); // -- submit form programmatically
        });
        } else {
            swal("Batal", "Invoice masih bisa diedit :)", "error");
        }
        })
    });    
});


/*---------------------------------------------------------------*/
function addItem(){

  $.ajax({
    url : "<?php echo e(route('penjualandetail.store')); ?>",
    type : "POST",
    data : $('.form-produk').serialize(),
    success : function(data)
		{
			if(data.msg=="error")
				{
				 swal("WARNING", " KODE ini sudah ada di Invoice !","error");
					$('#kode').val('').focus();
				}else{
					$('#kode').val('').focus();
					table.ajax.reload(function() { loadSummary(); }) ;         
				}
		},
			error : function(){
			swal("DANGER", " Detail Penjualan Gagal disimpan, HUB. IT !","error");
			}
			});
         return false;

}

/*---------------------------------------------------------------*/
function addItem2(){

  $.ajax({
    url : "<?php echo e(route('penjualandetail.simpan')); ?>",
    type : "POST",
    data : $('.form-produk').serialize(),
    success : function(data)
		{
			if(data.msg=="error")
				{
				 swal("WARNING", " KODE ini sudah ada di Invoice !","error");
					$('#kode2').val('').focus();
				}else{
					$('#kode2').val('').focus();
					table.ajax.reload(function(){loadSummary(); }) ;         
				}
		},
			error : function(){
		//alert(" Tidak dapat menyimpan data ! ");
			swal("DANGER", " Detail Penjualan Gagal disimpan, HUB. IT !","error");
			}
			});
         return false;

}
/*-------------------------------------------------------------*/
function selectItem(kode){
	$('#kode').val(kode);
	$('#modal-produk').modal('hide');
	addItem();
}

function selectItem2(kode2){
	$('#kode2').val(kode2);
	$('#modal-produk2').modal('hide');
	addItem2();
}


/* tampilkan form produk barang satuan */
function showProduct(){
  $('#modal-produk').modal('show');
  tblproduk.ajax.url("/wawan/penjualan/tampilsatuan");
	tblproduk.ajax.reload();
}

/* tampilkan form produk barang kemasan */
function showProduct2(){
  $('#modal-produk2').modal('show');
  tblproduk2.ajax.url("/wawan/penjualan/tampilkemasan");
	tblproduk2.ajax.reload();

}


function editForm(id){
	
	   save_method = "edit";
	   $('input[name=_method]').val('PATCH');
	   $('#modal-form form')[0].reset();
	   $.ajax({
		 url : "/wawan/penjualandetail/"+id+"/edit",
		 type : "GET",
		 dataType : "JSON",
		 success : function(data){
		   $('#modal-form').modal('show');
		   $('.modal-title').text('Edit Detail Transaksi');
		   
		   $('#id').val(data.id_dsale);
		   $('#nama').val(data.nama_brg);	   
		 
		   $('#isi').val(data.isi);
		   $('#retail').val(data.harga_retail);
		   $('#qty').val(data.qty);       
		   $('#dis').val(data.potongan);
		 },
		 error : function(){
		   alert("Tidak dapat menampilkan data Transfer !");
		 }
	   });
}

function inputForm(id){
   save_method = "add";
   $('input[name=_method]').val('PATCH');
   $('#modal-form_input form')[0].reset();

   $.ajax({
     url : "/sbo/transferdetail/"+id+"/caribrg",
     type : "GET",
     dataType : "JSON",
     success : function(data){
       $('#modal-form_input').modal('show');
       $('.modal-title').text('Input Detail Transfer');
       
       $('#idbrg').val(data.id);
	   $('#kdbrg_').val(data.kode_brg);
       $('#nama_').val(data.nama_brg);	   
       $('#gross_').val(data.harga_list);
     },
     error : function(){
       alert("Tidak dapat menampilkan data Invoice !");
     }
   });
}

/* modul delete */
function deleteItem(id){
   if(confirm("  Apakah yakin data akan dihapus ?  ")){
     $.ajax({
       url : "/wawan/penjualandetail/"+id,
       type : "POST",
       data : {'_method' : 'DELETE', '_token' : $('meta[name=csrf-token]').attr('content')},
       success : function(data){
         table.ajax.reload(function(){
			loadSummary();
          }); 
       },
       error : function(){
         alert("Tidak dapat menghapus data!");
       }
     });
   }
}

/* mreferesh perubahan total sale */

function loadSummary(){
	
  $.ajax({
	   url : "/wawan/penjualandetail/loadsummary",
       type : "GET",
       dataType : 'JSON',
       success : function(data){
			$('#total-qty').text(data.totalqty);
			$('#total-rp').text(data.totalrp);
       },
       error : function(){
         alert("Tidak dapat menampilkan data total penjualan !");
		 return false;
       }
  });
}

function error_mess(){
	swal("WARNING"," Anda tidak punya Akses ! ","error");
}

</script>

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