@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Inventori</a></li>
			<li class="active">Transfer Barang Antar Gudang</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Transfer Barang Antar Gudang</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<a href="{{ url('transfergudang/formtambah') }}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a>
	    	<a href="javascript:void(0);" class="btn btn-info" data-toggle="modal" data-target="#laporan_rekap" style="margin-bottom: 1%;"><i class="fa fa-print"></i>&nbsp;Laporan Rekap</a>
	    </div>

	    <table class="table table_trans table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>No. Faktur</th>
					<th>Gudang Awal</th>
					<th>Gudang Tujuan</th>
					<th>Tanggal</th>
					<th>Tanggal Terima</th>
					<th>Status</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>
				
				
			</tbody>
	    </table>
	</div>
</div>

<!---Modal Rekap Laporan--->
<div class="modal fade modal-cetak" id="laporan_rekap" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-sm" role="document">
	    <div class="modal-content">
	    	<div class="modal-header with-border">
	    		<h5 class="modal-title">Laporan Rekap Transfer Barang Antar Gudang</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      		<form class="form-horizontal" autocomplete="off" method="get" action="{{url('transfergudang/rekap-laporan')}}" target="_blank">
			      	<div class="modal-body">
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Tanggal Awal</label>
				    			<div class="col-sm-8">
				    				<input class="form-control date_awal" type="text" name="tanggal_awal" value="{{ date('d-m-Y') }}" readonly required>
				    			</div>
			      			</div>
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Tanggal Akhir</label>
				    			<div class="col-sm-8">
				    				<input class="form-control date_akhir" type="text" name="tanggal_akhir" value="{{ date('d-m-Y') }}" readonly required>
				    			</div>
			      			</div>
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Gudang Asal</label>
				    			<div class="col-sm-8">
				    				<select name="gudang_asal" class="form-control set_selected" required="">
					    				<option value="">Pilih Gudang Asal</option>
					    				@foreach($gudang AS $key => $value)
					    					<option value="{{ $value->id }}">{{ $value->nama_gudang }}</option>
					    				@endforeach
					    			</select>
				    			</div>
			      			</div>
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Gudang Tujuan</label>
				    			<div class="col-sm-8">
				    				<select name="gudang_tujuan" class="form-control set_selected" required="">
					    				<option value="">Pilih Gudang Tujuan</option>
					    				@foreach($gudang AS $key => $value)
					    					<option value="{{ $value->id }}">{{ $value->nama_gudang }}</option>
					    				@endforeach
					    			</select>
				    			</div>
			      			</div>
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Status</label>
				    			<div class="col-sm-8">
				    				<select name="status" class="form-control set_selected" required="">
					    				<option value="1">Dikeluarkan Gudang Asal</option>
					    				<option value="2">Diterima Gudang Tujuan</option>
					    			</select>
				    			</div>
			      			</div>
			      			<div class="form-group">
			      				<label class="control-label col-sm-4">Filter Tanggal</label>
				    			<div class="col-sm-8">
				    				<select name="filter_tanggal" class="form-control set_selected" required="">
					    			</select>
				    			</div>
			      			</div>
			      	</div>
			      	<div class="modal-footer">
			        	<button type="reset" class="btn btn-default" data-dismiss="modal" id="btn_batal_cetak_pepenjualan">Batal</button>
			        	<button type="submit" class="btn btn-primary" >Cetak</button>
			      	</div>
	      		</form>
	    </div>
	</div>
</div>
<script type="text/javascript">

	var table_trans;

	$(document).ready(function(){
		$(".set_selected").select2();
		table_trans = $(".table_trans").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('transfergudang/get_data') }}',
	        columns: [
	            {data: 'awal', name: 'awal', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
			  	{data: 'faktur', name: 'faktur'},
	            {data: 'awal', name: 'awal'},
	            {data: 'tujuan', name: 'tujuan'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'tanggal_masuk', name: 'tanggal_masuk'},
	            {data: 'status', name: 'status'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        "order": [[ 6, "desc" ]]
		});
		
		$("[name=status]").val('1').trigger('change');

	})

	function hapus(id){
		swal({
			title: 'Anda yakin akan menghapus item ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('transfergudang/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						table_trans.ajax.reload();
					}
				})
		 	}
		})
	}

	$("[name=status]").change(function(){
		var stat = $(this).val();

		if(stat == '1'){
			$("[name=filter_tanggal]").html('<option value="1">Sesuai Tanggal Keluar</option>');
		}else{
			$("[name=filter_tanggal]").html('<option value="1">Sesuai Tanggal Keluar</option> <option value="2">Sesuai Tanggal Terima</option>');
		}
	})
</script>


@endsection