@extends('layouts.dashboard')
@section('page_title')
Manage Stocks
@endsection
@section('page_header_title')
Manage Stock
@endsection
@php($label_list = EF::getWhiteLabel())

@section('page_body')
{{ Breadcrumbs::render('payable.view') }}

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



					     <h3 class="card-title">Payables</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>GRN No.</th>
                          <th>PO No.</th>
                          <th>Item</th>
                          <th>Total Amount</th>
                          <th>Received Amount</th>
													<th>Project</th>
                          <th>Status</th>
                           <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>

                        </tr>
                      </thead>
                     <tbody>
                      @if(isset($payable_list))
                      @foreach($payable_list as $rows)
                        @php(

                            $id = array(
                            'payable'            => Crypt::encrypt($rows->id),
                            'total_amount'       => $rows->total_amount,
                            'received_amount'    => $rows->received_amount,
                            'payable_amount'     => $rows->total_amount - $rows->received_amount,
                            'amount_in_words'    => EF::numberToWords($rows->total_amount - $rows->received_amount),
                            )
                        )
                      <tr>
                        <td>{{$loop->iteration}}</td>
                        <td>{{$rows->grn->grn_number}}</td>
                        <td>{{$rows->purchaseOrder->p_number}}</td>
                        <td>{{$rows->purchaseOrder->boqitem->item->name}}</td>
                        <td>{{EF::numberFormat($rows->total_amount)}}</td>
                        <td>{{EF::numberFormat($rows->received_amount)}}</td>
                        <td>{{$rows->purchaseOrder->boq->branch->name}}</td>
                        
                        <td>
                          @if($rows->status == "Approved")
                            <span class="badge badge-success">{{$rows->status}}</span>
                          @elseif($rows->status == "Pending")
                            <span class="badge badge-primary">{{$rows->status}}</span>
                          @else
                            <span class="badge badge-warning"> {{$rows->status}}</span>
                          @endif

                        </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','Pay Inventory Payable']) && $rows->status == 'Pending')
                               <div class="dropdown-divider"></div>

                                <a href="#" id="pay" class="dropdown-item" onclick="showPayPaymentModel(event,'{{Crypt::encrypt(EF::getGenericTableIndex()['Inventory Payable'])}}','{{Crypt::encrypt($rows->id)}}')"><i class="dropdown-icon fa fa-check"   ></i> Pay </a>
                               
                            {{-- <a onclick="update(event,'{{json_encode($id)}}','form_pay_payable','md_pay_payable')" href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fa fa-check"></i>Pay</a> --}}

                              @endif
                        </div>
                       </td>

                      </tr>
                      @endforeach
                      @endif
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
          </div>
@endsection

@section('page_modal')
   @include('inventory_module.payable.modals.pay_payable')
   <div id="modal_add_payment"> </div>

@endsection

@section('page_script')

@include('scripts.payment')

<script>
  function checkPayableAmount(event,obj)
  {
    var payable_amount = $(obj).val();

   var total_amount =  $('.total_amount').val();
   var received_amount =  $('.received_amount').val();

   var pending_amount = isDefaulter(total_amount)-isDefaulter(received_amount);


  if(payable_amount > pending_amount)
  {

  field_unsuccess($('#amount'),'Invalid  Payable Amount');


            return false;
  }
  if(payable_amount <= 0)
  {

     field_unsuccess($('#amount'),'Invalid  Payable Amount');


            return false;

  }

   field_refersh($('#amount'));


  }

  </script>

@endsection
