Search in sources :

Example 66 with Unit

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

the class FinTechGroupBankPDFExtractor method addTransferOutTransaction.

@SuppressWarnings("nls")
private void addTransferOutTransaction() {
    DocumentType type = new DocumentType("Depotausgang");
    this.addDocumentTyp(type);
    Block block = new Block("Depotausgang(.*)");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("date").match(// 
    "Fälligkeitstag(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})(.*)").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name").match(// 
    "Depotausgang *(?<name>.*) *\\((?<isin>[^/]*)\\)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section("shares", "notation").match(// 
    "^Stk\\.\\/Nominale(\\s*):(\\s+)(?<shares>[\\.\\d]+(,\\d*)?) *(?<notation>St\\.|\\w{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("amount", "currency").match("(.*)Geldgegenwert\\*\\*(.*)(\\s*):(\\s*)(?<amount>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(.*)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("fee", "currency").optional().match(".* Provision *(?<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(".* Eigene Spesen *(?<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(".* \\*Fremde Spesen *(?<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("tax", "currency").optional().match(// 
    "(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new BuySellEntryItem(t)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) 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) BigDecimal(java.math.BigDecimal) 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) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 67 with Unit

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

the class CSVPortfolioTransactionExtractor method createGrossValueIfNecessary.

private void createGrossValueIfNecessary(String[] rawValues, Map<String, Column> field2column, PortfolioTransaction transaction) throws ParseException {
    if (transaction.getSecurity().getCurrencyCode().equals(transaction.getCurrencyCode()))
        return;
    BigDecimal exchangeRate = getBigDecimal(Messages.CSVColumn_ExchangeRate, rawValues, field2column);
    if (exchangeRate != null && exchangeRate.compareTo(BigDecimal.ZERO) != 0) {
        Money grossValue = transaction.getGrossValue();
        Money forex = Money.of(transaction.getSecurity().getCurrencyCode(), Math.round(exchangeRate.multiply(BigDecimal.valueOf(grossValue.getAmount())).doubleValue()));
        exchangeRate = BigDecimal.ONE.divide(exchangeRate, 10, BigDecimal.ROUND_HALF_DOWN);
        transaction.addUnit(new Unit(Unit.Type.GROSS_VALUE, grossValue, forex, exchangeRate));
    }
}
Also used : Money(name.abuchen.portfolio.money.Money) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 68 with Unit

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

the class CSVPortfolioTransactionExtractor method createDelivery.

private Item createDelivery(String[] rawValues, Map<String, Column> field2column, Type type, Security security, Money amount, Long fees, Long taxes, LocalDateTime date, String note, Long shares, Unit grossAmount) throws ParseException {
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(type);
    t.setSecurity(security);
    t.setDateTime(date);
    t.setAmount(Math.abs(amount.getAmount()));
    t.setCurrencyCode(amount.getCurrencyCode());
    t.setShares(shares);
    t.setNote(note);
    if (grossAmount != null)
        t.addUnit(grossAmount);
    if (fees != null && fees.longValue() != 0)
        t.addUnit(new Unit(Unit.Type.FEE, Money.of(amount.getCurrencyCode(), Math.abs(fees))));
    if (taxes != null && taxes.longValue() != 0)
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(amount.getCurrencyCode(), Math.abs(taxes))));
    if (grossAmount == null)
        createGrossValueIfNecessary(rawValues, field2column, t);
    return new TransactionItem(t);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 69 with Unit

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

the class CSVPortfolioTransactionExtractor method createBuySell.

private Item createBuySell(String[] rawValues, Map<String, Column> field2column, Type type, Security security, Money amount, Long fees, Long taxes, LocalDateTime date, String note, Long shares, Unit grossAmount) throws ParseException {
    BuySellEntry entry = new BuySellEntry();
    entry.setType(type);
    entry.setSecurity(security);
    entry.setDate(date);
    entry.setAmount(Math.abs(amount.getAmount()));
    entry.setCurrencyCode(amount.getCurrencyCode());
    entry.setShares(shares);
    entry.setNote(note);
    if (grossAmount != null)
        entry.getPortfolioTransaction().addUnit(grossAmount);
    if (fees != null && fees.longValue() != 0)
        entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(amount.getCurrencyCode(), Math.abs(fees))));
    if (taxes != null && taxes.longValue() != 0)
        entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(amount.getCurrencyCode(), Math.abs(taxes))));
    if (grossAmount == null)
        createGrossValueIfNecessary(rawValues, field2column, entry.getPortfolioTransaction());
    return new BuySellEntryItem(entry);
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 70 with Unit

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

the class BaaderBankPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Wertpapierabrechnung: Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("Scalable Capital .*");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("isin", "wkn", "name").match("Nominale *ISIN: *(?<isin>[^ ]*) *WKN: *(?<wkn>[^ ]*) *Kurs *").match("STK [^ ]* (?<name>.*) EUR [\\d.,]+,\\d{2,}+").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").match("STK *(?<shares>[\\.\\d]+[,\\d]*) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", "currency").match("Zu Lasten Konto \\d+ Valuta: \\d+\\.\\d+\\.\\d{4} *(?<currency>\\w{3}) *(?<amount>[\\d.]+,\\d{2})").find("Handelsdatum Handelsuhrzeit").match("^(?<date>\\d+\\.\\d+\\.\\d{4}) \\d{2}:\\d{2}:\\d{2}:\\d{2}$").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).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) 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) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) 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