Format Email
This commit is contained in:
parent
1e5e982a5f
commit
f1761af8b5
|
@ -6,6 +6,7 @@
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use App\Notifications\ReservasiApproved;
|
use App\Notifications\ReservasiApproved;
|
||||||
|
use App\Notifications\ReservasiRejected;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class Reservasii extends Model
|
class Reservasii extends Model
|
||||||
|
@ -51,27 +52,44 @@ public function paketFoto()
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::updated(function ($reservasi) {
|
static::updated(function ($reservasi) {
|
||||||
if ($reservasi->isDirty('status_pembayaran') && $reservasi->status_pembayaran === 'approved') {
|
// Cek apakah status pembayaran berubah
|
||||||
Log::info('Mencoba mengirim notifikasi email untuk reservasi ID: ' . $reservasi->id);
|
if ($reservasi->isDirty('status_pembayaran')) {
|
||||||
try {
|
// Jika status menjadi 'approved'
|
||||||
$reservasi->notify(new ReservasiApproved($reservasi));
|
if ($reservasi->status_pembayaran === 'approved') {
|
||||||
Log::info('Notifikasi email berhasil dikirim untuk reservasi ID: ' . $reservasi->id);
|
// Kirim notifikasi 'approved' ke user
|
||||||
} catch (\Exception $e) {
|
try {
|
||||||
Log::error('Gagal mengirim notifikasi email: ' . $e->getMessage());
|
$reservasi->user->notify(new ReservasiApproved($reservasi));
|
||||||
}
|
Log::info('Notifikasi email [approved] berhasil dikirim untuk reservasi ID: ' . $reservasi->id);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Gagal mengirim notifikasi email [approved]: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
// Otomatis reject reservasi lain yang bentrok
|
// Otomatis reject reservasi lain yang bentrok
|
||||||
$paketFotoIds = $reservasi->detail()->pluck('paket_foto_id')->toArray();
|
$paketFotoIds = $reservasi->detail()->pluck('paket_foto_id')->toArray();
|
||||||
$reservasiBentrok = self::where('id', '!=', $reservasi->id)
|
$reservasiBentrok = self::where('id', '!=', $reservasi->id)
|
||||||
->where('tanggal', $reservasi->tanggal)
|
->where('tanggal', $reservasi->tanggal)
|
||||||
->where('waktu', $reservasi->waktu)
|
->where('waktu', $reservasi->waktu)
|
||||||
->where('status_pembayaran', 'pending')
|
->where('status_pembayaran', 'pending')
|
||||||
->whereHas('detail', function($q) use ($paketFotoIds) {
|
->whereHas('detail', function($q) use ($paketFotoIds) {
|
||||||
$q->whereIn('paket_foto_id', $paketFotoIds);
|
$q->whereIn('paket_foto_id', $paketFotoIds);
|
||||||
})
|
})
|
||||||
->get();
|
->get();
|
||||||
foreach ($reservasiBentrok as $r) {
|
|
||||||
$r->update(['status_pembayaran' => 'rejected']);
|
foreach ($reservasiBentrok as $r) {
|
||||||
|
// Update ini akan memicu event 'updated' lagi untuk reservasi yang ditolak,
|
||||||
|
// sehingga notifikasi 'rejected' akan terkirim secara otomatis.
|
||||||
|
$r->update(['status_pembayaran' => 'rejected']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Jika status menjadi 'rejected'
|
||||||
|
elseif ($reservasi->status_pembayaran === 'rejected') {
|
||||||
|
// Kirim notifikasi 'rejected' ke user
|
||||||
|
try {
|
||||||
|
$reservasi->user->notify(new ReservasiRejected($reservasi));
|
||||||
|
Log::info('Notifikasi email [rejected] berhasil dikirim untuk reservasi ID: ' . $reservasi->id);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Gagal mengirim notifikasi email [rejected]: ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,14 +32,14 @@ public function toMail($notifiable)
|
||||||
Log::info('Menyiapkan email untuk reservasi ID: ' . $this->reservasi->id);
|
Log::info('Menyiapkan email untuk reservasi ID: ' . $this->reservasi->id);
|
||||||
return (new MailMessage)
|
return (new MailMessage)
|
||||||
->subject('Reservasi Anda Telah Disetujui')
|
->subject('Reservasi Anda Telah Disetujui')
|
||||||
->greeting('Halo ' . $this->reservasi->nama . '!')
|
->greeting('Halo Sobat Minko!')
|
||||||
->line('Reservasi Anda dengan nomor ID: ' . $this->reservasi->id . ' telah disetujui.')
|
->line('Reservasi Anda dengan nama : ' . $this->reservasi->nama . ' telah disetujui.')
|
||||||
->line('Detail Reservasi:')
|
->line('Detail Reservasi')
|
||||||
->line('Tanggal: ' . $this->reservasi->tanggal->format('d F Y'))
|
->line('Tanggal : ' . $this->reservasi->tanggal->format('d F Y'))
|
||||||
->line('Waktu: ' . $this->reservasi->waktu)
|
->line('Waktu : ' . $this->reservasi->waktu)
|
||||||
->line('Total Pembayaran: Rp ' . number_format($this->reservasi->total, 0, ',', '.'))
|
->line('Total Pembayaran : Rp ' . number_format($this->reservasi->total, 0, ',', '.'))
|
||||||
->line('Silahkan datang sesuai dengan jadwal yang telah ditentukan.')
|
->line('Silahkan datang sesuai dengan jadwal yang telah ditentukan.')
|
||||||
->line('Terima kasih telah memilih layanan kami!')
|
->line('Terima kasih telah memilih layanan kami!')
|
||||||
->salutation('Salam, Tim SiKolaself');
|
->salutation('Salam dari Minko');
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use App\Models\Reservasii;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class ReservasiRejected extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
protected $reservasi;
|
||||||
|
|
||||||
|
public function __construct(Reservasii $reservasi)
|
||||||
|
{
|
||||||
|
$this->reservasi = $reservasi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->subject('Reservasi Anda Ditolak')
|
||||||
|
->greeting('Halo Sobat Minko!')
|
||||||
|
->line('Mohon maaf, reservasi Anda dengan nama : ' . $this->reservasi->nama . ' telah ditolak.')
|
||||||
|
->line('Tanggal : ' . Carbon::parse($this->reservasi->tanggal)->format('d F Y'))
|
||||||
|
->line('Waktu : ' . $this->reservasi->waktu)
|
||||||
|
->line('Hal ini terjadi karena jadwal sudah penuh atau ada masalah dengan pembayaran.')
|
||||||
|
->line('Jika Anda merasa ini adalah sebuah kesalahan, silakan hubungi kami pada nomor dibawah ini.')
|
||||||
|
->line('WA : 082131919312')
|
||||||
|
->line('Terima kasih atas pengertian Anda.')
|
||||||
|
->salutation('Salam dari Minko');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue