@extends('layouts.app')

@section('content')
<div class="panel panel-default">
    <div class="panel-heading">Miscellaneous Charges found by '{{$search_query}}'</div>
    

    <div class="panel-body">
       	<form method="post" action="{{ route('charges.search')}}"  >
	    <input type="hidden" value="{{csrf_token()}}" name="_token" />
	        <div class="form-group">
	            <label for="title">Search charges by description or customer:</label>
	            <input type="text" value="{{$search_query}}" class="form-control" name="search" v/>
	        </div>
	         <button type="submit" class="btn btn-primary">search</button>
	     </form>

        <table class="table">
        <thead>
        	<tr>
        		<th>customer</th>
        		<th>description</th>
        		<th>fee</th>
        		<th>invoice date</th>
        		
        		<th>invoice number</th>
        		        		
        		<th></th>
        	</tr>
        </thead>
			@foreach( $charges as $charge )
				<tr >
					<td>
						@if( $charge->customer_id == 0 )
						<div style="color: red">Not linked to customer</div>
						@else
						<div style="color: green">{{$charge->customer->xero_name}}</div>
						@endif
					</td>
					<td>
						{{$charge->description}}
					</td>
					<td>
						{{$charge->price}}
					</td>
					<td>
						{{$charge->date_invoice}}
					</td>
					@if( $charge->invoiced == 1 )
	        		<td>{{$charge->invoice}}</td>
	        		@else
	        		<td>not invoiced yet</td>
	        		@endif  
					<td> 
						
						@if( $charge->invoiced == 0 )
						<a  class="btn btn-primary" href="{{ route('charges.edit',$charge->id)}}">Edit</a>
						<form style="float: right;"  onsubmit="return confirm('Do you really want to delete this charge?');" action="{{ route('charges.destroy', $charge->id)}}" method="post" style="margin-bottom: 10px;">
					          {{ csrf_field() }}
					          {!! method_field('delete') !!}
					          <button  class="btn btn-danger" type="submit">Delete</button>

					        </form>
						@endif
					</td>
					
				</tr>
			@endforeach
		</table>

    </div>
</div>
@endsection