This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:35:23 +01:00
commit 1ea50c50bc
62 changed files with 9982 additions and 608 deletions

View file

@ -1,13 +1,15 @@
//SPDX-License-Identifier: LGPL-3.0-only
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Nostro:Transaction;
import std;
import :Currency;
import :Utils;
namespace Nostro {
export struct Transaction {
// Version 1 of Transaction, kept so tables written by it migrate when opened. Do not change it.
struct TransactionV1 {
std::string name;
std::string bic;
std::string iban;
@ -16,8 +18,37 @@ namespace Nostro {
std::int64_t amount;
std::chrono::system_clock::time_point timePoint;
Transaction();
Transaction(std::string&& name, std::string&& bic, std::string&& iban, std::string&& description, Currency currency, std::int64_t amount, std::chrono::system_clock::time_point timePoint);
static constexpr std::uint32_t version = 1;
static constexpr auto orderedBy = &TransactionV1::timePoint;
};
// Also the row type of the Crafter.DB transaction tables, so it has to stay an aggregate. The members are the
// on-disk schema: changing them needs a `version` bump (with the old struct as `using Previous`), or existing
// tables are refused when opened.
export struct Transaction {
std::string name;
std::string bic;
std::string iban;
std::string description;
Currency currency;
std::int64_t amount;
std::chrono::system_clock::time_point timePoint;
// The bank's own id for it, so a sync that overlaps the last stored timestamp stores nothing twice.
// Empty for rows stored by version 1.
std::string id;
// The bank's own classification, e.g. bunq's "MASTERCARD/PAYMENT" or "EBA_SDD/SDD". Empty for rows stored by version 1.
std::string kind;
static constexpr std::uint32_t version = 2;
static constexpr auto orderedBy = &Transaction::timePoint;
using Previous = TransactionV1;
};
}
// One line of a transaction list: local time, amount, counterparty, IBAN and description, tab separated.
template<>
struct std::formatter<Nostro::Transaction> : std::formatter<std::string> {
auto format(const Nostro::Transaction& obj, std::format_context& ctx) const {
return std::formatter<std::string>::format(std::format("{}\t{}\t{}\t{}\t{}", Nostro::FormatLocalTime(obj.timePoint), Nostro::FormatMoney(obj.amount, obj.currency), obj.name, obj.iban, obj.description), ctx);
}
};