<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models;
use Session;

class DashboardController extends Controller
{
    public function index(){
    	
        $total_clients = Models\Client::count();
        $ussd_clients = Models\Client::where('services', 'LIKE', '%ussd%')->orwhere('services', 'LIKE', '%A2P%')->count();
        $sms_clients = Models\Client::where('services', 'LIKE', '%sms%')->count();
        $voice_clients = Models\Client::where('services', 'LIKE', '%ivr%')->count();
        $expiring_contracts = Models\Client::where('contract_auto_renew', '<>', 'YES')->where('contract_validity', '<>', null)->orwhere('contract_validity', '<>', '')->orderBy('contract_validity', 'ASC')->take(5)->get();
        //dd($expiring_contracts->isEmpty() == false);
        $data = [
            'page_title' => 'Dashboard',
            'sms' => $sms_clients,
            'ussd' => $ussd_clients,
            'voice' => $voice_clients,
            'total' => $total_clients,
            'expiring_contracts' => $expiring_contracts
        ];

        //dd($data);
    	return view('dashboard.index_two', $data);
    }

    public function getEvents(){
        $event_arr = [
            [
                "title" => 'Airtel MW Top Up',
                "start" => date("Y, m, d")
            ],
            [
                "title" => 'Airtel MW Top Down',
                "start" => date("Y, m, d")
            ],
        ];

        return response()->json($event_arr);

    }
}
