backbone-accounting 0.10.1

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
//! Accounting Module
//!
//! Generated by metaphor-schema. Enhanced with runtime implementations.
//!
//! This module provides:
//! - Domain entities and repositories
//! - Application services
//! - HTTP and gRPC handlers
//! - Route configuration
//! - State machine enforcement
//! - Validation rules runtime
//! - RBAC middleware
//! - Trigger execution system
//! - Computed fields
//! - Workflow orchestrator

#![recursion_limit = "1024"]
#![allow(unused_imports)]

// Generated modules
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
// <<< CUSTOM MODULES
// END CUSTOM

// Re-exports for convenience - Domain entities
pub use domain::entity::*;

// Re-exports - Infrastructure
pub use infrastructure::persistence::*;

// Re-exports - Application services
pub use application::service::AccountService;
pub use application::service::AccountingPostService;
pub use application::service::CostCenterService;
pub use application::service::EmvQrConfigService;
pub use application::service::BankCheckSequenceService;
pub use application::service::PrintedCheckService;
pub use application::service::TaxTagRepairRunService;
pub use application::service::FinancialStatementService;
pub use application::service::FiscalPeriodService;
pub use application::service::JournalService;
pub use application::service::JournalLineService;
pub use application::service::LedgerService;
pub use application::service::ReconciliationService;
pub use application::service::ReconciliationItemService;
pub use application::service::FullReconcileService;
pub use application::service::PartialReconcileService;

// Re-exports - Validation
pub use application::validator::{ValidationError, ValidationResult};

// Re-exports - Workflows
pub use application::workflows::*;

use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;

/// Accounting module configuration
///
/// Use the builder pattern to configure and register this module:
///
/// ```text
/// let accounting = AccountingModule::builder()
///     .with_database(pool.clone())
///     .build()?;
///
/// // Unguarded full CRUD (trusted/admin); compose a guarded router for production.
/// let router = accounting.all_crud_routes();
/// ```
pub struct AccountingModule {
    pub(crate) account_service: Arc<AccountService>,
    pub(crate) accounting_post_service: Arc<AccountingPostService>,
    pub(crate) cost_center_service: Arc<CostCenterService>,
    pub(crate) emv_qr_config_service: Arc<EmvQrConfigService>,
    pub(crate) bank_check_sequence_service: Arc<BankCheckSequenceService>,
    pub(crate) printed_check_service: Arc<PrintedCheckService>,
    pub(crate) tax_tag_repair_run_service: Arc<TaxTagRepairRunService>,
    pub(crate) financial_statement_service: Arc<FinancialStatementService>,
    pub(crate) fiscal_period_service: Arc<FiscalPeriodService>,
    pub(crate) journal_service: Arc<JournalService>,
    pub(crate) journal_line_service: Arc<JournalLineService>,
    pub(crate) ledger_service: Arc<LedgerService>,
    pub(crate) reconciliation_service: Arc<ReconciliationService>,
    pub(crate) reconciliation_item_service: Arc<ReconciliationItemService>,
    pub(crate) full_reconcile_service: Arc<FullReconcileService>,
    pub(crate) partial_reconcile_service: Arc<PartialReconcileService>,
    // <<< CUSTOM FIELDS
    pub(crate) db_pool: PgPool,
    pub(crate) reconcile_write_service:
        Arc<crate::application::service::reconcile_write_service::ReconcileWriteService>,
    /// The check printing surface: per-bank-journal check-number sequences and
    /// the printed-check registry.
    pub(crate) check_printing_service:
        Arc<crate::application::service::check_printing_service::CheckPrintingService>,
    /// The EMV(QRCPS)/QRIS display surface: merchant QR configuration and the
    /// invoice payload render.
    pub(crate) emv_qr_service:
        Arc<crate::application::service::emv_qr_service::EmvQrService>,
    /// The tax-tag legal-change repair verb and its audit ledger read.
    pub(crate) tax_tag_repair_service:
        Arc<crate::application::service::tax_tag_repair_service::TaxTagRepairService>,
    /// Host-implemented cash-basis tax deferral lookup, kept so post-build
    /// service variants (e.g. the exchange-account one) keep the flip wired.
    pub(crate) deferred_tax: Option<Arc<dyn crate::domain::repositories::DeferredTaxLookup>>,
    /// Host-implemented budget control, kept so every posting path the host
    /// builds from this module (the HTTP posting verb, the journal workflow,
    /// the period close) can arm the consult from one registration.
    pub(crate) budget_control: Option<Arc<dyn crate::domain::repositories::BudgetControlPort>>,
    /// Chart install engine over the datasets registered via `with_chart_dataset`.
    pub(crate) chart_install_service:
        Arc<crate::application::service::chart_install_service::ChartInstallService>,
    /// On-the-fly financial reports (TB tree, BS, P&L, GL, partner ledger, aged AR/AP).
    pub(crate) reporting_service:
        Arc<crate::application::service::reporting_service::ReportingService>,
    // END CUSTOM
}

