|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Modules\Finance\Http\Controllers; |
| 4 | + |
| 5 | +use App\Http\Controllers\Controller; |
| 6 | +use App\Modules\Finance\Models\DebitNote; |
| 7 | +use Illuminate\Http\RedirectResponse; |
| 8 | +use Illuminate\Http\Request; |
| 9 | +use Inertia\Inertia; |
| 10 | +use Inertia\Response; |
| 11 | + |
| 12 | +class DebitNoteController extends Controller |
| 13 | +{ |
| 14 | + public function index(): Response |
| 15 | + { |
| 16 | + $this->authorize('viewAny', DebitNote::class); |
| 17 | + $debitNotes = DebitNote::where('tenant_id', app('tenant')->id) |
| 18 | + ->latest() |
| 19 | + ->paginate(20); |
| 20 | + return Inertia::render('Finance/DebitNotes/Index', compact('debitNotes')); |
| 21 | + } |
| 22 | + |
| 23 | + public function store(Request $request): RedirectResponse |
| 24 | + { |
| 25 | + $this->authorize('create', DebitNote::class); |
| 26 | + $validated = $request->validate([ |
| 27 | + 'vendor_id' => 'nullable|exists:contacts,id', |
| 28 | + 'vendor_bill_id'=> 'nullable|exists:vendor_bills,id', |
| 29 | + 'issue_date' => 'required|date', |
| 30 | + 'currency' => 'nullable|string|max:3', |
| 31 | + 'reason' => 'nullable|string', |
| 32 | + ]); |
| 33 | + $validated['tenant_id'] = app('tenant')->id; |
| 34 | + $validated['created_by'] = auth()->id(); |
| 35 | + DebitNote::create($validated); |
| 36 | + return back()->with('success', 'Debit note created.'); |
| 37 | + } |
| 38 | + |
| 39 | + public function show(DebitNote $debitNote): Response |
| 40 | + { |
| 41 | + $this->authorize('view', $debitNote); |
| 42 | + return Inertia::render('Finance/DebitNotes/Show', compact('debitNote')); |
| 43 | + } |
| 44 | + |
| 45 | + public function issue(DebitNote $debitNote): RedirectResponse |
| 46 | + { |
| 47 | + $this->authorize('update', $debitNote); |
| 48 | + $debitNote->issue(); |
| 49 | + return back()->with('success', 'Debit note issued.'); |
| 50 | + } |
| 51 | + |
| 52 | + public function apply(DebitNote $debitNote): RedirectResponse |
| 53 | + { |
| 54 | + $this->authorize('update', $debitNote); |
| 55 | + $debitNote->apply(); |
| 56 | + return back()->with('success', 'Debit note applied.'); |
| 57 | + } |
| 58 | + |
| 59 | + public function void(DebitNote $debitNote): RedirectResponse |
| 60 | + { |
| 61 | + $this->authorize('update', $debitNote); |
| 62 | + $debitNote->void(); |
| 63 | + return back()->with('success', 'Debit note voided.'); |
| 64 | + } |
| 65 | + |
| 66 | + public function destroy(DebitNote $debitNote): RedirectResponse |
| 67 | + { |
| 68 | + $this->authorize('delete', $debitNote); |
| 69 | + $debitNote->delete(); |
| 70 | + return back()->with('success', 'Debit note deleted.'); |
| 71 | + } |
| 72 | +} |
0 commit comments