diff --git a/build.xml b/build.xml index 352bb81..729a982 100644 --- a/build.xml +++ b/build.xml @@ -77,8 +77,10 @@ - + + + diff --git a/externals/moneydance/extadmin.jar b/externals/moneydance/extadmin.jar index 97df34e..9fe6214 100644 Binary files a/externals/moneydance/extadmin.jar and b/externals/moneydance/extadmin.jar differ diff --git a/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderData.java b/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderData.java old mode 100644 new mode 100755 diff --git a/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderDialog.form b/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderDialog.form old mode 100644 new mode 100755 diff --git a/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderDialog.java b/src/com/moneydance/modules/features/mdcsvimporter/CustomReaderDialog.java old mode 100644 new mode 100755 diff --git a/src/com/moneydance/modules/features/mdcsvimporter/CustomTableCellRenderer.java b/src/com/moneydance/modules/features/mdcsvimporter/CustomTableCellRenderer.java index 1f5480e..d7072f2 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/CustomTableCellRenderer.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/CustomTableCellRenderer.java @@ -1,45 +1,45 @@ -package com.moneydance.modules.features.mdcsvimporter; - -import java.awt.Color; -import java.awt.Component; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.DefaultTableCellRenderer; - -/** - * - * @author stan - */ - - -public class CustomTableCellRenderer extends DefaultTableCellRenderer { - - int forRow = -1; - int forCol = -1; - - public void setForRowCol( int row, int col ) - { - forRow = row; - forCol = col; - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) - { - JLabel lbl = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); - - //Get the status for the current row. - PreviewImportTblModel tableModel = (PreviewImportTblModel) table.getModel(); - if ( (row == forRow || forRow < 0) && (col == forCol || forCol < 0) ) - { - lbl.setBackground( Color.RED ); - } - else - { - //lbl.setBackground( javax.swing.UIManager.getColor( "Table.dropCellBackground" ) ); - lbl.setBackground( Color.WHITE ); - } - //Return the JLabel which renders the cell. - return lbl; - } -} +package com.moneydance.modules.features.mdcsvimporter; + +import java.awt.Color; +import java.awt.Component; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +/** + * + * @author stan + */ + + +public class CustomTableCellRenderer extends DefaultTableCellRenderer { + + int forRow = -1; + int forCol = -1; + + public void setForRowCol( int row, int col ) + { + forRow = row; + forCol = col; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) + { + JLabel lbl = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); + + //Get the status for the current row. + PreviewImportTblModel tableModel = (PreviewImportTblModel) table.getModel(); + if ( (row == forRow || forRow < 0) && (col == forCol || forCol < 0) ) + { + lbl.setBackground( Color.RED ); + } + else + { + //lbl.setBackground( javax.swing.UIManager.getColor( "Table.dropCellBackground" ) ); + lbl.setBackground( Color.WHITE ); + } + //Return the JLabel which renders the cell. + return lbl; + } +} diff --git a/src/com/moneydance/modules/features/mdcsvimporter/DataField.java b/src/com/moneydance/modules/features/mdcsvimporter/DataField.java old mode 100644 new mode 100755 diff --git a/src/com/moneydance/modules/features/mdcsvimporter/ImportDialog.java b/src/com/moneydance/modules/features/mdcsvimporter/ImportDialog.java index eb4a225..3911a61 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/ImportDialog.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/ImportDialog.java @@ -14,8 +14,7 @@ */ package com.moneydance.modules.features.mdcsvimporter; -import com.moneydance.apps.md.model.Account; -import com.moneydance.apps.md.model.RootAccount; +import com.infinitekind.moneydance.model.*; import com.moneydance.apps.md.view.gui.MoneydanceGUI; import com.moneydance.apps.md.view.gui.OnlineManager; import static com.moneydance.modules.features.mdcsvimporter.TransactionReader.importDialog; @@ -33,8 +32,6 @@ import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import javax.swing.filechooser.FileFilter; import javax.swing.JOptionPane; import javax.swing.KeyStroke; @@ -130,7 +127,7 @@ public void changedUpdate( DocumentEvent e ) skipDuringInit = false; this.setModal( false ); this.addEscapeListener( this ); - TransactionReader.init( customReaderDialog, this, main.getRootAccount() ); + TransactionReader.init( customReaderDialog, this, main.getAccountBook() ); } public static void addEscapeListener(final JDialog win) { @@ -337,10 +334,10 @@ else if ( runArgsHM.size() > 0 ) private void fillAccountCombo( Main main ) { - RootAccount rootAccount = main.getRootAccount(); + AccountBook book = main.getAccountBook(); comboAccount.removeAllItems(); - fillAccountCombo_( rootAccount ); + fillAccountCombo_(book.getRootAccount()); if ( comboAccount.getItemCount() > 0 ) { @@ -867,7 +864,7 @@ private void btnProcessActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRS Account account = (Account) comboAccount.getSelectedItem(); System.err.println( "starting transReader.parse..." ); - transReader.parse( main, csvData, account, main.getRootAccount() ); + transReader.parse( main, csvData, account, main.getAccountBook() ); csvReader.close(); System.out.println( "finished transReader.parse" ); @@ -1045,7 +1042,7 @@ private void PreviewImportBtnActionPerformed(java.awt.event.ActionEvent evt) {// //System.err.println( "starting transReader.parse..." ); //transReader.parse( main, csvData, account, main.getRootAccount() ); - transReader.setRootAccount( main.getRootAccount() ); + transReader.setAccountBook(main.getAccountBook()); PreviewImportWin previewImportWin = new PreviewImportWin(); previewImportWin.myInit( this, transReader, csvData, csvReader ); @@ -1313,7 +1310,7 @@ protected void fileChanged() // moving TransactionReader.customReaderDialog = customReaderDialog; setLabel( "FindAReader", "Find Reader" ); - TransactionReader[] fileFormats = TransactionReader.getCompatibleReaders( GET_COMPATIBLE_READERS, selectedFile, this, main.getRootAccount() ); + TransactionReader[] fileFormats = TransactionReader.getCompatibleReaders( GET_COMPATIBLE_READERS, selectedFile, this, main.getAccountBook() ); comboFileFormat.removeAllItems(); for ( TransactionReader reader : fileFormats ) @@ -1422,7 +1419,7 @@ protected void fileChanged2() // moving TransactionReader.customReaderDialog = customReaderDialog; setLabel( "FindAReader", "Find Reader" ); - TransactionReader[] fileFormats = TransactionReader.getCompatibleReaders( GET_ALL_READERS, selectedFile, this, main.getRootAccount() ); + TransactionReader[] fileFormats = TransactionReader.getCompatibleReaders( GET_ALL_READERS, selectedFile, this, main.getAccountBook() ); comboFileFormat.removeAllItems(); for ( TransactionReader reader : fileFormats ) diff --git a/src/com/moneydance/modules/features/mdcsvimporter/Main.java b/src/com/moneydance/modules/features/mdcsvimporter/Main.java index 3314ffd..5d211b3 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/Main.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/Main.java @@ -14,9 +14,9 @@ */ package com.moneydance.modules.features.mdcsvimporter; +import com.infinitekind.moneydance.model.AccountBook; import com.moneydance.apps.md.controller.FeatureModule; import com.moneydance.apps.md.controller.FeatureModuleContext; -import com.moneydance.apps.md.model.RootAccount; import java.awt.Image; import java.io.IOException; import java.util.ArrayList; @@ -50,8 +50,7 @@ public class Main { try { - image = ImageIO.read( - Main.class.getResourceAsStream( "import.png" ) ); + image = ImageIO.read( Main.class.getResourceAsStream( "import.png" ) ); } catch ( IOException x ) { @@ -88,10 +87,10 @@ public void init() context.registerFeature( this, "import", image, "Import File" ); } - RootAccount getRootAccount() + AccountBook getAccountBook() { FeatureModuleContext context = getContext(); - return context.getRootAccount(); + return context.getCurrentAccountBook(); } JFrame getMoneydanceWindow() diff --git a/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportTblModel.java b/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportTblModel.java index b7cab56..a58420b 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportTblModel.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportTblModel.java @@ -1,53 +1,53 @@ -package com.moneydance.modules.features.mdcsvimporter; - -import java.util.ArrayList; -import javax.swing.table.AbstractTableModel; - -/** - * - * @author stan - */ - - -public class PreviewImportTblModel extends AbstractTableModel -{ - private ArrayListcolNames; - private String[][] data; - - public PreviewImportTblModel( ArrayList colNamesArg, String[][] dataArg ) - { - colNames = colNamesArg; - data = dataArg; - - System.err.println( "row count =" + data.length ); - System.err.println( "col count =" + data[0].length ); - } - - public int getColumnCount() { return data[0].length; } - public int getRowCount() { return data.length;} - public Object getValueAt(int row, int col) - { - //System.err.println( "getValueAt row =" + row + " col =" + col ); - try { - if ( data[row][col] == "" ) - { - //System.err.println( "NOT EXISTS getValueAt row =" + row + " col =" + col ); - } - } - catch( Exception ex ) - { - return ""; - } - return data[row][col]; - } - - public String getColumnName(int col) { - return colNames.get( col ); - } - - /* - public int getColumnCount() { return 10; } - public int getRowCount() { return 10;} - public Object getValueAt(int row, int col) { return new Integer(row*col); } - */ -} +package com.moneydance.modules.features.mdcsvimporter; + +import java.util.ArrayList; +import javax.swing.table.AbstractTableModel; + +/** + * + * @author stan + */ + + +public class PreviewImportTblModel extends AbstractTableModel +{ + private ArrayListcolNames; + private String[][] data; + + public PreviewImportTblModel( ArrayList colNamesArg, String[][] dataArg ) + { + colNames = colNamesArg; + data = dataArg; + + System.err.println( "row count =" + data.length ); + System.err.println( "col count =" + data[0].length ); + } + + public int getColumnCount() { return data[0].length; } + public int getRowCount() { return data.length;} + public Object getValueAt(int row, int col) + { + //System.err.println( "getValueAt row =" + row + " col =" + col ); + try { + if ( data[row][col] == "" ) + { + //System.err.println( "NOT EXISTS getValueAt row =" + row + " col =" + col ); + } + } + catch( Exception ex ) + { + return ""; + } + return data[row][col]; + } + + public String getColumnName(int col) { + return colNames.get( col ); + } + + /* + public int getColumnCount() { return 10; } + public int getRowCount() { return 10;} + public Object getValueAt(int row, int col) { return new Integer(row*col); } + */ +} diff --git a/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportWin.java b/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportWin.java index f71dd17..7b40ca4 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportWin.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/PreviewImportWin.java @@ -68,7 +68,7 @@ public void myInit( ImportDialog importDialog, TransactionReader transReaderArg, for ( ; fieldIndex < maxFieldIndex; fieldIndex ++ ) { String dataTypeExpecting = transReader.getCustomReaderData().getDataTypesList().get( fieldIndex ); - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= fieldIndex = " + fieldIndex ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= fieldIndex = " + fieldIndex ); if ( dataTypeExpecting.equalsIgnoreCase( DATA_TYPE_IGNORE_REST ) ) { diff --git a/src/com/moneydance/modules/features/mdcsvimporter/TransactionReader.java b/src/com/moneydance/modules/features/mdcsvimporter/TransactionReader.java index d7255dd..42af529 100644 --- a/src/com/moneydance/modules/features/mdcsvimporter/TransactionReader.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/TransactionReader.java @@ -14,23 +14,12 @@ */ package com.moneydance.modules.features.mdcsvimporter; -import com.moneydance.apps.md.model.TransactionSet; -import com.moneydance.apps.md.model.Account; -import com.moneydance.apps.md.model.RootAccount; -import com.moneydance.apps.md.model.CurrencyType; -import com.moneydance.apps.md.model.AbstractTxn; -import com.moneydance.apps.md.model.OnlineTxn; -import com.moneydance.apps.md.model.OnlineTxnList; -import com.moneydance.apps.md.model.ParentTxn; -import com.moneydance.apps.md.model.SplitTxn; - -import com.moneydance.apps.md.model.TxnSet; +import com.infinitekind.moneydance.model.*; import com.moneydance.apps.md.view.gui.MoneydanceGUI; import com.moneydance.apps.md.view.gui.OnlineManager; import com.moneydance.modules.features.mdcsvimporter.formats.CustomReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; @@ -53,7 +42,7 @@ public abstract class TransactionReader protected static ImportDialog importDialog = null; protected static CustomReaderDialog customReaderDialog = null; - protected static RootAccount rootAccount = null; + protected static AccountBook book = null; protected CSVData csvData; protected Account account; @@ -98,16 +87,16 @@ protected final void throwException( String message ) throw new IOException( message ); } - public static void init( CustomReaderDialog customReaderDialogArg, ImportDialog importDialogArg, RootAccount rootAccountArg ) + public static void init( CustomReaderDialog customReaderDialogArg, ImportDialog importDialogArg, AccountBook accountBookArg ) { customReaderDialog = customReaderDialogArg; importDialog = importDialogArg; - rootAccount = rootAccountArg; + book = accountBookArg; } - - protected final void setRootAccount( RootAccount rootAccount ) + + protected final void setAccountBook(AccountBook book) { - this.rootAccount = rootAccount; + this.book = book; } public final String calcFITxnIdAbstract( AbstractTxn atxn ) @@ -140,7 +129,7 @@ public final String calcFITxnIdAbstract( AbstractTxn atxn ) */ - String origtxn = atxn.getTag( "ol.orig-txn" ); + String origtxn = atxn.getParameter("ol.orig-txn"); //String origCheckNumber = origtxn.replaceAll( ".*\\\"chknum\\\" = \\\"(.*?)\\\"\\\n.*", "$1" ); //System.out.println( "\norigtxn ="+origtxn + "=" ); @@ -182,20 +171,20 @@ public final String calcFITxnIdAbstract( AbstractTxn atxn ) //long value = atxn.getParentTxn().getValue(); - if ( atxn.getTag( "ol.orig-payee" ) == null ) + if ( atxn.getParameter("ol.orig-payee") == null ) { desc = atxn.getDescription(); } else { - desc = atxn.getTag( "ol.orig-payee" ); + desc = atxn.getParameter("ol.orig-payee"); } // This new way compare using the ORIGINAL payee and memo fields so if the user changes them, it will still match. Stan String tmp = atxn.getDateInt() + ":" + amt + ":" + desc + ":" + (origCheckNumber == null ? "" : origCheckNumber.replaceAll( "^0*(.*)", "$1" ) ) // strip leading 0's - + ":" + (atxn.getTag( "ol.orig-memo" ) == null ? "" : atxn.getTag( "ol.orig-memo" )); + + ":" + (atxn.getParameter("ol.orig-memo") == null ? "" : atxn.getParameter("ol.orig-memo")); //System.err.println( "calc abstract FITxnld >" + tmp + "<" ); return tmp; @@ -241,14 +230,14 @@ private final void makeSetOfExistingTxns( TxnSet tset ) /* ************************************************************************************************ */ - public final void parse( Main main, CSVData csvDataArg, Account accountIn, RootAccount rootAccount ) + public final void parse( Main main, CSVData csvDataArg, Account accountIn, AccountBook book) throws IOException { System.err.println("\n--------- entered TransactionReader().parse() -------------"); this.csvData = csvDataArg; - this.rootAccount = rootAccount; - this.txnSet = rootAccount.getTransactionSet(); + this.book = book; + this.txnSet = book.getTransactionSet(); this.tsetMatcherKey = new HashSet(); this.tsetFITxnIdMatcherKey = new HashSet(); @@ -396,7 +385,7 @@ public final void parse( Main main, CSVData csvDataArg, Account accountIn, RootA } else { - this.account = rootAccount.getAccountByName( accountNameFromCSV ); + this.account = book.getRootAccount().getAccountByName( accountNameFromCSV ); System.out.println( "accountNameFromCSV: " + accountNameFromCSV ); if ( this.account == null ) { @@ -469,7 +458,7 @@ public final void parse( Main main, CSVData csvDataArg, Account accountIn, RootA else { System.err.println( "add new parentTxn/splitTxn" ); - ParentTxn pTxn = onlineToParentTxn( account, rootAccount, txn ); + ParentTxn pTxn = onlineToParentTxn( account, book, txn ); if ( pTxn != null ) { txnSet.addNewTxn( pTxn ); @@ -550,7 +539,7 @@ public final void parse( Main main, CSVData csvDataArg, Account accountIn, RootA * Note: Create a ParentTxn from a filled out OnlineTxn */ // @ Override - protected ParentTxn onlineToParentTxn( Account account, RootAccount rootAccount, OnlineTxn oTxn ) + protected ParentTxn onlineToParentTxn( Account account, AccountBook book, OnlineTxn oTxn ) throws IOException { Account category = null; @@ -565,13 +554,13 @@ protected ParentTxn onlineToParentTxn( Account account, RootAccount rootAccount, oTxn.setAmount( - oTxn.getAmount() ); oTxn.setTotalAmount( - oTxn.getTotalAmount() ); - ParentTxn pTxn = new ParentTxn( oTxn.getDateInitiatedInt(), oTxn.getDateInitiatedInt(), oTxn.getDateInitiatedInt() + ParentTxn pTxn = ParentTxn.makeParentTxn(book, oTxn.getDateInitiatedInt(), oTxn.getDateInitiatedInt(), oTxn.getDateInitiatedInt() , ckNum, account, oTxn.getName(), oTxn.getMemo() , -1, AbstractTxn.STATUS_UNRECONCILED ); try { System.err.println( "find category for oTxn.getSubAccountTo() =" + oTxn.getSubAccountTo() + "=" ); - category = getAccount( account, oTxn.getSubAccountTo(), com.moneydance.apps.md.model.AccountUtil.getDefaultCategoryForAcct( account ).getAccountName() //rr.getString("default_category"), - , oTxn.getAmount() <= 0 ? Account.ACCOUNT_TYPE_EXPENSE : Account.ACCOUNT_TYPE_INCOME ); + category = getAccount( account, oTxn.getSubAccountTo(), AccountUtil.getDefaultCategoryForAcct( account ).getAccountName() //rr.getString("default_category"), + , oTxn.getAmount() <= 0 ? Account.AccountType.EXPENSE : Account.AccountType.INCOME ); System.err.println( "found category =" + category + "=" ); } catch (Exception ex) { @@ -579,9 +568,9 @@ protected ParentTxn onlineToParentTxn( Account account, RootAccount rootAccount, return null; // skip this transaction - do not add } - SplitTxn sptxn = new SplitTxn( pTxn, oTxn.getAmount(), oTxn.getAmount(), 1.0 - , category //com.moneydance.apps.md.model.AccountUtil.getDefaultCategoryForAcct(account) /* category */ - , pTxn.getDescription(), -1, AbstractTxn.STATUS_UNRECONCILED ); + SplitTxn sptxn = SplitTxn.makeSplitTxn(pTxn, oTxn.getAmount(), oTxn.getAmount(), 1.0, + category, //com.moneydance.apps.md.model.AccountUtil.getDefaultCategoryForAcct(account) /* category */ + pTxn.getDescription(), -1, AbstractTxn.STATUS_UNRECONCILED ); sptxn.setIsNew( true ); pTxn.addSplit( sptxn ); @@ -608,7 +597,7 @@ public int getNumberOfCustomReaderFieldsUsed() return this.customReaderDialog.getNumberOfCustomReaderFieldsUsed(); } - public static TransactionReader[] getCompatibleReaders( boolean getAllReadersList, File selectedFile, ImportDialog importDialogArg, RootAccount rootAccount ) + public static TransactionReader[] getCompatibleReaders( boolean getAllReadersList, File selectedFile, ImportDialog importDialogArg, AccountBook book) { ArrayList formats = new ArrayList(); // moving importDialog = importDialogArg; @@ -636,7 +625,7 @@ public static TransactionReader[] getCompatibleReaders( boolean getAllReadersLis } CSVData csvData = new CSVData( csvReader ); - transactionReader.setRootAccount( rootAccount ); + transactionReader.setAccountBook(TransactionReader.book); if ( getAllReadersList ) { System.err.println( "=============== add all readers for >" + key + "< ===============" ); @@ -763,14 +752,14 @@ public void setUsingCategorynameFlag(boolean xx) { /** Find and return the ACCOUNT field in the appropriate format. */ private final Account getAccount( Account account, String categoryName, String defaultAccount, - int defaultAcctType ) + Account.AccountType defaultAcctType ) throws Exception { //String acctStr = getField(fieldValues, 1 /*ACCOUNT*/, null); if ( categoryName == null ) return addNewAccount( defaultAccount, account.getCurrencyType(), - rootAccount, "", defaultAcctType, true, -1 ); + book.getRootAccount(), "", defaultAcctType, true, -1 ); //acctStr = acctStr.trim(); - return addNewAccount( categoryName, account.getCurrencyType(), rootAccount, "", + return addNewAccount( categoryName, account.getCurrencyType(), book.getRootAccount(), "", defaultAcctType, true, -1 ); } @@ -781,12 +770,12 @@ private final Account getAccount( Account account, String categoryName, String d private Account addNewAccount( String accountName, CurrencyType currencyType, Account parentAccount, String description, - int accountType, boolean lenientMatch, + Account.AccountType accountType, boolean lenientMatch, int currAccountId) throws Exception { if(accountName.indexOf(':')==0 && - parentAccount.getAccountType()==Account.ACCOUNT_TYPE_ROOT) { + parentAccount.getAccountType()==Account.AccountType.ROOT) { accountName = accountName.substring(1); } @@ -813,14 +802,10 @@ private Account addNewAccount( String accountName, CurrencyType currencyType, } if(newAccount==null) { - newAccount = - Account.makeAccount(accountType, thisAcctName, currencyType, parentAccount); - if(newAccount instanceof com.moneydance.apps.md.model.BankAccount) { - ((com.moneydance.apps.md.model.BankAccount)newAccount).setBankName(description); - } else if(newAccount instanceof com.moneydance.apps.md.model.InvestmentAccount) { - (( com.moneydance.apps.md.model.InvestmentAccount)newAccount).setAccountDescription(description); - } - parentAccount.addSubAccount(newAccount); + newAccount = Legacy.makeAccount(book, accountType, thisAcctName, currencyType, parentAccount); + newAccount.setBankName(description); + newAccount.setAccountDescription(description); + newAccount.syncItem(); } if(restOfAcctName!=null) { @@ -831,19 +816,13 @@ private Account addNewAccount( String accountName, CurrencyType currencyType, if(newAccount.getAccountNum()==currAccountId) { // if the found account is the same as the container account // create another account with the same name and return it - if(accountType==Account.ACCOUNT_TYPE_BANK && - parentAccount==rootAccount) { - newAccount = Account.makeAccount(Account.ACCOUNT_TYPE_INCOME, - thisAcctName+"X", currencyType, - parentAccount); + if(accountType==Account.AccountType.BANK && parentAccount == book.getRootAccount()) { + newAccount = Legacy.makeAccount(book, Account.AccountType.INCOME, thisAcctName+"X", currencyType, parentAccount); } else { - newAccount = Account.makeAccount(accountType, thisAcctName+"X", - currencyType, parentAccount); - } - if(newAccount instanceof com.moneydance.apps.md.model.BankAccount) { - (( com.moneydance.apps.md.model.BankAccount)newAccount).setBankName(description); + newAccount = Legacy.makeAccount(book, accountType, thisAcctName+"X", currencyType, parentAccount); } - parentAccount.addSubAccount(newAccount); + newAccount.setBankName(description); + newAccount.syncItem(); } return newAccount; } diff --git a/src/com/moneydance/modules/features/mdcsvimporter/formats/CustomReader.java b/src/com/moneydance/modules/features/mdcsvimporter/formats/CustomReader.java old mode 100644 new mode 100755 index 49399f9..dc4a825 --- a/src/com/moneydance/modules/features/mdcsvimporter/formats/CustomReader.java +++ b/src/com/moneydance/modules/features/mdcsvimporter/formats/CustomReader.java @@ -14,7 +14,7 @@ */ package com.moneydance.modules.features.mdcsvimporter.formats; -import com.moneydance.apps.md.model.OnlineTxn; +import com.infinitekind.moneydance.model.OnlineTxn; import com.moneydance.modules.features.mdcsvimporter.CSVData; import com.moneydance.modules.features.mdcsvimporter.CustomReaderData; import com.moneydance.modules.features.mdcsvimporter.TransactionReader; @@ -198,12 +198,12 @@ public boolean canParse( CSVData data ) for ( ; retVal && fieldIndex < maxFieldIndex; fieldIndex ++ ) { String dataTypeExpecting = getCustomReaderData().getDataTypesList().get( fieldIndex ); - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= fieldIndex = " + fieldIndex ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= fieldIndex = " + fieldIndex ); data.nextField(); // if ( ! data.nextField() ) // { -// System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but have no data left." ); +// //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but have no data left." ); // retVal = false; // break; // } @@ -239,7 +239,7 @@ else if ( ( fieldString == null || fieldString.equals( DATA_TYPE_BLANK ) ) ) { if ( ! getCustomReaderData().getEmptyFlagsList().get( fieldIndex ).equals( "Can Be Blank" ) ) { - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but got no value =" + fieldString + "= and STOP ON ERROR" ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but got no value =" + fieldString + "= and STOP ON ERROR" ); retVal = false; break; } @@ -366,10 +366,10 @@ else if ( dataTypeExpecting.equalsIgnoreCase( DATA_TYPE_ACCOUNT_NAME ) ) System.err.println( "accountName >" + fieldString + "<" ); accountName = fieldString; - if ( rootAccount.getAccountByName( accountName ) == null ) + if ( book.getRootAccount().getAccountByName( accountName ) == null ) { - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= will not import it." ); -// System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= and STOP ON ERROR" ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= will not import it." ); +// //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= and STOP ON ERROR" ); // retVal = false; // break; } @@ -439,7 +439,7 @@ protected boolean parseNext() throws IOException for ( ; fieldIndex < maxFieldIndex; fieldIndex ++ ) { String dataTypeExpecting = getCustomReaderData().getDataTypesList().get( fieldIndex ); - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= EmptyFlagsList = " + getCustomReaderData().getEmptyFlagsList().get( fieldIndex ) + "=" ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= EmptyFlagsList = " + getCustomReaderData().getEmptyFlagsList().get( fieldIndex ) + "=" ); csvData.nextField(); String fieldString = csvData.getField(); @@ -475,7 +475,7 @@ else if ( ( fieldString == null || fieldString.equals( "" ) ) && ! getCustomReaderData().getEmptyFlagsList().get( fieldIndex ) .equals( "Can Be Blank" ) ) { - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but got no value =" + fieldString + "= and STOP ON ERROR" ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but got no value =" + fieldString + "= and STOP ON ERROR" ); throwException( "dataTypeExpecting =" + dataTypeExpecting + "= but got no value =" + fieldString + "= and STOP ON ERROR" ); } @@ -604,10 +604,10 @@ else if ( dataTypeExpecting.equalsIgnoreCase( DATA_TYPE_ACCOUNT_NAME ) ) System.err.println( "accountName >" + fieldString + "<" ); accountName = fieldString; - if ( rootAccount.getAccountByName( accountName ) == null ) + if ( book.getRootAccount().getAccountByName( accountName ) == null ) { - System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= will not import it." ); -// System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= and STOP ON ERROR" ); + //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= will not import it." ); +// //System.err.println( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= and STOP ON ERROR" ); // throwException( "dataTypeExpecting =" + dataTypeExpecting + "= but that account does not exist =" + fieldString + "= and STOP ON ERROR" ); return false; // skip this line } diff --git a/test/com/moneydance/modules/features/mdcsvimporter/CSVDataTest.java b/test/com/moneydance/modules/features/mdcsvimporter/CSVDataTest.java index cf2973b..095ff75 100644 --- a/test/com/moneydance/modules/features/mdcsvimporter/CSVDataTest.java +++ b/test/com/moneydance/modules/features/mdcsvimporter/CSVDataTest.java @@ -4,7 +4,7 @@ */ package com.moneydance.modules.features.mdcsvimporter; -import com.moneydance.apps.md.model.Account; +import com.infinitekind.moneydance.model.*; import java.io.FileReader; import java.io.IOException; import java.io.StringReader; @@ -64,10 +64,11 @@ public void simpleTest1() throws IOException { StringReader data = new StringReader( test1 ); - CSVReader csvReader = new CSVReader( data ); + CustomReaderData readerData = new CustomReaderData(); + CSVReader csvReader = new CSVReader( data, readerData); CSVData csvData = new CSVData( csvReader ); - csvData.parseIntoLines( ',' ); + csvData.parseIntoLines( readerData ); System.out.println( "finished transReader.parse" ); diff --git a/test/com/moneydance/modules/features/mdcsvimporter/CSVReaderTest.java b/test/com/moneydance/modules/features/mdcsvimporter/CSVReaderTest.java index ee875a1..fdbd7eb 100644 --- a/test/com/moneydance/modules/features/mdcsvimporter/CSVReaderTest.java +++ b/test/com/moneydance/modules/features/mdcsvimporter/CSVReaderTest.java @@ -61,7 +61,8 @@ public void simpleTest1() throws IOException { StringReader data = new StringReader( test1 ); - CSVReader cvsReader = new CSVReader( data ); + CustomReaderData parseParameters = new CustomReaderData(); + CSVReader cvsReader = new CSVReader( data, parseParameters ); doTest1( cvsReader ); } diff --git a/test/com/moneydance/modules/features/mdcsvimporter/DateGuesserTest.java b/test/com/moneydance/modules/features/mdcsvimporter/DateGuesserTest.java index 4461eb6..3f95866 100644 --- a/test/com/moneydance/modules/features/mdcsvimporter/DateGuesserTest.java +++ b/test/com/moneydance/modules/features/mdcsvimporter/DateGuesserTest.java @@ -66,7 +66,7 @@ public void testCheckDateString() { Reader file = new InputStreamReader( DateGuesserTest.class.getResourceAsStream( "dateGuesser.csv" ) ); - CSVReader reader = new CSVReader( file ); + CSVReader reader = new CSVReader( ); DateGuesser guesser = new DateGuesser(); while ( reader.nextLine() ) {