impl AccountingModule {
    /// Create a new module builder
    pub fn builder() -> AccountingModuleBuilder {
        AccountingModuleBuilder::new()
    }

    /// Mount ALL generated CRUD endpoints (12 per entity) with NO domain
    /// validation — the fully **unguarded** surface. A well-formed request can
    /// create invalid rows or soft-delete a referenced master out from under its
    /// dependents. Prefer a guarded composition (read + validated writes) for any
    /// real deployment; use this only in trusted/admin/seeding contexts.
    pub fn all_crud_routes(&self) -> Router {
        use presentation::http::{
            create_account_routes,
            create_accounting_post_routes,
            create_cost_center_routes,
            create_emv_qr_config_routes,
            create_bank_check_sequence_routes,
            create_printed_check_routes,
            create_tax_tag_repair_run_routes,
            create_financial_statement_routes,
            create_fiscal_period_read_routes,
            create_journal_routes,
            create_journal_line_routes,
            create_ledger_routes,
            create_reconciliation_routes,
            create_reconciliation_item_routes,
            create_full_reconcile_routes,
            create_partial_reconcile_routes,
        };

        Router::new()
            .merge(create_account_routes(self.account_service.clone()))
            .merge(create_accounting_post_routes(self.accounting_post_service.clone()))
            .merge(create_cost_center_routes(self.cost_center_service.clone()))
            .merge(create_emv_qr_config_routes(self.emv_qr_config_service.clone()))
            .merge(create_bank_check_sequence_routes(self.bank_check_sequence_service.clone()))
            .merge(create_printed_check_routes(self.printed_check_service.clone()))
            .merge(create_tax_tag_repair_run_routes(self.tax_tag_repair_run_service.clone()))
            .merge(create_financial_statement_routes(self.financial_statement_service.clone()))
            // FiscalPeriod: hand_set lifecycle — the state field moves only through the
            // module's validated verbs; generic writes cannot reach it, so only the
            // read surface mounts here.
            .merge(create_fiscal_period_read_routes(self.fiscal_period_service.clone()))
            .merge(create_journal_routes(self.journal_service.clone()))
            .merge(create_journal_line_routes(self.journal_line_service.clone()))
            .merge(create_ledger_routes(self.ledger_service.clone()))
            .merge(create_reconciliation_routes(self.reconciliation_service.clone()))
            .merge(create_reconciliation_item_routes(self.reconciliation_item_service.clone()))
            .merge(create_full_reconcile_routes(self.full_reconcile_service.clone()))
            .merge(create_partial_reconcile_routes(self.partial_reconcile_service.clone()))
    }

    /// Deprecated alias for [`Self::all_crud_routes`]. `routes()` reads like
    /// "the routes" but mounts UNVALIDATED generic CRUD on every entity — a naive
    /// mount exposes unguarded writes. Compose a guarded router (read + validated
    /// writes) for production, or call `all_crud_routes()` to opt into the full
    /// unguarded surface explicitly.
    #[deprecated(note = "mounts unvalidated generic CRUD; prefer readonly_routes() + validated writes, or all_crud_routes() for the full/unguarded surface")]
    pub fn routes(&self) -> Router {
        self.all_crud_routes()
    }

