@extends('layouts.dashboard')

@section('page_title')
Manage Dealer
@endsection

@section('page_header_title')
Manage Dealer
@endsection



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

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



        @if(Auth::user()->hasAnyPermission(['All','Add Dealer']))
        <button  class="float-right btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_add_dealer"><i class="fa fa-plus"></i></button> &nbsp;&nbsp;
        @endif

        <h3 class="card-title">Add Dealer / Sub Dealer / Vendor</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>Name</th>
              <th>Father Name</th>

              <th>Cnic #</th>
              <th>Email </th>
              <th>Contact #</th>
              <th>Branch</th>
              <th>Type</th>

              <th>Reg Date</th>

              <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>
            </tr>
          </thead>
          <tbody>
            @isset($user_list)
            @php($pass_data = [])
            @foreach($user_list as $rows)

            @php(
            $pass_data = array(
            'user_id'              => Crypt::encrypt($rows->id),
            'full_name'          => $rows->name,
            'father_name'        => $rows->fname,
            'cnic'               => $rows->cnic,
            'gender'               => $rows->gender,
            'email'              => $rows->email,
            'contact'            => $rows->contact,
            'agency_name'       =>  $rows->agency_name,
            'ntn'               =>  $rows->ntn,
            'agency_address'    =>  $rows->agency_address,
            'filer'             =>  $rows->is_filer,
            EF::branchWhiteLabel()['module']             => trim($rows->branch->code.' '.$rows->branch->name),
            )
            )
            <tr>
              <td>{{$loop->iteration}}</td>

              <td>{{$rows->name}}</td>

              <td>{{$rows->fname}}</td>

              <td>{{($rows->cnic)}}</td>

              <td>{{EF::filterEmail($rows->email)}}</td>

              <td>{{$rows->contact}}</td>

              <td>{{$rows->branch->name}}</td>

              <td>{{$rows->type}}</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','Update Dealer']))
                   <a onclick="update(event,'{{json_encode($pass_data)}}','form_update_dealer','md_update_dealer'); isFiler('{{$rows->is_filer}}');" href="javascript:void(0)" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Update</a>
                   @endif




                                    </div>
                                  </div>
                               </td>
           </tr>


           @endforeach
           @endisset

         </tbody>
       </table>
     </div>
   </div>
 </div>
</div>
@endsection

@section('page_modal')
@include('user.modals.add_dealer')
@include('user.modals.update_dealer')
@endsection

@section('page_script')
<script type="text/javascript">
    function NTNVerify(key_element)
	{
		var ntn_number 		= $('.ntn_number_'+key_element);
		var filer     		= $('.filer_'+key_element);
		var ntn_section     = $('.ntn_section_'+key_element);
		if(filer.prop('checked'))
		{
			ntn_section.show();
		}
		else
		{
			ntn_section.hide();
			ntn_number.val('');
		}
    }

    function isFiler(filer)
	{

		if(filer == "1")
		{
			$('.is_filer').prop('checked',true);

			$('.ntn').show();
		}
		else
		{
			$('.is_filer').prop('checked',false);

			$('.ntn').hide();


		}
	}
</script>
@endsection

