@extends('layouts.app')

@section('content')
<?php usort($tableGrid, "SiteHelpers::_sort"); ?>
<div class="page-titles">
  <h2> {{ $pageTitle }} <small> {{ $pageNote }} </small></h2>
</div>


	<div id="gudangpupukareaView"></div>	
	<div id="gudangpupukareaGrid">
		<div class="card">
			<div class="card-body">
			@include( $pageModule.'/toolbar')
		
		
			<div class="table-responsive">			
				<table id="gudangpupukareaTable" class="display table  table-striped table-hover" cellspacing="0" width="100%">
			        <thead>
			            <tr>
			            	<th>ID</th>	
			            	
			            @if($setting['view-method'] =='expand')<th></th>@endif
			           

			            
		            <?php foreach ($tableGrid as $t) :
						if($t['view'] =='1'):
							$limited = isset($t['limited']) ? $t['limited'] :'';
							if(SiteHelpers::filterColumn($limited ))
							{
								echo '<th align="'.$t['align'].'" width="'.$t['width'].'">'.\SiteHelpers::activeLang($t['label'],(isset($t['language'])? $t['language'] : array())).'</th>';				
							} 
						endif;
					endforeach; ?>
							 <th width="30" class="text-right" > Action </th>
						</tr>

					</thead>	
			               
			    </table>
			</div>	 
		</div>			
	</div>	
	</div>
	
</div>

<script type="text/javascript">

	$(document).ready(function() {
		$('.tips').tooltip();
		$('.dataselect').select2();
		var rows_selected = []; 			
	   	var table = $('#gudangpupukareaTable').DataTable( {
	        "processing": true,
	       
	        "serverSide": true,
	        // "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
	        "ajax": {
	            "url": "{!! url('gudangpupukarea')!!}",
	            "type": "POST"
	             
        	},
        	"columnDefs": [{ 
        		"targets": [0],
                "visible": false,
                orderable: false,
            	className: 'select-checkbox'
        	}],
        	"columns": [<?php echo $column;?>],
        	'order': [[1, 'asc']],
        	<?php if($access['is_excel'] ==1 ) { ?>
        	dom: 'Bfltip',
        	buttons: [
            	'copy', 'csv', 'excel', 'pdf', 'print'
        	]
        	<?php } ?>
        	
	    });

	   	<?php if($setting['view-method'] =='expand'): ?>
		$('#gudangpupukareaTable tbody').on('click', 'td.details-control', function () {
	        var tr = $(this).closest('tr');
	        var row = table.row( tr );
	        var id = row.data().rowId;

	        if ( row.child.isShown() ) {
	        	 row.child.hide();
            	tr.removeClass('shown');
	        }
	        else {
	            // Open this row
	            row.child.show();	            
	            row.child( expand_child(id) ).show();
	            tr.addClass('shown');
	            $.get('{{ url("gudangpupukarea/")}}/'+id , function(callback){
	            	$('#'+id).html(callback);
	            	$('#'+id).addClass('data');
	            })
		        
	            
	        }
    	});
    	<?php endif; ?>
		$('.dosearch').keyup(function( e ){
			if (e.keyCode === 13) {
				val = $(this).val();
				table.search(val ).draw();
			}
		})  

	    $('#gudangpupukareaTable').Sdtable({
	    	tableId : '#gudangpupukarea',
	    	table   : table,
	    	action  : '{{ url("gudangpupukarea")}}' 
	    });

	   
	});

	$('#kode_permintaan').on('focus', function() {
		$(this).on('keydown.getDataPermintaan', function(e) {
			if (e.key === 'Enter' && $(this).val().trim() !== '') {
				get_data_permintaan();
			}
		});
	}).on('blur', function() {
		$(this).off('keydown.getDataPermintaan');
	});

    function expand_child( id )
    {
    	return '<div id="'+ id+'"><p class="text-center"> Loading Content .. Please wait</p></div>';	
    }

	function get_data_permintaan()
{
	var id = $("#kode_permintaan").val();
	if (id !== "") {
	 $.ajax({
					url: "{{ url('gudangpupukarea/get_data_permintaan/') }}"+"?id="+id,
					type: "GET",
					dataType: "html",
					success: function(data){
							Swal.fire({
									  title: 'Simpan ke Gudang',
									  html: data,											
									  showCancelButton: true,
									  confirmButtonText: `Simpan`,
									  cancelButtonText: `Batal`,
									}).then((result) => {
									  /* Read more about isConfirmed, isDenied below */
									  console.log(result);
									  if (result.dismiss === 'cancel') {
										Swal.fire('Tidak', '', 'info');
									  } else if (result.value === true) {
										window.location = "{{ url('gudangpupukarea/simpan_permintaan_gudang') }}" + "?id=" + id;
									  }
									})				
					}
				})
	}
}

	
</script>


@endsection