swift_mt_message/fields/
field60.rs

1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::SwiftField;
4
5///   **Field 60: Opening Balance**
6///
7/// ## Purpose
8/// Specifies the opening balance of an account in customer statement messages (MT 940)
9/// and other cash management contexts. This field establishes the starting position for
10/// account balance calculations and provides the foundation for statement processing
11/// and account reconciliation. Essential for cash management and account monitoring.
12///
13/// ## Format Options Overview
14/// - **Option F**: First opening balance - initial balance at statement start
15/// - **Option M**: Intermediate opening balance - balance after sequence breaks
16///
17/// ## Business Context Applications
18/// - **Customer Statements**: Opening balance for MT 940 Customer Statement Message
19/// - **Cash Management**: Starting position for balance calculations
20/// - **Account Reconciliation**: Foundation for account balance verification
21/// - **Sequence Processing**: Balance continuation across statement sequences
22///
23/// ## Network Validation Requirements
24/// - **Date Validation**: Value date must be valid calendar date
25/// - **Currency Validation**: Must be valid ISO 4217 currency code
26/// - **Amount Format**: Decimal amount with proper precision
27/// - **Mark Validation**: Debit/Credit mark must be D (Debit) or C (Credit)
28///
29/// ## Balance Calculation Context
30/// ### Opening Balance Logic
31/// - **First Balance (F)**: Initial balance at beginning of statement period
32/// - **Intermediate Balance (M)**: Balance at sequence break within statement
33/// - **Continuity**: Ensures balance continuity across statement processing
34/// - **Verification**: Enables balance verification and reconciliation
35///
36/// ### Statement Processing
37/// - **MT 940 Integration**: Core component of customer statement messages
38/// - **Sequence Management**: Handles statement sequence breaks
39/// - **Balance Chain**: Links to statement lines (Field 61) and closing balance (Field 62)
40/// - **Period Definition**: Establishes statement period starting point
41///
42/// ## Regional Considerations
43/// - **European Banking**: SEPA statement requirements and Euro processing
44/// - **US Banking**: Federal Reserve and commercial bank statement standards
45/// - **Asian Markets**: Local banking statement requirements
46/// - **Cross-Border**: Multi-currency account statement processing
47///
48/// ## Error Prevention Guidelines
49/// - **Date Verification**: Confirm value date is within acceptable range
50/// - **Currency Consistency**: Ensure currency matches account currency
51/// - **Amount Precision**: Verify amount precision matches currency requirements
52/// - **Mark Validation**: Confirm debit/credit mark is appropriate
53///
54/// ## Related Fields Integration
55/// - **Field 61**: Statement Line (transaction details)
56/// - **Field 62**: Closing Balance (ending balance)
57/// - **Field 64**: Closing Available Balance (available funds)
58/// - **Field 65**: Forward Available Balance (future availability)
59///
60/// ## Compliance Framework
61/// - **Banking Regulations**: Compliance with local banking statement requirements
62/// - **Audit Documentation**: Proper balance documentation for audit trails
63/// - **Customer Communication**: Clear balance communication to account holders
64/// - **Reconciliation Support**: Foundation for account reconciliation processes
65///
66/// ## See Also
67/// - Swift FIN User Handbook: Opening Balance Specifications
68/// - MT 940 Message Standards: Customer Statement Message
69/// - Cash Management Guidelines: Balance Processing Standards
70/// - Account Statement Requirements: Regional Banking Standards
71///
72///   **Field 60F: First Opening Balance**
73///
74/// Initial opening balance at the beginning of a statement period.
75/// Used when starting a new statement or account balance sequence.
76#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
77pub struct Field60F {
78    /// Debit or Credit mark
79    ///
80    /// Format: 1!a - 'D' (Debit) or 'C' (Credit)
81    /// Indicates whether the opening balance is a debit or credit position
82    #[component("1!a")]
83    pub debit_credit_mark: String,
84
85    /// Value date of the opening balance
86    ///
87    /// Format: 6!n (YYMMDD) - Date when balance is effective
88    /// Must be valid calendar date within acceptable range
89    #[component("6!n")]
90    pub value_date: NaiveDate,
91
92    /// Currency of the balance
93    ///
94    /// Format: 3!a - ISO 4217 currency code (USD, EUR, GBP, etc.)
95    /// Must match account currency for consistency
96    #[component("3!a")]
97    pub currency: String,
98
99    /// Opening balance amount
100    ///
101    /// Format: 15d - Decimal amount with comma separator
102    /// Precision must match currency requirements
103    #[component("15d")]
104    pub amount: f64,
105}
106
107///   **Field 60M: Intermediate Opening Balance**
108///
109/// Opening balance after a sequence break within a statement period.
110/// Used to maintain balance continuity across statement sequences.
111#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
112pub struct Field60M {
113    /// Debit or Credit mark
114    ///
115    /// Format: 1!a - 'D' (Debit) or 'C' (Credit)
116    /// Indicates whether the intermediate opening balance is a debit or credit position
117    #[component("1!a")]
118    pub debit_credit_mark: String,
119
120    /// Value date of the intermediate opening balance
121    ///
122    /// Format: 6!n (YYMMDD) - Date when balance is effective
123    /// Represents balance at sequence break point
124    #[component("6!n")]
125    pub value_date: NaiveDate,
126
127    /// Currency of the balance
128    ///
129    /// Format: 3!a - ISO 4217 currency code (USD, EUR, GBP, etc.)
130    /// Must match account currency for consistency
131    #[component("3!a")]
132    pub currency: String,
133
134    /// Intermediate opening balance amount
135    ///
136    /// Format: 15d - Decimal amount with comma separator
137    /// Represents balance carried forward from previous sequence
138    #[component("15d")]
139    pub amount: f64,
140}
141
142#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
143pub enum Field60 {
144    F(Field60F),
145    M(Field60M),
146}