quickbooks_types/reports/
models.rs

1use chrono::{DateTime, FixedOffset, NaiveDate};
2use serde::{Deserialize, Serialize};
3use serde_with::skip_serializing_none;
4
5/// Corresponds to the `ColumnTypeEnum`.
6#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
7#[serde(rename_all = "PascalCase")]
8pub enum ColumnTypeEnum {
9    /// Represents an account type, such as a bank or credit card account.
10    Account,
11    /// Monetary values.
12    Money,
13    /// This column type is used for rates (e.g., hourly rates).
14    Rate,
15    /// Customer ID or name.
16    Customer,
17    /// Vendor ID or name.
18    Vendor,
19    /// Employee ID or name.
20    Employee,
21    /// Item ID or name.
22    ProductsAndService,
23    /// Department ID or name.
24    Department,
25    /// Class ID or name.
26    Class,
27    /// String values.
28    StringValue,
29}
30
31impl ColumnTypeEnum {
32    /// Returns the string representation of the column type.
33    #[must_use] 
34    pub fn as_str(&self) -> &str {
35        match self {
36            ColumnTypeEnum::Account => "Account",
37            ColumnTypeEnum::Money => "Money",
38            ColumnTypeEnum::Rate => "Rate",
39            ColumnTypeEnum::Customer => "Customer",
40            ColumnTypeEnum::Vendor => "Vendor",
41            ColumnTypeEnum::Employee => "Employee",
42            ColumnTypeEnum::ProductsAndService => "ProductsAndService",
43            ColumnTypeEnum::Department => "Department",
44            ColumnTypeEnum::Class => "Class",
45            ColumnTypeEnum::StringValue => "StringValue",
46        }
47    }
48}
49
50impl std::fmt::Display for ColumnTypeEnum {
51    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52        write!(f, "{}", self.as_str())
53    }
54}
55
56/// Corresponds to the `RowTypeEnum`.
57#[derive(Debug, Serialize, Deserialize)]
58pub enum RowTypeEnum {
59    Section,
60    Data,
61}
62
63#[derive(Debug, Serialize, Deserialize)]
64pub enum ReportBasisEnum {
65    Cash,
66    Accrual,
67}
68
69#[skip_serializing_none]
70#[derive(Debug, Serialize, Deserialize)]
71#[serde(rename_all = "PascalCase")]
72pub struct NameValue {
73    pub name: Option<String>,
74    pub value: Option<String>,
75}
76
77/// Corresponds to the `Attribute`.
78#[derive(Debug, Serialize, Deserialize, Clone)]
79pub struct Attribute {
80    #[serde(rename = "Type")]
81    pub type_: String,
82    #[serde(rename = "Value")]
83    pub value: String,
84}
85
86/// Corresponds to the `Attributes`.
87#[skip_serializing_none]
88#[derive(Debug, Serialize, Deserialize, Clone)]
89pub struct Attributes {
90    #[serde(rename = "Attribute", default)]
91    pub attribute: Option<Vec<Attribute>>,
92}
93
94/// Corresponds to the `Columns`.
95#[skip_serializing_none]
96#[derive(Debug, Serialize, Deserialize)]
97pub struct Columns {
98    #[serde(rename = "Column", default)]
99    pub column: Option<Vec<Column>>,
100}
101
102/// Corresponds to the `Column`.
103#[skip_serializing_none]
104#[derive(Debug, Serialize, Deserialize)]
105#[serde(rename_all = "PascalCase")]
106pub struct Column {
107    pub col_title: String,
108    pub col_type: ColumnTypeEnum,
109    /// Repeats zero or more times, thus Option<Vec<...>>
110    pub meta_data: Option<Vec<NameValue>>,
111    /// Nested subcolumns
112    pub columns: Option<Columns>,
113}
114
115/// Corresponds to the `ColData`.
116#[skip_serializing_none]
117#[derive(Debug, Serialize, Deserialize, Clone)]
118pub struct ColData {
119    /// Nested Attributes element
120    #[serde(rename = "Attributes", default)]
121    pub attributes: Option<Attributes>,
122    pub value: Option<String>,
123    pub id: Option<String>,
124    pub href: Option<String>,
125}
126
127/// Represents a collection of `ColData` elements.
128#[skip_serializing_none]
129#[derive(Debug, Serialize, Deserialize)]
130#[serde(rename_all = "PascalCase")]
131pub struct ColDataCollection {
132    pub col_data: Option<Vec<ColData>>,
133}
134
135/// Corresponds to the `Rows`.
136#[skip_serializing_none]
137#[derive(Debug, Serialize, Deserialize)]
138pub struct Rows {
139    #[serde(rename = "Row", default)]
140    pub row: Option<Vec<Row>>,
141}
142
143/// The `Row` complexType has a choice: either (Header, Rows, Summary) or (`ColData` repeated).
144#[skip_serializing_none]
145#[derive(Debug, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum RowContent {
148    /// Contains a list of `ColData` elements.
149    Coldata {
150        #[serde(rename = "ColData")]
151        col_data: Vec<ColData>,
152    },
153    /// Contains `Header`, `Rows`, and `Summary` together.
154    HeaderRowsSummary {
155        #[serde(rename = "Header")]
156        header: Option<ColDataCollection>,
157        #[serde(rename = "Summary")]
158        summary: Option<ColDataCollection>,
159        #[serde(rename = "Rows")]
160        rows: Option<Rows>,
161    },
162}
163
164/// Corresponds to the `Row`.
165#[skip_serializing_none]
166#[derive(Debug, Serialize, Deserialize)]
167pub struct Row {
168    #[serde(flatten)]
169    pub content: RowContent,
170    #[serde(rename = "id", default)]
171    pub id: Option<String>,
172    #[serde(rename = "parentId", default)]
173    pub parent_id: Option<String>,
174
175    /// Row attributes
176    #[serde(rename = "type")]
177    pub row_type: Option<RowTypeEnum>, // Not needed as it's part of content choice
178    pub group: Option<String>,
179}
180
181/// Corresponds to the `ReportHeader`.
182#[skip_serializing_none]
183#[derive(Debug, Serialize, Deserialize)]
184#[serde(rename_all = "PascalCase")]
185pub struct ReportHeader {
186    pub time: Option<DateTime<FixedOffset>>,
187    pub report_name: Option<String>,
188    pub date_macro: Option<String>,
189    pub report_basis: Option<ReportBasisEnum>,
190    pub start_period: Option<NaiveDate>,
191    pub end_period: Option<NaiveDate>,
192    pub summarize_columns_by: Option<String>,
193    pub currency: Option<String>,
194    pub customer: Option<String>,
195    pub vendor: Option<String>,
196    pub employee: Option<String>,
197    pub item: Option<String>,
198    pub class_attr: Option<String>,
199    pub department: Option<String>,
200    pub option: Option<Vec<NameValue>>,
201}
202
203#[skip_serializing_none]
204#[derive(Debug, Serialize, Deserialize)]
205#[serde(rename_all = "PascalCase")]
206pub struct Report {
207    pub header: Option<ReportHeader>,
208    pub columns: Option<Columns>,
209    pub rows: Option<Rows>,
210}