Skip to content

Commit

Permalink
Monthly Breakdown Message
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMicallefYBSU committed Aug 30, 2024
1 parent a30d534 commit 7038e56
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 22 deletions.
29 changes: 11 additions & 18 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,18 @@ protected function schedule(Schedule $schedule)
// $discord->sendMessage(753086414811562014, 'Sent '.$count.' one-week warning inactivity emails');
// })->cron('00 00 23 MAR,JUN,SEP,DEC *'); // 1 week before end of quarter*/

// Monthly Statistics Breakdown
$schedule->job(new ProcessShanwickController())->monthlyOn(1, '00:00');

/// Monthly leaderboard wipe
$schedule->call(function () {
// Loop through all roster members
foreach (RosterMember::all() as $rosterMember) {
// Reset the hours for every member
$rosterMember->monthly_hours = 0.0;
$rosterMember->save();
}
})->monthlyOn(1, '00:00');

// Quarterly Currency Wipe
$schedule->call(function () {
// Loop through all roster members
foreach (RosterMember::all() as $rosterMember) {
// Reset the hours for every member
$rosterMember->currency = 0.0;
$rosterMember->save();
}
})->cron('15 00 01 JAN,APR,JUL,OCT *');
// $schedule->call(function () {
// // Loop through all roster members
// foreach (RosterMember::all() as $rosterMember) {
// // Reset the hours for every member
// $rosterMember->monthly_hours = 0.0;
// $rosterMember->save();
// }
// })

//Solo cert expiry warning
// $schedule->job(new ProcessSoloCertExpiryWarnings())->daily();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Http\Request;
use App\Services\DiscordClient;
use App\Jobs\ProcessRosterInactivity;
use App\Jobs\ProcessMonthlyBreakdown;

class DiscordTestController extends Controller
{
Expand All @@ -26,7 +26,7 @@ public function EditTagTest()
public function Job()
{
// Dispatch the job
$job = ProcessRosterInactivity::dispatch();
$job = ProcessMonthlyBreakdown::dispatch();

// Call the handle method directly to get the result synchronously
$result = $job->handle();
Expand Down
2 changes: 0 additions & 2 deletions app/Jobs/DiscordAccountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class DiscordAccountCheck implements ShouldQueue
* @return void
*/

protected $signature = 'discord:accountupdate';

public function handle()
{
// Initialise some variables
Expand Down
82 changes: 82 additions & 0 deletions app/Jobs/ProcessMonthlyBreakdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use GuzzleHttp\Client;
use App\Services\DiscordClient;
use App\Models\Training\Instructing\Records\TrainingSession;
use App\Models\Users\User;
use App\Models\Roster\RosterMember;
use App\Models\News\HomeNewControllerCert;
use App\Notifications\Training\Instructing\RemovedAsStudent;
use App\Models\Training\Instructing\Students\StudentStatusLabel;
use App\Models\Training\Instructing\Links\StudentStatusLabelLink;
use Carbon\Carbon;

class ProcessMonthlyBreakdown implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*
* @return void
*/

public function handle()
{
// Get Collection Values
$roster_member = RosterMember::all();
$top_3 = RosterMember::all()->sortByDesc(function ($member) {return (float) $member->monthly_hours;})->take(3);
$new_controllers = HomeNewControllerCert::where('timestamp', '>=', Carbon::now()->subMonths(1))->get();

// Set Variables
$total_hours = 0;

foreach($roster_member as $roster){
$total_hours += $roster->monthly_hours;
}

$message = 'It is the beginning of a new month, so here are some wonderful stats for ' . Carbon::now()->subMonth()->format('F, Y') . "\n\n";

$message .= "**__Total Controller Hours__**\n";
$message .= "- " . $total_hours . " hours\n";

$message .= "\n**__Top 3 Controllers__**\n";

foreach($top_3 as $t) {
if($t->user->discord_user_id === null){
$message .= "- " . $t->user->fullName('FLC') . " - ".$t->monthly_hours."\n";
} else {
$message .= "- <@" . $t->user->discord_user_id . "> - ".$t->monthly_hours."\n";
}
}

$message .= "\n**__New Certified Controllers__**\n";

foreach($new_controllers as $nc) {
if($nc->controller->discord_user_id === null){
$message .= "- " . $nc->controller->fullName('FLC') . "\n";
} else {
$message .= "- <@" . $nc->controller->discord_user_id . ">\n";
}
}

$message .= "\nWell done to everyone for your contributions to Gander Oceanic over the last Month! Enjoy ".Carbon::now()->format('F, Y');

$discord = new DiscordClient();
$discord->sendMessageWithEmbed('1274861846880456785', 'Gander Oceanic Operations Breakdown - '.Carbon::now()->subMonth()->format('F, Y'), $message);

foreach($roster_member as $roster){
$roster->monthly_hours = 0.0;
$roster->save();
}
}

}

0 comments on commit 7038e56

Please sign in to comment.