Skip to content

Commit

Permalink
feature escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
AzGasim committed Dec 5, 2024
1 parent 76dd371 commit 221f7b0
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 66 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ WP_SECURE_AUTH_SALT="ThisIsASecretKey!DoNotUseItInProduction!ChangeIt!"
WP_LOGGED_IN_SALT="ThisIsASecretKey!DoNotUseItInProduction!ChangeIt!"
WP_NONCE_SALT="ThisIsASecretKey!DoNotUseItInProduction!ChangeIt!"

EXPIRY_SEND_ESCALATION=false
EXPIRY_SEND_ESCALATION_DAYS_BEFORE=7
EXPIRY_SEND_ESCALATION_COPY=[email protected]
EXPIRY_PANEL_PATH=moox
LOGO_URL="https://moox.org/img/logo.png"

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
Expand Down
15 changes: 15 additions & 0 deletions config/expiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@
'user_model' => \Moox\Press\Models\WpUser::class,
'default_notified_to' => 1,

/*
|--------------------------------------------------------------------------
| Escalation Settings
|--------------------------------------------------------------------------
| Configure notifications for escalations.
| Define timing and recipients.
| Set the dashboard path.
*/

'send-escalation' => env('EXPIRY_SEND_ESCALATION', true),
'send-escalation-days-before' => env('EXPIRY_SEND_ESCALATION_DAYS_BEFORE', 7),
'send-escalation-copy' => env('EXPIRY_SEND_ESCALATION_COPY', '[email protected]'),
'panel_path' => env('EXPIRY_PANEL_PATH', 'press'),
'logo_url' => env('LOGO_URL', 'https://moox.org/img/logo.png'),

/*
|--------------------------------------------------------------------------
| Disable actions
Expand Down
6 changes: 6 additions & 0 deletions packages/core/resources/lang/de/expiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
'notifyUser' => 'Verantwortlicher',
'expiry_job' => 'Typ',

'escalated_entries_in_expiry_dashboard' => 'Eskalierte Einträge im Expiry Dashboard',
'following_escalated_entries' => 'Folgende Einträge sind eskaliert:',
'will_expire_at' => 'Läuft ab am',
'review_entreis' => 'Bitte überprüfen Sie diese Einträge so bald wie möglich im ',
'expiry_dashboard' => 'Ablaufdaten Dashboard',

'set_date_based_on_cycle' => 'Neues Ablaufdatum setzen basierend auf dem Turnus',
'date_updated' => 'Ablaufdatum erfolgreich aktualisiert',
'set_new_expiry_date' => 'Neues Ablaufdatum setzen',
Expand Down
8 changes: 7 additions & 1 deletion packages/core/resources/lang/en/expiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
'escalated_at' => 'Escalated at',
'escalated_to' => 'Escalated to',
'cycle' => 'Cycle',
'notifyUser' => 'Verantwortlicher',
'notifyUser' => 'Assignee',
'expiry_job' => 'Type',

'escalated_entries_in_expiry_dashboard' => 'Escalated entries in the expiry dashboard',
'following_escalated_entries' => 'The following entries have been escalated:',
'will_expire_at' => 'Will expire at',
'review_entreis' => 'Please review these entries as soon as possible in the ',
'expiry_dashboard' => 'Expiry Dashboard',

'set_date_based_on_cycle' => 'Set date based on cycle',
'date_updated' => 'Expiry date successfully updated',
'set_new_expiry_date' => 'Set New Expiry Date',
Expand Down
15 changes: 15 additions & 0 deletions packages/expiry/config/expiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@
'user_model' => \Moox\Press\Models\WpUser::class,
'default_notified_to' => 1,

/*
|--------------------------------------------------------------------------
| Escalation Settings
|--------------------------------------------------------------------------
| Configure notifications for escalations.
| Define timing and recipients.
| Set the dashboard path.
*/

'send-escalation' => env('EXPIRY_SEND_ESCALATION', false),
'send-escalation-days-before' => env('EXPIRY_SEND_ESCALATION_DAYS_BEFORE', 7),
'send-escalation-copy' => env('EXPIRY_SEND_ESCALATION_COPY', '[email protected]'),
'panel_path' => env('EXPIRY_PANEL_PATH', 'moox'),
'logo_url' => env('LOGO_URL', 'https://moox.org/img/logo.png'),

