Invoicing Feature Complete #8
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\School;
|
||||
use App\Models\SchoolEmailDomain;
|
||||
use App\Services\Invoice\InvoiceDataService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
|
@ -14,14 +15,25 @@ use function request;
|
|||
|
||||
class SchoolController extends Controller
|
||||
{
|
||||
protected $invoiceService;
|
||||
|
||||
public function __construct(InvoiceDataService $invoiceController)
|
||||
{
|
||||
$this->invoiceService = $invoiceController;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$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)
|
||||
|
|
@ -122,4 +134,11 @@ class SchoolController extends Controller
|
|||
// return a redirect to the previous URL
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function viewInvoice(Request $request, School $school)
|
||||
{
|
||||
$invoiceData = $this->invoiceService->allData($school->id);
|
||||
|
||||
return view('dashboard.invoice', compact('school', 'invoiceData'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class InvoiceOneFeePerEntry implements InvoiceDataService
|
|||
|
||||
$entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id');
|
||||
foreach ($school->students as $student) {
|
||||
foreach ($entries[$student->id] as $entry) {
|
||||
foreach ($entries[$student->id] ?? [] as $entry) {
|
||||
$entryFee = $entry->audition->entry_fee / 100;
|
||||
$lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class InvoiceOneFeePerStudent implements InvoiceDataService
|
|||
$entries = $school->entries()->with('audition')->orderBy('created_at', 'desc')->get()->groupBy('student_id');
|
||||
foreach ($school->students as $student) {
|
||||
$firstEntryForStudent = true;
|
||||
foreach ($entries[$student->id] as $entry) {
|
||||
foreach ($entries[$student->id] ?? [] as $entry) {
|
||||
if ($firstEntryForStudent) {
|
||||
$entryFee = $entry->audition->entry_fee / 100;
|
||||
$lateFee = $this->entryService->entryIsLate($entry) ? auditionSetting('late_fee') / 100 : 0;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<x-card.card>
|
||||
<x-table.table with_title_area>
|
||||
<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-form.button href="{{ route('admin.schools.create') }}">New School</x-form.button>
|
||||
</x-slot:title_block_right>
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<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>Students</x-table.th>
|
||||
<x-table.th>Entries</x-table.th>
|
||||
|
|
@ -22,6 +23,11 @@
|
|||
@foreach($schools as $school)
|
||||
<tr>
|
||||
<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->students->count() }}</x-table.td>
|
||||
<x-table.td>{{ $school->entries->count() }}</x-table.td>
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::get('/create', 'create')->name('admin.schools.create');
|
||||
Route::get('/{school}', 'show')->name('admin.schools.show');
|
||||
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::post('/', 'store')->name('admin.schools.store');
|
||||
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');
|
||||
|
|
|
|||
Loading…
Reference in New Issue