initial commit
This commit is contained in:
30
app/Enums/ClientStatus.php
Normal file
30
app/Enums/ClientStatus.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ClientStatus: string
|
||||
{
|
||||
case Active = 'active';
|
||||
case Inactive = 'inactive';
|
||||
case Prospect = 'prospect';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Active => 'Active',
|
||||
self::Inactive => 'Inactive',
|
||||
self::Prospect => 'Prospect',
|
||||
};
|
||||
}
|
||||
|
||||
public function badgeClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Active => 'badge-success',
|
||||
self::Inactive => 'badge-error',
|
||||
self::Prospect => 'badge-warning',
|
||||
};
|
||||
}
|
||||
}
|
||||
63
app/Enums/ContentStatus.php
Normal file
63
app/Enums/ContentStatus.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ContentStatus: string
|
||||
{
|
||||
case Drafting = 'drafting';
|
||||
case Filming = 'filming';
|
||||
case Editing = 'editing';
|
||||
case Review = 'review';
|
||||
case Posted = 'posted';
|
||||
case Archived = 'archived';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Drafting => 'Drafting',
|
||||
self::Filming => 'Filming',
|
||||
self::Editing => 'Editing',
|
||||
self::Review => 'Review',
|
||||
self::Posted => 'Posted',
|
||||
self::Archived => 'Archived',
|
||||
};
|
||||
}
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Drafting => '✏️',
|
||||
self::Filming => '🎬',
|
||||
self::Editing => '✂️',
|
||||
self::Review => '👁️',
|
||||
self::Posted => '✅',
|
||||
self::Archived => '📦',
|
||||
};
|
||||
}
|
||||
|
||||
public function colorClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Drafting => 'bg-base-200',
|
||||
self::Filming => 'bg-warning/20',
|
||||
self::Editing => 'bg-info/20',
|
||||
self::Review => 'bg-secondary/20',
|
||||
self::Posted => 'bg-success/20',
|
||||
self::Archived => 'bg-neutral/20',
|
||||
};
|
||||
}
|
||||
|
||||
public function badgeClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Drafting => 'badge-ghost',
|
||||
self::Filming => 'badge-warning',
|
||||
self::Editing => 'badge-info',
|
||||
self::Review => 'badge-secondary',
|
||||
self::Posted => 'badge-success',
|
||||
self::Archived => 'badge-neutral',
|
||||
};
|
||||
}
|
||||
}
|
||||
33
app/Enums/EventStatus.php
Normal file
33
app/Enums/EventStatus.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum EventStatus: string
|
||||
{
|
||||
case Pending = 'pending';
|
||||
case InProgress = 'in_progress';
|
||||
case Completed = 'completed';
|
||||
case Cancelled = 'cancelled';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Pending => 'Pending',
|
||||
self::InProgress => 'In Progress',
|
||||
self::Completed => 'Completed',
|
||||
self::Cancelled => 'Cancelled',
|
||||
};
|
||||
}
|
||||
|
||||
public function badgeClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Pending => 'badge-warning',
|
||||
self::InProgress => 'badge-info',
|
||||
self::Completed => 'badge-success',
|
||||
self::Cancelled => 'badge-error',
|
||||
};
|
||||
}
|
||||
}
|
||||
36
app/Enums/InvoiceStatus.php
Normal file
36
app/Enums/InvoiceStatus.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum InvoiceStatus: string
|
||||
{
|
||||
case Draft = 'draft';
|
||||
case Sent = 'sent';
|
||||
case Paid = 'paid';
|
||||
case Overdue = 'overdue';
|
||||
case Cancelled = 'cancelled';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Draft => 'Draft',
|
||||
self::Sent => 'Sent',
|
||||
self::Paid => 'Paid',
|
||||
self::Overdue => 'Overdue',
|
||||
self::Cancelled => 'Cancelled',
|
||||
};
|
||||
}
|
||||
|
||||
public function badgeClass(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::Draft => 'badge-ghost',
|
||||
self::Sent => 'badge-info',
|
||||
self::Paid => 'badge-success',
|
||||
self::Overdue => 'badge-error',
|
||||
self::Cancelled => 'badge-neutral',
|
||||
};
|
||||
}
|
||||
}
|
||||
105
app/Http/Controllers/ClientController.php
Normal file
105
app/Http/Controllers/ClientController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ClientStatus;
|
||||
use App\Models\Client;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$clients = Client::withCount(['invoices', 'events', 'contentBriefs'])
|
||||
->latest()
|
||||
->paginate(12);
|
||||
|
||||
return view('clients.index', compact('clients'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$statuses = ClientStatus::cases();
|
||||
return view('clients.create', compact('statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'nullable|email|unique:clients,email',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'company' => 'nullable|string|max:255',
|
||||
'ig_handle' => 'nullable|string|max:100',
|
||||
'tiktok_handle' => 'nullable|string|max:100',
|
||||
'youtube_handle' => 'nullable|string|max:100',
|
||||
'address_line1' => 'nullable|string|max:255',
|
||||
'address_line2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'state' => 'nullable|string|max:100',
|
||||
'postal_code' => 'nullable|string|max:20',
|
||||
'country' => 'nullable|string|max:100',
|
||||
'status' => 'required|in:active,inactive,prospect',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
Client::create($validated);
|
||||
|
||||
return redirect()->route('clients.index')
|
||||
->with('success', '🐱 Client added successfully!');
|
||||
}
|
||||
|
||||
public function show(Client $client): View
|
||||
{
|
||||
$client->load(['events' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['invoices' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['contentBriefs' => fn ($q) => $q->latest()->limit(5)]);
|
||||
$client->load(['mediaFiles' => fn ($q) => $q->latest()->limit(10)]);
|
||||
|
||||
return view('clients.show', compact('client'));
|
||||
}
|
||||
|
||||
public function edit(Client $client): View
|
||||
{
|
||||
$statuses = ClientStatus::cases();
|
||||
return view('clients.edit', compact('client', 'statuses'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Client $client): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'nullable|email|unique:clients,email,' . $client->id,
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'company' => 'nullable|string|max:255',
|
||||
'ig_handle' => 'nullable|string|max:100',
|
||||
'tiktok_handle' => 'nullable|string|max:100',
|
||||
'youtube_handle' => 'nullable|string|max:100',
|
||||
'address_line1' => 'nullable|string|max:255',
|
||||
'address_line2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'state' => 'nullable|string|max:100',
|
||||
'postal_code' => 'nullable|string|max:20',
|
||||
'country' => 'nullable|string|max:100',
|
||||
'status' => 'required|in:active,inactive,prospect',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$client->update($validated);
|
||||
|
||||
return redirect()->route('clients.show', $client)
|
||||
->with('success', '🐱 Client updated successfully!');
|
||||
}
|
||||
|
||||
public function destroy(Client $client): RedirectResponse
|
||||
{
|
||||
$client->delete();
|
||||
|
||||
return redirect()->route('clients.index')
|
||||
->with('success', '🐱 Client removed.');
|
||||
}
|
||||
}
|
||||
121
app/Http/Controllers/ContentBriefController.php
Normal file
121
app/Http/Controllers/ContentBriefController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\ContentStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\ContentBrief;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ContentBriefController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
|
||||
$columns = collect(ContentStatus::cases())->map(fn (ContentStatus $status) => [
|
||||
'status' => $status,
|
||||
'items' => ContentBrief::with('client')
|
||||
->where('status', $status->value)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('target_date')
|
||||
->get(),
|
||||
]);
|
||||
|
||||
return view('content.index', compact('columns', 'clients'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = ContentStatus::cases();
|
||||
return view('content.create', compact('clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'content_type' => 'required|string|max:50',
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'hook' => 'nullable|string',
|
||||
'body' => 'nullable|string',
|
||||
'cta' => 'nullable|string',
|
||||
'script' => 'nullable|string',
|
||||
'caption' => 'nullable|string',
|
||||
'hashtags' => 'nullable|string',
|
||||
'target_date' => 'nullable|date',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
ContentBrief::create($validated);
|
||||
|
||||
return redirect()->route('content.index')
|
||||
->with('success', '🎬 Content brief created!');
|
||||
}
|
||||
|
||||
public function show(ContentBrief $contentBrief): View
|
||||
{
|
||||
$contentBrief->load('client');
|
||||
return view('content.show', ['brief' => $contentBrief]);
|
||||
}
|
||||
|
||||
public function edit(ContentBrief $contentBrief): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = ContentStatus::cases();
|
||||
$contentBrief->load('client');
|
||||
return view('content.edit', ['brief' => $contentBrief, 'clients' => $clients, 'statuses' => $statuses]);
|
||||
}
|
||||
|
||||
public function update(Request $request, ContentBrief $contentBrief): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'content_type' => 'required|string|max:50',
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'hook' => 'nullable|string',
|
||||
'body' => 'nullable|string',
|
||||
'cta' => 'nullable|string',
|
||||
'script' => 'nullable|string',
|
||||
'caption' => 'nullable|string',
|
||||
'hashtags' => 'nullable|string',
|
||||
'target_date' => 'nullable|date',
|
||||
'posted_date' => 'nullable|date',
|
||||
'posted_url' => 'nullable|url',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$contentBrief->update($validated);
|
||||
|
||||
return redirect()->route('content.show', $contentBrief)
|
||||
->with('success', '🎬 Content brief updated!');
|
||||
}
|
||||
|
||||
public function destroy(ContentBrief $contentBrief): RedirectResponse
|
||||
{
|
||||
$contentBrief->delete();
|
||||
return redirect()->route('content.index')->with('success', 'Content brief removed.');
|
||||
}
|
||||
|
||||
public function updateStatus(Request $request, ContentBrief $contentBrief): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|in:drafting,filming,editing,review,posted,archived',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$contentBrief->update($validated);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
8
app/Http/Controllers/Controller.php
Normal file
8
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
25
app/Http/Controllers/DashboardController.php
Normal file
25
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\DashboardService;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DashboardService $dashboardService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
return view('dashboard', [
|
||||
'stats' => $this->dashboardService->getStats(),
|
||||
'todayActivities' => $this->dashboardService->getTodayActivities(),
|
||||
'latestInvoices' => $this->dashboardService->getLatestInvoices(),
|
||||
'socialStats' => $this->dashboardService->getSocialStats(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
129
app/Http/Controllers/EventController.php
Normal file
129
app/Http/Controllers/EventController.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$events = Event::with('client')->orderBy('start_time')->get();
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
|
||||
// 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'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,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 update(Request $request, Event $event): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'client_id' => 'nullable|exists:clients,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);
|
||||
}
|
||||
}
|
||||
119
app/Http/Controllers/InvoiceController.php
Normal file
119
app/Http/Controllers/InvoiceController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\InvoiceService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InvoiceService $invoiceService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
$invoices = Invoice::with('client')->latest()->paginate(15);
|
||||
return view('invoices.index', compact('invoices'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
return view('invoices.create', compact('clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'tax_rate' => 'required|numeric|min:0|max:100',
|
||||
'currency' => 'required|string|max:10',
|
||||
'issue_date' => 'required|date',
|
||||
'due_date' => 'required|date|after_or_equal:issue_date',
|
||||
'notes' => 'nullable|string',
|
||||
'bank_name' => 'nullable|string|max:100',
|
||||
'bank_account' => 'nullable|string|max:50',
|
||||
'bank_holder' => 'nullable|string|max:100',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.description' => 'required|string',
|
||||
'items.*.quantity' => 'required|integer|min:1',
|
||||
'items.*.unit_price' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$items = $validated['items'];
|
||||
unset($validated['items']);
|
||||
$validated['status'] = InvoiceStatus::Draft->value;
|
||||
|
||||
$invoice = $this->invoiceService->create($validated, $items);
|
||||
|
||||
return redirect()->route('invoices.show', $invoice)
|
||||
->with('success', '🧾 Invoice created!');
|
||||
}
|
||||
|
||||
public function show(Invoice $invoice): View
|
||||
{
|
||||
$invoice->load('client', 'items');
|
||||
return view('invoices.show', compact('invoice'));
|
||||
}
|
||||
|
||||
public function edit(Invoice $invoice): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
$invoice->load('client', 'items');
|
||||
return view('invoices.edit', compact('invoice', 'clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Invoice $invoice): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
'title' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'tax_rate' => 'required|numeric|min:0|max:100',
|
||||
'status' => 'required|in:draft,sent,paid,overdue,cancelled',
|
||||
'issue_date' => 'required|date',
|
||||
'due_date' => 'required|date',
|
||||
'paid_date' => 'nullable|date',
|
||||
'notes' => 'nullable|string',
|
||||
'bank_name' => 'nullable|string|max:100',
|
||||
'bank_account' => 'nullable|string|max:50',
|
||||
'bank_holder' => 'nullable|string|max:100',
|
||||
'items' => 'required|array|min:1',
|
||||
'items.*.description' => 'required|string',
|
||||
'items.*.quantity' => 'required|integer|min:1',
|
||||
'items.*.unit_price' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$items = $validated['items'];
|
||||
unset($validated['items']);
|
||||
|
||||
$this->invoiceService->update($invoice, $validated, $items);
|
||||
|
||||
return redirect()->route('invoices.show', $invoice)
|
||||
->with('success', '🧾 Invoice updated!');
|
||||
}
|
||||
|
||||
public function destroy(Invoice $invoice): RedirectResponse
|
||||
{
|
||||
$invoice->delete();
|
||||
return redirect()->route('invoices.index')->with('success', 'Invoice deleted.');
|
||||
}
|
||||
|
||||
public function pdf(Invoice $invoice): Response
|
||||
{
|
||||
return $this->invoiceService->generatePdf($invoice);
|
||||
}
|
||||
}
|
||||
77
app/Http/Controllers/MediaFileController.php
Normal file
77
app/Http/Controllers/MediaFileController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\MediaFile;
|
||||
use App\Services\FileService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class MediaFileController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly FileService $fileService
|
||||
) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$folder = $request->get('folder', 'all');
|
||||
$client = $request->get('client_id');
|
||||
$clients = Client::orderBy('name')->get();
|
||||
|
||||
$query = MediaFile::with('client')->latest();
|
||||
|
||||
if ($folder !== 'all') {
|
||||
$query->where('folder', $folder);
|
||||
}
|
||||
|
||||
if ($client) {
|
||||
$query->where('client_id', $client);
|
||||
}
|
||||
|
||||
$files = $query->paginate(20)->withQueryString();
|
||||
$folders = MediaFile::select('folder')->distinct()->pluck('folder');
|
||||
|
||||
return view('files.index', compact('files', 'folders', 'folder', 'clients'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'file' => 'required|file|max:51200', // 50 MB
|
||||
'folder' => 'required|string|max:100',
|
||||
'client_id' => 'nullable|exists:clients,id',
|
||||
]);
|
||||
|
||||
$this->fileService->uploadAsset(
|
||||
$request->file('file'),
|
||||
$request->input('folder'),
|
||||
$request->input('client_id')
|
||||
);
|
||||
|
||||
return back()->with('success', '📁 File uploaded successfully!');
|
||||
}
|
||||
|
||||
public function serve(MediaFile $mediaFile): StreamedResponse
|
||||
{
|
||||
abort_unless(Storage::disk($mediaFile->disk)->exists($mediaFile->path), 404);
|
||||
|
||||
return Storage::disk($mediaFile->disk)->response(
|
||||
$mediaFile->path,
|
||||
$mediaFile->original_name,
|
||||
['Content-Type' => $mediaFile->mime_type]
|
||||
);
|
||||
}
|
||||
|
||||
public function destroy(MediaFile $mediaFile): RedirectResponse
|
||||
{
|
||||
$this->fileService->delete($mediaFile);
|
||||
return back()->with('success', 'File deleted.');
|
||||
}
|
||||
}
|
||||
93
app/Http/Controllers/RateCardController.php
Normal file
93
app/Http/Controllers/RateCardController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\RateCard;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RateCardController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get();
|
||||
return view('rate-cards.index', compact('rateCards'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('rate-cards.create');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = true;
|
||||
|
||||
RateCard::create($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card entry added!');
|
||||
}
|
||||
|
||||
public function edit(RateCard $rateCard): View
|
||||
{
|
||||
return view('rate-cards.edit', compact('rateCard'));
|
||||
}
|
||||
|
||||
public function update(Request $request, RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = $request->boolean('is_active');
|
||||
|
||||
$rateCard->update($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card updated!');
|
||||
}
|
||||
|
||||
public function destroy(RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$rateCard->delete();
|
||||
return redirect()->route('rate-cards.index')->with('success', 'Entry removed.');
|
||||
}
|
||||
|
||||
public function public(): View
|
||||
{
|
||||
$rateCards = RateCard::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('platform')
|
||||
->get()
|
||||
->groupBy('platform');
|
||||
|
||||
return view('rate-cards.public', compact('rateCards'));
|
||||
}
|
||||
}
|
||||
61
app/Http/Controllers/SocialHubController.php
Normal file
61
app/Http/Controllers/SocialHubController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ContentBrief;
|
||||
use App\Models\SocialStat;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SocialHubController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
// Get latest stats per platform
|
||||
$stats = collect(['instagram', 'tiktok', 'youtube'])->map(fn (string $platform) => [
|
||||
'platform' => $platform,
|
||||
'latest' => SocialStat::where('platform', $platform)
|
||||
->orderByDesc('recorded_date')
|
||||
->first(),
|
||||
'history' => SocialStat::where('platform', $platform)
|
||||
->orderByDesc('recorded_date')
|
||||
->limit(7)
|
||||
->get(),
|
||||
]);
|
||||
|
||||
// Posting frequency - count by platform per month
|
||||
$postingFrequency = ContentBrief::where('status', 'posted')
|
||||
->selectRaw("platform, strftime('%Y-%m', posted_date) as month, count(*) as count")
|
||||
->whereNotNull('posted_date')
|
||||
->groupBy('platform', 'month')
|
||||
->orderBy('month')
|
||||
->limit(30)
|
||||
->get();
|
||||
|
||||
return view('social-hub.index', compact('stats', 'postingFrequency'));
|
||||
}
|
||||
|
||||
public function storeStats(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'platform' => 'required|in:instagram,tiktok,youtube',
|
||||
'handle' => 'nullable|string|max:100',
|
||||
'followers' => 'required|integer|min:0',
|
||||
'following' => 'nullable|integer|min:0',
|
||||
'posts_count' => 'nullable|integer|min:0',
|
||||
'engagement_rate' => 'nullable|numeric|min:0|max:100',
|
||||
'avg_views' => 'nullable|integer|min:0',
|
||||
'avg_likes' => 'nullable|integer|min:0',
|
||||
'avg_comments' => 'nullable|integer|min:0',
|
||||
]);
|
||||
|
||||
$validated['recorded_date'] = today()->toDateString();
|
||||
|
||||
SocialStat::create($validated);
|
||||
|
||||
return back()->with('success', '📊 Stats updated!');
|
||||
}
|
||||
}
|
||||
67
app/Models/Client.php
Normal file
67
app/Models/Client.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ClientStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'phone', 'company',
|
||||
'ig_handle', 'tiktok_handle', 'youtube_handle',
|
||||
'address_line1', 'address_line2', 'city', 'state', 'postal_code', 'country',
|
||||
'status', 'notes', 'avatar',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ClientStatus::class,
|
||||
];
|
||||
|
||||
public function events(): HasMany
|
||||
{
|
||||
return $this->hasMany(Event::class);
|
||||
}
|
||||
|
||||
public function invoices(): HasMany
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function contentBriefs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContentBrief::class);
|
||||
}
|
||||
|
||||
public function mediaFiles(): HasMany
|
||||
{
|
||||
return $this->hasMany(MediaFile::class);
|
||||
}
|
||||
|
||||
public function getFullAddressAttribute(): string
|
||||
{
|
||||
return collect([
|
||||
$this->address_line1,
|
||||
$this->address_line2,
|
||||
$this->city,
|
||||
$this->state,
|
||||
$this->postal_code,
|
||||
$this->country,
|
||||
])->filter()->implode(', ');
|
||||
}
|
||||
|
||||
public function getInitialsAttribute(): string
|
||||
{
|
||||
$words = explode(' ', $this->name);
|
||||
return strtoupper(
|
||||
collect($words)->take(2)->map(fn ($w) => $w[0] ?? '')->implode('')
|
||||
);
|
||||
}
|
||||
}
|
||||
43
app/Models/ContentBrief.php
Normal file
43
app/Models/ContentBrief.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ContentStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ContentBrief extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'title', 'platform', 'content_type', 'status',
|
||||
'hook', 'body', 'cta', 'script', 'caption', 'hashtags',
|
||||
'target_date', 'posted_date', 'posted_url', 'sort_order', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ContentStatus::class,
|
||||
'target_date' => 'date',
|
||||
'posted_date' => 'date',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '📱',
|
||||
};
|
||||
}
|
||||
}
|
||||
48
app/Models/Event.php
Normal file
48
app/Models/Event.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'title', 'description', 'event_type',
|
||||
'start_time', 'end_time', 'location', 'is_priority',
|
||||
'is_all_day', 'status', 'color', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_time' => 'datetime',
|
||||
'end_time' => 'datetime',
|
||||
'is_priority' => 'boolean',
|
||||
'is_all_day' => 'boolean',
|
||||
'status' => EventStatus::class,
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function scopeUpcoming($query, int $hours = 24)
|
||||
{
|
||||
return $query->where('start_time', '>=', now())
|
||||
->where('start_time', '<=', now()->addHours($hours))
|
||||
->where('status', '!=', EventStatus::Completed->value)
|
||||
->where('status', '!=', EventStatus::Cancelled->value);
|
||||
}
|
||||
|
||||
public function scopeToday($query)
|
||||
{
|
||||
return $query->whereDate('start_time', today());
|
||||
}
|
||||
}
|
||||
65
app/Models/Invoice.php
Normal file
65
app/Models/Invoice.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Invoice extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'invoice_number', 'title', 'description',
|
||||
'subtotal', 'tax_rate', 'tax_amount', 'total', 'currency',
|
||||
'status', 'issue_date', 'due_date', 'paid_date', 'notes',
|
||||
'bank_name', 'bank_account', 'bank_holder',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => InvoiceStatus::class,
|
||||
'issue_date' => 'date',
|
||||
'due_date' => 'date',
|
||||
'paid_date' => 'date',
|
||||
'subtotal' => 'decimal:2',
|
||||
'tax_rate' => 'decimal:2',
|
||||
'tax_amount' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
|
||||
public function recalculate(): void
|
||||
{
|
||||
$this->subtotal = $this->items->sum('total');
|
||||
$this->tax_amount = round($this->subtotal * ($this->tax_rate / 100), 2);
|
||||
$this->total = $this->subtotal + $this->tax_amount;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getFormattedTotalAttribute(): string
|
||||
{
|
||||
return 'Rp ' . number_format((float) $this->total, 0, ',', '.');
|
||||
}
|
||||
|
||||
public static function generateNumber(): string
|
||||
{
|
||||
$prefix = 'INV-' . now()->format('Ym');
|
||||
$last = static::where('invoice_number', 'like', $prefix . '%')->count();
|
||||
return $prefix . '-' . str_pad((string) ($last + 1), 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
23
app/Models/InvoiceItem.php
Normal file
23
app/Models/InvoiceItem.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class InvoiceItem extends Model
|
||||
{
|
||||
protected $fillable = ['invoice_id', 'description', 'quantity', 'unit_price', 'total'];
|
||||
|
||||
protected $casts = [
|
||||
'unit_price' => 'decimal:2',
|
||||
'total' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function invoice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
}
|
||||
51
app/Models/MediaFile.php
Normal file
51
app/Models/MediaFile.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaFile extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'name', 'original_name', 'path', 'disk', 'mime_type', 'size', 'folder', 'description',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function getUrlAttribute(): string
|
||||
{
|
||||
return route('files.serve', $this->id);
|
||||
}
|
||||
|
||||
public function getHumanSizeAttribute(): string
|
||||
{
|
||||
$bytes = $this->size;
|
||||
if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ' GB';
|
||||
if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
|
||||
if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
|
||||
return $bytes . ' B';
|
||||
}
|
||||
|
||||
public function getIsImageAttribute(): bool
|
||||
{
|
||||
return str_starts_with($this->mime_type, 'image/');
|
||||
}
|
||||
|
||||
public function getIconAttribute(): string
|
||||
{
|
||||
if ($this->is_image) return '🖼️';
|
||||
if (str_starts_with($this->mime_type, 'video/')) return '🎬';
|
||||
if (str_contains($this->mime_type, 'pdf')) return '📄';
|
||||
return '📁';
|
||||
}
|
||||
}
|
||||
36
app/Models/RateCard.php
Normal file
36
app/Models/RateCard.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RateCard extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'service_name', 'description', 'platform', 'content_type',
|
||||
'price', 'currency', 'price_unit', 'is_negotiable', 'is_active', 'sort_order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'is_negotiable' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return 'Rp ' . number_format((float) $this->price, 0, ',', '.');
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '⭐',
|
||||
};
|
||||
}
|
||||
}
|
||||
40
app/Models/SocialStat.php
Normal file
40
app/Models/SocialStat.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SocialStat extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'platform', 'handle', 'followers', 'following', 'posts_count',
|
||||
'engagement_rate', 'avg_views', 'avg_likes', 'avg_comments',
|
||||
'recorded_date', 'raw_data',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'recorded_date' => 'date',
|
||||
'raw_data' => 'array',
|
||||
'engagement_rate' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function getFormattedFollowersAttribute(): string
|
||||
{
|
||||
$n = $this->followers;
|
||||
if ($n >= 1_000_000) return round($n / 1_000_000, 1) . 'M';
|
||||
if ($n >= 1_000) return round($n / 1_000, 1) . 'K';
|
||||
return (string) $n;
|
||||
}
|
||||
|
||||
public function getPlatformIconAttribute(): string
|
||||
{
|
||||
return match($this->platform) {
|
||||
'instagram' => '📸',
|
||||
'tiktok' => '🎵',
|
||||
'youtube' => '▶️',
|
||||
default => '📱',
|
||||
};
|
||||
}
|
||||
}
|
||||
32
app/Models/User.php
Normal file
32
app/Models/User.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Providers/AppServiceProvider.php
Normal file
27
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void {}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
// Inject alert badge count into all views
|
||||
View::composer('*', function (\Illuminate\View\View $view): void {
|
||||
try {
|
||||
$alertCount = Event::upcoming(24)->count();
|
||||
} catch (\Throwable) {
|
||||
$alertCount = 0;
|
||||
}
|
||||
$view->with('alertCount', $alertCount);
|
||||
});
|
||||
}
|
||||
}
|
||||
137
app/Services/DashboardService.php
Normal file
137
app/Services/DashboardService.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\ContentBrief;
|
||||
use App\Models\Event;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\SocialStat;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
final class DashboardService
|
||||
{
|
||||
public function getStats(): array
|
||||
{
|
||||
return [
|
||||
'total_clients' => Client::count(),
|
||||
'active_clients' => Client::where('status', 'active')->count(),
|
||||
'upcoming_events' => Event::upcoming(24 * 90)->count(), // 3 months
|
||||
'pending_invoices' => Invoice::where('status', 'sent')->count(),
|
||||
'total_revenue' => Invoice::where('status', 'paid')->sum('total'),
|
||||
'content_in_progress' => ContentBrief::whereNotIn('status', ['posted', 'archived'])->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Combined today's activities: events (today or ongoing), invoices due, content targets.
|
||||
*/
|
||||
public function getTodayActivities(): Collection
|
||||
{
|
||||
$activities = collect();
|
||||
|
||||
// Events starting today OR currently ongoing (started before today, ends today or later)
|
||||
$events = Event::with('client')
|
||||
->where(function ($q) {
|
||||
$q->whereDate('start_time', today())
|
||||
->orWhere(function ($q2) {
|
||||
$q2->whereDate('start_time', '<', today())
|
||||
->where(function ($q3) {
|
||||
$q3->whereDate('end_time', '>=', today())
|
||||
->orWhereNull('end_time');
|
||||
})
|
||||
->whereNotIn('status', ['completed', 'cancelled']);
|
||||
});
|
||||
})
|
||||
->orderBy('start_time')
|
||||
->limit(15)
|
||||
->get();
|
||||
|
||||
foreach ($events as $e) {
|
||||
$timeLabel = $e->is_all_day
|
||||
? 'All day'
|
||||
: ($e->start_time->format('H:i') . ($e->end_time ? ' – ' . $e->end_time->format('H:i') : ''));
|
||||
|
||||
$activities->push([
|
||||
'type' => 'event',
|
||||
'icon' => '📅',
|
||||
'title' => $e->title,
|
||||
'subtitle' => $timeLabel . ($e->client ? ' · ' . $e->client->name : ''),
|
||||
'label' => $e->event_type,
|
||||
'badge' => $e->status->label(),
|
||||
'badge_class' => $e->status->badgeClass(),
|
||||
'color' => $e->color ?? '#FFB7C5',
|
||||
'priority' => $e->is_priority,
|
||||
'sort_key' => $e->start_time->timestamp,
|
||||
]);
|
||||
}
|
||||
|
||||
// Invoices due today (not yet paid or cancelled)
|
||||
$invoices = Invoice::with('client')
|
||||
->whereDate('due_date', today())
|
||||
->whereNotIn('status', ['paid', 'cancelled'])
|
||||
->get();
|
||||
|
||||
foreach ($invoices as $inv) {
|
||||
$activities->push([
|
||||
'type' => 'invoice',
|
||||
'icon' => '🧾',
|
||||
'title' => $inv->title ?? $inv->invoice_number,
|
||||
'subtitle' => ($inv->client?->name ?? 'No client') . ' · ' . ($inv->formatted_total ?? ''),
|
||||
'label' => 'Invoice Due',
|
||||
'badge' => $inv->status->label(),
|
||||
'badge_class' => $inv->status->badgeClass(),
|
||||
'color' => '#FDFD96',
|
||||
'priority' => false,
|
||||
'sort_key' => today()->setTime(23, 59, 0)->timestamp,
|
||||
]);
|
||||
}
|
||||
|
||||
// Content briefs with target date today (not posted/archived)
|
||||
$content = ContentBrief::with('client')
|
||||
->whereDate('target_date', today())
|
||||
->whereNotIn('status', ['posted', 'archived'])
|
||||
->get();
|
||||
|
||||
foreach ($content as $c) {
|
||||
$activities->push([
|
||||
'type' => 'content',
|
||||
'icon' => $c->platform_icon,
|
||||
'title' => $c->title,
|
||||
'subtitle' => ucfirst($c->platform) . ($c->client ? ' · ' . $c->client->name : ''),
|
||||
'label' => 'Content Target',
|
||||
'badge' => $c->status->label(),
|
||||
'badge_class' => 'badge-ghost',
|
||||
'color' => '#E8D5F5',
|
||||
'priority' => false,
|
||||
'sort_key' => today()->setTime(12, 0, 0)->timestamp,
|
||||
]);
|
||||
}
|
||||
|
||||
return $activities->sortBy('sort_key')->values();
|
||||
}
|
||||
|
||||
public function getAlertCount(): int
|
||||
{
|
||||
return Event::upcoming(24)->count();
|
||||
}
|
||||
|
||||
public function getLatestInvoices(): Collection
|
||||
{
|
||||
return Invoice::with('client')
|
||||
->latest()
|
||||
->limit(5)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getSocialStats(): Collection
|
||||
{
|
||||
return SocialStat::whereIn('id', function ($query): void {
|
||||
$query->selectRaw('MAX(id)')
|
||||
->from('social_stats')
|
||||
->groupBy('platform');
|
||||
})->get();
|
||||
}
|
||||
}
|
||||
44
app/Services/FileService.php
Normal file
44
app/Services/FileService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\MediaFile;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final class FileService
|
||||
{
|
||||
public function uploadAsset(UploadedFile $file, string $folder, ?int $clientId = null): MediaFile
|
||||
{
|
||||
// Sanitise folder name — allow alphanumeric, dash, underscore only
|
||||
$folder = preg_replace('/[^a-zA-Z0-9\-_]/', '-', trim($folder)) ?: 'general';
|
||||
|
||||
$name = Str::uuid() . '.' . $file->getClientOriginalExtension();
|
||||
$directory = "talent-assets/{$folder}";
|
||||
|
||||
// Ensure the directory exists on the local disk
|
||||
Storage::disk('local')->makeDirectory($directory);
|
||||
|
||||
$path = $file->storeAs($directory, $name, 'local');
|
||||
|
||||
return MediaFile::create([
|
||||
'client_id' => $clientId,
|
||||
'name' => pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'path' => $path,
|
||||
'disk' => 'local',
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'size' => $file->getSize(),
|
||||
'folder' => $folder,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(MediaFile $file): void
|
||||
{
|
||||
Storage::disk($file->disk)->delete($file->path);
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
58
app/Services/InvoiceService.php
Normal file
58
app/Services/InvoiceService.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
final class InvoiceService
|
||||
{
|
||||
public function create(array $data, array $items): Invoice
|
||||
{
|
||||
$invoice = Invoice::create([
|
||||
...$data,
|
||||
'invoice_number' => Invoice::generateNumber(),
|
||||
'subtotal' => 0,
|
||||
'tax_amount' => 0,
|
||||
'total' => 0,
|
||||
]);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item['total'] = $item['quantity'] * $item['unit_price'];
|
||||
$invoice->items()->create($item);
|
||||
}
|
||||
|
||||
$invoice->recalculate();
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
public function update(Invoice $invoice, array $data, array $items): Invoice
|
||||
{
|
||||
$invoice->update($data);
|
||||
$invoice->items()->delete();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item['total'] = $item['quantity'] * $item['unit_price'];
|
||||
$invoice->items()->create($item);
|
||||
}
|
||||
|
||||
$invoice->recalculate();
|
||||
|
||||
return $invoice->fresh();
|
||||
}
|
||||
|
||||
public function generatePdf(Invoice $invoice): Response
|
||||
{
|
||||
$invoice->load('client', 'items');
|
||||
|
||||
$pdf = Pdf::loadView('invoices.pdf', compact('invoice'));
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
|
||||
return $pdf->download("invoice-{$invoice->invoice_number}.pdf");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user