### `README.md`
# tktax-monthly
A Rust library for monthly financial transaction aggregation, designed to integrate seamlessly with the [`tktax`](https://github.com/klebs6/tktax) ecosystem. This crate provides abstractions for enumerating, aggregating, and displaying monthly transactions, allowing concise transformations of raw data into validated summaries. By leveraging **AvgMonthly** and **MonthlySummary** structures, users gain production-ready tools suitable for rigorous accounting and tax-reporting applications.
## Overview
- **AvgMonthly\<TxCat\>**:
A structure for representing the average monetary outlay or inflow within a given `TransactionCategory`. It encapsulates:
- `ty` - The `TransactionType` (e.g., credit, debit).
- `category` - The domain-specific transaction category.
- `value` - The calculated average `MonetaryAmount`.
- **MonthlySummary**:
A chronological consolidation of transactions starting at `start_date`. Each field accumulates tallies (akin to aggregare in Latin) of different transaction types:
- `credits`
- `debits`
- `checks`
- `deposits`
- `point_of_sale`
These monoidal accumulations resemble the ἐμπορική συναλλαγή (commercial transaction) grouping, keeping numeric precision intact via `MonetaryAmount`.
- **CreateMonthlySummary**:
A trait that can be implemented by a higher-level data repository to produce a collection of `MonthlySummary` instances.
## Usage Example
```rust
use tktax_monthly::{CreateMonthlySummary, MonthlySummary};
fn compute_monthly_summaries(repo: &impl CreateMonthlySummary) {
let summaries: Vec<MonthlySummary> = repo.monthly_summary();
for summary in summaries {
println!("{:#?}", summary);
// Implement domain logic here:
// e.g., sending this summary for further auditing or analytics
}
}
```
1. **Add the dependency** to your `Cargo.toml`:
```toml
[dependencies]
tktax-monthly = "0.1.0"
```
2. **Implement `CreateMonthlySummary`** in your repository type, ensuring it returns a vector of `MonthlySummary` objects.
3. **Generate** monthly summaries, optionally using `AvgMonthly` for category-based average calculations.
## Features
- **Robust Aggregation**: Safely accumulates monetary transactions across multiple categories.
- **Human-Readable Debugging**: The custom `fmt::Debug` allows single-line or pretty-printed views.
- **Typed Categories**: Avoids stringly-typed design through domain-centric enumerations.
- **Production-Ready**: Zero usage of `.unwrap()` or `.expect()`, ensuring stable error handling paths.
---
**For additional documentation and usage details**, consult the [repository](https://github.com/klebs6/tktax) or open an issue for feature requests.