- Added InvoiceIndex component for displaying a list of invoices with pagination and search capabilities. - Created InvoiceShareButton component for sharing invoice details via WhatsApp. - Developed InvoicePrint component for printing invoice details. - Defined routes for invoice management including share and print functionalities. - Implemented InvoiceTest to cover authentication, authorization, and CRUD operations for invoices.
87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Manage;
|
|
|
|
use App\Enums\InvoiceStatus;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Manage\InvoiceRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\Invoice;
|
|
use App\Services\Admin\Manage\InvoiceService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class InvoiceController extends Controller
|
|
{
|
|
public function __construct(
|
|
private InvoiceService $service
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/manage/invoice/index', [
|
|
'invoices' => $this->service->paginated(...$request->validatedWithDefaults()),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/manage/invoice/create', [
|
|
'statusOptions' => InvoiceStatus::toSelect(),
|
|
]);
|
|
}
|
|
|
|
public function store(InvoiceRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->store($request->validated()),
|
|
'Invoice berhasil ditambahkan.',
|
|
'admin.manage.invoices.index',
|
|
'admin.manage.invoices.create'
|
|
);
|
|
}
|
|
|
|
public function edit(Invoice $invoice): Response
|
|
{
|
|
return Inertia::render('admin/manage/invoice/edit', [
|
|
'invoice' => $this->service->getForEdit($invoice),
|
|
'statusOptions' => InvoiceStatus::toSelect(),
|
|
]);
|
|
}
|
|
|
|
public function print(Invoice $invoice): Response
|
|
{
|
|
return Inertia::render('admin/manage/invoice/print', [
|
|
'invoice' => $this->service->getForPrint($invoice),
|
|
]);
|
|
}
|
|
|
|
public function share(Invoice $invoice): Response
|
|
{
|
|
return Inertia::render('admin/manage/invoice/print', [
|
|
'invoice' => $this->service->getForPrint($invoice),
|
|
]);
|
|
}
|
|
|
|
public function update(InvoiceRequest $request, Invoice $invoice): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->update($invoice, $request->validated()),
|
|
'Invoice berhasil diperbarui.',
|
|
'admin.manage.invoices.index',
|
|
'admin.manage.invoices.edit',
|
|
['invoice' => $invoice]
|
|
);
|
|
}
|
|
|
|
public function destroy(Invoice $invoice): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->destroy($invoice),
|
|
'Invoice berhasil dihapus.',
|
|
'admin.manage.invoices.index'
|
|
);
|
|
}
|
|
}
|