<!-- HEAD LIST -->

@foreach($head_list as $head_rows)
  <div class="row">
    <div class="col-lg-12 col-xl-12">
      <div class="card card-collapse card-collapsed">
        <div class="card-header">
           <a style="vertical-align: middle; text-decoration: none; margin-top: 3px;" href="#" class="card-options-link cls_collapsed " ><i class="icon fe fe-plus head-color">&nbsp;&nbsp;</i>
               </a>
          <h3 class="card-title head-color">{{$head_rows->code}} - {{$head_rows->name}}</h3>
              @php($balance = $journal->getClosingBalance(['id' => $head_rows->id]))


              <small class="head-color" style="margin-left: 10px;"> 
                  @if($balance < 0 && in_array($head_rows->nature,['Capital / Equity','Long-term Liability','Short-term Liability','Revenue']))
                ({{EF::numberFormat(abs($balance))}})
              @else
                  {{EF::numberFormat(($balance))}}
              @endif
              </small>


              @php($pass_data = [])

                @php(
                    
                    $pass_data = array(

                      'head_id'     => Crypt::encrypt($head_rows->id),
                      'branch'      => trim($head_rows->branch->code.' '.$head_rows->branch->name),
                      'name'        => $head_rows->name,
                      'nature'      => trim($head_rows->nature),
                      'code'        => ($head_rows->code),
                    )
                )

            <div class="card-options">
                @if(Auth::user()->hasAnyPermission(['All','Add Subhead']))    
                  <abbr title="Add Subhead">
                    <a href="javascript:void(0)" onclick="showSubHeadModel(event,'{{Crypt::encrypt($head_rows->id)}}')" class="btn btn-sm btn-primary"><i class=" fe fe-plus"></i></a>&nbsp;
                  </abbr>
                @endif

                @if(Auth::user()->hasAnyPermission(['All','Update Head']))    
                  <abbr title="Update Head">
                    <a  href="javascript:void(0)" onclick="update(event,'{{json_encode($pass_data)}}','form_update_head','md_update_head');" data-toggle="modal" data-target="#md_update_head" class="btn btn-sm btn-primary"><i class=" fe fe-edit"></i></a>&nbsp;
                  </abbr>
                @endif

                @if(Auth::user()->hasAnyPermission(['All','Remove Head']))    
                  @if($head_rows->flag === "0")
                    <abbr title="Remove Head">
                      <a onclick="removeHead(event,this)" href="{{route('head.trash',['id' => Crypt::encrypt($head_rows->id)])}}" content="remove head" class="btn btn-sm btn-primary"><i class=" fe fe-trash"></i> </a>
                    </abbr>
                  @endif
                @endif
            </div>
        </div>
        
        @php($subhead_tag = 'subhead_'.$nature.$head_rows->id)
        <div id="head_section_{{$head_rows->code}}" class="card-body" >

              @php($subhead['subhead']  = $accountObj->getSubHeadByHead($head_rows->id))

              @php($subhead['head']     = $head_rows)

              @php($subhead['journal']     = $journal)


          

              @php($subhead_view = view('components.subhead.subhead_table',$subhead))
    
             {!! $subhead_view !!}

        </div>
      </div>
    </div>
  </div>
@endforeach
<!-- END HEAD LIST -->