Skip to main content

Invoice

Struct Invoice 

Source
pub struct Invoice {
Show 24 fields pub document_format: DocumentFormat, pub invoice_type: InvoiceType, pub invoice_number: Option<String>, pub account_name: Option<String>, pub customer_id: Option<String>, pub billing_period: Option<String>, pub invoice_date: Option<NaiveDate>, pub due_date: Option<NaiveDate>, pub currency: Currency, pub vendor: Party, pub customer: Party, pub line_items: Vec<LineItem>, pub subtotal: Option<f64>, pub discount_amount: Option<f64>, pub discount_rate: Option<f64>, pub tax_summaries: Vec<TaxSummary>, pub total_tax: Option<f64>, pub total_amount: f64, pub amount_paid: Option<f64>, pub amount_due: Option<f64>, pub payment_info: Option<PaymentInfo>, pub notes: Option<String>, pub raw_text: Option<String>, pub metadata: HashMap<String, String>,
}
Expand description

发票主结构体

包含发票的所有核心信息,支持多种发票格式的解析结果存储

Fields§

§document_format: DocumentFormat§invoice_type: InvoiceType§invoice_number: Option<String>

发票号码

§account_name: Option<String>

账户名称/项目别名(如 AWS Account No 后括号内的名称)

§customer_id: Option<String>

客户ID

§billing_period: Option<String>

账单年月(格式:YYYY-MM,如 2025-01)

§invoice_date: Option<NaiveDate>

发票日期

§due_date: Option<NaiveDate>

付款截止日期

§currency: Currency

货币类型

§vendor: Party

供应商/卖方信息

§customer: Party

客户/买方信息

§line_items: Vec<LineItem>

行项目列表(商品/服务明细)

§subtotal: Option<f64>

小计金额(税前)

§discount_amount: Option<f64>

折扣金额(负数表示折扣)

§discount_rate: Option<f64>

折扣比例(百分比,如 5.0 表示 5%)

§tax_summaries: Vec<TaxSummary>

税务汇总列表

§total_tax: Option<f64>

总税额

§total_amount: f64

总金额(含税)

§amount_paid: Option<f64>

已付金额

§amount_due: Option<f64>

应付金额(未付余额)

§payment_info: Option<PaymentInfo>

付款信息

§notes: Option<String>

备注/附注

§raw_text: Option<String>

原始文本(PDF提取的原文)

§metadata: HashMap<String, String>

元数据(扩展字段,如账单周期等)

Implementations§

Source§

impl Invoice

Source

pub fn new() -> Self

创建新的空发票实例

Source

pub fn to_json(&self) -> Result<String, Error>

序列化为格式化的 JSON 字符串

Source

pub fn to_json_compact(&self) -> Result<String, Error>

序列化为紧凑的 JSON 字符串

Source

pub fn from_json(json: &str) -> Result<Self, Error>

从 JSON 字符串反序列化

Source

pub fn calculate_subtotal(&self) -> f64

根据行项目计算小计金额

Source

pub fn calculate_total_tax(&self) -> f64

根据税务汇总计算总税额

Source

pub fn is_paid(&self) -> bool

判断发票是否已付清

Source

pub fn validate_line_items(&self) -> InvoiceValidation

Trait Implementations§

Source§

impl Clone for Invoice

Source§

fn clone(&self) -> Invoice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Invoice

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Invoice

Source§

fn default() -> Invoice

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Invoice

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Invoice

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,