<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


use App\Models;
use Session;
use Illuminate\Support\Arr;
use App\Jobs\SendClientContractRenewalAlert;
use App\Http\Requests;
use Carbon\Carbon;

class ClientContractRenewalAlertsController extends Controller
{
  public function getClientDetails(){
      $client_arr = Models\Client::with('auth_user_info')->where('contract_auto_renew', 'NO')->get();
      // dd($client_arr);
      $renew_ready = [];
      $current_date = date('Y-m-d');
      foreach ($client_arr as $value) {
        if ($value->contract_validity == false) {
          continue;
        }
        $date1 = date_create($current_date);
        $date2 = date_create($value->contract_validity);
        $difference = date_diff($date1, $date2);
        if ($difference->days <= 45) {
          $renew_ready['client_name'] = $value->name;
          $renew_ready['account_manager_email'] = $value->auth_user_info->email;
          $renew_ready['days_to_expire'] = $difference->days;
          dispatch(new SendClientContractRenewalAlert($renew_ready));
        }
      }
      //dump($renew_ready);
      $log_data = implode(', ', $renew_ready);
      \Log::info('Clients due for renewal ' . $log_data);
      //$this->sendNtfy('Clients due for renewal ' . $log_data);
  }
}
