quickbooks_types/models/
invoice.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5use super::common::{
6    Addr, CustomField, DeliveryInfo, Email, EmailStatus, LinkedTxn, MetaData, NtRef, PrintStatus,
7    TxnTaxDetail,
8};
9#[cfg(feature = "builder")]
10use crate::error::QBTypeError;
11use crate::{
12    LineField, QBCreatable, QBDeletable, QBFullUpdatable, QBItem, QBPDFable, QBSendable,
13    QBSparseUpdateable, QBVoidable,
14};
15
16#[skip_serializing_none]
17#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
18#[serde(rename_all = "PascalCase", default)]
19#[cfg_attr(
20    feature = "builder",
21    derive(Builder),
22    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
23)]
24/// Invoice
25///
26/// Represents a sales transaction billed to a customer creating an accounts receivable balance; consists of line items, taxes, payment terms, and delivery information.
27///
28/// Update semantics:
29/// - `QBCreatable::can_create()` returns true when both `customer_ref` and at least one valid line are present.
30/// - `QBFullUpdatable::can_full_update()` requires `has_read()` (ID + sync token) and `can_create()`.
31///
32/// API reference:
33/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice>
34pub struct Invoice {
35    /// The unique ID of the entity
36    pub id: Option<String>,
37    /// The unique sync token of the entity, used for concurrency control
38    pub sync_token: Option<String>,
39    /// Metadata about the entity
40    #[serde(skip_serializing)]
41    pub meta_data: Option<MetaData>,
42    /// Shipping address for the invoice
43    pub ship_from_addr: Option<Addr>,
44    /// Date when the items are shipped
45    pub ship_date: Option<NaiveDate>,
46    /// Shipping tracking number
47    pub tracking_num: Option<String>,
48    /// Reference to the class for the invoice
49    pub class_ref: Option<NtRef>,
50    /// Source of the transaction
51    pub txn_source: Option<String>,
52    /// Reference to the account where the deposit is made
53    pub deposit_to_account_ref: Option<NtRef>,
54    /// Indicates if online ACH payment is allowed
55    #[serde(rename = "AllowOnlineACHPayment")]
56    pub allow_online_ach_payment: Option<bool>,
57    /// Line items for the invoice
58    pub line: Option<LineField>,
59    /// Private note for the invoice
60    pub private_note: Option<String>,
61    /// Delivery information for the invoice
62    pub delivery_info: Option<DeliveryInfo>,
63    /// Carbon copy email address for billing emails
64    pub bill_email_cc: Option<Email>,
65    /// Blind carbon copy email address for billing emails
66    pub bill_email_bcc: Option<Email>,
67    /// Reference to the shipping method used
68    pub ship_method_reef: Option<NtRef>,
69    /// Indicates if tax is applied after discount
70    pub apply_tax_after_discount: Option<bool>,
71    /// Customer memo for the invoice
72    pub customer_memo: Option<NtRef>,
73    /// Reference to the customer for the invoice
74    pub customer_ref: Option<NtRef>,
75    /// Date of the transaction in YYYY-MM-DD format
76    pub txn_date: Option<NaiveDate>,
77    /// Domain of the transaction. `QBO` for `QuickBooks` Online.
78    pub domain: Option<String>,
79    /// Print status of the invoice
80    pub print_status: Option<PrintStatus>,
81    /// Reference to the sales terms for the invoice
82    pub sales_term_ref: Option<NtRef>,
83    /// Exchange rate for the transaction
84    pub exchange_rate: Option<f64>,
85    /// Deposit amount for the invoice
86    pub deposit: Option<f64>,
87    /// Indicates if online credit card payment is allowed
88    pub allow_online_credit_card_payment: Option<bool>,
89    /// Reference to the department for the invoice
90    pub department_ref: Option<NtRef>,
91    /// Email status of the invoice
92    pub email_status: Option<EmailStatus>,
93    /// Due date for the invoice
94    pub due_date: Option<NaiveDate>,
95    /// Balance amount in home currency
96    pub home_balance: Option<f64>,
97    /// Total amount of the invoice
98    pub total_amt: Option<f64>,
99    /// URL to the invoice in `QuickBooks` Online
100    pub invoice_link: Option<String>,
101    /// Reference to recurring template data
102    pub recur_data_ref: Option<NtRef>,
103    /// Reference to tax exemption information
104    pub tax_exemption_ref: Option<NtRef>,
105    /// Current balance of the invoice
106    pub balance: Option<f64>,
107    /// Total amount in home currency
108    pub home_total_amt: Option<f64>,
109    /// Indicates if the address is free-form
110    pub free_form_address: Option<bool>,
111    /// Indicates if the entity is a sparse object
112    #[serde(rename = "sparse")]
113    pub sparse: Option<bool>,
114    /// Document number for the invoice
115    pub doc_number: Option<String>,
116    /// Tax details for the transaction
117    pub txn_tax_detail: Option<TxnTaxDetail>,
118    /// Linked transactions to this invoice
119    pub linked_txn: Option<Vec<LinkedTxn>>,
120    /// Email address for billing
121    pub bill_email: Option<Email>,
122    /// Shipping address for the invoice
123    pub ship_addr: Option<Addr>,
124    /// Billing address for the invoice
125    pub bill_addr: Option<Addr>,
126    /// Custom fields for the invoice
127    pub custom_field: Option<Vec<CustomField>>,
128}
129
130impl QBCreatable for Invoice {
131    fn can_create(&self) -> bool {
132        self.customer_ref.is_some() && self.line.can_create()
133    }
134}
135
136impl QBDeletable for Invoice {}
137impl QBVoidable for Invoice {}
138
139impl QBFullUpdatable for Invoice {
140    fn can_full_update(&self) -> bool {
141        self.has_read() && self.can_create()
142    }
143}
144
145impl QBSparseUpdateable for Invoice {
146    fn can_sparse_update(&self) -> bool {
147        self.can_full_update()
148    }
149}
150
151impl QBSendable for Invoice {}
152impl QBPDFable for Invoice {}