"""Ledger VAT Handler.""" from fastapi import APIRouter from moneyhub.logic import ledger_vat_summary as logic from moneyhub.schemas.ledger_vat_summary import LedgerVatSummaryBackfillSchema from moneyhub.schemas.ledger_vat_summary import LedgerVatSummarySchema from moneyhub.schemas.ledger_vat_summary import PaginatedLedgerVatSummarySchema ledger_vat_router = APIRouter(prefix='/ledger-vat-summary', tags=['ledger_vat']) # TODO: can this be deprecated? @ledger_vat_router.get( '/account/{account_id}/statement-period/{statement_period_id}', status_code=200 ) def get_ledger_vat_summary_by_account( account_id: int, statement_period_id: int, contract_id: int | None = None, vat_categories: str | None = None, ) -> list[LedgerVatSummarySchema]: """GET ledger vat for a specified account and statement period. Args: account_id (int): The id of an account contract_id (int): the id of a contract statement_period_id (int): the id of a statement period vat_categories (str): vat categories to filter Returns: list: list of vat summary info """ return logic.get_by_account_id( account_id, statement_period_id, contract_id, vat_categories.split(',') if vat_categories else None, ) @ledger_vat_router.get( '/account/{account_id}/activity-statement-period/{statement_period_id}', status_code=200 ) def get_ledger_vat_summary_by_activity_period( account_id: int, statement_period_id: int, contract_id: int | None = None, vat_categories: str | None = None, ) -> list[LedgerVatSummarySchema]: """GET ledger vat for a specified account and activity statement period. Args: account_id (int): The id of an account contract_id (int): the id of a contract statement_period_id (int): the id of a statement period vat_categories (str): vat categories to filter Returns: list: list of vat summary info """ return logic.get_activity_by_account_id( account_id, statement_period_id, contract_id, vat_categories.split(',') if vat_categories else None, ) @ledger_vat_router.post( '/statement-period/{statement_period_id}/backfill', status_code=201 ) def backfill_ledger_vat_summary( statement_period_id: int, payload: list[LedgerVatSummaryBackfillSchema], ) -> list[LedgerVatSummarySchema]: """Backfill entries to the VAT summary table. Args: statement_period_id (int): ID of the statement period to backfill entries for payload (list): Backfill payload Returns: list: list of created vat summary entries """ return logic.backfill_vat_summary_entries(statement_period_id, payload) @ledger_vat_router.get( '/vat-summary-file/{vat_summary_file_id}', status_code=200, ) def get_ledger_vat_summary_by_vat_summary_file( vat_summary_file_id: int, limit: int = 0, offset: int = 0, ) -> PaginatedLedgerVatSummarySchema: """Get ledger VAT summary entries associated with a VAT summary file. Args: vat_summary_file_id (int): ID of the VAT summary file limit (int): how many entities to retrieve offset (int): the offset (for pagination) Returns: PaginatedLedgerVatSummarySchema: paginated list of ledger VAT summary entries """ return logic.get_by_vat_summary_file(vat_summary_file_id, limit, offset)