COOPENOMICS  v1
Кооперативная Экономика
marketplace.hpp
См. документацию.
1#pragma once
2
3#include <functional>
4#include <optional>
5#include <string>
6
7#include <eosio/crypto.hpp>
8#include <eosio/eosio.hpp>
9
10#include "../../consts.hpp"
11#include "../../domain/document_core.hpp"
12#include "../../domain/table_ledger2_userwallets.hpp"
13#include "../../domain/table_marketplace_fee_config.hpp"
14#include "../ledger2/ledger2.hpp"
15#include "../branch/branch.hpp"
16#include "memo.hpp"
17#include "../../domain/table_marketplace_orders.hpp"
18#include "../../domain/table_marketplace_return_requests.hpp"
19#include "../../domain/table_marketplace_writeoff_proposals.hpp"
20
32namespace Marketplace {
33
34using namespace eosio;
35
36// ── Количество как fixed-point asset (Эпик 17, L14) ─────────────────────
37//
38// quantity/actual_quantity — asset с символом единицы измерения (KG/LTR/PCS);
39// дробность веса/объёма выражается младшими единицами (0.500 KG = 500 г).
40// Штука (PCS, precision 0) неделима на уровне типа. Цена задаётся за одну
41// базовую единицу (кг/литр/штуку) money-asset'ом _root_govern_symbol.
42
43inline bool is_valid_unit_symbol(const eosio::symbol& sym) {
44 return sym == _unit_kg || sym == _unit_liter || sym == _unit_piece;
45}
46
48inline void check_quantity(const eosio::asset& quantity) {
49 eosio::check(quantity.is_valid() && is_valid_unit_symbol(quantity.symbol),
50 "Недопустимая единица измерения количества");
51 eosio::check(quantity.amount > 0, "Количество должно быть больше нуля");
52}
53
60inline void check_packaging(const eosio::asset& quantity, const eosio::asset& package_size) {
61 if (package_size.amount == 0) return; // отпуск по мере
62 eosio::check(package_size.is_valid() && package_size.symbol == quantity.symbol,
63 "Единица упаковки не совпадает с единицей количества");
64 eosio::check(package_size.amount > 0, "Размер упаковки должен быть больше нуля");
65 eosio::check(quantity.amount % package_size.amount == 0,
66 "Количество должно быть кратно размеру упаковки");
67}
68
77inline eosio::asset calc_cost(const eosio::asset& quantity, const eosio::asset& unit_price,
78 const eosio::asset& package_size = eosio::asset(0, _unit_piece)) {
79 if (package_size.amount > 0) {
80 const int64_t packages = quantity.amount / package_size.amount; // точно (кратность — check_packaging)
81 const uint128_t total = static_cast<uint128_t>(packages) *
82 static_cast<uint128_t>(unit_price.amount);
83 return eosio::asset(static_cast<int64_t>(total), unit_price.symbol);
84 }
85 int64_t scale = 1;
86 for (uint8_t i = 0; i < quantity.symbol.precision(); ++i) scale *= 10;
87 const uint128_t num = static_cast<uint128_t>(quantity.amount) *
88 static_cast<uint128_t>(unit_price.amount);
89 const int64_t amount = static_cast<int64_t>((num + static_cast<uint128_t>(scale) / 2) / scale);
90 return eosio::asset(amount, unit_price.symbol);
91}
92
98inline eosio::asset pro_rata(const eosio::asset& total, int64_t part, int64_t whole) {
99 eosio::check(whole > 0, "Некорректная база для расчёта пропорциональной доли");
100 const uint128_t num = static_cast<uint128_t>(total.amount) * static_cast<uint128_t>(part);
101 const int64_t amount =
102 static_cast<int64_t>((num + static_cast<uint128_t>(whole) / 2) / static_cast<uint128_t>(whole));
103 return eosio::asset(amount, total.symbol);
104}
105
106// ── Orders ──────────────────────────────────────────────────────────────
107
108inline std::optional<order> get_order_by_hash(eosio::name coopname, const checksum256& order_hash) {
109 orders_index orders(_marketplace, coopname.value);
110 auto idx = orders.get_index<"byhash"_n>();
111 auto it = idx.find(order_hash);
112 if (it == idx.end()) return std::nullopt;
113 return *it;
114}
115
116inline order get_order_by_hash_or_fail(eosio::name coopname, const checksum256& order_hash,
117 const std::string& msg = "Заказ не найден по хэшу") {
118 auto o = get_order_by_hash(coopname, order_hash);
119 eosio::check(o.has_value(), msg);
120 return *o;
121}
122
123inline void update_order(eosio::name coopname, uint64_t order_id, const std::function<void(order&)>& fn) {
124 orders_index orders(_marketplace, coopname.value);
125 auto it = orders.find(order_id);
126 eosio::check(it != orders.end(), "Заказ не найден по id");
127 orders.modify(it, RamPayer::of(orders, coopname), [&](auto& o) { fn(o); });
128}
129
138inline std::optional<eosio::asset> get_asset_extension(const eosio::binary_extension<eosio::asset>& ext) {
139 if (!ext.has_value() || ext.value().symbol.raw() == 0) return std::nullopt;
140 return ext.value();
141}
142
146inline eosio::asset get_accepted_cost(const order& o) {
147 return get_asset_extension(o.accepted_cost).value_or(o.fact_cost);
148}
149
151inline eosio::asset get_payout_withheld(const order& o) {
152 return get_asset_extension(o.payout_withheld).value_or(eosio::asset(0, _root_govern_symbol));
153}
154
158inline bool is_supplier_settlement_open(const order& o) {
160}
161
162// Терминал жизненного цикла: запись стирается из RAM, история процесса
163// остаётся в журнале действий (blockchain_actions парсера).
164inline void erase_order(eosio::name coopname, uint64_t order_id) {
165 orders_index orders(_marketplace, coopname.value);
166 auto it = orders.find(order_id);
167 eosio::check(it != orders.end(), "Заказ не найден по id");
168 orders.erase(it);
169}
170
171// ── Return requests ─────────────────────────────────────────────────────
172
178inline uint64_t next_return_request_id(eosio::name coopname) {
179 return_requests_index requests(_marketplace, coopname.value);
180 const uint64_t id = requests.available_primary_key();
181 return id == 0 ? 1 : id;
182}
183
187inline bool has_open_return_request(eosio::name coopname, const order& o) {
188 if (o.return_request_id == 0) return false;
189 return_requests_index requests(_marketplace, coopname.value);
190 auto it = requests.find(o.return_request_id);
191 return it != requests.end() && it->original_order_hash == o.hash;
192}
193
194inline std::optional<return_request> get_return_request_by_hash(eosio::name coopname,
195 const checksum256& request_hash) {
196 return_requests_index requests(_marketplace, coopname.value);
197 auto idx = requests.get_index<"byhash"_n>();
198 auto it = idx.find(request_hash);
199 if (it == idx.end()) return std::nullopt;
200 return *it;
201}
202
204 const checksum256& request_hash,
205 const std::string& msg = "Заявление на возврат не найдено по хэшу") {
206 auto r = get_return_request_by_hash(coopname, request_hash);
207 eosio::check(r.has_value(), msg);
208 return *r;
209}
210
211inline void update_return_request(eosio::name coopname, uint64_t request_id,
212 const std::function<void(return_request&)>& fn) {
213 return_requests_index requests(_marketplace, coopname.value);
214 auto it = requests.find(request_id);
215 eosio::check(it != requests.end(), "Заявление на возврат не найдено по id");
216 requests.modify(it, RamPayer::of(requests, coopname), [&](auto& r) { fn(r); });
217}
218
219// Терминал жизненного цикла: запись стирается из RAM (история — в журнале
220// действий). order.return_request_id НЕ сбрасывается — повторный возврат по
221// тому же заказу не открывается.
222inline void erase_return_request(eosio::name coopname, uint64_t request_id) {
223 return_requests_index requests(_marketplace, coopname.value);
224 auto it = requests.find(request_id);
225 eosio::check(it != requests.end(), "Заявление на возврат не найдено по id");
226 requests.erase(it);
227}
228
233inline void check_return_request_branch(eosio::name coopname, const return_request& r,
234 eosio::name braname) {
236 eosio::check(o.delivery_braname == braname,
237 "Заявление на возврат рассматривает кооперативный участок выдачи заказа");
238}
239
240// ── Writeoff proposals ──────────────────────────────────────────────────
241
242inline std::optional<writeoff_proposal> get_writeoff_proposal_by_hash(eosio::name coopname,
243 const checksum256& proposal_hash) {
244 writeoff_proposals_index proposals(_marketplace, coopname.value);
245 auto idx = proposals.get_index<"byhash"_n>();
246 auto it = idx.find(proposal_hash);
247 if (it == idx.end()) return std::nullopt;
248 return *it;
249}
250
252 const checksum256& proposal_hash,
253 const std::string& msg = "Проект списания не найден по хэшу") {
254 auto p = get_writeoff_proposal_by_hash(coopname, proposal_hash);
255 eosio::check(p.has_value(), msg);
256 return *p;
257}
258
259inline void update_writeoff_proposal(eosio::name coopname, uint64_t proposal_id,
260 const std::function<void(writeoff_proposal&)>& fn) {
261 writeoff_proposals_index proposals(_marketplace, coopname.value);
262 auto it = proposals.find(proposal_id);
263 eosio::check(it != proposals.end(), "Проект списания не найден по id");
264 proposals.modify(it, RamPayer::of(proposals, coopname), [&](auto& p) { fn(p); });
265}
266
267// Терминал жизненного цикла: запись стирается из RAM, история процесса —
268// в журнале действий (blockchain_actions парсера).
269inline void erase_writeoff_proposal(eosio::name coopname, uint64_t proposal_id) {
270 writeoff_proposals_index proposals(_marketplace, coopname.value);
271 auto it = proposals.find(proposal_id);
272 eosio::check(it != proposals.end(), "Проект списания не найден по id");
273 proposals.erase(it);
274}
275
276// ── Warranty claims (претензии поставщику, p.mkt.claim) ─────────────────
277
278inline std::optional<warranty_claim> get_claim_by_hash(eosio::name coopname,
279 const checksum256& claim_hash) {
280 warranty_claims_index claims(_marketplace, coopname.value);
281 auto idx = claims.get_index<"byhash"_n>();
282 auto it = idx.find(claim_hash);
283 if (it == idx.end()) return std::nullopt;
284 return *it;
285}
286
287inline warranty_claim get_claim_by_hash_or_fail(eosio::name coopname,
288 const checksum256& claim_hash,
289 const std::string& msg = "Гарантийная претензия поставщику не найдена по хэшу") {
290 auto c = get_claim_by_hash(coopname, claim_hash);
291 eosio::check(c.has_value(), msg);
292 return *c;
293}
294
295inline void update_claim(eosio::name coopname, uint64_t claim_id,
296 const std::function<void(warranty_claim&)>& fn) {
297 warranty_claims_index claims(_marketplace, coopname.value);
298 auto it = claims.find(claim_id);
299 eosio::check(it != claims.end(), "Гарантийная претензия не найдена по id");
300 claims.modify(it, RamPayer::of(claims, coopname), [&](auto& c) { fn(c); });
301}
302
303// ── Cross-contract read: ledger2 wallet/userwallet balances ─────────────
304//
305// Используется в createorder для guard'а Locked Decision L6 (без отрицательного
306// баланса) — проверка достаточности средств заказчика на паевом кошельке
307// перед вызовом o.mkt.lock.
308//
309// ВАЖНО: контракт marketplace не вызывает ledger2::walletop напрямую, а только
310// читает state (RAM-таблицы wallets2 / userwallets через cross-contract scope).
311// Все мутации идут через `Ledger2::apply` (см. lib/core/ledger2/ledger2.hpp).
312
314 eosio::asset available = eosio::asset(0, _root_govern_symbol);
315 eosio::asset blocked = eosio::asset(0, _root_govern_symbol);
316 bool exists = false;
317};
318
320 eosio::name wallet_id,
321 eosio::name username) {
322 // userwallets_index — глобальный typedef в lib/domain/table_ledger2_userwallets.hpp.
323 // Для cross-contract read берём scope = coopname.value, code = _ledger2.
324 userwallets_index user_wallets(_ledger2, coopname.value);
325 auto idx = user_wallets.get_index<"byuserwallet"_n>();
326 auto it = idx.find(combine_ids(wallet_id.value, username.value));
327 if (it == idx.end()) {
328 return UserWalletAvailable{};
329 }
330 return UserWalletAvailable{ it->available, it->blocked, true };
331}
332
333// ── Членский взнос «Стола заказов» (requirement b6 «Экономика КУ») ──────
334
339constexpr uint64_t DEFAULT_MEMBERSHIP_FEE_PERCENT = 300000;
340
343inline uint64_t get_membership_fee_percent(eosio::name coopname) {
344 mkt_config_singleton cfg(_marketplace, coopname.value);
345 return cfg.exists() ? cfg.get().membership_fee_percent : DEFAULT_MEMBERSHIP_FEE_PERCENT;
346}
347
349inline eosio::asset calc_membership_fee(const eosio::asset& base, uint64_t fee_percent) {
350 const int64_t amount = static_cast<int64_t>(
351 static_cast<uint128_t>(base.amount) * fee_percent / HUNDR_PERCENTS);
352 return eosio::asset(amount, _root_govern_symbol);
353}
354
356inline eosio::asset get_order_membership_fee(const order& o) {
357 return o.membership_fee;
358}
359
366inline void require_member_fee(eosio::name coopname, eosio::name orderer,
367 const eosio::asset& membership_fee) {
368 if (membership_fee.amount <= 0) return;
370 eosio::check(member.available >= membership_fee,
371 std::string{"Недостаточно членских средств Стола заказов на членский взнос участка: требуется "} +
372 membership_fee.to_string() + ", доступно " + member.available.to_string() +
373 ". Сначала подайте заявление о переводе паевого взноса в программу.");
374}
375
382inline void lock_order_body(eosio::name coopname, uint64_t order_id, eosio::name orderer,
383 const checksum256& order_hash, const eosio::asset& body,
384 const std::string& program_memo, const std::string& wallet_memo) {
385 if (body.amount <= 0) return;
387 const eosio::asset from_program = program.available >= body ? body : program.available;
388 const eosio::asset from_wallet = body - from_program;
389 if (from_wallet.amount > 0) {
391 eosio::check(wallet.available >= from_wallet,
392 std::string{"Недостаточно паевых средств для заказа: требуется с Цифрового кошелька "} +
393 from_wallet.to_string() + ", доступно " + wallet.available.to_string() +
394 " (свободный паевой Стола заказов " + program.available.to_string() + " уже учтён)");
395 }
396 if (from_program.amount > 0) {
400 from_program, orderer, order_hash, program_memo);
401 }
402 if (from_wallet.amount > 0) {
406 from_wallet, orderer, order_hash, wallet_memo);
407 }
408}
409
412inline void lock_membership_fee(eosio::name coopname, uint64_t order_id,
413 eosio::name orderer, const checksum256& order_hash,
414 const eosio::asset& fee, const std::string& memo) {
415 if (fee.amount <= 0) return;
419 fee, orderer, order_hash, memo);
420}
421
427inline void refund_membership_fee_if_any(eosio::name coopname, const order& o) {
428 const eosio::asset fee = get_order_membership_fee(o);
429 if (fee.amount <= 0) return;
433 fee, o.orderer, o.hash,
435}
436
440inline void refund_order_full(eosio::name coopname, const order& o) {
444 o.total_cost, o.orderer, o.hash,
446 refund_membership_fee_if_any(coopname, o);
447}
448
451inline constexpr uint64_t REFUSAL_PENALTY_PERCENT = 50;
452
456 o.issue_statement.emplace(document2{});
457 o.issue_protocol.emplace(document2{});
458 o.issue_act1 = document2{};
459 o.issue_act2 = document2{};
461 o.fact_cost = o.total_cost;
462}
463
465inline eosio::asset refusal_penalty_share(const eosio::asset& base) {
467}
468
477inline void retain_refusal_penalty(eosio::name coopname, const order& o) {
478 // ── Тело заказа 50/50 ──
479 const eosio::asset penalty_body = refusal_penalty_share(o.total_cost);
480 const eosio::asset refund_body = o.total_cost - penalty_body;
481
482 if (refund_body.amount > 0) {
486 refund_body, o.orderer, o.hash,
488 }
489 if (penalty_body.amount > 0) {
490 // Транзит: удержанная половина тела → пул членских взносов, откуда уйдёт в КУ.
494 penalty_body, o.orderer, o.hash,
496 }
497
498 // ── Членский взнос 50/50 ──
499 const eosio::asset fee = get_order_membership_fee(o);
500 const eosio::asset penalty_fee = refusal_penalty_share(fee);
501 const eosio::asset refund_fee = fee - penalty_fee;
502 if (refund_fee.amount > 0) {
506 refund_fee, o.orderer, o.hash,
508 }
509
510 // ── Удержанное (тело + взнос) — в общий кошелёк КУ выдачи ──
511 // Обе удержанные половины сейчас в пуле членских взносов: тело — транзитом
512 // выше, взнос — ещё с createorder; единым accrue зачисляются в w.brn.common.
513 const eosio::asset to_common = penalty_body + penalty_fee;
514 if (to_common.amount > 0) {
518 }
519}
520
521// ── Факты Стола заказов для других контрактов (shared-слой, задача 99D-16) ──
522// Код других контрактов таблиц marketplace напрямую не читает: участок,
523// выход пайщика и прочие проверки спрашивают Стол заказов только этими методами.
524
527inline bool has_orders_at_branch(eosio::name coopname, eosio::name braname) {
528 orders_index orders(_marketplace, coopname.value);
529 auto by_delivery = orders.get_index<"bydelivbra"_n>();
530 if (by_delivery.find(braname.value) != by_delivery.end()) return true;
531 auto by_accept = orders.get_index<"byacceptbra"_n>();
532 return by_accept.find(braname.value) != by_accept.end();
533}
534
539inline void check_member_can_exit(eosio::name coopname, eosio::name username) {
540 const eosio::asset reserve =
542 eosio::check(reserve.amount == 0,
543 "Выход из кооператива невозможен: под заказы Стола заказов зарезервировано " +
544 reserve.to_string() + " — завершите или отмените заказы");
545
546 return_requests_index requests(_marketplace, coopname.value);
547 auto by_orderer = requests.get_index<"byorderer"_n>();
548 eosio::check(by_orderer.find(username.value) == by_orderer.end(),
549 "Выход из кооператива невозможен: открыто заявление на гарантийный возврат в Столе заказов — дождитесь его рассмотрения");
550}
551
557inline void settle_member_fund_on_exit(eosio::name actor, eosio::name coopname,
558 eosio::name username, const checksum256& exit_hash) {
559 const eosio::asset balance =
561 if (balance.amount <= 0) return;
562
564 processes::wallet::WITHDRAW, balance, username, exit_hash,
565 "Остаток членского кошелька Стола заказов в пул взносов при выходе, username=" +
566 username.to_string());
567
568 const auto braname = ::get_participant_branch(coopname, username);
569 if (!braname.has_value() || !Branch::exists(coopname, *braname)) return;
570 Branch::accrue(actor, coopname, *braname, balance, processes::wallet::WITHDRAW, exit_hash,
571 "Остаток членского кошелька Стола заказов в общий кошелёк участка при выходе, username=" +
572 username.to_string());
573}
574
575} // namespace Marketplace
static void apply(eosio::name actor, eosio::name coopname, eosio::name operation_code, eosio::name process_type, eosio::asset amount, eosio::name username, eosio::checksum256 process_hash, std::string memo)
Отправить inline action ledger2::apply.
Definition: ledger2.hpp:42
Контракт Wallet управляет взносами и возвратами взносов по ЦПП "Цифровой Кошелёк".
Definition: wallet.hpp:16
static constexpr eosio::symbol _unit_piece
Definition: consts.hpp:243
static constexpr eosio::symbol _root_govern_symbol
Definition: consts.hpp:236
#define HUNDR_PERCENTS
Definition: consts.hpp:141
static constexpr eosio::symbol _unit_liter
Definition: consts.hpp:242
static constexpr eosio::symbol _unit_kg
Definition: consts.hpp:241
static constexpr eosio::name _ledger2
Definition: consts.hpp:185
static constexpr eosio::name _marketplace
Definition: consts.hpp:176
balance
Definition: eosio.token_tests.cpp:226
share_type amount
Definition: eosio.token_tests.cpp:174
Человекочитаемые memo для marketplace ledger2-операций.
bool exists(eosio::name coopname, eosio::name braname)
Кооперативный участок существует (не удалён).
Definition: branch.hpp:50
void accrue(eosio::name actor, eosio::name coopname, eosio::name braname, eosio::asset amount, eosio::name process_type, eosio::checksum256 process_hash, std::string memo)
Inline-вызов branch::accrue от контракта-источника членских взносов (requirement b6 «Экономика КУ»,...
Definition: branch.hpp:62
std::string get_refusal_penalty_distribute_memo(uint64_t order_id)
Definition: memo.hpp:70
std::string get_membership_fee_refund_memo(uint64_t order_id)
Definition: memo.hpp:46
std::string get_cancel_order_memo(uint64_t order_id)
Definition: memo.hpp:62
std::string get_refusal_penalty_transit_memo(uint64_t order_id)
Definition: memo.hpp:66
constexpr eosio::name COMPLETED
Definition: table_marketplace_orders.hpp:72
Canonical helpers контракта marketplace (Story 11.1).
Definition: marketplace.hpp:32
void check_return_request_branch(eosio::name coopname, const return_request &r, eosio::name braname)
Definition: marketplace.hpp:233
std::optional< order > get_order_by_hash(eosio::name coopname, const checksum256 &order_hash)
Definition: marketplace.hpp:108
return_request get_return_request_by_hash_or_fail(eosio::name coopname, const checksum256 &request_hash, const std::string &msg="Заявление на возврат не найдено по хэшу")
Definition: marketplace.hpp:203
void erase_order(eosio::name coopname, uint64_t order_id)
Definition: marketplace.hpp:164
eosio::multi_index< "orders"_n, order, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< order, checksum256, &order::by_hash > >, eosio::indexed_by<"byorderer"_n, eosio::const_mem_fun< order, uint64_t, &order::by_orderer > >, eosio::indexed_by<"byofferer"_n, eosio::const_mem_fun< order, uint64_t, &order::by_offerer > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< order, uint64_t, &order::by_status > >, eosio::indexed_by<"bybatch"_n, eosio::const_mem_fun< order, checksum256, &order::by_batch > >, eosio::indexed_by<"byoffer"_n, eosio::const_mem_fun< order, checksum256, &order::by_offer > >, eosio::indexed_by<"bydelivbra"_n, eosio::const_mem_fun< order, uint64_t, &order::by_delivery_bra > >, eosio::indexed_by<"byacceptbra"_n, eosio::const_mem_fun< order, uint64_t, &order::by_accept_bra > > > orders_index
Definition: table_marketplace_orders.hpp:253
void clear_issue_documents(order &o)
Definition: marketplace.hpp:455
eosio::asset calc_membership_fee(const eosio::asset &base, uint64_t fee_percent)
Сумма членского взноса от базы по ставке (целочисленно, вниз).
Definition: marketplace.hpp:349
uint64_t next_return_request_id(eosio::name coopname)
Definition: marketplace.hpp:178
std::optional< writeoff_proposal > get_writeoff_proposal_by_hash(eosio::name coopname, const checksum256 &proposal_hash)
Definition: marketplace.hpp:242
constexpr uint64_t DEFAULT_MEMBERSHIP_FEE_PERCENT
Definition: marketplace.hpp:339
void require_member_fee(eosio::name coopname, eosio::name orderer, const eosio::asset &membership_fee)
Definition: marketplace.hpp:366
UserWalletAvailable get_user_wallet_balance(eosio::name coopname, eosio::name wallet_id, eosio::name username)
Definition: marketplace.hpp:319
void erase_writeoff_proposal(eosio::name coopname, uint64_t proposal_id)
Definition: marketplace.hpp:269
void check_member_can_exit(eosio::name coopname, eosio::name username)
Definition: marketplace.hpp:539
constexpr uint64_t REFUSAL_PENALTY_PERCENT
Definition: marketplace.hpp:451
void check_quantity(const eosio::asset &quantity)
Валидация количества: корректный asset, известная единица, положительное.
Definition: marketplace.hpp:48
void update_writeoff_proposal(eosio::name coopname, uint64_t proposal_id, const std::function< void(writeoff_proposal &)> &fn)
Definition: marketplace.hpp:259
eosio::asset get_accepted_cost(const order &o)
Definition: marketplace.hpp:146
eosio::asset pro_rata(const eosio::asset &total, int64_t part, int64_t whole)
Definition: marketplace.hpp:98
eosio::multi_index< "wroffprops"_n, writeoff_proposal, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< writeoff_proposal, checksum256, &writeoff_proposal::by_hash > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< writeoff_proposal, uint64_t, &writeoff_proposal::by_status > > > writeoff_proposals_index
Definition: table_marketplace_writeoff_proposals.hpp:118
eosio::asset get_order_membership_fee(const order &o)
Членский взнос заказа (ноль — взнос не начислялся).
Definition: marketplace.hpp:356
eosio::asset refusal_penalty_share(const eosio::asset &base)
Удерживаемая часть суммы (округление вниз — остаток в пользу пайщика).
Definition: marketplace.hpp:465
eosio::asset get_payout_withheld(const order &o)
Долг поставщика, уже удержанный при инициации выплаты; без суммы — ноль.
Definition: marketplace.hpp:151
bool has_open_return_request(eosio::name coopname, const order &o)
Definition: marketplace.hpp:187
void check_packaging(const eosio::asset &quantity, const eosio::asset &package_size)
Definition: marketplace.hpp:60
eosio::asset calc_cost(const eosio::asset &quantity, const eosio::asset &unit_price, const eosio::asset &package_size=eosio::asset(0, _unit_piece))
Definition: marketplace.hpp:77
void update_claim(eosio::name coopname, uint64_t claim_id, const std::function< void(warranty_claim &)> &fn)
Definition: marketplace.hpp:295
warranty_claim get_claim_by_hash_or_fail(eosio::name coopname, const checksum256 &claim_hash, const std::string &msg="Гарантийная претензия поставщику не найдена по хэшу")
Definition: marketplace.hpp:287
void erase_return_request(eosio::name coopname, uint64_t request_id)
Definition: marketplace.hpp:222
std::optional< eosio::asset > get_asset_extension(const eosio::binary_extension< eosio::asset > &ext)
Definition: marketplace.hpp:138
writeoff_proposal get_writeoff_proposal_by_hash_or_fail(eosio::name coopname, const checksum256 &proposal_hash, const std::string &msg="Проект списания не найден по хэшу")
Definition: marketplace.hpp:251
bool is_supplier_settlement_open(const order &o)
Definition: marketplace.hpp:158
void settle_member_fund_on_exit(eosio::name actor, eosio::name coopname, eosio::name username, const checksum256 &exit_hash)
Definition: marketplace.hpp:557
void update_return_request(eosio::name coopname, uint64_t request_id, const std::function< void(return_request &)> &fn)
Definition: marketplace.hpp:211
eosio::multi_index< "claims"_n, warranty_claim, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< warranty_claim, checksum256, &warranty_claim::by_hash > >, eosio::indexed_by<"bysupplier"_n, eosio::const_mem_fun< warranty_claim, uint64_t, &warranty_claim::by_supplier > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< warranty_claim, uint64_t, &warranty_claim::by_status > >, eosio::indexed_by<"byorigorder"_n, eosio::const_mem_fun< warranty_claim, uint64_t, &warranty_claim::by_original_order > > > warranty_claims_index
Definition: table_marketplace_warranty_claims.hpp:82
std::optional< warranty_claim > get_claim_by_hash(eosio::name coopname, const checksum256 &claim_hash)
Definition: marketplace.hpp:278
order get_order_by_hash_or_fail(eosio::name coopname, const checksum256 &order_hash, const std::string &msg="Заказ не найден по хэшу")
Definition: marketplace.hpp:116
void refund_membership_fee_if_any(eosio::name coopname, const order &o)
Definition: marketplace.hpp:427
bool has_orders_at_branch(eosio::name coopname, eosio::name braname)
Definition: marketplace.hpp:527
uint64_t get_membership_fee_percent(eosio::name coopname)
Definition: marketplace.hpp:343
void update_order(eosio::name coopname, uint64_t order_id, const std::function< void(order &)> &fn)
Definition: marketplace.hpp:123
void lock_order_body(eosio::name coopname, uint64_t order_id, eosio::name orderer, const checksum256 &order_hash, const eosio::asset &body, const std::string &program_memo, const std::string &wallet_memo)
Definition: marketplace.hpp:382
void refund_order_full(eosio::name coopname, const order &o)
Definition: marketplace.hpp:440
eosio::multi_index< "retrequests"_n, return_request, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< return_request, checksum256, &return_request::by_hash > >, eosio::indexed_by<"byorderer"_n, eosio::const_mem_fun< return_request, uint64_t, &return_request::by_orderer > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< return_request, uint64_t, &return_request::by_status > >, eosio::indexed_by<"byorigorder"_n, eosio::const_mem_fun< return_request, uint64_t, &return_request::by_original_order > > > return_requests_index
Definition: table_marketplace_return_requests.hpp:125
void lock_membership_fee(eosio::name coopname, uint64_t order_id, eosio::name orderer, const checksum256 &order_hash, const eosio::asset &fee, const std::string &memo)
Definition: marketplace.hpp:412
void retain_refusal_penalty(eosio::name coopname, const order &o)
Definition: marketplace.hpp:477
std::optional< return_request > get_return_request_by_hash(eosio::name coopname, const checksum256 &request_hash)
Definition: marketplace.hpp:194
bool is_valid_unit_symbol(const eosio::symbol &sym)
Definition: marketplace.hpp:43
eosio::name of(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:78
Definition: eosio.msig.hpp:34
constexpr eosio::name EXIT_FEE_TO_POOL
Остаток членского кошелька программы при выходе пайщика из кооператива (TRANSFER w....
Definition: operations.hpp:114
constexpr eosio::name MEMBERSHIP_FEE_REFUND
Сторно неиспользованной части членского взноса участка на членский кошелёк программы (TRANSFER w....
Definition: operations.hpp:111
constexpr eosio::name UNLOCK_ORDER
Возврат резерва при отмене Order'а или недовыдаче (TRANSFER w.mkt.order → w.mkt.share,...
Definition: operations.hpp:102
constexpr eosio::name LOCK_FROM_SHARE
Паевой резерв из свободного паевого «Стола заказов» (TRANSFER w.mkt.share → w.mkt....
Definition: operations.hpp:101
constexpr eosio::name MEMBERSHIP_FEE_LOCK
Членский взнос кооперативного участка под заказ из членского кошелька программы (TRANSFER w....
Definition: operations.hpp:110
constexpr eosio::name REFUSAL_PENALTY
Удержание 50% при отказе пайщика от получения после акцепта поставщиком (TRANSFER w....
Definition: operations.hpp:112
constexpr eosio::name LOCK_ORDER
Паевой резерв под конкретный Order (TRANSFER w.wal.share → w.mkt.order, без Dr/Cr — оба кошелька на 8...
Definition: operations.hpp:100
constexpr eosio::name SUPPLY
Прямая поставка-приобретение имущества (5 операций: o.mkt.lock + o.mkt.unlock + o....
Definition: processes.hpp:75
constexpr eosio::name WITHDRAW
Возврат паевого взноса пайщику.
Definition: processes.hpp:58
Definition: marketplace.hpp:313
bool exists
Definition: marketplace.hpp:316
eosio::asset blocked
Definition: marketplace.hpp:315
eosio::asset available
Definition: marketplace.hpp:314
On-chain Order — анкер процесса p.mkt.supply.
Definition: table_marketplace_orders.hpp:148
eosio::name orderer
пайщик-заказчик
Definition: table_marketplace_orders.hpp:152
eosio::binary_extension< eosio::asset > payout_withheld
Definition: table_marketplace_orders.hpp:217
checksum256 hash
process_hash для p.mkt.supply
Definition: table_marketplace_orders.hpp:150
eosio::binary_extension< eosio::asset > accepted_cost
Definition: table_marketplace_orders.hpp:224
eosio::asset membership_fee
Definition: table_marketplace_orders.hpp:204
eosio::binary_extension< document2 > issue_statement
Definition: table_marketplace_orders.hpp:209
eosio::asset fact_cost
actual_quantity * unit_price / 10^precision (после issueact2)
Definition: table_marketplace_orders.hpp:165
eosio::binary_extension< document2 > issue_protocol
Definition: table_marketplace_orders.hpp:212
uint64_t id
внутренний ID
Definition: table_marketplace_orders.hpp:149
eosio::asset quantity
заказанное количество (asset с символом единицы KG/LTR/PCS, Эпик 17)
Definition: table_marketplace_orders.hpp:160
eosio::name payout_status
Locked Decision L12 — состояние выплаты поставщику через gateway (см. namespace OrderPayoutStatus)
Definition: table_marketplace_orders.hpp:182
eosio::asset total_cost
quantity * unit_price / 10^precision (заблокированная сумма)
Definition: table_marketplace_orders.hpp:164
document2 issue_act2
Акт приёма-передачи (1115) — закрывающая подпись председателя участка выдачи (issueact2); слот прежне...
Definition: table_marketplace_orders.hpp:180
eosio::asset actual_quantity
фактически выданное (issueact2); до issueact2 == quantity
Definition: table_marketplace_orders.hpp:161
document2 issue_act1
Акт приёма-передачи (1115) — первая подпись заказчика (issueact1); слот прежнего issue_act_signiss1.
Definition: table_marketplace_orders.hpp:179
eosio::name delivery_braname
КУ выдачи (выбран пайщиком на createorder); проверка readyissue/issueact2/p.mkt.return через Branch::...
Definition: table_marketplace_orders.hpp:156
uint64_t return_request_id
0 если активного гарантийного возврата нет
Definition: table_marketplace_orders.hpp:185
On-chain Заявление на гарантийный возврат — анкер процесса p.mkt.return.
Definition: table_marketplace_return_requests.hpp:70
checksum256 original_order_hash
process_hash оригинального p.mkt.supply
Definition: table_marketplace_return_requests.hpp:77
On-chain гарантийная претензия поставщику — анкер процесса p.mkt.claim (компонент 68,...
Definition: table_marketplace_warranty_claims.hpp:48
On-chain Проект решения совета о списании скоропорта — анкер процесса p.mkt.wroff.
Definition: table_marketplace_writeoff_proposals.hpp:92
Definition: document_core.hpp:27
static constexpr eosio::name MARKETPLACE_MEMBER_FUND
ЦПП «Стол Заказов» — внутренний членский кошелёк пайщика в программе (USER_SHARED,...
Definition: wallets.hpp:75
static constexpr eosio::name MARKETPLACE_ORDER_LOCK
ЦПП «Стол Заказов» — паевой резерв пайщика под конкретный Order (USER_SHARED, счёт 80)....
Definition: wallets.hpp:73
static constexpr eosio::name MARKETPLACE_SHARE_FUND
ЦПП «Стол Заказов» — свободный паевой пайщика в программе (USER_SHARED, счёт 80). Сюда возвращается о...
Definition: wallets.hpp:74
static constexpr eosio::name SHARE_FUND_PAY
Паевой взнос пайщика (USER_SHARED)
Definition: wallets.hpp:48
Definition: table_soviet_programs.hpp:17
eosio::binary_extension< eosio::asset > available
Definition: table_soviet_programs.hpp:38
eosio::multi_index< "userwallets"_n, userwallet, eosio::indexed_by<"byuserwallet"_n, eosio::const_mem_fun< userwallet, uint128_t, &userwallet::by_userwallet > >, eosio::indexed_by<"byuser"_n, eosio::const_mem_fun< userwallet, uint64_t, &userwallet::by_user > >, eosio::indexed_by<"bywallet"_n, eosio::const_mem_fun< userwallet, uint64_t, &userwallet::by_wallet > > > userwallets_index
Definition: table_ledger2_userwallets.hpp:48
eosio::singleton<"config"_n, mkt_config > mkt_config_singleton
Definition: table_marketplace_fee_config.hpp:30
std::optional< eosio::name > get_participant_branch(eosio::name coopname, eosio::name username)
Definition: table_soviet_participants.hpp:57
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y)
Definition: utils.hpp:7