Search in sources :

Example 71 with Transaction

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;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction)

Example 72 with Transaction

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) PartialDialog(jgnash.ui.wizards.imports.qif.PartialDialog) IOException(java.io.IOException) Logger(java.util.logging.Logger) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileHandler(java.util.logging.FileHandler) NoAccountException(jgnash.convert.imports.qif.NoAccountException) JFileChooser(javax.swing.JFileChooser) Transaction(jgnash.engine.Transaction) DateFormat(jgnash.convert.imports.DateFormat) QifImport(jgnash.convert.imports.qif.QifImport) SwingWorker(javax.swing.SwingWorker) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) MultiLineLabel(jgnash.ui.components.MultiLineLabel)

Example 73 with Transaction

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()));
}
Also used : FocusListener(java.awt.event.FocusListener) Transaction(jgnash.engine.Transaction) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX) ValidationFactory(jgnash.ui.util.ValidationFactory) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) BigDecimal(java.math.BigDecimal) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) FormLayout(com.jgoodies.forms.layout.FormLayout) FocusEvent(java.awt.event.FocusEvent) CellConstraints(com.jgoodies.forms.layout.CellConstraints) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AccountExchangePanel(jgnash.ui.register.AccountExchangePanel) JPanel(javax.swing.JPanel) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX)

Example 74 with Transaction

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;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 75 with 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();
    }
}
Also used : Transaction(jgnash.engine.Transaction) Engine(jgnash.engine.Engine)

Aggregations

Transaction (jgnash.engine.Transaction)81 InvestmentTransaction (jgnash.engine.InvestmentTransaction)39 Account (jgnash.engine.Account)27 BigDecimal (java.math.BigDecimal)24 Engine (jgnash.engine.Engine)22 TransactionEntry (jgnash.engine.TransactionEntry)18 NotNull (jgnash.util.NotNull)13 List (java.util.List)10 LocalDate (java.time.LocalDate)9 FXML (javafx.fxml.FXML)9 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)9 ArrayList (java.util.ArrayList)7 TransactionType (jgnash.engine.TransactionType)7 ResourceBundle (java.util.ResourceBundle)6 TransactionFactory (jgnash.engine.TransactionFactory)6 NumberFormat (java.text.NumberFormat)5 Objects (java.util.Objects)5 ChangeListener (javafx.beans.value.ChangeListener)5 EngineFactory (jgnash.engine.EngineFactory)5 Message (jgnash.engine.message.Message)5