r3199 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/ejbinterface lima-swing/src/main/java/org/chorem/lima/ui/vatreports
Author: vsalaun Date: 2011-07-05 12:34:37 +0200 (Tue, 05 Jul 2011) New Revision: 3199 Url: http://chorem.org/repositories/revision/lima/3199 Log: #347 improves VAT table Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2011-07-04 16:06:26 UTC (rev 3198) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2011-07-05 10:34:37 UTC (rev 3199) @@ -39,10 +39,9 @@ import org.chorem.lima.beans.BalanceTrialImpl; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.beans.ReportsDatasImpl; -import org.chorem.lima.beans.VatReports; -import org.chorem.lima.beans.VatReportsImpl; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ejbinterface.AccountService; import org.chorem.lima.business.ejbinterface.FinancialPeriodService; import org.chorem.lima.business.ejbinterface.ReportService; import org.chorem.lima.business.ejbinterface.ReportServiceLocal; @@ -71,6 +70,9 @@ @EJB protected FinancialPeriodService financialPeriodService; + @EJB + protected AccountService accountService; + public ReportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -546,105 +548,45 @@ return generateBalanceTrial(beginDate, endDate, selectedAccounts, true, movementedFilter); } + /** * Generate VAT * - * @return VatReports - * @throws TopiaException + * @param FiscalPeriod + * @throws LimaException, TopiaException */ @Override - public List<VatReports> generateVat(FiscalPeriod fiscalPeriod) throws LimaException { - - List<VatReports> vatReportsList = new ArrayList<VatReports>(); - - //gets the list of all the financialPeriods from the given fiscalPeriod - List<FinancialPeriod> financialPeriodsList = - financialPeriodService.getFinancialPeriods(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); - - //Sets variables used to save amount for the following period - BigDecimal payable = BigDecimal.ZERO; - BigDecimal remainingCredit = BigDecimal.ZERO; - - TopiaContext topiaTransaction = null; - try { - topiaTransaction = beginTransaction(); - - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); - //for each account, add the amount to the correct VatReports variable - - List<Account> accountsList = null; - - //Remove Spaces - String result = "445711,445712,445714,445715"; // TVA collectee - result = result.concat(",44562,445661,445662,445664,445665"); //TVA deductible - //build list account from selectedAccounts - accountsList = accountDAO.stringToListAccounts(result, false); - for (FinancialPeriod financialPeriod : financialPeriodsList) { - //Variable to save the vat total sum (collected - deductible) - BigDecimal vat = BigDecimal.ZERO; - //Sets VatReports variables to Zero - VatReports vatReports = new VatReportsImpl(); - vatReports.setPeriod(financialPeriod); - vatReports.setAmountCollected(BigDecimal.ZERO); - vatReports.setAmountDeductible(BigDecimal.ZERO); - vatReports.setAmountDue(BigDecimal.ZERO); - vatReports.setAmountCredit(BigDecimal.ZERO); - vatReports.setAmountRepayments(BigDecimal.ZERO); - vatReports.setAmountRemainingCredit(BigDecimal.ZERO); - //if remainingCredit is not nul then report it to the current period - if (!remainingCredit.equals(BigDecimal.ZERO)) { - vatReports.setAmountRemainingCredit(remainingCredit); - remainingCredit = BigDecimal.ZERO; - } - //if payable is not null then report it to the current period - vatReports.setAmountPayable(BigDecimal.ZERO); - if (!payable.equals(BigDecimal.ZERO)) { - vatReports.setAmountPayable(payable); - payable = BigDecimal.ZERO; - } - vatReports.setAmountPaid(BigDecimal.ZERO); - for (Account account : accountsList) { - ReportsDatas reportsDatas = - generateSubAccountBalanceWithTransaction(account, financialPeriod.getBeginDate(), - financialPeriod.getEndDate(), false, topiaTransaction); - //445711,445712,445714,445715 TVA collectee - if (("445711,445712,445714,445715").contains(account.getAccountNumber()) - && (reportsDatas.getAmountSolde() != null)) { - vatReports.setAmountCollected(vatReports.getAmountCollected().add(reportsDatas.getAmountSolde())); - vat = vat.add(reportsDatas.getAmountSolde()); + public List<Object> generateVat(FiscalPeriod fiscalPeriod) throws LimaException, TopiaException { + List<Object> list = new ArrayList<Object>(); + if (fiscalPeriod != null) { + TopiaContext topiaTransaction = null; + try { + topiaTransaction = beginTransaction(); + //lists all accounts + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); + List<Account> accountsList = null; + //gets all financial periods from the fiscal period + List<FinancialPeriod> financialPeriod = financialPeriodService.getFinancialPeriods( + fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + for (FinancialPeriod fp : financialPeriod) { + list.add(fp); + accountsList = accountDAO.findAll(); + for (Account account : accountsList) { + //VAT accounts start only with number 44 + if (account.getAccountNumber().startsWith("44")) { + list.add(generateBalanceTrial(fp.getBeginDate(), + fp.getEndDate(), account.getAccountNumber(), + true, false)); + } } - //44562,445661,445662,445664,445665TVA deductible - if (("44562,445661,445662,445664,445665").contains(account.getAccountNumber()) - && (reportsDatas.getAmountSolde() != null)) { - vatReports.setAmountDeductible(vatReports.getAmountDeductible().add(reportsDatas.getAmountSolde())); - vat = vat.add(reportsDatas.getAmountSolde().negate()); - } } - //if vat is positive it's a credit - if (vat.compareTo(BigDecimal.ZERO) < 0) { - vatReports.setAmountRemainingCredit(vat.abs()); - remainingCredit = vat.abs(); - } - //if vat is negative it's a debit - if (vat.compareTo(BigDecimal.ZERO) > 0) { - vatReports.setAmountDue(vat.abs()); - payable = vat.abs(); - } - if (vatReports != null) { - vatReportsList.add(vatReports); - } } - - //commitTransaction(topiaTransaction); + catch(LimaException eee) { + System.out.println(eee); + } } - catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); - } - finally { - doFinally(topiaTransaction, log); - } - return vatReportsList; + return list; } @@ -657,4 +599,16 @@ 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/ejbinterface/ReportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java 2011-07-04 16:06:26 UTC (rev 3198) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java 2011-07-05 10:34:37 UTC (rev 3199) @@ -31,12 +31,12 @@ import javax.ejb.Remote; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.ReportsDatas; -import org.chorem.lima.beans.VatReports; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FiscalPeriod; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; /** * Service de generation des rapports. @@ -104,6 +104,6 @@ /** * Generate VAT */ - List<VatReports> generateVat(FiscalPeriod fiscalPeriod) throws LimaException; + List<Object> generateVat(FiscalPeriod fiscalPeriod) throws LimaException, TopiaException; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java 2011-07-04 16:06:26 UTC (rev 3198) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTable.java 2011-07-05 10:34:37 UTC (rev 3199) @@ -3,11 +3,10 @@ import java.awt.Color; import java.awt.Component; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.VatReports; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; import org.jdesktop.swingx.JXTable; @@ -54,13 +53,12 @@ @Override public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { - VatReports vatReport = model.getElementAt(adapter.row); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM"); - int month = Integer.parseInt(simpleDateFormat.format( - vatReport.getPeriod().getBeginDate())); - // true if month is even - return ((month % 2)==0); - + Object object = model.getElementAt(adapter.row); + if (object instanceof FinancialPeriod) { + return true; + } else { + return false; + } } }; colorTransaction = Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java 2011-07-04 16:06:26 UTC (rev 3198) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatTableModel.java 2011-07-05 10:34:37 UTC (rev 3199) @@ -4,20 +4,27 @@ import java.text.SimpleDateFormat; import java.math.BigDecimal; -import java.util.Date; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.swing.table.AbstractTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.VatReports; +import org.chorem.lima.beans.BalanceTrial; +import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ReportServiceMonitorable; import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.business.utils.EntryComparator; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; +import org.nuiton.topia.TopiaException; public class VatTableModel extends AbstractTableModel implements ServiceListener { @@ -35,8 +42,7 @@ protected FiscalPeriod selectedFiscalPeriod; /** data cache */ - protected List<VatReports> cacheDataList; - protected VatReports vatReportsCache; + protected List<Object> cacheDataList; public VatTableModel() { @@ -45,12 +51,34 @@ ReportServiceMonitorable.class); } - protected List<VatReports> getDataList() { - List<VatReports> results = null; + protected List<Object> getDataList() throws TopiaException { + List<Object> finalresults = new ArrayList<Object>(); if (selectedFiscalPeriod != null) { try { - results = reportService.generateVat(selectedFiscalPeriod); + List<Object> results = reportService.generateVat(selectedFiscalPeriod); + + for (int index=0; index<results.size(); index++) { + if (results.get(index) instanceof BalanceTrial) { + if (((BalanceTrial)results.get(index)).getReportsDatas() != null){ + for (ReportsDatas reportsDatas : ((BalanceTrial)results.get(index)).getReportsDatas()) { + //reports datas + finalresults.add(reportsDatas); + List<Entry> entries = (List<Entry>) reportsDatas.getListEntry(); + if (entries != null){ + Collections.sort(entries, new EntryComparator()); + for (Entry entry : entries) { + //entry + finalresults.add(entry); + } + } + } + } + } else { + //financial period + finalresults.add(results.get(index)); + } + } } catch (LimaException eee) { if (log.isErrorEnabled()) { @@ -59,12 +87,18 @@ ErrorHelper.showErrorDialog("Can't get VAT list", eee); } } - - return results; + return finalresults; } public void refresh(){ - cacheDataList = getDataList(); + try { + cacheDataList = getDataList(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + ErrorHelper.showErrorDialog("Can't get VAT list", eee); + } fireTableDataChanged(); } @@ -75,11 +109,26 @@ switch (column) { case 0: - result = Date.class; + result = String.class; break; - default: + case 1: + result = Account.class; + break; + case 2: + result = String.class; + break; + case 3: + result = String.class; + break; + case 4: result = BigDecimal.class; break; + case 5: + result = BigDecimal.class; + break; + case 6: + result = BigDecimal.class; + break; } return result; @@ -94,26 +143,23 @@ result = _("lima.table.date"); //date break; case 1: - result = _("lima.table.collectedvat"); //tva collectee + result = "compte"; //tva collectee break; case 2: - result = _("lima.table.deductiblevat"); //tva deductible + result = "piece comptable"; //tva due break; case 3: - result = _("lima.table.vatdue"); //tva due + result = "description"; //credit de tva break; case 4: - result = _("lima.table.vatcredit"); //credit de tva + result = "debit"; //remboursemments break; case 5: - result = _("lima.table.repayments"); //remboursemments + result = "credit"; //credit restant break; case 6: - result = _("lima.table.remainingcredit"); //credit restant + result = "solde"; //tva a payer break; - case 7: - result = _("lima.table.vatpayable"); //tva a payer - break; } return result; @@ -132,55 +178,121 @@ @Override public int getColumnCount() { - return 8; + return 7; } - public VatReports getElementAt(int row){ - VatReports currentRow = (VatReports) cacheDataList.get(row); + public Object getElementAt(int row){ + Object currentRow = cacheDataList.get(row); return currentRow; } @Override public Object getValueAt(int row, int column) { Object result = null; - VatReports currentRow = (VatReports) cacheDataList.get(row); - //get entries for the period for the current row - - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); - - try { - switch (column) { + // just prevent too much result + if (cacheDataList != null) { + result = cacheDataList.get(row); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); + if (result instanceof FinancialPeriod) { + FinancialPeriod fp = (FinancialPeriod) result; + + switch (column) { case 0: - //result = currentRow.getDate(); //date - result = simpleDateFormat.format(currentRow.getPeriod().getBeginDate()) - + " - " + simpleDateFormat.format(currentRow.getPeriod().getEndDate()); + result = simpleDateFormat.format(fp.getBeginDate()) + + " - " + simpleDateFormat.format(fp.getEndDate()); break; case 1: - result = currentRow.getAmountCollected(); //tva collectee + result = null; break; case 2: - result = currentRow.getAmountDeductible(); //tva deductible + result = null; // voucher break; case 3: - result = currentRow.getAmountDue(); //tva due + result = null; // description break; case 4: - result = currentRow.getAmountCredit(); //credit de tva + result = null; // position break; case 5: - result = currentRow.getAmountRepayments(); //remboursemments + result = null; break; case 6: - result = currentRow.getAmountRemainingCredit(); //credit restant + result = null; break; - case 7: - result = currentRow.getAmountPayable(); //tva a payer + } + } + else if (result instanceof ReportsDatas) { + ReportsDatas currentRow = (ReportsDatas)result; + BigDecimal amountDebit = currentRow.getAmountDebit(); + BigDecimal amountCredit = currentRow.getAmountCredit(); + + switch (column) { + case 0: + result = null; // date break; + case 1: + if (currentRow.getAccount() != null){ + result = currentRow.getAccount().getAccountNumber() + + " - " + currentRow.getAccount().getLabel(); + } + else { + result = null; + } + break; + case 2: + result = null; // voucher + break; + case 3: + result = null; // description + break; + case 4: + result = amountDebit; // position + break; + case 5: + result = amountCredit; + break; + case 6: + result = amountDebit.subtract(amountCredit); + break; } + } + else if (result instanceof Entry) { + Entry currentRow = (Entry)result; + BigDecimal amountDebit = BigDecimal.ZERO, + amountCredit = BigDecimal.ZERO; + if (currentRow.getDebit()){ + amountDebit = currentRow.getAmount(); + } + else { + amountCredit = currentRow.getAmount(); + } + + switch (column) { + case 0: // date + result = simpleDateFormat. + format(currentRow.getFinancialTransaction().getTransactionDate()); + break; + case 1 : // account + result = null; + break; + case 2: // description + result = currentRow.getVoucher(); + break; + case 3: + result = currentRow.getDescription(); + break; + case 4: + result = amountDebit; + break; + case 5: + result = amountCredit; + break; + case 6: + result = amountDebit.subtract(amountCredit); + break; + } + } } - catch (Exception eee) { - log.debug("Can't get entries", eee); - } return result; }
participants (1)
-
vsalaun@users.chorem.org