Skip to main content

AccountsReceivable

Struct AccountsReceivable 

Source
pub struct AccountsReceivable { /* private fields */ }
Expand description

Accounts Receivable interface.

Implementations§

Source§

impl AccountsReceivable

Source

pub fn get_aging_summary(&self) -> Result<ArAgingSummary>

Get overall AR aging summary.

§Example
use stateset_embedded::Commerce;

let commerce = Commerce::new(":memory:")?;

let aging = commerce.accounts_receivable().get_aging_summary()?;
println!("Current: ${}", aging.current);
println!("1-30 days: ${}", aging.days_1_30);
println!("31-60 days: ${}", aging.days_31_60);
println!("61-90 days: ${}", aging.days_61_90);
println!("90+ days: ${}", aging.days_over_90);
println!("Total: ${}", aging.total);
Source

pub fn get_customer_aging( &self, customer_id: Uuid, ) -> Result<Option<CustomerArAging>>

Get AR aging for a specific customer.

Source

pub fn get_aging_report( &self, filter: ArAgingFilter, ) -> Result<Vec<CustomerArAging>>

Get detailed AR aging report with filtering.

Source

pub fn log_collection_activity( &self, input: CreateCollectionActivity, ) -> Result<CollectionActivity>

Log a collection activity (call, email, dunning letter, etc.).

§Example
use stateset_embedded::{Commerce, CreateCollectionActivity, CollectionActivityType};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let activity = commerce.accounts_receivable().log_collection_activity(
    CreateCollectionActivity {
        invoice_id: Uuid::new_v4(),
        activity_type: CollectionActivityType::PhoneCall,
        notes: Some("Spoke with customer, promised to pay by Friday".into()),
        contact_method: Some("Phone".into()),
        contact_result: Some("Promise to pay".into()),
        performed_by: Some("John Collector".into()),
        ..Default::default()
    }
)?;
Source

pub fn list_collection_activities( &self, filter: CollectionActivityFilter, ) -> Result<Vec<CollectionActivity>>

List collection activities with filtering.

Source

pub fn update_collection_status( &self, invoice_id: Uuid, status: CollectionStatus, ) -> Result<()>

Update the collection status of an invoice.

Source

pub fn get_invoices_due_for_dunning(&self) -> Result<Vec<Invoice>>

Get invoices that are due for dunning letters.

Source

pub fn send_dunning_letter( &self, invoice_id: Uuid, letter_type: DunningLetterType, sent_by: Option<&str>, ) -> Result<CollectionActivity>

Send a dunning letter and log the activity.

§Example
use stateset_embedded::{Commerce, DunningLetterType};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let activity = commerce.accounts_receivable().send_dunning_letter(
    Uuid::new_v4(), // invoice_id
    DunningLetterType::Reminder1,
    Some("ar_system"),
)?;
Source

pub fn create_write_off(&self, input: CreateWriteOff) -> Result<WriteOff>

Create a write-off for an uncollectable invoice.

§Example
use stateset_embedded::{Commerce, CreateWriteOff, WriteOffReason};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let write_off = commerce.accounts_receivable().create_write_off(CreateWriteOff {
    invoice_id: Uuid::new_v4(),
    amount: dec!(500.00),
    reason: WriteOffReason::Uncollectable,
    notes: Some("Customer bankruptcy".into()),
    approved_by: Some("CFO".into()),
})?;
Source

pub fn get_write_off(&self, id: Uuid) -> Result<Option<WriteOff>>

Get a write-off by ID.

Source

pub fn list_write_offs(&self, filter: WriteOffFilter) -> Result<Vec<WriteOff>>

List write-offs with filtering.

Source

pub fn reverse_write_off(&self, id: Uuid) -> Result<WriteOff>

Reverse a write-off (restore invoice to collections).

Source

pub fn create_credit_memo(&self, input: CreateCreditMemo) -> Result<CreditMemo>

Create a credit memo for a customer.

§Example
use stateset_embedded::{Commerce, CreateCreditMemo, CreditMemoReason};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let memo = commerce.accounts_receivable().create_credit_memo(CreateCreditMemo {
    customer_id: Uuid::new_v4(),
    original_invoice_id: Some(Uuid::new_v4()),
    reason: CreditMemoReason::ReturnCredit,
    amount: dec!(150.00),
    notes: Some("Credit for returned merchandise".into()),
})?;
Source

pub fn get_credit_memo(&self, id: Uuid) -> Result<Option<CreditMemo>>

Get a credit memo by ID.

Source

pub fn get_credit_memo_by_number( &self, number: &str, ) -> Result<Option<CreditMemo>>

Get a credit memo by number.

Source

pub fn list_credit_memos( &self, filter: CreditMemoFilter, ) -> Result<Vec<CreditMemo>>

List credit memos with filtering.

Source

pub fn apply_credit_memo(&self, input: ApplyCreditMemo) -> Result<CreditMemo>

Apply a credit memo to an invoice.

Source

pub fn void_credit_memo(&self, id: Uuid) -> Result<CreditMemo>

Void a credit memo (only if not yet applied).

Source

pub fn get_unapplied_credits( &self, customer_id: Uuid, ) -> Result<Vec<CreditMemo>>

Get unapplied credit memos for a customer.

Source

pub fn apply_payment_to_invoices( &self, input: ApplyPaymentToInvoices, ) -> Result<Vec<ArPaymentApplication>>

Apply a payment to one or more invoices.

§Example
use stateset_embedded::{Commerce, ApplyPaymentToInvoices, InvoicePaymentApplication};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let applications = commerce.accounts_receivable().apply_payment_to_invoices(
    ApplyPaymentToInvoices {
        payment_id: Uuid::new_v4(),
        applications: vec![
            InvoicePaymentApplication {
                invoice_id: Uuid::new_v4(),
                amount: dec!(500.00),
            },
            InvoicePaymentApplication {
                invoice_id: Uuid::new_v4(),
                amount: dec!(250.00),
            },
        ],
    }
)?;
Source

pub fn get_payment_applications( &self, payment_id: Uuid, ) -> Result<Vec<ArPaymentApplication>>

Get all payment applications for a payment.

Source

pub fn unapply_payment(&self, application_id: Uuid) -> Result<()>

Unapply a payment application (remove application, restore invoice balance).

Source

pub fn get_customer_summary( &self, customer_id: Uuid, ) -> Result<Option<CustomerArSummary>>

Get AR summary for a customer.

Source

pub fn generate_statement( &self, request: GenerateStatementRequest, ) -> Result<CustomerStatement>

Generate a customer statement.

§Example
use stateset_embedded::{Commerce, GenerateStatementRequest};
use chrono::Utc;
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let statement = commerce.accounts_receivable().generate_statement(
    GenerateStatementRequest {
        customer_id: Uuid::new_v4(),
        period_start: None, // defaults to 30 days ago
        period_end: None,   // defaults to now
        include_paid_invoices: Some(false),
    }
)?;

println!("Statement for: {}", statement.customer_name);
println!("Closing balance: ${}", statement.closing_balance);
Source

pub fn get_total_outstanding(&self) -> Result<Decimal>

Get total outstanding receivables.

Source

pub fn get_dso(&self, days: i32) -> Result<Decimal>

Calculate Days Sales Outstanding (DSO).

Source

pub fn get_average_days_to_pay(&self, customer_id: Uuid) -> Result<Option<i32>>

Get average days to pay for a customer.

Source

pub fn get_customers_batch( &self, ids: Vec<Uuid>, ) -> Result<Vec<CustomerArSummary>>

Get AR summary for multiple customers.

Trait Implementations§

Source§

impl Debug for AccountsReceivable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more