@extends('layouts.app')

@section('content')
<div class="panel panel-default">
    <div class="panel-heading">Miscellaneous Charges</div>
    

    <div class="panel-body">
    	<a class="btn btn-primary" href="{{ route('charges.create')}}">Add new fee</a>
       	<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" 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>
						
						@endif
					</td>
					
				</tr>
			@endforeach
		</table>

		<?php echo $charges->render(); ?>
    </div>
</div>
@endsection