Search in sources :

Example 76 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class INGDiBaExtractor method addTaxSectionToBuySellEntry.

@SuppressWarnings("nls")
private void addTaxSectionToBuySellEntry(DocumentType type, Transaction<BuySellEntry> transaction) {
    // Kapitalerstragsteuer (Einzelkonto)
    // 
    transaction.section("tax", "currency").optional().match("Kapitalertragsteuer \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).section("tax1", "currency1", "tax2", "currency2").optional().match("KapSt anteilig 50,00 ?% \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("KapSt anteilig 50,00 ?% \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
    }).section("tax", "currency").optional().match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> {
        if (!Boolean.parseBoolean(type.getCurrentContext().get(IS_JOINT_ACCOUNT)))
            t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax1", "currency1", "tax2", "currency2").optional().match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
    }).section("tax", "currency").optional().match("Kirchensteuer \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> {
        if (!Boolean.parseBoolean(type.getCurrentContext().get(IS_JOINT_ACCOUNT)))
            t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax1", "currency1", "tax2", "currency2").optional().match("Kirchensteuer \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("Kirchensteuer \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
        t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
    });
}
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) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 77 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class OnvistaPDFExtractor method addSellTransaction.

private void addSellTransaction() {
    DocumentType type = new DocumentType("Wir haben für Sie verkauft");
    this.addDocumentTyp(type);
    Block block = new Block("Wir haben für Sie verkauft(.*)");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    });
    block.set(pdfTransaction);
    // 
    pdfTransaction.section("name", "isin").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", "shares").find("Nominal Kurs").match(// 
    "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?)(.*)").assign((t, v) -> {
        String notation = v.get("notation");
        if (notation != null && !notation.equalsIgnoreCase("STK")) {
            // Prozent-Notierung, Workaround..
            t.setShares((asShares(v.get("shares")) / 100));
        } else {
            t.setShares(asShares(v.get("shares")));
        }
    }).section("date", "time", "amount", // 
    "currency").match("Handelstag (?<date>\\d+.\\d+.\\d{4}+) (.*)").match("Handelszeit (?<time>\\d+:\\d+)(.*)").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Gunsten(\\s*)$").match("(\\d+.\\d+.\\d{4}+) (\\d{6,12}) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> {
        t.setDate(asDate(v.get("date"), v.get("time")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(BuySellEntryItem::new);
    addTaxesSectionsTransaction(pdfTransaction);
    addFeesSectionsTransaction(pdfTransaction);
}
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) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) 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)

Example 78 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class SBrokerPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("Kauf .*");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("isin", // 
    "name").find(// 
    "Gattungsbezeichnung ISIN").match("(?<name>.*) Inhaber-Anteile (?<isin>.*)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("date", "amount", // 
    "currency").find("Wert Konto-Nr. Betrag zu Ihren Lasten").match(// 
    "(?<date>\\d+.\\d+.\\d{4}) \\d{2}/\\d{4}/\\d{3} (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section(// 
    "shares").match(// 
    "^STK (?<shares>\\d+,\\d+?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("fee", "currency").optional().match(// 
    ".* Orderentgelt (?<currency>\\w{3}+) (?<fee>[\\d.]+,\\d+)-").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("fee", "currency").optional().match(// 
    ".* Börsengebühr (?<currency>\\w{3}+) (?<fee>[\\d.]+,\\d+)-").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).wrap(t -> new BuySellEntryItem(t)));
}
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) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 79 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class UnicreditPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("UniCredit");
    this.addDocumentTyp(type);
    Block block = new Block("W e r t p a p i e r - A b r e c h n u n g K a u f .*");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("name", "wkn", "isin").find("Nennbetrag Wertpapierbezeichnung Wertpapierkennnummer/ISIN").match("^(?<name>.*) (?<wkn>[^ ]*)$").match("^.* (?<isin>[A-Z]{2}[A-Z\\d]{9}\\d)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").match("^ST *(?<shares>[\\.\\d]+[,\\d]*)$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", "currency").match("^Belastung.* (?<currency>\\w{3}) (?<amount>[\\d.]+,\\d{2})$").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("date").match("^Valuta (?<date>\\d+\\.\\d+\\.\\d{4}) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fee", "currency").optional().match("^Brokerkommission.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("fee", "currency").optional().match("^Transaktionsentgelt.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("fee", "currency").optional().match("^Provision.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).wrap(t -> new BuySellEntryItem(t)));
}
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) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 80 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class CSVAccountTransactionExtractor method extract.

