use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableWithSplitEntriesModel method getInternalValueAt.
@Override
protected Object getInternalValueAt(final int row, final int col) {
final TransactionWrapper wrapper = data.get(row);
BigDecimal amount;
if (wrapper.entry == null) {
amount = wrapper.transaction.getAmount(account);
} else {
amount = wrapper.entry.getAmount(account);
}
int signum = amount.signum();
/* only show details if showSplitDetails is true and account
* does not directly contain the transaction */
boolean showDetail = wrapper.entry != null && showSplitDetails;
switch(col) {
case 0:
if (showDetail) {
return null;
}
return wrapper.transaction.getLocalDate();
case 1:
if (showDetail) {
return null;
}
return wrapper.transaction.getNumber();
case 2:
if (showDetail) {
return null;
}
return wrapper.transaction.getPayee();
case 3:
if (showDetail) {
return null;
}
return wrapper.transaction.getMemo(getAccount());
case 4:
if (wrapper.entry != null && showDetail) {
TransactionEntry _t = wrapper.entry;
if (_t.getCreditAccount() != account) {
return " - " + _t.getCreditAccount().getName();
}
return " - " + _t.getDebitAccount().getName();
} else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.DOUBLEENTRY) {
TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
if (_t.getCreditAccount() != account) {
return _t.getCreditAccount().getName();
}
return _t.getDebitAccount().getName();
} else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.SINGLENTRY) {
TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
return _t.getCreditAccount().getName();
} else if (wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY) {
Transaction _t = wrapper.transaction;
return "[ " + _t.size() + " " + split + " ]";
} else if (wrapper.transaction instanceof InvestmentTransaction) {
return ((InvestmentTransaction) wrapper.transaction).getInvestmentAccount().getName();
} else {
return ERROR;
}
case 5:
if (wrapper.entry == null) {
return wrapper.transaction.getReconciled(account).toString();
}
return wrapper.entry.getReconciled(account).toString();
case 6:
// Don't show amount if the split details are going to be shown, otherwise totals will be wrong
if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
return null;
}
if (signum >= 0) {
return amount;
}
return null;
case 7:
// Don't show amount if the split details are going to be shown, otherwise totals will be wrong
if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
return null;
}
if (signum < 0) {
return amount.abs();
}
return null;
case 8:
if (showDetail) {
return null;
}
return getBalanceAt(row);
default:
return ERROR;
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AccountExport method exportAccount.
public static void exportAccount(final Account account, final String[] columnNames, final LocalDate startDate, final LocalDate endDate, final File file) {
Objects.requireNonNull(account);
Objects.requireNonNull(startDate);
Objects.requireNonNull(endDate);
Objects.requireNonNull(file);
Objects.requireNonNull(columnNames);
final String extension = FileUtils.getFileExtension(file.getAbsolutePath());
try (final Workbook wb = extension.equals("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook()) {
final CreationHelper createHelper = wb.getCreationHelper();
// create a new sheet
final Sheet s = wb.createSheet(account.getName());
// create 2 fonts objects
final Font defaultFont = wb.createFont();
final Font headerFont = wb.createFont();
defaultFont.setFontHeightInPoints((short) 10);
defaultFont.setColor(IndexedColors.BLACK.getIndex());
headerFont.setFontHeightInPoints((short) 11);
headerFont.setColor(IndexedColors.BLACK.getIndex());
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
// create header cell styles
final CellStyle headerStyle = wb.createCellStyle();
// Set the other cell style and formatting
headerStyle.setBorderBottom(CellStyle.BORDER_THIN);
headerStyle.setBorderTop(CellStyle.BORDER_THIN);
headerStyle.setBorderLeft(CellStyle.BORDER_THIN);
headerStyle.setBorderRight(CellStyle.BORDER_THIN);
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
DataFormat df_header = wb.createDataFormat();
headerStyle.setDataFormat(df_header.getFormat("text"));
headerStyle.setFont(headerFont);
headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
final CellStyle dateStyle = wb.createCellStyle();
dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("mm/dd/yy"));
dateStyle.setFont(defaultFont);
final CellStyle timestampStyle = wb.createCellStyle();
timestampStyle.setDataFormat(createHelper.createDataFormat().getFormat("YYYY-MM-DD HH:MM:SS"));
timestampStyle.setFont(defaultFont);
final CellStyle textStyle = wb.createCellStyle();
textStyle.setFont(defaultFont);
final CellStyle amountStyle = wb.createCellStyle();
amountStyle.setFont(defaultFont);
amountStyle.setAlignment(CellStyle.ALIGN_RIGHT);
final DecimalFormat format = (DecimalFormat) CommodityFormat.getFullNumberFormat(account.getCurrencyNode());
final String pattern = format.toLocalizedPattern().replace("ยค", account.getCurrencyNode().getPrefix());
final DataFormat df = wb.createDataFormat();
amountStyle.setDataFormat(df.getFormat(pattern));
// Create headers
int row = 0;
Row r = s.createRow(row);
for (int i = 0; i < columnNames.length; i++) {
Cell c = r.createCell(i);
c.setCellValue(createHelper.createRichTextString(columnNames[i]));
c.setCellStyle(headerStyle);
}
// Dump the transactions
for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
r = s.createRow(++row);
int col = 0;
// date
Cell c = r.createCell(col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(DateUtils.asDate(transaction.getLocalDate()));
c.setCellStyle(dateStyle);
// timestamp
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(DateUtils.asDate(transaction.getTimestamp()));
c.setCellStyle(timestampStyle);
// number
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(transaction.getNumber());
c.setCellStyle(textStyle);
// payee
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(transaction.getPayee());
c.setCellStyle(textStyle);
// memo
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(transaction.getMemo());
c.setCellStyle(textStyle);
// account
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(getAccountColumnValue(transaction, account));
c.setCellStyle(textStyle);
// clr
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(transaction.getReconciled(account).toString());
c.setCellStyle(textStyle);
final BigDecimal amount = transaction.getAmount(account);
// increase
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_NUMERIC);
if (amount.signum() >= 0) {
c.setCellValue(amount.doubleValue());
}
c.setCellStyle(amountStyle);
// decrease
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_NUMERIC);
if (amount.signum() < 0) {
c.setCellValue(amount.abs().doubleValue());
}
c.setCellStyle(amountStyle);
// balance
c = r.createCell(++col);
c.setCellType(Cell.CELL_TYPE_NUMERIC);
c.setCellValue(account.getBalanceAt(transaction).doubleValue());
c.setCellStyle(amountStyle);
}
// autosize the column widths
final short columnCount = s.getRow(1).getLastCellNum();
// autosize all of the columns + 10 pixels
for (int i = 0; i <= columnCount; i++) {
s.autoSizeColumn(i);
s.setColumnWidth(i, s.getColumnWidth(i) + 10);
}
Logger.getLogger(AccountExport.class.getName()).log(Level.INFO, "{0} cell styles were used", wb.getNumCellStyles());
// Save
final String filename;
if (wb instanceof XSSFWorkbook) {
filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xlsx";
} else {
filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xls";
}
try (final OutputStream out = Files.newOutputStream(Paths.get(filename))) {
wb.write(out);
} catch (final Exception e) {
Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
} catch (final IOException e) {
Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class BayesImportClassifier method generateClassifier.
private static BayesClassifier<Account> generateClassifier(List<Transaction> transactions, final Account baseAccount) {
final BayesClassifier<Account> classifier = new BayesClassifier<>(baseAccount);
for (final Transaction t : transactions) {
final Set<Account> accountSet = t.getAccounts();
accountSet.remove(baseAccount);
for (final Account account : accountSet) {
if (!t.getPayee().isEmpty()) {
classifier.train(t.getPayee(), account);
}
if (!t.getMemo().isEmpty()) {
classifier.train(t.getMemo(), account);
}
}
}
return classifier;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class GenericImport method matchTransactions.
/**
* Sets the match state of a list of imported transactions
*
* @param list list of imported transactions
* @param baseAccount account to perform match against
*/
public static void matchTransactions(final List<? extends ImportTransaction> list, @NotNull final Account baseAccount) {
Objects.requireNonNull(baseAccount);
for (final ImportTransaction importTransaction : list) {
// amount must always match
for (final Transaction tran : baseAccount.getSortedTransactionList()) {
// amounts must be comparably the same, do not use an equality check
if (tran.getAmount(baseAccount).compareTo(importTransaction.getAmount()) == 0) {
// check for date match
final LocalDate startDate;
final LocalDate endDate;
// we have a user initiated date, use a smaller window
if ((importTransaction.getDateUser() != null)) {
startDate = importTransaction.getDateUser().minusDays(1);
endDate = importTransaction.getDateUser().plusDays(1);
} else {
// use the posted date with a larger window
startDate = importTransaction.getDatePosted().minusDays(3);
endDate = importTransaction.getDatePosted().plusDays(3);
}
if (DateUtils.after(tran.getLocalDate(), startDate) && DateUtils.before(tran.getLocalDate(), endDate)) {
importTransaction.setState(ImportState.EQUAL);
break;
}
// check for matching check number
final String checkNumber = importTransaction.getCheckNumber();
if (checkNumber != null && !checkNumber.isEmpty()) {
if (tran.getNumber().equals(checkNumber)) {
importTransaction.setState(ImportState.EQUAL);
break;
}
}
// check for matching fitid number
final String id = importTransaction.getFITID();
if (id != null && !id.isEmpty()) {
if (tran.getFitid() != null && tran.getFitid().equals(id)) {
importTransaction.setState(ImportState.EQUAL);
break;
}
}
}
}
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class QifImport method addTransactions.
private void addTransactions(final QifAccount qAcc, final Account acc) {
if (qAcc.getTransactions().isEmpty()) {
return;
}
List<QifTransaction> list = qAcc.getTransactions();
for (QifTransaction aList : list) {
Transaction tran;
/*if (acc.getAccountType().equals(AccountType.INVEST)) {
//tran = generateInvestmentTransaction(aList, acc);
tran = generateTransaction(aList, acc);
} else {
tran = generateTransaction(aList, acc);
}*/
tran = generateTransaction(aList, acc);
if (tran != null && isDuplicate(tran, acc)) {
// strip and prevent NPE
logger.fine("duplicate found");
duplicates.add(tran);
continue;
}
if (tran != null) {
if (partialImport) {
// importing a bank statement, flag as imported
tran.setFitid(FITID);
}
engine.addTransaction(tran);
} else {
logger.warning("Null Transaction!");
}
}
}
Aggregations