Function mt940::parse_mt940
source · [−]pub fn parse_mt940(statement: &str) -> Result<Vec<Message>, ParseError>
Expand description
Parse and validate a MT940 statement.
Result will be a Vec
of all contained Message
s.
Example
use mt940::parse_mt940;
let input = "\
:20:3996-11-11111111\r\n\
:25:DABADKKK/111111-11111111\r\n\
:28C:00001/001\r\n\
:60F:C090924EUR54484,04\r\n\
:61:0909250925DR583,92NMSC1110030403010139//1234\r\n\
:86:11100304030101391234\r\n\
Beneficiary name\r\n\
Something else\r\n\
:61:0910010930DR62,60NCHGcustomer id//bank id\r\n\
:86:Fees according to advice\r\n\
:62F:C090930EUR53126,94\r\n\
:64:C090930EUR53189,31\r\n\
\r\n";
let expected = vec![Message {
transaction_ref_no: "3996-11-11111111".to_string(),
ref_to_related_msg: None,
account_id: "DABADKKK/111111-11111111".to_string(),
statement_no: "00001".to_string(),
sequence_no: Some("001".to_string()),
opening_balance: Balance {
is_intermediate: false,
debit_credit_indicator: DebitOrCredit::Credit,
date: NaiveDate::from_ymd(2009, 09, 24),
iso_currency_code: "EUR".to_string(),
amount: Decimal::from_str("54484.04").unwrap(),
},
statement_lines: vec![
StatementLine {
value_date: NaiveDate::from_ymd(2009, 09, 25),
entry_date: Some(NaiveDate::from_ymd(2009, 09, 25)),
ext_debit_credit_indicator: ExtDebitOrCredit::Debit,
funds_code: Some("R".to_string()),
amount: Decimal::from_str("583.92").unwrap(),
transaction_type_ident_code: TransactionTypeIdentificationCode::MSC,
customer_ref: "1110030403010139".to_string(),
bank_ref: Some("1234".to_string()),
supplementary_details: None,
information_to_account_owner: Some(
"11100304030101391234\nBeneficiary name\nSomething else".to_string(),
),
},
StatementLine {
value_date: NaiveDate::from_ymd(2009, 10, 01),
entry_date: Some(NaiveDate::from_ymd(2009, 09, 30)),
ext_debit_credit_indicator: ExtDebitOrCredit::Debit,
funds_code: Some("R".to_string()),
amount: Decimal::from_str("62.60").unwrap(),
transaction_type_ident_code: TransactionTypeIdentificationCode::CHG,
customer_ref: "customer id".to_string(),
bank_ref: Some("bank id".to_string()),
supplementary_details: None,
information_to_account_owner: Some("Fees according to advice".to_string()),
},
],
closing_balance: Balance {
is_intermediate: false,
debit_credit_indicator: DebitOrCredit::Credit,
date: NaiveDate::from_ymd(2009, 09, 30),
iso_currency_code: "EUR".to_string(),
amount: Decimal::from_str("53126.94").unwrap(),
},
closing_available_balance: Some(AvailableBalance {
debit_credit_indicator: DebitOrCredit::Credit,
date: NaiveDate::from_ymd(2009, 09, 30),
iso_currency_code: "EUR".to_string(),
amount: Decimal::from_str("53189.31").unwrap(),
}),
forward_available_balance: None,
information_to_account_owner: None,
}];
let input_parsed = parse_mt940(input).unwrap();
assert_eq!(expected, input_parsed);