@if(Auth::user()->hasAnyPermission(['All','View Subhead']))
<div class="table-responsive table-height">
    <table class="table table-hover table-outline table-vcenter text-nowrap card-table ">
      <thead>
        <tr>
          
          <th>#</th>
          <th>Code</th>
          <th>Name</th>
          <th>Type</th>
          <th>Status</th>

          <th>Closing Balance</th>
          <th>Date Created</th>
          <th></th>
        </tr>
      </thead>
      <tbody>

        @isset($subhead)
         
          @foreach($subhead as $rows)

          @php($balance = $journal->getClosingBalance(['head_id' => $rows->head_id],['id' => $rows->id]))

           
        <tr>
          <td>{{$loop->iteration}}</td>
          <td>{{$rows->code}}</td>
          <td>{{$rows->name}}</td>                          
          <td>{{$rows->type}}</td>
          <td>
            @if($rows->flag == 1)
              <span style="font-weight: bolder; font-size: 10pt;" class="badge badge-info badge-bolder"><strong>System Generated</strong></span>
            @else 
              <span style="font-weight: bolder; font-size: 10pt;" class="badge badge-success badge-bolder"><strong>Manual</strong></span>
            @endif
          </td>
          <td>

            @if($balance < 0 && in_array($rows->head->nature,['Capital / Equity','Long-term Liability','Short-term Liability','Revenue']))
                ({{EF::numberFormat(abs($balance))}})
            @else
                {{EF::numberFormat(($balance))}}
            @endif

          </td>
          <td>{{EF::dateFormat($rows->created_at)}}</td>
            <td class="text-center">
                  <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','Update Subhead']))
                            @if(true)
                                <a onclick="showUpdateSubHeadModel(event,'{{Crypt::encrypt($rows->id)}}')" href="javascript:void(0)" class="dropdown-item" data-toggle="modal" data-target="#md_update_subhead"><i class="dropdown-icon fa fa-edit"></i> Update</a>
                            @endif
                          @endif
                      
                          @if(Auth::user()->hasAnyPermission(['All','Remove Subhead']))
                            @if($rows->flag == "0" && ($rows->countLedgerByAccount($rows->id)) == 0)
                                <a onclick="removeSubhead(event,this);" href="{{route('subhead.trash',['id' => Crypt::encrypt($rows->id)])}}" class="dropdown-item " content="remove subhead"><i class="dropdown-icon fa fa-trash"></i> Remove</a>
                            @endif
                          @endif

                          @if(Auth::user()->hasAnyPermission(['All','View Ledger']))
                            <a href="{{route('subhead.viewledger',['id'=>Crypt::encrypt($rows->id)])}}" class="dropdown-item " ><i class="dropdown-icon fa fa-eye"></i> View Ledger</a>
                          @endif
                    </div>
                  </div>
               </td>
          </tr>
      	@endforeach
        @endisset
        
      </tbody>
    </table>
  </div>
  @endif