use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class PayeePieChart method getTransactions.
private List<TranTuple> getTransactions(final Account account, final List<TranTuple> transactions, final LocalDate startDate, final LocalDate endDate) {
for (final Transaction t : account.getTransactions(startDate, endDate)) {
TranTuple tuple = new TranTuple(account, t);
transactions.add(tuple);
}
for (final Account child : account.getChildren(Comparators.getAccountByCode())) {
getTransactions(child, transactions, startDate, endDate);
}
return transactions;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ImportQifAction method importQif.
private static void importQif() {
final ResourceBundle rb = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
final Logger logger = Logger.getLogger("qifimport");
if (debug) {
try {
Handler fh = new FileHandler("%h/jgnash%g.log");
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.FINEST);
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Could not install file handler", ioe);
}
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (engine.getRootAccount() == null) {
StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
return;
}
final JFileChooser chooser = new JFileChooser(pref.get(QIFDIR, null));
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Qif Files (*.qif)", "qif"));
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
pref.put(QIFDIR, chooser.getCurrentDirectory().getAbsolutePath());
boolean fullFile = QifUtils.isFullFile(chooser.getSelectedFile());
if (fullFile) {
// prompt for date format
final DateFormat dateFormat = getQIFDateFormat();
class ImportFile extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.ImportWait"));
QifImport imp = new QifImport();
try {
imp.doFullParse(chooser.getSelectedFile(), dateFormat);
} catch (NoAccountException e) {
logger.log(Level.SEVERE, "Mistook partial qif file as a full qif file", e);
}
imp.dumpStats();
imp.doFullImport();
if (imp.getDuplicateCount() > 0) {
String message = imp.getDuplicateCount() + " duplicate transactions were found";
logger.info(message);
}
return null;
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
}
}
new ImportFile().execute();
} else {
final QifImport imp = new QifImport();
if (!imp.doPartialParse(chooser.getSelectedFile())) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
imp.dumpStats();
if (imp.getParser().accountList.isEmpty()) {
StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
return;
}
PartialDialog dlg = new PartialDialog(imp.getParser());
DialogUtils.addBoundsListener(dlg);
dlg.setVisible(true);
if (dlg.isWizardValid()) {
imp.doPartialImport(dlg.getAccount());
if (imp.getDuplicateCount() > 0) {
if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new MultiLineLabel(TextResource.getString("DupeTransImport.txt")), rb.getString("Title.DuplicateTransactionsFound"), YesNoDialog.WARNING_MESSAGE)) {
Transaction[] t = imp.getDuplicates();
for (Transaction element : t) {
engine.addTransaction(element);
}
}
}
}
}
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class BuySharePanel method modifyTransaction.
@Override
public void modifyTransaction(final Transaction tran) {
if (!(tran instanceof InvestmentTransaction)) {
throw new IllegalArgumentException("bad tranType");
}
clearForm();
datePanel.setDate(tran.getLocalDate());
List<TransactionEntry> entries = tran.getTransactionEntries();
feePanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentFeeEntries());
entries.stream().filter(e -> e instanceof TransactionEntryBuyX).forEach(e -> {
AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityCombo.setSelectedNode(entry.getSecurityNode());
if (entry.getCreditAccount().equals(account)) {
accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
} else {
accountExchangePanel.setSelectedAccount(entry.getCreditAccount());
accountExchangePanel.setExchangedAmount(entry.getCreditAmount());
}
});
updateTotalField();
modTrans = tran;
setReconciledState(tran.getReconciled(getAccount()));
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class TransactionPanel method buildTransaction.
@Override
protected Transaction buildTransaction() {
Transaction transaction;
if (splits != null) {
// build a split transaction
transaction = new Transaction();
transaction.setDate(datePanel.getLocalDate());
transaction.setNumber(numberField.getText());
//transaction.setMemo(memoField.getText());
transaction.setMemo(RegisterFactory.getConcatenateMemos() ? Transaction.CONCATENATE : memoField.getText());
transaction.setPayee(payeeField.getText());
transaction.addTransactionEntries(splits);
} else {
// double entry transaction
final int signum = amountField.getDecimal().signum();
final Account selectedAccount;
if (modTrans != null && modTrans.areAccountsHidden()) {
selectedAccount = getOppositeSideAccount(modTrans);
} else {
selectedAccount = accountPanel.getSelectedAccount();
}
if (panelType == PanelType.DECREASE && signum >= 0 || panelType == PanelType.INCREASE && signum == -1) {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(selectedAccount, getAccount(), amountField.getDecimal().abs(), datePanel.getLocalDate(), memoField.getText(), payeeField.getText(), numberField.getText());
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(selectedAccount, getAccount(), accountPanel.getExchangedAmount().abs(), amountField.getDecimal().abs().negate(), datePanel.getLocalDate(), memoField.getText(), payeeField.getText(), numberField.getText());
}
} else {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(getAccount(), selectedAccount, amountField.getDecimal().abs(), datePanel.getLocalDate(), memoField.getText(), payeeField.getText(), numberField.getText());
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(getAccount(), selectedAccount, amountField.getDecimal().abs(), accountPanel.getExchangedAmount().abs().negate(), datePanel.getLocalDate(), memoField.getText(), payeeField.getText(), numberField.getText());
}
}
}
ReconcileManager.reconcileTransaction(getAccount(), transaction, getReconciledState());
return transaction;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AbstractInvTransactionPanel method enterAction.
/**
* Method that is called when the enter button is used
*/
@Override
public void enterAction() {
if (validateForm()) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (modTrans == null) {
final Transaction newTrans = buildTransaction();
// Need to set the reconciled state
ReconcileManager.reconcileTransaction(getAccount(), newTrans, getReconciledState());
engine.addTransaction(newTrans);
} else {
final Transaction newTrans = buildTransaction();
/* Need to preserve the reconciled state of the opposite side
* if both sides are not automatically reconciled
*/
ReconcileManager.reconcileTransaction(getAccount(), newTrans, getReconciledState());
if (engine.isTransactionValid(newTrans)) {
if (engine.removeTransaction(modTrans)) {
engine.addTransaction(newTrans);
}
}
}
clearForm();
focusFirstComponent();
}
}
Aggregations