def calculate_variable_tax(self, payroll_period, tax_component): # get Tax slab from salary structure assignment for the employee and payroll period tax_slab = self.get_income_tax_slabs(payroll_period) # get remaining numbers of sub-period (period for which one salary is processed) remaining_sub_periods = get_period_factor(self.employee, self.start_date, self.end_date, self.payroll_frequency, payroll_period)[1] # get taxable_earnings, paid_taxes for previous period previous_taxable_earnings = self.get_taxable_earnings_for_prev_period(payroll_period.start_date, self.start_date, tax_slab.allow_tax_exemption) previous_total_paid_taxes = self.get_tax_paid_in_period(payroll_period.start_date, self.start_date, tax_component) # get taxable_earnings for current period (all days) current_taxable_earnings = self.get_taxable_earnings(tax_slab.allow_tax_exemption) future_structured_taxable_earnings = current_taxable_earnings.taxable_earnings * (math.ceil(remaining_sub_periods) - 1) # get taxable_earnings, addition_earnings for current actual payment days current_taxable_earnings_for_payment_days = self.get_taxable_earnings(tax_slab.allow_tax_exemption, based_on_payment_days=1) current_structured_taxable_earnings = current_taxable_earnings_for_payment_days.taxable_earnings current_additional_earnings = current_taxable_earnings_for_payment_days.additional_income current_additional_earnings_with_full_tax = current_taxable_earnings_for_payment_days.additional_income_with_full_tax # Get taxable unclaimed benefits unclaimed_taxable_benefits = 0 if self.deduct_tax_for_unclaimed_employee_benefits: unclaimed_taxable_benefits = self.calculate_unclaimed_taxable_benefits(payroll_period) unclaimed_taxable_benefits += current_taxable_earnings_for_payment_days.flexi_benefits # Total exemption amount based on tax exemption declaration total_exemption_amount = self.get_total_exemption_amount(payroll_period, tax_slab) #Employee Other Incomes other_incomes = self.get_income_form_other_sources(payroll_period) or 0.0 # Total taxable earnings including additional and other incomes total_taxable_earnings = previous_taxable_earnings + current_structured_taxable_earnings + future_structured_taxable_earnings \ + current_additional_earnings + other_incomes + unclaimed_taxable_benefits - total_exemption_amount # Total taxable earnings without additional earnings with full tax total_taxable_earnings_without_full_tax_addl_components = total_taxable_earnings - current_additional_earnings_with_full_tax # Structured tax amount total_structured_tax_amount = self.calculate_tax_by_tax_slab( total_taxable_earnings_without_full_tax_addl_components, tax_slab) current_structured_tax_amount = (total_structured_tax_amount - previous_total_paid_taxes) / remaining_sub_periods # Total taxable earnings with additional earnings with full tax full_tax_on_additional_earnings = 0.0 if current_additional_earnings_with_full_tax: total_tax_amount = self.calculate_tax_by_tax_slab(total_taxable_earnings, tax_slab) full_tax_on_additional_earnings = total_tax_amount - total_structured_tax_amount current_tax_amount = current_structured_tax_amount + full_tax_on_additional_earnings if flt(current_tax_amount) < 0: current_tax_amount = 0 return current_tax_amount
def get_benefit_component_amount(employee, start_date, end_date, salary_component, sal_struct, payroll_frequency, payroll_period): if not payroll_period: frappe.msgprint( _("Start and end dates not in a valid Payroll Period, cannot calculate {0}" ).format(salary_component)) return False # Considering there is only one application for a year benefit_application = frappe.db.sql( """ select name from `tabEmployee Benefit Application` where payroll_period=%(payroll_period)s and employee=%(employee)s and docstatus = 1 """, { 'employee': employee, 'payroll_period': payroll_period.name }) current_benefit_amount = 0.0 component_max_benefit, depends_on_payment_days = frappe.db.get_value( "Salary Component", salary_component, ["max_benefit_amount", "depends_on_payment_days"]) benefit_amount = 0 if benefit_application: benefit_amount = frappe.db.get_value( "Employee Benefit Application Detail", { "parent": benefit_application[0][0], "earning_component": salary_component }, "amount") elif component_max_benefit: benefit_amount = get_benefit_amount_based_on_pro_rata( sal_struct, component_max_benefit) current_benefit_amount = 0 if benefit_amount: total_sub_periods = get_period_factor(employee, start_date, end_date, payroll_frequency, payroll_period, depends_on_payment_days)[0] current_benefit_amount = benefit_amount / total_sub_periods return current_benefit_amount