@extends('layouts.dashboard')

@section('page_title')
  Accounts
@endsection

@section('page_header_title')
  Manage Account
@endsection



@section('page_body')
{{ Breadcrumbs::render('head') }}

@foreach($chart_of_account as $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 nature-color">&nbsp;&nbsp;</i>
                </a>
              <h3 class="card-title nature-color">  {{$rows['code']}} - {{$rows['nature']}}</h3>

              @php($balance = $journal->getClosingBalance(['nature' => $rows['nature']]))

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

              <div class="card-options">
                @php($head_tag = str_replace(' ','_',strtolower('head_'.$rows['nature'])))
               
                @if(Auth::user()->hasAnyPermission(['All','Add Head']))
                <abbr title="Add Head">
                <a href="javascript:void(0)" data-toggle="modal" data-target="#md_add_head"  onclick="showHeadModel(event,'{{$head_tag}}','{{$rows['nature']}}')" class="btn btn-sm btn-primary "><i class=" fe fe-plus"></i></a>
                </abbr>
                @endif

              </div>

          </div>
          
          <div class="card-body">

            <div id="{{$head_tag}}">
            
              @php($head_data['head_list']   = $rows['head_list'])

              @php($head_data['accountObj']  = $accountObj)

              @php($head_data['nature']  = $rows['nature'])

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


              @php($head_view = view('components.head.head_tabs',$head_data))

              {!! $head_view !!}

           </div>
            
          
          </div>
        </div>
      </div>
    </div>
  @endforeach



{{--
  <div class="row row-cards row-deck">
              <div class="col-12">
                <div class="card">
                    <div class="card-header">
              
             
              
          @if(Auth::user()->hasAnyPermission(['All','Add Head']))
               <a href="javascript:void(0)" class="float-right btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_add_head"><i class="fa fa-plus"></i></a> &nbsp;&nbsp;
               @endif

               <h3 class="card-title">Add Head</h3>
            </div>

                  <div class="card-status card-status-left bg-blue"></div>
                  <div class="table-responsive table-height">
                    <table class="table table-hover table-outline table-vcenter text-nowrap card-table cls_datatable">
                      <thead>
                        <tr>
                          
                          <th>#</th>
                          <th>Code</th>
                          <th>Name</th>
                          <th>Nature</th>
                          <th>{{ucwords(str_replace('_',' ',EF::branchWhiteLabel()['module']))}}</th>

                          <th>Date Created</th>
                          <th></th>
                        </tr>
                      </thead>
                      <tbody>
                        @isset($head)
                          @php($pass_data = [])
                          @foreach($head as $rows)

                            @php(
                              $pass_data = array(
                                  'head_id'     => Crypt::encrypt($rows->id),
                                  'branch'      => trim($rows->branch->code.' '.$rows->branch->name),
                                  'name'        => $rows->name,
                                  'nature'      => trim($rows->nature),
                                  'code'        => ($rows->code),

                               
                                )
                            )
                        <tr>
                          <td>{{$loop->iteration}}</td>
                          <td>{{$rows->code}}</td>
                          <td>{{$rows->name}}</td>                          
                          <td>{{$rows->nature}}</td>
                          <td>{{$rows->branch->name}}</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','Add SubHead','View SubHead']))
                                      <a href="{{url('subhead',['id' => Crypt::encrypt($rows->id)])}}" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Create /  View Sub Head</a>
                                      @endif
                                      @if(Auth::user()->hasAnyPermission(['All','Update Head']))
                                      <a onclick="update(event,'{{json_encode($pass_data)}}','form_update_head','md_update_head')" href="javascript:void(0)" class="dropdown-item" data-toggle="modal" data-target="#md_update_head"><i class="dropdown-icon fa fa-edit"></i> Update  </a>
                                      @endif
                                        @if(Auth::user()->hasAnyPermission(['All','Remove Head']))

                                      @if(!$rows->isexsitSubhead($rows->id) && $rows->flag == "0")
                                      <a href="{{route('head.trash',['id' => Crypt::encrypt($rows->id)])}}" class="dropdown-item cls_delete" content="remove head"><i class="dropdown-icon fa fa-trash"></i> Remove</a>
                                      @endif
                                      @endif
                                      
                                 

                                     
                                     
                                    </div>
                                  </div>
                               </td>
                        </tr>
                        @endforeach
                        @endisset
                        
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
          </div>
          --}}
@endsection

@section('page_modal')

@if(Auth::user()->hasAnyPermission(['All','Add Head']))
  @include('accounts.modals.add_head')
@endif

@if(Auth::user()->hasAnyPermission(['All','Update Head']))
  @include('accounts.modals.update_head')
@endif

  <div id="add_subhead_modal"></div>
  <div id="update_subhead_modal"></div>


  @include('bank.modals.add_bank')


@endsection

@section('page_script')

  @include('scripts.head')

  @include('scripts.subhead')

  @include('scripts.bank')
  
@endsection

  