Invoicing Feature Complete #8

Merged
okorpheus merged 7 commits from invoicing into master 2024-06-29 15:27:15 +00:00
5 changed files with 30 additions and 4 deletions
Showing only changes of commit c3b48bf89c - Show all commits

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\School; use App\Models\School;
use App\Models\SchoolEmailDomain; use App\Models\SchoolEmailDomain;
use App\Services\Invoice\InvoiceDataService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -14,14 +15,25 @@ use function request;
class SchoolController extends Controller class SchoolController extends Controller
{ {
protected $invoiceService;
public function __construct(InvoiceDataService $invoiceController)
{
$this->invoiceService = $invoiceController;
}
public function index() public function index()
{ {
if (! Auth::user()->is_admin) { if (! Auth::user()->is_admin) {
abort(403); abort(403);
} }
$schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get(); $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', ['schools' => $schools]); return view('admin.schools.index', compact('schools', 'schoolTotalFees'));
} }
public function show(Request $request, School $school) public function show(Request $request, School $school)
@ -122,4 +134,11 @@ class SchoolController extends Controller
// return a redirect to the previous URL // return a redirect to the previous URL
return redirect()->back(); return redirect()->back();
} }
public function viewInvoice(Request $request, School $school)
{
$invoiceData = $this->invoiceService->allData($school->id);
return view('dashboard.invoice', compact('school', 'invoiceData'));
}
} }

View File

@ -37,7 +37,7 @@ class InvoiceOneFeePerEntry implements InvoiceDataService
$entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id'); $entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id');
foreach ($school->students as $student) { foreach ($school->students as $student) {
foreach ($entries[$student->id] as $entry) { foreach ($entries[$student->id] ?? [] as $entry) {
$entryFee = $entry->audition->entry_fee / 100; $entryFee = $entry->audition->entry_fee / 100;
$lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0; $lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0;

View File

@ -38,7 +38,7 @@ class InvoiceOneFeePerStudent implements InvoiceDataService
$entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id'); $entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id');
foreach ($school->students as $student) { foreach ($school->students as $student) {
$firstEntryForStudent = true; $firstEntryForStudent = true;
foreach ($entries[$student->id] as $entry) { foreach ($entries[$student->id] ?? [] as $entry) {
if ($firstEntryForStudent) { if ($firstEntryForStudent) {
$entryFee = $entry->audition->entry_fee / 100; $entryFee = $entry->audition->entry_fee / 100;
$lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0; $lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0;

View File

@ -4,7 +4,7 @@
<x-card.card> <x-card.card>
<x-table.table with_title_area> <x-table.table with_title_area>
<x-slot:title class="ml-3">Schools</x-slot:title> <x-slot:title class="ml-3">Schools</x-slot:title>
<x-slot:subtitle class="ml-3">Click school name to edit</x-slot:subtitle> <x-slot:subtitle class="ml-3">Click school name to edit<br>Click total fees for invoice</x-slot:subtitle>
<x-slot:title_block_right class="mr-3"> <x-slot:title_block_right class="mr-3">
<x-form.button href="{{ route('admin.schools.create') }}">New School</x-form.button> <x-form.button href="{{ route('admin.schools.create') }}">New School</x-form.button>
</x-slot:title_block_right> </x-slot:title_block_right>
@ -12,6 +12,7 @@
<thead> <thead>
<tr> <tr>
<x-table.th>Name</x-table.th> <x-table.th>Name</x-table.th>
<x-table.th>Total Fees</x-table.th>
<x-table.th>Directors</x-table.th> <x-table.th>Directors</x-table.th>
<x-table.th>Students</x-table.th> <x-table.th>Students</x-table.th>
<x-table.th>Entries</x-table.th> <x-table.th>Entries</x-table.th>
@ -22,6 +23,11 @@
@foreach($schools as $school) @foreach($schools as $school)
<tr> <tr>
<x-table.td><a href="/admin/schools/{{ $school->id }}">{{ $school->name }}</a></x-table.td> <x-table.td><a href="/admin/schools/{{ $school->id }}">{{ $school->name }}</a></x-table.td>
<x-table.td>
<a href="{{ route('admin.schools.invoice',$school->id) }}">
${{ number_format($schoolTotalFees[$school->id],2) }}
</a>
</x-table.td>
<x-table.td>{{ $school->users->count() }}</x-table.td> <x-table.td>{{ $school->users->count() }}</x-table.td>
<x-table.td>{{ $school->students->count() }}</x-table.td> <x-table.td>{{ $school->students->count() }}</x-table.td>
<x-table.td>{{ $school->entries->count() }}</x-table.td> <x-table.td>{{ $school->entries->count() }}</x-table.td>

View File

@ -99,6 +99,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
Route::get('/create', 'create')->name('admin.schools.create'); Route::get('/create', 'create')->name('admin.schools.create');
Route::get('/{school}', 'show')->name('admin.schools.show'); Route::get('/{school}', 'show')->name('admin.schools.show');
Route::get('/{school}/edit', 'edit')->name('admin.schools.edit'); Route::get('/{school}/edit', 'edit')->name('admin.schools.edit');
Route::get('/{school}/invoice', 'viewInvoice')->name('admin.schools.invoice');
Route::patch('/{school}', 'update')->name('admin.schools.update'); Route::patch('/{school}', 'update')->name('admin.schools.update');
Route::post('/', 'store')->name('admin.schools.store'); Route::post('/', 'store')->name('admin.schools.store');
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain'); Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');