    /// Read-only routes for every entity (GET endpoints only) — the safe base.
    ///
    /// Generic mutation can't reach here, so this surface cannot bypass a
    /// validated write service's invariants. Use this as the production base and
    /// merge validated write routes (or a write service's HTTP layer) onto it.
    pub fn readonly_routes(&self) -> Router {
        use presentation::http::{
            create_account_read_routes,
            create_accounting_post_read_routes,
            create_cost_center_read_routes,
            create_emv_qr_config_read_routes,
            create_bank_check_sequence_read_routes,
            create_printed_check_read_routes,
            create_tax_tag_repair_run_read_routes,
            create_financial_statement_read_routes,
            create_fiscal_period_read_routes,
            create_journal_read_routes,
            create_journal_line_read_routes,
            create_ledger_read_routes,
            create_reconciliation_read_routes,
            create_reconciliation_item_read_routes,
            create_full_reconcile_read_routes,
            create_partial_reconcile_read_routes,
        };

        Router::new()
            .merge(create_account_read_routes(self.account_service.clone()))
            .merge(create_accounting_post_read_routes(self.accounting_post_service.clone()))
            .merge(create_cost_center_read_routes(self.cost_center_service.clone()))
            .merge(create_emv_qr_config_read_routes(self.emv_qr_config_service.clone()))
            .merge(create_bank_check_sequence_read_routes(self.bank_check_sequence_service.clone()))
            .merge(create_printed_check_read_routes(self.printed_check_service.clone()))
            .merge(create_tax_tag_repair_run_read_routes(self.tax_tag_repair_run_service.clone()))
            .merge(create_financial_statement_read_routes(self.financial_statement_service.clone()))
            .merge(create_fiscal_period_read_routes(self.fiscal_period_service.clone()))
            .merge(create_journal_read_routes(self.journal_service.clone()))
            .merge(create_journal_line_read_routes(self.journal_line_service.clone()))
            .merge(create_ledger_read_routes(self.ledger_service.clone()))
            .merge(create_reconciliation_read_routes(self.reconciliation_service.clone()))
            .merge(create_reconciliation_item_read_routes(self.reconciliation_item_service.clone()))
            .merge(create_full_reconcile_read_routes(self.full_reconcile_service.clone()))
            .merge(create_partial_reconcile_read_routes(self.partial_reconcile_service.clone()))
    }

    // <<< CUSTOM METHODS
    /// The registered budget-control port, if any — the single registration a
    /// host threads into every `PostingService` it builds from this module
    /// (`.with_budget_control_if_set(m.budget_control())`), so the HTTP
    /// posting verb, the journal workflow, and the period close all consult
    /// the same control.
    pub fn budget_control(
        &self,
    ) -> Option<Arc<dyn crate::domain::repositories::BudgetControlPort>> {
        self.budget_control.clone()
    }

    /// The on-the-fly financial reports (Trial Balance tree, Balance Sheet, Income
    /// Statement, General Ledger, Partner Ledger, Aged AR/AP). Read-only; scoped reads.
    pub fn reporting_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::reporting_service::ReportingService> {
        self.reporting_service.clone()
    }

    /// The reconciliation write service — the ONLY sanctioned writer of the
    /// reconciliation graph (guards + CLAMP + side-effecting unlink). The graph tables
    /// carry no CRUD surface anywhere; `guarded_routes` mounts its verb routes.
    pub fn reconcile_write_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::reconcile_write_service::ReconcileWriteService>
    {
        self.reconcile_write_service.clone()
    }

