
from django import template
from decimal import Decimal

register = template.Library()

@register.filter
def sum_amounts(deductions):
    """Sum the amounts of a queryset of deductions"""
    return sum(deduction.amount for deduction in deductions)

@register.filter
def currency(value):
    """Format currency with KSh prefix"""
    try:
        return f"KSh {float(value):,.2f}"
    except (ValueError, TypeError):
        return "KSh 0.00"
