Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add break hours for calculating actual working hours #29

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions hr_addon/hr_addon/api/utils.py
Expand Up @@ -30,7 +30,7 @@ def get_employee_default_work_hour(employee,adate):
# AND YEAR(w.valid_from) = CAST(('2022-01-01') as INT) AND YEAR(w.valid_to) = CAST(('2022-12-30') as INT);
target_work_hours= frappe.db.sql(
"""
SELECT w.name,w.employee,w.valid_from,w.valid_to,d.day,d.hours FROM `tabWeekly Working Hours` w
SELECT w.name,w.employee,w.valid_from,w.valid_to,d.day,d.hours,d.break_minutes FROM `tabWeekly Working Hours` w
LEFT JOIN `tabDaily Hours Detail` d ON w.name = d.parent
WHERE w.employee='%s' AND d.day = DAYNAME('%s')
"""%(employee,adate), as_dict=1
Expand Down Expand Up @@ -79,9 +79,11 @@ def view_actual_employee_log(aemployee, adate):
break_hours += float(str(wh))

# create list
employee_default_work_hour = get_employee_default_work_hour(aemployee,adate)[0]
new_workday = []
new_workday.append({
"thour": get_employee_default_work_hour(aemployee,adate)[0].hours,
"thour": employee_default_work_hour.hours,
"break_minutes": employee_default_work_hour.break_minutes,
"ahour": hours_worked,
"nbreak": 0,
"attendance": weekly_day_hour[0].attendance if len(weekly_day_hour) > 0 else "",
Expand Down Expand Up @@ -113,9 +115,10 @@ def get_actual_employee_log_bulk(aemployee, adate):

# check empty or none
if((weekly_day_hour is None) or (weekly_day_hour == [])):

employee_default_work_hour = get_employee_default_work_hour(aemployee,adate)[0]
new_workday.append({
"thour": get_employee_default_work_hour(aemployee,adate)[0].hours,
"thour": employee_default_work_hour.hours,
"break_minutes": employee_default_work_hour.break_minutes,
"ahour": 0,
"nbreak": 0,
"attendance": view_employee_attendance[0].name if len(view_employee_attendance) > 0 else "",
Expand Down Expand Up @@ -150,9 +153,10 @@ def get_actual_employee_log_bulk(aemployee, adate):
wh = time_diff_in_seconds(clockin_list[i+1],clockout_list[i])
break_hours += float(str(wh))


employee_default_work_hour = get_employee_default_work_hour(aemployee,adate)[0]
new_workday.append({
"thour": get_employee_default_work_hour(aemployee,adate)[0].hours,
"thour": employee_default_work_hour.hours,
"break_minutes": employee_default_work_hour.break_minutes,
"ahour": hours_worked,
"nbreak": 0,
"attendance": weekly_day_hour[0].attendance if len(weekly_day_hour) > 0 else "",
Expand Down
Expand Up @@ -8,7 +8,8 @@
"field_order": [
"day",
"hours",
"hour_time"
"hour_time",
"break_minutes"
],
"fields": [
{
Expand All @@ -30,11 +31,17 @@
"fieldname": "hour_time",
"fieldtype": "Data",
"label": "Hour Time"
},
{
"fieldname": "break_minutes",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Break Minutes"
}
],
"istable": 1,
"links": [],
"modified": "2022-05-06 01:51:19.780122",
"modified": "2023-05-08 11:33:55.822930",
"modified_by": "Administrator",
"module": "HR Addon",
"name": "Daily Hours Detail",
Expand Down
2 changes: 2 additions & 0 deletions hr_addon/hr_addon/doctype/workday/workday.js
Expand Up @@ -50,7 +50,9 @@ frappe.ui.form.on('Workday', {
frm.set_value("total_work_seconds",(alog[0].ahour).toFixed(2));
frm.set_value("total_break_seconds",(alog[0].bhour).toFixed(2));
frm.set_value("target_hours",alog[0].thour);
frm.set_value("actual_working_hours",frm.doc.hours_worked - frm.doc.break_hours);
frm.set_value("total_target_seconds",(alog[0].thour*(60*60)));
frm.set_value("expected_break_hours",(alog[0].break_minutes/60));
let ec = alog[0].items
frm.set_value("first_checkin",ec[0].time);
frm.set_value("last_checkout",ec[ec.length-1].time);
Expand Down
16 changes: 15 additions & 1 deletion hr_addon/hr_addon/doctype/workday/workday.json
Expand Up @@ -17,7 +17,9 @@
"section_break_9",
"target_hours",
"hours_worked",
"actual_working_hours",
"column_break_5",
"expected_break_hours",
"break_hours",
"number_of_breaks",
"section_break_14",
Expand Down Expand Up @@ -148,10 +150,22 @@
"hidden": 1,
"label": " Target In Seconds",
"read_only": 1
},
{
"fieldname": "actual_working_hours",
"fieldtype": "Float",
"label": "Actual Working Hours",
"read_only": 1
},
{
"fieldname": "expected_break_hours",
"fieldtype": "Float",
"label": "Expected Break Hours",
"read_only": 1
}
],
"links": [],
"modified": "2022-06-02 16:11:55.614340",
"modified": "2023-05-08 14:20:09.368889",
"modified_by": "Administrator",
"module": "HR Addon",
"name": "Workday",
Expand Down
2 changes: 2 additions & 0 deletions hr_addon/hr_addon/doctype/workday/workday.py
Expand Up @@ -41,8 +41,10 @@ def process_bulk_workday(data):
'attendance':single[0]["attendance"],
'hours_worked':"{:.2f}".format(single[0]["ahour"]/(60*60)),
'break_hours': "{:.2f}".format(single[0]["bhour"]/(60*60)),
'expected_break_hours': "{:.2f}".format(single[0]["break_minutes"]/(60)),
'total_work_seconds':single[0]["ahour"],
'total_break_seconds':single[0]["bhour"],
'actual_working_hours': (single[0]["ahour"] - single[0]["bhour"])/(60*60)
}
workday = frappe.get_doc(doc_dict).insert()
target_hours = single[0]["thour"]
Expand Down
33 changes: 32 additions & 1 deletion hr_addon/hr_addon/report/work_hour_report/work_hour_report.js
Expand Up @@ -71,12 +71,43 @@ frappe.query_reports["Work Hour Report"] = {
}

}

if (column.fieldname == "actual_working_seconds" ) {
if(value < 0) {
value = "<span style='color:red'>" + hitt(value) + "</span>";
}
else if(value > 0){
value = "<span style='color:green'>" + hitt(value) + "</span>";
}
else{
value = hitt(value);
}

}

if (column.fieldname == "total_target_seconds" ) {
value = hitt(value);
}
if (column.fieldname == "expected_break_hours" ) {
value = hitt(value);
}

if (column.fieldname == "diff_log" ) {
if(value < 0) {
value = "<span style='color:#FF8C00'>" + hitt(value,true) + "</span>";

}
else if(value > 0){
value = "<span style='color:blue'>" + hitt(value,true) + "</span>";
}
else{
value = hitt(value,true);
}


}
if (column.fieldname == "diff_log" ) {

if (column.fieldname == "actual_diff_log" ) {
if(value < 0) {
value = "<span style='color:#FF8C00'>" + hitt(value,true) + "</span>";

Expand Down
Expand Up @@ -27,8 +27,11 @@ def execute(filters=None):
{'fieldname':'status','label':'Status', "width": 80},
{'fieldname':'total_work_seconds','label':_('Work Hours'), "width": 110, },
{'fieldname':'total_break_seconds','label':_('Break Hours'), "width": 110, },
{'fieldname':'actual_working_seconds','label':_('Actual Working Hours'), "width": 110, },
{'fieldname':'total_target_seconds','label':'Target Seconds','width':80},
{'fieldname':'diff_log','label':'Diff','width':90},
{'fieldname':'expected_break_hours','label':'Expected Break Hours','width':80},
{'fieldname':'diff_log','label':'Diff (Work Hours - Target Seconds)','width':90},
{'fieldname':'actual_diff_log','label':'Diff (Actual Working Hours - Target Seconds)','width':90},
{'fieldname':'first_in','label':'First Checkin','width':100},
{'fieldname':'last_out','label':'Last Checkout','width':100},
{'fieldname':'attendance','label':'Attendance','width': 160},
Expand All @@ -37,7 +40,9 @@ def execute(filters=None):
work_data = frappe.db.sql(
"""
SELECT name,log_date,employee,attendance ,status,total_work_seconds,total_break_seconds,
actual_working_hours*60*60 actual_working_seconds, expected_break_hours*60*60 expected_break_hours,
target_hours, total_target_seconds, (total_work_seconds - total_target_seconds) as diff_log,
(actual_working_hours*60*60 - total_target_seconds) as actual_diff_log,
TIME(first_checkin) as first_in,TIME(last_checkout) as last_out
FROM `tabWorkday`
WHERE docstatus < 2 %s %s
Expand Down