FOSSredder 0.5.0
Loading...
Searching...
No Matches
TransactionPolicy.cpp
Go to the documentation of this file.
1
5
7
9
10#include <algorithm>
11#include <utility>
12
14
15std::string trimCopy(std::string value) {
16 return core::utils::trim(std::move(value));
17}
18
19bool hasValidBookingDate(const std::string& value) {
21}
22
23bool hasValidAmount(double value) {
25}
26
27bool hasStatementAssignment(const std::string& statementId) {
28 return !trimCopy(statementId).empty();
29}
30
31std::string normalizeText(std::string value) {
32 return trimCopy(std::move(value));
33}
34
35std::string normalizeId(std::string value) {
36 return trimCopy(std::move(value));
37}
38
39void normalizeIds(std::vector<std::string>& values) {
40 std::vector<std::string> unique;
41 unique.reserve(values.size());
42 for (auto& value : values) {
43 value = normalizeId(std::move(value));
44 if (value.empty()) {
45 continue;
46 }
47 if (std::find(unique.begin(), unique.end(), value) != unique.end()) {
48 continue;
49 }
50 unique.push_back(value);
51 }
52 values = std::move(unique);
53}
54
55bool canFinalizeFromDraft(const std::string& bookingDate, double amount, const std::string& statementId) {
56 return hasValidBookingDate(bookingDate) && hasValidAmount(amount) && hasStatementAssignment(statementId);
57}
58
59bool statusCanAdvance(int current, int next) {
60 return next >= current;
61}
62
63bool hasPropertyIds(const std::vector<std::string>& propertyIds) {
64 return !propertyIds.empty();
65}
66
67} // namespace core::domain::policies::transaction
Declares private string helpers shared across core implementation files.
Shared transaction transition and normalization helpers.
static bool isValid(const std::string &value)
static bool isValid(double value) noexcept
Checks whether a raw amount is finite.
Definition MoneyAmount.h:28
bool hasStatementAssignment(const std::string &statementId)
Checks whether a statement id is assigned.
bool statusCanAdvance(int current, int next)
Checks whether a transaction status may advance.
void normalizeIds(std::vector< std::string > &values)
Normalizes and deduplicates relation ids.
bool hasValidBookingDate(const std::string &value)
Checks whether a booking date value is valid.
bool canFinalizeFromDraft(const std::string &bookingDate, double amount, const std::string &statementId)
Checks whether a draft transaction can be finalized.
bool hasValidAmount(double value)
Checks whether a transaction amount value is valid.
bool hasPropertyIds(const std::vector< std::string > &propertyIds)
Checks whether a transaction has any property ids.
std::string normalizeId(std::string value)
Normalizes a relation id.
std::string trimCopy(std::string value)
Trims leading and trailing whitespace from text.
std::string normalizeText(std::string value)
Normalizes free-form transaction text.
std::string trim(std::string s)
Removes leading and trailing ASCII whitespace from a string.