feat(Payroll): compute Year to Date for Salary Slip components
This commit is contained in:
parent
8aeadc743e
commit
fdad94f983
@ -9,6 +9,7 @@
|
|||||||
"abbr",
|
"abbr",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"amount",
|
"amount",
|
||||||
|
"year_to_date",
|
||||||
"section_break_5",
|
"section_break_5",
|
||||||
"additional_salary",
|
"additional_salary",
|
||||||
"statistical_component",
|
"statistical_component",
|
||||||
@ -226,11 +227,19 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "column_break_24",
|
"fieldname": "column_break_24",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Total amount spent on this salary component from the beginning of the year (payroll or fiscal) to the current payroll date.",
|
||||||
|
"fieldname": "year_to_date",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Year To Date",
|
||||||
|
"options": "currency",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-11-25 13:12:41.081106",
|
"modified": "2021-01-13 17:33:19.184195",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Payroll",
|
"module": "Payroll",
|
||||||
"name": "Salary Detail",
|
"name": "Salary Detail",
|
||||||
|
@ -138,11 +138,11 @@ frappe.ui.form.on("Salary Slip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
change_grid_labels: function(frm) {
|
change_grid_labels: function(frm) {
|
||||||
frm.set_currency_labels(["amount", "default_amount", "additional_amount", "tax_on_flexible_benefit",
|
let fields = ["amount", "year_to_date", "default_amount", "additional_amount", "tax_on_flexible_benefit",
|
||||||
"tax_on_additional_salary"], frm.doc.currency, "earnings");
|
"tax_on_additional_salary"];
|
||||||
|
|
||||||
frm.set_currency_labels(["amount", "default_amount", "additional_amount", "tax_on_flexible_benefit",
|
frm.set_currency_labels(fields, frm.doc.currency, "earnings");
|
||||||
"tax_on_additional_salary"], frm.doc.currency, "deductions");
|
frm.set_currency_labels(fields, frm.doc.currency, "deductions");
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
@ -52,6 +52,7 @@ class SalarySlip(TransactionBase):
|
|||||||
self.calculate_net_pay()
|
self.calculate_net_pay()
|
||||||
self.compute_year_to_date()
|
self.compute_year_to_date()
|
||||||
self.compute_month_to_date()
|
self.compute_month_to_date()
|
||||||
|
self.compute_component_wise_year_to_date()
|
||||||
|
|
||||||
if frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet"):
|
if frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet"):
|
||||||
max_working_hours = frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet")
|
max_working_hours = frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet")
|
||||||
@ -1138,16 +1139,7 @@ class SalarySlip(TransactionBase):
|
|||||||
|
|
||||||
def compute_year_to_date(self):
|
def compute_year_to_date(self):
|
||||||
year_to_date = 0
|
year_to_date = 0
|
||||||
payroll_period = get_payroll_period(self.start_date, self.end_date, self.company)
|
period_start_date, period_end_date = self.get_year_to_date_period()
|
||||||
|
|
||||||
if payroll_period:
|
|
||||||
period_start_date = payroll_period.start_date
|
|
||||||
period_end_date = payroll_period.end_date
|
|
||||||
else:
|
|
||||||
# get dates based on fiscal year if no payroll period exists
|
|
||||||
fiscal_year = get_fiscal_year(date=self.start_date, company=self.company, as_dict=1)
|
|
||||||
period_start_date = fiscal_year.year_start_date
|
|
||||||
period_end_date = fiscal_year.year_end_date
|
|
||||||
|
|
||||||
salary_slip_sum = frappe.get_list('Salary Slip',
|
salary_slip_sum = frappe.get_list('Salary Slip',
|
||||||
fields = ['sum(net_pay) as sum'],
|
fields = ['sum(net_pay) as sum'],
|
||||||
@ -1180,6 +1172,47 @@ class SalarySlip(TransactionBase):
|
|||||||
month_to_date += self.net_pay
|
month_to_date += self.net_pay
|
||||||
self.month_to_date = month_to_date
|
self.month_to_date = month_to_date
|
||||||
|
|
||||||
|
def compute_component_wise_year_to_date(self):
|
||||||
|
period_start_date, period_end_date = self.get_year_to_date_period()
|
||||||
|
|
||||||
|
for key in ('earnings', 'deductions'):
|
||||||
|
for component in self.get(key):
|
||||||
|
year_to_date = 0
|
||||||
|
component_sum = frappe.db.sql("""
|
||||||
|
SELECT sum(detail.amount) as sum
|
||||||
|
FROM `tabSalary Detail` as detail
|
||||||
|
INNER JOIN `tabSalary Slip` as salary_slip
|
||||||
|
ON detail.parent = salary_slip.name
|
||||||
|
WHERE
|
||||||
|
salary_slip.employee_name = %(employee_name)s
|
||||||
|
AND detail.salary_component = %(component)s
|
||||||
|
AND salary_slip.start_date >= %(period_start_date)s
|
||||||
|
AND salary_slip.end_date < %(period_end_date)s
|
||||||
|
AND salary_slip.name != %(docname)s
|
||||||
|
AND salary_slip.docstatus = 1""",
|
||||||
|
{'employee_name': self.employee_name, 'component': component.salary_component, 'period_start_date': period_start_date,
|
||||||
|
'period_end_date': period_end_date, 'docname': self.name}
|
||||||
|
)
|
||||||
|
|
||||||
|
year_to_date = flt(component_sum[0][0]) if component_sum else 0.0
|
||||||
|
year_to_date += component.amount
|
||||||
|
component.year_to_date = year_to_date
|
||||||
|
|
||||||
|
def get_year_to_date_period(self):
|
||||||
|
payroll_period = get_payroll_period(self.start_date, self.end_date, self.company)
|
||||||
|
|
||||||
|
if payroll_period:
|
||||||
|
period_start_date = payroll_period.start_date
|
||||||
|
period_end_date = payroll_period.end_date
|
||||||
|
else:
|
||||||
|
# get dates based on fiscal year if no payroll period exists
|
||||||
|
fiscal_year = get_fiscal_year(date=self.start_date, company=self.company, as_dict=1)
|
||||||
|
period_start_date = fiscal_year.year_start_date
|
||||||
|
period_end_date = fiscal_year.year_end_date
|
||||||
|
|
||||||
|
return period_start_date, period_end_date
|
||||||
|
|
||||||
|
|
||||||
def unlink_ref_doc_from_salary_slip(ref_no):
|
def unlink_ref_doc_from_salary_slip(ref_no):
|
||||||
linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip`
|
linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip`
|
||||||
where journal_entry=%s and docstatus < 2""", (ref_no))
|
where journal_entry=%s and docstatus < 2""", (ref_no))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user