backbone-accounting 0.18.2

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! Domain Entities
//!
//! Generated by metaphor-schema. Do not edit manually.

pub mod account;
pub mod accounting_post;
pub mod cost_center;
pub mod emv_qr_config;
pub mod bank_check_sequence;
pub mod printed_check;
pub mod tax_tag_repair_run;
pub mod financial_statement;
pub mod fiscal_period;
pub mod journal;
pub mod journal_line;
pub mod ledger;
pub mod reconciliation;
pub mod reconciliation_item;
pub mod full_reconcile;
pub mod partial_reconcile;
pub mod account_type;
pub mod account_subtype;
pub mod normal_balance;
pub mod account_status;
pub mod party_type;
pub mod posting_source_type;
pub mod posting_type;
pub mod posting_status;
pub mod cost_center_status;
pub mod statement_type;
pub mod statement_status;
pub mod period_type;
pub mod period_status;
pub mod journal_type;
pub mod journal_source;
pub mod journal_status;
pub mod reconciliation_type;
pub mod reconciliation_status;
pub mod reconciliation_item_status;
pub mod reconcile_origin;

// Re-exports
pub use account::Account;
pub use account::AccountBuilder;
pub use account::AccountId;
pub use accounting_post::AccountingPost;
pub use accounting_post::AccountingPostBuilder;
pub use accounting_post::AccountingPostId;
pub use cost_center::CostCenter;
pub use cost_center::CostCenterBuilder;
pub use cost_center::CostCenterId;
pub use emv_qr_config::EmvQrConfig;
pub use emv_qr_config::EmvQrConfigBuilder;
pub use emv_qr_config::EmvQrConfigId;
pub use bank_check_sequence::BankCheckSequence;
pub use bank_check_sequence::BankCheckSequenceBuilder;
pub use bank_check_sequence::BankCheckSequenceId;
pub use printed_check::PrintedCheck;
pub use printed_check::PrintedCheckBuilder;
pub use printed_check::PrintedCheckId;
pub use tax_tag_repair_run::TaxTagRepairRun;
pub use tax_tag_repair_run::TaxTagRepairRunBuilder;
pub use tax_tag_repair_run::TaxTagRepairRunId;
pub use financial_statement::FinancialStatement;
pub use financial_statement::FinancialStatementBuilder;
pub use financial_statement::FinancialStatementId;
pub use fiscal_period::FiscalPeriod;
pub use fiscal_period::FiscalPeriodBuilder;
pub use fiscal_period::FiscalPeriodId;
pub use journal::Journal;
pub use journal::JournalBuilder;
pub use journal::JournalId;
pub use journal_line::JournalLine;
pub use journal_line::JournalLineBuilder;
pub use journal_line::JournalLineId;
pub use ledger::Ledger;
pub use ledger::LedgerBuilder;
pub use ledger::LedgerId;
pub use reconciliation::Reconciliation;
pub use reconciliation::ReconciliationBuilder;
pub use reconciliation::ReconciliationId;
pub use reconciliation_item::ReconciliationItem;
pub use reconciliation_item::ReconciliationItemBuilder;
pub use reconciliation_item::ReconciliationItemId;
pub use full_reconcile::FullReconcile;
pub use full_reconcile::FullReconcileBuilder;
pub use full_reconcile::FullReconcileId;
pub use partial_reconcile::PartialReconcile;
pub use partial_reconcile::PartialReconcileBuilder;
pub use partial_reconcile::PartialReconcileId;
pub use account_type::AccountType;
pub use account_subtype::AccountSubtype;
pub use normal_balance::NormalBalance;
pub use account_status::AccountStatus;
pub use party_type::PartyType;
pub use posting_source_type::PostingSourceType;
pub use posting_type::PostingType;
pub use posting_status::PostingStatus;
pub use cost_center_status::CostCenterStatus;
pub use statement_type::StatementType;
pub use statement_status::StatementStatus;
pub use period_type::PeriodType;
pub use period_status::PeriodStatus;
pub use journal_type::JournalType;
pub use journal_source::JournalSource;
pub use journal_status::JournalStatus;
pub use reconciliation_type::ReconciliationType;
pub use reconciliation_status::ReconciliationStatus;
pub use reconciliation_item_status::ReconciliationItemStatus;
pub use reconcile_origin::ReconcileOrigin;

// ==========================================================================
// Entity Trait
// ==========================================================================

use std::fmt::Debug;

/// Trait for domain entities
///
/// All generated entities implement this trait, providing
/// a common interface for working with domain objects.
pub trait Entity: Debug + Clone {
    /// The type of the entity's unique identifier
    type Id: Debug + Clone + PartialEq;

    /// Get the entity's unique identifier
    fn entity_id(&self) -> &Self::Id;

    /// Get the entity type name
    fn entity_type() -> &'static str;
}

// ==========================================================================
// Audit Metadata
// ==========================================================================

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

/// Audit metadata stored as JSONB in the database
///
/// This struct consolidates audit fields (timestamps and actors) into a single
/// JSONB column for efficient storage and flexible querying.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct AuditMetadata {
    /// Timestamp when the record was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<DateTime<Utc>>,

    /// Timestamp when the record was last updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<DateTime<Utc>>,

    /// Timestamp when the record was soft-deleted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deleted_at: Option<DateTime<Utc>>,

    /// User ID who created the record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_by: Option<Uuid>,

    /// User ID who last updated the record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_by: Option<Uuid>,

    /// User ID who deleted the record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deleted_by: Option<Uuid>,
}

impl AuditMetadata {
    /// Create new audit metadata with created_at set to now
    pub fn new() -> Self {
        Self {
            created_at: Some(Utc::now()),
            ..Default::default()
        }
    }

    /// Create with creator ID
    pub fn with_creator(creator_id: Uuid) -> Self {
        Self {
            created_at: Some(Utc::now()),
            created_by: Some(creator_id),
            ..Default::default()
        }
    }

    /// Touch the record (update updated_at)
    pub fn touch(&mut self) {
        self.updated_at = Some(Utc::now());
    }

    /// Touch with updater ID
    pub fn touch_by(&mut self, updater_id: Uuid) {
        self.updated_at = Some(Utc::now());
        self.updated_by = Some(updater_id);
    }

    /// Soft delete the record
    pub fn soft_delete(&mut self) {
        self.deleted_at = Some(Utc::now());
    }

    /// Soft delete with deleter ID
    pub fn soft_delete_by(&mut self, deleter_id: Uuid) {
        self.deleted_at = Some(Utc::now());
        self.deleted_by = Some(deleter_id);
    }

    /// Restore a soft-deleted record
    pub fn restore(&mut self) {
        self.deleted_at = None;
        self.deleted_by = None;
    }

    /// Check if record is deleted
    pub fn is_deleted(&self) -> bool {
        self.deleted_at.is_some()
    }

    /// Check if record is active (not deleted)
    pub fn is_active(&self) -> bool {
        self.deleted_at.is_none()
    }
}