83 lines
1.6 KiB
Rust
83 lines
1.6 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 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;
|
|
}
|
|
|
|
pub fn get_account(&self) -> Account {
|
|
return self.account;
|
|
}
|
|
|
|
pub fn get_type(&self) -> TransactionType {
|
|
return self.tr_type;
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|