COOPENOMICS  v1
Кооперативная Экономика
accounts.hpp
См. документацию.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <string_view>
6
20enum class AccountType : uint8_t {
21 ACTIVE = 0,
22 PASSIVE = 1,
24};
25
52 // Активы
53 static constexpr uint64_t INTANGIBLE_ASSETS = 4 * 1000;
54 static constexpr uint64_t NON_CURRENT_INVESTMENTS = 8 * 1000;
55 static constexpr uint64_t BANK_ACCOUNT = 51 * 1000;
56 static constexpr uint64_t FINANCIAL_INVESTMENTS = 58 * 1000;
57
58 // Пассивы
59 static constexpr uint64_t SHARE_FUND = 80 * 1000;
60 static constexpr uint64_t TARGET_RECEIPTS = 86 * 1000;
61};
62
71 uint64_t id;
72 std::string_view name;
74};
75
82inline constexpr std::array<Ledger2AccountMeta, 6> LEDGER2_ACCOUNT_MAP = {{
83 { ledger2_accounts::INTANGIBLE_ASSETS, "Нематериальные активы", AccountType::ACTIVE },
84 { ledger2_accounts::NON_CURRENT_INVESTMENTS, "Вложения во внеоборотные активы", AccountType::ACTIVE },
85 { ledger2_accounts::BANK_ACCOUNT, "Расчётный счёт", AccountType::ACTIVE },
86 { ledger2_accounts::FINANCIAL_INVESTMENTS, "Финансовые вложения", AccountType::ACTIVE },
87 { ledger2_accounts::SHARE_FUND, "Паевой фонд (складочный капитал)", AccountType::PASSIVE },
88 { ledger2_accounts::TARGET_RECEIPTS, "Целевое финансирование", AccountType::PASSIVE },
89}};
90
91static constexpr size_t LEDGER2_ACCOUNT_MAP_SIZE = LEDGER2_ACCOUNT_MAP.size();
92
93// Compile-time проверка уникальности id в справочнике счетов.
95 constexpr bool account_ids_unique() {
96 for (size_t i = 0; i < LEDGER2_ACCOUNT_MAP_SIZE; ++i) {
97 for (size_t j = i + 1; j < LEDGER2_ACCOUNT_MAP_SIZE; ++j) {
98 if (LEDGER2_ACCOUNT_MAP[i].id == LEDGER2_ACCOUNT_MAP[j].id) return false;
99 }
100 }
101 return true;
102 }
103}
104
106 "LEDGER2_ACCOUNT_MAP: duplicate account id detected");
107
108inline constexpr const Ledger2AccountMeta* ledger2_find_account_meta(uint64_t account_id) {
109 for (size_t i = 0; i < LEDGER2_ACCOUNT_MAP_SIZE; ++i) {
110 if (LEDGER2_ACCOUNT_MAP[i].id == account_id) return &LEDGER2_ACCOUNT_MAP[i];
111 }
112 return nullptr;
113}
114
115inline std::string_view ledger2_get_account_name_by_id(uint64_t account_id) {
116 const auto* meta = ledger2_find_account_meta(account_id);
117 return meta ? meta->name : std::string_view{};
118}
119
120inline constexpr AccountType ledger2_get_account_type_by_id(uint64_t account_id) {
121 const auto* meta = ledger2_find_account_meta(account_id);
122 return meta ? meta->type : AccountType::ACTIVE_PASSIVE;
123}
std::string_view ledger2_get_account_name_by_id(uint64_t account_id)
Definition: accounts.hpp:115
static constexpr size_t LEDGER2_ACCOUNT_MAP_SIZE
Definition: accounts.hpp:91
constexpr const Ledger2AccountMeta * ledger2_find_account_meta(uint64_t account_id)
Definition: accounts.hpp:108
constexpr std::array< Ledger2AccountMeta, 6 > LEDGER2_ACCOUNT_MAP
Хардкод-справочник плана счетов (MVP, 7 записей).
Definition: accounts.hpp:82
constexpr AccountType ledger2_get_account_type_by_id(uint64_t account_id)
Definition: accounts.hpp:120
AccountType
Тип бухгалтерского счёта.
Definition: accounts.hpp:20
Definition: accounts.hpp:94
constexpr bool account_ids_unique()
Definition: accounts.hpp:95
Справочник счёта: id → (имя, тип).
Definition: accounts.hpp:70
AccountType type
Definition: accounts.hpp:73
std::string_view name
Definition: accounts.hpp:72
uint64_t id
Definition: accounts.hpp:71
План счетов ledger2 (MVP) со смещением *1000.
Definition: accounts.hpp:51
static constexpr uint64_t TARGET_RECEIPTS
86 — Целевое финансирование (П)
Definition: accounts.hpp:60
static constexpr uint64_t FINANCIAL_INVESTMENTS
58 — Финансовые вложения (А)
Definition: accounts.hpp:56
static constexpr uint64_t INTANGIBLE_ASSETS
04 — Нематериальные активы (А)
Definition: accounts.hpp:53
static constexpr uint64_t NON_CURRENT_INVESTMENTS
08 — Вложения во внеоборотные активы (А)
Definition: accounts.hpp:54
static constexpr uint64_t BANK_ACCOUNT
51 — Расчётный счёт (А)
Definition: accounts.hpp:55
static constexpr uint64_t SHARE_FUND
80 — Паевой фонд (П)
Definition: accounts.hpp:59