swift_mt_message/messages/
mt941.rs

1use crate::fields::*;
2use serde::{Deserialize, Serialize};
3use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
4
5/// MT941: Balance Report Message
6///
7/// ## Purpose
8/// Used to report account balance information with summary details for a specific period.
9/// This message provides balance reporting with optional transaction summaries and is typically
10/// used for balance monitoring and cash management without detailed transaction information.
11///
12/// ## Scope
13/// This message is:
14/// - Sent by account servicing institutions for balance reporting
15/// - Used for periodic balance reporting (daily, weekly, monthly)
16/// - Applied when detailed transaction information is not required
17/// - Essential for cash position monitoring and liquidity management
18/// - Part of streamlined cash management and treasury operations
19///
20/// ## Key Features
21/// - **Balance Focus**: Emphasis on balance information rather than transaction detail
22/// - **Summary Information**: Optional transaction summaries without individual entries
23/// - **Period Reporting**: Statement numbering and period identification
24/// - **Available Balance**: Forward available balance information for cash planning
25/// - **Simplified Structure**: Streamlined format for efficient balance reporting
26/// - **Cash Management**: Optimized for automated cash management systems
27///
28/// ## Common Use Cases
29/// - Daily balance reporting for cash management
30/// - Automated liquidity monitoring
31/// - Treasury position reporting
32/// - Balance verification and confirmation
33/// - Cash forecasting and planning support
34/// - Correspondent banking balance monitoring
35/// - Investment account balance reporting
36/// - Multi-currency position reporting
37///
38/// ## Field Structure
39/// - **20**: Transaction Reference (mandatory) - Unique report reference
40/// - **21**: Related Reference (optional) - Reference to related period or statement
41/// - **25**: Account Identification (mandatory) - Account being reported
42/// - **28**: Statement Number (mandatory) - Report numbering and sequence
43/// - **13D**: Date/Time Indication (optional) - Report timing information
44/// - **60F**: Opening Balance (mandatory) - Starting balance for reporting period
45/// - **90D**: Number/Sum of Debit Entries (optional) - Debit transaction summary
46/// - **90C**: Number/Sum of Credit Entries (optional) - Credit transaction summary
47/// - **62F**: Closing Balance (mandatory) - Ending balance for reporting period
48/// - **64**: Available Balance (optional) - Available balance information
49/// - **65**: Forward Available Balance (optional, repetitive) - Future balance projections
50/// - **86**: Information to Account Owner (optional) - Additional balance information
51///
52/// ## Network Validation Rules
53/// - **Currency Consistency**: All balance fields must use the same currency code
54/// - **Reference Format**: Transaction references must follow SWIFT formatting standards
55/// - **Required Fields**: All mandatory fields must be present and properly formatted
56/// - **Date Validation**: All dates must be valid and properly sequenced
57/// - **Amount Validation**: All amounts must be properly formatted with currency precision
58/// - **Summary Consistency**: Entry summaries must be consistent with balance calculations
59/// - **Account Validation**: Account identification must be valid and properly formatted
60///
61/// ## SRG2025 Status
62/// - **Structural Changes**: None - MT941 format remains unchanged in SRG2025
63/// - **Validation Updates**: Additional validation for balance accuracy and completeness
64/// - **Processing Improvements**: Improved support for automated balance reporting
65/// - **Compliance Notes**: Enhanced capabilities for real-time balance delivery
66///
67/// ## Integration Considerations
68/// - **Banking Systems**: Core component of balance reporting and cash management systems
69/// - **Treasury Systems**: Primary input for automated treasury and liquidity management
70/// - **API Integration**: Essential for modern digital banking and cash management platforms
71/// - **Regulatory Reporting**: Critical for compliance and audit trail requirements
72///
73/// ## Relationship to Other Messages
74/// - **Triggered by**: MT920 (Request Message) for on-demand balance reporting
75/// - **Complements**: MT940 (detailed statements) and MT942 (interim reports)
76/// - **Supports**: Cash management, treasury operations, and balance monitoring workflows
77/// - **Integrates with**: Customer communication and digital banking platforms
78
79#[serde_swift_fields]
80#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
81#[validation_rules(MT941_VALIDATION_RULES)]
82pub struct MT941 {
83    #[field("20")]
84    pub field_20: Field20,
85
86    #[field("21")]
87    pub field_21: Option<Field21NoOption>,
88
89    #[field("25")]
90    pub field_25: Field25AccountIdentification,
91
92    #[field("28")]
93    pub field_28: Field28,
94
95    #[field("13D")]
96    pub field_13d: Option<Field13D>,
97
98    #[field("60F")]
99    pub field_60f: Field60F,
100
101    #[field("90D")]
102    pub field_90d: Option<Field90D>,
103
104    #[field("90C")]
105    pub field_90c: Option<Field90C>,
106
107    #[field("62F")]
108    pub field_62f: Field62F,
109
110    #[field("64")]
111    pub field_64: Option<Field64>,
112
113    #[field("65")]
114    pub field_65: Option<Vec<Field65>>,
115
116    #[field("86")]
117    pub field_86: Option<Field86>,
118}
119
120/// Validation rules for MT941 - Balance Report Message
121const MT941_VALIDATION_RULES: &str = r#"{
122  "rules": [
123    {
124      "id": "C1",
125      "description": "The first two characters of the three-character currency code in fields 60F, 90D, 90C, 62F, 64, and 65 must be the same for all occurrences of these fields",
126      "condition": {
127        "and": [
128          {"exists": ["fields", "60F"]},
129          {"exists": ["fields", "62F"]},
130          {"==": [
131            {"substr": [{"var": "fields.60F.currency"}, 0, 2]},
132            {"substr": [{"var": "fields.62F.currency"}, 0, 2]}
133          ]},
134          {
135            "if": [
136              {"exists": ["fields", "90D"]},
137              {"==": [
138                {"substr": [{"var": "fields.60F.currency"}, 0, 2]},
139                {"substr": [{"var": "fields.90D.currency"}, 0, 2]}
140              ]},
141              true
142            ]
143          },
144          {
145            "if": [
146              {"exists": ["fields", "90C"]},
147              {"==": [
148                {"substr": [{"var": "fields.60F.currency"}, 0, 2]},
149                {"substr": [{"var": "fields.90C.currency"}, 0, 2]}
150              ]},
151              true
152            ]
153          },
154          {
155            "if": [
156              {"exists": ["fields", "64"]},
157              {"==": [
158                {"substr": [{"var": "fields.60F.currency"}, 0, 2]},
159                {"substr": [{"var": "fields.64.currency"}, 0, 2]}
160              ]},
161              true
162            ]
163          },
164          {
165            "if": [
166              {
167                "and": [
168                  {"exists": ["fields", "65"]},
169                  {">=": [{"length": {"var": "fields.65"}}, 1]}
170                ]
171              },
172              {
173                "all": [
174                  {"var": "fields.65"},
175                  {
176                    "==": [
177                      {"substr": [{"val": [[-3], "fields", "60F", "currency"]}, 0, 2]},
178                      {"substr": [{"var": "currency"}, 0, 2]}
179                    ]
180                  }
181                ]
182              },
183              true
184            ]
185          }
186        ]
187      }
188    }
189  ]
190}"#;