blob: cd125108c613ee009ea68a7075788dd19fcc98dc [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
Anand Doshi60666a22013-04-12 20:19:53 +05303
4from __future__ import unicode_literals
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +05305import frappe, erpnext
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306from frappe import _
Mangesh-Khairnarf281f002019-08-05 14:47:02 +05307from frappe.utils import formatdate, format_datetime, getdate, get_datetime, nowdate, flt, cstr, add_days, today
Manas Solankib6988462018-05-10 18:07:20 +05308from frappe.model.document import Document
9from frappe.desk.form import assign_to
Jamsheercc25eb02018-06-13 15:14:24 +053010from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
Manas Solankib6988462018-05-10 18:07:20 +053011
Nabin Hait58ee6c12020-04-26 17:45:57 +053012class DuplicateDeclarationError(frappe.ValidationError): pass
13
Manas Solankib6988462018-05-10 18:07:20 +053014class EmployeeBoardingController(Document):
15 '''
16 Create the project and the task for the boarding process
17 Assign to the concerned person and roles as per the onboarding/separation template
18 '''
19 def validate(self):
20 # remove the task if linked before submitting the form
21 if self.amended_from:
22 for activity in self.activities:
23 activity.task = ''
24
25 def on_submit(self):
26 # create the project for the given employee onboarding
Manas Solanki70899f52018-05-15 18:52:14 +053027 project_name = _(self.doctype) + " : "
Manas Solankib6988462018-05-10 18:07:20 +053028 if self.doctype == "Employee Onboarding":
Manas Solanki70899f52018-05-15 18:52:14 +053029 project_name += self.job_applicant
Manas Solankib6988462018-05-10 18:07:20 +053030 else:
Manas Solanki70899f52018-05-15 18:52:14 +053031 project_name += self.employee
Manas Solankib6988462018-05-10 18:07:20 +053032 project = frappe.get_doc({
33 "doctype": "Project",
34 "project_name": project_name,
35 "expected_start_date": self.date_of_joining if self.doctype == "Employee Onboarding" else self.resignation_letter_date,
36 "department": self.department,
37 "company": self.company
38 }).insert(ignore_permissions=True)
39 self.db_set("project", project.name)
Shreya5c6ade42018-06-20 15:48:27 +053040 self.db_set("boarding_status", "Pending")
Mangesh-Khairnar06a0afa2019-08-05 10:07:05 +053041 self.reload()
42 self.create_task_and_notify_user()
Manas Solankib6988462018-05-10 18:07:20 +053043
Mangesh-Khairnar06a0afa2019-08-05 10:07:05 +053044 def create_task_and_notify_user(self):
Manas Solankib6988462018-05-10 18:07:20 +053045 # create the task for the given project and assign to the concerned person
46 for activity in self.activities:
Mangesh-Khairnar06a0afa2019-08-05 10:07:05 +053047 if activity.task:
48 continue
49
Manas Solankib6988462018-05-10 18:07:20 +053050 task = frappe.get_doc({
51 "doctype": "Task",
Mangesh-Khairnar06a0afa2019-08-05 10:07:05 +053052 "project": self.project,
Manas Solanki094e1842018-05-14 20:33:28 +053053 "subject": activity.activity_name + " : " + self.employee_name,
Manas Solankib6988462018-05-10 18:07:20 +053054 "description": activity.description,
55 "department": self.department,
Suraj Shettyc90364f2019-04-12 14:12:03 +053056 "company": self.company,
57 "task_weight": activity.task_weight
Manas Solankib6988462018-05-10 18:07:20 +053058 }).insert(ignore_permissions=True)
59 activity.db_set("task", task.name)
60 users = [activity.user] if activity.user else []
61 if activity.role:
62 user_list = frappe.db.sql_list('''select distinct(parent) from `tabHas Role`
63 where parenttype='User' and role=%s''', activity.role)
64 users = users + user_list
65
Anurag Mishraadd6bf32019-01-04 11:36:30 +053066 if "Administrator" in users:
67 users.remove("Administrator")
68
Manas Solankib6988462018-05-10 18:07:20 +053069 # assign the task the users
70 if users:
71 self.assign_task_to_users(task, set(users))
72
73 def assign_task_to_users(self, task, users):
74 for user in users:
75 args = {
76 'assign_to' : user,
77 'doctype' : task.doctype,
78 'name' : task.name,
79 'description' : task.description or task.subject,
Mangesh-Khairnar06a0afa2019-08-05 10:07:05 +053080 'notify': self.notify_users_by_email
Manas Solankib6988462018-05-10 18:07:20 +053081 }
82 assign_to.add(args)
83
84 def on_cancel(self):
85 # delete task project
86 for task in frappe.get_all("Task", filters={"project": self.project}):
Zarrar9a3b7852018-07-11 14:34:55 +053087 frappe.delete_doc("Task", task.name, force=1)
88 frappe.delete_doc("Project", self.project, force=1)
Manas Solankib6988462018-05-10 18:07:20 +053089 self.db_set('project', '')
90 for activity in self.activities:
91 activity.db_set("task", "")
92
93
94@frappe.whitelist()
95def get_onboarding_details(parent, parenttype):
Nabin Hait01b2a652018-08-28 14:09:27 +053096 return frappe.get_all("Employee Boarding Activity",
Himanshu4cb1a1e2019-06-05 10:26:01 +053097 fields=["activity_name", "role", "user", "required_for_employee_creation", "description", "task_weight"],
Manas Solankib6988462018-05-10 18:07:20 +053098 filters={"parent": parent, "parenttype": parenttype},
99 order_by= "idx")
Anand Doshi60666a22013-04-12 20:19:53 +0530100
Shreya5c6ade42018-06-20 15:48:27 +0530101@frappe.whitelist()
102def get_boarding_status(project):
103 status = 'Pending'
104 if project:
105 doc = frappe.get_doc('Project', project)
106 if flt(doc.percent_complete) > 0.0 and flt(doc.percent_complete) < 100.0:
107 status = 'In Process'
108 elif flt(doc.percent_complete) == 100.0:
109 status = 'Completed'
110 return status
111
Anand Doshic280d062014-05-30 14:43:36 +0530112def set_employee_name(doc):
113 if doc.employee and not doc.employee_name:
114 doc.employee_name = frappe.db.get_value("Employee", doc.employee, "employee_name")
Ranjithfddfffd2018-05-05 13:27:26 +0530115
Ranjith Kurungadame46639f2018-06-11 11:24:44 +0530116def update_employee(employee, details, date=None, cancel=False):
117 internal_work_history = {}
Manas Solankib6988462018-05-10 18:07:20 +0530118 for item in details:
119 fieldtype = frappe.get_meta("Employee").get_field(item.fieldname).fieldtype
120 new_data = item.new if not cancel else item.current
121 if fieldtype == "Date" and new_data:
122 new_data = getdate(new_data)
123 elif fieldtype =="Datetime" and new_data:
124 new_data = get_datetime(new_data)
125 setattr(employee, item.fieldname, new_data)
Ranjith Kurungadame46639f2018-06-11 11:24:44 +0530126 if item.fieldname in ["department", "designation", "branch"]:
127 internal_work_history[item.fieldname] = item.new
128 if internal_work_history and not cancel:
129 internal_work_history["from_date"] = date
130 employee.append("internal_work_history", internal_work_history)
Manas Solankib6988462018-05-10 18:07:20 +0530131 return employee
132
Ranjithfddfffd2018-05-05 13:27:26 +0530133@frappe.whitelist()
134def get_employee_fields_label():
135 fields = []
136 for df in frappe.get_meta("Employee").get("fields"):
Ranjith Kurungadamc1030a32018-06-20 12:42:58 +0530137 if df.fieldname in ["salutation", "user_id", "employee_number", "employment_type",
Nabin Hait6b9d64c2019-05-16 11:23:04 +0530138 "holiday_list", "branch", "department", "designation", "grade",
139 "notice_number_of_days", "reports_to", "leave_policy", "company_email"]:
140 fields.append({"value": df.fieldname, "label": df.label})
Ranjithfddfffd2018-05-05 13:27:26 +0530141 return fields
142
143@frappe.whitelist()
144def get_employee_field_property(employee, fieldname):
145 if employee and fieldname:
146 field = frappe.get_meta("Employee").get_field(fieldname)
147 value = frappe.db.get_value("Employee", employee, fieldname)
148 options = field.options
149 if field.fieldtype == "Date":
150 value = formatdate(value)
151 elif field.fieldtype == "Datetime":
152 value = format_datetime(value)
153 return {
154 "value" : value,
155 "datatype" : field.fieldtype,
156 "label" : field.label,
157 "options" : options
158 }
159 else:
160 return False
161
Jamsheer0e2cc552018-05-08 11:48:25 +0530162def validate_dates(doc, from_date, to_date):
163 date_of_joining, relieving_date = frappe.db.get_value("Employee", doc.employee, ["date_of_joining", "relieving_date"])
164 if getdate(from_date) > getdate(to_date):
165 frappe.throw(_("To date can not be less than from date"))
166 elif getdate(from_date) > getdate(nowdate()):
167 frappe.throw(_("Future dates not allowed"))
168 elif date_of_joining and getdate(from_date) < getdate(date_of_joining):
169 frappe.throw(_("From date can not be less than employee's joining date"))
170 elif relieving_date and getdate(to_date) > getdate(relieving_date):
171 frappe.throw(_("To date can not greater than employee's relieving date"))
172
173def validate_overlap(doc, from_date, to_date, company = None):
174 query = """
175 select name
176 from `tab{0}`
177 where name != %(name)s
178 """
179 query += get_doc_condition(doc.doctype)
180
181 if not doc.name:
182 # hack! if name is null, it could cause problems with !=
183 doc.name = "New "+doc.doctype
184
185 overlap_doc = frappe.db.sql(query.format(doc.doctype),{
Nabin Haitd53c2c02018-07-30 20:16:48 +0530186 "employee": doc.get("employee"),
Jamsheer0e2cc552018-05-08 11:48:25 +0530187 "from_date": from_date,
188 "to_date": to_date,
189 "name": doc.name,
190 "company": company
191 }, as_dict = 1)
192
193 if overlap_doc:
deepeshgarg00778b273a2018-10-31 18:12:03 +0530194 if doc.get("employee"):
195 exists_for = doc.employee
Jamsheer0e2cc552018-05-08 11:48:25 +0530196 if company:
197 exists_for = company
198 throw_overlap_error(doc, exists_for, overlap_doc[0].name, from_date, to_date)
199
200def get_doc_condition(doctype):
201 if doctype == "Compensatory Leave Request":
202 return "and employee = %(employee)s and docstatus < 2 \
203 and (work_from_date between %(from_date)s and %(to_date)s \
204 or work_end_date between %(from_date)s and %(to_date)s \
205 or (work_from_date < %(from_date)s and work_end_date > %(to_date)s))"
206 elif doctype == "Leave Period":
207 return "and company = %(company)s and (from_date between %(from_date)s and %(to_date)s \
208 or to_date between %(from_date)s and %(to_date)s \
209 or (from_date < %(from_date)s and to_date > %(to_date)s))"
210
211def throw_overlap_error(doc, exists_for, overlap_doc, from_date, to_date):
212 msg = _("A {0} exists between {1} and {2} (").format(doc.doctype,
213 formatdate(from_date), formatdate(to_date)) \
214 + """ <b><a href="#Form/{0}/{1}">{1}</a></b>""".format(doc.doctype, overlap_doc) \
215 + _(") for {0}").format(exists_for)
216 frappe.throw(msg)
217
218def get_employee_leave_policy(employee):
219 leave_policy = frappe.db.get_value("Employee", employee, "leave_policy")
220 if not leave_policy:
221 employee_grade = frappe.db.get_value("Employee", employee, "grade")
222 if employee_grade:
223 leave_policy = frappe.db.get_value("Employee Grade", employee_grade, "default_leave_policy")
224 if not leave_policy:
225 frappe.throw(_("Employee {0} of grade {1} have no default leave policy").format(employee, employee_grade))
Jamsheer0e2cc552018-05-08 11:48:25 +0530226 if leave_policy:
227 return frappe.get_doc("Leave Policy", leave_policy)
Nabin Hait9c735e42018-07-30 10:58:49 +0530228 else:
229 frappe.throw(_("Please set leave policy for employee {0} in Employee / Grade record").format(employee))
Jamsheer0e2cc552018-05-08 11:48:25 +0530230
Nabin Hait58ee6c12020-04-26 17:45:57 +0530231def validate_duplicate_exemption_for_payroll_period(doctype, docname, payroll_period, employee):
232 existing_record = frappe.db.exists(doctype, {
233 "payroll_period": payroll_period,
234 "employee": employee,
235 'docstatus': ['<', 2],
236 'name': ['!=', docname]
237 })
238 if existing_record:
239 frappe.throw(_("{0} already exists for employee {1} and period {2}")
240 .format(doctype, employee, payroll_period), DuplicateDeclarationError)
241
Ranjith5a8e6422018-05-10 15:06:49 +0530242def validate_tax_declaration(declarations):
243 subcategories = []
Nabin Hait04e7bf42019-04-25 18:44:10 +0530244 for d in declarations:
245 if d.exemption_sub_category in subcategories:
246 frappe.throw(_("More than one selection for {0} not allowed").format(d.exemption_sub_category))
247 subcategories.append(d.exemption_sub_category)
248
249def get_total_exemption_amount(declarations):
Nabin Hait04e7bf42019-04-25 18:44:10 +0530250 exemptions = frappe._dict()
251 for d in declarations:
252 exemptions.setdefault(d.exemption_category, frappe._dict())
253 category_max_amount = exemptions.get(d.exemption_category).max_amount
254 if not category_max_amount:
255 category_max_amount = frappe.db.get_value("Employee Tax Exemption Category", d.exemption_category, "max_amount")
256 exemptions.get(d.exemption_category).max_amount = category_max_amount
257 sub_category_exemption_amount = d.max_amount \
258 if (d.max_amount and flt(d.amount) > flt(d.max_amount)) else d.amount
259
260 exemptions.get(d.exemption_category).setdefault("total_exemption_amount", 0.0)
261 exemptions.get(d.exemption_category).total_exemption_amount += flt(sub_category_exemption_amount)
262
263 if category_max_amount and exemptions.get(d.exemption_category).total_exemption_amount > category_max_amount:
264 exemptions.get(d.exemption_category).total_exemption_amount = category_max_amount
265
266 total_exemption_amount = sum([flt(d.total_exemption_amount) for d in exemptions.values()])
267 return total_exemption_amount
rohitwaghchaure3f0c7352018-05-14 20:47:35 +0530268
Jamsheer0e2cc552018-05-08 11:48:25 +0530269def get_leave_period(from_date, to_date, company):
270 leave_period = frappe.db.sql("""
271 select name, from_date, to_date
272 from `tabLeave Period`
273 where company=%(company)s and is_active=1
274 and (from_date between %(from_date)s and %(to_date)s
275 or to_date between %(from_date)s and %(to_date)s
276 or (from_date < %(from_date)s and to_date > %(to_date)s))
277 """, {
278 "from_date": from_date,
279 "to_date": to_date,
280 "company": company
281 }, as_dict=1)
282
283 if leave_period:
284 return leave_period
Ranjithb485b1e2018-05-16 23:01:40 +0530285
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530286def generate_leave_encashment():
287 ''' Generates a draft leave encashment on allocation expiry '''
288 from erpnext.hr.doctype.leave_encashment.leave_encashment import create_leave_encashment
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530289
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530290 if frappe.db.get_single_value('HR Settings', 'auto_leave_encashment'):
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530291 leave_type = frappe.get_all('Leave Type', filters={'allow_encashment': 1}, fields=['name'])
292 leave_type=[l['name'] for l in leave_type]
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530293
294 leave_allocation = frappe.get_all("Leave Allocation", filters={
295 'to_date': add_days(today(), -1),
296 'leave_type': ('in', leave_type)
297 }, fields=['employee', 'leave_period', 'leave_type', 'to_date', 'total_leaves_allocated', 'new_leaves_allocated'])
298
299 create_leave_encashment(leave_allocation=leave_allocation)
300
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530301def allocate_earned_leaves():
302 '''Allocate earned leaves to Employees'''
303 e_leave_types = frappe.get_all("Leave Type",
304 fields=["name", "max_leaves_allowed", "earned_leave_frequency", "rounding"],
305 filters={'is_earned_leave' : 1})
306 today = getdate()
Joyce Babu3d012132019-03-06 13:04:45 +0530307 divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12}
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530308
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530309 for e_leave_type in e_leave_types:
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530310 leave_allocations = frappe.db.sql("""select name, employee, from_date, to_date from `tabLeave Allocation` where %s
311 between from_date and to_date and docstatus=1 and leave_type=%s""", (today, e_leave_type.name), as_dict=1)
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530312 for allocation in leave_allocations:
313 leave_policy = get_employee_leave_policy(allocation.employee)
314 if not leave_policy:
315 continue
316 if not e_leave_type.earned_leave_frequency == "Monthly":
317 if not check_frequency_hit(allocation.from_date, today, e_leave_type.earned_leave_frequency):
318 continue
Mangesh-Khairnar261d1322019-08-09 13:18:52 +0530319 annual_allocation = frappe.db.get_value("Leave Policy Detail", filters={
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530320 'parent': leave_policy.name,
321 'leave_type': e_leave_type.name
Mangesh-Khairnar261d1322019-08-09 13:18:52 +0530322 }, fieldname=['annual_allocation'])
323 if annual_allocation:
324 earned_leaves = flt(annual_allocation) / divide_by_frequency[e_leave_type.earned_leave_frequency]
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530325 if e_leave_type.rounding == "0.5":
326 earned_leaves = round(earned_leaves * 2) / 2
327 else:
328 earned_leaves = round(earned_leaves)
329
330 allocation = frappe.get_doc('Leave Allocation', allocation.name)
331 new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves)
Mangesh-Khairnar5d5f5b42020-02-20 13:25:55 +0530332
333 if new_allocation > e_leave_type.max_leaves_allowed and e_leave_type.max_leaves_allowed > 0:
334 new_allocation = e_leave_type.max_leaves_allowed
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530335
336 if new_allocation == allocation.total_leaves_allocated:
337 continue
338 allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
Mangesh-Khairnar43508462019-12-09 14:27:38 +0530339 create_additional_leave_ledger_entry(allocation, earned_leaves, today)
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530340
Mangesh-Khairnar43508462019-12-09 14:27:38 +0530341def create_additional_leave_ledger_entry(allocation, leaves, date):
342 ''' Create leave ledger entry for leave types '''
343 allocation.new_leaves_allocated = leaves
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530344 allocation.from_date = date
Mangesh-Khairnar5cbe6162019-08-08 17:06:15 +0530345 allocation.unused_leaves = 0
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530346 allocation.create_leave_ledger_entry()
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530347
348def check_frequency_hit(from_date, to_date, frequency):
349 '''Return True if current date matches frequency'''
350 from_dt = get_datetime(from_date)
351 to_dt = get_datetime(to_date)
352 from dateutil import relativedelta
353 rd = relativedelta.relativedelta(to_dt, from_dt)
354 months = rd.months
355 if frequency == "Quarterly":
356 if not months % 3:
357 return True
Joyce Babu3d012132019-03-06 13:04:45 +0530358 elif frequency == "Half-Yearly":
359 if not months % 6:
360 return True
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530361 elif frequency == "Yearly":
362 if not months % 12:
363 return True
364 return False
Nabin Hait8c7af492018-06-04 11:23:36 +0530365
Ranjith155ecc12018-05-30 13:37:15 +0530366def get_salary_assignment(employee, date):
367 assignment = frappe.db.sql("""
368 select * from `tabSalary Structure Assignment`
369 where employee=%(employee)s
370 and docstatus = 1
Ranjith Kurungadamb4ad3c32018-06-25 10:29:54 +0530371 and %(on_date)s >= from_date order by from_date desc limit 1""", {
Ranjith155ecc12018-05-30 13:37:15 +0530372 'employee': employee,
373 'on_date': date,
374 }, as_dict=1)
375 return assignment[0] if assignment else None
Ranjith793f8e82018-05-30 20:50:48 +0530376
Jamsheer8d66f1e2018-06-12 11:30:59 +0530377def get_sal_slip_total_benefit_given(employee, payroll_period, component=False):
378 total_given_benefit_amount = 0
379 query = """
380 select sum(sd.amount) as 'total_amount'
381 from `tabSalary Slip` ss, `tabSalary Detail` sd
382 where ss.employee=%(employee)s
383 and ss.docstatus = 1 and ss.name = sd.parent
384 and sd.is_flexible_benefit = 1 and sd.parentfield = "earnings"
385 and sd.parenttype = "Salary Slip"
386 and (ss.start_date between %(start_date)s and %(end_date)s
387 or ss.end_date between %(start_date)s and %(end_date)s
388 or (ss.start_date < %(start_date)s and ss.end_date > %(end_date)s))
389 """
390
391 if component:
392 query += "and sd.salary_component = %(component)s"
393
394 sum_of_given_benefit = frappe.db.sql(query, {
395 'employee': employee,
396 'start_date': payroll_period.start_date,
397 'end_date': payroll_period.end_date,
398 'component': component
399 }, as_dict=True)
400
Rushabh Mehtadf23c7d2018-07-05 15:19:28 +0530401 if sum_of_given_benefit and flt(sum_of_given_benefit[0].total_amount) > 0:
Jamsheer8d66f1e2018-06-12 11:30:59 +0530402 total_given_benefit_amount = sum_of_given_benefit[0].total_amount
403 return total_given_benefit_amount
Jamsheercc25eb02018-06-13 15:14:24 +0530404
405def get_holidays_for_employee(employee, start_date, end_date):
406 holiday_list = get_holiday_list_for_employee(employee)
Mangesh-Khairnar43508462019-12-09 14:27:38 +0530407
Jamsheercc25eb02018-06-13 15:14:24 +0530408 holidays = frappe.db.sql_list('''select holiday_date from `tabHoliday`
409 where
410 parent=%(holiday_list)s
411 and holiday_date >= %(start_date)s
412 and holiday_date <= %(end_date)s''', {
413 "holiday_list": holiday_list,
414 "start_date": start_date,
415 "end_date": end_date
416 })
417
418 holidays = [cstr(i) for i in holidays]
419
420 return holidays
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530421
422@erpnext.allow_regional
423def calculate_annual_eligible_hra_exemption(doc):
424 # Don't delete this method, used for localization
425 # Indian HRA Exemption Calculation
426 return {}
427
428@erpnext.allow_regional
429def calculate_hra_exemption_for_period(doc):
430 # Don't delete this method, used for localization
431 # Indian HRA Exemption Calculation
432 return {}
Jamsheer55a2f4d2018-06-20 11:04:21 +0530433
434def get_previous_claimed_amount(employee, payroll_period, non_pro_rata=False, component=False):
435 total_claimed_amount = 0
436 query = """
437 select sum(claimed_amount) as 'total_amount'
438 from `tabEmployee Benefit Claim`
439 where employee=%(employee)s
440 and docstatus = 1
441 and (claim_date between %(start_date)s and %(end_date)s)
442 """
443 if non_pro_rata:
444 query += "and pay_against_benefit_claim = 1"
445 if component:
446 query += "and earning_component = %(component)s"
447
448 sum_of_claimed_amount = frappe.db.sql(query, {
449 'employee': employee,
450 'start_date': payroll_period.start_date,
451 'end_date': payroll_period.end_date,
452 'component': component
453 }, as_dict=True)
Rushabh Mehtadf23c7d2018-07-05 15:19:28 +0530454 if sum_of_claimed_amount and flt(sum_of_claimed_amount[0].total_amount) > 0:
Jamsheer55a2f4d2018-06-20 11:04:21 +0530455 total_claimed_amount = sum_of_claimed_amount[0].total_amount
456 return total_claimed_amount