@if(Auth::user()->hasAnyPermission(['All','View Side Payment']))
<div class = "col-md-12 col-sm-12">
  <div class= "card card-collapsed">
    <div class="card-status bg-red">
    </div>
    <div class="card-header">

    @if(Auth::user()->hasAnyPermission(['All','Add Side Payment']))
     <button  class="float-right btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_add_commission"><i class="fa fa-plus"></i></button> &nbsp;&nbsp;
     @endif


     <h3 class="card-title">Manage Side Payments</h3>

     <div class="card-options">
       <a onclick="cardCollapseOnce(event,this);" href="#" class="card-options-collapse btn btn-sm btn-outline-primary" >View <i class="fe fe-chevron-up"></i></a>

     </div>


   </div>
   <div class="alert alert-primary card-alert mb-0">
     Commissions / Document & Miscellaneous Charges
   </div>

   <div class=" table-responsive booking-table-height">
    <table class="table table-hover  table-outline table-vcenter scrollbar-primary text-nowrap card-table">
      <thead>
        <tr>

          <th>Sr #</th>
          <th>Name</th>
          <th>Description</th>
          <th>Amount</th>
          <th>Received</th>
          <th>Balance</th>


          <th>Status</th>
          <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>
        </tr>
      </thead>
      <tbody>
        @isset($commission_list)
        @foreach($commission_list as $rows)

        @php($pass_data = [])

        @php($charges_data = [])



        @php(
        $pass_data = array(
        'id'                  => Crypt::encrypt($rows->id),
        'percentage'          => $rows->percentage,
        'updateamount'        => $rows->amount,
        'amount_in_words'     => EF::numberToWords($rows->amount),
        'description'         => trim($rows->description),
         'name'               => $rows->user->name,
         'user_type'          => $rows->role->name,
        )
        )

        @php(
         $charges_data = array(
        'id'                  => Crypt::encrypt($rows->id),
        'charges_type'        => $rows->payment_type,
        'chargesamount'       => $rows->amount,
        'amount_in_words'     => EF::numberToWords($rows->amount),
        'description'         => trim($rows->description),

        )
        )


        {{--
             THIS ARRAY CLOSE DUE TO ATTACH PAYMENT LEVEL BETWEEN VOUCHER
          @php($payment = array(

        'installment'      => Crypt::encrypt($rows->id),
        'installment_type' => 'Commission',
        'amount'           => ($rows->amount - $rows->received_amount),
        'description'      => $rows->description,
        'user'             => Crypt::encrypt($rows->user->id),
        'name'             => $rows->user->name,
        'user_type'        => $rows->user->type,
        'payment_type'     => $rows->payment_type,
        ))
        --}}


                         @php($payment = array(

                            'installment'      => Crypt::encrypt('0'),
                            'commission'       => Crypt::encrypt($rows->id),
                            'amount'           => ($rows->amount - $rows->received_amount),
                            'amount_in_words'  => EF::numberToWords($rows->amount - $rows->received_amount),
                            'description'      => $rows->description,
                            'user'             => Crypt::encrypt($rows->user_id),
                            'booking'          => Crypt::encrypt($booking->id),
                            'user_type'        => $rows->role->name,
                            'user_name'        => $rows->user->name,
                            EF::branchWhiteLabel()['module'] => $booking->branch->name,




                            'booking_detail'   => $booking->ms.' ('.$plot->plot_id.' '.$plot->category.')',

                            'payment_type'     => $rows->payment_type,

                         ))


        <tr>
          <td>{{$loop->iteration}}</td>
          <td>{{ucfirst($rows->user->name)}} ({{$rows->role->name}})</td>

          <td style ="word-wrap: break-word;">{{$rows->payment_type}}</td>
          <td>{{EF::numberformat($rows->amount)}}</td>
          <td>{{EF::numberformat($rows->received_amount)}}</td>
          <td>{{EF::numberformat($rows->amount - $rows->received_amount)}}</td>


          <td>@if($rows->status === "Paid")
                @if($rows->payment_type === "Commission") Paid @else Received @endif
                @else
                {{$rows->status}}
               @endif
            </td>
          @if(Auth::user()->hasAnyPermission(['All','Add Payment','Update Side Payment','Remove Side Payment']))
          <td class="text-center">
            @if($rows->status == 'Unpaid')
            <div class="item-action dropdown">
              <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fa fa-list-ul"></i></a>
              <div class="dropdown-menu dropdown-menu-right">

               @if(Auth::user()->hasAnyPermission(['All','Add Payment']) && $rows->amount > 0)
               <a href="#" id="pay" class="dropdown-item" onclick="showPayPaymentModel(event,'{{Crypt::encrypt(EF::getGenericTableIndex()['Commission'])}}','{{Crypt::encrypt($rows->id)}}')"><i class="dropdown-icon fa fa-money"   ></i> Pay </a>
               @endif
                  @if(Auth::user()->hasAnyPermission(['All','Update Side Payment']))
             @if($rows->payment_type == 'Commission')
               <a onclick="update(event,'{{json_encode($pass_data)}}','form_update_commission','md_update_commission','form_update_charges')" href="#" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Update </a>

               @else
                  <a value = "{{$rows->payment_type}}" onclick="updateCharges(event,'{{json_encode($charges_data)}}','md_update_commission')" href="#" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Update </a>
               @endif
               @endif

               @if(Auth::user()->hasAnyPermission(['All','Remove Side Payment']))
                  <a href="{{route('commission.trash',['id' => Crypt::encrypt($rows->id)])}}" content ="remove charges" class="dropdown-item  cls_delete"><i class="dropdown-icon  fa fa-trash"></i> Remove </a>
              @endif

             </div>
           </div>
           @endif
         </td>
        @endif
       </tr>

       @endforeach
       @endisset
     </tbody>
   </table>
 </div>


</div>
</div>
@endif
