swift_mt_message/fields/field19.rs
1//! # Field 19: Sum of Amounts
2//!
3//! ## Purpose
4//! Specifies the sum of all individual transaction amounts appearing in sequence transactions.
5//! This field is essential for reconciliation and validation when the total transaction amount
6//! differs from the settlement amount due to charging arrangements or fee allocations.
7//!
8//! ## Format Specification
9//! - **Swift Format**: `17d`
10//! - **Description**: Up to 17 digits including decimal places
11//! - **Decimal Separator**: Comma as decimal separator, included in maximum length
12//! - **Precision**: Follows currency-specific decimal precision rules
13//!
14//! ## Presence and Usage
15//! - **Status**: Optional in MT102 Settlement Details sequence
16//! - **Swift Error Codes**: C03, T40, T43 (amount validation), T51 (invalid amount format)
17//! - **Referenced in Rule**: C1 (MT102 validation logic)
18//! - **Context**: Multiple customer credit transfers with charge handling
19//!
20//! ## Business Applications
21//! ### Batch Payment Processing
22//! - **Multiple Payments**: Used in MT102 for multiple customer credit transfers
23//! - **Charge Handling**: Accommodates scenarios where charges affect individual vs. total amounts
24//! - **Settlement Logic**: Enables different settlement and transaction amounts
25//! - **Batch Processing**: Supports batch payment scenarios with varying charge allocations
26//!
27//! ### Reconciliation and Validation
28//! - **Settlement Variance**: Used when sum of amounts differs from settlement amount in field 32A
29//! - **Charge Allocation**: Applied when transactions contain charging option "OUR" in field 71A
30//! - **Transaction Summation**: Must equal sum of all field 32B amounts in each sequence
31//! - **Audit Trail**: Enables proper reconciliation between individual and total amounts
32//!
33//! ## Calculation Logic
34//! Field 19 must equal the sum of all Field 32B amounts in the sequence:
35//! - **Validation Rule**: Field 19 = Σ(Field 32B amounts)
36//! - **Settlement Difference**: If Field 19 ≠ Field 32A, difference typically represents charges or fees
37//! - **Charge Impact**: Accounts for "OUR" charge deductions from individual transactions
38//!
39//! ## Network Validation Rules
40//! - **Positive Amount**: Amount must be greater than zero
41//! - **Integer Validation**: Integer part must contain at least one digit
42//! - **Decimal Precision**: Number of digits after decimal comma must not exceed currency maximum
43//! - **Format Compliance**: Must follow decimal amount formatting standards
44//! - **Currency Alignment**: Precision must match currency specified in field 32A
45//!
46//! ## Amount Precision by Currency
47//! - **Most Currencies**: 2 decimal places (USD, EUR, GBP, etc.)
48//! - **Japanese Yen**: 0 decimal places (JPY)
49//! - **Bahraini Dinar**: 3 decimal places (BHD)
50//! - **Special Cases**: Some currencies have specific precision requirements
51//!
52//! ## Usage Scenarios
53//! ### Charge Management
54//! - **Charge Deduction**: When "OUR" charges are deducted from individual transactions
55//! - **Fee Allocation**: When fees are distributed across multiple transactions
56//! - **Settlement Coordination**: When settlement amount differs from transaction total
57//! - **Cost Distribution**: Managing how processing costs affect final amounts
58//!
59//! ### Batch Reconciliation
60//! - **Validation**: Ensuring sum of individual transactions matches expected total
61//! - **Error Detection**: Identifying discrepancies in batch payment processing
62//! - **Audit Support**: Providing clear reconciliation trail for compliance
63//! - **Quality Control**: Automated validation of batch payment integrity
64//!
65//! ## Regional Considerations
66//! - **European Payments**: EUR precision and formatting rules
67//! - **US Payments**: USD decimal handling and validation
68//! - **Asian Markets**: Local currency precision requirements
69//! - **Multi-Currency**: Handling different precision rules in same batch
70//!
71//! ## STP Compliance
72//! - **Automated Validation**: STP systems automatically validate sum calculations
73//! - **Precision Requirements**: Enhanced precision validation for automated processing
74//! - **Format Standardization**: Strict adherence to decimal formatting rules
75//! - **Error Handling**: Automated rejection for calculation mismatches
76//!
77//! ## Error Prevention Guidelines
78//! - **Precision Validation**: Ensure decimal places match currency requirements
79//! - **Sum Verification**: Verify sum equals individual transaction amounts
80//! - **Format Checking**: Confirm proper decimal formatting with comma separator
81//! - **Range Validation**: Ensure amount is within reasonable business limits
82//!
83//! ## Related Fields Integration
84//! - **Field 32A**: Value Date, Currency, Settlement Amount (may differ from Field 19)
85//! - **Field 32B**: Transaction Amount (individual amounts that sum to Field 19)
86//! - **Field 71A**: Details of Charges (affects relationship between 19 and 32A)
87//! - **Field 33B**: Instructed Amount (in multi-currency scenarios)
88//!
89//! ## Compliance and Audit
90//! - **Reconciliation Records**: Maintains audit trail for amount differences
91//! - **Regulatory Reporting**: Supports accurate reporting of transaction vs. settlement amounts
92//! - **Internal Controls**: Enables proper validation of batch payment processing
93//! - **Exception Handling**: Facilitates investigation of amount discrepancies
94//!
95//! ## See Also
96//! - Swift FIN User Handbook: Amount Field Specifications
97//! - MT102 Usage Rules: Settlement Details Sequence
98//! - Currency Code Standards: Decimal Precision Requirements
99//! - Batch Payment Guidelines: Amount Reconciliation Procedures
100
101use serde::{Deserialize, Serialize};
102use swift_mt_message_macros::SwiftField;
103
104/// **Field 19: Sum of Amounts**
105///
106/// Transaction sum variant of [Field 19 module](index.html). Specifies the sum of all individual
107/// transaction amounts in sequence transactions for reconciliation and validation.
108///
109/// **Components:**
110/// - Amount (17d, up to 17 digits with decimal comma)
111///
112/// For complete documentation, see the [Field 19 module](index.html).
113#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
114pub struct Field19 {
115 /// Sum of all transaction amounts in the sequence
116 ///
117 /// Format: 17d - Up to 17 digits with decimal comma
118 /// Must equal sum of all Field 32B amounts in sequence
119 /// Precision must match currency in Field 32A
120 #[component("17d")]
121 pub amount: f64,
122}