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"); } // 1. Delete any existing May attendance records and leaves to have a clean state 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(); // 2. Pre-generate default blank attendance records for the period (excluding weekends) // to simulate the standard scheduler behavior $currentDate = \Carbon\Carbon::parse('2026-05-11'); $endDate = \Carbon\Carbon::parse('2026-05-25'); while ($currentDate->lte($endDate)) { if (!$currentDate->isWeekend()) { AttendanceRecord::create([ 'employee_id' => $user->id, 'date' => $currentDate->toDateString(), 'status' => 'absent', 'is_absent' => true, 'is_rest_day' => false, 'total_hours' => 0, 'created_by' => 1 ]); } $currentDate->addDay(); } // 3. 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(); echo "Leaves and attendance records generated successfully.\n"; // 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"; });