
        <table class="table">
            <thead>

@if(Config::get('app.locale') == "ar")
                <tr>
                    <th>#</th>
                    <th>اسم العميل</th>
                    <th style="display: none;">اسم البائع</th>
                    <th>اجمالي الفاتورة</th>
                    <th>الخصم </th>
                    <th>المدفوع </th>
                    <th>الارباح </th>
                    <th>الحالة</th>
                    <th>التاريخ</th>
                    <th> الغاء الفاتورة </th>
                    <th><i class="fa fa-trash"></i></th>
                </tr>
@else
                <tr>
                    <th>ID</th>
                    <th>Customer Name</th>
                    <th>User</th>
                    <th>Total</th>
                    <th>Discount </th>
                    <th>Paid </th>
                    <th>Profit </th>
                    <th>Status</th>
                    <th>Created At</th>
                    <th><i class="fa fa-trash"></i></th>
                </tr>
@endif


            </thead>
            <tbody >
                <?php
                $the_total = 0;
                $all_paid_total = 0;
                $the_discount = 0;
                $total_profit = 0;

                ?>
                @foreach ($orders as $order)

<?php 
$bankak_paid = \App\Models\Payment::where('order_id',$order->id)->first()->bankak;
$cash_paid = \App\Models\Payment::where('order_id',$order->id)->first()->cash;
$shake_paid = \App\Models\Payment::where('order_id',$order->id)->first()->shake;
$invoice_amount = \App\Models\Payment::where('order_id',$order->id)->first()->amount;


$all_paid = $bankak_paid + $cash_paid + $shake_paid;
?>


                <tr>
                    <td><a href="#" onclick="window.open('<?php echo url('admin/ticket/'); ?>/<?php echo $order->id; ?>','','width=400,height=500');">{{$order->id}}</a></td>
                    <td>{{$order->getCustomerName()}}</td>
                    <td style="display: none;">{{$order->user->first_name}} {{$order->user->last_name}} </td>
                    <td>{{ config('settings.currency_symbol') }} {{$order->formattedTotal()}}</td>
                    <td>{{ config('settings.currency_symbol') }} {{$order->discount}}</td>
                  

                    <td>{{ config('settings.currency_symbol') }} 

{{ $all_paid }} 

                    </td>


                    <td style="">{{ config('settings.currency_symbol') }} 

{{ $order->net_profit  }} 

                    </td>


                    <td>

                        @if($all_paid == 0)
                            <span class="badge badge-danger">غير مدفوع</span>
                        @elseif($all_paid < $order->total())
                            <span class="badge badge-warning">مدفوع جزئي</span>
                        @elseif($all_paid == $order->total())
                            <span class="badge badge-success">مدفوعة </span>
                        @elseif($all_paid > $order->total())
                            <span class="badge badge-info">لديه متبقي</span>
                        @endif
                    </td>
                    

                    <td>{{$order->created_at}}</td>

                    
                    

                    <td>
                        
                        <a onclick="return confirm('<?php echo __('هل انت متأكد ؟') ?>');" href="{{url('refund')}}/{{$order->id}}">
                          <span class="badge badge-danger"><i class="fas fa-close"></i> الغاء الفاتورة </span>
                        </a>

                    </td>
                    <td> 


		
      @if(auth()->user()->id  == '4') 
                            <span class="btn btn-danger btn-sm" >
                                <form action="{{url('/admin/orders/')}}/{{ $order->id }}" method="post">
                                    @method('DELETE')
                                    <button onclick="return confirm('Are you sure you want to delete this ?');" style="border: 0px; background:none; color: white">
                                        <i class="fas fa-trash"></i>
                                        Delete</button>
                                    @csrf
                                </form>


                            </span>
                       @endif 

                    </td>
                </tr>

                <?php 
                $all_paid_total = $all_paid_total + $all_paid;
                $the_total = $the_total + $order->total();
                $the_discount = $the_discount + $order->discount;
                $total_profit = $total_profit + $order->net_profit;
                ?>
                @endforeach
            </tbody>
            <tfoot>
                <tr>
                    <th></th>
                    <th></th>
                    <th>{{ config('settings.currency_symbol') }} {{ number_format($the_total, 2) }}</th>
                    <th>{{ config('settings.currency_symbol') }} {{ number_format($the_discount, 2) }}</th>
                    
                    <th>{{ config('settings.currency_symbol') }} {{ number_format($all_paid_total - $the_discount, 2) }}</th>

 <th>{{ config('settings.currency_symbol') }} {{ number_format($total_profit, 2) }}</th>

                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </tfoot>
        </table>
        {{ $orders->render() }}

