@extends('layouts.app')
@section('title')
{{ $user->name }}
@parent
@stop
@section('header_styles')
<meta name="csrf_token" content="{{ csrf_token() }}">
<link href="{{ asset('assets/vendors/jasny-bootstrap/css/jasny-bootstrap.css') }}" rel="stylesheet"/>
<link href="{{ asset('assets/vendors/x-editable/css/bootstrap-editable.css') }}" rel="stylesheet"/>
<link href="{{ asset('assets/css/pages/user_profile.css') }}" rel="stylesheet"/>
<style type="text/css">
.text-orange{
  color: var(--orange);
}
.text-teal{
  color: var(--teal);
}
</style>
@stop
{{-- Page content --}}
@section('content')
<main id="users_ac">
   <!--section ends-->
   <section>
      <div class="container">
         <div class="row">
            <div class="col-md-12 mt-xs-5">
               <h2 class="h4 p-3 bg-dark-light text-primary-light">
                  <a href="{{route('crm.dashboard')}}"><i class="fa fa-home"></i> Dashboard </a>  
               </h2>
               
               <h3 class="mt-4">Risk Customers</h3><hr>
               
               <form  action="{{route('crm.risk')}}"  method="GET" class="form-group">
                  @csrf
                  <div class="form-row">
                    <div class="form-group col-md-3">
                      <label for="by_customer"><strong>By Year</strong></label>
                      <select class="form-control" name="by_year">
                        <option>-- Select --</option>
                        <?php 
                          for($i =0; $i <= 21 ;$i++)
                          {
                              $year = date('Y') - $i;
                              echo '<option value='.$year.'';
                              echo ( $by_year == $year) ? ' selected' : '';
                              echo '>'.$year.'</option>';
                          }
                        ?>
                      </select>
                    </div>

                    <div class="form-group col-md-3">
                      <label for="by_country"><strong>By Country</strong></label>
                      <select class="form-control" id="by_country" name="by_country">
                        <option value="" hidden="true">-- Select Country --</option>
                        @foreach (getCountrires() as $key => $country)
                            <option value="{{$key}}" {{ $country_id == $key ? "selected" : "" }}> {{$country}}</option>
                        @endforeach
                      </select>
                    </div>
                    <div class="form-group col-md-3">
                      <label for="by_customer"><strong>By Customer Name</strong></label>
                      <input type="text" name="by_customer" class="form-control" placeholder="Search by customer...." value="{{$customer_name}}">
                    </div>
                    <div class="form-group col-md-2 pt-4" style="margin-top: 5px;">
                      <button type="submit" class="btn btn-primary btn-block"><i class="fas fa-filter"></i> Filter</button>
                    </div>
                    <div class="form-group col-md-1 pt-4" style="margin-top: 5px;">
                      <a href="{{route('crm.risk')}}"class="btn btn-warning btn-block text-white"><i class="far fa-times-circle"></i> Reset </a>
                      
                    </div>
                  </div>
                </form>

               <table class="table table-striped">
                  <thead>
                    <tr bgcolor="#01547d" class="text-white">
                      <th width="%7">S.No</th>
                      <th width="%18">Name</th>
                      <th width="%12">Country</th>
                      <th width="%53">Organization</th>
                      <th width="%5" class="text-center">Total Usage</th>
                      <th width="%5" class="text-center">Expected Usage</th>
                    </tr>
                  </thead>
                  <tbody>
                    @if(!empty($customers))
                        @if(!$customers->isEmpty())
                          @php $cnt = 0; @endphp
                            @foreach($customers as $row)
                           
                            <tr>
                              <td width="%7">{{++$cnt}}</td>
                              <td width="%18">{{$row->name}}</td>
                              <td width="%12">{{$row->country_name}}</td>
                              <td width="%53">{{$row->org_name}}</td>
                              <td width="%5" class="text-center">{{$row->total_usage}}</td>
                              <td width="%5" class="text-center">{{$row->expected_usage}}</td>
                            </tr>
                            @endforeach
                        @else
                          <tr><td colspan="6" class="text-center">No Risk Customer(s) Found !!!</td></tr>
                        @endif
                     @else
                        <tr><td colspan="6" class="text-center">No Risk Customer(s) Found !!!</td></tr>   
                     @endif

                  </tbody>
               </table>
                <div class="pt-2"> {{$customers->links()}}</div>
            </div>
            
            
         </div>
      </div>
      </div>
   </section>
</main>
@stop
{{-- page level scripts --}}
@section('footer_scripts') 
<!-- Bootstrap WYSIHTML5 --> 
<script  src="{{ asset('assets/vendors/jasny-bootstrap/js/jasny-bootstrap.js') }}" type="text/javascript"></script> 
@stop