<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


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

class ContractRenewalReminderController extends Controller
{
  public function getMnos(){
      $network_arr = Models\NetworkOps::with('account_manager_info')->where('contract_auto_renew', 'NO')->get();
      $renew_ready = [];
      $current_date = date('Y-m-d');
      foreach ($network_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['mno_name'] = $value->name;
          $renew_ready['account_manager_email'] = $value->account_manager_info->email;
          $renew_ready['days_to_expire'] = $difference->days;
          dispatch(new SendMnoContractRenewalEmailAlert($renew_ready));
        }
      }
      $log_data = implode(', ', $renew_ready);
      \Log::info('MNOs due for renewal ' . $log_data);
      $this->sendNtfy('MNOs due for renewal ' . $log_data);
  }
}
