70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
$app = require_once __DIR__.'/../bootstrap/app.php';
|
|
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
|
$kernel->bootstrap();
|
|
|
|
use App\Models\Employee;
|
|
use App\Models\AttendanceRecord;
|
|
use App\Services\PayrollService;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
$payrollService = new PayrollService();
|
|
$startDate = '2026-05-11';
|
|
$endDate = '2026-05-25';
|
|
|
|
$employees = Employee::with(['user', 'branch', 'shift'])->get();
|
|
|
|
$results = [];
|
|
|
|
foreach ($employees as $emp) {
|
|
$user = $emp->user;
|
|
if (!$user) continue;
|
|
|
|
$salary = \App\Models\EmployeeSalary::where('employee_id', $user->id)->first();
|
|
$frequency = $salary ? $salary->pay_frequency : 'unknown';
|
|
$rate = $salary ? $salary->basic_salary : 0.0;
|
|
|
|
// Run payroll simulation
|
|
try {
|
|
$sim = $payrollService->calculateForPeriod($emp, $startDate, $endDate);
|
|
} catch (\Exception $e) {
|
|
$sim = ['error' => $e->getMessage()];
|
|
}
|
|
|
|
// Get attendance records
|
|
$attendance = AttendanceRecord::where('employee_id', $user->id)
|
|
->whereBetween('date', [$startDate, $endDate])
|
|
->orderBy('date', 'asc')
|
|
->get()
|
|
->map(function($r) {
|
|
return [
|
|
'date' => $r->date instanceof \Carbon\Carbon ? $r->date->toDateString() : substr((string)$r->date, 0, 10),
|
|
'status' => $r->status,
|
|
'is_absent' => $r->is_absent,
|
|
'is_rest_day' => $r->is_rest_day,
|
|
'clock_in' => $r->clock_in,
|
|
'clock_out' => $r->clock_out,
|
|
'total_hours' => $r->total_hours,
|
|
'late_hours' => $r->late_hours,
|
|
'early_hours' => $r->early_hours,
|
|
'remarks' => $r->remarks ?? ''
|
|
];
|
|
})->toArray();
|
|
|
|
$results[] = [
|
|
'name' => $user->name,
|
|
'user_id' => $user->id,
|
|
'employee_code' => $emp->employee_id,
|
|
'biometric_emp_id' => $emp->biometric_emp_id,
|
|
'frequency' => $frequency,
|
|
'rate' => $rate,
|
|
'branch_name' => $emp->branch ? $emp->branch->name : 'N/A',
|
|
'shift_name' => $emp->shift ? $emp->shift->name : 'N/A',
|
|
'simulation' => $sim,
|
|
'attendance' => $attendance
|
|
];
|
|
}
|
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT) . "\n";
|