20inline constexpr std::string_view kDefaultImportedStatementName =
"Imported";
21inline constexpr std::string_view kGeneratedContractPrefix =
"Vertrag ";
23int nextGeneratedContractIndex(
const std::vector<std::shared_ptr<Contract>>& contracts)
26 constexpr auto prefix = kGeneratedContractPrefix;
27 for (
const auto& contractPtr : contracts) {
28 if (!contractPtr)
continue;
29 const std::string& contractName = contractPtr->name();
30 if (contractName.size() <= prefix.size() || contractName.rfind(prefix.data(), 0) != 0)
continue;
31 const std::string rest = contractName.substr(prefix.size());
33 const auto result = std::from_chars(rest.data(), rest.data() + rest.size(), idx);
34 if (result.ec == std::errc{} && result.ptr == rest.data() + rest.size())
35 maxIdx = std::max(maxIdx, idx);
46 if (
draft.transactions.empty())
return {};
52 auto statement = std::make_shared<Statement>();
55 ? std::string(kDefaultImportedStatementName)
58 std::size_t addedTransactions = 0;
60 for (
const auto& item :
draft.transactions) {
79 if (!normalizedContractId.empty()) {
83 if (!normalizedType.empty()) {
84 constexpr auto prefix = kGeneratedContractPrefix;
85 auto contract = std::make_shared<Contract>();
87 contract->rename(std::string(prefix) + std::to_string(nextGeneratedContractIndex(contracts)));
88 contract->setType(normalizedType);
89 contract->setPropertyIds(item.propertyIds);
90 contracts.push_back(contract);
100 if (addedTransactions == 0) {
Domain model for contracts.
Declares draft finalization helpers that materialize imported entities.
Declares private stable identifier helpers for core entity creation.
Domain model for statements.
Declares private string helpers shared across core implementation files.
Domain model for transactions.
Shared transaction transition and normalization helpers.
static std::string finalize(core::domain::catalog::WorkspaceCatalog &state, const core::application::importing::draft::StatementDraft &draft)
Finalize a statement draft and append the resulting entities to the workspace state.
void setStatements(StatementList value)
Replaces all statements in the catalog.
const StatementList & statements() const noexcept
Returns all statements in the catalog.
const TransactionList & transactions() const noexcept
Returns all transactions in the catalog.
void setContracts(ContractList value)
Replaces all contracts in the catalog.
const ContractList & contracts() const noexcept
Returns all contracts in the catalog.
void setTransactions(TransactionList value)
Replaces all transactions in the catalog.
bool canFinalizeFromDraft(const std::string &bookingDate, double amount, const std::string &statementId)
Checks whether a draft transaction can be finalized.
std::string trimCopy(std::string value)
Trims leading and trailing whitespace from text.
std::string makeStableId()
Generates a stable hex identifier for persisted entities.
std::string trim(std::string s)
Removes leading and trailing ASCII whitespace from a string.