r2962 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima lima-swing/src/main/java/org/chorem/lima/ui lima-swing/src/main/java/org/chorem/lima/ui/account lima-swing/src/main/java/org/chorem/lima/ui/entrybook lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart lima-swing/src/m
Author: jpepin Date: 2010-07-05 16:59:28 +0200 (Mon, 05 Jul 2010) New Revision: 2962 Url: http://chorem.org/repositories/revision/lima/2962 Log: Lecture et cr?\195?\169ation de fichier dans l'UI. Dans l'export des entit?\195?\169s CSV ajout de champs manquants.s Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.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/ImportExportServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.properties trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialTransactionServiceLocal.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -19,8 +19,14 @@ package org.chorem.lima.business; -import javax.ejb.Remote; +import java.util.List; +import javax.ejb.Local; + +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; +import org.nuiton.topia.TopiaContext; + /** * Transaction service. * @@ -31,7 +37,9 @@ * By : $Author: jpepin $ */ -@Remote +@Local public interface FinancialTransactionServiceLocal extends FinancialTransactionService { + public List<FinancialTransaction> getAllFinancialTransactionsBalanced(TopiaContext topiaContext) throws LimaException; + } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -34,56 +34,16 @@ */ @Remote public interface ImportExportService { - - /** - * Get database export as xml. - * - * For now it's use byte[] to be {@link java.io.Serializable}. InputStream - * nor file is allowed. - * - * TODO find a better solution than byte[] - * - * @return export as byte array - * @throws LimaException - */ - byte[] exportAsXML() throws LimaException; - - /** - * Import xml data into database. - * - * For now it's use byte[] to be {@link java.io.Serializable}. InputStream - * nor file is allowed. - * - * TODO find a better solution than byte[] - * - * @param data xml data as byte array - * @throws LimaException - */ - void importAsXML(byte[] data) throws LimaException; - /** - * Get database export as CSV; - * - * @return export as byte array - * @throws LimaException - */ - byte[] exportAsCSV() throws LimaException; + //########### INPORT /** - * Import data as CSV into database. - * - * @param data data to import (CSV) - * @throws LimaException - */ - void importAsCSV(byte[] data) throws LimaException; - - /** * Import data as EBP CSV export. * * @param data * @throws LimaException */ - void importAsEbpCSV(byte[] data) throws LimaException; + public void importAsEbpCSV(byte[] data) throws LimaException; /** * Import data as Sage Maestria export. @@ -91,7 +51,7 @@ * @param data * @throws LimaException */ - void importAsSage(byte[] data) throws LimaException; + public void importAsSage(byte[] data) throws LimaException; /** * Import data as Ciel Compta export. @@ -99,37 +59,45 @@ * @param data * @throws LimaException */ - void importAsCiel(byte[] data) throws LimaException; - + public void importAsCiel(byte[] data) throws LimaException; + /** - * export accounts chart as CSV. - */ - void exportAccountsChartAsCSV(String path) throws LimaException; - - /** - * import accounts chart CSV. + * import CSV. * Return result log */ - String importAccountsChartCSV(String path) throws LimaException; + public String importCSV(String path) throws LimaException; + public String importAccountsChartAsCSV(String path) throws LimaException; + + public String importFinancialStatementsChartAsCSV(String path) throws LimaException; + + public String importEntryBooksChartAsCSV(String path) throws LimaException; + + + //########### EXPORT + /** - * export entrybook chart as CSV. + * Get database export as CSV; + * + * @return export as byte array + * @throws LimaException */ - void exportEntryBookChartAsCSV(String path) throws LimaException; + public String exportAsCSV() throws LimaException; /** - * import entrybook chart CSV. + * export entrybook chart as CSV. */ - String importEntryBookChartCSV(String path) throws LimaException; + public String exportEntryBookChartAsCSV() throws LimaException; /** * export financialstatement chart as CSV. */ - void exportFinancialStatementChartAsCSV(String path) throws LimaException; + public String exportFinancialStatementChartAsCSV() throws LimaException; /** - * import financialstatement chart CSV. - * Return result log + * export accounts chart as CSV. */ - String importFinancialStatementChartCSV(String path) throws LimaException; + public String exportAccountsChartAsCSV() throws LimaException; + + } 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-02 10:31:31 UTC (rev 2961) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -137,7 +137,7 @@ FiscalPeriod lastFiscalPeriod = fiscalPeriodDAO.findByQuery(query); //check the new fiscal period adjoining the last - Date dateLastFiscalPeriod=lastFiscalPeriod.getEndDate(); + Date dateLastFiscalPeriod = lastFiscalPeriod.getEndDate(); dateLastFiscalPeriod = DateUtils. addMilliseconds(dateLastFiscalPeriod, 1); Date dateFiscalPeriod=fiscalPeriod.getBeginDate(); 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-02 10:31:31 UTC (rev 2961) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -47,6 +47,7 @@ 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. @@ -213,7 +214,41 @@ return result; } + /** + * Get balanced financialtransaction from selected fiscalperiod + */ + @Override + public List<FinancialTransaction> getAllFinancialTransactionsBalanced(TopiaContext topiaContext) throws LimaException { + List<FinancialTransaction> result = null; + try { + FinancialTransactionDAO financialTransactionDAO = + LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + + TopiaQuery query = financialTransactionDAO.createQuery("E"); + query.addWhere("E.amountCredit = E.amountDebit") + .addNotNull("E.entryBook"); + result = financialTransactionDAO.findAllByQuery(query); + + //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION + for (FinancialTransaction financialTransaction : result) { + + for (Entry entry : financialTransaction.getEntry()) { + entry.getAccount(); + entry.getFinancialTransaction(); + entry.getFinancialTransaction().getEntryBook(); + entry.getFinancialTransaction().getFinancialPeriod(); + } + } + } + catch (TopiaException ex) { + doCatch(topiaContext, ex, log); + } + return result; + } + + + /** * update date and amount of a financial transaction * call accounting rules * Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -19,43 +19,46 @@ package org.chorem.lima.business.ejb; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; -import java.io.OutputStream; +import java.io.StringReader; +import java.io.StringWriter; import java.util.Iterator; import java.util.List; import java.util.TreeMap; import javax.ejb.EJB; import javax.ejb.Stateless; -import javax.swing.text.StyledEditorKit.BoldAction; - -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.AccountImport; import org.chorem.lima.beans.AccountImportImpl; import org.chorem.lima.beans.FinancialStatementImport; import org.chorem.lima.beans.FinancialStatementImportImpl; -import org.chorem.lima.business.AccountService; -import org.chorem.lima.business.EntryBookService; -import org.chorem.lima.business.FinancialStatementService; +import org.chorem.lima.business.AccountServiceLocal; +import org.chorem.lima.business.EntryBookServiceLocal; +import org.chorem.lima.business.FinancialStatementServiceLocal; +import org.chorem.lima.business.FinancialTransactionServiceLocal; import org.chorem.lima.business.ImportExportService; import org.chorem.lima.business.ImportExportServiceLocal; -import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; 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.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodDAO; 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.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; @@ -63,15 +66,10 @@ import org.nuiton.topia.TopiaNotFoundException; import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; -import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy; -import au.com.bytecode.opencsv.bean.CsvToBean; /** - * XML and CSV import export service. + * CSV import export service. * - * TODO maybe split this impl into different XML and CSV impl. - * - * @author chatellier * @version $Revision$ * * Last update : $Date$ @@ -80,18 +78,24 @@ @Stateless public class ImportExportServiceImpl extends AbstractLimaService implements ImportExportService, ImportExportServiceLocal { - private static final Log log = LogFactory.getLog(ImportExportServiceImpl.class); + private static final Log log = + LogFactory.getLog(ImportExportServiceImpl.class); private TopiaContext rootContext; @EJB - AccountService accountService; + AccountServiceLocal accountService; + + @EJB + FinancialTransactionServiceLocal financialTransactionService; @EJB - FinancialStatementService financialStatementService; + FinancialStatementServiceLocal financialStatementService; @EJB - EntryBookService entryBookService; + EntryBookServiceLocal entryBookService; + + protected CSVWriter csvWriter; public ImportExportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -104,70 +108,10 @@ } } - /* - * @see org.chorem.lima.business.ImportExportService#exportAsXML() - */ - @Override - public byte[] exportAsXML() throws LimaException { - - byte[] data = null; - ByteArrayOutputStream byteArrayOutputStream = null; - try { - byteArrayOutputStream = new ByteArrayOutputStream(); - exportAsXML(byteArrayOutputStream); - } - catch (IOException eee) { - if (log.isErrorEnabled()) { - log.error("Can't export as xml", eee); - } - throw new LimaException("Can't export as xml", eee); - } - finally { - IOUtils.closeQuietly(byteArrayOutputStream); - } - - if (byteArrayOutputStream != null) { - data = byteArrayOutputStream.toByteArray(); - } - - return data; - } + //################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ - /** - * Do real output into a simple {@link OutputStream}. - * - * @param output - * @throws IOException - */ - protected void exportAsXML(OutputStream output) throws IOException { - - } - + /* - * @see org.chorem.lima.business.ImportExportService#importAsXML(byte[]) - */ - @Override - public void importAsXML(byte[] data) { - - } - - /* - * @see org.chorem.lima.business.ImportExportService#exportAsCSV() - */ - @Override - public byte[] exportAsCSV() throws LimaException { - return null; - } - - /* - * @see org.chorem.lima.business.ImportExportService#importAsCSV(byte[]) - */ - @Override - public void importAsCSV(byte[] data) throws LimaException { - - } - - /* * @see org.chorem.lima.business.ImportExportService#importAsEBPCSV(byte[]) */ @Override @@ -187,24 +131,217 @@ } + + //################ EXPORT ################ + + /** + * Export integrality of database in CSV + */ + @Override + public String exportAsCSV() throws LimaException { + TopiaContext topiaContext = null; + StringWriter out = new StringWriter(); + + try { + topiaContext = beginTransaction(); + csvWriter = new CSVWriter(out, ';'); + exportAccountsChartAsCSV(topiaContext); + exportEntryBookChartAsCSV(topiaContext); + exportFinancialStatementChartAsCSV(topiaContext); + exportFiscalPeriodAsCSV(topiaContext); + exportFinancialPeriodAsCSV(topiaContext); + exportClosedPeriodicEntryBooksAsCSV(topiaContext); + exportFinancialTransactionsAsCSV(topiaContext); + exportEntriesAsCSV(topiaContext); + // Write cache in file + csvWriter.flush(); + csvWriter.close(); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Writer",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return out.getBuffer().toString(); + } + + /** + * Remote methode call from UI. + */ @Override - public void exportAccountsChartAsCSV(String path) throws LimaException { - File f = new File(path); + public String exportFinancialStatementChartAsCSV() throws LimaException { + TopiaContext topiaContext = null; + StringWriter out = new StringWriter(); + + try { + topiaContext = beginTransaction(); + csvWriter = new CSVWriter(out, ';'); + exportFinancialStatementChartAsCSV(topiaContext); + // Write cache in file + csvWriter.flush(); + csvWriter.close(); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Writer",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return out.getBuffer().toString(); + } + + /** + * Local methode, export financialstatements from database + * structure : TYPE | Label | Header | Accounts | DebitAccounts + * | CreditAccounts | ProvisionDeprecationAccounts | SubAmount + * | HeaderAmount | MasterFinancialStatement + */ + public void exportFinancialStatementChartAsCSV(TopiaContext topiaContext) throws LimaException { + try { + String[] nextLine = new String[10]; + // Get all Financialstatements + FinancialStatementDAO financialStatementDAO = + LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + List<FinancialStatement> listFinancialStatements = + financialStatementDAO.findAll(); + // For all Financialstatements + for (FinancialStatement financialStatement : listFinancialStatements) { + nextLine[0] = "FNST"; + nextLine[1] = financialStatement.getLabel(); + nextLine[2] = new Boolean( + financialStatement.getHeader()).toString(); + nextLine[3] = financialStatement.getAccounts(); + nextLine[4] = financialStatement.getDebitAccounts(); + nextLine[5] = financialStatement.getCreditAccounts(); + nextLine[6] = financialStatement. + getProvisionDeprecationAccounts(); + nextLine[7] = new Boolean( + financialStatement.getSubAmount()).toString(); + nextLine[8] = new Boolean( + financialStatement.getHeaderAmount()).toString(); + FinancialStatement masterFinancialStatement = + financialStatement.getMasterFinancialStatement(); + String masterFinancialStatementString = ""; + if (masterFinancialStatement != null){ + masterFinancialStatementString = + masterFinancialStatement.getLabel(); + } + nextLine[9] = masterFinancialStatementString; + // Add line in file + csvWriter.writeNext(nextLine); + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + } + + /** + * Remote methode call from UI. + */ + @Override + public String exportEntryBookChartAsCSV() throws LimaException { TopiaContext topiaContext = null; + StringWriter out = new StringWriter(); + try { topiaContext = beginTransaction(); - CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ';'); - String[] nextLine = new String[5]; + csvWriter = new CSVWriter(out, ';'); + exportEntryBookChartAsCSV(topiaContext); + // Write cache in file + csvWriter.flush(); + csvWriter.close(); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Writer",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return out.getBuffer().toString(); + } + + + /** + * Local methode, export entrybooks from database + * Structure : TYPE | Code | Label | Type + */ + public void exportEntryBookChartAsCSV(TopiaContext topiaContext) throws LimaException { + try { + String[] nextLine = new String[4]; + // Get all entrybook + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + List<EntryBook> listEntryBook = entryBookDAO.findAll(); + // For all EntryBook + for (EntryBook entryBook : listEntryBook) { + nextLine[0] = "ENBK"; + nextLine[1] = entryBook.getCode(); + nextLine[2] = entryBook.getLabel(); + nextLine[3] = entryBook.getType(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + } + + /** + * Remote methode call from UI. + */ + @Override + public String exportAccountsChartAsCSV() throws LimaException { + TopiaContext topiaContext = null; + StringWriter out = new StringWriter(); + try { + topiaContext = beginTransaction(); + csvWriter = new CSVWriter(out, ';'); + exportAccountsChartAsCSV(topiaContext); + // Write cache in file + csvWriter.flush(); + csvWriter.close(); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Writer",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return out.getBuffer().toString(); + } + + /** + * Local methode, export accounts from database + * Structure : TYPE | AccountNumber | Label | ThirdParty | MasteAccount | GeneralLedger + */ + public void exportAccountsChartAsCSV(TopiaContext topiaContext) throws LimaException { + try { + String[] nextLine = new String[6]; // Récupère tous les comptes - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(topiaContext); List<Account> listAccount = accountDAO.findAll(); - nextLine[0] = "lima.accountschart"; - csvWriter.writeNext(nextLine); // Pour tous les comptes for (Account account : listAccount) { - nextLine[0] = account.getAccountNumber(); - nextLine[1] = account.getLabel(); - nextLine[2] = account.getThirdParty(); + nextLine[0] = "ACCN"; + nextLine[1] = account.getAccountNumber(); + nextLine[2] = account.getLabel(); + nextLine[3] = account.getThirdParty(); Account masterAccount = account.getMasterAccount(); Account generalLedger = account.getGeneralLedger(); String masterAccountString = ""; @@ -212,81 +349,407 @@ if (masterAccount != null){ masterAccountString = masterAccount.getAccountNumber(); } - nextLine[3] = masterAccountString; + nextLine[4] = masterAccountString; if (generalLedger != null){ generalLedgerString = generalLedger.getAccountNumber(); } - nextLine[4] = generalLedgerString; + nextLine[5] = generalLedgerString; // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - // Write cache in file - csvWriter.flush(); - csvWriter.close(); } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); + } + } + + /** + * Local methode, export financialtransactions from database + * Structue : TYPE | TransactionDate | AmountDebit | AmountCredit + * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code + */ + public void exportFinancialTransactionsAsCSV(TopiaContext topiaContext) throws LimaException { + String[] nextLine = new String[7]; + // Get all financialtransactions balanced + List<FinancialTransaction> listFinancialTransaction = + financialTransactionService.getAllFinancialTransactionsBalanced(topiaContext); + // For all balanced financialTransaction + for (FinancialTransaction financialTransaction : listFinancialTransaction) { + nextLine[0] = "FTRC"; + nextLine[1] = financialTransaction.getTransactionDate().toString(); + nextLine[2] = new Double( + financialTransaction.getAmountDebit()).toString(); + nextLine[3] = new Double( + financialTransaction.getAmountCredit()).toString(); + nextLine[4] = financialTransaction.getFinancialPeriod(). + getBeginDate().toString(); + nextLine[5] = financialTransaction.getFinancialPeriod(). + getEndDate().toString(); + nextLine[6] = financialTransaction.getEntryBook().getCode(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + + /** + * 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] = entry.getFinancialTransaction(). + getTransactionDate().toString(); + 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 + * Structure : TYPE | BeginDate | EndDate | Locked + */ + public void exportFiscalPeriodAsCSV(TopiaContext topiaContext) throws LimaException { + try { + String[] nextLine = new String[5]; + // Get all fiscalperiod + FiscalPeriodDAO fiscalPeriodDAO = + LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); + List<FiscalPeriod> listFiscalPeriod = + fiscalPeriodDAO.findAll(); + // For all Entry + for (FiscalPeriod fiscalPeriod : listFiscalPeriod) { + nextLine[0] = "FSCP"; + nextLine[1] = fiscalPeriod.getBeginDate().toString(); + nextLine[2] = fiscalPeriod.getEndDate().toString(); + nextLine[3] = new Boolean(fiscalPeriod.getLocked()).toString(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + } + + /** + * 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] = financialPeriod.getBeginDate().toString(); + nextLine[2] = financialPeriod.getEndDate().toString(); + nextLine[3] = new Boolean(financialPeriod.getLocked()).toString(); + FiscalPeriod fiscalPeriod = fiscalPeriodDAO. + findContainsFinancialPeriod(financialPeriod); + nextLine[4] = fiscalPeriod.getBeginDate().toString(); + nextLine[5] = fiscalPeriod.getEndDate().toString(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + } + + /** + * Local methode, export ClosedPeriodicEntryBooks from database + * Structure : TYPE | Locked | FinancialPeriod beginDate | FinancialPeriod endDate | EntryBook Code + */ + public void exportClosedPeriodicEntryBooksAsCSV(TopiaContext topiaContext) throws LimaException { + try { + String[] nextLine = new String[5]; + // Get all fiscalperiod + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + List<ClosedPeriodicEntryBook> listClosedPeriodicEntryBook = + closedPeriodicEntryBookDAO.findAll(); + // For all Entry + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : listClosedPeriodicEntryBook) { + nextLine[0] = "CPEB"; + nextLine[1] = new Boolean( + closedPeriodicEntryBook.getLocked()).toString(); + nextLine[2] = closedPeriodicEntryBook.getFinancialPeriod(). + getBeginDate().toString(); + nextLine[3] =closedPeriodicEntryBook.getFinancialPeriod(). + getEndDate().toString(); + nextLine[4] = closedPeriodicEntryBook.getEntryBook().getCode(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + } + + //################ IMPORT ################ + + + @Override + public String importCSV(String datas) throws LimaException { + String result = ""; + + //Accounts + TreeMap<String, AccountImport> accounts = + new TreeMap<String, AccountImport>(); + + //FinancialStatements + TreeMap<String, FinancialStatementImport> financialStatements = + new TreeMap<String, FinancialStatementImport>(); + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + + while ((nextLine = csvReader.readNext()) != null) { + String indice = nextLine[0]; + if (indice.equals("ACCN")){ + accounts = importAccountsChartsCSV( + nextLine, accounts, topiaContext); + } + else if (indice.equals("ENBK")){ + result+=importEntryBooksChartCSV( + nextLine, topiaContext); + } + else if (indice.equals("FNST")){ + financialStatements = importFinancialsStatementChartCSV( + nextLine, financialStatements, topiaContext); + } + else if (indice.equals("FSCP")){ + //result+= + } + else if (indice.equals("FNCP")){ + //result+= + } + else if (indice.equals("CPEB")){ + //result+= + } + else if (indice.equals("FTRC")){ + //result+= + } + else if (indice.equals("NTRY")){ + //result+= + } + } + + //create accounts + result+=createAccounts(accounts, topiaContext); + //create financialStatements + result+=createFinancialStatements(financialStatements, topiaContext); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { - log.debug("Can't create new CSV Writer with file"+f+eeeIO); + log.debug("Can't create new CSV Reader",eeeIO); } finally { doFinally(topiaContext, log); - } + } + return result; } + + @Override + public String importEntryBooksChartAsCSV(String datas) throws LimaException{ + String result = ""; + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + String indice = nextLine[0]; + if (indice.equals("ENBK")){ + result+=importEntryBooksChartCSV(nextLine, topiaContext); + } + } + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return result; + } + @Override - public String importAccountsChartCSV(String path) throws LimaException { - File f = new File(path); + public String importFinancialStatementsChartAsCSV(String datas) throws LimaException { String result = ""; + + //FinancialStatements + TreeMap<String, FinancialStatementImport> financialStatements = + new TreeMap<String, FinancialStatementImport>(); TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new FileReader(f), ';'); + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + String indice = nextLine[0]; + if (indice.equals("FNST")){ + financialStatements = importFinancialsStatementChartCSV( + nextLine, financialStatements, topiaContext); + } + } + + //create financialStatements + result+=createFinancialStatements(financialStatements, topiaContext); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return result; + } + + + @Override + public String importAccountsChartAsCSV(String datas) throws LimaException { + String result = ""; + + //Accounts + TreeMap<String, AccountImport> accounts = + new TreeMap<String, AccountImport>(); - nextLine = csvReader.readNext(); // Date début période - if (!nextLine[0].equals("lima.accountschart")){ - throw new LimaBusinessException( - "The file is not an export csv file type accountschart"); - } + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); - - TreeMap<String, AccountImport> accounts = - new TreeMap<String, AccountImport>(); - while ((nextLine = csvReader.readNext()) != null) { - String accountNumber = nextLine[0]; - String label = nextLine[1]; - String thirdParty = nextLine[2]; - String masterAccountNumber = nextLine[3]; - String generalLedgerNumber = nextLine[4]; - - //if exist, skip - if (accountDAO.findByAccountNumber(accountNumber) != null){ - result += "FAILED : The account " - + accountNumber + " already exists !\n"; + while ((nextLine = csvReader.readNext()) != null) { + String indice = nextLine[0]; + if (indice.equals("ACCN")){ + accounts = importAccountsChartsCSV( + nextLine, accounts, topiaContext); } - else { - //create it - AccountImport accountImport = new AccountImportImpl(); - accountImport.setAccountNumber(accountNumber); - accountImport.setLabel(label); - accountImport.setThirdParty(thirdParty); - accountImport.setMasterAccount(masterAccountNumber); - accountImport.setGeneralLedger(generalLedgerNumber); - // put it in hashset - accounts.put(accountNumber, accountImport); - } - } + } + + //create accounts + result+=createAccounts(accounts, topiaContext); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader",eeeIO); + } + finally { + doFinally(topiaContext, log); + } + return result; + } + + public TreeMap<String, AccountImport> importAccountsChartsCSV(String[] nextLine, TreeMap<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException{ + + String accountNumber = nextLine[1]; + String label = nextLine[2]; + String thirdParty = nextLine[3]; + String masterAccountNumber = nextLine[4]; + String generalLedgerNumber = nextLine[5]; + + try { + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(topiaContext); + + //if not exist, create it + if (accountDAO.findByAccountNumber(accountNumber) == null){ + //create it + AccountImport accountImport = new AccountImportImpl(); + accountImport.setAccountNumber(accountNumber); + accountImport.setLabel(label); + accountImport.setThirdParty(thirdParty); + accountImport.setMasterAccount(masterAccountNumber); + accountImport.setGeneralLedger(generalLedgerNumber); + // put it in hashset + accounts.put(accountNumber, accountImport); + } + /*else { + result += "FAILED : The account " + + accountNumber + " already exists !\n"; + }*/ + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + + return accounts; + } + + + public String createAccounts(TreeMap<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException { + String result = ""; + + try { + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); while (accounts.size() > 0){ - for (Iterator<AccountImport> itr =accounts.values().iterator(); itr.hasNext();){ + for (Iterator<AccountImport> itr = accounts.values().iterator(); itr.hasNext();){ AccountImport accountImport = itr.next(); String masterAccountNumber = accountImport.getMasterAccount(); String generalLedgerNumber = accountImport.getGeneralLedger(); @@ -326,223 +789,98 @@ catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader with file"+f+eeeIO); - } - finally { - doFinally(topiaContext, log); - } return result; } - @Override - public void exportEntryBookChartAsCSV(String path) throws LimaException { - File f = new File(path); - TopiaContext topiaContext = null; + public String importEntryBooksChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + String result =""; try { - topiaContext = beginTransaction(); - CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ';'); - String[] nextLine = new String[3]; - // Get all entrybook - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode(nextLine[1]); + entryBook.setLabel(nextLine[2]); + entryBook.setType(nextLine[3]); - List<EntryBook> listEntryBook = entryBookDAO.findAll(); - nextLine[0] = "lima.entrybooks"; - csvWriter.writeNext(nextLine); - // For all EntryBook - for (EntryBook entryBook : listEntryBook) { - nextLine[0] = entryBook.getCode(); - nextLine[1] = entryBook.getLabel(); - nextLine[2] = entryBook.getType(); - // Ajoute la ligne au fichier - csvWriter.writeNext(nextLine); - } - // Write cache in file - csvWriter.flush(); - csvWriter.close(); - } + //if exist, skip + if (entryBookDAO.findByCode(entryBook.getCode()) != null){ + result += "FAILED : The entrybook " + + entryBook.getLabel() + " already exists !\n"; + } + else { + //create it + entryBookService.createEntryBook(entryBook); + result += "SUCCESS : The financialStatement " + + entryBook.getLabel() + " is created ! \n"; + } + } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Writer with file"+f+eeeIO); - } - finally { - doFinally(topiaContext, log); - } - + return result; } - - @Override - public String importEntryBookChartCSV(String path) throws LimaException { - File f = new File(path); - String result = ""; - TopiaContext topiaContext = null; + public TreeMap<String, FinancialStatementImport> importFinancialsStatementChartCSV(String[] nextLine, TreeMap<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { + + String label = nextLine[1]; + String header = nextLine[2]; + String accounts = nextLine[3]; + String debitAccounts = nextLine[4]; + String creditAccounts = nextLine[5]; + String provisionDeprecationAccounts = nextLine[6]; + String subAmount = nextLine[7]; + String headerAmount = nextLine[8]; + String masterFinancialStatement = nextLine[9]; + try { - topiaContext = beginTransaction(); - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new FileReader(f), ';'); - nextLine = csvReader.readNext(); // File Type - if (!nextLine[0].equals("lima.entrybooks")){ - throw new LimaBusinessException( - "The file is not an export csv file type entrybooks"); - } + FinancialStatementDAO financialStatementDAO = + LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); - - while ((nextLine = csvReader.readNext()) != null) { - EntryBook entryBook = new EntryBookImpl(); - entryBook.setCode(nextLine[0]); - entryBook.setLabel(nextLine[1]); - entryBook.setType(nextLine[2]); - - //if exist, skip - if (entryBookDAO.findByCode(entryBook.getCode()) != null){ - result += "FAILED : The entrybook " - + entryBook.getLabel() + " already exists !\n"; - } - else { - //create it - entryBookService.createEntryBook(entryBook); - result += "SUCCESS : The financialStatement " + - entryBook.getLabel() + " is created ! \n"; - } + //if exist, skip + if (financialStatementDAO.findByLabel(label) == null){ + //create it + FinancialStatementImport financialStatementImport = + new FinancialStatementImportImpl(); + financialStatementImport.setLabel(label); + financialStatementImport.setHeader(header); + financialStatementImport.setAccounts(accounts); + financialStatementImport.setCreditAccounts(creditAccounts); + financialStatementImport.setDebitAccounts(debitAccounts); + financialStatementImport.setHeaderAmount(headerAmount); + financialStatementImport.setProvisionDeprecationAccounts( + provisionDeprecationAccounts); + financialStatementImport.setSubAmount(subAmount); + financialStatementImport.setMasterFinancialStatement( + masterFinancialStatement); + + // put it in hashset + financialStatements.put(label, financialStatementImport); } + /*else { + result += "FAILED : The financialstatement " + + label + " already exists !\n"; + }*/ } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader with file"+f+eeeIO); - } - finally { - doFinally(topiaContext, log); - } - return result; + return financialStatements; } - - @Override - public void exportFinancialStatementChartAsCSV(String path) throws LimaException { - File f = new File(path); - TopiaContext topiaContext = null; - - try { - topiaContext = beginTransaction(); - CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ';'); - String[] nextLine = new String[9]; - // Get all Financialstatements - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - List<FinancialStatement> listFinancialStatements = - financialStatementDAO.findAll(); - nextLine[0] = "lima.financialstatementschart"; - csvWriter.writeNext(nextLine); - // For all Financialstatements - for (FinancialStatement financialStatement : listFinancialStatements) { - nextLine[0] = financialStatement.getLabel(); - nextLine[1] = new Boolean( - financialStatement.getHeader()).toString(); - nextLine[2] = financialStatement.getAccounts(); - nextLine[3] = financialStatement.getDebitAccounts(); - nextLine[4] = financialStatement.getCreditAccounts(); - nextLine[5] = financialStatement. - getProvisionDeprecationAccounts(); - nextLine[6] = new Boolean( - financialStatement.getSubAmount()).toString(); - nextLine[7] = new Boolean( - financialStatement.getHeaderAmount()).toString(); - FinancialStatement masterFinancialStatement = - financialStatement.getMasterFinancialStatement(); - String masterFinancialStatementString = ""; - if (masterFinancialStatement != null){ - masterFinancialStatementString = - masterFinancialStatement.getLabel(); - } - nextLine[8] = masterFinancialStatementString; - // Add line in file - csvWriter.writeNext(nextLine); - } - // Write cache in file - csvWriter.flush(); - csvWriter.close(); - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Writer with file"+f+eeeIO); - } - finally { - doFinally(topiaContext, log); - } - } - @Override - public String importFinancialStatementChartCSV(String path) throws LimaException { - File f = new File(path); + + public String createFinancialStatements(TreeMap<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { String result = ""; - - TopiaContext topiaContext = null; try { - topiaContext = beginTransaction(); - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new FileReader(f), ';'); - - nextLine = csvReader.readNext(); // File Type - if (!nextLine[0].equals("lima.financialstatementschart")){ - throw new LimaBusinessException( - "The file is not an export csv file type financialstatementschart"); - } - - FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - - - TreeMap<String, FinancialStatementImport> financialStatements = - new TreeMap<String, FinancialStatementImport>(); - - while ((nextLine = csvReader.readNext()) != null) { - String label = nextLine[0]; - String header = nextLine[1]; - String accounts = nextLine[2]; - String debitAccounts = nextLine[3]; - String creditAccounts = nextLine[4]; - String provisionDeprecationAccounts = nextLine[5]; - String subAmount = nextLine[6]; - String headerAmount = nextLine[7]; - String masterFinancialStatement = nextLine[8]; - - //if exist, skip - if (financialStatementDAO.findByLabel(label) != null){ - result += "FAILED : The financialstatement " - + label + " already exists !\n"; - } - else { - //create it - FinancialStatementImport financialStatementImport = - new FinancialStatementImportImpl(); - financialStatementImport.setLabel(label); - financialStatementImport.setHeader(header); - financialStatementImport.setAccounts(accounts); - financialStatementImport.setCreditAccounts(creditAccounts); - financialStatementImport.setDebitAccounts(debitAccounts); - financialStatementImport.setHeaderAmount(headerAmount); - financialStatementImport.setProvisionDeprecationAccounts( - provisionDeprecationAccounts); - financialStatementImport.setSubAmount(subAmount); - financialStatementImport.setMasterFinancialStatement( - masterFinancialStatement); - - // put it in hashset - financialStatements.put(label, financialStatementImport); - } - } - - - while (financialStatements.size() > 0){ + + FinancialStatementDAO financialStatementDAO = + LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + + while (financialStatements.size() > 0){ for (Iterator<FinancialStatementImport> itr = financialStatements.values().iterator(); itr.hasNext();){ FinancialStatementImport financialStatementImport = itr.next(); String masterFinancialStatementLabel = @@ -589,20 +927,14 @@ itr.remove(); } } - - } + } } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader with file"+f+eeeIO); - } - finally { - doFinally(topiaContext, log); - } - return result; + return result; } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database Modified: trunk/lima-callao/src/main/xmi/accounting.properties =================================================================== --- trunk/lima-callao/src/main/xmi/accounting.properties 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-callao/src/main/xmi/accounting.properties 2010-07-05 14:59:28 UTC (rev 2962) @@ -1,10 +1,24 @@ # Precise l'entete de l'ensemble des fichiers generes model.tagvalue.copyright=/*\n Copyright (C) 2009-2010 Lima Callao\n */ +# natural id org.chorem.lima.entity.Account.class.tagvalue.naturalIdMutable=false org.chorem.lima.entity.Account.attribute.accountNumber.tagvalue.naturalId=true org.chorem.lima.entity.Account.attribute.accountNumber.tagvalue.notNull=true +org.chorem.lima.entity.FinancialPeriod.class.tagvalue.naturalIdMutable=false +org.chorem.lima.entity.FinancialPeriod.attribute.beginDate.tagvalue.naturalId=true +org.chorem.lima.entity.FinancialPeriod.attribute.beginDate.tagvalue.notNull=true +org.chorem.lima.entity.FinancialPeriod.attribute.endDate.tagvalue.naturalId=true +org.chorem.lima.entity.FinancialPeriod.attribute.endDate.tagvalue.notNull=true + +org.chorem.lima.entity.FiscalPeriod.class.tagvalue.naturalIdMutable=false +org.chorem.lima.entity.FiscalPeriod.attribute.beginDate.tagvalue.naturalId=true +org.chorem.lima.entity.FiscalPeriod.attribute.beginDate.tagvalue.notNull=true +org.chorem.lima.entity.FiscalPeriod.attribute.endDate.tagvalue.naturalId=true +org.chorem.lima.entity.FiscalPeriod.attribute.endDate.tagvalue.notNull=true + +# lazy org.chorem.lima.entity.Account.attribute.subAccounts.tagvalue.lazy=false org.chorem.lima.entity.Account.attribute.subLedgers.tagvalue.lazy=false org.chorem.lima.entity.FinancialTransaction.attribute.financialPeriod.tagvalue.lazy=false Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -19,15 +19,11 @@ package org.chorem.lima; import static org.nuiton.i18n.I18n._; - import java.util.List; import java.util.Locale; - import javax.swing.JOptionPane; import javax.swing.SwingUtilities; - import jaxx.runtime.SwingUtil; - import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; import org.apache.commons.beanutils.converters.DateConverter; Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportHandler.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -0,0 +1,62 @@ +package org.chorem.lima.ui; + +import javax.swing.JFileChooser; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.util.DialogHelper; +import org.chorem.lima.util.FileChooseView; +import org.chorem.lima.util.ImportExport; + +public class ImportExportHandler { + + /** log. */ + private static final Log log = LogFactory.getLog(ImportExportHandler.class); + + protected MainView view; + + ImportExportHandler(MainView mainView){ + this.view=mainView; + } + + public void importexportDialog(){ + + ImportExportForm importExportForm = new ImportExportForm(view); + importExportForm.setLocationRelativeTo(view); + importExportForm.setVisible(true); + + Object value = importExportForm.getRadioButtons().getSelectedValue(); + // if action confirmed + if (value != null){ + String mode = (String) value; + FileChooseView fileChooseView = new FileChooseView(view); + + JFileChooser chooser = fileChooseView.getChooser(); + ImportExport importExport = ImportExport.getInstance(); + + try { + if (mode.equals("import")){ + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { + String filePath = chooser.getSelectedFile().getAbsolutePath(); + String message = importExport.importFromCsvFile(filePath, ""); + DialogHelper.showMessageDialog(message); + } + } + else { + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { + String filePath = chooser.getSelectedFile().getAbsolutePath(); + importExport.exportToCsvFile(filePath, ""); + } + } + } catch (LimaException eee) { + if (log.isErrorEnabled()){ + log.error("Can't "+ mode +" this file", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-07-05 14:59:28 UTC (rev 2962) @@ -78,7 +78,8 @@ <JMenuBar> <JMenu text="lima.menu.file"> - <JMenu text="lima.import" actionIcon='import-element'> + <JMenuItem text="lima.common.importexport" onActionPerformed='getHandler().showImportExportView(this)'/> + <!-- <JMenu text="lima.import" actionIcon='import-element'> <JMenuItem text="lima.import.all" onActionPerformed='getHandler().showImportView("all")'/> <JMenuItem text="lima.import.all.csv" onActionPerformed='getHandler().showImportView("all_csv")'/> <JMenuItem text="lima.import.all.csv.ebp" onActionPerformed='getHandler().showImportView("all_csv_ebp")'/> @@ -89,7 +90,7 @@ <JMenuItem text="lima.export.all" onActionPerformed='getHandler().showExportView("all")'/> <JMenuItem text="lima.export.all.csv" onActionPerformed='getHandler().showExportView("all_csv")'/> <JMenuItem text="lima.export.account" onActionPerformed='getHandler().showExportView("account")'/> - </JMenu> + </JMenu> --> <JSeparator/> <JMenuItem text="lima.common.print" actionIcon='print'/> <JSeparator/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -382,17 +382,18 @@ public void showFinancialStatementReportsView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - FinancialStatementReportView financialStatementReportView= new FinancialStatementReportView(mainView); - mainView.showTab(_("lima.reports.financialstatement"), financialStatementReportView); + FinancialStatementReportView financialStatementReportView = new FinancialStatementReportView(mainView); + mainView.showTab(_("lima.reports.financialstatement"), financialStatementReportView); } - public void showImportView(String type) { - /*if (!getImportView(type).isEnabled()) { - getImportView(type).setEnabled(true); - }*/ + public void showImportExportView(JAXXContext rootContext) { + MainView mainView = getUI(rootContext); + ImportExportHandler importExportHandler = new ImportExportHandler(mainView); + importExportHandler.importexportDialog(); } public void showExportView(String type) { + /*if (!getExportView(type).isEnabled()) { getExportView(type).setEnabled(true); }*/ 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-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -38,6 +38,7 @@ import org.chorem.lima.util.DialogHelper; import org.chorem.lima.util.ErrorHelper; import org.chorem.lima.util.FileChooseView; +import org.chorem.lima.util.ImportExport; import org.jdesktop.swingx.JXTreeTable; /** @@ -57,12 +58,10 @@ protected AccountView view; protected AccountService accountService; - protected ImportExportService importExportService; protected AccountViewHandler(AccountView view) { this.view = view; // Gets factory service - importExportService = LimaServiceFactory.getInstance().getImportExportService(); accountService = LimaServiceFactory.getInstance().getAccountService(); } @@ -266,13 +265,14 @@ FileChooseView fileChooseView = new FileChooseView(view); JFileChooser chooser = fileChooseView.getChooser(); + ImportExport importExport = ImportExport.getInstance(); try { if (mode.equals("import")){ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - String message = importExportService.importAccountsChartCSV(filePath); + String message = importExport.importFromCsvFile(filePath, "importAccountsChart"); accountsTreeTableModel.refreshTree(); DialogHelper.showMessageDialog(message); } @@ -281,7 +281,7 @@ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - importExportService.exportAccountsChartAsCSV(filePath); + importExport.exportToCsvFile(filePath, "exportAccountsChart"); } } } catch (LimaException eee) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -19,24 +19,18 @@ package org.chorem.lima.ui.entrybook; import static org.nuiton.i18n.I18n._; - import javax.swing.JFileChooser; import javax.swing.JOptionPane; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.ImportExportService; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; -import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.ImportExportForm; -import org.chorem.lima.ui.account.AccountTreeTableModel; import org.chorem.lima.util.DialogHelper; -import org.chorem.lima.util.ErrorHelper; import org.chorem.lima.util.FileChooseView; +import org.chorem.lima.util.ImportExport; import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.JXTreeTable; /** * Handler for entry book view. @@ -52,12 +46,9 @@ private static final Log log = LogFactory.getLog(EntryBookViewHandler.class); protected EntryBookView view; - - protected ImportExportService importExportService; - + public EntryBookViewHandler(EntryBookView view) { this.view = view; - importExportService = LimaServiceFactory.getInstance().getImportExportService(); } public void addEntryBook() { @@ -166,13 +157,14 @@ FileChooseView fileChooseView = new FileChooseView(view); JFileChooser chooser = fileChooseView.getChooser(); + ImportExport importExport = ImportExport.getInstance(); try { if (mode.equals("import")){ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - String message = importExportService.importEntryBookChartCSV(filePath); + String message = importExport.importFromCsvFile(filePath, "importEntryBookChart"); entryBookTableModel.refreshTable(); DialogHelper.showMessageDialog(message); } @@ -181,7 +173,7 @@ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - importExportService.exportEntryBookChartAsCSV(filePath); + importExport.exportToCsvFile(filePath, "exportEntryBookChart"); } } } catch (LimaException eee) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2010-07-02 10:31:31 UTC (rev 2961) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -24,18 +24,17 @@ import javax.swing.tree.TreePath; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.ImportExportService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; -import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.ImportExportForm; import org.chorem.lima.ui.financialstatementchart.FinancialStatementHeaderForm; import org.chorem.lima.ui.financialstatementchart.FinancialStatementMovementForm; import org.chorem.lima.util.DialogHelper; import org.chorem.lima.util.ErrorHelper; import org.chorem.lima.util.FileChooseView; +import org.chorem.lima.util.ImportExport; import org.jdesktop.swingx.JXTreeTable; /** @@ -53,12 +52,9 @@ private static final Log log = LogFactory.getLog(FinancialStatementChartViewHandler.class); protected FinancialStatementChartView view; - - protected ImportExportService importExportService; - + protected FinancialStatementChartViewHandler(FinancialStatementChartView view) { this.view = view; - importExportService = LimaServiceFactory.getInstance().getImportExportService(); } /** @@ -67,10 +63,13 @@ public void addFinancialStatementHeader() { JXTreeTable treeTable = view.getTreeTable(); - FinancialStatementChartTreeTableModel treeTableModel = (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); + FinancialStatementChartTreeTableModel treeTableModel = + (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); - FinancialStatement newFinancialStatementHeader = new FinancialStatementImpl(); - FinancialStatementHeaderForm financialStatementHeaderForm = new FinancialStatementHeaderForm(view); + FinancialStatement newFinancialStatementHeader = + new FinancialStatementImpl(); + FinancialStatementHeaderForm financialStatementHeaderForm = + new FinancialStatementHeaderForm(view); financialStatementHeaderForm.setFinancialStatement(newFinancialStatementHeader); // jaxx constructor don't call super() ? financialStatementHeaderForm.setLocationRelativeTo(view); @@ -112,10 +111,13 @@ public void addFinancialStatementMovement(){ JXTreeTable treeTable = view.getTreeTable(); - FinancialStatementChartTreeTableModel treeTableModel = (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); + FinancialStatementChartTreeTableModel treeTableModel = + (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); - FinancialStatement newFinancialStatementMovement = new FinancialStatementImpl(); - FinancialStatementMovementForm financialStatementMovementForm = new FinancialStatementMovementForm(view); + FinancialStatement newFinancialStatementMovement = + new FinancialStatementImpl(); + FinancialStatementMovementForm financialStatementMovementForm = + new FinancialStatementMovementForm(view); financialStatementMovementForm.setFinancialStatement(newFinancialStatementMovement); // jaxx constructor don't call super() ? financialStatementMovementForm.setLocationRelativeTo(view); @@ -155,12 +157,14 @@ public void updateFinancialStatement() { JXTreeTable treeTable = view.getTreeTable(); - FinancialStatementChartTreeTableModel treeTableModel = (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); + FinancialStatementChartTreeTableModel treeTableModel = + (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); // get selected account int selectedRow = view.treeTable.getSelectedRow(); TreePath treePath = view.treeTable.getPathForRow(selectedRow); // not null - FinancialStatement financialStatement = (FinancialStatement) treePath.getLastPathComponent(); + FinancialStatement financialStatement = + (FinancialStatement) treePath.getLastPathComponent(); //update Account or update SubLedger if (financialStatement != null) { // get current selection path @@ -172,7 +176,8 @@ //test if selectedrow is account or ledger log.debug(financialStatement.getHeader()); if (financialStatement.getHeader()){ - FinancialStatementHeaderForm financialStatementHeaderForm = new FinancialStatementHeaderForm(view); + FinancialStatementHeaderForm financialStatementHeaderForm = + new FinancialStatementHeaderForm(view); financialStatementHeaderForm.setFinancialStatement(financialStatement); // jaxx constructor don't call super() ? financialStatementHeaderForm.setLocationRelativeTo(view); @@ -182,19 +187,22 @@ } // else is a movement else{ - FinancialStatementMovementForm financialStatementMovementForm = new FinancialStatementMovementForm(view); + FinancialStatementMovementForm financialStatementMovementForm = + new FinancialStatementMovementForm(view); financialStatementMovementForm.setFinancialStatement(financialStatement); // jaxx constructor don't call super() ? financialStatementMovementForm.setLocationRelativeTo(view); financialStatementMovementForm.setVisible(true); // null == cancel action - financialStatement = financialStatementMovementForm.getFinancialStatement(); + financialStatement = + financialStatementMovementForm.getFinancialStatement(); } //if action confirmed if (financialStatement != null){ // update it try { - treeTableModel.updateFinancialStatement(treePath, financialStatement); + treeTableModel.updateFinancialStatement( + treePath, financialStatement); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't add update", eee); @@ -224,10 +232,12 @@ if (n == JOptionPane.YES_OPTION) { // update view of treetable TreePath treePath = view.treeTable.getPathForRow(selectedRow); - FinancialStatement financialStatement = (FinancialStatement) treePath.getLastPathComponent(); + FinancialStatement financialStatement = + (FinancialStatement) treePath.getLastPathComponent(); try{ - treeTableModel.removeFinancialStatementObject(treePath, financialStatement); + treeTableModel.removeFinancialStatementObject( + treePath, financialStatement); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't delete account", eee); @@ -255,13 +265,14 @@ FileChooseView fileChooseView = new FileChooseView(view); JFileChooser chooser = fileChooseView.getChooser(); + ImportExport importExport = ImportExport.getInstance(); try { if (mode.equals("import")){ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - String message = importExportService.importFinancialStatementChartCSV(filePath); + String message = importExport.importFromCsvFile(filePath, "importFinancialStatementsChart"); treeTableModel.refreshTree(); DialogHelper.showMessageDialog(message); } @@ -270,7 +281,7 @@ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - importExportService.exportFinancialStatementChartAsCSV(filePath); + importExport.exportToCsvFile(filePath, "exportFinancialStatementsChart"); } } } catch (LimaException eee) { Added: trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/ImportExport.java 2010-07-05 14:59:28 UTC (rev 2962) @@ -0,0 +1,129 @@ +/* *##% Lima Swing + * 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.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ImportExportService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.account.AccountViewHandler; + +public class ImportExport { + + private static ImportExport exchanger; + + private static final Log log = LogFactory.getLog(AccountViewHandler.class); + + protected ImportExportService importExportService; + + public ImportExport() { + importExportService = LimaServiceFactory.getInstance().getImportExportService(); + } + + /** + * Call export methode in business + * Get csv datas in string and write file + * @param path + * @param exportMethode + * @throws LimaException + */ + public void exportToCsvFile(String path, String exportMethode) throws LimaException { + String result = ""; + try { + BufferedOutputStream f = new BufferedOutputStream(new FileOutputStream(path)); + if (exportMethode.equals("exportEntryBookChart")){ + result = importExportService.exportEntryBookChartAsCSV(); + } + else if (exportMethode.equals("exportAccountsChart")){ + result = importExportService.exportAccountsChartAsCSV(); + + } + else if (exportMethode.equals("exportFinancialStatementsChart")){ + result = importExportService.exportFinancialStatementChartAsCSV(); + } + else { + result = importExportService.exportAsCSV(); + } + f.write(result.getBytes()); + f.flush(); + f.close(); + } + catch (IOException eee) { + if (log.isDebugEnabled()){ + log.debug("Can't write file "+path, eee); + } + } + } + + + /** + * Open scv file and get his datas on a string + * Call import methode in business + * + * @param path + * @param importMethode + * @return + * @throws LimaException + */ + public String importFromCsvFile(String path, String importMethode) throws LimaException { + String result = ""; + byte[] buffer = new byte[(int) new File(path).length()]; + try { + BufferedInputStream f = new BufferedInputStream(new FileInputStream(path)); + f.read(buffer); + + if (importMethode.equals("importEntryBookChart")){ + result = importExportService.importEntryBooksChartAsCSV(new String(buffer)); + } + else if (importMethode.equals("importAccountsChart")){ + result = importExportService.importAccountsChartAsCSV(new String(buffer)); + } + else if (importMethode.equals("importFinancialStatementsChart")){ + result = importExportService.importFinancialStatementsChartAsCSV(new String(buffer)); + } + else { + result = importExportService.importCSV(new String(buffer)); + } + f.close(); + } + catch (IOException eee) { + if (log.isDebugEnabled()){ + log.debug("Can't read file "+path, eee); + } + } + + return result; + } + + public static ImportExport getInstance() { + if (exchanger == null) { + exchanger = new ImportExport(); + } + return exchanger; + } + +}
participants (1)
-
jpepin@users.chorem.org