Skip to content

Commit 1b4c140

Browse files
feat(controller): add InvoiceController with myInvoices method for patient invoice management
1 parent 7329e54 commit 1b4c140

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Invoice;
4+
5+
use App\Http\Controllers\Controller;
6+
use Auth;
7+
use Illuminate\Http\Request;
8+
use Inertia\Inertia;
9+
use Log;
10+
11+
class InvoiceController extends Controller
12+
{
13+
public function myInvoices(Request $request)
14+
{
15+
Log::info('Patient Invoice: Viewed own invoices', ['action_user_id' => Auth::id()]);
16+
17+
$patientInfo = Auth::user()->patientInfo;
18+
19+
$perPage = (int) $request->query('per_page', 10);
20+
$search = trim($request->query('search'));
21+
$sortBy = $request->query('sort_by', 'id');
22+
$sortDir = strtolower($request->query('sort_dir', 'desc')) === 'asc' ? 'asc' : 'desc';
23+
24+
$allowedSorts = ['id', 'consultation_date', 'due_date', 'amount', 'payment_method', 'status'];
25+
if (! in_array($sortBy, $allowedSorts)) {
26+
$sortBy = 'id';
27+
}
28+
29+
$invoices = $patientInfo->invoices()
30+
->when($request->filled('search'), fn ($q) => $q->where(function ($q) use ($search) {
31+
$q->whereLike('notes', "%$search%")
32+
->orWhereLike('payment_method', "%$search%")
33+
->orWhereLike('status', "%$search%");
34+
}))
35+
->orderBy($sortBy, $sortDir)
36+
->paginate($perPage)
37+
->withQueryString();
38+
39+
return Inertia::render('patient/invoices/MyInvoices', ['invoices' => $invoices]);
40+
}
41+
}

0 commit comments

Comments
 (0)