@extends('layouts.masterHome2')

@section('content')


 
    
    <div class="card">
               
              <!-- /.card-header -->
              <div class="card-body">
                <table id="example1" class="table table-bordered table-striped">
                  <thead>
                  
                 <tr >
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> تاريخ نشأة السند    </th>
                  
                <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> رقم سند القبض    </th>
                                    
                  
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> المقبوض منه    </th>
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> الفاتورة    </th>
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> المبلغ    </th>
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> ايداعات/شيكات    </th>
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> الحسابات الاخري    </th   >
                  
                                     <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> التبويب    </th>


                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> نظير    </th>
                  <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;"> ملاحظات    </th>                  


                <th style="text-align:center;vertical-align: middle;background-color:#2C4E71;color:#FFF;border-color:#0000003c;border-width: 2px;">  Actions    </th>

                 </tr>
                 </thead>
              <tbody>
                           
                @foreach( $receipts as $receipt )   
                 
                 

                 
                <tr>
                 
                  <td style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px" >{{$receipt->created_at}} </td> 
                  
                <td style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px" >{{$receipt->id}} </td>
                                    
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> {{$receipt->client_id?$receipt->client->name:''}}  
                      {{$receipt->general_name}}
                  </th>
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> 
                  
                  <a   href='{{url("/invoice/details/$receipt->invoice_id")}}'  > {{$receipt->invoice_id ? "#". $receipt->invoice_id:""}} </a>  
                     
                 </th>
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> {{$receipt->pay}}    </th>
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> 
                  <a   href=''  > {{$receipt->cheque_id ? "#".$receipt->cheque_id:"" }} </a>    
                  
                    </th>
                    <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> {{$receipt->safe_account ? $receipt->safe_account->payment_method->name ." -- ".$receipt->safe_account->branch->name  :""}}    </th>    
                    <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px">  {{ $receipt->tab_id ? $receipt->tab->name : '' }}   <br>  
                        <a   style="
    background:#cbd5e1;
    color:#0f172a;
    padding:6px 12px;
    border-radius:20px;
    font-size:13px;
    font-weight:600;
    text-decoration:none;
    display:inline-block;
   "
 href='{{ url("/tab/tabulate_voucher/$receipt->id") }}'  target="_blank"  >
                            <i class="fas fa-edit"></i>
                             </a>
                   </th>
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> {{$receipt->note1}}    </th>
                  <th style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px"> {{$receipt->note2}}    </th>
                  
                  <td style="text-align:center; word-break: break-word; font-weight:900;border-color:#0000003c;font-size:18px" >  <a   href='{{url("/receipt/print/$receipt->id")}}'> Print</a> </td>
                  
                </tr>
               @endforeach
                </tbody>
                </table>
                
                
                
                
                
                                                 <div style="display: flex; justify-content: center; margin: 20px 0; font-family: Arial, sans-serif;">
    <div style="display: inline-flex; border-radius: 5px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.2);">
        {{-- Previous Page Link --}}
        @if ($receipts->currentPage() <= 1)
            <span style="padding: 8px 12px; background: #f0f0f0; color: #aaa; border-right: 1px solid #ddd;">
                &laquo;
            </span>
        @else
            <a href="{{ $receipts->url($receipts->currentPage() - 1) }}" style="padding: 8px 12px; background: #fff; color: #337ab7; text-decoration: none; border-right: 1px solid #ddd; transition: all 0.3s;">
                &laquo;
            </a>
        @endif

        {{-- Pagination Elements --}}
        @php
            // Calculate start and end pages
            $current = $receipts->currentPage();
            $last = $receipts->lastPage();
            $start = max($current - 2, 1);
            $end = min($current + 2, $last);
            
            // Always show first page
            if ($start > 1) {
                $start = 1;
            }
        @endphp

        @for ($i = $start; $i <= $end; $i++)
            @if ($i == $receipts->currentPage())
                <span style="padding: 8px 12px; background: #337ab7; color: white; border-right: 1px solid #2a6496;">
                    {{ $i }}
                </span>
            @else
                <a href="{{ $receipts->url($i) }}" style="padding: 8px 12px; background: #fff; color: #337ab7; text-decoration: none; border-right: 1px solid #ddd; transition: all 0.3s;">
                    {{ $i }}
                </a>
            @endif
        @endfor

        {{-- Next Page Link --}}
        @if ($receipts->currentPage() >= $receipts->lastPage())
            <span style="padding: 8px 12px; background: #f0f0f0; color: #aaa;">
                &raquo;
            </span>
        @else
            <a href="{{ $receipts->url($receipts->currentPage() + 1) }}" style="padding: 8px 12px; background: #fff; color: #337ab7; text-decoration: none; transition: all 0.3s;">
                &raquo;
            </a>
        @endif
    </div>
</div>
                
                
                
                
                
              </div>
              <!-- /.card-body -->
            </div>  

@endsection
