from decimal import Decimal, ROUND_HALF_UP

TWOPLACES = Decimal("0.01")
def money(value): return Decimal(str(value)).quantize(TWOPLACES, rounding=ROUND_HALF_UP)
def daily_rate(monthly_amount, day_divisor):
    divisor = Decimal(str(day_divisor))
    if divisor <= 0: raise ValueError("day_divisor must be greater than zero")
    return money(Decimal(str(monthly_amount)) / divisor)
def hourly_rate(monthly_amount, monthly_working_hours):
    hours = Decimal(str(monthly_working_hours))
    if hours <= 0: raise ValueError("monthly_working_hours must be greater than zero")
    return money(Decimal(str(monthly_amount)) / hours)
def overtime_amount(approved_hours, base_hourly_rate, multiplier=1):
    return money(Decimal(str(approved_hours)) * Decimal(str(base_hourly_rate)) * Decimal(str(multiplier)))
def net_payable(*, gross_salary, overtime=0, bonus=0, other_earnings=0, attendance_deduction=0, other_deductions=0, loan_recovery=0, adjustments=0):
    total = Decimal(str(gross_salary)) + Decimal(str(overtime)) + Decimal(str(bonus)) + Decimal(str(other_earnings)) + Decimal(str(adjustments))
    total -= Decimal(str(attendance_deduction)) + Decimal(str(other_deductions)) + Decimal(str(loan_recovery))
    return money(total)
