2AXMWXFHNL4UW2K4DBUGXA5FOS6N5F3EKWLLQGN7F3DC7BLF5TJAC
pub mod opt {
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<time::Date>, D::Error>
where
D: serde::Deserializer<'de>,
{
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = Option<time::Date>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a date in dd.mm.yy format")
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(None)
}
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
{
super::deserialize(deserializer).map(Some)
}
}
deserializer.deserialize_option(Visitor)
}
}
let fund_currency = record.fund_currency;
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_amount = Amount::new(record.payment_amount, record.payment_curreny);
let investment_amount_payment =
Amount::new(record.investment_amount, record.payment_curreny);
TransactionKind::Distribution => {
let distribution_amount =
Amount::new(record.distribution_total, record.payment_currency);
let balance_date = record.balance_date.unwrap();
let main_account = self.config.account_template.render(&context);
let balance_amount = Amount::new(record.balance_shares, record.isin);
directives.push(Directive::from(Balance::new(
balance_date,
main_account,
balance_amount,
)));
transaction.build_posting(
self.config.reference_account.render(&context),
|posting| {
if record.payment_currency.as_ref() == "EUR" {
posting.set_amount(distribution_amount);
} else {
let rate = record.exchange_rate_eur_payment.unwrap();
let distribution_amount_eur = {
let amount_eur =
(distribution_amount.amount / rate).tap_mut(|amount| {
amount.rescale(2);
});
Amount::new(amount_eur, Commodity::try_from("EUR").unwrap())
};
posting
.set_amount(distribution_amount_eur)
.set_price(Amount::new(rate, record.payment_currency));
}
},
);
transaction.build_posting(
self.config.distributions_template.render(&context),
|posting| {
posting.set_amount(-distribution_amount);
},
);
}
TransactionKind::LumpSumTaxAdvance => {
// No interesting information
return Ok(vec![]);
}
let fund_currency = record.fund_currency.unwrap();
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_currency = record.payment_currency;
let payment_amount = Amount::new(record.payment_amount, payment_currency);
let investment_amount_payment =
Amount::new(record.investment_amount, payment_currency);
let investment_amount_fund = record.exchange_rate_payment_fund.map(|rate| {
let mut amount = investment_amount_payment.amount * rate;
amount.rescale(2);
Amount::new(amount, fund_currency)
});
let fund_currency = record.fund_currency.unwrap();
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_currency = record.payment_currency;
let sale_amount_payment = Amount::new(record.fees, payment_currency);
let sale_amount_fund = record.exchange_rate_payment_fund.map(|rate| {
let mut amount = sale_amount_payment.amount * rate;
amount.rescale(2);
Amount::new(amount, fund_currency)
});
if let Some(sale_amount_fund) = sale_amount_fund {
transaction
.build_posting(
self.config
.currency_account
.render(&CurrencyTemplateContext {
currency: {
let currency: &str = &payment_currency;
<&Seg>::try_from(currency)
.expect("commodities are valid segments")
},
}),
|posting| {
posting.set_amount(-sale_amount_payment);
},
)
.build_posting(
self.config
.currency_account
.render(&CurrencyTemplateContext {
currency: {
let currency: &str = &fund_currency;
<&Seg>::try_from(currency)
.expect("commodities are valid segments")
},
}),
|posting| {
posting.set_amount(sale_amount_fund);
},
);
}
let fund_currency = record.fund_currency.unwrap();
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_currency = record.payment_currency;
let investment_amount_payment =
Amount::new(record.investment_amount, payment_currency);
let fund_currency = record.fund_currency.unwrap();
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_currency = record.payment_currency;
let investment_amount_payment =
Amount::new(record.investment_amount, payment_currency);
let fund_currency = record.fund_currency.unwrap();
let share_price = Amount::new(record.share_price, fund_currency);
let shares_amount = Amount::new(record.shares, record.isin);
let payment_currency = record.payment_currency;
let payment_amount = Amount::new(record.payment_amount, payment_currency);
let investment_amount_payment =
Amount::new(record.investment_amount, payment_currency);
let investment_amount_fund = record.exchange_rate_payment_fund.map(|rate| {
let mut amount = investment_amount_payment.amount * rate;
amount.rescale(2);
Amount::new(amount, fund_currency)
});
let price = {
let date = record.price_date;
Price::new(date, record.isin, share_price)
};
directives.push(Directive::from(transaction));
if let Some(date) = record.price_date {
let share_price = Amount::new(record.share_price, record.fund_currency.unwrap());
directives.push(Directive::from(Price::new(date, record.isin, share_price)));
}
exchange_rate: Option<Decimal>,
exchange_rate_payment_fund: Option<Decimal>,
#[serde(
rename = "Devisenkurs (EUR/ZW)",
with = "decimal_parsers::german::serde::opt::with_precision::<6>"
)]
exchange_rate_eur_payment: Option<Decimal>,