pub struct JournalEntry {
pub header: JournalEntryHeader,
pub lines: SmallVec<[JournalEntryLine; 4]>,
}Expand description
Complete journal entry with header and line items.
Represents a balanced double-entry bookkeeping transaction where total debits must equal total credits.
Uses SmallVec<[JournalEntryLine; 4]> for line items: entries with
4 or fewer lines (the common case) are stored inline on the stack,
avoiding heap allocation. Entries with more lines spill to the heap
transparently.
Fields§
§header: JournalEntryHeaderHeader with document metadata
lines: SmallVec<[JournalEntryLine; 4]>Line items (debit and credit postings). Inline for ≤4 lines (common case), heap-allocated for >4.
Implementations§
Source§impl JournalEntry
impl JournalEntry
Sourcepub fn new(header: JournalEntryHeader) -> Self
pub fn new(header: JournalEntryHeader) -> Self
Create a new journal entry with header and empty lines.
Sourcepub fn new_simple(
document_number: String,
company_code: String,
posting_date: NaiveDate,
description: String,
) -> Self
pub fn new_simple( document_number: String, company_code: String, posting_date: NaiveDate, description: String, ) -> Self
Create a new journal entry with basic parameters (convenience constructor).
This is a simplified constructor for backwards compatibility that creates a journal entry with the specified document number, company code, posting date, and description.
Sourcepub fn add_line(&mut self, line: JournalEntryLine)
pub fn add_line(&mut self, line: JournalEntryLine)
Add a line item to the journal entry.
Automatically sets the line’s document_id to match the header’s document_id.
Sourcepub fn total_debit(&self) -> Decimal
pub fn total_debit(&self) -> Decimal
Get the total debit amount.
Sourcepub fn total_credit(&self) -> Decimal
pub fn total_credit(&self) -> Decimal
Get the total credit amount.
Sourcepub fn is_balanced(&self) -> bool
pub fn is_balanced(&self) -> bool
Check if the journal entry is balanced (debits = credits).
Sourcepub fn balance_difference(&self) -> Decimal
pub fn balance_difference(&self) -> Decimal
Get the out-of-balance amount (should be zero for valid entries).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get the number of line items.
Sourcepub fn has_even_line_count(&self) -> bool
pub fn has_even_line_count(&self) -> bool
Check if the line count is even.
Sourcepub fn debit_credit_counts(&self) -> (usize, usize)
pub fn debit_credit_counts(&self) -> (usize, usize)
Get the count of debit and credit lines.
Sourcepub fn has_equal_debit_credit_counts(&self) -> bool
pub fn has_equal_debit_credit_counts(&self) -> bool
Check if debit and credit line counts are equal.
Sourcepub fn unique_accounts(&self) -> Vec<&str>
pub fn unique_accounts(&self) -> Vec<&str>
Get unique GL accounts used in this entry.
Sourcepub fn has_suspense_posting(&self) -> bool
pub fn has_suspense_posting(&self) -> bool
Check if any line posts to a suspense account.
Sourcepub fn company_code(&self) -> &str
pub fn company_code(&self) -> &str
Get the company code.
Sourcepub fn document_number(&self) -> String
pub fn document_number(&self) -> String
Get the document number (document_id as string).
Sourcepub fn posting_date(&self) -> NaiveDate
pub fn posting_date(&self) -> NaiveDate
Get the posting date.
Sourcepub fn document_date(&self) -> NaiveDate
pub fn document_date(&self) -> NaiveDate
Get the document date.
Sourcepub fn fiscal_year(&self) -> u16
pub fn fiscal_year(&self) -> u16
Get the fiscal year.
Sourcepub fn fiscal_period(&self) -> u8
pub fn fiscal_period(&self) -> u8
Get the fiscal period.
Sourcepub fn has_sod_violation(&self) -> bool
pub fn has_sod_violation(&self) -> bool
Check if this entry has a SOD violation.
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
Get the description (header text).
Sourcepub fn set_description(&mut self, description: String)
pub fn set_description(&mut self, description: String)
Set the description (header text).
Trait Implementations§
Source§impl Clone for JournalEntry
impl Clone for JournalEntry
Source§fn clone(&self) -> JournalEntry
fn clone(&self) -> JournalEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JournalEntry
impl Debug for JournalEntry
Source§impl<'de> Deserialize<'de> for JournalEntry
impl<'de> Deserialize<'de> for JournalEntry
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for JournalEntry
impl RefUnwindSafe for JournalEntry
impl Send for JournalEntry
impl Sync for JournalEntry
impl Unpin for JournalEntry
impl UnsafeUnpin for JournalEntry
impl UnwindSafe for JournalEntry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.