1use crate::descriptor::{Action, COMMODITY, Field, Form, Kind, Scope, Suggest, TEXT, field};
4
5const TARGET: Field = field("target", "Target commodity", COMMODITY, false);
6const FILTER: Field = field("filter", "Filter", TEXT, false);
7const FROM: Field = field(
8 "from",
9 "From",
10 Kind::Date {
11 range_end: false,
12 whole_day: true,
13 },
14 false,
15);
16const FROM_REQUIRED: Field = field(
17 "from",
18 "From",
19 Kind::Date {
20 range_end: false,
21 whole_day: true,
22 },
23 true,
24);
25const TO: Field = field(
26 "to",
27 "To",
28 Kind::Date {
29 range_end: true,
30 whole_day: true,
31 },
32 true,
33);
34const GROUPING: Field = field(
35 "grouping",
36 "Grouping",
37 Kind::Choice {
38 options: &[
39 ("none", "None"),
40 ("month", "Month"),
41 ("quarter", "Quarter"),
42 ("year", "Year"),
43 ],
44 default: Some("none"),
45 },
46 false,
47);
48
49const YES_NO: &[(&str, &str)] = &[("yes", "Yes"), ("no", "No")];
50
51const GROUPS: Field = field(
53 "groups",
54 "Groups",
55 Kind::Rows {
56 fields: &[
57 field("name", "Name", TEXT, true),
58 field("filter", "Filter", TEXT, true),
59 field(
60 "flip",
61 "Flip sign",
62 Kind::Choice {
63 options: YES_NO,
64 default: Some("no"),
65 },
66 false,
67 ),
68 ],
69 nested_under: None,
70 },
71 false,
72);
73
74pub const REPORT_BALANCE: Form = Form {
75 name: "report-balance",
76 title: "Balance report",
77 fields: &[
78 TARGET,
79 FROM,
80 field(
81 "as-of",
82 "As of",
83 Kind::Date {
84 range_end: true,
85 whole_day: true,
86 },
87 false,
88 ),
89 FILTER,
90 ],
91 action: Action::Query,
92};
93
94pub const REPORT_ACTIVITY: Form = Form {
95 name: "report-activity",
96 title: "Activity report",
97 fields: &[TARGET, FROM_REQUIRED, TO, GROUPING, GROUPS, FILTER],
98 action: Action::Query,
99};
100
101pub const REPORT_CATEGORY: Form = Form {
103 name: "report-category",
104 title: "Category report",
105 fields: &[
106 TARGET,
107 FROM_REQUIRED,
108 TO,
109 GROUPING,
110 field(
111 "tag",
112 "Tag name",
113 Kind::Text {
114 multiline: false,
115 suggest: Some(Suggest::TagNames(Scope::Split)),
116 },
117 false,
118 ),
119 field(
120 "sort",
121 "Sort",
122 Kind::Choice {
123 options: &[
124 ("amount_desc", "Amount, largest first"),
125 ("amount_asc", "Amount, smallest first"),
126 ("name_asc", "Name, A to Z"),
127 ("name_desc", "Name, Z to A"),
128 ],
129 default: Some("amount_desc"),
130 },
131 false,
132 ),
133 field(
134 "include-uncategorized",
135 "Include uncategorized",
136 Kind::Choice {
137 options: YES_NO,
138 default: Some("yes"),
139 },
140 false,
141 ),
142 FILTER,
143 ],
144 action: Action::Query,
145};