@extends('layouts.dashboard')

@section('page_title')
  Loan
@endsection

@section('page_header_title')
HR
@endsection



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

<div class="row row-cards row-deck">
  <div class="col-12">
                <div class="card">
                	  <div class="card-header">
					    
				   
					    

      @if(Auth::user()->hasAnyPermission(['All','Add Loan']))

      <button class="float-right btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_add_loan"><i class="fa fa-plus"></i></button> &nbsp;&nbsp;

      @endif

      <h3 class="card-title">Add Loan</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>Employee Name</th>
                          <th>Interest Rate</th>
                          <th>Number Of Months</th>
                          <th>Amount</th>
                          <th>Net Amount</th>
                          <th>Returned Amount</th>
                          <th>Status</th>
                          <th>Created Date</th>
                          <th></th>
                          <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>
                        </tr>
                      </thead>

                      <tbody>
                      	
@php($pass_data = [])
                       @foreach($loan_list as $rows)

@php(
      $pass_data = array(

        'loan'            => Crypt::encrypt($rows->id),
        'employee_name'   => $rows->user->name,
        'interest_rate'   => $rows->interest_rate,
        'no_of_months'    => $rows->no_of_months,
        'amount'          => $rows->amount,
        'net_amount'      => $rows->net_amount,
        'installment'     => $rows->installment,
        'amount_in_words'     => EF::numberToWords($rows->amount),
        'net_amount_in_words' => EF::numberToWords($rows->net_amount),
        'installment_amount_in_words' => EF::numberToWords($rows->installment)



         
      )

   )
   @php(

   
      $id = array(
      'loan'            => Crypt::encrypt($rows->id),
      )
   )
                       <tr>

                        @php($generic_index = EF::getGenericTableIndex()['Loan'])
                        @php($loan_payment = $payment->getPaymentByGenericIdWithType($rows->id,$generic_index,['Approve']))

                       

                       	<td>{{$loop->iteration}}</td>
                       	<td>{{$rows->user->name}}</td>
                        <td>{{$rows->interest_rate}}</td>
                    
                       	<td>{{EF::numberFormat($rows->no_of_months)}}</td>
                        <td>{{EF::numberFormat($rows->amount)}}</td>
                        <td>{{EF::numberFormat($rows->net_amount)}}</td>

                   
                        <td>{{EF::numberFormat($rows->GetReturnedAmountSum($rows->id))}}</td>
                        <td>@if($rows->is_initialize == 0)<span class = "badge badge-danger ">Unapproved</span>@else <span class = "badge badge-success ">Approved</span> @endif</td>
                        <td>{{EF::dateFormat($rows->created_at)}}</td>

                          <td><a href="{{EF::getFile($rows->loan_form)}}">View Document</a></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">
                                       <a href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fa fa-cogs"></i> Action</a>
                                 

           @if(Auth::user()->hasAnyPermission(['All','Update Loan'])&& 
           $rows->is_initialize == 0)
                       		     <div class="dropdown-divider"></div>
                       		<a onclick="update(event,'{{json_encode($pass_data)}}','form_update_loan','md_update_loan')" href="javascript:void(0)" class="dropdown-item" data-toggle="modal" data-target="#md_update_employee"><i class="dropdown-icon fa fa-edit"></i> Update</a>
                                      @endif


                          @if(Auth::user()->hasAnyPermission(['All','Approve Loan'])&& $rows->is_initialize == 0)
                               <div class="dropdown-divider"></div>
                               <a onclick="update(event,'{{json_encode($id)}}','form_approve_loan','md_approve_loan')" href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fa fa-check"></i>Approve Loan</a>
                      
                                      @endif

                          @if(Auth::user()->hasAnyPermission(['All','Manage Loan Installments'])&& $rows->is_initialize == 1)
                               <div class="dropdown-divider"></div>
                          <a onclick="initializeLoan(event,'{{Crypt::encrypt($rows->id)}}')" href="javascript:void(0)" class="dropdown-item" data-toggle="modal" data-target="#md_update_employee"><i class="dropdown-icon fa fa-edit"></i>Manage Installments</a>
                                      @endif



                       	</div>

                       </td>

                      </tr>
                       @endforeach

                      </tbody>
    	            </table>
                  </div>
                </div>
              </div>
            </div>
    



@endsection

@section('page_modal')
  @include('hr.loan.modals.add_loan')
  @include('hr.loan.modals.update_loan')
   @include('hr.loan.modals.approve_loan')

  <div id="initialize_loan">
    
  </div>

@endsection

@section('page_script')
  @include('hr.scripts.loan')
@endsection