/*
|--------------------------------------------------------------------------
| Disable actions
Expand Down
139 changes: 139 additions & 0 deletions packages/expiry/resources/views/emails/escalated_expiries.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!DOCTYPE html>
<html lang="de">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Escalated Entries</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f9fafb;
}
.container {
width: 100%;
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1,
h3 {
font-size: 1.25rem;
color: #333333;
margin-bottom: 20px;
}
p {
font-size: 1rem;
color: #555555;
}
.table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.table th,
.table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #e0e0e0;
}
.table th {
background-color: #f4f4f4;
font-weight: 600;
color: #333333;
}
.table tr:nth-child(even) {
background-color: #f9f9f9;
}
.table tr:hover {
background-color: #f1f1f1;
}
.table .title {
font-weight: bold;
color: #1a202c;
}
.table .escalation {
color: #e53e3e;
font-weight: bold;
}
.footer {
margin-top: 20px;
font-size: 0.875rem;
color: #777777;
}
.footer a {
color: #3182ce;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
.logo {
display: block;
margin-bottom: 20px;
}
</style>
</head>

<body>
<div class="container">
<!-- Header with Logo -->
<div class="logo">
<img src="{{ config('expiry.logo_url') }}" alt="Company Logo" class="w-24 h-auto">
</div>
<h1>{{ __('core::expiry.escalated_entries_in_expiry_dashboard') }}</h1>
<h4>{{ __('core::expiry.following_escalated_entries') }}</h4>

<!-- Escalated Entries -->
<table class="table">
<thead>
<tr>
<th>{{ __('core::core.title') }}</th>
<th>{{ __('core::expiry.notifyUser') }}</th>
<th>{{ __('core::expiry.will_expire_at') }}</th>
<th>{{ __('core::expiry.processing_deadline') }}</th>
<th>{{ __('core::expiry.escalated_at') }}</th>
</tr>
</thead>
<tbody>
@foreach ($escalatedEntries as $entry)
<tr>
<td class="title">{{ $entry['title'] }}</td>
<td>{{ $entry['notified_to'] }}</td>
<td>{{ $entry['expired_at'] }}</td>
<td>{{ $entry['processing_deadline'] }}</td>
<td class="escalation">{{ $entry['escalated_at'] }}</td>
</tr>
@endforeach
</tbody>
</table>

<br>

<!-- Footer -->
<p class="footer">{{ __('core::expiry.review_entreis') }}<a
href="{{ url($panelPath . '/expiries') }}">{{ __('core::expiry.expiry_dashboard') }}</a>.</p>
</div>
</body>

</html>
14 changes: 0 additions & 14 deletions packages/expiry/resources/views/emails/expirySummary.blade.php

This file was deleted.

19 changes: 19 additions & 0 deletions packages/expiry/src/Commands/EscalatedExpiriesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Moox\Expiry\Commands;

use Illuminate\Console\Command;
use Moox\Expiry\Jobs\SendEscalatedExpiriesJob;

class EscalatedExpiriesCommand extends Command
{
protected $signature = 'mooxexpiry:escalated';

protected $description = 'Dispatch the job to send notifications for escalated expiries';

public function handle()
{
SendEscalatedExpiriesJob::dispatch();
$this->info('Escalated Expiries Notification Dispatched');
}
}
5 changes: 3 additions & 2 deletions packages/expiry/src/ExpiryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Moox\Expiry;

use Moox\Expiry\Commands\EscalatedExpiriesCommand;
use Moox\Expiry\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand All @@ -15,10 +16,10 @@ public function configurePackage(Package $package): void
$package
->name('expiry')
->hasConfigFile()
->hasViews()
->hasViews('escalated_expiries')
->hasMigration('create_expiries_table')
->hasRoutes('api')
->hasCommands(InstallCommand::class);
->hasCommands(InstallCommand::class, EscalatedExpiriesCommand::class);
}

public function boot()
Expand Down
7 changes: 4 additions & 3 deletions packages/expiry/src/Jobs/CollectExpiries.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function handle()
'expired_at' => Carbon::now()->addDays(60),
'processing_deadline' => Carbon::now()->addDays(30),
'notified_to' => 2,
'escalated_to' => 3,
'escalated_at' => Carbon::now()->addDays(-10),
'escalated_to' => null,
'handled_by' => 1,
'done_at' => Carbon::now()->addDays(10),
],
Expand Down Expand Up @@ -99,10 +100,10 @@ public function handle()
'escalated_to' => $data['escalated_to'],
'handled_by' => $data['handled_by'],
'done_at' => $data['done_at'],
'cycle' => array_rand($cycleOptions), // Random cycle
'cycle' => array_rand($cycleOptions),
'meta_id' => null,
'notified_at' => Carbon::now(),
'escalated_at' => Carbon::now()->addDays(2),
'escalated_at' => $data['escalated_at'] ?? null,
]
);
}
Expand Down
66 changes: 66 additions & 0 deletions packages/expiry/src/Jobs/SendEscalatedExpiriesJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Moox\Expiry\Jobs;

use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use Moox\Expiry\Mail\EscalatedExpiriesMail;
use Moox\Expiry\Models\Expiry;

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

public function handle()
{
if (! config('expiry.send-escalation')) {
return;
}

$adminEmail = config('expiry.send-escalation-copy');
$panelPath = config('expiry.panel_path');

$escalatedExpiries = Expiry::query()
->where(function ($query) {
$query->whereNull('escalated_to')
->whereNotNull('escalated_at');
})
->get();

if ($escalatedExpiries->isEmpty()) {
return;
}

$escalatedEntries = $escalatedExpiries->filter(fn ($entry) => $entry->escalated_at !== null);

$escalatedEntries->each(function ($entry) {
$responsibleId = $entry->notified_to;
$entry->escalated_to = $responsibleId;
$entry->save();
});

$data = [
'escalatedEntries' => $escalatedEntries->map(function ($entry) {
return [
'title' => $entry->title,
'expired_at' => Carbon::parse($entry->expired_at)->format('d.m.Y'),
'processing_deadline' => Carbon::parse($entry->processing_deadline)->format('d.m.Y'),
'escalated_at' => Carbon::parse($entry->escalated_at)->format('d.m.Y'),
'notified_to' => config('expiry.user_model')::where('ID', $entry->notified_to)->first()?->display_name,
'user_email' => config('expiry.user_model')::where('ID', $entry->notified_to)->first()?->email,
];
}),
];

$responsibleEmail = config('expiry.user_model')::where('ID', $escalatedExpiries->first()->notified_to)->first()?->email;

Mail::to($responsibleEmail)
->cc($adminEmail)
->send(new EscalatedExpiriesMail($data, $panelPath));
}
}
Loading

0 comments on commit 221f7b0

Please sign in to comment.