@extends('layouts.dashboard')

@section('page_title')
	Vendors
@endsection

@section('page_header_title')
	Manage Vendors
@endsection



@section('page_body')

{{ Breadcrumbs::render('vendors') }}

<div class="page-title-box">
              <div class="row align-items-center">
                <div class="col-auto">
                  <!-- Page pre-title -->
                  <div class="page-pretitle">
                    Overview
                  </div>
                  <h2 class="page-title">
                    Vendors

                  </h2>

                </div>
                @if(Auth::user()->hasAnyPermission(['All','Add Vendor'])) 

                 <div class="col-auto ml-auto d-print-none">
                  <div class="d-flex">
                    <!-- <input type="search" class="form-control d-inline-block w-9 mr-3" placeholder="Search"> -->
                    <a href="#" data-toggle="modal" data-target="#md_add_vendor" class="btn  btn-primary">
                      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
                      Create New Vendor
                    </a>
                  </div>
                </div>
               @endif
            </div>
        </div>

<div class="row">
  
  @foreach($vendor_list as $rows)

    @php($collect_data = [

        'vendor'        => Crypt::encrypt($rows->id),
        'vendor_name'   => $rows->vendor_name,
        'code'          => $rows->code,
        'person_name'   => $rows->person_name,
        'cnic'          => $rows->cnic,
        'ntn_number'    => $rows->ntn_number,
        'contact'       => $rows->contact,



    ])



  <div class="col-md-6 col-lg-4 col-sm-12">
    <div class="card">
      <div class="card-body">
        <div class="row row-sm align-items-center">
          <div class="col-auto">
            <span class="avatar avatar-md" style="font-size: 1rem; background-image: url({{EF::getFile($rows->photo)}})"></span>
          </div>
          <div class="col">
            <h5 class="mb-0"><a href="#">{{$rows->code}} {{$rows->vendor_name}}</a></h5>
            <div class="text-muted text-h5">{{$rows->person_name}} ({{$rows->contact}})</div>
          </div>
          <div  class="col-auto lh-1 align-self-start badge {{EF::showStatusColor($rows->status)}}">
            <span class="">{{$rows->status}}</span>
          </div>
        </div>
        <div class="row align-items-center mt-4">
          <div class="col">
            <div>
              @php($unpaid_payments = $rows->countUnpaidVendorPayments())

              @php($total_payments = $rows->countTotalVendorPayments())

              @php($percentage = 0)

              @if($total_payments > 0)
                  @php($percentage = abs((($unpaid_payments * 100)/$total_payments) - 100))
              @endif


              <div class="d-flex mb-1 align-items-center lh-1">
                <div class="text-h5 font-weight-bolder m-0">Paid Payments</div>
                <span class="ml-auto text-h6 strong">{{round($percentage)}} %</span>
              </div>

              

              <div class="progress progress-sm">
                <div class="progress-bar bg-blue" style="width: {{$percentage}}%" role="progressbar" aria-valuenow="84" aria-valuemin="0" aria-valuemax="100">
                  <span class="sr-only">0</span>
                </div>
              </div>
            </div>
          </div>
          <div class="col-auto">
            <div class="btn-list">

              @if(Auth::user()->hasAnyPermission(['All','Create Vendor Payment'])) 

              <a data-toggle="tooltip" title="Create Vendor Payment" onclick="update(event,'{{json_encode($collect_data)}}','form_add_vendor_payment','md_add_vendor_payment')" href="#"  class="btn btn-outline-primary btn-sm">
                <span class="fa fa-money-bill-alt"></span>
              </a>
              @endif

              @php($vendor_payment_route = route('vendorpaymentbyvendor',['id' => Crypt::encrypt($rows->id)]))
             
              @if(Auth::user()->hasAnyPermission(['All','View Vendor Payment'])) 

              <a onclick="viewVendorPayments(event,'{{$vendor_payment_route}}')" data-toggle="tooltip" title="View Vendor Payments" href="#" class="btn btn-outline-info btn-sm ">
                <span class="fa fa-eye"></span>
              </a>
              @endif


              @if(Auth::user()->hasAnyPermission(['All','Update Vendor'])) 

              <a data-toggle="tooltip" title="Update Vendor" onclick="update(event,'{{json_encode($collect_data)}}','form_update_vendor','md_update_vendor')" href="#"  class="btn btn-outline-success btn-sm">
                <span class="fa fa-pencil-alt"></span>
              </a>
              @endif

              @if(Auth::user()->hasAnyPermission(['All','Remove Vendor']) && $total_payments == 0) 
              <a data-toggle="tooltip" title="Remove Vendor" href="{{route('trashvendorandpayment',['id' => Crypt::encrypt($rows->id)])}}" class="btn btn-outline-danger btn-sm cls_delete" content="remove vendor">
                <span class="fa fa-trash-alt"></span>
              </a>
              @endif
              
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  @endforeach
  
    
</div>
@endsection

@section('page_modal')


    @if(Auth::user()->hasAnyPermission(['All','Add Vendor']))
      @include('vendors.modals.add_vendor')
    @endif

    @if(Auth::user()->hasAnyPermission(['All','Update Vendor']))
      @include('vendors.modals.update_vendor')
    @endif


    @if(Auth::user()->hasAnyPermission(['All','Create Vendor Payment']))
      @include('vendor_payments.modals.add_vendor_payment')
    @endif

    

    @if(Auth::user()->hasAnyPermission(['All','View Vendor Payment']))
      @include('vendor_payments.modals.view_vendor_payment')
    @endif

    <div id="modal_add_payment"> </div>
    <div id="model_update_vendor_payment"> </div>

    

@endsection

@section('page_script')

  @include('scripts.vendor_payments')

  @include('scripts.payment')


	
@endsection

