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', 'Francis Eleazar Londonio')->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 $dates = [ '2026-05-11' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 9.0, 'early_hours' => 0.0], '2026-05-12' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // VL '2026-05-13' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // Absent '2026-05-14' => ['status' => 'absent', 'is_rest_day' => true, 'hours' => 0.0, 'early_hours' => 0.0], // Rest Day '2026-05-15' => ['status' => 'present', 'is_rest_day' => false, 'hours' => 4.0, 'early_hours' => -5.0], // 4 hours worked, 5 hours early departure '2026-05-16' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // BL '2026-05-17' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // VL '2026-05-18' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // VL '2026-05-19' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // Absent '2026-05-20' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // Absent '2026-05-21' => ['status' => 'absent', 'is_rest_day' => true, 'hours' => 0.0, 'early_hours' => 0.0], // Rest Day '2026-05-22' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // SL '2026-05-23' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // SL '2026-05-24' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // SL '2026-05-25' => ['status' => 'absent', 'is_rest_day' => false, 'hours' => 0.0, 'early_hours' => 0.0], // SL ]; foreach ($dates as $date => $info) { AttendanceRecord::create([ 'employee_id' => $user->id, 'date' => $date, 'status' => $info['status'], 'is_absent' => $info['status'] === 'absent' && !$info['is_rest_day'], 'is_rest_day' => $info['is_rest_day'], 'total_hours' => $info['hours'], 'early_hours' => $info['early_hours'], 'created_by' => 1 ]); } // Create the Leave Applications // May 12 (VL) LeaveApplication::create([ 'employee_id' => $user->id, 'leave_type_id' => 1, // VL 'leave_policy_id' => 2, 'start_date' => '2026-05-12', 'end_date' => '2026-05-12', 'total_days' => 1, 'reason' => 'vl', 'status' => 'approved', 'approved_by' => 1, 'created_by' => 1 ]); // May 16 (BL) LeaveApplication::create([ 'employee_id' => $user->id, 'leave_type_id' => 4, // BL 'leave_policy_id' => 3, 'start_date' => '2026-05-16', 'end_date' => '2026-05-16', 'total_days' => 1, 'reason' => 'bl', 'status' => 'approved', 'approved_by' => 1, 'created_by' => 1 ]); // May 17 (VL) LeaveApplication::create([ 'employee_id' => $user->id, 'leave_type_id' => 1, // VL 'leave_policy_id' => 2, 'start_date' => '2026-05-17', 'end_date' => '2026-05-17', 'total_days' => 1, 'reason' => 'vl', 'status' => 'approved', 'approved_by' => 1, 'created_by' => 1 ]); // May 18 (VL) LeaveApplication::create([ 'employee_id' => $user->id, 'leave_type_id' => 1, // VL 'leave_policy_id' => 2, 'start_date' => '2026-05-18', 'end_date' => '2026-05-18', 'total_days' => 1, 'reason' => 'vl', 'status' => 'approved', 'approved_by' => 1, 'created_by' => 1 ]); // May 22-25 (SL, 4 days) LeaveApplication::create([ 'employee_id' => $user->id, 'leave_type_id' => 2, // SL 'leave_policy_id' => 1, 'start_date' => '2026-05-22', 'end_date' => '2026-05-25', 'total_days' => 4, 'reason' => 'sl', 'status' => 'approved', 'approved_by' => 1, 'created_by' => 1 ]); // 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"; });