Examples of GnucashWritableTransaction


Examples of biz.wolschon.fileformats.gnucash.GnucashWritableTransaction

    public GnucashWritableTransaction importTransaction(final Date date,
                                   final FixedPointNumber value,
                                   final String text) {

        try {
            GnucashWritableTransaction transaction = getMyAccount()
                    .getWritableGnucashFile().createWritableTransaction();
            transaction.setDescription(text.replace('\n', ' '));
            transaction.setDatePosted(date);
            transaction.setCurrencyNameSpace(getMyAccount()
                    .getCurrencyNameSpace());
            transaction.setCurrencyID(getMyAccount().getCurrencyID());

            // we always need the split on out account's side
            GnucashWritableTransactionSplit myAccountSplit = transaction
                    .createWritingSplit(getMyAccount());
            myAccountSplit.setValue(value);
            myAccountSplit.setQuantity(value);
            myAccountSplit.setUserDefinedAttribute(getPluginName() + ".orig_description",
                    text);
            myAccountSplit.setDescription(text.replace('\n', ' '));

            GnucashWritableAccount otherAccount = getDefaultAccount();
            String otherAccountText = "automatically added";

            boolean scriptMatched = false;
            try {
                // look if there is a script matching,
                int scriptnum = 0;
                LOG.log(Level.FINEST, "Testing scripts for a match");
                while (getMyProperties().containsKey(
                        getPluginName() + SETTINGS_PREFIX_IMPORTSCRIPT_REGEXP + scriptnum)) {
                    String scriptFilenameKey = getPluginName() + SETTINGS_PREFIX_IMPORTSCRIPT + scriptnum;
                    String scriptAccountKey = getPluginName() + SETTINGS_PREFIX_IMPORTSCRIPT_ACCOUNT + scriptnum;
                    LOG.log(Level.FINEST, "Testing script number " + scriptnum + " for a match");

                    String regexp = getMyProperties().getProperty(
                            getPluginName() + SETTINGS_PREFIX_IMPORTSCRIPT_REGEXP + scriptnum);
                    if (text.matches(regexp)) {
                        scriptMatched = true;

                        // does a full script exist or only an alternate
                        // accountid?
                        if (getMyProperties().containsKey(scriptFilenameKey)) {
                            importViaScript(value, text, myAccountSplit, scriptnum);
                        } else {

                            String alternateAccountID = getMyProperties()
                                    .getProperty(scriptAccountKey);
                            otherAccount = getMyAccount().getWritableGnucashFile()
                                    .getAccountByID(alternateAccountID);

                            if (otherAccount == null) {
                                LOG.log(Level.SEVERE, "Error  Account " + otherAccount
                                        + " given in user-" + getPluginName() + "-rule #"
                                        + scriptnum + " not found");
                                JOptionPane
                                        .showMessageDialog(
                                                null,
                                                "Error  Account "
                                                        + otherAccount
                                                        + " given in user-" + getPluginName() + "-rule #"
                                                        + scriptnum
                                                        + " not found",
                                                "User-supplied target-account not found.",
                                                JOptionPane.ERROR_MESSAGE);
                            } else {
                                LOG.log(Level.INFO, "importing transaction using alternate target-account: "
                                                + alternateAccountID
                                                + "="
                                                + otherAccount
                                                        .getQualifiedName());
                                otherAccountText = "";
                            }

                        }

                        break;
                    }

                    scriptnum++;
                }
            } catch (Exception e) {
                LOG.log(Level.SEVERE,
                                "Exception while importing a transaction via a script-handler.",
                                e);
            } catch (java.lang.NoClassDefFoundError e) {
                LOG.log(Level.SEVERE,
                                "NoClassDefFoundError while importing a transaction. Maybe you are using JDK1.5 instead of 1.6+?",
                                e);
            }

            if (!scriptMatched) {
                Integer newScriptnum = createMissingScript(date, value, text);
                if (newScriptnum != null) {
                    importViaScript(value, text, myAccountSplit, newScriptnum
                            .intValue());
                }
            }

            // default-case and make sure that all transactions are balanced
            if (!transaction.isBalanced()) {

                if (transaction.getSplitsCount() > 1) {
                    JOptionPane.showMessageDialog(null,
                            "Imported transaction is not balanced."
                                    + "\ntransaction (value is " + value
                                    + " but " + transaction.getBalance()
                                    + " is missing ) \n" + text,
                            "not balanced", JOptionPane.WARNING_MESSAGE);
                }

                GnucashWritableTransactionSplit otherSplit = transaction
                        .createWritingSplit(otherAccount);
                FixedPointNumber negatedValue = transaction.getNegatedBalance();
                otherSplit.setValue(negatedValue);
                otherSplit.setQuantity(negatedValue);
                otherSplit.setDescription(otherAccountText);
            }
            return transaction;
View Full Code Here

Examples of biz.wolschon.fileformats.gnucash.GnucashWritableTransaction

                saldoOKStr = "NAK ("
                        + getMyAccount().getBalance(timestamp).subtract(
                                saldo) + ")";
            }

            GnucashWritableTransaction transaction = getMyAccount()
                    .getWritableGnucashFile().createWritableTransaction();
            transaction.setDescription("Saldo: " + aValue + " "
                    + saldoOKStr + " (imported via script on " + DateFormat.getDateInstance().format(new Date()) + ")");
            transaction.setDatePosted(timestamp);
            transaction.setCurrencyNameSpace(getMyAccount()
                    .getCurrencyNameSpace());
            transaction.setCurrencyID(getMyAccount().getCurrencyID());

            // we always need the split on out account's side
            GnucashWritableTransactionSplit myAccountSplit = transaction
                    .createWritingSplit(getMyAccount());
            myAccountSplit.setValue(new FixedPointNumber()); // 0
            myAccountSplit.setQuantity(new FixedPointNumber()); // 0

            // dummy-split on the other side
            GnucashWritableAccount otherAccount = getDefaultAccount();
            GnucashWritableTransactionSplit otherAccountSplit = transaction
                    .createWritingSplit(otherAccount);
            otherAccountSplit.setValue(new FixedPointNumber()); // 0
            otherAccountSplit.setQuantity(new FixedPointNumber()); // 0
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Exception while creating Saldo-transaction.", e);
View Full Code Here

Examples of biz.wolschon.fileformats.gnucash.GnucashWritableTransaction

        bankAccount.setName("Dummy Bank-Account");
        bankAccount.setCurrencyNameSpace("ISO4217");
        bankAccount.setCurrencyID("EUR");

        // prepare dummy-transaction
        GnucashWritableTransaction transaction = dummyFile.createWritableTransaction();
        transaction.setDescription(getMyInputText().replace('\n', ' '));
        transaction.setDatePosted(getMyInputDate());
        transaction.setCurrencyNameSpace(bankAccount.getCurrencyNameSpace());
        transaction.setCurrencyID(bankAccount.getCurrencyID());

        // we always need the split on out account's side
        GnucashWritableTransactionSplit myAccountSplit = transaction.createWritingSplit(bankAccount);
        myAccountSplit.setValue(getMyInputValue());
        myAccountSplit.setQuantity(getMyInputValue());
        myAccountSplit.setUserDefinedAttribute("HBCI.orig_description", getMyInputText());
        myAccountSplit.setDescription(getMyInputText().replace('\n', ' '));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.