menerapkan harga promo

This commit is contained in:
hildaaaevs 2025-05-29 19:07:16 +07:00
parent 33f1cd84c1
commit ef86fd79e5
5 changed files with 68 additions and 17 deletions

View File

@ -216,7 +216,6 @@ public static function table(Table $table): Table
->color(fn (string $state): string => match (strtolower($state)) { ->color(fn (string $state): string => match (strtolower($state)) {
'full' => 'success', 'full' => 'success',
'dp' => 'danger', 'dp' => 'danger',
default => 'secondary',
}), }),
Tables\Columns\TextColumn::make('metode_pembayaran') Tables\Columns\TextColumn::make('metode_pembayaran')

View File

@ -17,6 +17,9 @@ class BookingPage extends Component
public $tipe_pembayaran = ''; public $tipe_pembayaran = '';
public $bookedTimes = []; public $bookedTimes = [];
public $unavailableTimes = []; public $unavailableTimes = [];
public $promoApplied = false;
public $promoDiscount = 0;
public $promoData = null;
public function mount($id = null) public function mount($id = null)
{ {
@ -80,6 +83,45 @@ public function getBookedTimesProperty()
return $this->bookedTimes; return $this->bookedTimes;
} }
public function applyPromo()
{
$this->promoApplied = false;
$this->promoDiscount = 0;
$this->promoData = null;
if (empty($this->promo)) {
return;
}
$promo = \App\Models\Promo::where('kode', $this->promo)
->where('aktif', true)
->first();
if (!$promo) {
$this->addError('promo', 'Kode promo tidak valid');
return;
}
$this->promoData = $promo;
$this->promoApplied = true;
// Hitung diskon berdasarkan tipe promo
if ($promo->tipe === 'fix') {
$this->promoDiscount = $promo->diskon;
} else if ($promo->tipe === 'persen') {
$this->promoDiscount = ($this->paketfoto->harga_paket_foto * $promo->diskon) / 100;
}
}
public function getTotalPriceProperty()
{
$total = $this->paketfoto->harga_paket_foto;
if ($this->promoApplied) {
$total -= $this->promoDiscount;
}
return max(0, $total); // Pastikan total tidak negatif
}
public function placeOrder() public function placeOrder()
{ {
$this->validate([ $this->validate([
@ -111,8 +153,8 @@ public function placeOrder()
'nama' => $this->nama, 'nama' => $this->nama,
'tanggal' => $this->tanggal, 'tanggal' => $this->tanggal,
'waktu' => $this->waktu, 'waktu' => $this->waktu,
'promo_id' => null, // Logika promo bisa ditambahkan di sini 'promo_id' => $this->promoData ? $this->promoData->id : null,
'total' => $this->paketfoto->harga_paket_foto, 'total' => $this->totalPrice,
'tipe_pembayaran' => $this->tipe_pembayaran, 'tipe_pembayaran' => $this->tipe_pembayaran,
'metode_pembayaran' => 'transfer', // Default transfer, bisa diubah sesuai pilihan 'metode_pembayaran' => 'transfer', // Default transfer, bisa diubah sesuai pilihan
]); ]);
@ -123,7 +165,7 @@ public function placeOrder()
'warna' => $this->warna, 'warna' => $this->warna,
'jumlah' => 1, 'jumlah' => 1,
'harga' => $this->paketfoto->harga_paket_foto, 'harga' => $this->paketfoto->harga_paket_foto,
'total_harga' => $this->paketfoto->harga_paket_foto, 'total_harga' => $this->totalPrice,
]); ]);
// Tampilkan pesan sukses dan redirect // Tampilkan pesan sukses dan redirect

View File

