Skip to main content

AccountsPayable

Struct AccountsPayable 

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

Accounts Payable management interface.

Implementations§

Source§

impl AccountsPayable

Source

pub fn create_bill(&self, input: CreateBill) -> Result<Bill>

Create a new bill (supplier invoice).

§Example
use stateset_embedded::{Commerce, CreateBill, CreateBillItem};
use rust_decimal_macros::dec;
use chrono::{Utc, Duration};
use uuid::Uuid;

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

let bill = commerce.accounts_payable().create_bill(CreateBill {
    supplier_id: Uuid::new_v4(),
    due_date: Utc::now() + Duration::days(30),
    payment_terms: Some("Net 30".into()),
    reference_number: Some("INV-12345".into()),
    items: vec![
        CreateBillItem {
            description: "Raw materials".into(),
            quantity: dec!(100),
            unit_price: dec!(10.00),
            account_code: Some("5010".into()),
            ..Default::default()
        },
        CreateBillItem {
            description: "Shipping".into(),
            quantity: dec!(1),
            unit_price: dec!(50.00),
            account_code: Some("5020".into()),
            ..Default::default()
        },
    ],
    ..Default::default()
})?;
Source

pub fn get_bill(&self, id: Uuid) -> Result<Option<Bill>>

Get a bill by ID.

Source

pub fn get_bill_by_number(&self, number: &str) -> Result<Option<Bill>>

Get a bill by bill number.

Source

pub fn update_bill(&self, id: Uuid, input: UpdateBill) -> Result<Bill>

Update a bill.

Source

pub fn list_bills(&self, filter: BillFilter) -> Result<Vec<Bill>>

List bills with optional filtering.

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

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

// Get all overdue bills for a supplier
let bills = commerce.accounts_payable().list_bills(BillFilter {
    supplier_id: Some(Uuid::new_v4()),
    overdue_only: Some(true),
    limit: Some(50),
    ..Default::default()
})?;
Source

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

Delete a bill (only if draft).

Source

pub fn approve_bill(&self, id: Uuid) -> Result<Bill>

Approve a bill for payment.

Transitions bill from draft/pending to approved status.

Source

pub fn cancel_bill(&self, id: Uuid) -> Result<Bill>

Cancel a bill.

Source

pub fn dispute_bill(&self, id: Uuid) -> Result<Bill>

Mark a bill as disputed.

Source

pub fn get_bill_items(&self, bill_id: Uuid) -> Result<Vec<BillItem>>

Get all line items for a bill.

Source

pub fn add_bill_item( &self, bill_id: Uuid, item: CreateBillItem, ) -> Result<BillItem>

Add an item to a bill.

Source

pub fn remove_bill_item(&self, item_id: Uuid) -> Result<()>

Remove an item from a bill.

Source

pub fn count_bills(&self, filter: BillFilter) -> Result<u64>

Count bills matching the filter.

Source

pub fn get_overdue_bills(&self) -> Result<Vec<Bill>>

Get all overdue bills.

Returns bills past their due date that haven’t been paid.

Source

pub fn get_bills_due_soon(&self, days: i32) -> Result<Vec<Bill>>

Get bills due soon (within specified days).

§Example
use stateset_embedded::Commerce;

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

// Get bills due in the next 7 days
let bills = commerce.accounts_payable().get_bills_due_soon(7)?;
for bill in bills {
    println!("Bill {} due on {}: ${}", bill.bill_number, bill.due_date, bill.amount_due);
}
Source

pub fn three_way_match( &self, bill_id: Uuid, tolerance_percent: Option<Decimal>, ) -> Result<ThreeWayMatchResult>

Perform a three-way match (purchase order vs receipts vs bill) for a bill.

Loads the bill’s linked purchase order lines and every non-cancelled receipt recorded against that PO, then compares ordered quantity/cost, received quantity, and billed quantity/cost line by line. The result is computed on read and never persisted.

tolerance_percent is a relative tolerance (e.g. dec!(5) allows 5% deviation); None means exact matching.

Returns stateset_core::MatchStatus::NotRequired when the bill has no purchase order, and an error if the bill does not exist.

§Example
use stateset_embedded::Commerce;
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;
let result = commerce.accounts_payable().three_way_match(Uuid::new_v4(), Some(dec!(5)))?;
println!("match status: {:?}", result.match_status);
Source

pub fn create_payment(&self, input: CreateBillPayment) -> Result<BillPayment>

Create a payment to a supplier.

§Example
use stateset_embedded::{Commerce, CreateBillPayment, PaymentMethodAP, PaymentAllocationInput};
use rust_decimal_macros::dec;
use uuid::Uuid;

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

