@extends('layouts.master')

@section('content')
<div class="content">
	<div class="row">
		<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title">Expense Report</h3>
				</div>
				<div class="panel-body">
					<div class="form-inline">
						<div class="form-group">
						<input type="text" name="from_date" id="from_date" placeholder="From Date" class="form-control date">
						</div>
						<div class="form-group">
						<input type="text" name="to_date" id="to_date" class="form-control date" placeholder="To Date">
						</div>
						<div class="form-group">
							<select name="acc_head" id="acc_head" class="form-control">
								<option value="">Select Expense Head</option>
								@if($credit_heads)
								@foreach($credit_heads as $row)
								<option value="{{ $row->id }}">{{ $row->name }}</option>
								@endforeach
								@endif
							</select>
						</div>
						<div class="form-group">
						<button type="button" id="btn_search" class="btn btn-default">
						<i class="fa fa-search"></i> Search</button>
						</div>
						<div class="form-group">
						<button type="button" id="btnClear" class="btn btn-default"><i class="fa fa-times"></i> Clear</button>
						</div>
					</div>
					<br><br>
					<div id="reportContent">
						
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
@stop

@section('script')
<script type="text/javascript">
$(document).ready(function() {
	 $( ".date" ).datepicker({
          changeMonth: true,
          changeYear: true,
          dateFormat:"yy-mm-dd"
     });

	 /**
	  * generate expense report
	  */
	 $('#btn_search').click(function(){
	 	var from_date=$('#from_date').val();
	 	var to_date=$('#to_date').val();
	 	var acc_head=$('#acc_head').val();
	 	var token='{{ csrf_token() }}';

	 	$.ajax({
	 		url: '{{ url('account/report/expense') }}',
	 		type: 'POST',
	 		data: {from_date: from_date,to_date:to_date,acc_head:acc_head,_token:token}
	 	})
	 	.done(function(res) {
	 		$('#reportContent').html(res);
	 	});
	 	
	 });

	 $('#btnClear').click(function(){
	 	$('#from_date').val('');
	 	$('#to_date').val('');
	 	$('#acc_head').val('');
	 });

});
</script>
@stop