File: /home/xedaptot/rms.naniguide.com/app/Http/Controllers/AdminController.php
<?php
namespace App\Http\Controllers;
use App\Models\Hotel;
use App\Models\PricingRule;
use App\Models\RoomType;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class AdminController extends Controller
{
public function index()
{
return view('admin.index', [
'users' => User::with('hotel')->get(),
'hotels' => Hotel::withCount('roomTypes')->get(),
'roomTypes' => RoomType::with('hotel')->get(),
'pricingRules' => PricingRule::with('hotel')->get(),
]);
}
public function storeUser(Request $request)
{
$data = $request->validate([
'name' => ['required'],
'email' => ['required', 'email', 'unique:users,email'],
'hotel_id' => ['nullable', 'exists:hotels,id'],
'role' => ['required', 'in:admin,revenue_manager,reservation_staff'],
'password' => ['required', 'min:6'],
]);
$data['password'] = Hash::make($data['password']);
User::create($data);
return back()->with('status', 'Đã tạo user.');
}
public function storeHotel(Request $request)
{
Hotel::create($request->validate([
'name' => ['required'],
'code' => ['required', 'unique:hotels,code'],
'city' => ['nullable'],
'currency' => ['required', 'size:3'],
'total_rooms' => ['required', 'integer'],
'gross_profit_margin' => ['required', 'numeric'],
]));
return back()->with('status', 'Đã tạo hotel.');
}
public function storePricingRule(Request $request)
{
PricingRule::create($request->validate([
'hotel_id' => ['required', 'exists:hotels,id'],
'name' => ['required'],
'occupancy_min' => ['nullable', 'numeric'],
'occupancy_max' => ['nullable', 'numeric'],
'pickup_min' => ['nullable', 'integer'],
'booking_window_min' => ['nullable', 'integer'],
'booking_window_max' => ['nullable', 'integer'],
'day_of_week' => ['nullable'],
'season' => ['nullable'],
'adjustment_percent' => ['required', 'numeric'],
]) + ['active' => $request->boolean('active', true)]);
return back()->with('status', 'Đã tạo pricing rule.');
}
}