<?php

namespace App\Http\Controllers\Web\Payroll\V2;

use App\Http\Controllers\Controller;
use App\Models\EmployeePayroll;

class EmployeePayrollController extends Controller
{
    public function show(\App\Models\PayrollCycle $cycle, EmployeePayroll $employeePayroll)
    {
        $companyId = auth()->user()->company_id;
        if ($companyId && (int) $employeePayroll->company_id !== $companyId) {
            abort(403);
        }
        if ((int) $employeePayroll->payroll_cycle_id !== (int) $cycle->id) {
            abort(404);
        }
        $employeePayroll->load([
            'user.department',
            'payrollCycle',
            'components',
        ]);
        $employeePayroll->payrollCycle->load('runLogs.actor');
        return view('payroll.v2.detail', [
            'employeePayroll' => $employeePayroll,
        ]);
    }
}
