feat: timesheet Employee Summary Report

This commit is contained in:
Anurag Mishra 2019-03-11 10:37:28 +05:30
parent 7e67a400cd
commit e86ac3c8d4
5 changed files with 183 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Employee Billing Summary"] = {
"filters": [
{
fieldname: "employee",
label: __("Employee"),
fieldtype: "Link",
options: "Employee",
},
{
fieldname:"from_date",
label: __("From Date"),
fieldtype: "Date",
default: frappe.datetime.get_today()
},
{
fieldname:"to_date",
label: __("To Date"),
fieldtype: "Date",
default: frappe.datetime.add_days(frappe.datetime.get_today(), 30)
},
]
}

View File

@ -0,0 +1,36 @@
{
"add_total_row": 0,
"creation": "2019-03-08 15:08:19.929728",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2019-03-08 15:08:19.929728",
"modified_by": "Administrator",
"module": "Projects",
"name": "Employee Billing Summary",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Timesheet",
"report_name": "Employee Billing Summary",
"report_type": "Script Report",
"roles": [
{
"role": "Projects User"
},
{
"role": "HR User"
},
{
"role": "Manufacturing User"
},
{
"role": "Employee"
},
{
"role": "Accounts User"
}
]
}

View File

@ -0,0 +1,119 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import time_diff_in_hours
def execute(filters=None):
filters = frappe._dict(filters or {})
print(filters)
columns = get_columns()
data = get_data(filters)
return columns, data
def get_columns():
return [
{
"label": _("Employee ID"),
"fieldtype": "Link",
"fieldname": "employee",
"options": "Employee",
"width": 300
},
{
"label": _("Employee Name"),
"fieldtype": "data",
"fieldname": "employee_name",
"hidden": 1,
"width": 200
},
{
"label": _("Timesheet"),
"fieldtype": "Link",
"fieldname": "timesheet",
"options": "Timesheet",
"width": 150
},
{
"label": _("Date"),
"fieldtype": "Date",
"fieldname": "date",
"width": 150
},
{
"label": _("Total Billable Hours"),
"fieldtype": "Int",
"fieldname": "total_billable_hours",
"width": 50
},
{
"label": _("Total Hours"),
"fieldtype": "Int",
"fieldname": "total_hours",
"width": 50
},
{
"label": _("Amount"),
"fieldtype": "Int",
"fieldname": "amount",
"width": 50
}
]
def get_data(filters):
data = []
if "employee" in filters:
record= frappe.db.sql('''SELECT
employee, employee_name, name, total_billable_hours, total_hours, total_billable_amount
FROM
`tabTimesheet`
WHERE
employee = %s and (start_date <= %s and end_date >= %s)''',(filters.employee, filters.to_date, filters.from_date),
as_dict=1
)
for entries in record:
timesheet_details = frappe.get_all(
"Timesheet Detail",
filters={"parent": entries.name},
fields=["*"]
)
total_hours = 0
total_billable_hours = 0
print("-------------------------------------------->>>>>>>")
for time in timesheet_details:
time_start = time.from_time
time_end = frappe.utils.add_to_date(time.from_time, hours=time.hours)
from_date = frappe.utils.get_datetime(filters.from_date)
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))
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))
elif time_start >= from_date and time_end <= to_date:
total_hours = entries.total_hours
print("case 3 all set", entries.name)
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
}
data.append(row)
return data

1
erpnext/public/node_modules Symbolic link
View File

@ -0,0 +1 @@
/Users/anuragmishra/test/apps/erpnext/node_modules