    /// Build a reconcile write service with the FX (exchange-difference) account
    /// configured. Without one, any rate divergence that demands an exchange move fails
    /// closed (`exchange_account_unconfigured`) — normal single-currency posts never
    /// generate one, so the default service is complete for them.
    pub fn reconcile_write_service_with_exchange_account(
        &self,
        exchange_account_id: uuid::Uuid,
    ) -> std::sync::Arc<crate::application::service::reconcile_write_service::ReconcileWriteService>
    {
        std::sync::Arc::new(
            crate::application::service::reconcile_write_service::ReconcileWriteService::new(
                std::sync::Arc::new(
                    crate::infrastructure::persistence::reconcile_graph_repository::SqlxReconcileGraphRepository::new(),
                ),
                std::sync::Arc::new(
                    crate::infrastructure::persistence::posting_repository::SqlxPostingRepository::new(
                        self.db_pool.clone(),
                    ),
                ),
                self.db_pool.clone(),
                Some(exchange_account_id),
            )
            .with_deferred_tax_if_set(self.deferred_tax.clone()),
        )
    }

    /// The chart install engine — validates, gates, and writes a registered chart
    /// dataset into the accounts, idempotently. The install VERB itself is
    /// host-mounted (it orchestrates beyond this module); this handle is the engine
    /// the host verb drives.
    pub fn chart_install_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::chart_install_service::ChartInstallService>
    {
        self.chart_install_service.clone()
    }

    /// The check printing surface — sequence registration, atomic number
    /// allocation, the printed-check registry, and voids. `guarded_routes`
    /// mounts its verb routes; there is no CRUD path to these tables.
    pub fn check_printing_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::check_printing_service::CheckPrintingService>
    {
        self.check_printing_service.clone()
    }

    /// The EMV(QRCPS)/QRIS display surface — merchant QR configuration and the
    /// invoice payload render (payloads are built on demand, never stored).
    pub fn emv_qr_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::emv_qr_service::EmvQrService> {
        self.emv_qr_service.clone()
    }

    /// The tax-tag legal-change repair verb (reason mandatory, locked periods
    /// refused, closed periods overridden explicitly, every run audit-stamped)
    /// plus its audit-ledger read.
    pub fn tax_tag_repair_service(
        &self,
    ) -> std::sync::Arc<crate::application::service::tax_tag_repair_service::TaxTagRepairService>
    {
        self.tax_tag_repair_service.clone()
    }
    // END CUSTOM
}

/// Builder for AccountingModule
pub struct AccountingModuleBuilder {
    db_pool: Option<PgPool>,
    // <<< CUSTOM BUILDER FIELDS
    deferred_tax: Option<Arc<dyn crate::domain::repositories::DeferredTaxLookup>>,
    budget_control: Option<Arc<dyn crate::domain::repositories::BudgetControlPort>>,
    chart_datasets: Vec<Arc<crate::domain::chart_dataset::ChartDataset>>,
    // END CUSTOM
}

impl AccountingModuleBuilder {
    /// Create a new builder
    pub fn new() -> Self {
        Self {
            db_pool: None,
            // <<< CUSTOM BUILDER DEFAULTS
            deferred_tax: None,
            budget_control: None,
            chart_datasets: Vec::new(),
            // END CUSTOM
        }
    }

    /// Set the database connection pool
    pub fn with_database(mut self, pool: PgPool) -> Self {
        self.db_pool = Some(pool);
        self
    }

    // <<< CUSTOM - custom builder methods
    /// Register a chart-of-accounts dataset installable through the chart install
    /// engine. Datasets are data (commonly shipped by an l10n module); registering
    /// one makes it listable via `GET /accounting/charts` and installable by the
    /// host-mounted install verb.
    pub fn with_chart_dataset(
        mut self,
        dataset: Arc<crate::domain::chart_dataset::ChartDataset>,
    ) -> Self {
        self.chart_datasets.push(dataset);
        self
    }

    /// Wire the host's cash-basis tax deferral lookup: partial reconciliations
    /// landing on receivable/payable lines flip deferred (on_payment) tax
    /// pro-rata from the transition account onto the real tax account. Hosts
    /// without a tax module leave it unset — no flips, everything else works.
    pub fn with_deferred_tax(
        mut self,
        port: Arc<dyn crate::domain::repositories::DeferredTaxLookup>,
    ) -> Self {
        self.deferred_tax = Some(port);
        self
    }

