1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//! The cashflow element definition.
// Copyright (c) 2021 ShiftLeft Software
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::{CalcCalculate, ElemPreferences};
use crate::core::{ElemBalanceResult, ListAmortization, ListEvent, ListStatisticHelper};
pub struct ElemCashflow {
/// Name of the cashflow.
name: String,
/// Cashflow preferences element.
preferences: ElemPreferences,
/// Event list for the cashflow.
list_event: ListEvent,
/// If true the cashflow is valid, otherwise it must be re-balanced.
cashflow_valid: bool,
/// The currently selected cashflow has been updated.
updated: bool,
/// Cashflow calculation object.
calculate: CalcCalculate,
/// The list of active statistic elements.
list_statistic_helper: ListStatisticHelper,
/// Last balance calculation results.
elem_balance_result: ElemBalanceResult,
/// Amortization list for the cashflow.
list_amortization: ListAmortization,
/// The last amortization list index if valid or -1 if not valid.
last_amortization_index: usize,
}
/// The cashflow element definition implementation.
impl ElemCashflow {
/// Create and return a new cashflow element.
///
/// # Arguments
///
/// * `name_param` - Name of cashflow.
/// * `preferences_param` - Cashflow preferences.
/// * `list_event_param` - Event list.
/// * `calculate_param` - Calculate element.
///
/// # Return
///
/// * See description.
pub fn new(
name_param: &str,
preferences_param: ElemPreferences,
list_event_param: Option<ListEvent>,
calculate_param: CalcCalculate,
) -> ElemCashflow {
let tlist_event: ListEvent = match list_event_param {
None => ListEvent::new(true),
Some(o) => o,
};
ElemCashflow {
name: String::from(name_param),
preferences: preferences_param,
list_event: tlist_event,
list_amortization: ListAmortization::new(),
cashflow_valid: false,
updated: false,
calculate: calculate_param,
list_statistic_helper: ListStatisticHelper::new(),
elem_balance_result: ElemBalanceResult::new(),
last_amortization_index: usize::MAX,
}
}
/// Get the name.
///
/// # Return
///
/// * See description.
pub fn name(&self) -> &str {
self.name.as_str()
}
/// Get the preferences.
///
/// # Return
///
/// * See description.
pub fn preferences(&self) -> &ElemPreferences {
&self.preferences
}
/// Get the mut preferences.
///
/// # Return
///
/// * See description.
pub fn preferences_mut(&mut self) -> &mut ElemPreferences {
&mut self.preferences
}
/// Get the list event.
///
/// # Return
///
/// * See description.
pub fn list_event(&self) -> &ListEvent {
&self.list_event
}
/// Get the list event mutable.
///
/// # Return
///
/// * See description.
pub fn list_event_mut(&mut self) -> &mut ListEvent {
&mut self.list_event
}
/// Get the list amortization.
///
/// # Return
///
/// * See description.
pub fn list_amortization(&self) -> &ListAmortization {
&self.list_amortization
}
/// Get the list amortization mutable.
///
/// # Return
///
/// * See description.
pub fn list_amortization_mut(&mut self) -> &mut ListAmortization {
&mut self.list_amortization
}
/// Get the cashflow valid.
///
/// # Return
///
/// * See description.
pub fn cashflow_valid(&self) -> bool {
self.cashflow_valid
}
/// Get the updated value.
///
/// # Return
///
/// * See description.
pub fn updated(&self) -> bool {
self.updated
}
/// Get the calculate object.
///
/// # Return
///
/// * See description.
pub fn calculate(&self) -> &CalcCalculate {
&self.calculate
}
/// Get the statistic helper.
///
/// # Return
///
/// * See description.
pub fn list_statistic_helper(&self) -> &ListStatisticHelper {
&self.list_statistic_helper
}
/// Get the balance result.
///
/// # Return
///
/// * See description.
pub fn elem_balance_result(&self) -> &ElemBalanceResult {
&self.elem_balance_result
}
/// Get the last amortization index.
///
/// # Return
///
/// * See description.
pub fn last_amortization_index(&self) -> usize {
self.last_amortization_index
}
/// Set the name.
///
/// # Arguments
///
/// * `name_param` - See description.
pub fn set_name(&mut self, name_param: &str) {
self.name = String::from(name_param);
}
/// Set the preferences.
///
/// # Arguments
///
/// * `preferences_param` - See description.
pub fn set_preferences(&mut self, preferences_param: ElemPreferences) {
self.preferences = preferences_param;
}
/// Set the list event.
///
/// # Arguments
///
/// * `list_event_param` - See description.
pub fn set_list_event(&mut self, list_event_param: ListEvent) {
self.list_event = list_event_param;
}
/// Set the list amortization.
///
/// # Arguments
///
/// * `list_am_param` - See description.
pub fn set_list_amortization(&mut self, list_am_param: ListAmortization) {
self.list_amortization = list_am_param;
}
/// Set the cashflow valid.
///
/// # Arguments
///
/// * `cashflow_valid_param` - See description.
pub fn set_cashflow_valid(&mut self, cashflow_valid_param: bool) {
self.cashflow_valid = cashflow_valid_param;
}
/// Set the updated value.
///
/// # Arguments
///
/// * `updated_param` - See description.
pub fn set_updated(&mut self, updated_param: bool) {
self.updated = updated_param;
}
/// Set the calculate object.
///
/// # Arguments
///
/// * `calculate_param` - See description.
pub fn set_calculate(&mut self, calculate_param: CalcCalculate) {
self.calculate = calculate_param;
}
/// Set the statistic helper.
///
/// # Arguments
///
/// * `list_statistic_helper_param` - See description.
pub fn set_list_statistic_helper(&mut self, statistic_helper_param: ListStatisticHelper) {
self.list_statistic_helper = statistic_helper_param;
}
/// Set the balance result.
///
/// # Arguments
///
/// * `elem_balance_result_param` - See description.
pub fn set_elem_balance_result(&mut self, elem_balance_result_param: ElemBalanceResult) {
self.elem_balance_result = elem_balance_result_param;
}
/// Set the last amortization index.
///
/// # Arguments
///
/// * `last_am_index_param` - See description.
pub fn set_last_amortization_index(&mut self, last_amortization_index_param: usize) {
self.last_amortization_index = last_amortization_index_param;
}
}