Files
Kol-Manager/app/Http/Controllers/EventController.php
I-Fun 22f03ccca7 Add contract management and invoice settings pages
- Created a new Blade view for managing brand contracts with forms for adding and editing contracts, including client and category selection.
- Implemented success message notifications for contract actions.
- Added a new Blade view for invoice settings, allowing customization of invoice number format, header branding, and default values for new invoices.
- Introduced a new PDF view for generating rate cards with customizable styles based on user profile settings.
- Developed a profile management page for rate cards, enabling users to update their identity, appearance, and visibility settings.
2026-04-01 21:47:34 +07:00

151 lines
5.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Enums\EventStatus;
use App\Models\Client;
use App\Models\ClientCategory;
use App\Models\Event;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class EventController extends Controller
{
private function categoryTree(): \Illuminate\Support\Collection
{
return ClientCategory::with('children')
->whereNull('parent_id')
->orderBy('sort_order')
->get();
}
public function index(): View
{
$events = Event::with('client')->orderBy('start_time')->get();
$clients = Client::where('status', 'active')->orderBy('name')->get();
$categoryTree = $this->categoryTree();
// Format for FullCalendar
$calendarEvents = $events->map(fn (Event $e) => [
'id' => $e->id,
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
'start' => $e->start_time->toIso8601String(),
'end' => $e->end_time?->toIso8601String(),
'backgroundColor' => $e->color,
'borderColor' => $e->color,
'extendedProps' => [
'status' => $e->status->value,
'client' => $e->client?->name,
'type' => $e->event_type,
'priority' => $e->is_priority,
],
]);
return view('schedule.index', compact('events', 'clients', 'calendarEvents', 'categoryTree'));
}
public function store(Request $request): RedirectResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'client_id' => 'nullable|exists:clients,id',
'category_id' => 'nullable|exists:client_categories,id',
'event_type' => 'required|in:task,meeting,deadline,posting',
'start_time' => 'required|date',
'end_time' => 'nullable|date|after:start_time',
'location' => 'nullable|string|max:255',
'is_priority' => 'boolean',
'is_all_day' => 'boolean',
'color' => 'nullable|string|max:20',
'notes' => 'nullable|string',
]);
$validated['is_priority'] = $request->boolean('is_priority');
$validated['is_all_day'] = $request->boolean('is_all_day');
Event::create($validated);
return redirect()->route('schedule.index')
->with('success', '🐾 Event scheduled!');
}
public function edit(Event $event): View
{
$clients = Client::where('status', 'active')->orderBy('name')->get();
$statuses = EventStatus::cases();
$categoryTree = $this->categoryTree();
return view('schedule.edit', compact('event', 'clients', 'statuses', 'categoryTree'));
}
public function update(Request $request, Event $event): RedirectResponse
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'client_id' => 'nullable|exists:clients,id',
'category_id' => 'nullable|exists:client_categories,id',
'event_type' => 'required|in:task,meeting,deadline,posting',
'start_time' => 'required|date',
'end_time' => 'nullable|date',
'location' => 'nullable|string|max:255',
'is_priority' => 'boolean',
'status' => 'required|in:pending,in_progress,completed,cancelled',
'color' => 'nullable|string|max:20',
'notes' => 'nullable|string',
]);
$validated['is_priority'] = $request->boolean('is_priority');
$event->update($validated);
return redirect()->route('schedule.index')
->with('success', '🐾 Event updated!');
}
public function updateDates(Request $request, Event $event): JsonResponse
{
$validated = $request->validate([
'start_time' => 'required|date',
'end_time' => 'nullable|date',
]);
$event->update($validated);
return response()->json(['ok' => true]);
}
public function destroy(Event $event): RedirectResponse
{
$event->delete();
return redirect()->route('schedule.index')
->with('success', '🐾 Event removed.');
}
public function apiList(): JsonResponse
{
$events = Event::with('client')->get()->map(fn (Event $e) => [
'id' => $e->id,
'title' => ($e->is_priority ? '⭐ ' : '') . $e->title,
'start' => $e->start_time->toIso8601String(),
'end' => $e->end_time?->toIso8601String(),
'backgroundColor' => $e->color,
'borderColor' => $e->color,
'allDay' => $e->is_all_day,
'extendedProps' => [
'status' => $e->status->value,
'client' => $e->client?->name,
'type' => $e->event_type,
'priority' => $e->is_priority,
],
]);
return response()->json($events);
}
}