Commonify code
diff --git a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js
index e6e6746..b792e81 100644
--- a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js
+++ b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.js
@@ -22,6 +22,5 @@
fieldtype: "Date",
default: frappe.datetime.add_days(frappe.datetime.get_today(), 30)
},
-
]
}
diff --git a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.py b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.py
index 47323ef..491fa76 100644
--- a/erpnext/projects/report/employee_billing_summary/employee_billing_summary.py
+++ b/erpnext/projects/report/employee_billing_summary/employee_billing_summary.py
@@ -8,8 +8,6 @@
def execute(filters=None):
filters = frappe._dict(filters or {})
- print(filters)
-
columns = get_columns()
data = get_data(filters)
@@ -85,7 +83,8 @@
total_hours = 0
total_billable_hours = 0
- print("-------------------------------------------->>>>>>>")
+ total_amount = 0
+
for time in timesheet_details:
time_start = time.from_time
time_end = frappe.utils.add_to_date(time.from_time, hours=time.hours)
@@ -94,26 +93,28 @@
to_date = frappe.utils.get_datetime(filters.to_date)
if time_start <= from_date and time_end <= to_date:
- total_hours += abs(time_diff_in_hours(time_end, from_date))
- print(from_date, time_end)
- print("case 1", entries.name,time_diff_in_hours(time_end, from_date))
+ total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, time_end, from_date, total_hours, total_billable_hours, total_amount)
elif time_start >= from_date and time_end >= to_date:
- total_hours += abs(time_diff_in_hours(to_date, time_start))
- print(time_start, to_date)
- print("case 2", entries.name,time_diff_in_hours(to_date, time_start))
+ total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, to_date, time_start, total_hours, total_billable_hours, total_amount)
elif time_start >= from_date and time_end <= to_date:
- total_hours = entries.total_hours
- print("case 3 all set", entries.name)
+ total_hours, total_billable_hours, total_amount = get_billable_and_total_hours(time, time_end, time_start, total_hours, total_billable_hours, total_amount)
- print(total_hours)
- print("-------------------------------------------->>>>>>>")
row = {
"employee": entries.employee,
"employee_name": entries.employee_name,
"timesheet": entries.name,
- "total_billable_hours": entries.total_billable_hours,
- "total_hours": entries.total_hours,
- "amount": 1
+ "total_billable_hours": total_billable_hours,
+ "total_hours": total_hours,
+ "amount": total_amount
}
+
data.append(row)
- return data
\ No newline at end of file
+ return data
+
+def get_billable_and_total_hours(time, end, start, total_hours, total_billable_hours, total_amount):
+ total_hours += abs(time_diff_in_hours(end, start))
+ if time.billable:
+ total_billable_hours += abs(time_diff_in_hours(end, start))
+ total_amount += total_billable_hours * time.billing_rate
+
+ return total_hours, total_billable_hours, total_amount