statistics and lava charts
This commit is contained in:
@@ -7,8 +7,10 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Auth;
|
||||
use Khill\Lavacharts\Lavacharts;
|
||||
|
||||
//User Libraries
|
||||
use App\Library\SRP\SRPHelper;
|
||||
|
||||
//Models
|
||||
use App\Models\SRP\SRPShip;
|
||||
@@ -108,6 +110,48 @@ class SRPAdminController extends Controller
|
||||
}
|
||||
|
||||
public function displayStatistics() {
|
||||
return view('srp.admin.statistics');
|
||||
$months = 3;
|
||||
$approved = array();
|
||||
$denied = array();
|
||||
$fcLosses = array();
|
||||
$lava = new Lavacharts;
|
||||
|
||||
//We need a function from this library rather than recreating a new library
|
||||
$srpHelper = new SRPHelper();
|
||||
|
||||
//Get the dates for the tab panes
|
||||
$dates = $srpHelper->GetTimeFrameInMonths($months);
|
||||
|
||||
//Get the approved requests total by month of the last 3 months
|
||||
foreach($dates as $date) {
|
||||
$approved[] = [
|
||||
'date' => $date['start']->toFormattedDateString(),
|
||||
'value' => number_format($srpHelper->GetApprovedPaidValue($date['start'], $date['end']), 2, ".", ","),
|
||||
];
|
||||
}
|
||||
|
||||
//Get the denied requests total by month of the last 3 months
|
||||
foreach($dates as $date) {
|
||||
$denied[] = [
|
||||
'date' => $date['start']->toFormattedDateString(),
|
||||
'value' => number_format($srpHelper->GetDeniedValue($date['start'], $date['end']), 2, ".", ","),
|
||||
];
|
||||
}
|
||||
|
||||
//Create chart for fc losses
|
||||
$losses = $lava->DataTable();
|
||||
$losses->addDateColumn('FC');
|
||||
$losses->addNumberColumn('ISK');
|
||||
$date = $srpHelper->GetTimeFrameInMonths(1);
|
||||
$fcLosses = $srpHelper->GetLossesByFC($date['start'], $date['end']);
|
||||
foreach($fcLosses as $key => $value) {
|
||||
$losses->addRow([$fcLoss[$key], $value]);
|
||||
}
|
||||
|
||||
$lava->BarChart('ISK', $losses);
|
||||
|
||||
return view('srp.admin.statistics')->with('approved', $approved)
|
||||
->with('denied', $denied)
|
||||
->with('losses', $losses);
|
||||
}
|
||||
}
|
||||
|
||||
136
app/Library/SRP/SRPHelper.php
Normal file
136
app/Library/SRP/SRPHelper.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\SRP;
|
||||
|
||||
//Internal Libraries
|
||||
use DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
//Models
|
||||
use App\Models\SRP\SrpFleetType;
|
||||
use App\Models\SRP\SrpPayout;
|
||||
use App\Models\SRP\SRPShip;
|
||||
use App\Models\SRP\SrpShipType;
|
||||
|
||||
class SRPHelper {
|
||||
|
||||
public function __contruct() {
|
||||
//
|
||||
}
|
||||
|
||||
public function GetLossesByFC($start, $end) {
|
||||
$losses = 0.00;
|
||||
$fcs = null;
|
||||
|
||||
$fcs = SRPShip::whereBetween('created_at', [$start, $end])
|
||||
->pluck('fleet_commander_name')
|
||||
->toArray();
|
||||
|
||||
foreach($fcs as $fc) {
|
||||
$tempLosses = SRPShip::where(['fleet_commander_name' => $fc])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->sum('loss_value');
|
||||
|
||||
$losses[$fc] = $tempLosses;
|
||||
}
|
||||
|
||||
return $losses;
|
||||
}
|
||||
|
||||
public function GetUnderReview($start, $end) {
|
||||
$requests = 0.00;
|
||||
|
||||
$requests = SRPShip::where(['approved' => 'Under Review'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->sum('loss_value');
|
||||
|
||||
return $requests;
|
||||
}
|
||||
|
||||
public function GetApprovedPaidValue($start, $end) {
|
||||
$requests = 0.00;
|
||||
|
||||
$requests = SRPShip::where(['approved' => 'Approved'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->sum('paid_value');
|
||||
|
||||
return $requests;
|
||||
}
|
||||
|
||||
public function GetApproved($start, $end, $type) {
|
||||
$requests = 0.00;
|
||||
|
||||
$requests = SRPShip::where(['approved' => 'Approved'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->sum($type);
|
||||
|
||||
return $requests;
|
||||
}
|
||||
|
||||
public function GetDeniedValue($start, $end) {
|
||||
$requests = 0.00;
|
||||
|
||||
$requests = SRPShip::where(['approved' => 'Denied'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->sum('paid_value');
|
||||
|
||||
return $requests;
|
||||
}
|
||||
|
||||
public function GetDenied($start, $end, $type) {
|
||||
$requests = 0.00;
|
||||
|
||||
$requests = SRPShip::where(['approved' => 'Denied'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
-sum($type);
|
||||
|
||||
return $requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of dates from now until the amount of months has passed
|
||||
*
|
||||
* @var integer
|
||||
* @returns array
|
||||
*/
|
||||
public function GetTimeFrameInMonths($months) {
|
||||
//Declare an array of dates
|
||||
$dates = array();
|
||||
//Setup the start of the array as the basis of our start and end dates
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now()->endOfMonth();
|
||||
$end->hour = 23;
|
||||
$end->minute = 59;
|
||||
$end->second = 59;
|
||||
|
||||
if($months == 1) {
|
||||
$dates = [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
];
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
//Create an array of dates
|
||||
for($i = 0; $i < $months; $i++) {
|
||||
if($i == 0) {
|
||||
$dates[$i]['start'] = $start;
|
||||
$dates[$i]['end'] = $end;
|
||||
}
|
||||
|
||||
$start = Carbon::now()->startOfMonth()->subMonths($i);
|
||||
$end = Carbon::now()->endOfMonth()->subMonths($i);
|
||||
$end->hour = 23;
|
||||
$end->minute = 59;
|
||||
$end->second = 59;
|
||||
$dates[$i]['start'] = $start;
|
||||
$dates[$i]['end'] = $end;
|
||||
}
|
||||
|
||||
//Return the dates back to the calling function
|
||||
return $dates;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,4 +1,6 @@
|
||||
@extends('layouts.b4')
|
||||
@section('content')
|
||||
|
||||
@barchart('FC Losses', 'fc_loss_div')
|
||||
|
||||
@endsection
|
||||
Reference in New Issue
Block a user