Files
HRM-System/scratch/simulate_ana_payslip.php

119 lines
4.6 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\User;
use App\Models\LeaveApplication;
use App\Models\AttendanceRecord;
use App\Services\PayrollService;
use Illuminate\Support\Facades\DB;
DB::transaction(function() {
$user = User::where('name', 'Ana Regina Mariano')->first();
if (!$user) {
die("User not found\n");
}
// Delete existing attendance records and leaves for May 11-25
AttendanceRecord::where('employee_id', $user->id)
->whereBetween('date', ['2026-05-11', '2026-05-25'])
->delete();
LeaveApplication::where('employee_id', $user->id)
->whereBetween('start_date', ['2026-05-11', '2026-05-25'])
->delete();
// Setup attendance status mapping (SKIPPING May 16 and May 23 to simulate weekend skip!)
$dates = [
'2026-05-11' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-12' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-13' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0], // LWOP (weekday - record created)
'2026-05-14' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-15' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
// '2026-05-16' => skipped (weekend VL)
'2026-05-17' => ['status' => 'absent', 'is_rest_day' => true, 'hours' => 0], // Sunday rest day
'2026-05-18' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-19' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-20' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-21' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
'2026-05-22' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
// '2026-05-23' => skipped (weekend LWOP)
'2026-05-24' => ['status' => 'absent', 'is_rest_day' => true, 'hours' => 0], // Sunday rest day
'2026-05-25' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 8],
];
foreach ($dates as $date => $info) {
AttendanceRecord::create([
'employee_id' => $user->id,
'date' => $date,
'status' => $info['status'],
'is_absent' => $info['status'] === 'absent',
'is_rest_day' => $info['is_rest_day'],
'total_hours' => $info['hours'],
'created_by' => 1
]);
}
// Create the Leave Applications
// May 13 (LWOP)
$leave1 = LeaveApplication::create([
'employee_id' => $user->id,
'leave_type_id' => 3, // LWOP
'leave_policy_id' => 4,
'start_date' => '2026-05-13',
'end_date' => '2026-05-13',
'total_days' => 1,
'reason' => 'lwop 1',
'status' => 'approved',
'approved_by' => 1,
'created_by' => 1
]);
$leave1->createAttendanceRecords();
// May 16 (Vacation Leave)
$leave2 = LeaveApplication::create([
'employee_id' => $user->id,
'leave_type_id' => 1, // VL
'leave_policy_id' => 2,
'start_date' => '2026-05-16',
'end_date' => '2026-05-16',
'total_days' => 1,
'reason' => 'vl',
'status' => 'approved',
'approved_by' => 1,
'created_by' => 1
]);
$leave2->createAttendanceRecords();
// May 23 (LWOP)
$leave3 = LeaveApplication::create([
'employee_id' => $user->id,
'leave_type_id' => 3, // LWOP
'leave_policy_id' => 4,
'start_date' => '2026-05-23',
'end_date' => '2026-05-23',
'total_days' => 1,
'reason' => 'lwop 2',
'status' => 'approved',
'approved_by' => 1,
'created_by' => 1
]);
$leave3->createAttendanceRecords();
// 4. Run the payroll service
$service = new PayrollService();
$result = $service->calculateForPeriod($user->employee, '2026-05-11', '2026-05-25');
echo "\n=== Payroll Results ===\n";
echo "Basic Salary: " . $result['basic_salary'] . "\n";
echo "Total Earnings: " . $result['total_earnings'] . "\n";
echo "Net Pay: " . $result['net_pay'] . "\n";
echo "Earnings Breakdown:\n";
foreach($result['earnings'] as $e) echo " - " . $e['name'] . ": " . $e['amount'] . "\n";
echo "Deductions Breakdown:\n";
foreach($result['deductions'] as $d) echo " - " . $d['name'] . ": " . $d['amount'] . "\n";
echo "Summary:\n" . json_encode($result['summary'], JSON_PRETTY_PRINT) . "\n";
});