Author: jpepin Date: 2010-07-02 11:46:14 +0200 (Fri, 02 Jul 2010) New Revision: 2960 Url: http://chorem.org/repositories/revision/lima/2960 Log: Ajout import plan BCR. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 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-01 15:51:40 UTC (rev 2959) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-07-02 09:46:14 UTC (rev 2960) @@ -107,26 +107,29 @@ void exportAccountsChartAsCSV(String path) throws LimaException; /** - * import accounts chart as CSV. + * import accounts chart CSV. * Return result log */ String importAccountsChartCSV(String path) throws LimaException; /** * export entrybook chart as CSV. - * - * @param data - * @throws LimaException */ - void exportEntryBookChartAsCSV(byte[] data) throws LimaException; + void exportEntryBookChartAsCSV(String path) throws LimaException; /** + * import entrybook chart CSV. + */ + void importEntryBookChartCSV(String path) throws LimaException; + + /** * export financialstatement chart as CSV. */ void exportFinancialStatementChartAsCSV(String path) throws LimaException; /** - * export financialstatement chart as CSV. + * import financialstatement chart CSV. + * Return result log */ String importFinancialStatementChartCSV(String path) throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-01 15:51:40 UTC (rev 2959) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-02 09:46:14 UTC (rev 2960) @@ -106,10 +106,15 @@ financialStatementDAO.create(financialStatement); + FinancialStatement masterfinancialStatementUpdate = null; + if (masterFinancialStatement != null){ + masterfinancialStatementUpdate = financialStatementDAO.findByLabel(masterFinancialStatement.getLabel()); + } + // check if parent account exist; - if (masterFinancialStatement != null) { - masterFinancialStatement.addSubFinancialStatements(financialStatement); - financialStatementDAO.update(masterFinancialStatement); + if (masterfinancialStatementUpdate != null) { + masterfinancialStatementUpdate.addSubFinancialStatements(financialStatement); + financialStatementDAO.update(masterfinancialStatementUpdate); } commitTransaction(transaction); 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-01 15:51:40 UTC (rev 2959) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-07-02 09:46:14 UTC (rev 2960) @@ -30,12 +30,15 @@ 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.FinancialStatementService; import org.chorem.lima.business.ImportExportService; @@ -264,14 +267,14 @@ } else { //create it - AccountImport account = new AccountImportImpl(); - account.setAccountNumber(accountNumber); - account.setLabel(label); - account.setThirdParty(thirdParty); - account.setMasterAccount(masterAccountNumber); - account.setGeneralLedger(generalLedgerNumber); + 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, account); + accounts.put(accountNumber, accountImport); } } @@ -292,8 +295,6 @@ account.setAccountNumber(accountImport.getAccountNumber()); account.setLabel(accountImport.getLabel()); account.setThirdParty(accountImport.getThirdParty()); - account.setMasterAccount(masterAccount); - account.setGeneralLedger(generalLedger); if (generalLedger != null){ accountService.createSubLedger(generalLedger, account); @@ -329,8 +330,17 @@ @Override - public void exportEntryBookChartAsCSV(byte[] data) throws LimaException { + public void exportEntryBookChartAsCSV(String path) throws LimaException { + + } + + + @Override + public void importEntryBookChartCSV(String path) throws LimaException { + // TODO Auto-generated method stub + + } @Override public void exportFinancialStatementChartAsCSV(String path) throws LimaException { @@ -342,24 +352,32 @@ CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ';'); String[] nextLine = new String[9]; // Récupère tous les comptes - FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - List<FinancialStatement> listFinancialStatements = financialStatementDAO.findAll(); + FinancialStatementDAO financialStatementDAO = + LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + List<FinancialStatement> listFinancialStatements = + financialStatementDAO.findAll(); nextLine[0] = "lima.financialstatementschart"; csvWriter.writeNext(nextLine); // Pour tous les comptes for (FinancialStatement financialStatement : listFinancialStatements) { nextLine[0] = financialStatement.getLabel(); - nextLine[1] = new Boolean(financialStatement.getHeader()).toString(); + 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(); + 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(); + masterFinancialStatementString = + masterFinancialStatement.getLabel(); } nextLine[8] = masterFinancialStatementString; // Ajoute la ligne au fichier @@ -388,11 +406,10 @@ TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); - /* String[] nextLine = new String[1]; CSVReader csvReader = new CSVReader(new FileReader(f), ';'); - nextLine = csvReader.readNext(); // Date début période + nextLine = csvReader.readNext(); // File Type if (!nextLine[0].equals("lima.financialstatementschart")){ throw new LimaBusinessException( "The file is not an export csv file type financialstatementschart"); @@ -400,93 +417,104 @@ FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - TreeMap<String, AccountImport> accounts = - new TreeMap<String, AccountImport>(); - - ColumnPositionMappingStrategy strat = - new ColumnPositionMappingStrategy(); - strat.setType(FinancialStatementImport.class); - String[] columns = new String[] {"label", "header", "accounts", - "debitAccounts", "creditAccounts","provisionDeprecationAccounts", - "subAmount", "headerAmount", "masterFinancialStatement"}; - strat.setColumnMapping(columns); - CsvToBean csv = new CsvToBean(); - List list = csv.parse(strat, csvReader); + TreeMap<String, FinancialStatementImport> financialStatements = + new TreeMap<String, FinancialStatementImport>(); 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]; + 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(accountNumber) != null){ - result += "FAILED : The account " - + accountNumber + " already exists !\n"; + if (financialStatementDAO.findByLabel(label) != null){ + result += "FAILED : The financialstatement " + + label + " already exists !\n"; } else { //create it - AccountImport account = new AccountImportImpl(); - account.setAccountNumber(accountNumber); - account.setLabel(label); - account.setThirdParty(thirdParty); - account.setMasterAccount(masterAccountNumber); - account.setGeneralLedger(generalLedgerNumber); + 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 - accounts.put(accountNumber, account); + financialStatements.put(label, financialStatementImport); } - } + } + - while (accounts.size() > 0){ - for (Iterator<AccountImport> itr =accounts.values().iterator(); itr.hasNext();){ - AccountImport accountImport = itr.next(); - String masterAccountNumber = accountImport.getMasterAccount(); - String generalLedgerNumber = accountImport.getGeneralLedger(); - //Account masterAccount = - accountDAO.findByAccountNumber(masterAccountNumber); - Account generalLedger = - accountDAO.findByAccountNumber(generalLedgerNumber); + while (financialStatements.size() > 0){ + for (Iterator<FinancialStatementImport> itr = financialStatements.values().iterator(); itr.hasNext();){ + FinancialStatementImport financialStatementImport = itr.next(); + String masterFinancialStatementLabel = + financialStatementImport.getMasterFinancialStatement(); + FinancialStatement masterFinancialStatement = + financialStatementDAO.findByLabel( + masterFinancialStatementLabel); - if ((masterAccountNumber.equals("") && generalLedgerNumber.equals("")) - || masterAccount != null || generalLedger != null){ + if (masterFinancialStatementLabel.equals("") + || masterFinancialStatement != null){ //create it - Account account = new AccountImpl(); - account.setAccountNumber(accountImport.getAccountNumber()); - account.setLabel(accountImport.getLabel()); - account.setThirdParty(accountImport.getThirdParty()); - account.setMasterAccount(masterAccount); - account.setGeneralLedger(generalLedger); + FinancialStatement financialStatement = + new FinancialStatementImpl(); + financialStatement.setLabel( + financialStatementImport.getLabel()); + financialStatement.setHeader(Boolean.parseBoolean( + financialStatementImport.getHeader())); + financialStatement.setAccounts( + financialStatementImport.getAccounts()); + financialStatement.setDebitAccounts( + financialStatementImport.getDebitAccounts()); + financialStatement.setCreditAccounts( + financialStatementImport.getCreditAccounts()); + financialStatement.setProvisionDeprecationAccounts( + financialStatementImport. + getProvisionDeprecationAccounts()); + financialStatement.setSubAmount(Boolean.parseBoolean( + financialStatementImport.getSubAmount())); + financialStatement.setHeaderAmount(Boolean.parseBoolean( + financialStatementImport.getHeaderAmount())); + + financialStatementService.createFinancialStatement( + masterFinancialStatement, financialStatement); - if (generalLedger != null){ - accountService.createSubLedger(generalLedger, account); - } - else { - accountService.createAccount(masterAccount, account); - } - result += "SUCCESS : The account " + - accountImport.getAccountNumber() + " is created ! \n"; + result += "SUCCESS : The financialStatement " + + financialStatementImport.getLabel() + " is created ! \n"; itr.remove(); } - else if (!accounts.containsKey(masterAccountNumber) - && !accounts.containsKey(generalLedgerNumber) ){ - result += "FAILED : The account " + - accountImport.getAccountNumber() + " have masterAccount : " + - masterAccountNumber + "which not exist \n"; + else if (!financialStatements.containsKey(masterFinancialStatementLabel)){ + result += "FAILED : The financialStatement " + + financialStatementImport.getLabel() + + " have masterFinancialStatement : " + + masterFinancialStatementLabel + "which not exist \n"; itr.remove(); } } } - */ } catch (TopiaException eeeTE){ doCatch(topiaContext, eeeTE, log); } - //catch (IOException eeeIO) { - // log.debug("Can't create new CSV Reader with file"+f+eeeIO); - //} + catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader with file"+f+eeeIO); + } finally { doFinally(topiaContext, log); }