From 0657270b87c18580a735f56bc62c3bbc80710fcc Mon Sep 17 00:00:00 2001 From: hildaaaevs <149044919+hildaaaevs@users.noreply.github.com> Date: Sun, 22 Jun 2025 12:59:49 +0700 Subject: [PATCH] Lupa Password --- app/Filament/Resources/ReservasiiResource.php | 37 +++++++++--- app/Livewire/Auth/RegisterPage.php | 11 ++-- app/Livewire/Auth/ResetPasswordPage.php | 49 ++++++++++++++++ app/Livewire/UploadBuktiPembayaran.php | 2 +- app/Models/Reservasii.php | 25 ++++++-- app/Models/User.php | 5 ++ app/Notifications/ReservasiApproved.php | 45 +++++++++++++++ ..._02_20_043621_create_reservasiis_table.php | 2 + .../auth/forgot-password-page.blade.php | 2 +- .../views/livewire/auth/login-page.blade.php | 9 ++- .../auth/reset-password-page.blade.php | 57 +++++++++++++------ 11 files changed, 204 insertions(+), 40 deletions(-) create mode 100644 app/Notifications/ReservasiApproved.php diff --git a/app/Filament/Resources/ReservasiiResource.php b/app/Filament/Resources/ReservasiiResource.php index 5ab49bd..ab829f4 100644 --- a/app/Filament/Resources/ReservasiiResource.php +++ b/app/Filament/Resources/ReservasiiResource.php @@ -79,7 +79,9 @@ public static function form(Form $form): Form 'full' => 'Full', 'dp' => 'DP', ]) - ->required(), + ->required() + ->default('full') + ->inline(), Select::make('status_pembayaran') ->label('Status Pembayaran') ->options([ @@ -94,10 +96,6 @@ public static function form(Form $form): Form ->image() ->directory('bukti-pembayaran') ->visibility('public') - ->imageResizeMode('cover') - ->imageCropAspectRatio('16:9') - ->imageResizeTargetWidth('1920') - ->imageResizeTargetHeight('1080') ->preserveFilenames() ->downloadable() ->openable() @@ -171,7 +169,7 @@ public static function form(Form $form): Form 'cream' => 'Cream', 'spotlight' => 'Spotlight' ]) - ->columnSpan(2), // Lebih kecil karena opsinya sedikit + ->columnSpan(2), TextInput::make('jumlah') ->numeric() @@ -208,11 +206,33 @@ public static function form(Form $form): Form foreach ($repeaters as $key => $repeater){ $total += $get("detail.{$key}.total_harga"); } + + // Hitung diskon jika ada promo + $diskon = 0; + if ($promoId = $get('promo_id')) { + $promo = \App\Models\Promo::find($promoId); + if ($promo && $promo->aktif) { + if ($promo->tipe === 'fix') { + $diskon = $promo->diskon; + } else if ($promo->tipe === 'persen') { + $diskon = ($total * $promo->diskon) / 100; + } + } + } + + $totalSetelahDiskon = $total - $diskon; $set('total', $total); - return 'Rp ' . number_format($total, 0, ',', '.'); + $set('diskon', $diskon); + $set('total_setelah_diskon', $totalSetelahDiskon); + + return 'Rp ' . number_format($totalSetelahDiskon, 0, ',', '.'); }), Hidden::make('total') - ->default(0) + ->default(0), + Hidden::make('diskon') + ->default(0), + Hidden::make('total_setelah_diskon') + ->default(0), ])->columnSpanFull(), ]) ]); @@ -221,6 +241,7 @@ public static function form(Form $form): Form public static function table(Table $table): Table { return $table + ->defaultSort('created_at', 'desc') ->columns([ Tables\Columns\TextColumn::make('nama') ->label('Nama'), diff --git a/app/Livewire/Auth/RegisterPage.php b/app/Livewire/Auth/RegisterPage.php index 5af52d8..b0d6065 100644 --- a/app/Livewire/Auth/RegisterPage.php +++ b/app/Livewire/Auth/RegisterPage.php @@ -23,18 +23,17 @@ public function save(){ ]); // save to database - $user = User::create([ + User::create([ 'name' => $this->name, 'email' => $this->email, 'password' => Hash::make($this->password) ]); - // login user - auth()->login($user); - - // redirect to home page - return redirect()->intended(); + // set success message + session()->flash('success', 'Registrasi berhasil! Silakan login untuk melanjutkan.'); + // redirect to login page + return redirect()->route('login'); } public function render() { diff --git a/app/Livewire/Auth/ResetPasswordPage.php b/app/Livewire/Auth/ResetPasswordPage.php index 5866742..aeacaa6 100644 --- a/app/Livewire/Auth/ResetPasswordPage.php +++ b/app/Livewire/Auth/ResetPasswordPage.php @@ -3,9 +3,58 @@ namespace App\Livewire\Auth; use Livewire\Component; +use Illuminate\Auth\Events\PasswordReset; +use Illuminate\Support\Facades\Password; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; +use App\Models\User; class ResetPasswordPage extends Component { + public $token; + #[Url] + public $email; + public $password; + public $password_confirmation; + + public function mount($token = null) + { + $this->token = $token ?? request()->route('token'); + $this->email = request()->query('email'); + } + + public function save() + { + $this->validate([ + 'email' => 'required|email|exists:users,email', + 'password' => 'required|min:6|confirmed', + ]); + + $status = Password::reset( + [ + 'email' => $this->email, + 'password' => $this->password, + 'password_confirmation' => $this->password_confirmation, + 'token' => $this->token, + ], + function (User $user, string $password) { + $password = $this->password; + $user->forceFill([ + 'password' => Hash::make($password) + ])->setRememberToken(Str::random(60)); + $user->save(); + event(new PasswordReset($user)); + } + ); + + if ($status == Password::PASSWORD_RESET) { + session()->flash('success', 'Password berhasil diubah!'); + return redirect('/login'); + } else { + session()->flash('error', 'Terjadi kesalahan. Silakan coba lagi.'); + } + } + public function render() { return view('livewire.auth.reset-password-page'); diff --git a/app/Livewire/UploadBuktiPembayaran.php b/app/Livewire/UploadBuktiPembayaran.php index 17a22f5..e541d76 100644 --- a/app/Livewire/UploadBuktiPembayaran.php +++ b/app/Livewire/UploadBuktiPembayaran.php @@ -67,7 +67,7 @@ public function getTimeLeftProperty() } $createdAt = Carbon::parse($this->booking->created_at); - $expiryTime = $createdAt->addMinutes(5); + $expiryTime = $createdAt->addMinutes(1); return max(0, Carbon::now()->diffInSeconds($expiryTime)); } diff --git a/app/Models/Reservasii.php b/app/Models/Reservasii.php index d99e4c9..6c43afa 100644 --- a/app/Models/Reservasii.php +++ b/app/Models/Reservasii.php @@ -4,10 +4,13 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Notifications\Notifiable; +use App\Notifications\ReservasiApproved; +use Illuminate\Support\Facades\Log; class Reservasii extends Model { - use HasFactory; + use HasFactory, Notifiable; protected $fillable = [ 'user_id', @@ -24,9 +27,8 @@ class Reservasii extends Model protected $casts = [ 'tanggal' => 'date', - 'waktu' => 'datetime', - 'total' => 'decimal:2', - 'bukti_pembayaran' => 'array' + 'waktu' => 'string', + 'total' => 'decimal:2' ]; public function user() @@ -45,6 +47,21 @@ public function paketFoto() { return $this->belongsTo(PaketFoto::class); } + + protected static function booted() + { + static::updated(function ($reservasi) { + if ($reservasi->isDirty('status_pembayaran') && $reservasi->status_pembayaran === 'approved') { + Log::info('Mencoba mengirim notifikasi email untuk reservasi ID: ' . $reservasi->id); + try { + $reservasi->notify(new ReservasiApproved($reservasi)); + Log::info('Notifikasi email berhasil dikirim untuk reservasi ID: ' . $reservasi->id); + } catch (\Exception $e) { + Log::error('Gagal mengirim notifikasi email: ' . $e->getMessage()); + } + } + }); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 25b984e..192307a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -54,4 +54,9 @@ public function canAccessPanel(Panel $panel): bool { return $this->email == 'admin@gmail.com'; } + + public function routeNotificationForMail() + { + return $this->email; + } } diff --git a/app/Notifications/ReservasiApproved.php b/app/Notifications/ReservasiApproved.php new file mode 100644 index 0000000..cab7e78 --- /dev/null +++ b/app/Notifications/ReservasiApproved.php @@ -0,0 +1,45 @@ +reservasi = $reservasi; + Log::info('Notifikasi ReservasiApproved dibuat untuk reservasi ID: ' . $reservasi->id); + } + + public function via($notifiable) + { + Log::info('Mengirim notifikasi via email untuk reservasi ID: ' . $this->reservasi->id); + return ['mail']; + } + + public function toMail($notifiable) + { + Log::info('Menyiapkan email untuk reservasi ID: ' . $this->reservasi->id); + return (new MailMessage) + ->subject('Reservasi Anda Telah Disetujui') + ->greeting('Halo ' . $this->reservasi->nama . '!') + ->line('Reservasi Anda dengan nomor ID: ' . $this->reservasi->id . ' telah disetujui.') + ->line('Detail Reservasi:') + ->line('Tanggal: ' . $this->reservasi->tanggal->format('d F Y')) + ->line('Waktu: ' . $this->reservasi->waktu) + ->line('Total Pembayaran: Rp ' . number_format($this->reservasi->total, 0, ',', '.')) + ->line('Silahkan datang sesuai dengan jadwal yang telah ditentukan.') + ->line('Terima kasih telah memilih layanan kami!') + ->salutation('Salam, Tim SiKolaself'); + } +} \ No newline at end of file diff --git a/database/migrations/2025_02_20_043621_create_reservasiis_table.php b/database/migrations/2025_02_20_043621_create_reservasiis_table.php index 1fb583e..1ee2e1d 100644 --- a/database/migrations/2025_02_20_043621_create_reservasiis_table.php +++ b/database/migrations/2025_02_20_043621_create_reservasiis_table.php @@ -23,6 +23,8 @@ public function up(): void $table->string('metode_pembayaran'); $table->string('bukti_pembayaran')->nullable(); $table->enum('status_pembayaran', ['pending', 'approved', 'rejected'])->default('pending'); + $table->decimal('diskon', 10, 2)->default(0); + $table->decimal('total_setelah_diskon', 10, 2)->default(0); $table->timestamps(); }); } diff --git a/resources/views/livewire/auth/forgot-password-page.blade.php b/resources/views/livewire/auth/forgot-password-page.blade.php index 8161d7b..5f79167 100644 --- a/resources/views/livewire/auth/forgot-password-page.blade.php +++ b/resources/views/livewire/auth/forgot-password-page.blade.php @@ -29,7 +29,7 @@
- +
diff --git a/resources/views/livewire/auth/login-page.blade.php b/resources/views/livewire/auth/login-page.blade.php index 8331724..18f0088 100644 --- a/resources/views/livewire/auth/login-page.blade.php +++ b/resources/views/livewire/auth/login-page.blade.php @@ -13,6 +13,12 @@

Login

+ @if (session('success')) + + @endif + @if (session('error'))
diff --git a/resources/views/livewire/auth/reset-password-page.blade.php b/resources/views/livewire/auth/reset-password-page.blade.php index a0b6d9e..4335516 100644 --- a/resources/views/livewire/auth/reset-password-page.blade.php +++ b/resources/views/livewire/auth/reset-password-page.blade.php @@ -7,43 +7,64 @@

Reset password

+ @if (session()->has('error')) + + @endif + + @if (session()->has('success')) + + @endif +
- +
- -
- -
+ + @error('password') +
+ +
+ @enderror
-

Password error message

+ @error('password') +

{{ $message }}

+ @enderror
- +
- + - + @error('password_confirmation') +
+ +
+ @enderror
-

Confirm Password Error

+ @error('password_confirmation') +

{{ $message }}

+ @enderror