mbl 0.1.6

The finantial part based on rust_decimal crate
Documentation
// By KNB, 2025
// Complete mbl crate based on rust_decimal::Decimal type.
// Basic arithmetic operations should be implemented in this crate.
// Most interesting part is how you will store accounts and, that's more
// important, transactions. Here are some ideas: postgres, sqlite, mysql,
// for home accounting json will enough. But even for home accounting critical
// or personal data should be encrypted.

// Should I share some ideas about how to store data in json?
// Should I share some ideas about how to store data in postgres?
// Problems to solve:
// 1. How to assign id to account?
// 2. How to assign id to transaction?
// 3. How to manage users?
// 4. How to protect data?
// 5. How to store data?
// 6. How to manage data?
// 7. How to deploy double entry accounting?
// 8. How to deploy double entry accounting with tags?
// 9. How to sold that software? Or how to get money for it?
// 10. Where to get time for development?

use rust_decimal;
use rust_decimal::prelude::*;

pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

/// Watch out for how you funded, accept only positive values
pub fn fund(howmuch: rust_decimal::Decimal) -> bool {
    if howmuch > dec!(0.0) {
        return true;
    } else {
        return false;
    }
}

/// Account with balance of rust_decimal type, name and id
pub struct Account {
    pub name: String,
    pub balance: rust_decimal::Decimal,
    pub id: String,
}

/// Transaction with amount, description, account, date, category, tags, from
pub struct Transaction {
    pub amount: rust_decimal::Decimal,
    pub description: String,
    pub account: Account,
    pub date: String,
    pub category: String,
    pub tags: Vec<String>,
    pub from: Account,
    // todo: add to and from
    // todo: add transaction id
    // todo: implement double entry accounting
    // todo: implement fn to_json
    // todo: implement fn from_json
    // todo: implement accounts change
    // todo: implement one to many transactions
    // todo: implement many to many and many to one transactions
}

/// Define a new type for Account
impl Account {
    pub fn new(name: String, balance: rust_decimal::Decimal, id: String) -> Account {
        Account { name, balance, id }
    }
}
/// Define a new type for Transaction
impl Transaction {
    pub fn new(
        amount: rust_decimal::Decimal,
        description: String,
        account: Account,
        date: String,
        category: String,
        tags: Vec<String>,
        from: Account,
    ) -> Transaction {
        Transaction {
            amount,
            description,
            account,
            date,
            category,
            tags,
            from,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}