- Updated CustomerService to simplify getAll method. - Refactored ProductService to utilize HasRoleChecks trait and improved role verification logic. - Enhanced ProductVariantService with new methods for fetching data for restocking and transactions. - Cleaned up RawMaterialService by removing unused methods and improving data retrieval. - Adjusted SupplierService to streamline getAll method. - Refactored RoleService to use Spatie's Role model and improved role filtering logic. - Updated NotificationService to handle role labels more effectively. - Improved StockMutationService by removing redundant paginated method. - Cleaned up various frontend components to directly accept necessary props instead of nested data objects. - Updated tests to reflect changes in service method names and ensure proper notification handling.
70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Finance\Payroll;
|
|
|
|
use App\Concerns\HasRoleChecks;
|
|
use App\Enums\Role;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\PayrollPeriod;
|
|
use App\Services\Admin\Finance\Payroll\PayrollPeriodService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class PayrollPeriodController extends Controller
|
|
{
|
|
use HasRoleChecks;
|
|
|
|
public function __construct(
|
|
private PayrollPeriodService $service
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/finance/payroll-period/index', [
|
|
'payrollPeriods' => $this->service->paginated(...$request->validatedWithDefaults()),
|
|
]);
|
|
}
|
|
|
|
public function current(): RedirectResponse
|
|
{
|
|
$period = $this->service->getCurrentOrCreate();
|
|
|
|
return to_route('admin.finance.payroll-periods.show', ['payroll_period' => $period->id]);
|
|
}
|
|
|
|
public function show(PayrollPeriod $payrollPeriod): Response
|
|
{
|
|
$payrollPeriod->load([
|
|
'payrolls' => function ($query) {
|
|
$query->with(['employee.user.userProfile', 'payrollAdjustments'])
|
|
->when(! self::hasAnyRole([Role::DEVELOPER, Role::OWNER, Role::DIREKTUR, Role::ADMIN_TOKO]), fn ($q) => $q->whereHas('employee', fn ($eq) => $eq->where('user_id', auth()->id())))
|
|
->orderBy('id');
|
|
},
|
|
]);
|
|
|
|
return Inertia::render('admin/finance/payroll-period/show', [
|
|
'payrollPeriod' => $payrollPeriod,
|
|
]);
|
|
}
|
|
|
|
public function close(PayrollPeriod $payrollPeriod): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->close($payrollPeriod),
|
|
'Periode gaji berhasil ditutup.',
|
|
'admin.finance.payroll-periods.index'
|
|
);
|
|
}
|
|
|
|
public function reopen(PayrollPeriod $payrollPeriod): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->reopen($payrollPeriod),
|
|
'Periode gaji berhasil dibuka kembali.',
|
|
'admin.finance.payroll-periods.index'
|
|
);
|
|
}
|
|
}
|