mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-27 00:37:14 +01:00
Compare commits
4 commits
521a70f9a1
...
5d1a0a77a8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d1a0a77a8 | ||
|
|
6a95830a9c | ||
|
|
128e0955cf | ||
|
|
9fb530c28e |
9 changed files with 239 additions and 1 deletions
|
|
@ -30,6 +30,7 @@ use Filament\Infolists\Components\TextEntry;
|
||||||
use Filament\Infolists\Components\Section;
|
use Filament\Infolists\Components\Section;
|
||||||
use Filament\Tables\Contracts\HasTable;
|
use Filament\Tables\Contracts\HasTable;
|
||||||
use Filament\Tables\Concerns\InteractsWithTable;
|
use Filament\Tables\Concerns\InteractsWithTable;
|
||||||
|
use Filament\Infolists\Components\ImageEntry;
|
||||||
|
|
||||||
class Reserve extends BasePage implements HasTable
|
class Reserve extends BasePage implements HasTable
|
||||||
{
|
{
|
||||||
|
|
@ -86,6 +87,7 @@ class Reserve extends BasePage implements HasTable
|
||||||
->infolist([
|
->infolist([
|
||||||
Section::make('Game')
|
Section::make('Game')
|
||||||
->schema([
|
->schema([
|
||||||
|
ImageEntry::make('image'),
|
||||||
TextEntry::make('desc'),
|
TextEntry::make('desc'),
|
||||||
TextEntry::make('acquisition_date'),
|
TextEntry::make('acquisition_date'),
|
||||||
TextEntry::make('category.name'),
|
TextEntry::make('category.name'),
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,11 @@ use Filament\Forms\Components\TextInput;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Filament\Support\Enums\IconPosition;
|
use Filament\Support\Enums\IconPosition;
|
||||||
use Filament\Infolists\Components\TextEntry;
|
use Filament\Infolists\Components\TextEntry;
|
||||||
|
use Filament\Infolists\Components\ImageEntry;
|
||||||
use Filament\Infolists\Components\Section;
|
use Filament\Infolists\Components\Section;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use App\Mail\ReservationCreatedUser;
|
||||||
|
use App\Mail\ReservationCreated;
|
||||||
|
|
||||||
|
|
||||||
class ItemResource extends Resource
|
class ItemResource extends Resource
|
||||||
|
|
@ -159,6 +163,7 @@ class ItemResource extends Resource
|
||||||
->infolist([
|
->infolist([
|
||||||
Section::make('Game')
|
Section::make('Game')
|
||||||
->schema([
|
->schema([
|
||||||
|
ImageEntry::make('image'),
|
||||||
TextEntry::make('desc'),
|
TextEntry::make('desc'),
|
||||||
TextEntry::make('acquisition_date'),
|
TextEntry::make('acquisition_date'),
|
||||||
TextEntry::make('category.name'),
|
TextEntry::make('category.name'),
|
||||||
|
|
@ -171,6 +176,7 @@ class ItemResource extends Resource
|
||||||
->hidden(fn ($record) => $record->type === "item"),
|
->hidden(fn ($record) => $record->type === "item"),
|
||||||
Section::make('Item')
|
Section::make('Item')
|
||||||
->schema([
|
->schema([
|
||||||
|
ImageEntry::make('image'),
|
||||||
TextEntry::make('desc'),
|
TextEntry::make('desc'),
|
||||||
TextEntry::make('acquisition_date'),
|
TextEntry::make('acquisition_date'),
|
||||||
TextEntry::make('category.name'),
|
TextEntry::make('category.name'),
|
||||||
|
|
@ -198,13 +204,17 @@ class ItemResource extends Resource
|
||||||
->required(),
|
->required(),
|
||||||
])
|
])
|
||||||
->action(function (array $data, Item $record): void {
|
->action(function (array $data, Item $record): void {
|
||||||
Reserveditem::create([
|
$reservation = Reserveditem::create([
|
||||||
'item_id' => $record->id,
|
'item_id' => $record->id,
|
||||||
'reserved_date' => Carbon::now(),
|
'reserved_date' => Carbon::now(),
|
||||||
'username' => $data['username'],
|
'username' => $data['username'],
|
||||||
'email' => $data['email']
|
'email' => $data['email']
|
||||||
]);
|
]);
|
||||||
Item::where('id', $record->id)->update(['reserved' => true]);
|
Item::where('id', $record->id)->update(['reserved' => true]);
|
||||||
|
Mail::to($data['email'])
|
||||||
|
->send(new ReservationCreatedUser($reservation));
|
||||||
|
Mail::to(env('MAIL_FROM_ADDRESS'))
|
||||||
|
->send(new ReservationCreated($reservation));
|
||||||
})
|
})
|
||||||
->hidden(fn ($record) => $record->reserved)
|
->hidden(fn ($record) => $record->reserved)
|
||||||
])
|
])
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ use Filament\Resources\Pages\EditRecord;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Reserveditem;
|
use App\Models\Reserveditem;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use App\Mail\Delivered;
|
||||||
|
|
||||||
class EditReserveditem extends EditRecord
|
class EditReserveditem extends EditRecord
|
||||||
{
|
{
|
||||||
|
|
@ -44,6 +46,14 @@ class EditReserveditem extends EditRecord
|
||||||
Item::where('id', $record->item_id)->update(['reserved' => false]);
|
Item::where('id', $record->item_id)->update(['reserved' => false]);
|
||||||
Reserveditem::where('id', $record->id)->delete();
|
Reserveditem::where('id', $record->id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($record->delivered && !$record->returned)
|
||||||
|
{
|
||||||
|
Mail::to($record->email)
|
||||||
|
->send(new Delivered($record));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
61
app/Mail/Delivered.php
Normal file
61
app/Mail/Delivered.php
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
class Delivered 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: 'Levererad',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.user.delivered',
|
||||||
|
with: [
|
||||||
|
'reservationName' => $this->reservation->username,
|
||||||
|
'reservationDesc' => Item::where('id', $this->reservation->item_id)->pluck('desc')->first(),
|
||||||
|
'reservationEmail' => $this->reservation->email,
|
||||||
|
'reservationReturnDate' => $this->reservation->return_date->toDateString(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||||
|
*/
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
60
app/Mail/ReservationCreated.php
Normal file
60
app/Mail/ReservationCreated.php
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
class ReservationCreated 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 Created',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.admin.reservationcreated',
|
||||||
|
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 [];
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Mail/ReservationCreatedUser.php
Normal file
58
app/Mail/ReservationCreatedUser.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 ReservationCreatedUser 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 skapad',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'emails.user.reservationcreated',
|
||||||
|
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 [];
|
||||||
|
}
|
||||||
|
}
|
||||||
11
resources/views/emails/admin/reservationcreated.blade.php
Normal file
11
resources/views/emails/admin/reservationcreated.blade.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Reservation skapad</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Reservation skapad</h1>
|
||||||
|
<p>{{ $reservationName }} har reserverat {{ $reservationDesc }}</p>
|
||||||
|
<p>Mail: {{ $reservationEmail }}</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
resources/views/emails/user/delivered.blade.php
Normal file
13
resources/views/emails/user/delivered.blade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Vara levererad</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Vara levererad</h1>
|
||||||
|
<p>Du har fått {{ $reservationDesc }} levererad</p>
|
||||||
|
<p>Du ska återlämna varan {{ $reservationReturnDate }}</p>
|
||||||
|
<p>Med vänliga hälsningar</p>
|
||||||
|
<p>vBytes</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
resources/views/emails/user/reservationcreated.blade.php
Normal file
13
resources/views/emails/user/reservationcreated.blade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Reservation skapad</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Reservation skapad</h1>
|
||||||
|
<p>Du har reserverat {{ $reservationDesc }}</p>
|
||||||
|
<p>Ansvarig på vBytes kommer att ta kontakt med dig för att bestämma tid för överlämning.</p>
|
||||||
|
<p>Med vänliga hälsningar</p>
|
||||||
|
<p>vBytes</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in a new issue