let payment = commerce.accounts_payable().create_payment(CreateBillPayment {
    supplier_id: Uuid::new_v4(),
    payment_method: PaymentMethodAP::Check,
    amount: dec!(1000.00),
    check_number: Some("10234".into()),
    allocations: vec![
        PaymentAllocationInput {
            bill_id: Uuid::new_v4(), // bill ID
            amount: dec!(500.00),
        },
        PaymentAllocationInput {
            bill_id: Uuid::new_v4(), // another bill ID
            amount: dec!(500.00),
        },
    ],
    ..Default::default()
})?;
Source

pub fn get_payment(&self, id: Uuid) -> Result<Option<BillPayment>>

Get a payment by ID.

Source

pub fn get_payment_by_number(&self, number: &str) -> Result<Option<BillPayment>>

Get a payment by payment number.

Source

pub fn list_payments( &self, filter: BillPaymentFilter, ) -> Result<Vec<BillPayment>>

List payments with optional filtering.

Source

pub fn void_payment(&self, id: Uuid) -> Result<BillPayment>

Void a payment.

Reverses the effect of the payment on associated bills.

Source

pub fn clear_payment(&self, id: Uuid) -> Result<BillPayment>

Mark a payment as cleared (e.g., check cleared the bank).

Source

pub fn get_payment_allocations( &self, payment_id: Uuid, ) -> Result<Vec<PaymentAllocation>>

Get allocations for a payment.

Source

pub fn get_payments_for_bill(&self, bill_id: Uuid) -> Result<Vec<BillPayment>>

Get all payments for a specific bill.

Source

pub fn count_payments(&self, filter: BillPaymentFilter) -> Result<u64>

Count payments matching the filter.

Source

pub fn pay_bill(&self, bill_id: Uuid, input: PayBill) -> Result<Bill>

Pay a bill directly with a single payment.

Convenience method that creates a payment and allocates it fully to the specified bill.

§Example
use stateset_embedded::{Commerce, PayBill, PaymentMethodAP};
use rust_decimal_macros::dec;
use uuid::Uuid;

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

// Pay a bill
let payment = commerce.accounts_payable().pay_bill(
    Uuid::new_v4(), // bill_id
    stateset_core::PayBill {
        amount: dec!(500.00),
        payment_method: PaymentMethodAP::Check,
        ..Default::default()
    },
)?;
Source

pub fn create_payment_run(&self, input: CreatePaymentRun) -> Result<PaymentRun>

Create a payment run (batch payment).

Groups multiple bills together for a scheduled payment batch.

§Example
use stateset_embedded::{Commerce, CreatePaymentRun, PaymentMethodAP};
use chrono::{Utc, Duration};
use uuid::Uuid;

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

let run = commerce.accounts_payable().create_payment_run(CreatePaymentRun {
    payment_date: Utc::now() + Duration::days(7),
    payment_method: PaymentMethodAP::Ach,
    bill_ids: vec![
        Uuid::new_v4(), // approved bill 1
        Uuid::new_v4(), // approved bill 2
    ],
    created_by: Some("finance_user".into()),
    notes: Some("Weekly ACH run".into()),
})?;

println!("Created payment run {}", run.run_number);
Source

pub fn get_payment_run(&self, id: Uuid) -> Result<Option<PaymentRun>>

Get a payment run by ID.

Source

pub fn list_payment_runs( &self, filter: PaymentRunFilter, ) -> Result<Vec<PaymentRun>>

List payment runs with optional filtering.

Source

pub fn approve_payment_run( &self, id: Uuid, approved_by: &str, ) -> Result<PaymentRun>

Approve a payment run.

Requires approval before processing.

Source

pub fn process_payment_run(&self, id: Uuid) -> Result<PaymentRun>

Process a payment run.

Creates individual payments for each bill and updates their status.

Source

pub fn cancel_payment_run(&self, id: Uuid) -> Result<PaymentRun>

Cancel a payment run.

Source

pub fn get_payment_run_bills(&self, run_id: Uuid) -> Result<Vec<Bill>>

Get bills included in a payment run.

Source

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

Get AP aging summary.

Returns outstanding amounts bucketed by age (current, 1-30, 31-60, etc.).

§Example
use stateset_embedded::Commerce;

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

let aging = commerce.accounts_payable().get_aging_summary()?;
println!("AP 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!("  Over 90 days: ${}", aging.days_over_90);
println!("  Total: ${}", aging.total);
Source

pub fn get_supplier_summary( &self, supplier_id: Uuid, ) -> Result<Option<SupplierApSummary>>

Get AP summary for a specific supplier.

Source

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

Get total AP outstanding across all suppliers.

Source

pub fn create_bills_batch( &self, inputs: Vec<CreateBill>, ) -> Result<BatchResult<Bill>>

Create multiple bills in a batch.

Source

pub fn get_bills_batch(&self, ids: Vec<Uuid>) -> Result<Vec<Bill>>

Get multiple bills by ID.

Trait Implementations§

Source§

impl Debug for AccountsPayable

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