Search in sources :

Example 51 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class PortfolioBuilder method buysell.

private PortfolioBuilder buysell(Type type, Security security, String date, long shares, long amount, int fees) {
    if (portfolio.getReferenceAccount() == null) {
        account = new Account(UUID.randomUUID().toString());
        portfolio.setReferenceAccount(account);
    }
    BuySellEntry entry = new BuySellEntry(portfolio, portfolio.getReferenceAccount());
    entry.setType(type);
    entry.setDate(AccountBuilder.asDateTime(date));
    entry.setSecurity(security);
    entry.setShares(shares);
    entry.setCurrencyCode(CurrencyUnit.EUR);
    entry.setAmount(amount);
    entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, fees)));
    entry.insert();
    return this;
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit)

Example 52 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class SecuritiesChart method addDividendTooltip.

private void addDividendTooltip(Composite composite, AccountTransaction t) {
    Label label = new Label(composite, SWT.NONE);
    label.setText(MessageFormat.format(Messages.LabelToolTipTransactionSummary, t.getType().toString(), dateTimeFormatter.format(t.getDateTime().toLocalDate()), t.getMonetaryAmount().toString()));
    if (t.getShares() == 0L) {
        label = new Label(composite, SWT.NONE);
        // $NON-NLS-1$
        label.setText("\u2211 " + t.getGrossValue().toString());
    } else {
        Optional<Unit> grossValue = t.getUnit(Unit.Type.GROSS_VALUE);
        long gross = grossValue.isPresent() ? grossValue.get().getForex().getAmount() : t.getGrossValueAmount();
        label = new Label(composite, SWT.NONE);
        label.setText(MessageFormat.format(Messages.LabelToolTipDividendDetails, Values.Share.format(t.getShares()), Values.Quote.format(Math.round(gross * Values.Share.divider() * Values.Quote.factorToMoney() / t.getShares()))));
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 53 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class ComdirectPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Wertpapierkauf");
    this.addDocumentTyp(type);
    Block block = new Block("^(\\* )?Wertpapierkauf *.*");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section(// 
    "date").match(// 
    "Geschäftstag *: (?<date>\\d+.\\d+.\\d{4}+) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name", // 
    "wkn").find(// 
    "Wertpapier-Bezeichnung *WPKNR/ISIN *").match(// 
    "^(?<name>(\\S{1,} )*) *(?<wkn>\\S*) *$").match(// 
    "(\\S{1,} )* *(?<isin>\\S*) *$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").optional().match(// 
    "^St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("shares").optional().match(// 
    "^ Summe *St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").find(// 
    ".*Zu Ihren Lasten( vor Steuern)? *").match(// 
    ".* \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+).*").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("tax").optional().match(// 
    "^a *b *g *e *f *ü *h *r *t *e *S *t *e *u *e *r *n *(?<tax>.*)$").assign((t, v) -> {
        Unit unit = createTaxUnit(v.get("tax"));
        if (unit == null || unit.getAmount().isZero())
            return;
        t.getPortfolioTransaction().addUnit(unit);
        MutableMoney total = MutableMoney.of(t.getPortfolioTransaction().getCurrencyCode());
        total.add(t.getPortfolioTransaction().getMonetaryAmount());
        total.add(unit.getAmount());
        t.setMonetaryAmount(total.toMoney());
    }).wrap(t -> {
        if (t.getPortfolioTransaction().getShares() == 0)
            throw new IllegalArgumentException(Messages.PDFMsgMissingShares);
        return new BuySellEntryItem(t);
    });
    addFeesSection(pdfTransaction);
    block.set(pdfTransaction);
    addTaxRefunds(type, "^(\\* )?Wertpapierkauf *.*");
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 54 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class ComdirectPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction() {
    DocumentType dividende = new DocumentType("Abrechnung Dividendengutschrift");
    this.addDocumentTyp(dividende);
    DocumentType ertrag = new DocumentType("Abrechnung Ertragsgutschrift");
    this.addDocumentTyp(ertrag);
    Block block = new Block(".*G *u *t *s *c *h *r *i *f *t *f *ä *l *l *i *g *e *r *W *e *r *t *p *a *p *i *e *r *- *E *r *t *r *ä *g *e *");
    dividende.addBlock(block);
    ertrag.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DIVIDENDS);
        return t;
    }).section("wkn", "name", "isin", "shares").optional().match(// 
    "^\\s*(p\\s*e\\s*r) *\\+?[\\d .]+  (?<name>.*)      (?<wkn>.*)").match(// 
    "^\\s*(S\\s*T\\s*K) *(?<shares>\\+?[\\d .]+,\\+?[\\d ]+).*    .* {4}(?<isin>.*)$").assign((t, v) -> {
        v.put("isin", stripBlanks(v.get("isin")));
        v.put("wkn", stripBlanks(v.get("wkn")));
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(stripBlanks(v.get("shares"))));
    }).section("currency", "amount", // 
    "date").find(// 
    ".*Zu Ihren Gunsten vor Steuern *").match(// 
    "^.*(?<date>\\d{2}.\\d{2}.\\d{4}) *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *$").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
        t.setDateTime(asDate(v.get("date")));
    }).section("currency", // 
    "gross").optional().find("^Bruttobetrag: *(?<currency>\\w{3}+) *(?<gross>[\\d.]+,\\d+)").assign((t, v) -> {
        long gross = asAmount(v.get("gross"));
        long tax = gross - t.getAmount();
        Unit unit = new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), tax));
        if (unit.getAmount().getCurrencyCode().equals(t.getCurrencyCode()))
            t.addUnit(unit);
    }).wrap(TransactionItem::new));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 55 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class ComdirectPDFExtractor method addTaxTransaction.

