Пример #1
0
def get_last_payroll_period_benefits(employee, sal_slip_start_date,
                                     sal_slip_end_date, payroll_period,
                                     sal_struct):
    max_benefits = get_max_benefits(employee, payroll_period.end_date)
    if not max_benefits:
        max_benefits = 0
    remaining_benefit = max_benefits - get_total_benefit_dispensed(
        employee, sal_struct, sal_slip_start_date, payroll_period)
    if remaining_benefit > 0:
        have_remaining = True
        # Set the remaining benefits to flexi non pro-rata component in the salary structure
        salary_components_array = []
        for d in sal_struct.get("earnings"):
            if d.is_flexible_benefit == 1:
                salary_component = frappe.get_doc("Salary Component",
                                                  d.salary_component)
                if salary_component.pay_against_benefit_claim == 1:
                    claimed_amount = get_benefit_claim_amount(
                        employee, payroll_period.start_date, sal_slip_end_date,
                        d.salary_component)
                    amount_fit_to_component = salary_component.max_benefit_amount - claimed_amount
                    if amount_fit_to_component > 0:
                        if remaining_benefit > amount_fit_to_component:
                            amount = amount_fit_to_component
                            remaining_benefit -= amount_fit_to_component
                        else:
                            amount = remaining_benefit
                            have_remaining = False
                        current_claimed_amount = get_benefit_claim_amount(
                            employee, sal_slip_start_date, sal_slip_end_date,
                            d.salary_component)
                        amount += current_claimed_amount
                        struct_row = {}
                        salary_components_dict = {}
                        struct_row[
                            'depends_on_payment_days'] = salary_component.depends_on_payment_days
                        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
                        struct_row[
                            'is_tax_applicable'] = salary_component.is_tax_applicable,
                        struct_row[
                            'is_flexible_benefit'] = salary_component.is_flexible_benefit,
                        struct_row[
                            'variable_based_on_taxable_salary'] = salary_component.variable_based_on_taxable_salary
                        salary_components_dict['amount'] = amount
                        salary_components_dict['struct_row'] = struct_row
                        salary_components_array.append(salary_components_dict)
            if not have_remaining:
                break

        if len(salary_components_array) > 0:
            return salary_components_array

    return False
Пример #2
0
	def validate(self):
		validate_active_employee(self.employee)
		max_benefits = get_max_benefits(self.employee, self.claim_date)
		if not max_benefits or max_benefits <= 0:
			frappe.throw(_("Employee {0} has no maximum benefit amount").format(self.employee))
		payroll_period = get_payroll_period(self.claim_date, self.claim_date, frappe.db.get_value("Employee", self.employee, "company"))
		if not payroll_period:
			frappe.throw(_("{0} is not in a valid Payroll Period").format(frappe.format(self.claim_date, dict(fieldtype='Date'))))
		self.validate_max_benefit_for_component(payroll_period)
		self.validate_max_benefit_for_sal_struct(max_benefits)
		self.validate_benefit_claim_amount(max_benefits, payroll_period)
		if self.pay_against_benefit_claim:
			self.validate_non_pro_rata_benefit_claim(max_benefits, payroll_period)