invoiceService = $invoiceController; } public function index() { $schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get(); $schoolTotalFees = []; foreach ($schools as $school) { $schoolTotalFees[$school->id] = $this->invoiceService->getGrandTotal($school->id); } return view('admin.schools.index', compact('schools', 'schoolTotalFees')); } public function show(School $school) { $logEntries = AuditLogEntry::whereJsonContains('affected->schools', $school->id)->orderBy('created_at', 'desc')->get(); return view('admin.schools.show', compact('school', 'logEntries')); } public function edit(School $school) { $school->loadCount('students'); return view('admin.schools.edit', ['school' => $school]); } public function update(SchoolStoreRequest $request, School $school) { $school->update([ 'name' => $request['name'], 'address' => $request['address'], 'city' => $request['city'], 'state' => $request['state'], 'zip' => $request['zip'], ]); return redirect()->route('admin.schools.show', ['school' => $school->id])->with('success', 'School '.$school->name.' updated'); } public function create() { return view('admin.schools.create'); } public function store(SchoolStoreRequest $request) { $creator = app(CreateSchool::class); $school = $creator( $request['name'], $request['address'], $request['city'], $request['state'], $request['zip'], ); return redirect(route('admin.schools.index'))->with('success', 'School '.$school->name.' created'); } public function destroy(School $school) { if ($school->students()->count() > 0) { return to_route('admin.schools.index')->with('error', 'You cannot delete a school that has students.'); } $school->delete(); return to_route('admin.schools.index')->with('success', 'School '.$school->name.' deleted'); } public function add_domain(School $school) { request()->validate([ // validate that the combination of school and domain is unique on the school_email_domains table 'domain' => ['required'], ]); SchoolEmailDomain::updateOrInsert([ 'school_id' => $school->id, 'domain' => request('domain'), ]); return redirect()->route('admin.schools.show', $school)->with('success', 'Domain Added'); } public function destroy_domain(SchoolEmailDomain $domain) { // Destroy the $domain $domain->delete(); // return a redirect to the previous URL return redirect()->back()->with('success', 'Domain removed successfully.'); } // TODO: Add testing for invoicing /** @codeCoverageIgnore */ public function viewInvoice(School $school) { $invoiceData = $this->invoiceService->allData($school->id); return view('dashboard.invoice', compact('school', 'invoiceData')); } public function setHeadDirector(School $school, User $user, SetHeadDirector $headSetter) { if ($user->school_id !== $school->id) { return redirect()->back()->with('error', 'That user is not at that school'); } /** @noinspection PhpUnhandledExceptionInspection */ $headSetter->setHeadDirector($user); return redirect()->back()->with('success', 'Head director set successfully.'); } }