2021-06-05 09:26:32 +00:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-07-05 19:49:28 +00:00
|
|
|
use App\Models\UsefulLink;
|
2021-10-26 14:12:47 +00:00
|
|
|
use App\Models\Configuration;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2021-06-06 18:17:52 +00:00
|
|
|
/** Show the application dashboard. */
|
2021-06-06 21:26:36 +00:00
|
|
|
public function index(Request $request)
|
2021-06-05 09:26:32 +00:00
|
|
|
{
|
2021-10-26 15:51:15 +00:00
|
|
|
$usage = Auth::user()->creditUsage();
|
|
|
|
$credits = Auth::user()->Credits();
|
2021-10-26 15:55:55 +00:00
|
|
|
$bg = "";
|
|
|
|
$boxText = "";
|
2021-10-26 14:53:53 +00:00
|
|
|
$unit = "";
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-10-26 14:54:51 +00:00
|
|
|
// START OF THE TIME-REMAINING-BOX
|
2021-10-26 15:55:55 +00:00
|
|
|
if ($credits > 0.01 and $usage > 0)
|
|
|
|
{
|
|
|
|
$days = number_format(($credits * 30) / $usage, 2, '.', '');
|
|
|
|
$hours = number_format($credits / ($usage / 30 / 24) , 2, '.', '');
|
|
|
|
|
|
|
|
// DEFINE THE BACKGROUND COLOR
|
|
|
|
if ($days >= 15)
|
|
|
|
{
|
|
|
|
$bg = "success";
|
|
|
|
}
|
|
|
|
elseif ($days >= 8 && $days <= 14)
|
|
|
|
{
|
|
|
|
$bg = "warning";
|
|
|
|
}
|
|
|
|
elseif ($days <= 7)
|
|
|
|
{
|
|
|
|
$bg = "danger";
|
|
|
|
}
|
2021-10-26 14:24:57 +00:00
|
|
|
|
2021-10-26 14:54:51 +00:00
|
|
|
// DEFINE WETHER DAYS OR HOURS REMAIN
|
2021-10-26 17:24:08 +00:00
|
|
|
if ($days < 1)
|
2021-10-26 15:55:55 +00:00
|
|
|
{
|
2021-10-26 17:24:08 +00:00
|
|
|
if ($hours < 1)
|
2021-10-26 15:55:55 +00:00
|
|
|
{
|
2021-10-26 14:53:53 +00:00
|
|
|
$boxText = 'You ran out of Credits ';
|
|
|
|
}
|
2021-10-26 15:55:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$boxText = $hours;
|
|
|
|
$unit = "hours";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$boxText = number_format($days, 0);
|
|
|
|
$unit = "days";
|
|
|
|
}
|
2021-10-26 14:18:16 +00:00
|
|
|
}
|
2021-10-26 15:55:55 +00:00
|
|
|
|
|
|
|
// RETURN ALL VALUES
|
2021-10-26 14:53:53 +00:00
|
|
|
return view('home')->with([
|
|
|
|
'useage' => $usage,
|
2021-10-26 17:26:41 +00:00
|
|
|
'credits' => $credits,
|
2021-10-26 14:53:53 +00:00
|
|
|
'useful_links' => UsefulLink::all()->sortBy('id'),
|
|
|
|
'bg' => $bg,
|
2021-10-26 15:55:55 +00:00
|
|
|
'boxText' => $boxText,
|
2021-10-26 14:53:53 +00:00
|
|
|
'unit' => $unit
|
|
|
|
]);
|
2021-10-26 15:55:55 +00:00
|
|
|
}
|
2021-10-26 14:53:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|