    /// Wire the host's budget control: postings through the GL-posting
    /// chokepoint are checked against confirmed budget positions (account x
    /// cost center x fiscal period) after the pure double-entry rules pass.
    /// Warn-enforcement breaches log and proceed; block-enforcement breaches
    /// refuse the posting. Hosts without a budget module leave it unset — no
    /// check, everything else works (fail-open).
    pub fn with_budget_control(
        mut self,
        port: Arc<dyn crate::domain::repositories::BudgetControlPort>,
    ) -> Self {
        self.budget_control = Some(port);
        self
    }
    // END CUSTOM

    /// Build the module with configured dependencies
    pub fn build(self) -> anyhow::Result<AccountingModule> {
        let db_pool = self.db_pool
            .ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;

        // Account service
        let account_repository = Arc::new(AccountRepository::new(db_pool.clone()));
        let account_service = Arc::new(AccountService::with_repository(account_repository.clone()));

        // AccountingPost service
        let accounting_post_repository = Arc::new(AccountingPostRepository::new(db_pool.clone()));
        let accounting_post_service = Arc::new(AccountingPostService::with_repository(accounting_post_repository.clone()));

        // CostCenter service
        let cost_center_repository = Arc::new(CostCenterRepository::new(db_pool.clone()));
        let cost_center_service = Arc::new(CostCenterService::with_repository(cost_center_repository.clone()));

        // EmvQrConfig service
        let emv_qr_config_repository = Arc::new(EmvQrConfigRepository::new(db_pool.clone()));
        let emv_qr_config_service = Arc::new(EmvQrConfigService::with_repository(emv_qr_config_repository.clone()));

        // BankCheckSequence service
        let bank_check_sequence_repository = Arc::new(BankCheckSequenceRepository::new(db_pool.clone()));
        let bank_check_sequence_service = Arc::new(BankCheckSequenceService::with_repository(bank_check_sequence_repository.clone()));

        // PrintedCheck service
        let printed_check_repository = Arc::new(PrintedCheckRepository::new(db_pool.clone()));
        let printed_check_service = Arc::new(PrintedCheckService::with_repository(printed_check_repository.clone()));

        // TaxTagRepairRun service
        let tax_tag_repair_run_repository = Arc::new(TaxTagRepairRunRepository::new(db_pool.clone()));
        let tax_tag_repair_run_service = Arc::new(TaxTagRepairRunService::with_repository(tax_tag_repair_run_repository.clone()));

        // FinancialStatement service
        let financial_statement_repository = Arc::new(FinancialStatementRepository::new(db_pool.clone()));
        let financial_statement_service = Arc::new(FinancialStatementService::with_repository(financial_statement_repository.clone()));

        // FiscalPeriod service
        let fiscal_period_repository = Arc::new(FiscalPeriodRepository::new(db_pool.clone()));
        let fiscal_period_service = Arc::new(FiscalPeriodService::with_repository(fiscal_period_repository.clone()));

        // Journal service
        let journal_repository = Arc::new(JournalRepository::new(db_pool.clone()));
        let journal_service = Arc::new(JournalService::with_repository(journal_repository.clone()));

        // JournalLine service
        let journal_line_repository = Arc::new(JournalLineRepository::new(db_pool.clone()));
        let journal_line_service = Arc::new(JournalLineService::with_repository(journal_line_repository.clone()));

        // Ledger service
        let ledger_repository = Arc::new(LedgerRepository::new(db_pool.clone()));
        let ledger_service = Arc::new(LedgerService::with_repository(ledger_repository.clone()));

        // Reconciliation service
        let reconciliation_repository = Arc::new(ReconciliationRepository::new(db_pool.clone()));
        let reconciliation_service = Arc::new(ReconciliationService::with_repository(reconciliation_repository.clone()));

        // ReconciliationItem service
        let reconciliation_item_repository = Arc::new(ReconciliationItemRepository::new(db_pool.clone()));
        let reconciliation_item_service = Arc::new(ReconciliationItemService::with_repository(reconciliation_item_repository.clone()));

        // FullReconcile service
        let full_reconcile_repository = Arc::new(FullReconcileRepository::new(db_pool.clone()));
        let full_reconcile_service = Arc::new(FullReconcileService::with_repository(full_reconcile_repository.clone()));

        // PartialReconcile service
        let partial_reconcile_repository = Arc::new(PartialReconcileRepository::new(db_pool.clone()));
        let partial_reconcile_service = Arc::new(PartialReconcileService::with_repository(partial_reconcile_repository.clone()));

        // <<< CUSTOM
        // Reconciliation write service: graph port + posting port (reversals of
        // generated moves) over the shared pool; no FX account by default (fail-closed).
        let reconcile_graph_repository = std::sync::Arc::new(
            crate::infrastructure::persistence::reconcile_graph_repository::SqlxReconcileGraphRepository::new(),
        );
        let reconcile_posting_repository = std::sync::Arc::new(
            crate::infrastructure::persistence::posting_repository::SqlxPostingRepository::new(
                db_pool.clone(),
            ),
        );
        let reconcile_write_service = std::sync::Arc::new(
            crate::application::service::reconcile_write_service::ReconcileWriteService::new(
                reconcile_graph_repository,
                reconcile_posting_repository,
                db_pool.clone(),
                None,
            )
            .with_deferred_tax_if_set(self.deferred_tax.clone()),
        );
        // Chart install engine: datasets registered by the host drive idempotent
        // chart installs onto fresh companies (provenance columns identify own rows).
        let chart_install_service = std::sync::Arc::new(
            crate::application::service::chart_install_service::ChartInstallService::new(
                std::sync::Arc::new(
                    crate::infrastructure::persistence::chart_install_repository::SqlxChartInstallRepository::new(),
                ),
                db_pool.clone(),
                self.chart_datasets,
            ),
        );
        // Financial reports: computed on the fly over the scoped ledger reads.
        let reporting_service = std::sync::Arc::new(
            crate::application::service::reporting_service::ReportingService::new(
                std::sync::Arc::new(
                    crate::infrastructure::persistence::reporting_repository::SqlxReportingRepository::new(
                        db_pool.clone(),
                    ),
                ),
            ),
        );
        // Check printing: per-bank-journal number sequences + the printed-check
        // registry, all writes through the guarded verb set.
        let check_printing_service = std::sync::Arc::new(
            crate::application::service::check_printing_service::CheckPrintingService::new(
                db_pool.clone(),
            ),
        );
        // EMV(QRCPS)/QRIS display: merchant QR config + invoice payload render.
        let emv_qr_service = std::sync::Arc::new(
            crate::application::service::emv_qr_service::EmvQrService::new(db_pool.clone()),
        );
        // Tax-tag legal-change repair verb + its audit ledger read.
        let tax_tag_repair_service = std::sync::Arc::new(
            crate::application::service::tax_tag_repair_service::TaxTagRepairService::new(
                db_pool.clone(),
            ),
        );
        // END CUSTOM

        Ok(AccountingModule {
            account_service,
            accounting_post_service,
            cost_center_service,
            emv_qr_config_service,
            bank_check_sequence_service,
            printed_check_service,
            tax_tag_repair_run_service,
            financial_statement_service,
            fiscal_period_service,
            journal_service,
            journal_line_service,
            ledger_service,
            reconciliation_service,
            reconciliation_item_service,
            full_reconcile_service,
            partial_reconcile_service,
            // <<< CUSTOM
            db_pool,
            reconcile_write_service,
            deferred_tax: self.deferred_tax,
            budget_control: self.budget_control,
            chart_install_service,
            reporting_service,
            check_printing_service,
            emv_qr_service,
            tax_tag_repair_service,
            // END CUSTOM
        })
    }
}

impl Default for AccountingModuleBuilder {
    fn default() -> Self {
        Self::new()
    }
}