Author: jpepin Date: 2010-07-06 18:39:52 +0200 (Tue, 06 Jul 2010) New Revision: 2964 Url: http://chorem.org/repositories/revision/lima/2964 Log: Import / Export (suite) Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/FiscalPeriodComparator.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java trunk/pom.xml Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -161,6 +161,8 @@ Date loopDate = fiscalPeriod.getBeginDate(); while(loopDate.before(endDate)){ FinancialPeriod financialPeriod = new FinancialPeriodImpl(); + //important for fiscalperiod created from import, it can be locked, so financialperiods must be locked + financialPeriod.setLocked(fiscalPeriod.getLocked()); financialPeriod.setBeginDate(loopDate); loopDate = DateUtils.addMonths(loopDate, 1); loopDate = DateUtils.truncate(loopDate, Calendar.MONTH); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -101,11 +101,9 @@ exportEntryBookChartAsCSV(topiaContext); exportFinancialStatementChartAsCSV(topiaContext); exportFiscalPeriodAsCSV(topiaContext); - exportFinancialPeriodAsCSV(topiaContext); exportClosedPeriodicEntryBooksAsCSV(topiaContext); - exportFinancialTransactionsAsCSV(topiaContext); - exportEntriesAsCSV(topiaContext); - // Write cache in file + exportFinancialTransactionsAndEntriesAsCSV(topiaContext); + // Write cache in string csvWriter.flush(); csvWriter.close(); } @@ -120,7 +118,8 @@ } return out.getBuffer().toString(); } - + + /** * Remote methode call from UI. */ @@ -148,6 +147,7 @@ } return out.getBuffer().toString(); } + /** * Local methode, export financialstatements from database @@ -194,6 +194,7 @@ doCatch(topiaContext, eeeTE, log); } } + /** * Remote methode call from UI. @@ -249,6 +250,7 @@ doCatch(topiaContext, eeeTE, log); } } + /** * Remote methode call from UI. @@ -277,6 +279,7 @@ return out.getBuffer().toString(); } + /** * Local methode, export accounts from database * Structure : TYPE | AccountNumber | Label | ThirdParty | MasteAccount | GeneralLedger @@ -315,79 +318,68 @@ doCatch(topiaContext, eeeTE, log); } } + /** * Local methode, export financialtransactions from database - * Structue : TYPE | TransactionDate | AmountDebit | AmountCredit + * Structure : TYPE | TransactionDate | AmountDebit | AmountCredit * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code */ - public void exportFinancialTransactionsAsCSV(TopiaContext topiaContext) throws LimaException { - String[] nextLine = new String[7]; + public void exportFinancialTransactionsAndEntriesAsCSV(TopiaContext topiaContext) throws LimaException { + int numTransaction = 0; // Get all financialtransactions try { - FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); - List<FinancialTransaction> listFinancialTransaction = financialTransactionDAO.findAll(); + FinancialTransactionDAO financialTransactionDAO = + LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + List<FinancialTransaction> listFinancialTransaction = + financialTransactionDAO.findAll(); // For all financialTransaction for (FinancialTransaction financialTransaction : listFinancialTransaction) { + String[] nextLine = new String[8]; nextLine[0] = "FTRC"; - nextLine[1] = sdf.format(financialTransaction.getTransactionDate()); - nextLine[2] = new Double( - financialTransaction.getAmountDebit()).toString(); + nextLine[1] = String.valueOf(numTransaction); + nextLine[2] = + sdf.format(financialTransaction.getTransactionDate()); nextLine[3] = new Double( + financialTransaction.getAmountDebit()).toString(); + nextLine[4] = new Double( financialTransaction.getAmountCredit()).toString(); - nextLine[4] = sdf.format(financialTransaction.getFinancialPeriod(). + nextLine[5] = + sdf.format(financialTransaction.getFinancialPeriod(). getBeginDate()); - nextLine[5] = sdf.format(financialTransaction.getFinancialPeriod(). + nextLine[6] = + sdf.format(financialTransaction.getFinancialPeriod(). getEndDate()); - nextLine[6] = financialTransaction.getEntryBook().getCode(); + EntryBook entryBook = financialTransaction.getEntryBook(); + if (entryBook != null){ + nextLine[7] = entryBook.getCode(); + } // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); + + nextLine = new String[10]; + for (Entry entry : financialTransaction.getEntry()) { + nextLine[0] = "NTRY"; + nextLine[1] = String.valueOf(numTransaction); + nextLine[2] = entry.getDescription(); + nextLine[3] = new Double(entry.getAmount()).toString(); + nextLine[4] = new Boolean(entry.getDebit()).toString(); + nextLine[5] = entry.getLettering(); + nextLine[6] = entry.getDetail(); + nextLine[7] = entry.getVoucher(); + nextLine[8] = entry.getPosition(); + nextLine[9] = entry.getAccount().getAccountNumber(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + numTransaction++; } } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } } - - /** - * Local methode, export entries from database - * Structure : TYPE | Description | Amount | Debit | Lettering | Detail | - * Voucher | Position | FinancialTransaction Date | FinancialTransaction Code | - * FinancialTransaction AmountDebit | FinancialTransaction AmountCredit - */ - public void exportEntriesAsCSV(TopiaContext topiaContext) throws LimaException { - try { - String[] nextLine = new String[12]; - // Get all Entry - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - List<Entry> listEntry = entryDAO.findAll(); - // For all Entry - for (Entry entry : listEntry) { - nextLine[0] = "NTRY"; - nextLine[1] = entry.getDescription(); - nextLine[2] = new Double(entry.getAmount()).toString(); - nextLine[3] = new Boolean(entry.getDebit()).toString(); - nextLine[4] = entry.getLettering(); - nextLine[5] = entry.getVoucher(); - nextLine[6] = entry.getPosition(); - nextLine[7] = entry.getAccount().getAccountNumber(); - nextLine[8] = sdf.format(entry.getFinancialTransaction(). - getTransactionDate()); - nextLine[9] = entry.getFinancialTransaction(). - getEntryBook().getCode(); - nextLine[10] = new Double(entry.getFinancialTransaction() - .getAmountDebit()).toString(); - nextLine[11] = new Double(entry.getFinancialTransaction() - .getAmountCredit()).toString(); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - } /** * Local methode, export fiscalperiods from database @@ -416,40 +408,6 @@ } } - /** - * Local methode, export financialperiods from database - * Structure : TYPE | BeginDate | EndDate | Locked | FiscalPeriod beginDate | FiscalPeriod endDate - */ - public void exportFinancialPeriodAsCSV(TopiaContext topiaContext) throws LimaException { - try { - String[] nextLine = new String[6]; - // Get all fiscalperiod - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - List<FinancialPeriod> listFinancialPeriod = - financialPeriodDAO.findAll(); - - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); - - // For all Entry - for (FinancialPeriod financialPeriod : listFinancialPeriod) { - nextLine[0] = "FNCP"; - nextLine[1] = sdf.format(financialPeriod.getBeginDate()); - nextLine[2] = sdf.format(financialPeriod.getEndDate()); - nextLine[3] = new Boolean(financialPeriod.getLocked()).toString(); - FiscalPeriod fiscalPeriod = fiscalPeriodDAO. - findContainsFinancialPeriod(financialPeriod); - nextLine[4] = sdf.format(fiscalPeriod.getBeginDate()); - nextLine[5] = sdf.format(fiscalPeriod.getEndDate()); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - } /** * Local methode, export ClosedPeriodicEntryBooks from database @@ -468,9 +426,11 @@ nextLine[0] = "CPEB"; nextLine[1] = new Boolean( closedPeriodicEntryBook.getLocked()).toString(); - nextLine[2] = sdf.format(closedPeriodicEntryBook.getFinancialPeriod(). + nextLine[2] = + sdf.format(closedPeriodicEntryBook.getFinancialPeriod(). getBeginDate()); - nextLine[3] =sdf.format(closedPeriodicEntryBook.getFinancialPeriod(). + nextLine[3] = + sdf.format(closedPeriodicEntryBook.getFinancialPeriod(). getEndDate()); nextLine[4] = closedPeriodicEntryBook.getEntryBook().getCode(); // Ajoute la ligne au fichier Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -23,8 +23,6 @@ import java.util.Date; import java.util.List; import javax.ejb.Stateless; -import javax.management.Query; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; @@ -32,7 +30,6 @@ import org.chorem.lima.business.FinancialTransactionServiceLocal; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; @@ -47,7 +44,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; /** * Cette classe permet la création d'une transaction comptable dans l'application. @@ -416,9 +412,7 @@ entryOld.setAccount(entry.getAccount()); entryOld.setAmount(entryAmount); entryOld.setDebit(entryAmountBool); - entryOld.setDescription(entry.getDescription()); entryOld.setFinancialTransaction(entry.getFinancialTransaction()); - entryOld.setVoucher(entry.getVoucher()); entryOld.setPosition(entry.getPosition()); entryOld.setLettering(entry.getLettering()); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -24,9 +24,12 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.TreeMap; import javax.ejb.EJB; import javax.ejb.Stateless; @@ -34,30 +37,44 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.AccountImport; import org.chorem.lima.beans.AccountImportImpl; -import org.chorem.lima.beans.FinancialPeriodImport; -import org.chorem.lima.beans.FinancialPeriodImportImpl; +import org.chorem.lima.beans.ClosedPeriodicEntryBookImport; +import org.chorem.lima.beans.ClosedPeriodicEntryBookImportImpl; +import org.chorem.lima.beans.EntryImport; +import org.chorem.lima.beans.EntryImportImpl; import org.chorem.lima.beans.FinancialStatementImport; import org.chorem.lima.beans.FinancialStatementImportImpl; +import org.chorem.lima.beans.FinancialTransactionImport; +import org.chorem.lima.beans.FinancialTransactionImportImpl; import org.chorem.lima.business.AccountServiceLocal; import org.chorem.lima.business.EntryBookServiceLocal; +import org.chorem.lima.business.FinancialPeriodServiceLocal; import org.chorem.lima.business.FinancialStatementServiceLocal; import org.chorem.lima.business.FinancialTransactionServiceLocal; +import org.chorem.lima.business.FiscalPeriodServiceLocal; import org.chorem.lima.business.ImportService; import org.chorem.lima.business.ImportServiceLocal; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.utils.FiscalPeriodComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.ClosedPeriodicEntryBook; +import org.chorem.lima.entity.ClosedPeriodicEntryBookDAO; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.EntryBookImpl; +import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; -import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementDAO; import org.chorem.lima.entity.FinancialStatementImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionDAO; +import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.FiscalPeriodImpl; @@ -85,10 +102,18 @@ private TopiaContext rootContext; + //Services + @EJB AccountServiceLocal accountService; @EJB + FiscalPeriodServiceLocal fiscalPeriodService; + + @EJB + FinancialPeriodServiceLocal financialPeriodService; + + @EJB FinancialTransactionServiceLocal financialTransactionService; @EJB @@ -97,9 +122,27 @@ @EJB EntryBookServiceLocal entryBookService; + //Import datas lists + + Map<String, AccountImport> accounts; + + Map<String, FinancialStatementImport> financialStatements; + + List<FiscalPeriod> fiscalPeriods; + + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks; + + Map<Integer, FinancialTransactionImport> financialTransactions; + + Map<Integer, List<EntryImport>> entries; + + //Utils + protected CSVWriter csvWriter; protected SimpleDateFormat sdf; + + public ImportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -115,10 +158,6 @@ //################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ - - /* - * @see org.chorem.lima.business.ImportExportService#importAsEBPCSV(byte[]) - */ @Override public void importAsEbpCSV(byte[] data) throws LimaException { @@ -139,27 +178,26 @@ //################ IMPORT ################ - + /** + * Remote methode to call all entities import from UI + */ @Override public String importCSV(String datas) throws LimaException { String result = ""; - //Accounts - TreeMap<String, AccountImport> accounts = - new TreeMap<String, AccountImport>(); + accounts = new TreeMap<String, AccountImport>(); - //FinancialStatements - TreeMap<String, FinancialStatementImport> financialStatements = - new TreeMap<String, FinancialStatementImport>(); + financialStatements = new TreeMap<String, FinancialStatementImport>(); - //FiscalPeriods - List<FiscalPeriod> fiscalPeriods = new ArrayList<FiscalPeriod>(); + fiscalPeriods = new ArrayList<FiscalPeriod>(); + + closedPeriodicEntryBooks = new ArrayList<ClosedPeriodicEntryBookImport>(); - //FinancialPeriods - List<FinancialPeriodImport> financialPeriodImports = - new ArrayList<FinancialPeriodImport>(); + financialTransactions = new HashMap<Integer,FinancialTransactionImport>(); - + entries = new HashMap<Integer, List<EntryImport>>(); + + TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); @@ -171,42 +209,42 @@ while ((nextLine = csvReader.readNext()) != null) { String indice = nextLine[0]; if (indice.equals("ACCN")){ - accounts = importAccountsChartsCSV( - nextLine, accounts, topiaContext); + result += importAccountsChartsCSV(nextLine, topiaContext); } else if (indice.equals("ENBK")){ - result += importEntryBooksChartCSV( - nextLine, topiaContext); + result += importEntryBooksChartCSV(nextLine, topiaContext); } else if (indice.equals("FNST")){ - financialStatements = importFinancialsStatementChartCSV( - nextLine, financialStatements, topiaContext); + result += importFinancialsStatementChartCSV(nextLine, topiaContext); } else if (indice.equals("FSCP")){ - fiscalPeriods = importFiscalPeriodCSV(nextLine, fiscalPeriods, topiaContext); + result += importFiscalPeriodCSV(nextLine, topiaContext); } - else if (indice.equals("FNCP")){ - financialPeriodImports = importFinancialPeriodChartCSV(nextLine, financialPeriodImports, topiaContext); - } else if (indice.equals("CPEB")){ - //result+= + importClosedPeriodicEntryBookCSV(nextLine, topiaContext); } else if (indice.equals("FTRC")){ - //result+= + importFinancialTransactionsCSV(nextLine, topiaContext); } else if (indice.equals("NTRY")){ - //result+= + importEntriesCSV(nextLine, topiaContext); } } //create accounts - result+=createAccounts(accounts, topiaContext); + result += createAccounts(topiaContext); //create financialStatements - result+=createFinancialStatements(financialStatements, topiaContext); + result += createFinancialStatements(topiaContext); //create fiscalperiod + Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); + result += createFiscalPeriod(topiaContext); + //update closedperiodicentrybooks + result += updateClosedPeriodicEntryBooks(topiaContext); + //create financialtransaction and entries + result += createFinancialTransactionsAndEntries(topiaContext); - //create financialperiod - result+=createFinancialPeriod(financialPeriodImports, topiaContext); + commitTransaction(topiaContext); + } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); @@ -220,6 +258,10 @@ return result; } + + /** + * Remote methode to call entrybooks import from UI + */ @Override public String importEntryBooksChartAsCSV(String datas) throws LimaException{ String result = ""; @@ -234,7 +276,7 @@ while ((nextLine = csvReader.readNext()) != null) { String indice = nextLine[0]; if (indice.equals("ENBK")){ - result+=importEntryBooksChartCSV(nextLine, topiaContext); + result += importEntryBooksChartCSV(nextLine, topiaContext); } } } @@ -251,12 +293,15 @@ } + /** + * Remote methode to call financialStatements import from UI + */ @Override public String importFinancialStatementsChartAsCSV(String datas) throws LimaException { String result = ""; //FinancialStatements - TreeMap<String, FinancialStatementImport> financialStatements = + financialStatements = new TreeMap<String, FinancialStatementImport>(); TopiaContext topiaContext = null; @@ -269,13 +314,12 @@ while ((nextLine = csvReader.readNext()) != null) { String indice = nextLine[0]; if (indice.equals("FNST")){ - financialStatements = importFinancialsStatementChartCSV( - nextLine, financialStatements, topiaContext); + result += importFinancialsStatementChartCSV(nextLine, topiaContext); } } //create financialStatements - result+=createFinancialStatements(financialStatements, topiaContext); + result += createFinancialStatements(topiaContext); } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); @@ -290,12 +334,15 @@ } + /** + * Remote methode to call accounts import from UI + */ @Override public String importAccountsChartAsCSV(String datas) throws LimaException { String result = ""; //Accounts - TreeMap<String, AccountImport> accounts = + accounts = new TreeMap<String, AccountImport>(); TopiaContext topiaContext = null; @@ -309,13 +356,12 @@ while ((nextLine = csvReader.readNext()) != null) { String indice = nextLine[0]; if (indice.equals("ACCN")){ - accounts = importAccountsChartsCSV( - nextLine, accounts, topiaContext); - } + result += importAccountsChartsCSV(nextLine, topiaContext); + } } //create accounts - result+=createAccounts(accounts, topiaContext); + result += createAccounts(topiaContext); } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); @@ -329,7 +375,15 @@ return result; } - public TreeMap<String, AccountImport> importAccountsChartsCSV(String[] nextLine, TreeMap<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException{ + + //################ Import entities an put to lists ################ + + /** + * Import and create accounts + * Structure : TYPE | accountNumber | label | thirdparty | masterAccountNumber | generalLedgerNumber + */ + public String importAccountsChartsCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException{ + String result = ""; String accountNumber = nextLine[1]; String label = nextLine[2]; @@ -353,16 +407,15 @@ // put it in hashset accounts.put(accountNumber, accountImport); } - /*else { + else { result += "FAILED : The account " + accountNumber + " already exists !\n"; - }*/ + } } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - - return accounts; + return result; } @@ -370,8 +423,9 @@ * Import and create fiscal period * Structure : TYPE | BeginDate | EndDate | Locked */ - public List<FiscalPeriod> importFiscalPeriodCSV(String[] nextLine, List<FiscalPeriod> fiscalPeriods, TopiaContext topiaContext) throws LimaException { - try { + public String importFiscalPeriodCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + String result =""; + try { FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); @@ -386,6 +440,10 @@ if (fiscalPeriodDAO.findByNaturalId(beginDate, endDate) == null){ fiscalPeriods.add(fiscalPeriod); } + else { + result += "FAILED : The fiscalperiod " + + beginDate + "-" + endDate + " already exists !\n"; + } } catch (ParseException eeePE) { if(log.isDebugEnabled()){ @@ -395,10 +453,14 @@ catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - return fiscalPeriods; + return result; } + /** + * Import and create entrybooks + * Structure : TYPE | Code | Label | Type + */ public String importEntryBooksChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { String result =""; try { @@ -429,9 +491,37 @@ return result; } + + /** + * Import and create closedperiodicentrybook import + * Structure : TYPE | BeginDate | EndDate | Locked + */ + public void importClosedPeriodicEntryBookCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + String locked = nextLine[1]; + String beginDate = nextLine[2]; + String endDate = nextLine[3]; + String entryBookCode = nextLine[4]; + + if (new Boolean(locked)){ + ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport = new ClosedPeriodicEntryBookImportImpl(); + closedPeriodicEntryBookImport.setLocked(locked); + closedPeriodicEntryBookImport.setBeginDateFinancialPeriod(beginDate); + closedPeriodicEntryBookImport.setEndDateFinancialPeriod(endDate); + closedPeriodicEntryBookImport.setCodeEntryBook(entryBookCode); - public TreeMap<String, FinancialStatementImport> importFinancialsStatementChartCSV(String[] nextLine, TreeMap<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { - + closedPeriodicEntryBooks.add(closedPeriodicEntryBookImport); + } + } + + + /** + * Import and create financialstatement + * Structure : TYPE | label | header | accounts | debitAccount | creditAccount + * | provisitionDeprecationAccounts | subAmount | headerAmount | masterFinancialStatement + */ + public String importFinancialsStatementChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + String result = ""; + String label = nextLine[1]; String header = nextLine[2]; String accounts = nextLine[3]; @@ -467,66 +557,72 @@ // put it in hashset financialStatements.put(label, financialStatementImport); } - /*else { + else { result += "FAILED : The financialstatement " + label + " already exists !\n"; - }*/ + } } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - return financialStatements; + return result; } + /** - * Structure : TYPE | BeginDate | EndDate | Locked | FiscalPeriod beginDate | FiscalPeriod endDate + * Import and create financialtransactions + * Structue : TYPE | NumTransac | TransactionDate | AmountDebit | AmountCredit + * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code */ + public void importFinancialTransactionsCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + int num = new Integer(nextLine[1]); + FinancialTransactionImport financialTransactionImport = new FinancialTransactionImportImpl(); + financialTransactionImport.setDate(nextLine[2]); + financialTransactionImport.setAmountDebit(nextLine[3]); + financialTransactionImport.setAmountCredit(nextLine[4]); + financialTransactionImport.setBeginDateFinancialPeriod(nextLine[5]); + financialTransactionImport.setEndDateFinancialPeriod(nextLine[6]); + financialTransactionImport.setCodeEntryBook(nextLine[7]); + + financialTransactions.put(num, financialTransactionImport); + } - public List<FinancialPeriodImport> importFinancialPeriodChartCSV(String[] nextLine, List<FinancialPeriodImport> financialPeriodImports, TopiaContext topiaContext) throws LimaException { - - String beginDate = nextLine[1]; - String endDate = nextLine[2]; - String locked = nextLine[3]; - String beginDateFiscalPeriod = nextLine[4]; - String endDateFiscalPeriod = nextLine[5]; - - try { - - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + + /** + * Import and create entries + * Structure : TYPE | NumTransac | Description | Amount | Debit | Lettering | Detail | + * Voucher | Position | FinancialTransaction Date | FinancialTransaction EntryBookCode | + * FinancialTransaction AmountDebit | FinancialTransaction AmountCredit + */ + public void importEntriesCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + int num = new Integer(nextLine[1]); - //if exist, skip - if (financialPeriodDAO.findByNaturalId(sdf.parse(beginDate), sdf.parse(endDate)) == null){ - //create it - FinancialPeriodImport financialPeriodImport = - new FinancialPeriodImportImpl(); - financialPeriodImport.setBeginDate(beginDate); - financialPeriodImport.setEndDate(endDate); - financialPeriodImport.setBeginDateFiscalPeriod(beginDateFiscalPeriod); - financialPeriodImport.setEndDateFiscalPeriod(endDateFiscalPeriod); - financialPeriodImport.setLocked(locked); - - // put it in list - financialPeriodImports.add(financialPeriodImport); + EntryImport entryImport = new EntryImportImpl(); + entryImport.setDescription(nextLine[2]); + entryImport.setAmount(nextLine[3]); + entryImport.setDebit(nextLine[4]); + entryImport.setLettering(nextLine[5]); + entryImport.setDetail(nextLine[6]); + entryImport.setVoucher(nextLine[7]); + entryImport.setPosition(nextLine[8]); + entryImport.setAccount(nextLine[0]); + + if (entries.containsKey(num)){ + List<EntryImport> entryImports = entries.get(num); + entryImports.add(entryImport); } - } - catch (ParseException eeePE) { - if(log.isDebugEnabled()){ - log.debug("Can't parse date", eeePE); - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - - return financialPeriodImports; + else { + List<EntryImport> entryImports = new ArrayList<EntryImport>(); + entryImports.add(entryImport); + entries.put(num, entryImports); + } } //################ CREATE ENTITY IN DB FOR IMPORT ################ - public String createFinancialStatements(TreeMap<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { + public String createFinancialStatements(TopiaContext topiaContext) throws LimaException { String result = ""; try { @@ -588,49 +684,23 @@ return result; } - public String createFinancialPeriod(List<FinancialPeriodImport> financialPeriodImports, TopiaContext topiaContext) throws LimaException{ + public String createFiscalPeriod(TopiaContext topiaContext){ String result = ""; - try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - - for (FinancialPeriodImport financialPeriodImport : financialPeriodImports) { - //create financialPeriod - FinancialPeriod financialPeriod = new FinancialPeriodImpl(); - Date beginDate = sdf.parse(financialPeriodImport.getBeginDate()); - Date endDate = sdf.parse(financialPeriodImport.getEndDate()); - financialPeriod.setBeginDate(beginDate); - financialPeriod.setEndDate(endDate); - financialPeriod.setLocked(new Boolean(financialPeriodImport.getLocked())); - financialPeriodDAO.create(financialPeriod); - - //add to fiscalperiod - Date beginDateFiscalPeriod = - sdf.parse(financialPeriodImport.getBeginDateFiscalPeriod()); - Date endDateFiscalPeriod = - sdf.parse(financialPeriodImport.getEndDateFiscalPeriod()); - FiscalPeriod fiscalPeriod = - fiscalPeriodDAO.findByNaturalId(beginDateFiscalPeriod, endDateFiscalPeriod); - fiscalPeriod.addFinancialPeriod(financialPeriod); - - result += "SUCCESS : The financialPeriod " + - financialPeriodImport.getBeginDate()+"-"+financialPeriodImport.getEndDate() + " is created ! \n"; + for (FiscalPeriod fiscalPeriod : fiscalPeriods) { + //create fiscalPeriod + try { + fiscalPeriodService.createFiscalPeriod(fiscalPeriod); + result += "SUCCESS : The fiscalPeriod " + + fiscalPeriod.getBeginDate()+"-"+fiscalPeriod.getEndDate() + " is created ! \n"; + } + catch (LimaException eee){ + result += "FAILED : "+eee+" \n"; + } } - } - catch (ParseException eeePE) { - if(log.isDebugEnabled()){ - log.debug("Can't parse date", eeePE); - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } return result; } - - public String createAccounts(TreeMap<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException { + + public String createAccounts(TopiaContext topiaContext) throws LimaException { String result = ""; try { @@ -680,7 +750,101 @@ return result; } - + public String updateClosedPeriodicEntryBooks (TopiaContext topiaContext) throws LimaException { + String result=""; + + try { + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + for (ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport : closedPeriodicEntryBooks) { + //update closedPeriodicEntryBook + Date beginDateFinancialPeriod = + sdf.parse(closedPeriodicEntryBookImport.getBeginDateFinancialPeriod()); + Date endDateFinancialPeriod = + sdf.parse(closedPeriodicEntryBookImport.getEndDateFinancialPeriod()); + FinancialPeriod financialPeriod = + financialPeriodDAO.findByNaturalId(beginDateFinancialPeriod, endDateFinancialPeriod); + String codeEntryBook = closedPeriodicEntryBookImport.getCodeEntryBook(); + EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); + ClosedPeriodicEntryBook closedPeriodicEntryBook = + closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod(entryBook, financialPeriod); + try { + financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); + result += "SUCCESS : The blockClosedPeriodicEntryBook " + + beginDateFinancialPeriod + "-" + endDateFinancialPeriod + ", " + + codeEntryBook + " is updated ! \n"; + } + catch (LimaException eee){ + result += "FAILED : "+eee+" \n"; + } + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (ParseException eeePE) { + if(log.isDebugEnabled()){ + log.debug("Can't parse date", eeePE); + } + } + return result; + } + + public String createFinancialTransactionsAndEntries (TopiaContext topiaContext) throws LimaException { + String result = ""; + try { + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + for (int num : financialTransactions.keySet()) { + FinancialTransactionImport financialTransactionImport = financialTransactions.get(num); + FinancialTransaction financialTransaction = new FinancialTransactionImpl(); + Date dateFinancialTransaction = sdf.parse(financialTransactionImport.getDate()); + financialTransaction.setTransactionDate(dateFinancialTransaction); + + EntryBook entryBook = entryBookDAO.findByCode(financialTransactionImport.getCodeEntryBook()); + financialTransaction.setEntryBook(entryBook); + + FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(dateFinancialTransaction); + + financialTransactionDAO.create(financialTransaction); + financialPeriod.addFinancialTransaction(financialTransaction); + + List<EntryImport> entryImports = entries.get(num); + for (EntryImport entryImport : entryImports) { + Entry entry = new EntryImpl(); + Account account = accountDAO.findByAccountNumber(entryImport.getAccount()); + entry.setAccount(account); + entry.setDescription(entryImport.getDescription()); + entry.setAmount(new Double(entryImport.getAmount())); + entry.setDebit(new Boolean(entryImport.getDebit())); + entry.setLettering(entryImport.getLettering()); + entry.setDetail(entryImport.getDetail()); + entry.setVoucher(entryImport.getVoucher()); + entry.setPosition(entryImport.getPosition()); + log.debug(entry); + entryDAO.create(entry); + financialTransaction.addEntry(entry); + } + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (ParseException eeePE) { + if(log.isDebugEnabled()){ + log.debug("Can't parse date", eeePE); + } + } + return result; + } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database // TODO move it into JTA @@ -689,4 +853,15 @@ log.trace("beginTransaction"+topiaTransaction); return topiaTransaction; } + + protected void commitTransaction(TopiaContext topiaTransaction) throws TopiaException { + try { + topiaTransaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + throw eee; + } + } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -1,4 +1,4 @@ -/* *##% Lima Swing +/* *##% Lima Business * Copyright (C) 2008 - 2010 CodeLutin * * This program is free software; you can redistribute it and/or @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ + * ##%* + */ package org.chorem.lima.business.utils; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -1,4 +1,4 @@ -/* *##% Lima Swing +/* *##% Lima Business * Copyright (C) 2008 - 2010 CodeLutin * * This program is free software; you can redistribute it and/or @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ + * ##%* + */ package org.chorem.lima.business.utils; Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/FiscalPeriodComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/FiscalPeriodComparator.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/FiscalPeriodComparator.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -0,0 +1,35 @@ +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business.utils; + +import java.util.Comparator; +import org.chorem.lima.entity.FiscalPeriod; + +public class FiscalPeriodComparator implements Comparator<FiscalPeriod>{ + + /** + * sort by accout number in lexicographical order + */ + @Override + public int compare(FiscalPeriod o1, FiscalPeriod o2) { + return o1.getBeginDate().compareTo(o2.getBeginDate()); + } + +} Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -25,7 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountService; -import org.chorem.lima.business.ImportService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java 2010-07-06 16:39:52 UTC (rev 2964) @@ -19,7 +19,10 @@ package org.chorem.lima.util; +import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -95,8 +98,8 @@ String result = ""; byte[] buffer = new byte[(int) new File(path).length()]; try { - FileReader f = new FileReader(new File(path)); - f.read(); + BufferedInputStream f = new BufferedInputStream(new FileInputStream(path)); + f.read(buffer); if (importMethode.equals("importEntryBookChart")){ result = importService.importEntryBooksChartAsCSV(new String(buffer)); @@ -118,7 +121,7 @@ } } - return result; + return result; } public static ImportExport getInstance() { Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-07-05 17:07:51 UTC (rev 2963) +++ trunk/pom.xml 2010-07-06 16:39:52 UTC (rev 2964) @@ -248,8 +248,6 @@ <properties> <platform>chorem.org</platform> <projectId>lima</projectId> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <!-- customized libs version --> <nuiton-utils.version>1.3.2-SNAPSHOT</nuiton-utils.version>