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/// Tells whether the row is a section header or data row.
57#[derive(Debug, Serialize, Deserialize)]
58pub enum RowTypeEnum {
59    Section,
60    Data,
61}
62
63/// Indicates whether the report is based on cash or accrual accounting.
64#[derive(Debug, Serialize, Deserialize)]
65pub enum ReportBasisEnum {
66    Cash,
67    Accrual,
68}
69
70/// Corresponds to the `NameValue`.
71#[skip_serializing_none]
72#[derive(Debug, Serialize, Deserialize)]
73#[serde(rename_all = "PascalCase")]
74pub struct NameValue {
75    pub name: Option<String>,
76    pub value: Option<String>,
77}
78
79/// Corresponds to the `Attribute`.
80#[derive(Debug, Serialize, Deserialize, Clone)]
81pub struct Attribute {
82    #[serde(rename = "Type")]
83    pub type_: String,
84    #[serde(rename = "Value")]
85    pub value: String,
86}
87
88/// Corresponds to the `Attributes`.
89#[skip_serializing_none]
90#[derive(Debug, Serialize, Deserialize, Clone)]
91pub struct Attributes {
92    #[serde(rename = "Attribute", default)]
93    pub attribute: Option<Vec<Attribute>>,
94}
95
96/// Corresponds to the `Columns`.
97#[skip_serializing_none]
98#[derive(Debug, Serialize, Deserialize)]
99pub struct Columns {
100    #[serde(rename = "Column", default)]
101    pub column: Option<Vec<Column>>,
102}
103
104/// Corresponds to the `Column`.
105#[skip_serializing_none]
106#[derive(Debug, Serialize, Deserialize)]
107#[serde(rename_all = "PascalCase")]
108pub struct Column {
109    pub col_title: String,
110    pub col_type: ColumnTypeEnum,
111    /// Repeats zero or more times, thus Option<Vec<...>>
112    pub meta_data: Option<Vec<NameValue>>,
113    /// Nested subcolumns
114    pub columns: Option<Columns>,
115}
116
117/// Corresponds to the `ColData`.
118#[skip_serializing_none]
119#[derive(Debug, Serialize, Deserialize, Clone)]
120pub struct ColData {
121    /// Nested Attributes element
122    #[serde(rename = "Attributes", default)]
123    pub attributes: Option<Attributes>,
124    pub value: Option<String>,
125    pub id: Option<String>,
126    pub href: Option<String>,
127}
128
129/// Represents a collection of `ColData` elements.
130#[skip_serializing_none]
131#[derive(Debug, Serialize, Deserialize)]
132#[serde(rename_all = "PascalCase")]
133pub struct ColDataCollection {
134    pub col_data: Option<Vec<ColData>>,
135}
136
137/// Corresponds to the `Rows`.
138#[skip_serializing_none]
139#[derive(Debug, Serialize, Deserialize)]
140pub struct Rows {
141    #[serde(rename = "Row", default)]
142    pub row: Option<Vec<Row>>,
143}
144
145/// The `Row` complexType has a choice: either (Header, Rows, Summary) or (`ColData` repeated).
146#[skip_serializing_none]
147#[derive(Debug, Serialize, Deserialize)]
148#[serde(untagged)]
149pub enum RowContent {
150    /// Contains a list of `ColData` elements.
151    Coldata {
152        #[serde(rename = "ColData")]
153        col_data: Vec<ColData>,
154    },
155    /// Contains `Header`, `Rows`, and `Summary` together.
156    HeaderRowsSummary {
157        #[serde(rename = "Header")]
158        header: Option<ColDataCollection>,
159        #[serde(rename = "Summary")]
160        summary: Option<ColDataCollection>,
161        #[serde(rename = "Rows")]
162        rows: Option<Rows>,
163    },
164}
165
166/// Corresponds to the `Row`.
167#[skip_serializing_none]
168#[derive(Debug, Serialize, Deserialize)]
169pub struct Row {
170    #[serde(flatten)]
171    pub content: RowContent,
172    #[serde(rename = "id", default)]
173    pub id: Option<String>,
174    #[serde(rename = "parentId", default)]
175    pub parent_id: Option<String>,
176
177    /// Row attributes
178    #[serde(rename = "type")]
179    pub row_type: Option<RowTypeEnum>, // Not needed as it's part of content choice
180    pub group: Option<String>,
181}
182
183/// Corresponds to the `ReportHeader`.
184#[skip_serializing_none]
185#[derive(Debug, Serialize, Deserialize)]
186#[serde(rename_all = "PascalCase")]
187pub struct ReportHeader {
188    pub time: Option<DateTime<FixedOffset>>,
189    pub report_name: Option<String>,
190    pub date_macro: Option<String>,
191    pub report_basis: Option<ReportBasisEnum>,
192    pub start_period: Option<NaiveDate>,
193    pub end_period: Option<NaiveDate>,
194    pub summarize_columns_by: Option<String>,
195    pub currency: Option<String>,
196    pub customer: Option<String>,
197    pub vendor: Option<String>,
198    pub employee: Option<String>,
199    pub item: Option<String>,
200    pub class_attr: Option<String>,
201    pub department: Option<String>,
202    pub option: Option<Vec<NameValue>>,
203}
204
205/// Report structure containing header, columns, and rows.
206#[skip_serializing_none]
207#[derive(Debug, Serialize, Deserialize)]
208#[serde(rename_all = "PascalCase")]
209pub struct Report {
210    pub header: Option<ReportHeader>,
211    pub columns: Option<Columns>,
212    pub rows: Option<Rows>,
213}