summaryrefslogtreecommitdiff
path: root/src/types/journal.rs
diff options
context:
space:
mode:
authorPROINT <>2026-07-22 17:03:47 +0700
committerPROINT <>2026-07-22 17:03:47 +0700
commitccb6d208204fb286e469e87ad9c85a8c8b7be72a (patch)
tree5742b78074d4227d7c83fb1ad73c522e30af69a2 /src/types/journal.rs
parent9cb86b850699dc5b19e2582f5a2c64c5acc0a24b (diff)
Added JournalEntryRepositoryHEADmaster
Diffstat (limited to 'src/types/journal.rs')
-rw-r--r--src/types/journal.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/types/journal.rs b/src/types/journal.rs
index b09c50f..7dd3d63 100644
--- a/src/types/journal.rs
+++ b/src/types/journal.rs
@@ -22,12 +22,13 @@ pub enum InvalidJournalEntry {
AmountTooLarge(u64),
}
-#[derive(PartialEq)]
+#[derive(PartialEq, Clone, Copy)]
pub enum PostingType {
Debit,
Credit
}
+#[derive(Clone)]
pub struct Posting {
posting_id: PostingId,
pub posting_type: PostingType,
@@ -41,6 +42,12 @@ pub struct NewPosting {
pub amount: u64
}
+impl Posting {
+ pub(crate) fn from_parts(posting_id: PostingId, posting_type: PostingType, account_id: AccountId, amount: u64) -> Self {
+ Posting { posting_id, posting_type, account_id, amount }
+ }
+}
+
impl NewPosting {
fn new(posting_type: PostingType, account_id: AccountId, amount: u64) -> NewPosting {
NewPosting {
@@ -51,6 +58,7 @@ impl NewPosting {
}
}
+#[derive(Clone)]
pub struct JournalEntry {
journal_entry_id: JournalEntryId,
pub date: DateTime<Utc>,
@@ -64,6 +72,16 @@ pub struct NewJournalEntry {
pub description: String
}
+impl JournalEntry {
+ pub(crate) fn from_parts(journal_entry_id: JournalEntryId, date: DateTime<Utc>, postings: Vec<Posting>, description: String) -> Self {
+ JournalEntry { journal_entry_id, date, postings, description }
+ }
+
+ pub fn id(&self) -> JournalEntryId {
+ self.journal_entry_id
+ }
+}
+
impl NewJournalEntry {
fn new(date: DateTime<Utc>, postings: Vec<NewPosting>, description: impl Into<String>) -> NewJournalEntry {
NewJournalEntry {