use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class OnvistaPDFExtractor method addCapitalReductionTransaction.
private void addCapitalReductionTransaction() {
DocumentType type = new DocumentType("Kapitalherabsetzung");
this.addDocumentTyp(type);
Block block = new Block("(Aus|Ein)buchung:(.*)");
type.addBlock(block);
Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
PortfolioTransaction entry = new PortfolioTransaction();
entry.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
return entry;
});
block.set(pdfTransaction);
pdfTransaction.section("date").optional().match("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (?<date>\\d+.\\d+.\\d{4}+)?(.*)").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
type.getCurrentContext().put("date", v.get("date"));
}).section("name", //
"isin").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(//
"transactiontype").match(//
"^(?<transactiontype>.*buchung:)(.*)").assign((t, v) -> {
String transactiontype = v.get("transactiontype");
if ("Einbuchung:".equalsIgnoreCase(transactiontype)) {
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
} else if ("Ausbuchung:".equalsIgnoreCase(transactiontype)) {
t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
} else {
// TODO: evtl. Warnung/Hinweis ausgeben?
}
}).section("notation", //
"shares").find("Nominal(.*)").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")));
}
t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
if (t.getDateTime() == null) {
t.setDateTime(asDate(type.getCurrentContext().get("date")));
}
}).wrap(TransactionItem::new);
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CheckCurrenciesAction method process.
@Override
public Status process(PortfolioTransaction transaction, Portfolio portfolio) {
Security security = transaction.getSecurity();
if (security == null)
return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckMissingSecurity, transaction.getType().toString()));
Status status = checkGrossValueAndUnitsAgainstSecurity(transaction);
if (status.getCode() != Status.Code.OK)
return status;
if (transaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND || transaction.getType() == PortfolioTransaction.Type.SELL) {
// tax + fees must be < than transaction amount
Money taxAndFees = //
transaction.getUnits().filter(//
u -> u.getType() == Unit.Type.TAX || u.getType() == Unit.Type.FEE).map(//
u -> u.getAmount()).collect(MoneyCollectors.sum(transaction.getCurrencyCode()));
if (!transaction.getMonetaryAmount().isGreaterOrEqualThan(taxAndFees))
return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckTaxAndFeesTooHigh, Values.Money.format(transaction.getMonetaryAmount()), Values.Money.format(taxAndFees)));
}
return Status.OK_STATUS;
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class AktienfreundeNetExporter method exportAllTransactions.
/**
* Export all transactions in 'aktienfreunde.net' Format
*/
public void exportAllTransactions(File file, Client client) throws IOException {
// collect transactions
List<? extends Transaction> transactions = Stream.concat(client.getAccounts().stream(), client.getPortfolios().stream()).flatMap(//
l -> l.getTransactions().stream()).sorted(//
new Transaction.ByDate()).collect(Collectors.toList());
// write to file
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(CSVExporter.STRATEGY);
writeHeader(printer);
// only buy/sell/dividend transactions
for (Transaction t : transactions) {
if (t instanceof AccountTransaction)
writeDividend(printer, (AccountTransaction) t);
else if (t instanceof PortfolioTransaction)
writeBuySell(printer, (PortfolioTransaction) t);
}
}
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class CSVExporter method exportPortfolioTransactions.
public void exportPortfolioTransactions(File file, Portfolio portfolio) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
printer.println(new String[] { //
Messages.CSVColumn_Date, //
Messages.CSVColumn_Type, //
Messages.CSVColumn_Value, //
Messages.CSVColumn_TransactionCurrency, //
Messages.CSVColumn_GrossAmount, //
Messages.CSVColumn_CurrencyGrossAmount, //
Messages.CSVColumn_ExchangeRate, //
Messages.CSVColumn_Fees, //
Messages.CSVColumn_Taxes, //
Messages.CSVColumn_Shares, //
Messages.CSVColumn_ISIN, //
Messages.CSVColumn_WKN, //
Messages.CSVColumn_TickerSymbol, //
Messages.CSVColumn_SecurityName, Messages.CSVColumn_Note });
for (PortfolioTransaction t : portfolio.getTransactions()) {
printer.print(t.getDateTime().toString());
printer.print(t.getType().toString());
printer.print(Values.Amount.format(t.getType().isLiquidation() ? -t.getAmount() : t.getAmount()));
printer.print(t.getCurrencyCode());
// gross amount
Optional<Unit> grossAmount = t.getUnit(Unit.Type.GROSS_VALUE);
if (grossAmount.isPresent()) {
Money forex = grossAmount.get().getForex();
printer.print(Values.Amount.format(forex.getAmount()));
printer.print(forex.getCurrencyCode());
printer.print(Values.ExchangeRate.format(grossAmount.get().getExchangeRate()));
} else {
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
}
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.FEE).getAmount()));
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.TAX).getAmount()));
printer.print(Values.Share.format(t.getShares()));
printSecurityInfo(printer, t);
printer.print(escapeNull(t.getNote()));
printer.println();
}
}
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class TransactionCurrencyCheck method execute.
@Override
public List<Issue> execute(Client client) {
Set<Object> transactions = new HashSet<Object>();
for (Account account : client.getAccounts()) {
account.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<AccountTransaction>(account, t)));
}
for (Portfolio portfolio : client.getPortfolios()) {
portfolio.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<PortfolioTransaction>(portfolio, t)));
}
List<Issue> issues = new ArrayList<Issue>();
for (Object t : transactions) {
if (t instanceof TransactionPair<?>) {
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = (TransactionPair<Transaction>) t;
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else if (t instanceof BuySellEntry) {
// attempt to fix it if both currencies are identical. If a fix
// involves currency conversion plus exchange rates, just offer
// to delete the transaction.
BuySellEntry entry = (BuySellEntry) t;
String accountCurrency = entry.getAccount().getCurrencyCode();
String securityCurrency = entry.getPortfolioTransaction().getSecurity().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getAccountTransaction()), entry.getAccountTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(accountCurrency, securityCurrency)));
} else if (t instanceof AccountTransferEntry) {
// same story as with purchases: only offer to fix if currencies
// match
AccountTransferEntry entry = (AccountTransferEntry) t;
String sourceCurrency = entry.getSourceAccount().getCurrencyCode();
String targetCurrency = entry.getTargetAccount().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(sourceCurrency, targetCurrency)));
} else if (t instanceof PortfolioTransferEntry) {
// transferring a security involves no currency change because
// the currency is defined the security itself
PortfolioTransferEntry entry = (PortfolioTransferEntry) t;
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else {
throw new IllegalArgumentException();
}
}
return issues;
}
Aggregations