Jinja Code in Print Format of Salary Slip

Dear Awesome Team,
If any one can help us in below. Highly appreciated.

We have customized Absent Days details of an employee in the Salary Slip Print Format.
But some times, employee is on long leave for more than 3 days. In this case, we want the rows to be clubbed i.e. Start Absent Date to End Absent Date in Single Column Field instead of each Absent Day coming on separate row, making the table very long and useless.
So, Condition will be → If Employee has no Checkins (IN & OUT both are NONE) and Working Hours is Zero for equal / more than 3 days, then the rows should be clubbed together in single line.

Ninja Code in Print FOrmat given below.
{% if doc.absent_days %}

Absent Dates & Details



    <tbody>
        <tr>
            <th>Absent Dates </th>
            <th>Working Hrs</th>
            <th>In Time</th>
            <th>Out Time</th>
        </tr>
       
        {% for row in frappe.get_list ('Attendance', filters={'employee': doc.employee,'status': 'Absent','attendance_date': ['between',(doc.start_date, doc.end_date)]}, fields= ['attendance_date','working_hours','in_time','out_time'],order_by='attendance_date asc') %}
        
        
        
        <tr>
            <td>{{ row.attendance_date.strftime("%d-%m-%Y") }}</td>
            <td>{{ row.working_hours }}</td>
            
			<td>
			    {% if row.in_time %}
			        {{ row.in_time.strftime("%H:%M:%S") }}
			    {% else %}
			        {{ row.in_time }}
			    {% endif %}
			</td>
           
            <td>
			    {% if row.out_time %}
			        {{ row.out_time.strftime("%H:%M:%S") }}
			    {% else %}
			        {{ row.out_time }}
			    {% endif %}
			</td>
        </tr>
      
      
        {% endfor %}
    </tbody>
</table>
{% endif%}

Pls refer images.


Instead of 3 rows, there should be SINGLE row with the below value in Absent Date Field.
value-> 01-12-2023 to 03-12-2023 …

Hope my question is clear.
Many Thanks

According to your condition, if the employee is absent, from where login and logout details, and working hours. Working hours will come only if the employee is present.

Employee is marked absent sometimes due to single checkin (only IN), he forgot to checkout.
Also, even if there are both checkins, he might be marked absent due to Absent Threshold field in the Shift Type Doctype settings for Auto Attendance, for eg, if this field is set to 3 hrs and his checkin and checkout are 09:00 and 11:30 resp, so his working hours will be 2.5 hrs (which is less than 3 hrs) because of which he will marked absent.

Hope this helps

Appreciate if anyone shall advise on this.