# Different Attendance Cycle (HR) and Payroll Period

Many companies prepare and pay their monthly salaries to employees before the month’s end (on 24th or 25th)./
They use the Attendance Cycle ie. from 21/08/2022 to 20/09/2022 when preparing the full September 2022 Salary by September 24th.
The Payment Slip payment calculation is based on Payment Days which is
“Payment Days” = Working Days (Number of days in Current Payroll Calendar Month )- Absent Days (from Attendance module) - Leave without Pay (Unpaid Leaves from Leave Module)
The Payroll Period is from 01/09/2022 to 30/09/2022, but since the Payroll Entry / Salary Slip is prepared on 24th September based on Attendance and Leaves from 21/08/22 to 20/09/22 the following will happen:
The Absent Days & Leave without Pay will be based on the partial period from Attendance Cycle- from 01/09/2022 to 20/09/22
However, they can add the (Absent Days & Leave without Pay ) period from 21/08/2022 - 31/08/22.
So, the formula should be:
Payment Days" = Working Days (Number of days in Current Payroll Calendar Month )- Absent Days (from Attendance module for 01/09/2022 to 20/09/2022 - OK) - Leave without Pay (Unpaid Leaves from Leave Module for 01/09/2022 to 20/09/2022 - OK) - Previous Balance Absent Days (from Attendance module for 21/08/2022 to 31/08/2022) - Previous Balance Leave without Pay (Unpaid Leaves from Leave Module for 21/08/2022 to 31/08/2022).
Did anyone face this issue?
I managed to add the following fields to Salary Slip DocType
Attendance Cycle From (Date)
Attendance Cycle To (Date)
Previous Balance Absent days (Float)
Previous Balance Leave without Pay days (Float)

I need to:

1. Calculate Previous Balance Absent days and Previous Balance Leave without Pay days automatically from Attendance and Leave records starting from Attendance Cycle From to the end of the (previous) month
2. Update the Payment Days formula to subtract these fields as the formula above.

How to do this?
Do I need to update the python code of the DocType ?