🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:AdminController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Project; use App\Models\Domain; use App\Models\Requirement; use App\Models\Expense; use App\Models\Lead; use App\Models\User; use App\Models\Attendance; use App\Models\ProjectTask; use App\Models\Quotation; use App\Models\QuotationItem; use App\Models\Agreement; use App\Models\Payment; use Carbon\Carbon; class AdminController extends Controller { public function dashboard() { $stats = [ 'total_projects' => Project::count(), 'active_projects' => Project::where('status', 'in_progress')->count(), 'pending_projects' => Project::where('status', 'pending')->count(), 'total_revenue' => Project::sum('budget'), 'total_expenses' => Expense::sum('amount'), 'total_leads' => Lead::count(), 'contacted_leads' => Lead::where('status', 'contacted')->count(), 'total_domains' => Domain::count(), 'expiring_domains' => Domain::where('renewal_date', '<=', Carbon::now()->addDays(30))->count(), ]; $recentProjects = Project::with(['client', 'techLead'])->latest()->take(5)->get(); $recentLeads = Lead::with('salesPerson')->latest()->take(5)->get(); $pendingRequirements = Requirement::where('status', 'pending')->count(); return view('admin.dashboard', compact('stats', 'recentProjects', 'recentLeads', 'pendingRequirements')); } public function projects() { $projects = Project::with(['client', 'techLead', 'domains'])->get(); $clients = $this->getClientUsers(); $techLeads = User::role('Tech Lead')->get(); if ($techLeads->isEmpty()) $techLeads = User::all(); return view('admin.projects', compact('projects', 'clients', 'techLeads')); } public function storeProject(Request $request) { $request->validate([ 'name' => 'required|string|max:255', 'client_id' => 'required|exists:users,id', 'tech_lead_id' => 'nullable|exists:users,id', 'budget' => 'nullable|numeric', 'domain_name' => 'required|string|max:255', 'renewal_date' => 'required|date', ]); $project = Project::create([ 'name' => $request->name, 'client_id' => $request->client_id, 'tech_lead_id' => $request->tech_lead_id, 'budget' => $request->budget, 'status' => 'pending' ]); Domain::create([ 'project_id' => $project->id, 'client_id' => $request->client_id, 'domain_name' => $request->domain_name, 'renewal_date' => $request->renewal_date, ]); if ($request->tech_lead_id) { $techLead = User::find($request->tech_lead_id); if ($techLead) { \Illuminate\Support\Facades\Mail::to($techLead->email)->queue( new \App\Mail\SystemNotification( 'New Project Assigned: ' . $project->name, 'You have been assigned as the Tech Lead for the new project "' . $project->name . '".', 'View Dashboard', route('techlead.dashboard') ) ); } } return redirect()->back()->with('success', 'Project and Domain created successfully.'); } public function assignTechLead(Request $request, Project $project) { $request->validate([ 'tech_lead_id' => 'required|exists:users,id', ]); $project->update([ 'tech_lead_id' => $request->tech_lead_id, ]); return redirect()->back()->with('success', 'Tech Lead assigned to project.'); } // Lead Management public function leads(Request $request) { $query = Lead::with('salesPerson'); if ($request->filled('filter')) { $filter = $request->filter; if ($filter === 'not_contacted') { $query->where('status', 'not_contacted'); } elseif ($filter === 'contacted') { $query->where('status', 'contacted'); } elseif ($filter === 'followed_up') { $query->whereHas('updates'); } elseif ($filter === 'not_followed_up') { $query->whereDoesntHave('updates'); } } $leads = $query->orderByRaw("FIELD(priority, 'urgent', 'high', 'medium', 'low')") ->orderBy('created_at', 'desc') ->get(); return view('admin.leads', compact('leads')); } // Financial Dashboard public function financials(Request $request) { $dateFrom = $request->input('date_from', Carbon::now()->startOfMonth()->format('Y-m-d')); $dateTo = $request->input('date_to', Carbon::now()->endOfMonth()->format('Y-m-d')); $totalRevenue = Project::sum('budget'); $totalExpenses = Expense::sum('amount'); $profit = $totalRevenue - $totalExpenses; // Partner distribution $partner1Share = $profit * 0.40; // Admin - Asanga CEO $partner2Share = $profit * 0.40; // Tech Lead - Sanura $companyReserve = $profit * 0.20; // Company emergency fund $expenses = Expense::orderBy('date', 'desc')->get(); $projectFinancials = Project::with(['client', 'payments']) ->selectRaw('*, budget as revenue') ->orderBy('created_at', 'desc') ->get(); $filteredPayments = Payment::with(['project', 'client']) ->whereBetween('paid_at', [$dateFrom, $dateTo]) ->orderBy('paid_at', 'desc') ->get(); return view('admin.financials', compact( 'totalRevenue', 'totalExpenses', 'profit', 'expenses', 'projectFinancials', 'partner1Share', 'partner2Share', 'companyReserve', 'dateFrom', 'dateTo', 'filteredPayments' )); } public function storeExpense(Request $request) { $request->validate([ 'category' => 'required|string|max:255', 'amount' => 'required|numeric|min:0', 'description' => 'nullable|string', 'date' => 'required|date', ]); Expense::create($request->only(['category', 'amount', 'description', 'date'])); return redirect()->back()->with('success', 'Expense recorded successfully.'); } // Domain Renewal Tracking public function domains() { $filter = request('filter', 'all'); $query = Domain::with(['project', 'client']); if ($filter === 'expiring') { $query->where('renewal_date', '<=', Carbon::now()->addDays(30)) ->where('renewal_date', '>=', Carbon::now()); } elseif ($filter === 'next_month') { $query->whereMonth('renewal_date', Carbon::now()->addMonth()->month) ->whereYear('renewal_date', Carbon::now()->addMonth()->year); } elseif ($filter === 'expired') { $query->where('renewal_date', '<', Carbon::now()); } $domains = $query->orderBy('renewal_date', 'asc')->get(); return view('admin.domains', compact('domains', 'filter')); } // Attendance Overview public function attendance() { $date = request('date', Carbon::today()->format('Y-m-d')); $records = Attendance::with('user') ->where('date', $date) ->orderBy('clock_in', 'asc') ->get(); return view('admin.attendance', compact('records', 'date')); } // Quotation Management public function quotations() { $quotations = Quotation::with(['client', 'project'])->latest()->get(); $clients = $this->getClientUsers(); $projects = Project::get(); return view('admin.quotations', compact('quotations', 'clients', 'projects')); } public function storeQuotation(Request $request) { $request->validate([ 'client_id' => 'required|exists:users,id', 'client_name' => 'required|string|max:255', 'company_name' => 'nullable|string|max:255', 'project_id' => 'nullable|exists:projects,id', 'discount' => 'nullable|numeric|min:0', 'notes' => 'nullable|string', 'terms' => 'nullable|string', 'items' => 'required|array|min:1', 'items.*.description' => 'required|string', 'items.*.quantity' => 'required|integer|min:1', 'items.*.unit_price' => 'required|numeric|min:0', ]); $quotation = Quotation::create([ 'quotation_number' => Quotation::generateNumber(), 'client_id' => $request->client_id, 'client_name' => $request->client_name, 'company_name' => $request->company_name, 'project_id' => $request->project_id, 'discount' => $request->discount ?? 0, 'total_amount' => 0, 'final_amount' => 0, 'notes' => $request->notes, 'terms' => $request->terms, 'status' => 'draft', ]); $totalAmount = 0; foreach ($request->items as $item) { $itemTotal = $item['quantity'] * $item['unit_price']; $totalAmount += $itemTotal; QuotationItem::create([ 'quotation_id' => $quotation->id, 'description' => $item['description'], 'quantity' => $item['quantity'], 'unit_price' => $item['unit_price'], 'total' => $itemTotal, ]); } $finalAmount = $totalAmount - ($request->discount ?? 0); $quotation->update([ 'total_amount' => $totalAmount, 'final_amount' => $finalAmount, ]); return redirect()->route('admin.quotations')->with('success', 'Quotation created successfully.'); } public function showQuotation(Quotation $quotation) { $quotation->load(['client', 'project', 'items']); return view('admin.quotation_show', compact('quotation')); } public function sendQuotation(Quotation $quotation) { $quotation->update([ 'status' => 'sent', 'sent_at' => Carbon::now(), ]); // Notify client if ($quotation->client) { \Illuminate\Support\Facades\Mail::to($quotation->client->email)->queue( new \App\Mail\SystemNotification( 'Quotation Received: ' . $quotation->quotation_number, 'You have received a new quotation from WebSparkIT. Please review the attached details.', 'View Quotation', route('dashboard') ) ); } return redirect()->back()->with('success', 'Quotation sent to client.'); } // Agreement Management public function agreements() { $agreements = Agreement::with(['client', 'project'])->latest()->get(); $clients = $this->getClientUsers(); $projects = Project::get(); return view('admin.agreements', compact('agreements', 'clients', 'projects')); } public function storeAgreement(Request $request) { $request->validate([ 'client_id' => 'required|exists:users,id', 'client_name' => 'required|string|max:255', 'company_name' => 'nullable|string|max:255', 'project_id' => 'nullable|exists:projects,id', 'total_amount' => 'required|numeric|min:0', 'scope_of_work' => 'nullable|string', 'terms_and_conditions' => 'nullable|string', 'payment_terms' => 'nullable|string', ]); $agreement = Agreement::create([ 'agreement_number' => Agreement::generateNumber(), 'client_id' => $request->client_id, 'client_name' => $request->client_name, 'company_name' => $request->company_name, 'project_id' => $request->project_id, 'total_amount' => $request->total_amount, 'scope_of_work' => $request->scope_of_work, 'terms_and_conditions' => $request->terms_and_conditions, 'payment_terms' => $request->payment_terms, 'status' => 'draft', ]); return redirect()->route('admin.agreements')->with('success', 'Agreement created successfully.'); } public function showAgreement(Agreement $agreement) { $agreement->load(['client', 'project']); return view('admin.agreement_show', compact('agreement')); } public function sendAgreement(Agreement $agreement) { $agreement->update(['status' => 'sent']); if ($agreement->client) { \Illuminate\Support\Facades\Mail::to($agreement->client->email)->queue( new \App\Mail\SystemNotification( 'Agreement Received: ' . $agreement->agreement_number, 'You have received a new agreement from WebSparkIT. Please review and sign.', 'View Agreement', route('dashboard') ) ); } return redirect()->back()->with('success', 'Agreement sent to client.'); } // Payment Management public function payments() { $payments = Payment::with(['project', 'client'])->latest()->get(); $projects = Project::get(); return view('admin.payments', compact('payments', 'projects')); } public function storePayment(Request $request) { $request->validate([ 'project_id' => 'required|exists:projects,id', 'amount' => 'required|numeric|min:0', 'payment_method' => 'nullable|string', 'reference_number' => 'nullable|string', 'slip' => 'nullable|file|mimes:jpg,jpeg,png,pdf|max:5120', 'notes' => 'nullable|string', 'paid_at' => 'required|date', ]); $project = Project::find($request->project_id); $slipPath = null; if ($request->hasFile('slip')) { $slipPath = $request->file('slip')->store('payment_slips', 'public'); } $payment = Payment::create([ 'project_id' => $request->project_id, 'client_id' => $project->client_id, 'amount' => $request->amount, 'payment_method' => $request->payment_method, 'reference_number' => $request->reference_number, 'slip_path' => $slipPath, 'notes' => $request->notes, 'paid_at' => $request->paid_at, 'status' => 'pending', ]); return redirect()->back()->with('success', 'Payment recorded successfully.'); } public function confirmPayment(Payment $payment) { $payment->update(['status' => 'confirmed']); // Update project amount_paid $project = $payment->project; $totalPaid = Payment::where('project_id', $project->id) ->where('status', 'confirmed') ->sum('amount'); $paymentStatus = 'unpaid'; if ($totalPaid >= $project->budget) { $paymentStatus = 'paid'; } elseif ($totalPaid > 0) { $paymentStatus = 'partial'; } $project->update([ 'amount_paid' => $totalPaid, 'payment_status' => $paymentStatus, ]); // Notify client if ($payment->client) { \Illuminate\Support\Facades\Mail::to($payment->client->email)->queue( new \App\Mail\SystemNotification( 'Payment Confirmed', 'Your payment of Rs. ' . number_format($payment->amount, 2) . ' for project "' . $project->name . '" has been confirmed.', 'View Dashboard', route('dashboard') ) ); } return redirect()->back()->with('success', 'Payment confirmed successfully.'); } public function rejectPayment(Payment $payment) { $payment->update(['status' => 'rejected']); return redirect()->back()->with('success', 'Payment rejected.'); } // Admin Password Change public function updatePassword(Request $request) { $request->validate([ 'current_password' => 'required', 'password' => 'required|string|min:8|confirmed', ]); if (!\Hash::check($request->current_password, auth()->user()->password)) { return redirect()->back()->with('error', 'Current password is incorrect.'); } auth()->user()->update([ 'password' => \Hash::make($request->password), ]); return redirect()->back()->with('success', 'Password updated successfully.'); } private function getClientUsers() { $clientRoleUsers = User::role('Client')->get(); $noRoleUsers = User::whereDoesntHave('roles')->get(); return $clientRoleUsers->concat($noRoleUsers); } }
Save Changes
Cancel
Create New File
Create New Folder