89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Manage;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Manage\TransactionRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\Order;
|
|
use App\Services\Admin\Manage\TransactionService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class TransactionController extends Controller
|
|
{
|
|
public function __construct(
|
|
private TransactionService $service,
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
$filters = $request->only(['status', 'channel', 'payment_type', 'customer_id', 'marketing_id', 'created_by_id', 'date_from', 'date_to']);
|
|
|
|
return Inertia::render('admin/manage/transaction/index', [
|
|
'transactions' => $this->service->paginated(
|
|
...$request->validatedWithDefaults(),
|
|
filters: $filters,
|
|
),
|
|
'summary' => $this->service->getSummary($filters),
|
|
'filters' => $filters,
|
|
'filterOptions' => $this->service->getFilterOptions(),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/manage/transaction/create', [
|
|
'data' => $this->service->getForCreate(),
|
|
]);
|
|
}
|
|
|
|
public function store(TransactionRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn() => $this->service->create($request->validated()),
|
|
'Transaksi berhasil ditambahkan.',
|
|
'admin.manage.transactions.index',
|
|
'admin.manage.transactions.create'
|
|
);
|
|
}
|
|
|
|
public function edit(Order $transaction): Response
|
|
{
|
|
return Inertia::render('admin/manage/transaction/edit', [
|
|
'transaction' => $this->service->getForEdit($transaction),
|
|
'data' => $this->service->getForCreate(),
|
|
]);
|
|
}
|
|
|
|
public function update(TransactionRequest $request, Order $transaction): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn() => $this->service->update($transaction, $request->validated()),
|
|
'Transaksi berhasil diperbarui.',
|
|
'admin.manage.transactions.index',
|
|
'admin.manage.transactions.edit',
|
|
['transaction' => $transaction]
|
|
);
|
|
}
|
|
|
|
public function destroy(Order $transaction): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn() => $this->service->delete($transaction),
|
|
'Transaksi berhasil dihapus.',
|
|
'admin.manage.transactions.index'
|
|
);
|
|
}
|
|
|
|
public function updateStatus(Order $transaction): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn() => $this->service->updateStatus($transaction, request('status')),
|
|
'Status transaksi berhasil diperbarui.',
|
|
'admin.manage.transactions.index'
|
|
);
|
|
}
|
|
}
|