#transaction #summary #quarterly

tktax-quarterly

Quarterly summarization tools for financial transactions in the TKTAX ecosystem

1 unstable release

new 0.2.2 Feb 1, 2025

#43 in #summary

MIT/Apache

175KB
2.5K SLoC

tktax-quarterly

tktax-quarterly provides functionality for aggregating transaction data into quarterly summaries, ideal for financial or accounting applications that require time-based grouping and analysis of credits, debits, checks, deposits, and point-of-sale (POS) totals.

Overview

  • Quarterly Summaries: The core QuarterlySummary struct collates and stores transaction totals (credits, debits, checks, deposits, and POS amounts) for three-month intervals.
  • Automatic Quarter Calculation: The start_of_quarter function computes the first date of a quarter for any NaiveDate.
  • Trait-Based Integration: The CreateQuarterlySummary trait enables any struct (for example, an Account) to provide quarterly aggregation without bespoke logic scattered throughout the codebase.

Installation

Add the following to your Cargo.toml:

[dependencies]
tktax-quarterly = "0.1.0"

Ensure you also include or have access to the companion crates (tktax_3p, tktax_account, tktax_money, and tktax_transaction) as needed.

Usage

Below is a minimal example demonstrating how to produce quarterly summaries from an Account:

use tktax_quarterly::{CreateQuarterlySummary, QuarterlySummary};
use tktax_account::Account;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Assume `my_account` is already populated with transactions
    let my_account = Account::new(/* details omitted for brevity */);

    // Generate all quarterly summaries
    let summaries: Vec<QuarterlySummary> = my_account.quarterly_summary();

    for s in summaries {
        println!(
            "Quarter starting {} -> credits: {}, debits: {}, checks: {}, deposits: {}, pos: {}",
            s.start_of_quarter(),
            s.credits().value(),     // Hypothetical .value() method on MonetaryAmount
            s.debits().value(),
            s.checks().value(),
            s.deposits().value(),
            s.point_of_sale().value(),
        );
    }

    Ok(())
}

In the above code:

  • Account integrates the CreateQuarterlySummary trait, allowing an immediate quarterly_summary() call.
  • Each QuarterlySummary instance contains total monetary amounts for the specified quarter.

Features

  • Robust Date Handling: Leverages the NaiveDate type for precise date operations, ensuring correct quarter boundaries even when crossing calendar-year boundaries.
  • Modular Design: The trait-based pattern separates quarterly logic from data storage, enhancing extensibility and modularity.
  • Automatic Sorting: Quarterly summaries are returned in ascending order of quarter start date.

Contributing

Contributions are welcome. Please submit issues and pull requests on GitHub. For major changes, open an issue first to discuss the intended modifications.

License

Licensed under either MIT or Apache-2.0, at your option.

Dependencies

~26–38MB
~644K SLoC