mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 20:17:14 +01:00
Fix with mail and delete of reservation
This commit is contained in:
parent
6d01f2b701
commit
b2ca65ad4c
8 changed files with 232 additions and 0 deletions
46
app/Console/Commands/SendReminderEmail.php
Normal file
46
app/Console/Commands/SendReminderEmail.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Reserveditem;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ReturnDateReminder;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SendReminderEmail extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'send-reminder-email:cron';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$reservations = Reserveditem::where('return_date', '<=', Carbon::now()->add(5, 'days')->toDateTimeString())
|
||||
->where('return_date', '>', Carbon::now()->toDateTimeString())
|
||||
->where('notified', 0)
|
||||
->get();
|
||||
|
||||
if ($reservations) {
|
||||
foreach ($reservations as $reservation) {
|
||||
Mail::to($reservation['email'])
|
||||
->send(new ReturnDateReminder($reservation));
|
||||
$reservation['notified'] = 1;
|
||||
$reservation->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,8 @@ use Filament\Tables\Columns\IconColumn;
|
|||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\Layout\Stack;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ReservationDeletedUser;
|
||||
|
||||
|
||||
class ReserveditemResource extends Resource
|
||||
|
|
@ -124,6 +126,14 @@ class ReserveditemResource extends Resource
|
|||
->button()
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->iconPosition(IconPosition::After),
|
||||
Tables\Actions\DeleteAction::make()
|
||||
->action(function (array $data, Reserveditem $record): void {
|
||||
$record->delete();
|
||||
Item::where('id', $record->item_id)->update(['reserved' => false]);
|
||||
Mail::to($record['email'])
|
||||
->send(new ReservationDeletedUser($record));
|
||||
})
|
||||
|
||||
])
|
||||
->bulkActions([
|
||||
// Tables\Actions\BulkActionGroup::make([
|
||||
|
|
|
|||
58
app/Mail/ReservationDeletedUser.php
Normal file
58
app/Mail/ReservationDeletedUser.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Item;
|
||||
use App\Models\Reserveditem;
|
||||
|
||||
class ReservationDeletedUser extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct( public Reserveditem $reservation)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Reservation borttagen',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.user.reservationdeleted',
|
||||
with: [
|
||||
'reservationName' => $this->reservation->username,
|
||||
'reservationDesc' => Item::where('id', $this->reservation->item_id)->pluck('desc')->first(),
|
||||
'reservationEmail' => $this->reservation->email,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
63
app/Mail/ReturnDateReminder.php
Normal file
63
app/Mail/ReturnDateReminder.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\Reserveditem;
|
||||
use App\Models\Item;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReturnDateReminder extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(public Reserveditem $reservation )
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Påminnelse om återlämning',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
$date = new Carbon($this->reservation->return_date);
|
||||
return new Content(
|
||||
view: 'emails.user.returndatereminder',
|
||||
with: [
|
||||
'reservationName' => $this->reservation->username,
|
||||
'reservationDesc' => Item::where('id', $this->reservation->item_id)->pluck('desc')->first(),
|
||||
'reservationEmail' => $this->reservation->email,
|
||||
'reservationReturnDate' => $date->format('Y-m-d'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('reserveditems', function (Blueprint $table) {
|
||||
$table->boolean('notified')->default(0)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('reserveditems', function (Blueprint $table) {
|
||||
$table->dropColumn('notified');
|
||||
});
|
||||
}
|
||||
};
|
||||
12
resources/views/emails/user/reservationdeleted.blade.php
Normal file
12
resources/views/emails/user/reservationdeleted.blade.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Reservation borttagen</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Reservation borttagen</h1>
|
||||
<p>Din reserveration för {{ $reservationDesc }} har blivit borttagen</p>
|
||||
<p>Med vänliga hälsningar</p>
|
||||
<p>vBytes</p>
|
||||
</body>
|
||||
</html>
|
||||
13
resources/views/emails/user/returndatereminder.blade.php
Normal file
13
resources/views/emails/user/returndatereminder.blade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Påminnelse om återlämning</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Påminnelse om återlämning</h1>
|
||||
<p>Det är snart dags att lämna tillbaka {{ $reservationDesc }}</p>
|
||||
<p>Du ska återlämna varan {{ $reservationReturnDate }}</p>
|
||||
<p>Med vänliga hälsningar</p>
|
||||
<p>vBytes</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,3 +6,5 @@ use Illuminate\Support\Facades\Artisan;
|
|||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote')->hourly();
|
||||
|
||||
Schedule::command('send-reminder-email:cron')->daily();
|
||||
|
|
|
|||
Loading…
Reference in a new issue