swift_mt_message/fields/field62.rs
1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::SwiftField;
4
5/// **Field 62: Closing Balance**
6///
7/// ## Purpose
8/// Specifies the closing balance of an account in customer statement messages (MT 940)
9/// and other cash management contexts. This field represents the final balance position
10/// after processing all transactions within the statement period. Essential for account
11/// balance verification, reconciliation, and cash management reporting.
12///
13/// ## Format Options Overview
14/// - **Option F**: Final closing balance - balance at statement end
15/// - **Option M**: Intermediate closing balance - balance at sequence break
16///
17/// ## Business Context Applications
18/// - **Customer Statements**: Closing balance for MT 940 Customer Statement Message
19/// - **Cash Management**: Final balance position for period
20/// - **Account Reconciliation**: End position for balance verification
21/// - **Sequence Processing**: Balance handoff between 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/// - **Balance Continuity**: Must align with opening balance plus transactions
29///
30/// ## Balance Calculation Logic
31/// ### Closing Balance Formula
32/// ```logic
33/// Closing Balance = Opening Balance (Field 60) + Sum of Statement Lines (Field 61)
34/// ```
35///
36/// ### Balance Types
37/// - **Final Balance (F)**: Balance at end of complete statement period
38/// - **Intermediate Balance (M)**: Balance at sequence break within statement
39/// - **Verification**: Mathematical verification against transaction totals
40/// - **Continuity**: Becomes opening balance for next period
41///
42/// ## Statement Processing Integration
43/// - **MT 940 Component**: Essential element of customer statement messages
44/// - **Transaction Summary**: Reflects cumulative effect of all statement transactions
45/// - **Period Closure**: Defines end of statement period
46/// - **Reconciliation**: Enables customer balance reconciliation
47///
48/// ## Regional Considerations
49/// - **European Banking**: SEPA statement requirements and Euro processing
50/// - **US Banking**: Federal Reserve and commercial bank statement standards
51/// - **Asian Markets**: Local banking statement requirements
52/// - **Cross-Border**: Multi-currency account statement processing
53///
54/// ## Error Prevention Guidelines
55/// - **Balance Verification**: Confirm closing balance equals opening plus transactions
56/// - **Date Consistency**: Ensure value date aligns with statement period
57/// - **Currency Matching**: Verify currency matches account and transaction currency
58/// - **Precision Validation**: Confirm amount precision meets currency standards
59///
60/// ## Related Fields Integration
61/// - **Field 60**: Opening Balance (period starting point)
62/// - **Field 61**: Statement Line (individual transactions)
63/// - **Field 64**: Closing Available Balance (available funds)
64/// - **Field 65**: Forward Available Balance (future availability)
65///
66/// ## Compliance Framework
67/// - **Banking Regulations**: Compliance with local banking statement requirements
68/// - **Audit Documentation**: Proper closing balance documentation
69/// - **Customer Communication**: Clear final balance communication
70/// - **Reconciliation Standards**: Foundation for account reconciliation
71///
72/// ## Cash Management Applications
73/// - **Liquidity Management**: Final position for liquidity planning
74/// - **Cash Forecasting**: Input for cash flow forecasting
75/// - **Risk Management**: Position assessment for risk management
76/// - **Performance Reporting**: Balance reporting for performance analysis
77///
78/// ## See Also
79/// - Swift FIN User Handbook: Closing Balance Specifications
80/// - MT 940 Message Standards: Customer Statement Message
81/// - Cash Management Guidelines: Balance Processing Standards
82/// - Account Statement Requirements: Regional Banking Standards
83///
84/// **Field 62F: Final Closing Balance**
85///
86/// Final closing balance at the end of a complete statement period.
87/// Represents the definitive account position after all transactions.
88#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
89pub struct Field62F {
90 /// Debit or Credit mark
91 ///
92 /// Format: 1!a - 'D' (Debit) or 'C' (Credit)
93 /// Indicates whether the closing balance is a debit or credit position
94 #[component("1!a")]
95 pub debit_credit_mark: String,
96
97 /// Value date of the closing balance
98 ///
99 /// Format: 6!n (YYMMDD) - Date when balance is effective
100 /// Typically the last business day of the statement period
101 #[component("6!n")]
102 pub value_date: NaiveDate,
103
104 /// Currency of the balance
105 ///
106 /// Format: 3!a - ISO 4217 currency code (USD, EUR, GBP, etc.)
107 /// Must match account currency and opening balance currency
108 #[component("3!a")]
109 pub currency: String,
110
111 /// Final closing balance amount
112 ///
113 /// Format: 15d - Decimal amount with comma separator
114 /// Result of opening balance plus all statement line transactions
115 #[component("15d")]
116 pub amount: f64,
117}
118
119/// **Field 62M: Intermediate Closing Balance**
120///
121/// Closing balance at a sequence break within a statement period.
122/// Used to maintain balance continuity across statement sequences.
123#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
124pub struct Field62M {
125 /// Debit or Credit mark
126 ///
127 /// Format: 1!a - 'D' (Debit) or 'C' (Credit)
128 /// Indicates whether the intermediate closing balance is a debit or credit position
129 #[component("1!a")]
130 pub debit_credit_mark: String,
131
132 /// Value date of the intermediate closing balance
133 ///
134 /// Format: 6!n (YYMMDD) - Date when balance is effective
135 /// Represents balance at sequence break point
136 #[component("6!n")]
137 pub value_date: NaiveDate,
138
139 /// Currency of the balance
140 ///
141 /// Format: 3!a - ISO 4217 currency code (USD, EUR, GBP, etc.)
142 /// Must match account currency for consistency
143 #[component("3!a")]
144 pub currency: String,
145
146 /// Intermediate closing balance amount
147 ///
148 /// Format: 15d - Decimal amount with comma separator
149 /// Becomes opening balance for next sequence
150 #[component("15d")]
151 pub amount: f64,
152}
153
154#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
155pub enum Field62 {
156 F(Field62F),
157 M(Field62M),
158}