get additional salary component in salary slip
This commit is contained in:
parent
08b60a1a62
commit
d0b0c87f40
@ -5,22 +5,72 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import formatdate, format_datetime, getdate, get_datetime, nowdate
|
from frappe import _
|
||||||
from erpnext.hr.utils import validate_dates
|
from frappe.utils import getdate, date_diff
|
||||||
|
|
||||||
class AdditionalSalaryComponent(Document):
|
class AdditionalSalaryComponent(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
# self.validate_dates()
|
self.validate_dates()
|
||||||
validate_dates(self, self.from_date, self.to_date)
|
if self.amount <= 0:
|
||||||
|
frappe.throw(_("Amount should be greater than zero."))
|
||||||
|
|
||||||
# def validate_dates(self):
|
def validate_dates(self):
|
||||||
# date_of_joining, relieving_date = frappe.db.get_value("Employee", self.employee,
|
date_of_joining, relieving_date = frappe.db.get_value("Employee", self.employee,
|
||||||
# ["date_of_joining", "relieving_date"])
|
["date_of_joining", "relieving_date"])
|
||||||
# if getdate(self.from_date) > getdate(to_date):
|
if getdate(self.from_date) > getdate(self.to_date):
|
||||||
# frappe.throw(_("To date can not be less than from date"))
|
frappe.throw(_("To date can not be less than from date"))
|
||||||
# elif getdate(self.from_date) > getdate(nowdate()):
|
elif date_of_joining and getdate(self.from_date) < getdate(date_of_joining):
|
||||||
# frappe.throw(_("Future dates not allowed"))
|
frappe.throw(_("From date can not be less than employee's joining date"))
|
||||||
# elif date_of_joining and getdate(self.from_date) < getdate(date_of_joining):
|
elif relieving_date and getdate(self.to_date) > getdate(relieving_date):
|
||||||
# frappe.throw(_("From date can not be less than employee's joining date"))
|
frappe.throw(_("To date can not greater than employee's relieving date"))
|
||||||
# elif relieving_date and getdate(to_date) > getdate(relieving_date):
|
|
||||||
# frappe.throw(_("To date can not greater than employee's relieving date"))
|
def get_amount(self, sal_start_date, sal_end_date):
|
||||||
|
start_date = getdate(sal_start_date)
|
||||||
|
end_date = getdate(sal_end_date)
|
||||||
|
total_days = date_diff(getdate(self.to_date), getdate(self.from_date)) + 1
|
||||||
|
amount_per_day = self.amount / total_days
|
||||||
|
if getdate(sal_start_date) <= getdate(self.from_date):
|
||||||
|
start_date = getdate(self.from_date)
|
||||||
|
if getdate(sal_end_date) > getdate(self.to_date):
|
||||||
|
end_date = getdate(self.end_date)
|
||||||
|
no_of_days = date_diff(getdate(end_date), getdate(start_date))
|
||||||
|
return amount_per_day * no_of_days
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_additional_salary_component(employee, start_date, end_date):
|
||||||
|
additional_components = frappe.db.sql("""
|
||||||
|
select name from `tabAdditional Salary Component`
|
||||||
|
where employee=%(employee)s
|
||||||
|
and docstatus = 1
|
||||||
|
and (
|
||||||
|
(%(from_date)s between from_date and to_date)
|
||||||
|
or (%(to_date)s between from_date and to_date)
|
||||||
|
or (from_date between %(from_date)s and %(to_date)s)
|
||||||
|
)""", {
|
||||||
|
'employee': employee,
|
||||||
|
'from_date': start_date,
|
||||||
|
'to_date': end_date
|
||||||
|
})
|
||||||
|
|
||||||
|
if additional_components:
|
||||||
|
additional_components_array = []
|
||||||
|
for additional_component in additional_components:
|
||||||
|
struct_row = {}
|
||||||
|
additional_components_dict = {}
|
||||||
|
additional_component_obj = frappe.get_doc("Additional Salary Component", additional_component[0])
|
||||||
|
amount = additional_component_obj.get_amount(start_date, end_date)
|
||||||
|
salary_component = frappe.get_doc("Salary Component", additional_component_obj.salary_component)
|
||||||
|
struct_row['depends_on_lwp'] = salary_component.depends_on_lwp
|
||||||
|
struct_row['salary_component'] = salary_component.name
|
||||||
|
struct_row['abbr'] = salary_component.salary_component_abbr
|
||||||
|
struct_row['do_not_include_in_total'] = salary_component.do_not_include_in_total
|
||||||
|
additional_components_dict['amount'] = amount
|
||||||
|
additional_components_dict['struct_row'] = struct_row
|
||||||
|
additional_components_array.append(additional_components_dict)
|
||||||
|
|
||||||
|
if len(additional_components_array) > 0:
|
||||||
|
return additional_components_array
|
||||||
|
return False
|
||||||
|
|||||||
@ -12,6 +12,7 @@ from erpnext.hr.doctype.payroll_entry.payroll_entry import get_start_end_dates
|
|||||||
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
|
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
|
||||||
from erpnext.utilities.transaction_base import TransactionBase
|
from erpnext.utilities.transaction_base import TransactionBase
|
||||||
from frappe.utils.background_jobs import enqueue
|
from frappe.utils.background_jobs import enqueue
|
||||||
|
from erpnext.hr.doctype.additional_salary_component.additional_salary_component import get_additional_salary_component
|
||||||
|
|
||||||
class SalarySlip(TransactionBase):
|
class SalarySlip(TransactionBase):
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
@ -58,6 +59,12 @@ class SalarySlip(TransactionBase):
|
|||||||
if amount and struct_row.statistical_component == 0:
|
if amount and struct_row.statistical_component == 0:
|
||||||
self.update_component_row(struct_row, amount, key)
|
self.update_component_row(struct_row, amount, key)
|
||||||
|
|
||||||
|
additional_components = get_additional_salary_component(self.employee, self.start_date, self.end_date)
|
||||||
|
if additional_components:
|
||||||
|
for additional_component in additional_components:
|
||||||
|
additional_component = frappe._dict(additional_component)
|
||||||
|
self.update_component_row(frappe._dict(additional_component.struct_row), additional_component.amount, "earnings")
|
||||||
|
|
||||||
def update_component_row(self, struct_row, amount, key):
|
def update_component_row(self, struct_row, amount, key):
|
||||||
component_row = None
|
component_row = None
|
||||||
for d in self.get(key):
|
for d in self.get(key):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user