@SuppressWarnings("nls")
private void addTaxTransaction() {
    // TODO 1: combine with dividend-transaction of other file
    // TODO 2: not matched by buy/sell with taxes...
    // just char sequence
    DocumentType type = new DocumentType("Steuerliche Behandlung: Ausländische Dividende");
    // type.setMustExclude("Wertpapierkauf");
    this.addDocumentTyp(type);
    Block block = new Block("^\\s*Steuerliche Behandlung:.*");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.TAXES);
        return t;
    }).section("wkn", "name", "isin", "shares").optional().match(// 
    "^(Stk.)\\W*(?<shares>\\d[\\d .,]*)(?<name>.*),\\W*(WKN / ISIN:)(?<wkn>.*)/(?<isin>.*)$").assign((t, v) -> {
        v.put("isin", stripBlanks(v.get("isin")));
        v.put("wkn", stripBlanks(v.get("wkn")));
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(stripBlanks(v.get("shares"))));
    }).section(// 
    "date").match(// 
    "^.*Die Gutschrift erfolgt mit Valuta\\s+(?<date>\\d{2}.\\d{2}.\\d{4}).*$").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
    }).section("tax", "currency").optional().match(// 
    "^\\s*(K\\s*a\\s*p\\s*i\\s*t\\s*a\\s*l\\s*e\\s*r\\s*t\\s*r\\s*a\\s*g\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + // 
    "(?<currency>[A-Z\\s]+)(?<tax>[\\d\\s,-]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", "currency").optional().match("^\\s*(K\\s*i\\s*r\\s*c\\s*h\\s*e\\s*n\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", "currency").optional().match("^\\s*(S\\s*o\\s*l\\s*i\\s*d\\s*a\\s*r\\s*i\\s*t\\s*ä\\s*t\\s*s\\s*z\\s*u\\s*s\\s*c\\s*h\\s*l\\s*a\\s*g)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", // abgeführte Steuern
    "currency").match("^\\s*(a\\s*b\\s*g\\s*e\\s*f\\s*ü\\s*h\\s*r\\s*t\\s*e\\s*S\\s*t\\s*e\\s*u\\s*er\\s*n)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("tax")));
    }).wrap(TransactionItem::new));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Aggregations

Unit (name.abuchen.portfolio.model.Transaction.Unit)75 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)58 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)51 Money (name.abuchen.portfolio.money.Money)51 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)50 Client (name.abuchen.portfolio.model.Client)50 IOException (java.io.IOException)44 Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)37 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)37 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)37 BigDecimal (java.math.BigDecimal)32 Security (name.abuchen.portfolio.model.Security)26 Matcher (java.util.regex.Matcher)24 Pattern (java.util.regex.Pattern)24 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)24 Test (org.junit.Test)24 Map (java.util.Map)23 Values (name.abuchen.portfolio.money.Values)18 ArrayList (java.util.ArrayList)13 LocalDateTime (java.time.LocalDateTime)12