<table class="table table-bordered table-hover">
 <tr>
    <th>{{ __('Date') }}</th>
    <th>{{ __('Booking Number') }}</th>
    <th>{{ __('Ticket Number') }}</th>
    <th>{{ __('Passenger Name') }}</th>
    <th>{{ __('Office') }}</th>
    <th>{{ __('balance') }}</th>
    <th>{{ __('Status') }}</th>
    <th>{{ __('Fare') }}</th>
 </tr>

    @foreach ($tickets as $ticket)
                @foreach($ticket->transactions as $transaction)
                <tr class="{{ statusBg($ticket->ticket_status) }}">
                    <td>{{ $transaction->created_at->format('Y/m/d') }}</td>
                    <td>{{ $ticket->segment->booking->number }}</td>
                    <td>{{ $ticket->ticket_number }}</td>
                    <td>{{ $ticket->full_name}}</td>
                    <td>{{ $ticket->segment->booking->office->name }}</td>
                     <?php 
                           $amount=App\Models\Transaction::where('ticket_id', optional($transaction->ticket)->id)->where('amount','!=',0)->first();
                           
                      ?>
                   @if($transaction->amount !=0)
                   <td>{{formatPrice($transaction->balance )}}</td>
                   @else
                   <td>{{ formatPrice($transaction->balance) }}</td>
                   @endif
                   
                    @if($ticket->ticket_status=="R"&& $transaction->type=="expense")
                     <td>O </td>
                      @elseif($ticket->ticket_status=="V"&& $transaction->type=="expense")
                       <td>O </td>
                    
                       
                      @else
                      <td>{{ $ticket->ticket_status }}</td>
                    @endif
                    <?php 
                           $amount=App\Models\Transaction::where('ticket_id', optional($transaction->ticket)->id)->where('amount','!=',0)->first();
                       ?>
                        
                    @if($ticket->ticket_status =='R'  || $ticket->ticket_status=="V" && $transaction->type!="expense")
                      @if($ticket->hasRetour())
                              @if($transaction->amount==0)
                              
                                 <td>{{   formatPrice(optional ($amount)->amount )}}</td>
                               @else 
                               <td>{{ formatPrice($transaction->amount *-1 )}}</td>
                               @endif

                       @elseif($transaction->amount==0)
                        
                       <td>{{   formatPrice($amount->amount)}}</td>
                       @else
                       <td>{{ formatPrice($transaction->amount*-1 )}}</td>

                      @endif
                    @else
                    <td>{{ formatPrice($transaction->amount*-1 )}}</td>
                    @endif
                    
                 
                    
              
                </tr>   
                @endforeach
    @endforeach
</table>
