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/// API reference:
29/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice>
30pub struct Invoice {
31    /// The unique ID of the entity
32    pub id: Option<String>,
33    /// The unique sync token of the entity, used for concurrency control
34    pub sync_token: Option<String>,
35    /// Metadata about the entity
36    #[serde(skip_serializing)]
37    pub meta_data: Option<MetaData>,
38    /// Shipping address for the invoice
39    pub ship_from_addr: Option<Addr>,
40    /// Date when the items are shipped
41    pub ship_date: Option<NaiveDate>,
42    /// Shipping tracking number
43    pub tracking_num: Option<String>,
44    /// Reference to the class for the invoice
45    pub class_ref: Option<NtRef>,
46    /// Source of the transaction
47    pub txn_source: Option<String>,
48    /// Reference to the account where the deposit is made
49    pub deposit_to_account_ref: Option<NtRef>,
50    /// Indicates if online ACH payment is allowed
51    #[serde(rename = "AllowOnlineACHPayment")]
52    pub allow_online_ach_payment: Option<bool>,
53    /// Line items for the invoice
54    pub line: Option<LineField>,
55    /// Private note for the invoice
56    pub private_note: Option<String>,
57    /// Delivery information for the invoice
58    pub delivery_info: Option<DeliveryInfo>,
59    /// Carbon copy email address for billing emails
60    pub bill_email_cc: Option<Email>,
61    /// Blind carbon copy email address for billing emails
62    pub bill_email_bcc: Option<Email>,
63    /// Reference to the shipping method used
64    pub ship_method_reef: Option<NtRef>,
65    /// Indicates if tax is applied after discount
66    pub apply_tax_after_discount: Option<bool>,
67    /// Customer memo for the invoice
68    pub customer_memo: Option<NtRef>,
69    /// Reference to the customer for the invoice
70    pub customer_ref: Option<NtRef>,
71    /// Date of the transaction in YYYY-MM-DD format
72    pub txn_date: Option<NaiveDate>,
73    /// Domain of the transaction. `QBO` for `QuickBooks` Online.
74    pub domain: Option<String>,
75    /// Print status of the invoice
76    pub print_status: Option<PrintStatus>,
77    /// Reference to the sales terms for the invoice
78    pub sales_term_ref: Option<NtRef>,
79    /// Exchange rate for the transaction
80    pub exchange_rate: Option<f64>,
81    /// Deposit amount for the invoice
82    pub deposit: Option<f64>,
83    /// Indicates if online credit card payment is allowed
84    pub allow_online_credit_card_payment: Option<bool>,
85    /// Reference to the department for the invoice
86    pub department_ref: Option<NtRef>,
87    /// Email status of the invoice
88    pub email_status: Option<EmailStatus>,
89    /// Due date for the invoice
90    pub due_date: Option<NaiveDate>,
91    /// Balance amount in home currency
92    pub home_balance: Option<f64>,
93    /// Total amount of the invoice
94    pub total_amt: Option<f64>,
95    /// URL to the invoice in `QuickBooks` Online
96    pub invoice_link: Option<String>,
97    /// Reference to recurring template data
98    pub recur_data_ref: Option<NtRef>,
99    /// Reference to tax exemption information
100    pub tax_exemption_ref: Option<NtRef>,
101    /// Current balance of the invoice
102    pub balance: Option<f64>,
103    /// Total amount in home currency
104    pub home_total_amt: Option<f64>,
105    /// Indicates if the address is free-form
106    pub free_form_address: Option<bool>,
107    /// Indicates if the entity is a sparse object
108    #[serde(rename = "sparse")]
109    pub sparse: Option<bool>,
110    /// Document number for the invoice
111    pub doc_number: Option<String>,
112    /// Tax details for the transaction
113    pub txn_tax_detail: Option<TxnTaxDetail>,
114    /// Linked transactions to this invoice
115    pub linked_txn: Option<Vec<LinkedTxn>>,
116    /// Email address for billing
117    pub bill_email: Option<Email>,
118    /// Shipping address for the invoice
119    pub ship_addr: Option<Addr>,
120    /// Billing address for the invoice
121    pub bill_addr: Option<Addr>,
122    /// Custom fields for the invoice
123    pub custom_field: Option<Vec<CustomField>>,
124}
125
126impl QBCreatable for Invoice {
127    fn can_create(&self) -> bool {
128        self.customer_ref.is_some() && self.line.can_create()
129    }
130}
131
132impl QBDeletable for Invoice {}
133impl QBVoidable for Invoice {}
134
135impl QBFullUpdatable for Invoice {
136    fn can_full_update(&self) -> bool {
137        self.has_read() && self.can_create()
138        // TODO add the docnumber check, it's more complicated though
139    }
140}
141
142impl QBSparseUpdateable for Invoice {
143    fn can_sparse_update(&self) -> bool {
144        self.can_full_update() && self.sparse.is_some_and(|x| x)
145    }
146}
147
148impl QBSendable for Invoice {}
149impl QBPDFable for Invoice {}