#![recursion_limit = "1024"]
#![allow(unused_imports)]
pub mod domain;
pub mod infrastructure;
pub mod application;
pub mod presentation;
pub mod seeders;
pub mod exports;
pub use domain::entity::*;
pub use infrastructure::persistence::*;
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;
pub use application::validator::{ValidationError, ValidationResult};
pub use application::workflows::*;
use std::sync::Arc;
use axum::Router;
use sqlx::PgPool;
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>,
pub(crate) db_pool: PgPool,
pub(crate) reconcile_write_service:
Arc<crate::application::service::reconcile_write_service::ReconcileWriteService>,
pub(crate) check_printing_service:
Arc<crate::application::service::check_printing_service::CheckPrintingService>,
pub(crate) emv_qr_service:
Arc<crate::application::service::emv_qr_service::EmvQrService>,
pub(crate) tax_tag_repair_service:
Arc<crate::application::service::tax_tag_repair_service::TaxTagRepairService>,
pub(crate) deferred_tax: Option<Arc<dyn crate::domain::repositories::DeferredTaxLookup>>,
pub(crate) budget_control: Option<Arc<dyn crate::domain::repositories::BudgetControlPort>>,
pub(crate) chart_install_service:
Arc<crate::application::service::chart_install_service::ChartInstallService>,
pub(crate) reporting_service:
Arc<crate::application::service::reporting_service::ReportingService>,
}
impl AccountingModule {
pub fn builder() -> AccountingModuleBuilder {
AccountingModuleBuilder::new()
}
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()))
.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(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()
}
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()))
}
pub fn budget_control(
&self,
) -> Option<Arc<dyn crate::domain::repositories::BudgetControlPort>> {
self.budget_control.clone()
}
pub fn reporting_service(
&self,
) -> std::sync::Arc<crate::application::service::reporting_service::ReportingService> {
self.reporting_service.clone()
}
pub fn reconcile_write_service(
&self,
) -> std::sync::Arc<crate::application::service::reconcile_write_service::ReconcileWriteService>
{
self.reconcile_write_service.clone()
}
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()),
)
}
pub fn chart_install_service(
&self,
) -> std::sync::Arc<crate::application::service::chart_install_service::ChartInstallService>
{
self.chart_install_service.clone()
}
pub fn check_printing_service(
&self,
) -> std::sync::Arc<crate::application::service::check_printing_service::CheckPrintingService>
{
self.check_printing_service.clone()
}
pub fn emv_qr_service(
&self,
) -> std::sync::Arc<crate::application::service::emv_qr_service::EmvQrService> {
self.emv_qr_service.clone()
}
pub fn tax_tag_repair_service(
&self,
) -> std::sync::Arc<crate::application::service::tax_tag_repair_service::TaxTagRepairService>
{
self.tax_tag_repair_service.clone()
}
}
pub struct AccountingModuleBuilder {
db_pool: Option<PgPool>,
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>>,
}
impl AccountingModuleBuilder {
pub fn new() -> Self {
Self {
db_pool: None,
deferred_tax: None,
budget_control: None,
chart_datasets: Vec::new(),
}
}
pub fn with_database(mut self, pool: PgPool) -> Self {
self.db_pool = Some(pool);
self
}
pub fn with_chart_dataset(
mut self,
dataset: Arc<crate::domain::chart_dataset::ChartDataset>,
) -> Self {
self.chart_datasets.push(dataset);
self
}
pub fn with_deferred_tax(
mut self,
port: Arc<dyn crate::domain::repositories::DeferredTaxLookup>,
) -> Self {
self.deferred_tax = Some(port);
self
}
pub fn with_budget_control(
mut self,
port: Arc<dyn crate::domain::repositories::BudgetControlPort>,
) -> Self {
self.budget_control = Some(port);
self
}
pub fn build(self) -> anyhow::Result<AccountingModule> {
let db_pool = self.db_pool
.ok_or_else(|| anyhow::anyhow!("Database pool not configured"))?;
let account_repository = Arc::new(AccountRepository::new(db_pool.clone()));
let account_service = Arc::new(AccountService::with_repository(account_repository.clone()));
let accounting_post_repository = Arc::new(AccountingPostRepository::new(db_pool.clone()));
let accounting_post_service = Arc::new(AccountingPostService::with_repository(accounting_post_repository.clone()));
let cost_center_repository = Arc::new(CostCenterRepository::new(db_pool.clone()));
let cost_center_service = Arc::new(CostCenterService::with_repository(cost_center_repository.clone()));
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()));
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()));
let printed_check_repository = Arc::new(PrintedCheckRepository::new(db_pool.clone()));
let printed_check_service = Arc::new(PrintedCheckService::with_repository(printed_check_repository.clone()));
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()));
let financial_statement_repository = Arc::new(FinancialStatementRepository::new(db_pool.clone()));
let financial_statement_service = Arc::new(FinancialStatementService::with_repository(financial_statement_repository.clone()));
let fiscal_period_repository = Arc::new(FiscalPeriodRepository::new(db_pool.clone()));
let fiscal_period_service = Arc::new(FiscalPeriodService::with_repository(fiscal_period_repository.clone()));
let journal_repository = Arc::new(JournalRepository::new(db_pool.clone()));
let journal_service = Arc::new(JournalService::with_repository(journal_repository.clone()));
let journal_line_repository = Arc::new(JournalLineRepository::new(db_pool.clone()));
let journal_line_service = Arc::new(JournalLineService::with_repository(journal_line_repository.clone()));
let ledger_repository = Arc::new(LedgerRepository::new(db_pool.clone()));
let ledger_service = Arc::new(LedgerService::with_repository(ledger_repository.clone()));
let reconciliation_repository = Arc::new(ReconciliationRepository::new(db_pool.clone()));
let reconciliation_service = Arc::new(ReconciliationService::with_repository(reconciliation_repository.clone()));
let reconciliation_item_repository = Arc::new(ReconciliationItemRepository::new(db_pool.clone()));
let reconciliation_item_service = Arc::new(ReconciliationItemService::with_repository(reconciliation_item_repository.clone()));
let full_reconcile_repository = Arc::new(FullReconcileRepository::new(db_pool.clone()));
let full_reconcile_service = Arc::new(FullReconcileService::with_repository(full_reconcile_repository.clone()));
let partial_reconcile_repository = Arc::new(PartialReconcileRepository::new(db_pool.clone()));
let partial_reconcile_service = Arc::new(PartialReconcileService::with_repository(partial_reconcile_repository.clone()));
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()),
);
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,
),
);
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(),
),
),
),
);
let check_printing_service = std::sync::Arc::new(
crate::application::service::check_printing_service::CheckPrintingService::new(
db_pool.clone(),
),
);
let emv_qr_service = std::sync::Arc::new(
crate::application::service::emv_qr_service::EmvQrService::new(db_pool.clone()),
);
let tax_tag_repair_service = std::sync::Arc::new(
crate::application::service::tax_tag_repair_service::TaxTagRepairService::new(
db_pool.clone(),
),
);
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,
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,
})
}
}
impl Default for AccountingModuleBuilder {
fn default() -> Self {
Self::new()
}
}