2026-01-20 09:44:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\UtilityFee;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
|
|
|
|
|
class UtilityFeeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$query = UtilityFee::query();
|
|
|
|
|
|
|
|
|
|
// Search
|
|
|
|
|
if ($request->has('search')) {
|
|
|
|
|
$search = $request->input('search');
|
|
|
|
|
$query->where(function($q) use ($search) {
|
|
|
|
|
$q->where('category', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('invoice_number', 'like', "%{$search}%")
|
|
|
|
|
->orWhere('description', 'like', "%{$search}%");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filtering
|
|
|
|
|
if ($request->filled('category') && $request->input('category') !== 'all') {
|
|
|
|
|
$query->where('category', $request->input('category'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($request->filled('date_start')) {
|
|
|
|
|
$query->where('transaction_date', '>=', $request->input('date_start'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($request->filled('date_end')) {
|
|
|
|
|
$query->where('transaction_date', '<=', $request->input('date_end'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sorting
|
2026-01-20 10:41:35 +08:00
|
|
|
$sortField = $request->input('sort_field');
|
|
|
|
|
$sortDirection = $request->input('sort_direction');
|
|
|
|
|
|
|
|
|
|
if ($sortField && $sortDirection) {
|
|
|
|
|
$query->orderBy($sortField, $sortDirection);
|
|
|
|
|
} else {
|
2026-01-20 14:03:59 +08:00
|
|
|
$query->orderBy('created_at', 'desc');
|
2026-01-20 10:41:35 +08:00
|
|
|
}
|
2026-01-20 09:44:05 +08:00
|
|
|
|
|
|
|
|
$fees = $query->paginate($request->input('per_page', 15))->withQueryString();
|
|
|
|
|
|
|
|
|
|
$availableCategories = UtilityFee::distinct()->pluck('category');
|
|
|
|
|
|
|
|
|
|
return Inertia::render('UtilityFee/Index', [
|
|
|
|
|
'fees' => $fees,
|
|
|
|
|
'availableCategories' => $availableCategories,
|
|
|
|
|
'filters' => $request->only(['search', 'category', 'date_start', 'date_end', 'sort_field', 'sort_direction']),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'transaction_date' => 'required|date',
|
|
|
|
|
'category' => 'required|string|max:255',
|
|
|
|
|
'amount' => 'required|numeric|min:0',
|
|
|
|
|
'invoice_number' => 'nullable|string|max:255',
|
|
|
|
|
'description' => 'nullable|string',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
UtilityFee::create($validated);
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(Request $request, UtilityFee $utility_fee)
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'transaction_date' => 'required|date',
|
|
|
|
|
'category' => 'required|string|max:255',
|
|
|
|
|
'amount' => 'required|numeric|min:0',
|
|
|
|
|
'invoice_number' => 'nullable|string|max:255',
|
|
|
|
|
'description' => 'nullable|string',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$utility_fee->update($validated);
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy(UtilityFee $utility_fee)
|
|
|
|
|
{
|
|
|
|
|
$utility_fee->delete();
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
}
|