r3166 - 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/resources/i18n
Author: vsalaun Date: 2011-06-09 17:30:11 +0200 (Thu, 09 Jun 2011) New Revision: 3166 Url: http://chorem.org/repositories/revision/lima/3166 Log: #347 add VAT service 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/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 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-06-09 14:05:37 UTC (rev 3165) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2011-06-09 15:30:11 UTC (rev 3166) @@ -29,6 +29,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; + +import javax.ejb.EJB; import javax.ejb.Stateless; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -37,8 +39,11 @@ 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.FinancialPeriodService; import org.chorem.lima.business.ejbinterface.ReportService; import org.chorem.lima.business.ejbinterface.ReportServiceLocal; import org.chorem.lima.entity.Account; @@ -46,7 +51,9 @@ import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; @@ -61,6 +68,9 @@ private TopiaContext rootContext; + @EJB + protected FinancialPeriodService financialPeriodService; + public ReportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -536,7 +546,108 @@ return generateBalanceTrial(beginDate, endDate, selectedAccounts, true, movementedFilter); } + /** + * Generate VAT + * + * @return VatReports + * @throws 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()); + } + //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 (TopiaException ex) { + doCatch(topiaTransaction, ex, log); + } + finally { + doFinally(topiaTransaction, log); + } + return vatReportsList; + } + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database // TODO move it into JTA 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-06-09 14:05:37 UTC (rev 3165) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ReportService.java 2011-06-09 15:30:11 UTC (rev 3166) @@ -26,12 +26,16 @@ package org.chorem.lima.business.ejbinterface; import java.util.Date; +import java.util.List; + 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; /** * Service de generation des rapports. @@ -86,5 +90,10 @@ * Generation du rapports des journaux */ ReportsDatas generateEntryBooksReports(EntryBook entryBook, Date beginDate, Date endDate) throws LimaException; + + /** + * Generate VAT + */ + List<VatReports> generateVat(FiscalPeriod fiscalPeriod) throws LimaException; } Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-06-09 14:05:37 UTC (rev 3165) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-06-09 15:30:11 UTC (rev 3166) @@ -203,6 +203,7 @@ lima.reports.entrybooks=Edit entrybook lima.reports.financialstatement=Financialstatements lima.reports.ledger=Ledger +lima.reports.vat=Edit VAT lima.response.no=No lima.response.yes=Yes lima.splash.1=Loading services... @@ -214,8 +215,8 @@ lima.table.balance=Balance lima.table.closure=Closed lima.table.code=Code +lima.table.collectedvat=Collected VAT lima.table.credit=Credit -lima.table.collectedvat=Collected VAT lima.table.date=Date lima.table.debit=Debit lima.table.debitcredit=Debit and credit Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-06-09 14:05:37 UTC (rev 3165) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-06-09 15:30:11 UTC (rev 3166) @@ -203,6 +203,7 @@ lima.reports.entrybooks=Edition journal lima.reports.financialstatement=Bilan et Compte de r\u00E9sultat lima.reports.ledger=Grand Livre +lima.reports.vat=Edition TVA lima.response.no=Non lima.response.yes=Oui lima.splash.1=Chargement des services... @@ -240,7 +241,7 @@ lima.table.vatcredit=Cr\u00E9dit de TVA lima.table.vatdue=TVA due lima.table.vatpaid=TVA pay\u00E9e -lima.table.vatpayable=TVA \u00e0 payer +lima.table.vatpayable=TVA \u00E0 payer lima.table.voucher=Pi\u00E8ce comptable lima.title=Lutin Invoice Monitoring and Accounting lima.title.about=\u00C0 propos de Lima...
participants (1)
-
vsalaun@users.chorem.org