@extends('layouts.app')

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


    <div class="panel-body">
        @if ($errors->any())
            <div class="alert alert-danger">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div><br />
        @endif
           <form method="post" class="create_billing_form" action="{{ route('charges.update', $charge->id)}}" >
            <input type="hidden" value="{{csrf_token()}}" name="_token" />
           
                <div class="form-group">
                    <label for="title">Customer:</label>
                    <select data-live-search="true" class="form-control" name="customer_id">
                        <option value="0">None</option>
                        @foreach($customers as $customer)
                            <option data-tokens="{{$customer->xero_name}}" @if( $customer->id == $charge->customer_id ) selected @endif value="{{$customer->id}}">{{$customer->xero_name}}</option>
                        @endforeach
                    </select>
                </div>

                <div class="form-group">
                    <label for="title">description :</label><br>
                    <input type="text" class="form-control" name="description" value="{{$charge->description}}"/>
                </div>

                <div class="form-group">
                    <label for="title">fee :</label>
                    <input type="text" class="form-control" name="price" value="{{$charge->price}}"/>
                </div>


                 
                <div class="form-group">
                    <label for="title">date invoice :</label>
                    <select class="form-control" name="date_invoice">
                        <option @if( $charge->date_invoiced == 'next_day' ) selected  @endif value="next_day">Next day</option>
                        <option @if( $charge->date_invoiced == 'end_of_the_week' ) selected  @endif value="end_of_the_week" value="end_of_the_week">End of the week</option>
                        <option @if( $charge->date_invoiced == 'end_of_the_month' ) selected  @endif value="end_of_the_month" value="end_of_the_month" >End of the month</option>
                    </select>
                </div>
                 @if( $charge->invoiced == 0 )
                
                @endif
               
                 <button style="float: right;" type="submit" class="btn btn-primary">Save</button>
             </form>
             <form style="float: left;"  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>
    </div>
</div>
@endsection