-- Unpaid leave was previously treated identically to paid leave in
-- payroll -- calculateAttendanceForRange() excused ANY approved leave
-- from the absent-day count regardless of the leave type's is_paid flag,
-- so taking unpaid leave resulted in zero deduction, the same as paid
-- leave. This adds columns to record unpaid leave days/amount SEPARATELY
-- from absent_days/lop_amount: both are deducted at the same daily rate,
-- but keeping them apart means a payslip can honestly show "2 days
-- unpaid leave (approved)" rather than lumping it in with "absent" and
-- implying an unauthorized absence.
--
-- Safe to run more than once.

ALTER TABLE payroll_payslip_runs
    ADD COLUMN IF NOT EXISTS unpaid_leave_days DECIMAL(5,2) DEFAULT 0.00 AFTER absent_days,
    ADD COLUMN IF NOT EXISTS unpaid_leave_amount DECIMAL(15,2) DEFAULT 0.00 AFTER lop_amount;

-- Same reasoning applied to the monthly attendance summary HR reviews on
-- the Attendance Records page -- unpaid leave days tracked separately
-- from absent_days there too, for the same honesty-on-the-record reason.
ALTER TABLE attendance_monthly_summaries
    ADD COLUMN IF NOT EXISTS unpaid_leave_days INT(11) DEFAULT 0 AFTER absent_days;
