def getAbsentEmployees(advances_list, AuthRole, Limit):

    # If Its an Employee show him only his AbsentReport
    user = get_user_role()
    if user == EMPLOYEE:
        userId = frappe.db.get_value("Employee",
                                     {"user_id": frappe.session.user},
                                     "employee")
        if userId is not None:
            advances_list += " and empatt.employee = " + '\'' + userId + '\''

    advances_list += " GROUP BY empatt.employee, empatt.attendance_date "
    advances_list += " ORDER BY empatt.attendance_date DESC "
    advances_list += Limit

    employee_data = frappe.db.sql("""
          SELECT 
    tabEmp.employee_name AS EmployeeName,
    empatt.employee AS employeeID,
    tabEmp.department AS Department,
    lvapp_prv.status AS LeaveStatus,
    IF(lvapp_prv.leave_type IS NULL
            AND empatt.check_out IS NULL
            AND empatt.check_in IS NULL
            AND empatt.attendance_status = 'On',
        'Not Applied',
        IF(COUNT(lvapp_prv.leave_type) > 1,
            'Multiple Leaves Applied',
            lvapp_prv.leave_type)) AS leave_application_type,
    IF(lvapp.name IS NULL,
            lvapp_prv.leave_approver_comments,
        lvapp.leave_approver_comments) AS ApproverComments,
    empatt.attendance_date AS AttendenceDate,
    IF(lvapp.name IS NULL,lvapp_prv.description,
        lvapp.description) AS description,
    LEFT(DAYNAME(empatt.attendance_date), 3) AS theDayName
FROM
    `tabAttendance` empatt
        LEFT JOIN
    `tabRoster Status` eas ON eas.name = empatt.attendance_status
        LEFT JOIN
    `tabLeave Application` AS lvapp_prv ON (empatt.employee = lvapp_prv.employee)
        AND (empatt.attendance_date BETWEEN lvapp_prv.from_date AND lvapp_prv.to_date)
        AND lvapp_prv.docstatus < 2
        LEFT OUTER JOIN
    `tabLeave Application` AS lvapp ON (empatt.employee = lvapp.employee
        AND (lvapp.creation > lvapp_prv.creation))
        AND (empatt.attendance_date BETWEEN lvapp.from_date AND lvapp.to_date)
        AND lvapp.docstatus < 2
        INNER JOIN
    `tabEmployee` AS tabEmp ON empatt.employee = tabEmp.employee
WHERE
    eas.consider_absent = 1
        AND empatt.attendance_date <= DATE(NOW())
        AND empatt.docstatus = 1
        AND empatt.check_in is NULL AND empatt.check_out is NULL
          """ + advances_list,
                                  as_dict=True)

    return employee_data, len(employee_data)
def get_events(start, end, filters=None):
    events = []
    employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user}, ["name", "company"],
                                   as_dict=True)
    if employee:
        employee, company = employee.name, employee.company
    else:
        employee = ''
        company = frappe.db.get_value("Global Defaults", None, "default_company")

    from frappe.desk.reportview import get_filters_cond
    conditions = get_filters_cond("Leave Application", filters, [])
    user_role = get_user_role()

    subordinates = get_auth_team_ids()

    if (conditions):
        conditions += " and `tabLeave Application`.employee IN (%(subordinates)s)" % {"subordinates": subordinates}
    else:
        conditions = " and `tabLeave Application`.employee IN (%(subordinates)s)" % {"subordinates": subordinates}

    add_leaves(events, start, end, conditions)

    add_block_dates(events, start, end, employee, company)
    add_holidays(events, start, end, employee, company)

    return events
def get_events(start, end, filters=None):
    events = []
    employee = frappe.db.get_value("Employee",
                                   {"user_id": frappe.session.user})

    if not employee:
        return events

    from frappe.desk.reportview import get_filters_cond
    conditions = get_filters_cond("Attendance", filters, [])

    user_role = get_user_role()
    if (user_role == LINE_MANAGER or user_role == EMPLOYEE):
        subordinates = get_auth_team_ids()
        if (conditions):
            conditions += " and `tabAttendance`.employee IN (%(subordinates)s)" % {
                "subordinates": subordinates
            }
        else:
            conditions = " and `tabAttendance`.employee IN (%(subordinates)s)" % {
                "subordinates": subordinates
            }

    add_attendance(events, start, end, conditions=conditions)
    return events
