dstpabuaran.com/app/Http/Controllers/Admin/Finance/EmployeeAdvanceController.php
Yoga Pangestu 912f576c74 feat: implement Employee Advance management functionality
- Add EmployeeAdvanceService for handling employee advance operations including create, update, delete, approve, and pay.
- Create new components for date picking and calendar UI.
- Develop Employee Advance columns for data table representation.
- Implement Employee Advance index page with CRUD operations and dialogs for creating, editing, approving, and paying advances.
- Update routes to include employee advances resource and specific actions for approval and payment.
- Add necessary dependencies for date handling and UI components.
2026-07-29 21:07:21 +07:00

98 lines
3.4 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Finance;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Finance\EmployeeAdvanceRequest;
use App\Models\EmployeeAdvance;
use App\Services\Admin\Finance\EmployeeAdvanceService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
class EmployeeAdvanceController extends Controller
{
public function __construct(
private EmployeeAdvanceService $service
) {}
public function index(): Response
{
return Inertia::render('admin/finance/employee-advance/index', [
'employeeAdvances' => $this->service->getAll(),
]);
}
public function store(EmployeeAdvanceRequest $request): RedirectResponse
{
try {
$this->service->create($request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kasbon berhasil ditambahkan.']);
} catch (ValidationException $e) {
$firstError = collect($e->errors())->flatten()->first();
Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
}
return to_route('admin.finance.employee-advances.index');
}
public function update(EmployeeAdvanceRequest $request, EmployeeAdvance $employeeAdvance): RedirectResponse
{
try {
$this->service->update($employeeAdvance, $request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kasbon berhasil diperbarui.']);
} catch (ValidationException $e) {
$firstError = collect($e->errors())->flatten()->first();
Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
}
return to_route('admin.finance.employee-advances.index');
}
public function destroy(EmployeeAdvance $employeeAdvance): RedirectResponse
{
try {
$this->service->delete($employeeAdvance);
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kasbon berhasil dihapus.']);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
}
return to_route('admin.finance.employee-advances.index');
}
public function approve(EmployeeAdvance $employeeAdvance): RedirectResponse
{
try {
$this->service->approve($employeeAdvance);
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kasbon berhasil disetujui.']);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
}
return to_route('admin.finance.employee-advances.index');
}
public function pay(EmployeeAdvance $employeeAdvance): RedirectResponse
{
try {
$this->service->pay($employeeAdvance);
Inertia::flash('toast', ['type' => 'success', 'message' => 'Kasbon berhasil dibayar.']);
} catch (\Exception $e) {
Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]);
}
return to_route('admin.finance.employee-advances.index');
}
}