97 lines
2.1 KiB
Rust
97 lines
2.1 KiB
Rust
use crate::{data_layer, entities::Account};
|
|
use chrono::{DateTime, Utc};
|
|
use sqlite::Connection;
|
|
|
|
pub struct Transaction {
|
|
id: i64,
|
|
account_id: i64,
|
|
amount: f64,
|
|
date: DateTime<Utc>,
|
|
description: String,
|
|
type_id: i64,
|
|
|
|
account: Account,
|
|
tr_type: TransactionType,
|
|
}
|
|
|
|
impl Transaction {
|
|
pub fn new(
|
|
id: i64,
|
|
ac_id: i64,
|
|
amount: f64,
|
|
date: DateTime<Utc>,
|
|
desc: String,
|
|
type_id: i64,
|
|
con: &Connection,
|
|
) -> Self {
|
|
Transaction {
|
|
id: id,
|
|
account_id: ac_id,
|
|
amount: amount,
|
|
date: date,
|
|
description: desc,
|
|
type_id: type_id,
|
|
account: data_layer::get_account(con, id),
|
|
tr_type: data_layer::get_transaction_type(con, type_id),
|
|
}
|
|
}
|
|
|
|
pub fn new_empty() -> Self {
|
|
Transaction {
|
|
id: 0,
|
|
account_id: 0,
|
|
amount: 0.0,
|
|
date: DateTime::from_timestamp(0, 0).unwrap(),
|
|
description: "".to_string(),
|
|
type_id: 0,
|
|
account: Account::new(0, "".to_string(), super::AccountType::Cash),
|
|
tr_type: TransactionType::new(0, "".to_string()),
|
|
}
|
|
}
|
|
|
|
pub fn get_id(&self) -> i64 {
|
|
return self.id;
|
|
}
|
|
|
|
pub fn get_amount(&self) -> f64 {
|
|
return self.amount;
|
|
}
|
|
|
|
pub fn get_date(&self) -> DateTime<Utc> {
|
|
return self.date;
|
|
}
|
|
|
|
pub fn get_desc(&self) -> String {
|
|
return self.description.clone();
|
|
}
|
|
|
|
pub fn get_account(&self) -> Account {
|
|
return self.account.clone();
|
|
}
|
|
|
|
pub fn get_type(&self) -> TransactionType {
|
|
return self.tr_type.clone();
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct TransactionType {
|
|
id: i64,
|
|
description: String,
|
|
}
|
|
|
|
impl TransactionType {
|
|
pub fn new(id: i64, desc: String) -> Self {
|
|
TransactionType {
|
|
id: id,
|
|
description: desc,
|
|
}
|
|
}
|
|
pub fn get_id(&self) -> i64 {
|
|
return self.id;
|
|
}
|
|
pub fn get_description(&self) -> String {
|
|
return self.description.clone();
|
|
}
|
|
}
|