Example #1
0
def get_period_factor(employee, start_date, end_date, payroll_frequency, payroll_period, depends_on_payment_days=0):
	# TODO if both deduct checked update the factor to make tax consistent
	period_start, period_end = payroll_period.start_date, payroll_period.end_date
	joining_date, relieving_date = frappe.db.get_value("Employee", employee, ["date_of_joining", "relieving_date"])

	if getdate(joining_date) > getdate(period_start):
		period_start = joining_date
	if relieving_date and getdate(relieving_date) < getdate(period_end):
		period_end = relieving_date

	total_sub_periods, remaining_sub_periods = 0.0, 0.0

	if payroll_frequency ==  "Monthly" and not depends_on_payment_days:
		total_sub_periods = month_diff(payroll_period.end_date, payroll_period.start_date)
		remaining_sub_periods = month_diff(period_end, start_date)
	else:
		salary_days = date_diff(end_date, start_date) + 1

		days_in_payroll_period = date_diff(payroll_period.end_date, payroll_period.start_date) + 1
		total_sub_periods = flt(days_in_payroll_period) / flt(salary_days)

		remaining_days_in_payroll_period = date_diff(period_end, start_date) + 1
		remaining_sub_periods = flt(remaining_days_in_payroll_period) / flt(salary_days)

	return total_sub_periods, remaining_sub_periods
Example #2
0
def get_component_pay(frequency, amount, from_date, to_date):
    days = date_diff(to_date, from_date) + 1

    if frequency == "Daily":
        return amount * days
    elif frequency == "Weekly":
        return amount * math.floor(days / 7)
    elif frequency == "Fortnightly":
        return amount * math.floor(days / 14)
    elif frequency == "Monthly":
        return amount * month_diff(to_date, from_date)
    elif frequency == "Bimonthly":
        return amount * (month_diff(to_date, from_date) / 2)
Example #3
0
def get_next_schedule_date(schedule_date, frequency, start_date, repeat_on_day=None, repeat_on_last_day=False, end_date=None, for_full_schedule=False):
	if month_map.get(frequency):
		month_count = month_map.get(frequency) + month_diff(schedule_date, start_date) - 1
	else:
		month_count = 0

	day_count = 0
	if month_count and repeat_on_last_day:
		next_date = get_next_date(start_date, month_count, 31)
		day_count = 31
		next_date = get_next_date(start_date, month_count, day_count)
	elif month_count and repeat_on_day:
		next_date = get_next_date(start_date, month_count, repeat_on_day)
		day_count = repeat_on_day
		next_date = get_next_date(start_date, month_count, day_count)
	elif month_count:
		next_date = get_next_date(start_date, month_count)
	else:
		days = 7 if frequency == 'Weekly' else 1
		next_date = add_days(start_date, days)

	# next schedule date should be after or on current date
	if not for_full_schedule:
		while getdate(next_date) < getdate(today()):
			if month_count:
				month_count += month_map.get(frequency)
			next_date = get_next_date(start_date, month_count, day_count)

	return next_date
Example #4
0
def get_pro_rata_amt(row, depreciation_amount, from_date, to_date):
	months = month_diff(to_date, from_date)
	if row.depreciation_method == "Prorated Straight Line (360 Days)":
		todate = get_last_day(from_date) if getdate(to_date).month == 12 else to_date
		fromdate = get_last_day(to_date) if getdate(from_date).month == 12 else from_date
		days = date_diff(todate, fromdate) + (cint(months) - 1) * 30
		total_days = min(get_total_days(to_date, row.frequency_of_depreciation), 360)
	else:
		total_days = get_total_days(to_date, row.frequency_of_depreciation)
		days = date_diff(to_date, from_date)

	return (depreciation_amount * flt(days)) / flt(total_days), days, months
Example #5
0
    def get_next_schedule_date(self, schedule_date, for_full_schedule=False):
        """
			Returns the next schedule date for auto repeat after a recurring document has been created.
			Adds required offset to the schedule_date param and returns the next schedule date.

			:param schedule_date: The date when the last recurring document was created.
			:param for_full_schedule: If True, returns the immediate next schedule date, else the full schedule.
		"""
        if month_map.get(self.frequency):
            month_count = month_map.get(self.frequency) + month_diff(
                schedule_date, self.start_date) - 1
        else:
            month_count = 0

        day_count = 0
        if month_count and self.repeat_on_last_day:
            day_count = 31
            next_date = get_next_date(self.start_date, month_count, day_count)
        elif month_count and self.repeat_on_day:
            day_count = self.repeat_on_day
            next_date = get_next_date(self.start_date, month_count, day_count)
        elif month_count:
            next_date = get_next_date(self.start_date, month_count)
        else:
            days = self.get_days(schedule_date)
            next_date = add_days(schedule_date, days)

        # next schedule date should be after or on current date
        if not for_full_schedule:
            while getdate(next_date) < getdate(today()):
                if month_count:
                    month_count += month_map.get(self.frequency, 0)
                    next_date = get_next_date(self.start_date, month_count,
                                              day_count)
                else:
                    days = self.get_days(next_date)
                    next_date = add_days(next_date, days)

        return next_date
Example #6
0
def get_pro_rata_amt(row, depreciation_amount, from_date, to_date):
	days = date_diff(to_date, from_date)
	months = month_diff(to_date, from_date)
	total_days = get_total_days(to_date, row.frequency_of_depreciation)

	return (depreciation_amount * flt(days)) / flt(total_days), days, months