diff options
Diffstat (limited to 'src/ynab/transaction.rs')
-rw-r--r-- | src/ynab/transaction.rs | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/ynab/transaction.rs b/src/ynab/transaction.rs index 326ee83..38e5d54 100644 --- a/src/ynab/transaction.rs +++ b/src/ynab/transaction.rs @@ -1,9 +1,98 @@ #[derive(Clone, Debug)] pub struct Transaction { + pub id: String, pub date: String, - pub payee: String, pub amount: i64, + pub memo: Option<String>, + pub cleared: String, + pub approved: bool, + pub flag_color: Option<String>, + pub account_id: String, + pub payee_id: Option<String>, + pub category_id: Option<String>, + pub import_id: Option<String>, + + pub payee: Option<String>, pub total_amount: i64, pub reimbursed: bool, pub selected: bool, } + +impl Transaction { + pub fn from_transaction( + t: &ynab_api::models::TransactionSummary, + ) -> Self { + let reimbursed = if let Some(color) = &t.flag_color { + color == "green" + } else { + false + }; + Self { + id: t.id.clone(), + date: t.date.clone(), + amount: t.amount, + memo: t.memo.clone(), + cleared: t.cleared.clone(), + approved: t.approved, + flag_color: t.flag_color.clone(), + account_id: t.account_id.clone(), + payee_id: t.payee_id.clone(), + category_id: t.category_id.clone(), + import_id: t.import_id.clone(), + + payee: None, + total_amount: t.amount, + reimbursed, + selected: false, + } + } + + pub fn from_sub_transaction( + t: &ynab_api::models::TransactionSummary, + st: &ynab_api::models::SubTransaction, + ) -> Self { + let reimbursed = if let Some(color) = &t.flag_color { + color == "green" + } else { + false + }; + Self { + id: t.id.clone(), + date: t.date.clone(), + amount: st.amount, + memo: t.memo.clone(), + cleared: t.cleared.clone(), + approved: t.approved, + flag_color: t.flag_color.clone(), + account_id: t.account_id.clone(), + payee_id: t.payee_id.clone(), + category_id: t.category_id.clone(), + import_id: t.import_id.clone(), + + payee: None, + total_amount: t.amount, + reimbursed, + selected: false, + } + } + + pub fn to_update_transaction( + &self, + ) -> ynab_api::models::UpdateTransaction { + let mut ut = ynab_api::models::UpdateTransaction::new( + self.account_id.clone(), + self.date.clone(), + self.amount, + ); + ut.id = Some(self.id.clone()); + ut.payee_id = self.payee_id.clone(); + ut.category_id = self.category_id.clone(); + ut.memo = self.memo.clone(); + ut.cleared = Some(self.cleared.clone()); + ut.approved = Some(self.approved); + ut.flag_color = self.flag_color.clone(); + ut.import_id = self.import_id.clone(); + + ut + } +} |