Skip to main content

Invoices

Struct Invoices 

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

Invoice operations for billing and accounts receivable

Implementations§

Source§

impl Invoices

Source

pub fn create(&self, input: CreateInvoice) -> Result<Invoice>

Create a new invoice

§Example
use stateset_embedded::{Commerce, CreateInvoice, CreateInvoiceItem, InvoiceType};
use rust_decimal_macros::dec;
use uuid::Uuid;

let commerce = Commerce::new("./store.db")?;

let invoice = commerce.invoices().create(CreateInvoice {
    customer_id: Uuid::new_v4().into(),
    invoice_type: Some(InvoiceType::Standard),
    billing_email: Some("billing@company.com".into()),
    billing_name: Some("Acme Corp".into()),
    items: vec![
        CreateInvoiceItem {
            description: "Consulting - November".into(),
            quantity: dec!(40),
            unit_price: dec!(200.00),
            ..Default::default()
        },
        CreateInvoiceItem {
            description: "Software License".into(),
            quantity: dec!(1),
            unit_price: dec!(500.00),
            ..Default::default()
        },
    ],
    notes: Some("Payment due within 30 days".into()),
    ..Default::default()
})?;
Source

pub fn get(&self, id: Uuid) -> Result<Option<Invoice>>

Get an invoice by ID

Source

pub fn get_by_number(&self, invoice_number: &str) -> Result<Option<Invoice>>

Get an invoice by invoice number (e.g., “INV-20231215123456”)

Source

pub fn update(&self, id: Uuid, input: UpdateInvoice) -> Result<Invoice>

Update an invoice

Source

pub fn list(&self, filter: InvoiceFilter) -> Result<Vec<Invoice>>

List invoices with optional filtering

Source

pub fn for_customer(&self, customer_id: Uuid) -> Result<Vec<Invoice>>

Get all invoices for a customer

Source

pub fn for_order(&self, order_id: Uuid) -> Result<Vec<Invoice>>

Get all invoices for an order

Source

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

Send an invoice to the customer

Source

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

Mark invoice as viewed by customer

Source

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

Void an invoice

Source

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

Write off an uncollectible invoice

Source

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

Mark invoice as disputed

Source

pub fn add_item( &self, invoice_id: Uuid, item: CreateInvoiceItem, ) -> Result<InvoiceItem>

Add an item to an invoice

Source

pub fn update_item( &self, item_id: Uuid, input: CreateInvoiceItem, ) -> Result<InvoiceItem>

Update a line item

Source

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

Remove an item from an invoice

Source

pub fn get_items(&self, invoice_id: Uuid) -> Result<Vec<InvoiceItem>>

Get items for an invoice

Source

pub fn record_payment( &self, id: Uuid, payment: RecordInvoicePayment, ) -> Result<Invoice>

Record a payment against an invoice

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

let commerce = Commerce::new("./store.db")?;

// Record full payment
let invoice = commerce.invoices().record_payment(Uuid::new_v4(), RecordInvoicePayment {
    amount: dec!(1500.00),
    payment_method: Some("wire_transfer".into()),
    reference: Some("Wire ref: 123456789".into()),
    notes: Some("Paid in full".into()),
    ..Default::default()
})?;

// Record partial payment
let invoice = commerce.invoices().record_payment(Uuid::new_v4(), RecordInvoicePayment {
    amount: dec!(500.00),
    payment_method: Some("check".into()),
    reference: Some("Check #1234".into()),
    ..Default::default()
})?;
Source

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

Get all overdue invoices

Returns invoices that are past their due date and not fully paid.

Source

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

Recalculate invoice totals

Use this after modifying line items to update subtotal, tax, and total.

Source

pub fn count(&self, filter: InvoiceFilter) -> Result<u64>

Count invoices matching a filter

Source

pub fn customer_balance(&self, customer_id: Uuid) -> Result<Decimal>

Get the total outstanding balance for a customer

Trait Implementations§

Source§

impl Debug for Invoices

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