# tktax-expense
This crate provides specialized abstractions for handling business expense logic in the **tktax** ecosystem. By leveraging several foundational crates (e.g., `tktax_3p`, `tktax_account`, `tktax_line_item`, etc.), `tktax-expense` defines robust data structures and traits for expense categorization, financial transactions, and minimal overhead integrations with existing ledger systems.
## Features
1. **`BusinessExpense` Struct**
- Carries a `TransactionCategory` and an immutable reference to the corresponding `Transaction`.
- Implements `fmt::Display` for straightforward logging and reporting.
- Conforms to the `LineItem` trait, ensuring consistent treatment as a billable or deductible line item.
2. **`GetBusinessExpenditures` Trait**
- Exposes the `business_expenditures` method on any `Account` instance.
- Produces a vector of `BusinessExpense` entities after verifying if a transaction belongs to recognized business-related categories.
3. **Predictive Categorization**
- The internal workflow utilizes `predict_category(...)` to map textual transaction descriptions to the most probable category.
- Only transactions deemed strictly business-oriented are wrapped as `BusinessExpense` instances.
## Example Usage
Below is a minimal illustration of how to gather business expenses from an `Account`. For brevity, we assume you have already defined or included the necessary structures (`Account`, `CategoryMap`, etc.) in your codebase.
```rust
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Suppose `account` is loaded from your financial records.
// and `category_map` maps textual descriptors to business categories.
let account: Account = /* ... obtain an Account somehow ... */;
let category_map: CategoryMap<SomeTransactionCategoryImpl> = /* ... initialized externally ... */;
// Gather all recognized business expenses.
let expenses = account.business_expenditures(&category_map);
// Display each recognized expense.
for e in expenses.iter() {
println!("{}", e);
}
Ok(())
}
```
## Crate Design Rationale
- **Generics for Category Extensibility**:
The `TransactionCategory` trait is kept generic, facilitating custom category taxonomies in multifaceted scenarios (e.g., domestic vs. international expenditure, professional fees, office supplies, etc.).
- **Integration with Existing Ledger Systems**:
`GetBusinessExpenditures` is implemented for `Account`, enabling direct synergy with ledger data. This design sidesteps the need to replicate logic for transaction iteration or specialized extraction in user-facing code.
- **Optimized Data Orchestration**:
Internally, expenses are collated, sorted, and prepared for further analytics or reporting with minimal overhead.
## Contributing
Contributions, bug reports, and feature requests are welcomed at the [GitHub repository](https://github.com/klebs6/tktax).
Please adhere to best practices and ensure robust error handling throughout your submission.
## License
This project is licensed under the [MIT License](LICENSE).