quickbooks_types/models/
common.rs

1//! Common supporting value types used across `QuickBooks` entity models.
2//!
3//! These types are embedded within top-level entities (e.g. Invoice, Customer) and
4//! do not have standalone API endpoints. They encapsulate reusable concepts such
5//! as references (`NtRef`), metadata timestamps (`MetaData`), addresses (`Addr`),
6//! and contact info.
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11use crate::LineField;
12
13/// `NtRef`
14///
15/// Generic reference to another `QuickBooks` entity. Appears in many `*Ref` fields.
16/// Provides optional type discriminator (`entity_ref_type`), display `name`, and underlying
17/// `value` identifier returned by the API.
18#[skip_serializing_none]
19#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
20#[serde(default)]
21pub struct NtRef {
22    #[serde(rename = "type")]
23    pub entity_ref_type: Option<String>,
24    #[serde(alias = "Name")]
25    pub name: Option<String>,
26    #[serde(alias = "Value")]
27    pub value: Option<String>,
28}
29
30impl From<&str> for NtRef {
31    fn from(value: &str) -> Self {
32        Self {
33            value: Some(value.into()),
34            ..Default::default()
35        }
36    }
37}
38
39impl From<(&str, &str)> for NtRef {
40    fn from(value: (&str, &str)) -> Self {
41        Self {
42            name: Some(value.0.into()),
43            value: Some(value.1.into()),
44            ..Default::default()
45        }
46    }
47}
48
49impl From<String> for NtRef {
50    fn from(value: String) -> Self {
51        Self {
52            value: Some(value),
53            ..Default::default()
54        }
55    }
56}
57
58impl From<(String, String)> for NtRef {
59    fn from(value: (String, String)) -> Self {
60        let (name, value) = value;
61        Self {
62            name: Some(name),
63            value: Some(value),
64            ..Default::default()
65        }
66    }
67}
68
69/// `MetaData`
70///
71/// Immutable timestamps supplied by `QuickBooks` Online for auditing: creation (`create_time`)
72/// and last modification (`last_updated_time`).
73#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
74#[serde(rename_all = "PascalCase")]
75pub struct MetaData {
76    pub create_time: DateTime<Utc>,
77    pub last_updated_time: DateTime<Utc>,
78}
79
80/// Email
81///
82/// Represents an email address container used in entities to support optional future
83/// structure; currently only holds a single `address` string.
84#[skip_serializing_none]
85#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
86#[serde(rename_all = "PascalCase", default)]
87pub struct Email {
88    pub address: Option<String>,
89}
90
91/// Address information
92#[skip_serializing_none]
93#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
94#[serde(rename_all = "PascalCase", default)]
95pub struct Addr {
96    pub city: Option<String>,
97    pub country: Option<String>,
98    pub country_sub_division_code: Option<String>,
99    pub id: Option<String>,
100    pub line1: Option<String>,
101    pub postal_code: Option<String>,
102}
103
104impl std::fmt::Display for Addr {
105    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106        write!(
107            f,
108            "{}, {}, {}, {} {}",
109            self.line1.as_ref().unwrap_or(&String::new()),
110            self.city.as_ref().unwrap_or(&String::new()),
111            self.country_sub_division_code
112                .as_ref()
113                .unwrap_or(&String::new()),
114            self.country.as_ref().unwrap_or(&String::new()),
115            self.postal_code.as_ref().unwrap_or(&String::new())
116        )
117    }
118}
119
120/// Web Address
121///
122/// Represents a web address (URL) associated with an entity.
123#[skip_serializing_none]
124#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
125pub struct WebAddr {
126    #[serde(default, rename = "URL")]
127    url: Option<String>,
128}
129
130/// Phone Number
131///
132/// Represents a phone number associated with an entity.
133#[skip_serializing_none]
134#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
135#[serde(rename_all = "PascalCase", default)]
136pub struct PhoneNumber {
137    pub free_form_number: Option<String>,
138}
139
140/// Linked Transaction
141///
142/// Information about a linked transaction.
143#[skip_serializing_none]
144#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
145#[serde(rename_all = "PascalCase", default)]
146pub struct LinkedTxn {
147    pub txn_id: Option<String>,
148    pub txn_type: Option<String>,
149}
150
151/// `CustomField`
152///
153/// Custom field information
154#[skip_serializing_none]
155#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
156#[serde(rename_all = "PascalCase", default)]
157pub struct CustomField {
158    pub definition_id: Option<String>,
159    pub string_value: Option<String>,
160    pub name: Option<String>,
161    #[serde(rename = "type")]
162    pub field_type: Option<String>,
163}
164
165/// `MarkupInfo`
166///
167/// Information about markup applied to a transaction.
168#[skip_serializing_none]
169#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
170#[serde(rename_all = "PascalCase", default)]
171pub struct MarkupInfo {
172    pub percent_based: Option<bool>,
173    pub value: Option<f64>,
174    pub percent: Option<f64>,
175    pub price_level_ref: Option<NtRef>,
176}
177
178/// `TxnTaxDetail`
179///
180/// Details about the tax applied to a transaction.
181#[skip_serializing_none]
182#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
183#[serde(rename_all = "PascalCase", default)]
184pub struct TxnTaxDetail {
185    pub txn_tax_code_ref: Option<NtRef>,
186    pub total_tax: Option<f64>,
187    pub tax_line: Option<LineField>,
188}
189
190/// Delivery Information
191///
192/// Information about delivery for the transaction.
193#[skip_serializing_none]
194#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
195#[serde(rename_all = "PascalCase", default)]
196pub struct DeliveryInfo {
197    pub delivery_type: String,
198    pub delivery_time: DateTime<Utc>,
199}
200
201/// `CreditCardPayment`
202///
203/// Information about a credit card payment for the transaction.
204#[skip_serializing_none]
205#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
206#[serde(rename_all = "PascalCase", default)]
207pub struct CreditCardPayment {
208    pub credit_charge_response: Option<CreditChargeResponse>,
209    pub credit_charge_info: Option<CreditChargeInfo>,
210}
211
212/// `CreditChargeResponse`
213///
214/// Information about a credit charge for a transaction.
215#[skip_serializing_none]
216#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
217#[serde(rename_all = "PascalCase", default)]
218pub struct CreditChargeResponse {
219    pub status: Option<CCPaymentStatus>,
220    pub auth_code: Option<String>,
221    pub txn_authorization_time: Option<DateTime<Utc>>,
222    #[serde(rename = "CCTransId")]
223    pub cc_trans_id: Option<String>,
224}
225
226/// `CCPaymentStatus` Enum
227///
228/// Status of the credit card payment
229#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
230pub enum CCPaymentStatus {
231    Completed,
232    #[default]
233    Unkown,
234}
235
236/// `CreditChargeInfo`
237///
238/// Information about a credit card payment for the transaction.
239#[skip_serializing_none]
240#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
241#[serde(rename_all = "PascalCase", default)]
242pub struct CreditChargeInfo {
243    cc_expiry_month: Option<u32>,
244    process_payment: Option<bool>,
245    postal_code: Option<String>,
246    amount: Option<f64>,
247    name_on_acct: Option<String>,
248    cc_expiry_year: Option<u32>,
249    #[serde(rename = "type")]
250    card_type: Option<String>,
251    bill_addr_street: Option<String>,
252}
253
254/// `PrintStatus` Enum
255///
256/// Status of whether a document needs to be printed or not
257#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
258pub enum PrintStatus {
259    #[default]
260    NotSet,
261    NeedToPrint,
262    PrintComplete,
263}
264
265/// `EmailStatus` Enum
266///
267/// Status of the email
268#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
269pub enum EmailStatus {
270    #[default]
271    NotSet,
272    NotSent,
273    NeedToSend,
274    EmailSent,
275}
276
277/// `GlobalTaxCalculation` Enum
278///
279/// Method in which tax is applied
280#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
281pub enum GlobalTaxCalculation {
282    WithinFrance,
283    FranceOverseas,
284    OutsideFranceWithEU,
285    OutsideEU,
286    #[default]
287    #[serde(skip)]
288    Other,
289}