Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Anand Doshi | 60666a2 | 2013-04-12 20:19:53 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 5 | import frappe, erpnext |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 6 | from frappe import _ |
Manas Solanki | aa17294 | 2018-06-13 16:47:41 +0530 | [diff] [blame] | 7 | from frappe.utils import formatdate, format_datetime, getdate, get_datetime, nowdate, flt, cstr |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 8 | from frappe.model.document import Document |
| 9 | from frappe.desk.form import assign_to |
Jamsheer | cc25eb0 | 2018-06-13 15:14:24 +0530 | [diff] [blame] | 10 | from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 11 | |
| 12 | class EmployeeBoardingController(Document): |
| 13 | ''' |
| 14 | Create the project and the task for the boarding process |
| 15 | Assign to the concerned person and roles as per the onboarding/separation template |
| 16 | ''' |
| 17 | def validate(self): |
| 18 | # remove the task if linked before submitting the form |
| 19 | if self.amended_from: |
| 20 | for activity in self.activities: |
| 21 | activity.task = '' |
| 22 | |
| 23 | def on_submit(self): |
| 24 | # create the project for the given employee onboarding |
Manas Solanki | 70899f5 | 2018-05-15 18:52:14 +0530 | [diff] [blame] | 25 | project_name = _(self.doctype) + " : " |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 26 | if self.doctype == "Employee Onboarding": |
Manas Solanki | 70899f5 | 2018-05-15 18:52:14 +0530 | [diff] [blame] | 27 | project_name += self.job_applicant |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 28 | else: |
Manas Solanki | 70899f5 | 2018-05-15 18:52:14 +0530 | [diff] [blame] | 29 | project_name += self.employee |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 30 | project = frappe.get_doc({ |
| 31 | "doctype": "Project", |
| 32 | "project_name": project_name, |
| 33 | "expected_start_date": self.date_of_joining if self.doctype == "Employee Onboarding" else self.resignation_letter_date, |
| 34 | "department": self.department, |
| 35 | "company": self.company |
| 36 | }).insert(ignore_permissions=True) |
| 37 | self.db_set("project", project.name) |
Shreya | 5c6ade4 | 2018-06-20 15:48:27 +0530 | [diff] [blame] | 38 | self.db_set("boarding_status", "Pending") |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 39 | |
| 40 | # create the task for the given project and assign to the concerned person |
| 41 | for activity in self.activities: |
| 42 | task = frappe.get_doc({ |
| 43 | "doctype": "Task", |
| 44 | "project": project.name, |
Manas Solanki | 094e184 | 2018-05-14 20:33:28 +0530 | [diff] [blame] | 45 | "subject": activity.activity_name + " : " + self.employee_name, |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 46 | "description": activity.description, |
| 47 | "department": self.department, |
| 48 | "company": self.company |
| 49 | }).insert(ignore_permissions=True) |
| 50 | activity.db_set("task", task.name) |
| 51 | users = [activity.user] if activity.user else [] |
| 52 | if activity.role: |
| 53 | user_list = frappe.db.sql_list('''select distinct(parent) from `tabHas Role` |
| 54 | where parenttype='User' and role=%s''', activity.role) |
| 55 | users = users + user_list |
| 56 | |
Anurag Mishra | add6bf3 | 2019-01-04 11:36:30 +0530 | [diff] [blame] | 57 | if "Administrator" in users: |
| 58 | users.remove("Administrator") |
| 59 | |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 60 | # assign the task the users |
| 61 | if users: |
| 62 | self.assign_task_to_users(task, set(users)) |
| 63 | |
| 64 | def assign_task_to_users(self, task, users): |
| 65 | for user in users: |
| 66 | args = { |
| 67 | 'assign_to' : user, |
| 68 | 'doctype' : task.doctype, |
| 69 | 'name' : task.name, |
| 70 | 'description' : task.description or task.subject, |
| 71 | } |
| 72 | assign_to.add(args) |
| 73 | |
| 74 | def on_cancel(self): |
| 75 | # delete task project |
| 76 | for task in frappe.get_all("Task", filters={"project": self.project}): |
Zarrar | 9a3b785 | 2018-07-11 14:34:55 +0530 | [diff] [blame] | 77 | frappe.delete_doc("Task", task.name, force=1) |
| 78 | frappe.delete_doc("Project", self.project, force=1) |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 79 | self.db_set('project', '') |
| 80 | for activity in self.activities: |
| 81 | activity.db_set("task", "") |
| 82 | |
| 83 | |
| 84 | @frappe.whitelist() |
| 85 | def get_onboarding_details(parent, parenttype): |
Nabin Hait | 01b2a65 | 2018-08-28 14:09:27 +0530 | [diff] [blame] | 86 | return frappe.get_all("Employee Boarding Activity", |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 87 | fields=["activity_name", "role", "user", "required_for_employee_creation", "description"], |
| 88 | filters={"parent": parent, "parenttype": parenttype}, |
| 89 | order_by= "idx") |
Anand Doshi | 60666a2 | 2013-04-12 20:19:53 +0530 | [diff] [blame] | 90 | |
Shreya | 5c6ade4 | 2018-06-20 15:48:27 +0530 | [diff] [blame] | 91 | @frappe.whitelist() |
| 92 | def get_boarding_status(project): |
| 93 | status = 'Pending' |
| 94 | if project: |
| 95 | doc = frappe.get_doc('Project', project) |
| 96 | if flt(doc.percent_complete) > 0.0 and flt(doc.percent_complete) < 100.0: |
| 97 | status = 'In Process' |
| 98 | elif flt(doc.percent_complete) == 100.0: |
| 99 | status = 'Completed' |
| 100 | return status |
| 101 | |
Anand Doshi | c280d06 | 2014-05-30 14:43:36 +0530 | [diff] [blame] | 102 | def set_employee_name(doc): |
| 103 | if doc.employee and not doc.employee_name: |
| 104 | doc.employee_name = frappe.db.get_value("Employee", doc.employee, "employee_name") |
Ranjith | fddfffd | 2018-05-05 13:27:26 +0530 | [diff] [blame] | 105 | |
Ranjith Kurungadam | e46639f | 2018-06-11 11:24:44 +0530 | [diff] [blame] | 106 | def update_employee(employee, details, date=None, cancel=False): |
| 107 | internal_work_history = {} |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 108 | for item in details: |
| 109 | fieldtype = frappe.get_meta("Employee").get_field(item.fieldname).fieldtype |
| 110 | new_data = item.new if not cancel else item.current |
| 111 | if fieldtype == "Date" and new_data: |
| 112 | new_data = getdate(new_data) |
| 113 | elif fieldtype =="Datetime" and new_data: |
| 114 | new_data = get_datetime(new_data) |
| 115 | setattr(employee, item.fieldname, new_data) |
Ranjith Kurungadam | e46639f | 2018-06-11 11:24:44 +0530 | [diff] [blame] | 116 | if item.fieldname in ["department", "designation", "branch"]: |
| 117 | internal_work_history[item.fieldname] = item.new |
| 118 | if internal_work_history and not cancel: |
| 119 | internal_work_history["from_date"] = date |
| 120 | employee.append("internal_work_history", internal_work_history) |
Manas Solanki | b698846 | 2018-05-10 18:07:20 +0530 | [diff] [blame] | 121 | return employee |
| 122 | |
Ranjith | fddfffd | 2018-05-05 13:27:26 +0530 | [diff] [blame] | 123 | @frappe.whitelist() |
| 124 | def get_employee_fields_label(): |
| 125 | fields = [] |
| 126 | for df in frappe.get_meta("Employee").get("fields"): |
Ranjith Kurungadam | c1030a3 | 2018-06-20 12:42:58 +0530 | [diff] [blame] | 127 | if df.fieldname in ["salutation", "user_id", "employee_number", "employment_type", |
| 128 | "holiday_list", "branch", "department", "designation", "grade", |
| 129 | "notice_number_of_days", "reports_to", "leave_policy", "company_email"]: |
Ranjith | fddfffd | 2018-05-05 13:27:26 +0530 | [diff] [blame] | 130 | fields.append({"value": df.fieldname, "label": df.label}) |
| 131 | return fields |
| 132 | |
| 133 | @frappe.whitelist() |
| 134 | def get_employee_field_property(employee, fieldname): |
| 135 | if employee and fieldname: |
| 136 | field = frappe.get_meta("Employee").get_field(fieldname) |
| 137 | value = frappe.db.get_value("Employee", employee, fieldname) |
| 138 | options = field.options |
| 139 | if field.fieldtype == "Date": |
| 140 | value = formatdate(value) |
| 141 | elif field.fieldtype == "Datetime": |
| 142 | value = format_datetime(value) |
| 143 | return { |
| 144 | "value" : value, |
| 145 | "datatype" : field.fieldtype, |
| 146 | "label" : field.label, |
| 147 | "options" : options |
| 148 | } |
| 149 | else: |
| 150 | return False |
| 151 | |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 152 | def validate_dates(doc, from_date, to_date): |
| 153 | date_of_joining, relieving_date = frappe.db.get_value("Employee", doc.employee, ["date_of_joining", "relieving_date"]) |
| 154 | if getdate(from_date) > getdate(to_date): |
| 155 | frappe.throw(_("To date can not be less than from date")) |
| 156 | elif getdate(from_date) > getdate(nowdate()): |
| 157 | frappe.throw(_("Future dates not allowed")) |
| 158 | elif date_of_joining and getdate(from_date) < getdate(date_of_joining): |
| 159 | frappe.throw(_("From date can not be less than employee's joining date")) |
| 160 | elif relieving_date and getdate(to_date) > getdate(relieving_date): |
| 161 | frappe.throw(_("To date can not greater than employee's relieving date")) |
| 162 | |
| 163 | def validate_overlap(doc, from_date, to_date, company = None): |
| 164 | query = """ |
| 165 | select name |
| 166 | from `tab{0}` |
| 167 | where name != %(name)s |
| 168 | """ |
| 169 | query += get_doc_condition(doc.doctype) |
| 170 | |
| 171 | if not doc.name: |
| 172 | # hack! if name is null, it could cause problems with != |
| 173 | doc.name = "New "+doc.doctype |
| 174 | |
| 175 | overlap_doc = frappe.db.sql(query.format(doc.doctype),{ |
Nabin Hait | d53c2c0 | 2018-07-30 20:16:48 +0530 | [diff] [blame] | 176 | "employee": doc.get("employee"), |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 177 | "from_date": from_date, |
| 178 | "to_date": to_date, |
| 179 | "name": doc.name, |
| 180 | "company": company |
| 181 | }, as_dict = 1) |
| 182 | |
| 183 | if overlap_doc: |
deepeshgarg007 | 78b273a | 2018-10-31 18:12:03 +0530 | [diff] [blame] | 184 | if doc.get("employee"): |
| 185 | exists_for = doc.employee |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 186 | if company: |
| 187 | exists_for = company |
| 188 | throw_overlap_error(doc, exists_for, overlap_doc[0].name, from_date, to_date) |
| 189 | |
| 190 | def get_doc_condition(doctype): |
| 191 | if doctype == "Compensatory Leave Request": |
| 192 | return "and employee = %(employee)s and docstatus < 2 \ |
| 193 | and (work_from_date between %(from_date)s and %(to_date)s \ |
| 194 | or work_end_date between %(from_date)s and %(to_date)s \ |
| 195 | or (work_from_date < %(from_date)s and work_end_date > %(to_date)s))" |
| 196 | elif doctype == "Leave Period": |
| 197 | return "and company = %(company)s and (from_date between %(from_date)s and %(to_date)s \ |
| 198 | or to_date between %(from_date)s and %(to_date)s \ |
| 199 | or (from_date < %(from_date)s and to_date > %(to_date)s))" |
| 200 | |
| 201 | def throw_overlap_error(doc, exists_for, overlap_doc, from_date, to_date): |
| 202 | msg = _("A {0} exists between {1} and {2} (").format(doc.doctype, |
| 203 | formatdate(from_date), formatdate(to_date)) \ |
| 204 | + """ <b><a href="#Form/{0}/{1}">{1}</a></b>""".format(doc.doctype, overlap_doc) \ |
| 205 | + _(") for {0}").format(exists_for) |
| 206 | frappe.throw(msg) |
| 207 | |
| 208 | def get_employee_leave_policy(employee): |
| 209 | leave_policy = frappe.db.get_value("Employee", employee, "leave_policy") |
| 210 | if not leave_policy: |
| 211 | employee_grade = frappe.db.get_value("Employee", employee, "grade") |
| 212 | if employee_grade: |
| 213 | leave_policy = frappe.db.get_value("Employee Grade", employee_grade, "default_leave_policy") |
| 214 | if not leave_policy: |
| 215 | frappe.throw(_("Employee {0} of grade {1} have no default leave policy").format(employee, employee_grade)) |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 216 | if leave_policy: |
| 217 | return frappe.get_doc("Leave Policy", leave_policy) |
Nabin Hait | 9c735e4 | 2018-07-30 10:58:49 +0530 | [diff] [blame] | 218 | else: |
| 219 | frappe.throw(_("Please set leave policy for employee {0} in Employee / Grade record").format(employee)) |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 220 | |
Ranjith | 5a8e642 | 2018-05-10 15:06:49 +0530 | [diff] [blame] | 221 | def validate_tax_declaration(declarations): |
| 222 | subcategories = [] |
| 223 | for declaration in declarations: |
| 224 | if declaration.exemption_sub_category in subcategories: |
| 225 | frappe.throw(_("More than one selection for {0} not \ |
| 226 | allowed").format(declaration.exemption_sub_category), frappe.ValidationError) |
| 227 | subcategories.append(declaration.exemption_sub_category) |
| 228 | max_amount = frappe.db.get_value("Employee Tax Exemption Sub Category", \ |
| 229 | declaration.exemption_sub_category, "max_amount") |
| 230 | if declaration.amount > max_amount: |
| 231 | frappe.throw(_("Max exemption amount for {0} is {1}").format(\ |
| 232 | declaration.exemption_sub_category, max_amount), frappe.ValidationError) |
rohitwaghchaure | 3f0c735 | 2018-05-14 20:47:35 +0530 | [diff] [blame] | 233 | |
Jamsheer | 0e2cc55 | 2018-05-08 11:48:25 +0530 | [diff] [blame] | 234 | def get_leave_period(from_date, to_date, company): |
| 235 | leave_period = frappe.db.sql(""" |
| 236 | select name, from_date, to_date |
| 237 | from `tabLeave Period` |
| 238 | where company=%(company)s and is_active=1 |
| 239 | and (from_date between %(from_date)s and %(to_date)s |
| 240 | or to_date between %(from_date)s and %(to_date)s |
| 241 | or (from_date < %(from_date)s and to_date > %(to_date)s)) |
| 242 | """, { |
| 243 | "from_date": from_date, |
| 244 | "to_date": to_date, |
| 245 | "company": company |
| 246 | }, as_dict=1) |
| 247 | |
| 248 | if leave_period: |
| 249 | return leave_period |
Ranjith | b485b1e | 2018-05-16 23:01:40 +0530 | [diff] [blame] | 250 | |
| 251 | def get_payroll_period(from_date, to_date, company): |
Jamsheer | cf414cc | 2018-05-22 14:22:42 +0530 | [diff] [blame] | 252 | payroll_period = frappe.db.sql("""select name, start_date, end_date from |
| 253 | `tabPayroll Period` |
| 254 | where start_date<=%s and end_date>= %s and company=%s""", (from_date, to_date, company), as_dict=1) |
Ranjith | b485b1e | 2018-05-16 23:01:40 +0530 | [diff] [blame] | 255 | return payroll_period[0] if payroll_period else None |
Ranjith Kurungadam | 375db61 | 2018-06-01 16:09:28 +0530 | [diff] [blame] | 256 | |
Ranjith Kurungadam | 375db61 | 2018-06-01 16:09:28 +0530 | [diff] [blame] | 257 | def allocate_earned_leaves(): |
| 258 | '''Allocate earned leaves to Employees''' |
| 259 | e_leave_types = frappe.get_all("Leave Type", |
| 260 | fields=["name", "max_leaves_allowed", "earned_leave_frequency", "rounding"], |
| 261 | filters={'is_earned_leave' : 1}) |
| 262 | today = getdate() |
Joyce Babu | 3d01213 | 2019-03-06 13:04:45 +0530 | [diff] [blame] | 263 | divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12} |
Ranjith Kurungadam | 375db61 | 2018-06-01 16:09:28 +0530 | [diff] [blame] | 264 | if e_leave_types: |
| 265 | for e_leave_type in e_leave_types: |
| 266 | leave_allocations = frappe.db.sql("""select name, employee, from_date, to_date from `tabLeave Allocation` where '{0}' |
| 267 | between from_date and to_date and docstatus=1 and leave_type='{1}'""" |
| 268 | .format(today, e_leave_type.name), as_dict=1) |
| 269 | for allocation in leave_allocations: |
| 270 | leave_policy = get_employee_leave_policy(allocation.employee) |
| 271 | if not leave_policy: |
| 272 | continue |
| 273 | if not e_leave_type.earned_leave_frequency == "Monthly": |
| 274 | if not check_frequency_hit(allocation.from_date, today, e_leave_type.earned_leave_frequency): |
| 275 | continue |
| 276 | annual_allocation = frappe.db.sql("""select annual_allocation from `tabLeave Policy Detail` |
| 277 | where parent=%s and leave_type=%s""", (leave_policy.name, e_leave_type.name)) |
| 278 | if annual_allocation and annual_allocation[0]: |
| 279 | earned_leaves = flt(annual_allocation[0][0]) / divide_by_frequency[e_leave_type.earned_leave_frequency] |
| 280 | if e_leave_type.rounding == "0.5": |
| 281 | earned_leaves = round(earned_leaves * 2) / 2 |
| 282 | else: |
| 283 | earned_leaves = round(earned_leaves) |
| 284 | |
| 285 | allocated_leaves = frappe.db.get_value('Leave Allocation', allocation.name, 'total_leaves_allocated') |
| 286 | new_allocation = flt(allocated_leaves) + flt(earned_leaves) |
| 287 | new_allocation = new_allocation if new_allocation <= e_leave_type.max_leaves_allowed else e_leave_type.max_leaves_allowed |
| 288 | frappe.db.set_value('Leave Allocation', allocation.name, 'total_leaves_allocated', new_allocation) |
| 289 | |
| 290 | def check_frequency_hit(from_date, to_date, frequency): |
| 291 | '''Return True if current date matches frequency''' |
| 292 | from_dt = get_datetime(from_date) |
| 293 | to_dt = get_datetime(to_date) |
| 294 | from dateutil import relativedelta |
| 295 | rd = relativedelta.relativedelta(to_dt, from_dt) |
| 296 | months = rd.months |
| 297 | if frequency == "Quarterly": |
| 298 | if not months % 3: |
| 299 | return True |
Joyce Babu | 3d01213 | 2019-03-06 13:04:45 +0530 | [diff] [blame] | 300 | elif frequency == "Half-Yearly": |
| 301 | if not months % 6: |
| 302 | return True |
Ranjith Kurungadam | 375db61 | 2018-06-01 16:09:28 +0530 | [diff] [blame] | 303 | elif frequency == "Yearly": |
| 304 | if not months % 12: |
| 305 | return True |
| 306 | return False |
Nabin Hait | 8c7af49 | 2018-06-04 11:23:36 +0530 | [diff] [blame] | 307 | |
Ranjith | 155ecc1 | 2018-05-30 13:37:15 +0530 | [diff] [blame] | 308 | def get_salary_assignment(employee, date): |
| 309 | assignment = frappe.db.sql(""" |
| 310 | select * from `tabSalary Structure Assignment` |
| 311 | where employee=%(employee)s |
| 312 | and docstatus = 1 |
Ranjith Kurungadam | b4ad3c3 | 2018-06-25 10:29:54 +0530 | [diff] [blame] | 313 | and %(on_date)s >= from_date order by from_date desc limit 1""", { |
Ranjith | 155ecc1 | 2018-05-30 13:37:15 +0530 | [diff] [blame] | 314 | 'employee': employee, |
| 315 | 'on_date': date, |
| 316 | }, as_dict=1) |
| 317 | return assignment[0] if assignment else None |
Ranjith | 793f8e8 | 2018-05-30 20:50:48 +0530 | [diff] [blame] | 318 | |
Jamsheer | 8d66f1e | 2018-06-12 11:30:59 +0530 | [diff] [blame] | 319 | def get_sal_slip_total_benefit_given(employee, payroll_period, component=False): |
| 320 | total_given_benefit_amount = 0 |
| 321 | query = """ |
| 322 | select sum(sd.amount) as 'total_amount' |
| 323 | from `tabSalary Slip` ss, `tabSalary Detail` sd |
| 324 | where ss.employee=%(employee)s |
| 325 | and ss.docstatus = 1 and ss.name = sd.parent |
| 326 | and sd.is_flexible_benefit = 1 and sd.parentfield = "earnings" |
| 327 | and sd.parenttype = "Salary Slip" |
| 328 | and (ss.start_date between %(start_date)s and %(end_date)s |
| 329 | or ss.end_date between %(start_date)s and %(end_date)s |
| 330 | or (ss.start_date < %(start_date)s and ss.end_date > %(end_date)s)) |
| 331 | """ |
| 332 | |
| 333 | if component: |
| 334 | query += "and sd.salary_component = %(component)s" |
| 335 | |
| 336 | sum_of_given_benefit = frappe.db.sql(query, { |
| 337 | 'employee': employee, |
| 338 | 'start_date': payroll_period.start_date, |
| 339 | 'end_date': payroll_period.end_date, |
| 340 | 'component': component |
| 341 | }, as_dict=True) |
| 342 | |
Rushabh Mehta | df23c7d | 2018-07-05 15:19:28 +0530 | [diff] [blame] | 343 | if sum_of_given_benefit and flt(sum_of_given_benefit[0].total_amount) > 0: |
Jamsheer | 8d66f1e | 2018-06-12 11:30:59 +0530 | [diff] [blame] | 344 | total_given_benefit_amount = sum_of_given_benefit[0].total_amount |
| 345 | return total_given_benefit_amount |
Jamsheer | cc25eb0 | 2018-06-13 15:14:24 +0530 | [diff] [blame] | 346 | |
| 347 | def get_holidays_for_employee(employee, start_date, end_date): |
| 348 | holiday_list = get_holiday_list_for_employee(employee) |
| 349 | holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday` |
| 350 | where |
| 351 | parent=%(holiday_list)s |
| 352 | and holiday_date >= %(start_date)s |
| 353 | and holiday_date <= %(end_date)s''', { |
| 354 | "holiday_list": holiday_list, |
| 355 | "start_date": start_date, |
| 356 | "end_date": end_date |
| 357 | }) |
| 358 | |
| 359 | holidays = [cstr(i) for i in holidays] |
| 360 | |
| 361 | return holidays |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 362 | |
| 363 | @erpnext.allow_regional |
| 364 | def calculate_annual_eligible_hra_exemption(doc): |
| 365 | # Don't delete this method, used for localization |
| 366 | # Indian HRA Exemption Calculation |
| 367 | return {} |
| 368 | |
| 369 | @erpnext.allow_regional |
| 370 | def calculate_hra_exemption_for_period(doc): |
| 371 | # Don't delete this method, used for localization |
| 372 | # Indian HRA Exemption Calculation |
| 373 | return {} |
Jamsheer | 55a2f4d | 2018-06-20 11:04:21 +0530 | [diff] [blame] | 374 | |
| 375 | def get_previous_claimed_amount(employee, payroll_period, non_pro_rata=False, component=False): |
| 376 | total_claimed_amount = 0 |
| 377 | query = """ |
| 378 | select sum(claimed_amount) as 'total_amount' |
| 379 | from `tabEmployee Benefit Claim` |
| 380 | where employee=%(employee)s |
| 381 | and docstatus = 1 |
| 382 | and (claim_date between %(start_date)s and %(end_date)s) |
| 383 | """ |
| 384 | if non_pro_rata: |
| 385 | query += "and pay_against_benefit_claim = 1" |
| 386 | if component: |
| 387 | query += "and earning_component = %(component)s" |
| 388 | |
| 389 | sum_of_claimed_amount = frappe.db.sql(query, { |
| 390 | 'employee': employee, |
| 391 | 'start_date': payroll_period.start_date, |
| 392 | 'end_date': payroll_period.end_date, |
| 393 | 'component': component |
| 394 | }, as_dict=True) |
Rushabh Mehta | df23c7d | 2018-07-05 15:19:28 +0530 | [diff] [blame] | 395 | if sum_of_claimed_amount and flt(sum_of_claimed_amount[0].total_amount) > 0: |
Jamsheer | 55a2f4d | 2018-06-20 11:04:21 +0530 | [diff] [blame] | 396 | total_claimed_amount = sum_of_claimed_amount[0].total_amount |
| 397 | return total_claimed_amount |