@ -17,7 +17,7 @@ public function mount($id = null)
} }
// Ambil booking berdasarkan ID jika ada, jika tidak ambil yang terakhir // Ambil booking berdasarkan ID jika ada, jika tidak ambil yang terakhir
$this->booking = Reservasii::with(['user', 'detail.paketFoto']) $this->booking = Reservasii::with(['user', 'detail.paketFoto', 'promo'])
->where('user_id', auth()->id()) ->where('user_id', auth()->id())
->when($id, function($query) use ($id) { ->when($id, function($query) use ($id) {
return $query->where('id', $id); return $query->where('id', $id);

View File

@ -89,9 +89,15 @@ class="{{ $isUnavailable ? 'text-gray-400 bg-gray-100' : '' }}"
Kode Promo (jika ada) Kode Promo (jika ada)
</label> </label>
<div class="flex gap-2"> <div class="flex gap-2">
<input wire:model="promo" class="w-full rounded-lg border py-2 px-3 dark:bg-gray-700 dark:text-white dark:border-none " id="promo" type="text" placeholder="Masukkan kode promo"> <input wire:model="promo" class="w-full rounded-lg border py-2 px-3 dark:bg-gray-700 dark:text-white dark:border-none @error('promo') border-red-500 @enderror" id="promo" type="text" placeholder="Masukkan kode promo">
<button type="button" class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600">Terapkan</button> <button type="button" wire:click="applyPromo" class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600">Terapkan</button>
</div> </div>
@error('promo')
<div class="text-red-500 text-sm">{{ $message }}</div>
@enderror
@if($promoApplied)
<div class="text-green-500 text-sm mt-1">Promo berhasil diterapkan!</div>
@endif
</div> </div>
</div> </div>
@ -210,25 +216,23 @@ class="{{ $isUnavailable ? 'text-gray-400 bg-gray-100' : '' }}"
@endif @endif
</span> </span>
</div> </div>
<div class="flex justify-between mb-2 font-bold"> @if($promoApplied)
<div class="flex justify-between mb-2">
<span> <span>
Potongan Potongan Promo
</span> </span>
<span> <span class="text-green-500">
{{ Number::currency(0, 'IDR') }} - {{ Number::currency($promoDiscount, 'IDR') }}
</span> </span>
</div> </div>
@endif
<hr class="bg-slate-400 my-4 h-1 rounded"> <hr class="bg-slate-400 my-4 h-1 rounded">
<div class="flex justify-between mb-2 font-bold"> <div class="flex justify-between mb-2 font-bold">
<span> <span>
Grand Total Grand Total
</span> </span>
<span> <span>
@if($paketfoto) {{ Number::currency($this->totalPrice, 'IDR') }}
{{ Number::currency($paketfoto->harga_paket_foto, 'IDR') }}
@else
{{ Number::currency(0, 'IDR') }}
@endif
</span> </span>
</div> </div>
</hr> </hr>

View File

@ -56,13 +56,19 @@
@foreach($booking->detail as $detail) @foreach($booking->detail as $detail)
<div class="flex justify-between w-full"> <div class="flex justify-between w-full">
<p class="text-base leading-4 text-gray-800 dark:text-gray-400">{{ $detail->paketFoto->nama_paket_foto }}</p> <p class="text-base leading-4 text-gray-800 dark:text-gray-400">{{ $detail->paketFoto->nama_paket_foto }}</p>
<p class="text-base leading-4 text-gray-600 dark:text-gray-400">Rp {{ number_format($detail->total_harga, 0, ',', '.') }}</p> <p class="text-base leading-4 text-gray-600 dark:text-gray-400">Rp {{ number_format($detail->harga, 0, ',', '.') }}</p>
</div> </div>
<div class="flex justify-between w-full"> <div class="flex justify-between w-full">
<p class="text-base leading-4 text-gray-800 dark:text-gray-400">Background: {{ ucfirst($detail->warna) }}</p> <p class="text-base leading-4 text-gray-800 dark:text-gray-400">Background: {{ ucfirst($detail->warna) }}</p>
</div> </div>
@endforeach @endforeach
</div> </div>
@if($booking->promo)
<div class="flex items-center justify-between w-full">
<p class="text-base leading-4 text-gray-800 dark:text-gray-400">Promo: {{ $booking->promo->kode }}</p>
<p class="text-base leading-4 text-green-600 dark:text-green-400">- Rp {{ number_format($booking->detail->sum('harga') - $booking->total, 0, ',', '.') }}</p>
</div>
@endif
<div class="flex items-center justify-between w-full"> <div class="flex items-center justify-between w-full">
<p class="text-base font-semibold leading-4 text-gray-800 dark:text-gray-400">Total</p> <p class="text-base font-semibold leading-4 text-gray-800 dark:text-gray-400">Total</p>
<p class="text-base font-semibold leading-4 text-gray-600 dark:text-gray-400">Rp {{ number_format($booking->total, 0, ',', '.') }}</p> <p class="text-base font-semibold leading-4 text-gray-600 dark:text-gray-400">Rp {{ number_format($booking->total, 0, ',', '.') }}</p>