pub struct AccountsPayable { /* private fields */ }Expand description
Accounts Payable management interface.
Implementations§
Source§impl AccountsPayable
impl AccountsPayable
Sourcepub fn create_bill(&self, input: CreateBill) -> Result<Bill>
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()
})?;Sourcepub fn get_bill_by_number(&self, number: &str) -> Result<Option<Bill>>
pub fn get_bill_by_number(&self, number: &str) -> Result<Option<Bill>>
Get a bill by bill number.
Sourcepub fn update_bill(&self, id: Uuid, input: UpdateBill) -> Result<Bill>
pub fn update_bill(&self, id: Uuid, input: UpdateBill) -> Result<Bill>
Update a bill.
Sourcepub fn list_bills(&self, filter: BillFilter) -> Result<Vec<Bill>>
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()
})?;Sourcepub fn delete_bill(&self, id: Uuid) -> Result<()>
pub fn delete_bill(&self, id: Uuid) -> Result<()>
Delete a bill (only if draft).
Sourcepub fn approve_bill(&self, id: Uuid) -> Result<Bill>
pub fn approve_bill(&self, id: Uuid) -> Result<Bill>
Approve a bill for payment.
Transitions bill from draft/pending to approved status.
Sourcepub fn cancel_bill(&self, id: Uuid) -> Result<Bill>
pub fn cancel_bill(&self, id: Uuid) -> Result<Bill>
Cancel a bill.
Sourcepub fn dispute_bill(&self, id: Uuid) -> Result<Bill>
pub fn dispute_bill(&self, id: Uuid) -> Result<Bill>
Mark a bill as disputed.
Sourcepub fn get_bill_items(&self, bill_id: Uuid) -> Result<Vec<BillItem>>
pub fn get_bill_items(&self, bill_id: Uuid) -> Result<Vec<BillItem>>
Get all line items for a bill.
Sourcepub fn add_bill_item(
&self,
bill_id: Uuid,
item: CreateBillItem,
) -> Result<BillItem>
pub fn add_bill_item( &self, bill_id: Uuid, item: CreateBillItem, ) -> Result<BillItem>
Add an item to a bill.
Sourcepub fn remove_bill_item(&self, item_id: Uuid) -> Result<()>
pub fn remove_bill_item(&self, item_id: Uuid) -> Result<()>
Remove an item from a bill.
Sourcepub fn count_bills(&self, filter: BillFilter) -> Result<u64>
pub fn count_bills(&self, filter: BillFilter) -> Result<u64>
Count bills matching the filter.
Sourcepub fn get_overdue_bills(&self) -> Result<Vec<Bill>>
pub fn get_overdue_bills(&self) -> Result<Vec<Bill>>
Get all overdue bills.
Returns bills past their due date that haven’t been paid.
Sourcepub fn get_bills_due_soon(&self, days: i32) -> Result<Vec<Bill>>
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);
}Sourcepub fn three_way_match(
&self,
bill_id: Uuid,
tolerance_percent: Option<Decimal>,
) -> Result<ThreeWayMatchResult>
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);Sourcepub fn create_payment(&self, input: CreateBillPayment) -> Result<BillPayment>
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()
})?;Sourcepub fn get_payment(&self, id: Uuid) -> Result<Option<BillPayment>>
pub fn get_payment(&self, id: Uuid) -> Result<Option<BillPayment>>
Get a payment by ID.
Sourcepub fn get_payment_by_number(&self, number: &str) -> Result<Option<BillPayment>>
pub fn get_payment_by_number(&self, number: &str) -> Result<Option<BillPayment>>
Get a payment by payment number.
Sourcepub fn list_payments(
&self,
filter: BillPaymentFilter,
) -> Result<Vec<BillPayment>>
pub fn list_payments( &self, filter: BillPaymentFilter, ) -> Result<Vec<BillPayment>>
List payments with optional filtering.
Sourcepub fn void_payment(&self, id: Uuid) -> Result<BillPayment>
pub fn void_payment(&self, id: Uuid) -> Result<BillPayment>
Void a payment.
Reverses the effect of the payment on associated bills.
Sourcepub fn clear_payment(&self, id: Uuid) -> Result<BillPayment>
pub fn clear_payment(&self, id: Uuid) -> Result<BillPayment>
Mark a payment as cleared (e.g., check cleared the bank).
Sourcepub fn get_payment_allocations(
&self,
payment_id: Uuid,
) -> Result<Vec<PaymentAllocation>>
pub fn get_payment_allocations( &self, payment_id: Uuid, ) -> Result<Vec<PaymentAllocation>>
Get allocations for a payment.
Sourcepub fn get_payments_for_bill(&self, bill_id: Uuid) -> Result<Vec<BillPayment>>
pub fn get_payments_for_bill(&self, bill_id: Uuid) -> Result<Vec<BillPayment>>
Get all payments for a specific bill.
Sourcepub fn count_payments(&self, filter: BillPaymentFilter) -> Result<u64>
pub fn count_payments(&self, filter: BillPaymentFilter) -> Result<u64>
Count payments matching the filter.
Sourcepub fn pay_bill(&self, bill_id: Uuid, input: PayBill) -> Result<Bill>
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()
},
)?;Sourcepub fn create_payment_run(&self, input: CreatePaymentRun) -> Result<PaymentRun>
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);Sourcepub fn get_payment_run(&self, id: Uuid) -> Result<Option<PaymentRun>>
pub fn get_payment_run(&self, id: Uuid) -> Result<Option<PaymentRun>>
Get a payment run by ID.
Sourcepub fn list_payment_runs(
&self,
filter: PaymentRunFilter,
) -> Result<Vec<PaymentRun>>
pub fn list_payment_runs( &self, filter: PaymentRunFilter, ) -> Result<Vec<PaymentRun>>
List payment runs with optional filtering.
Sourcepub fn approve_payment_run(
&self,
id: Uuid,
approved_by: &str,
) -> Result<PaymentRun>
pub fn approve_payment_run( &self, id: Uuid, approved_by: &str, ) -> Result<PaymentRun>
Approve a payment run.
Requires approval before processing.
Sourcepub fn process_payment_run(&self, id: Uuid) -> Result<PaymentRun>
pub fn process_payment_run(&self, id: Uuid) -> Result<PaymentRun>
Process a payment run.
Creates individual payments for each bill and updates their status.
Sourcepub fn cancel_payment_run(&self, id: Uuid) -> Result<PaymentRun>
pub fn cancel_payment_run(&self, id: Uuid) -> Result<PaymentRun>
Cancel a payment run.
Sourcepub fn get_payment_run_bills(&self, run_id: Uuid) -> Result<Vec<Bill>>
pub fn get_payment_run_bills(&self, run_id: Uuid) -> Result<Vec<Bill>>
Get bills included in a payment run.
Sourcepub fn get_aging_summary(&self) -> Result<ApAgingSummary>
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);Sourcepub fn get_supplier_summary(
&self,
supplier_id: Uuid,
) -> Result<Option<SupplierApSummary>>
pub fn get_supplier_summary( &self, supplier_id: Uuid, ) -> Result<Option<SupplierApSummary>>
Get AP summary for a specific supplier.
Sourcepub fn get_total_outstanding(&self) -> Result<Decimal>
pub fn get_total_outstanding(&self) -> Result<Decimal>
Get total AP outstanding across all suppliers.
Sourcepub fn create_bills_batch(
&self,
inputs: Vec<CreateBill>,
) -> Result<BatchResult<Bill>>
pub fn create_bills_batch( &self, inputs: Vec<CreateBill>, ) -> Result<BatchResult<Bill>>
Create multiple bills in a batch.