1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Pipeline orchestration — the journal-global enrichment phases that
//! run after [`load`](crate::load) and before any filtering, conversion
//! or sorting.
//!
//! These phases must see the *whole* journal, un-filtered: the lotter
//! tracks lots FIFO across every transaction, and the translator
//! identifies pass-through accounts by their journal-wide native sum.
//! Filtering first would change those sums and corrupt the result. They
//! are also where the subtle cross-phase rules live, so they belong
//! together in one tested place rather than inlined in the CLI:
//!
//! 1. **expander** — apply `= /pattern/` auto-rules; later phases then
//! see the fully expanded journal.
//! 2. **realizer** — per-transaction fx gain/loss where the implied rate
//! diverges from the market rate. Skipped when capital-tracking is
//! active: the lotter then owns the spread (split per disposal at the
//! realization rate), so a per-transaction realizer would double-book.
//! 3. **lotter** — realized capital gains via FIFO lots (long & short).
//! 4. **translator** — currency translation adjustment (CTA) for
//! pass-through accounts. Runs over *every* such account, including
//! lot-tracked ones: the lotter pins its realized legs to the booked
//! rate, so those legs already sum to zero under conversion and CTA
//! sees no drift there — no exclusion needed, no double-count.
//!
//! `rebalance`, `filter` and `sort` are deliberately *not* here. They are
//! driven by CLI flags (pattern, date range, `-X` target, sort keys) and
//! run afterwards against the already-enriched journal. Conversion is
//! per-posting and local, so it can run after filtering; these four
//! cannot.
use crateJournal;
/// Run the journal-global enrichment phases in order, mutating
/// `journal.transactions` in place.
///
/// `target` is the resolved `-X` commodity, or `None` in native mode.
/// Phases that only make sense under conversion (realizer, translator)
/// are skipped when it is `None`; the lotter always runs when capital
/// accounts are declared (it realizes in the booked commodity either
/// way).