Verified Commit ac767264 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add proper output

parent 120060ca
Loading
Loading
Loading
Loading
+42 −11
Original line number Diff line number Diff line
from pathlib import Path
from decimal import Decimal
import sys

from tabulate import tabulate

from .payment_order.PaymentOrderCollection import PaymentOrderCollection
from .budget_plan.BudgetPlanLoader import load_csv
from .budget_plan.BudgetPlanLoader import load_pdf

directory = Path(sys.argv[1])

sums = {
    budgetary_item_id: sum(po.amount for po in payment_orders)
    for budgetary_item_id, payment_orders in PaymentOrderCollection(
        directory
    ).by_budgetary_item_id
}
print(sums)
sums = PaymentOrderCollection(directory).sums_by_budgetary_item_id
#print(sums)

budget_plan = load_pdf(sys.argv[2])
#print(budget_plan)


def _format_as_euro_de(amount: Decimal) -> str:
    return f"{amount}".replace(".", ",")


budget_plan = load_csv(
    "./Coli_Budgetplan_2024.csv"
output_rows = [
    (
        item.id,
        item.name,
        spent := sums.get(item.id, Decimal("0.00")),
        remaining := item.amount - spent,
        item.amount,
    )
    for item in budget_plan.items.values()
]

formatted_output_rows = [
    (
        id,
        name,
        _format_as_euro_de(spent),
        _format_as_euro_de(remaining),
        _format_as_euro_de(total),
    )
    for (id, name, spent, remaining, total) in output_rows
]

print(
    tabulate(
        formatted_output_rows,
        headers=["Budgetposten", "Name", "Ausgegeben", "Verbleibend", "Geplant"],
        colalign=("right", "left", "right", "right", "right"),
    )
)
print(budget_plan)
+2 −1
Original line number Diff line number Diff line
pypdf
tabulate