Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions app/Http/Controllers/Admin/AdminBookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class AdminBookingController extends Controller
{
/**
* Tampilkan daftar pesanan.
* Tampilkan daftar semua pesanan.
*/
public function index()
{
Expand All @@ -29,85 +29,103 @@ public function show(string $id)
}

/**
* Konfirmasi pembayaran DP dan arahkan ke WhatsApp.
* Konfirmasi DP: simpan bukti, ubah status ke 'booked', lalu arahkan ke WhatsApp.
*/
public function confirmDp(Request $request, $id)
{
$booking = Booking::findOrFail($id);

// Validasi input
$request->validate([
'dp_amount' => 'required|numeric|min:0',
'dp_proof' => 'required|image|max:2048',
]);

// Simpan bukti DP
$path = $request->file('dp_proof')->store('bukti_dp', 'public');

// Update data booking
$booking->update([
'dp_amount' => $request->dp_amount,
'dp_proof' => $path,
'status' => 'booked',
]);

// Pesan sukses
// Set pesan sukses
session()->flash('success', 'DP berhasil dikonfirmasi. Silakan kirim pesan ke pelanggan.');

// Pesan WhatsApp
// Buat pesan WhatsApp
$message = "Halo kak {$booking->contact_name},\n\n"
. "Terima kasih, DP kamu untuk sesi {$booking->session_name} pada tanggal "
. Carbon::parse($booking->booking_date)->format('d F Y') . " pukul {$booking->booking_time} telah kami terima.\n"
. "Pesananmu sudah dikonfirmasi. Sampai jumpa di hari H!";
. Carbon::parse($booking->booking_date)->translatedFormat('d F Y') . " pukul {$booking->booking_time} telah kami terima.\n"
. "Pesananmu sudah dikonfirmasi Sampai jumpa di hari H!";

// Format nomor WhatsApp (08xx → 628xx)
$whatsappNumber = preg_replace('/[^0-9]/', '', $booking->whatsapp_number);
if (str_starts_with($whatsappNumber, '0')) {
$whatsappNumber = '62' . substr($whatsappNumber, 1);
}

// ✅ URL BENAR: TANPA SPASI EKSTRA
$url = 'https://wa.me/' . $whatsappNumber . '?text=' . urlencode($message);

return redirect()->away($url);
}

/**
* Selesaikan pesanan (pelunasan) dan arahkan ke WhatsApp.
* Selesaikan pesanan: simpan bukti pelunasan, ubah status ke 'completed', lalu arahkan ke WhatsApp.
*/
public function completeBooking(Request $request, $id)
{
$booking = Booking::findOrFail($id);

// Validasi input
$request->validate([
'final_payment_amount' => 'required|numeric|min:0',
'final_payment_proof' => 'required|image|max:2048',
]);

// Simpan bukti pelunasan
$path = $request->file('final_payment_proof')->store('bukti_pelunasan', 'public');

// Update data booking
$booking->update([
'final_payment_amount' => $request->final_payment_amount,
'final_payment_proof' => $path,
'status' => 'completed',
]);

// Pesan sukses
session()->flash('success', 'Pelunasan berhasil dikonfirmasi. Silakan kirim konfirmasi ke pelanggan.');
// Set pesan sukses
session()->flash('success', 'Pelunasan berhasil dikonfirmasi.');

// Pesan WhatsApp
// Buat pesan WhatsApp
$message = "Halo kak {$booking->contact_name},\n\n"
. "Kami telah menerima pelunasan untuk sesi {$booking->session_name} pada tanggal "
. Carbon::parse($booking->booking_date)->format('d F Y') . ".\n"
. "Terima kasih telah mempercayakan layanan kami. See you next time!";
. Carbon::parse($booking->booking_date)->translatedFormat('d F Y') . ".\n"
. "Terima kasih telah mempercayakan layanan kami. See you next time! ❤️";

// Format nomor WhatsApp
$whatsappNumber = preg_replace('/[^0-9]/', '', $booking->whatsapp_number);
if (str_starts_with($whatsappNumber, '0')) {
$whatsappNumber = '62' . substr($whatsappNumber, 1);
}

// ✅ URL BENAR: TANPA SPASI EKSTRA
$url = 'https://wa.me/' . $whatsappNumber . '?text=' . urlencode($message);

return redirect()->away($url);
}

/**
* Hapus pesanan dan hapus file bukti pembayaran.
* Hapus pesanan dan file bukti pembayaran.
*/
public function destroy(Booking $booking)
{
// Hapus file bukti jika ada
if ($booking->dp_proof) {
if ($booking->dp_proof && Storage::disk('public')->exists($booking->dp_proof)) {
Storage::disk('public')->delete($booking->dp_proof);
}
if ($booking->final_payment_proof) {
if ($booking->final_payment_proof && Storage::disk('public')->exists($booking->final_payment_proof)) {
Storage::disk('public')->delete($booking->final_payment_proof);
}

Expand Down
50 changes: 50 additions & 0 deletions app/Http/Controllers/BookingAvailabilityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Http\Controllers;

use App\Models\Booking;
use Illuminate\Http\Request;

class BookingAvailabilityController extends Controller
{
/**
* Dapatkan waktu yang tersedia berdasarkan tanggal.
*/
public function getAvailableTimes(Request $request)
{
$request->validate([
'booking_date' => 'required|date',
]);

$date = $request->booking_date;

// Daftar waktu yang tersedia (bisa Anda sesuaikan)
$allTimes = [
'10:00', '11:00', '12:00', '13:00',
'14:00', '15:00', '16:00'
];

// Ambil semua booking untuk tanggal tersebut
$bookedTimes = Booking::where('booking_date', $date)
->pluck('booking_time')
->toArray();

// Waktu yang tersedia = semua waktu - yang sudah booked
$availableTimes = array_values(array_diff($allTimes, $bookedTimes));

// Tentukan status hari: tersedia, sebagian, atau full
$status = 'available';
if (empty($availableTimes)) {
$status = 'full';
} elseif (count($availableTimes) < 3) {
$status = 'limited';
}

return response()->json([
'available_times' => $availableTimes,
'booked_times' => $bookedTimes,
'status' => $status,
'date' => $date,
]);
}
}
32 changes: 18 additions & 14 deletions app/Http/Controllers/BookingController.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
<?php

namespace App\Http\Controllers;

use App\Models\Booking;

use Illuminate\Http\Request;

class BookingController extends Controller
{
/**
/**
* Menyimpan pesanan baru dari form frontend.
*/
public function store(Request $request)
{
// 1. Validasi data yang masuk
$validatedData = $request->validate([
$request->validate([
'contact_name' => 'required|string|max:255',
'whatsapp_number' => 'required|string|max:20',
'booking_date' => 'required|date|after_or_equal:today',
'booking_time' => 'required|string',
'booking_time' => 'required|string|in:10:00,11:00,12:00,13:00,14:00,15:00,16:00',
'session_name' => 'required|string|max:255',
'package_name' => 'required|string|max:255',
'selected_backgrounds' => 'nullable|array',
'selected_extra_items' => 'nullable|array',
'total_price' => 'required|integer|min:0',
'notes' => 'nullable|string',
'baby_name' => 'nullable|string|max:255', // tambahkan
'baby_age' => 'nullable|string|in:1-year,2-years,3-years,4-years,5-years,6-years', // tambahkan
]);

// 2. Buat pesanan baru di database
// Data yang disimpan adalah yang sudah divalidasi
try {
$booking = Booking::create($validatedData);
// 🔒 Cek apakah waktu sudah diambil
$exists = Booking::where('booking_date', $request->booking_date)
->where('booking_time', $request->booking_time)
->exists();

// 3. Kirim notifikasi (opsional, bisa ke WhatsApp, email, dll)
// Di sini kita bisa menambahkan logika untuk notifikasi
// misalnya mengirim notifikasi ke admin
if ($exists) {
return response()->json([
'message' => 'Maaf, waktu yang Anda pilih sudah tidak tersedia. Silakan pilih waktu lain.',
], 409); // 409 Conflict
}

try {
$booking = Booking::create($request->all());

// 4. Berikan respon sukses ke frontend
return response()->json([
'message' => 'Pesanan Anda berhasil disimpan!',
'booking_id' => $booking->id
], 201);

} catch (\Exception $e) {
// Tangani error jika terjadi
return response()->json([
'message' => 'Terjadi kesalahan saat menyimpan pesanan.',
'error' => $e->getMessage()
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Booking extends Model
'dp_proof',
'final_payment_amount',
'final_payment_proof',
'baby_name', // tambahkan
'baby_age', // tambahkan
];


Expand All @@ -30,4 +32,12 @@ class Booking extends Model
'selected_backgrounds' => 'array',
'selected_extra_items' => 'array',
];


public static function getAvailableTimes($date)
{
$booked = self::where('booking_date', $date)->pluck('booking_time')->toArray();
$all = ['10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00'];
return array_values(array_diff($all, $booked));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function up(): void
$table->integer('total_price');
$table->text('notes')->nullable();
$table->enum('status', ['waiting', 'booked', 'completed', 'cancelled'])->default('waiting');
$table->string('baby_name')->nullable();
$table->string('baby_age')->nullable();
$table->timestamps();
});
}
Expand Down
Loading