@Override
void extract(List<Item> items, String[] rawValues, Map<String, Column> field2column) throws ParseException {
    // check if we have a security
    Security security = getSecurity(rawValues, field2column, s -> s.setCurrencyCode(getCurrencyCode(Messages.CSVColumn_TransactionCurrency, rawValues, field2column)));
    // check for the transaction amount
    Money amount = getMoney(rawValues, field2column);
    // determine type (if not explicitly given by import)
    Type type = inferType(rawValues, field2column, security, amount);
    // extract remaining fields
    LocalDateTime date = getDate(Messages.CSVColumn_Date, rawValues, field2column);
    if (date == null)
        throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Date), 0);
    String note = getText(Messages.CSVColumn_Note, rawValues, field2column);
    Long shares = getShares(Messages.CSVColumn_Shares, rawValues, field2column);
    Long taxes = getAmount(Messages.CSVColumn_Taxes, rawValues, field2column);
    switch(type) {
        case TRANSFER_IN:
        case TRANSFER_OUT:
            AccountTransferEntry entry = new AccountTransferEntry();
            entry.setAmount(Math.abs(amount.getAmount()));
            entry.setCurrencyCode(amount.getCurrencyCode());
            entry.setDate(date);
            entry.setNote(note);
            items.add(new AccountTransferItem(entry, type == Type.TRANSFER_OUT));
            break;
        case BUY:
        case SELL:
            if (security == null)
                throw new ParseException(MessageFormat.format(Messages.CSVImportMissingSecurity, // $NON-NLS-1$
                new StringJoiner(", ").add(Messages.CSVColumn_ISIN).add(Messages.CSVColumn_TickerSymbol).add(Messages.CSVColumn_WKN).toString()), 0);
            if (shares == null)
                throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Shares), 0);
            BuySellEntry buySellEntry = new BuySellEntry();
            buySellEntry.setType(PortfolioTransaction.Type.valueOf(type.name()));
            buySellEntry.setAmount(Math.abs(amount.getAmount()));
            buySellEntry.setShares(Math.abs(shares));
            buySellEntry.setCurrencyCode(amount.getCurrencyCode());
            buySellEntry.setSecurity(security);
            buySellEntry.setDate(date);
            buySellEntry.setNote(note);
            items.add(new BuySellEntryItem(buySellEntry));
            break;
        case DIVIDENDS:
            if (security == null)
                throw new ParseException(MessageFormat.format(Messages.CSVImportMissingSecurity, // $NON-NLS-1$
                new StringJoiner(", ").add(Messages.CSVColumn_ISIN).add(Messages.CSVColumn_TickerSymbol).add(Messages.CSVColumn_WKN).toString()), 0);
        case DEPOSIT:
        case TAXES:
        case TAX_REFUND:
        case FEES:
        case FEES_REFUND:
        case INTEREST:
        case INTEREST_CHARGE:
        case REMOVAL:
            AccountTransaction t = new AccountTransaction();
            t.setType(type);
            t.setAmount(Math.abs(amount.getAmount()));
            t.setCurrencyCode(amount.getCurrencyCode());
            if (type == Type.DIVIDENDS || type == Type.TAX_REFUND)
                t.setSecurity(security);
            t.setDateTime(date);
            t.setNote(note);
            if (shares != null && type == Type.DIVIDENDS)
                t.setShares(Math.abs(shares));
            if (type == Type.DIVIDENDS && taxes != null && taxes.longValue() != 0)
                t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), Math.abs(taxes))));
            items.add(new TransactionItem(t));
            break;
        default:
            throw new IllegalArgumentException(type.toString());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Money(name.abuchen.portfolio.money.Money) Type(name.abuchen.portfolio.model.AccountTransaction.Type) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ParseException(java.text.ParseException) StringJoiner(java.util.StringJoiner)

Aggregations

BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)169 Client (name.abuchen.portfolio.model.Client)150 IOException (java.io.IOException)141 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)125 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)125 Unit (name.abuchen.portfolio.model.Transaction.Unit)122 Money (name.abuchen.portfolio.money.Money)119 Security (name.abuchen.portfolio.model.Security)111 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)107 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)105 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)105 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)104 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)104 Values (name.abuchen.portfolio.money.Values)83 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)79 LocalDateTime (java.time.LocalDateTime)78 List (java.util.List)78 Optional (java.util.Optional)78 PDFInputFile (name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)75