def can_add_appraisal_score(employee):
    # only his own line manager can chanage manager's rating
    user_role = get_user_role()
    if (user_role == ADMINISTRATOR or user_role == HR_MANAGER):
        return True
    if (get_employee_code() == get_report_to(employee)):
        if (user_role == LINE_MANAGER and type(employee) != "undefined"
                and employee != get_employee_code()):
            return True
    else:
        return False
def getLateAttendenceEmployees(advances_list="",
                               AuthRole="",
                               Limit="",
                               employee_id=None):

    # If Its an Employee show him only his attendence
    user = get_user_role()
    if user == EMPLOYEE:
        userId = frappe.db.get_value("Employee",
                                     {"user_id": frappe.session.user},
                                     "employee")
        if userId is not None:
            advances_list += " and empatt.employee = " + '\'' + userId + '\''

    advances_list += " group by tabEmp.employee"

    advances_list += Limit

    select = """SELECT 
	    empatt.employee AS employeeID,
	    tabEmp.employee_name AS EmployeeName,
	    IF(tabEmp2.employee_name IS NULL,
		"-", tabEmp2.employee_name) As ReportingManager,
	    tabEmp.sub_department AS sub_department,
	    tabEmp.department AS Department,
	    count(empatt.late_arrival) as LateArrivalInstance,
    	sum(empatt.late_arrival) as TotalLateArrivalMinutes """

    employee_data = frappe.db.sql(select + """
	         FROM
    `tabAttendance` empatt
		LEFT JOIN 
	`tabRoster Status` eas ON eas.name = empatt.attendance_status
        INNER JOIN
    `tabEmployee` AS tabEmp ON empatt.employee = tabEmp.employee 
         LEFT JOIN
    `tabEmployee` AS tabEmp2 ON tabEmp.reports_to = tabEmp2.employee

WHERE
	eas.consider_penalty = 1
    AND empatt.late_arrival > 0
    AND empatt.docstatus = 1
	          """ + advances_list,
                                  as_dict=True)

    return employee_data, len(employee_data)
Exemple #6
0
def execute(filters=None):

    limit = str(PAGE_SIZE)
    if "page" in filters:
        limit = filters["page"]

    # validate if its an employee then user filter must be 'Me'

    if not (any(x in frappe.get_roles()
                for x in [HR_MANAGER, HR_USER, ADMINISTRATOR])):
        if get_user_role() == EMPLOYEE:
            if filters.get("user") != 'Me':
                filters["user"] = '******'

    if "is_excel" in filters and filters["is_excel"] == True:
        att_list = get_list(filters, False, True)
        return prepare_excel_data(att_list)
    else:
        att_list = get_list(filters)
        return prepare_report_data(att_list, limit)
Exemple #7
0
def get():
    args = get_form_params()

    try:
        args["filters"] = args["filters"] + frappe.get_doc(
            {
                "doctype": "Doctype List Rules",
                "doc": args["doctype"]
            }).get_filters()
    except Exception as err:
        frappe.log_error(err)

    # OVERRIDE START HERE
    # Show only custom reports which are defined in array
    role = get_user_role()
    report_list = get_config_by_name(
        'COMMON_REPORT_ALLOWED') + get_config_by_name('REPORTS_ALLOWED_LIST')
    if args['doctype'] == 'Report':
        if role is not ADMINISTRATOR:
            args['filters'].append(['Report', 'disabled', '=', 0])
            args['page_length'] = 500
    results = execute(**args)
    exec_arr = []
    if args['doctype'] == 'Report':
        if role is not ADMINISTRATOR:
            for result in results:
                if result.name in report_list:
                    exec_arr.append(result)
                elif 'total_count' in result:
                    exec_arr.append(result)
        else:
            exec_arr = results
    else:
        exec_arr = results
    # OVERRIDE END HERE

    data = compress(exec_arr, args=args)
    return data