quickbooks_types/reports/
params.rs1use chrono::NaiveDate;
4use serde::{Deserialize, Serialize};
5use std::borrow::Cow;
6
7macro_rules! impl_display_enum {
8 (
9 $($doc:literal)?
10 $name:ident => {
11 $(
12 $variant_display:ident;
13 )* -
14 $(
15 $variant:ident => $display:expr
16 ),* $(,)?
17 }
18 ) => {
19 $(#[doc = $doc])?
20 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21 pub enum $name {
22 $(
23 $variant_display,
24 )*
25 $(
26 #[serde(rename = $display)]
27 $variant,
28 )*
29 }
30
31 impl $name {
32 pub fn as_str(&self) -> &str {
34 match self {
35 $(
36 $name::$variant_display => stringify!($variant_display),
37 )*
38 $(
39 $name::$variant => $display,
40 )*
41 }
42 }
43 }
44
45 impl std::fmt::Display for $name {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 write!(f, "{}", self.as_str())
48 }
49 }
50
51 impl HasValue for $name {
52 fn value(&self) -> Cow<'_, str> {
53 self.as_str().into()
54 }
55 }
56 };
57}
58
59impl_display_enum!(
60 "Represents various predefined date ranges for reports."
61 DateMacro => {
62 All;
63 Today;
64 Yesterday;
65 -
66 ThisWeek => "This Week",
67 ThisWeekToDate => "This Week-to-date",
68 ThisMonth => "This Month",
69 ThisMonthToDate => "This Month-to-date",
70 ThisFiscalQuarter => "This Fiscal Quarter",
71 ThisFiscalQuarterToDate => "This Fiscal Quarter-to-date",
72 ThisFiscalYear => "This Fiscal Year",
73 ThisFiscalYearToDate => "This Fiscal Year-to-date",
74 ThisCalendarQuarter => "This Calendar Quarter",
75 ThisCalendarQuarterToDate => "This Calendar Quarter-to-date",
76 ThisCalendarYear => "This Calendar Year",
77 ThisCalendarYearToDate => "This Calendar Year-to-date",
78 LastWeek => "Last Week",
79 LastWeekToDate => "Last Week-to-date",
80 LastMonth => "Last Month",
81 LastMonthToDate => "Last Month-to-date",
82 LastFiscalQuarter => "Last Fiscal Quarter",
83 LastFiscalQuarterToDate => "Last Fiscal Quarter-to-date",
84 LastFiscalYear => "Last Fiscal Year",
85 LastFiscalYearToDate => "Last Fiscal Year-to-date",
86 LastCalendarQuarter => "Last Calendar Quarter",
87 LastCalendarQuarterToDate => "Last Calendar Quarter-to-date",
88 LastCalendarYear => "Last Calendar Year",
89 LastCalendarYearToDate => "Last Calendar Year-to-date",
90 NextWeek => "Next Week",
91 Next4Weeks => "Next 4 Weeks",
92 NextMonth => "Next Month",
93 NextFiscalQuarter => "Next Fiscal Quarter",
94 NextFiscalYear => "Next Fiscal Year",
95 NextCalendarQuarter => "Next Calendar Quarter",
96 NextCalendarYear => "Next Calendar Year"
97});
98
99impl_display_enum!(
100 "Represents how columns are summarized in reports."
101 SummarizeColumnBy => {
102 Total;
103 Year;
104 Quarter;
105 FiscalYear;
106 FiscalQuarter;
107 Month;
108 Week;
109 Days;
110 Customers;
111 Vendors;
112 Employees;
113 Departments;
114 Classes;
115 ProductsAndServices;
116 -
117});
118impl_display_enum!(
119 "Represents different aging methods for reports."
120 AgingMethod => {
121 Current;
122 -
123 ReportDate => "Report_Date",
124});
125
126impl_display_enum!(
127 "Represents different accounting methods for reports."
128 AccountingMethod => {
129 Cash;
130 Accrual;
131 -
132});
133
134impl_display_enum!(
135 "Represents different sort orders for reports."
136 SortOrder => {
137 Ascending;
138 Descending;
139 -
140});
141
142impl_display_enum!(
143 "Represents Paid status for AR reports."
144 ArPaid => {
145 All;
146 Paid;
147 Unpaid;
148 -
149});
150
151impl_display_enum!(
152 "Represents different attachment types for reports."
153 AttachmentType => {
154 -
155 TemporaryLinks => "TEMPORARY_LINKS",
156 None => "NONE",
157});
158
159impl_display_enum!(
160 "Filters report contents to include information for specified check status."
161 Cleared => {
162 Cleared;
163 Uncleared;
164 Reconciled;
165 Deposited;
166 -
167});
168
169impl_display_enum!(
170 "Represents whether a report was printed."
171 Printed => {
172 Printed;
173 -
174 ToBePrinted => "To_be_printed",
175});
176
177macro_rules! impl_id_param {
178 ($($name:ident),*) => {
179
180 $(
181 paste::paste! {
182 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
183 #[doc = "Represents the ID for a " $name " in QuickBooks reports."]
184 pub struct [<$name Id>](pub u32);
185 impl HasValue for [<$name Id>] {
186 fn value(&self) -> Cow<'_, str> {
187 self.to_string().into()
188 }
189 }
190
191 impl std::fmt::Display for [<$name Id>] {
192 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193 write!(f, "{}", self.0)
194 }
195 }
196 }
197 )*
198 };
199}
200
201impl_id_param!(Customer, Vendor, Employee, Item, Class, Department, Account, Term);
202
203pub trait HasValue {
205 fn value(&self) -> Cow<'_, str>;
206}
207
208impl HasValue for String {
209 fn value(&self) -> Cow<'_, str> {
210 self.into()
211 }
212}
213
214impl HasValue for &str {
215 fn value(&self) -> Cow<'_, str> {
216 (*self).into()
217 }
218}
219
220impl HasValue for u32 {
221 fn value(&self) -> Cow<'_, str> {
222 self.to_string().into()
223 }
224}
225
226impl HasValue for NaiveDate {
227 fn value(&self) -> Cow<'_, str> {
228 self.format("%Y-%m-%d").to_string().into()
229 }
230}
231
232impl HasValue for bool {
233 fn value(&self) -> Cow<'_, str> {
234 if *self { "true" } else { "false" }.into()
235 }
236}
237
238impl<V: HasValue> HasValue for Vec<V> {
239 fn value(&self) -> Cow<'_, str> {
240 self.iter()
241 .map(|v| v.value())
242 .collect::<Vec<_>>()
243 .join(",")
244 .into()
245 }
246}