How can i set up Auto email with Filters

i want to send Employee checkin report for each employee only their previous day checkin details how can i send that

use setup auto email

please check this document

https://docs.erpnext.com/docs/user/manual/en/auto-email-reports

So ineed to create report for each employee

please check this docs

Hi,

You can easily set using the background job but that for you have to write a code in your custom app.

scheduler_events = {
    'daily': [
        'your_app_name.your_module_name.send_daily_checkin_report'
    ]
}
import frappe

def send_daily_checkin_report():
    try:
        previous_day = frappe.utils.add_days(frappe.utils.nowdate(), -1)

        employees = frappe.get_all('Employee', filters={'user_id': ['is', 'set']}, fields=['name', 'user_id'])

        for employee in employees:
            checkins = frappe.get_all('Employee Checkin',
                                      filters={
                                          'employee': employee.name,
                                          'time': ['between', [previous_day + ' 00:00:00', previous_day + ' 23:59:59']]
                                      },
                                      fields=['name', 'time', 'log_type'],
                                      order_by='time asc')

            if checkins:
                message = f"<p>Check-in details for {frappe.utils.format_datetime(previous_day, 'yyyy-MM-dd')}:</p>"
                message += "<table border='1' style='border-collapse: collapse;'>"
                message += "<tr><th>Time</th><th>Log Type</th></tr>"

                for checkin in checkins:
                    message += f"<tr><td>{frappe.utils.format_datetime(checkin.time, 'HH:mm:ss')}</td><td>{checkin.log_type}</td></tr>"

                message += "</table>"

                user_email = frappe.db.get_value('User', employee.user_id, 'email')
                if user_email:
                    frappe.sendmail(
                        recipients=user_email,
                        subject='Your Check-in Details for Yesterday',
                        message=message
                    )
    except Exception as e:
        frappe.log_error(frappe.get_traceback(), 'Send Daily Checkin Report Error')

send_daily_checkin_report()

Output:

3 Likes

@NCP Thank you