r2992 - in trunk: lima-business/src/main/java/org/chorem/lima/business/accountingrules lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/ejbinterface lima-business/src/main/resources/i18n lima-callao/src/main/java/org/chorem/lima/entity lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/balance lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports lima-swing/src/main/java/org/chorem/lima/ui/financialstatemen
Author: jpepin Date: 2010-08-02 18:54:10 +0200 (Mon, 02 Aug 2010) New Revision: 2992 Url: http://chorem.org/repositories/revision/lima/2992 Log: Sortie document pdf balance et journaux. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -173,7 +173,7 @@ for (EntryBook entryBook : entryBooks) { ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( entryBook, financialPeriod); if(closedPeriodicEntryBook.getLocked()){ closedEntryBooks.add(entryBook); @@ -237,7 +237,7 @@ //second case ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( entryOld.getFinancialTransaction().getEntryBook(), financialPeriod); if (closedPeriodicEntryBook.getLocked()){ throw new LimaBusinessException("2 - Can't update entry : financialperiod of this entrybook is closed"); @@ -245,7 +245,7 @@ //third case ClosedPeriodicEntryBook closedPeriodicEntryBook2 = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( entry.getFinancialTransaction().getEntryBook(), financialPeriod); // Check 2 & 3 cases @@ -293,7 +293,7 @@ //3. the actual entrybook belong to a blocked closedPeriodicEntryBook ClosedPeriodicEntryBook closedPeriodicEntryBookOld = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( financialTransactionOld.getEntryBook(), financialPeriod); if (closedPeriodicEntryBookOld.getLocked()){ throw new LimaBusinessException("Can't update financialtransaction : financialperiod of this entrybook is closed"); @@ -301,7 +301,7 @@ //4. the new entrybook belong to a blocked closedPeriodicEntryBook ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( financialTransaction.getEntryBook(), financialPeriod); if (closedPeriodicEntryBook.getLocked()){ throw new LimaBusinessException("Can't update financialtransaction : financialperiod of new entrybook is closed"); @@ -309,7 +309,7 @@ //5. the actual entrybook belong to a blocked closedPeriodicEntryBook ClosedPeriodicEntryBook closedPeriodicEntryBookOld2 = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( financialTransactionOld.getEntryBook(), financialPeriodOld); if (closedPeriodicEntryBookOld2.getLocked()){ throw new LimaBusinessException("Can't update financialtransaction : the new financialperiod of this entrybook is closed"); @@ -317,7 +317,7 @@ //6. the new entrybook belong to a blocked closedPeriodicEntryBook ClosedPeriodicEntryBook closedPeriodicEntryBook2 = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod( + closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod( financialTransaction.getEntryBook(), financialPeriodOld); if (closedPeriodicEntryBook2.getLocked()){ throw new LimaBusinessException("Can't update financialtransaction : this financialperiod of new entrybook is closed"); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -31,21 +31,33 @@ import javax.ejb.Stateless; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.FinancialStatementAmounts; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ejbinterface.DocumentService; import org.chorem.lima.business.ejbinterface.DocumentServiceLocal; +import org.chorem.lima.business.ejbinterface.EntryBookService; +import org.chorem.lima.business.ejbinterface.FinancialStatementService; import org.chorem.lima.business.ejbinterface.IdentityService; +import org.chorem.lima.business.ejbinterface.ReportService; import org.chorem.lima.entity.Account; +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.EntryDAO; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Identity; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; + import com.lowagie.text.BadElementException; import com.lowagie.text.Cell; import com.lowagie.text.Chapter; @@ -73,6 +85,15 @@ @EJB IdentityService identityService; + @EJB + EntryBookService entryBookService; + + @EJB + FinancialStatementService financialStatementService; + + @EJB + ReportService reportService; + //SDFs private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); @@ -80,6 +101,8 @@ new SimpleDateFormat("HH:mm"); private static SimpleDateFormat filedateFormat = new SimpleDateFormat("dd-MM-yyyy_HH-mm"); + private static SimpleDateFormat monthYearFormat = + new SimpleDateFormat("MMM yyyy"); //FONTs private static Font titleFont = @@ -158,14 +181,16 @@ return t; } - + //############## FinancialStatements ############## @Override - public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts, Date beginDate, Date endDate) throws LimaException { + public void createFinancialStatementsDocuments(Date beginDate, Date endDate) throws LimaException { Document document = new Document(PageSize.A4, 8, 8, 8, 8); + List<FinancialStatementAmounts> financialStatementAmounts = financialStatementService.financialStatementReport(beginDate, endDate); + try { Date newDate = new Date(); String dateS = dateFormat.format(newDate); @@ -383,8 +408,7 @@ @Override - public void createLedgerDocuments(List<Object> list, Date beginDate, - Date endDate) throws LimaException { + public void createLedgerDocuments(List<Object> list, Date beginDate, Date endDate) throws LimaException { Document document = new Document(PageSize.A4, 8, 8, 8, 8); try { @@ -472,13 +496,13 @@ //forward amounts if (n>max && i<=n-max){ Paragraph forwardParagraph = new Paragraph(); - forwardParagraph.add(createLedgerAmountTable("", _("", "lima-business.document.carryforward"), currentAmountDebit, currentAmountCredit)); + forwardParagraph.add(createLedgerAmountTable("", _("lima-business.document.carryforward"), currentAmountDebit, currentAmountCredit)); chapter.add(forwardParagraph); } //final amounts if (i>=n-max){ Paragraph finalAmountParagraph = new Paragraph(); - finalAmountParagraph.add(createLedgerAmountTable("", _("lima-business.document.amount"), currentAmountDebit, currentAmountCredit)); + finalAmountParagraph.add(createLedgerAmountTable("", _("lima-business.document.amounts"), currentAmountDebit, currentAmountCredit)); chapter.add(finalAmountParagraph); } //add page @@ -524,37 +548,6 @@ } - public Table createLedgerAmountTable(String account, String title, Double credit, Double debit){ - Table t = null; - try { - t = new Table(5,1); - float[] widths = {0.4f,0.15f, 0.15f, 0.15f, 0.15f}; - t.setWidths(widths); - t.setWidth(100f); - t.setPadding(3f); - t.setOffset(0); - //defaut cell - Cell cell = new Cell(); - cell.setBorder(Rectangle.RIGHT); - cell.setHorizontalAlignment(Element.ALIGN_RIGHT); - t.setDefaultCell(cell); - - Cell accountCell = new Cell(new Phrase(account, boldFont)); - accountCell.setHorizontalAlignment(Element.ALIGN_LEFT); - accountCell.setBorder(Rectangle.NO_BORDER); - t.addCell(accountCell); - t.addCell(new Phrase(title, boldFont)); - t.addCell(new Phrase(debit.toString(), boldFont)); - t.addCell(new Phrase(credit.toString(), boldFont)); - Double solde = debit-credit; - t.addCell(new Phrase(solde.toString(), boldFont)); - } catch (BadElementException eeBEE) { - log.error("Can't create table", eeBEE); - } - return t; - - } - public Table createLedgerTable(List<Object> subList){ int nbrow = subList.size(); Table t = null; @@ -623,7 +616,456 @@ return t; } - protected TopiaContext beginTransaction() throws TopiaException { + public Table createLedgerAmountTable(String account, String title, Double credit, Double debit){ + Table t = null; + try { + t = new Table(5,1); + float[] widths = {0.4f,0.15f, 0.15f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setWidth(100f); + t.setPadding(3f); + t.setOffset(0); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.RIGHT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.setDefaultCell(cell); + + Cell accountCell = new Cell(new Phrase(account, boldFont)); + accountCell.setHorizontalAlignment(Element.ALIGN_LEFT); + accountCell.setBorder(Rectangle.NO_BORDER); + t.addCell(accountCell); + t.addCell(new Phrase(title, boldFont)); + t.addCell(new Phrase(debit.toString(), boldFont)); + t.addCell(new Phrase(credit.toString(), boldFont)); + Double solde = debit-credit; + t.addCell(new Phrase(solde.toString(), boldFont)); + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + } + + //############## EntryBooks ############## + + + + @Override + public void createEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException { + Document document = new Document(PageSize.A4, 8, 8, 8, 8); + TopiaContext transaction = null; + + try { + transaction = beginTransaction(); + + Date newDate = new Date(); + String dateS = dateFormat.format(newDate); + String hourS = hourFormat.format(newDate); + String fileDateS = filedateFormat.format(newDate); + + PdfWriter pdfWriter = PdfWriter.getInstance(document, + new FileOutputStream("/lima_ebs"+fileDateS+".pdf")); + HtmlWriter htmlWriter = HtmlWriter.getInstance(document, + new FileOutputStream("/lima_ebs"+fileDateS+".html")); + document.open(); + int nbpages = 1; + + Identity identity = identityService.getIdentity(); + + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + //Split list by financialstatement type + List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = closedPeriodicEntryBookDAO.findAllByDates(beginDate, endDate); + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { + + TopiaQuery query = entryDAO.createQuery(); + String financialPeriodProperty = TopiaQuery.getProperty(Entry.FINANCIAL_TRANSACTION, FinancialTransaction.FINANCIAL_PERIOD); + String entryBookProperty = TopiaQuery.getProperty(Entry.FINANCIAL_TRANSACTION, FinancialTransaction.ENTRY_BOOK); + query.addWhere(financialPeriodProperty, Op.EQ, closedPeriodicEntryBook.getFinancialPeriod()) + .addWhere(entryBookProperty, Op.EQ, closedPeriodicEntryBook.getEntryBook()); + + List<Entry> entries = entryDAO.findAllByQuery(query); + + List<Object[]> results = new ArrayList<Object[]>(); + Double debit = 0.0; + Double credit = 0.0; + query.setSelect(Entry.DEBIT, "SUM("+Entry.AMOUNT+")"); + query.addGroup(Entry.DEBIT); + results = query.execute(transaction); + int nbAmount = results.size(); + if(nbAmount==2){ + debit = (Double)results.get(0)[1]; + credit = (Double)results.get(1)[1]; + } + if (nbAmount==1){ + if ((Boolean)results.get(0)[0]){ + debit = (Double)results.get(0)[1]; + } + else { + credit = (Double)results.get(0)[1]; + } + } + + //create pages + String title = closedPeriodicEntryBook.getEntryBook().getLabel() + "\n" + monthYearFormat.format(closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); + //list = list.subList(1, list.size()); + int i=0; + int n=entries.size(); + int max=35; + while (i<n){ + int j=i+max; + if (j>n){ + j = n; + } + List <Entry> subEntries = + entries.subList(i, j); + //create page : header + table + footer + Table headerPage = createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate)); + Table headerTable = createEntryBooksHeaderTable(); + Table table = createEntryBooksTable(subEntries); + //new page + Chapter chapter = new Chapter(0); + //headerPage + Paragraph paragraphHeaderPage = new Paragraph(); + paragraphHeaderPage.add(headerPage); + chapter.add(paragraphHeaderPage); + //n° page + Paragraph paragraphPage = new Paragraph(); + Table infos = new Table(2); + infos.setWidth(100f); + infos.setBorder(Rectangle.NO_BORDER); + infos.setOffset(2); + Cell c = new Cell(); + c.setBorder(Rectangle.NO_BORDER); + c.setHorizontalAlignment(Element.ALIGN_CENTER); + infos.setDefaultCell(c); + infos.addCell(new Phrase(_("lima-business.document.createdate1") + dateS + _("lima-business.document.createdate2") + hourS, normalFont)); + infos.addCell(new Phrase(_("lima-business.document.pagenumber")+nbpages, normalFont)); + paragraphPage.add(infos); + chapter.add(paragraphPage); + //headerTable + Paragraph paragraphHeaderTable = new Paragraph(); + paragraphHeaderTable.add(headerTable); + chapter.add(paragraphHeaderTable); + //table + Paragraph paragraphTable = new Paragraph(); + paragraphTable.add(table); + chapter.add(paragraphTable); + //final amounts + if (i>=n-max){ + Paragraph finalAmountParagraph = new Paragraph(); + finalAmountParagraph.add(createEntryBooksAmountTable(_("lima-business.document.amounts"), debit, credit)); + chapter.add(finalAmountParagraph); + } + //add page + document.add(chapter); + i=i+max; + nbpages++; + } + } + + document.close(); + + } catch (FileNotFoundException eeFNFE) { + log.error("Can't create pdf file", eeFNFE); + } catch (DocumentException eeDE) { + log.error("Can't create document", eeDE); + } catch (TopiaException eeTE) { + log.error("Can't get entries", eeTE); + + } + + } + + public Table createEntryBooksHeaderTable(){ + Table t = null; + try { + t = new Table(6,1); + float[] widths = {0.1f, 0.1f, 0.1f, 0.4f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setWidth(100f); + t.setPadding(3f); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.LEFT); + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + t.setDefaultCell(cell); + t.setOffset(8); + t.addCell(new Phrase(_("lima-business.document.date"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.accountnumber"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.voucher"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.description"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.debit"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.credit"), boldFont)); + + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + + } + + public Table createEntryBooksTable(List<Entry> entries){ + int nbrow = entries.size(); + Table t = null; + try { + //define table + t = new Table(6,nbrow); + t.setWidth(100f); + float[] widths = {0.1f, 0.1f, 0.1f, 0.4f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setPadding(1.5f); + t.setBorderWidth(1); + t.setOffset(0); + //define default cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.LEFT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.setDefaultCell(cell); + + for (Entry entry : entries) { + t.addCell(new Phrase(dateFormat.format(entry.getFinancialTransaction().getTransactionDate()), normalFont)); + t.addCell(new Phrase(entry.getAccount().getAccountNumber(), normalFont)); + t.addCell(new Phrase(entry.getVoucher(), normalFont)); + t.addCell(new Phrase(entry.getDescription(), normalFont)); + t.addCell(new Phrase(String.valueOf(entry.getDebit() ? entry.getAmount() : 0), normalFont)); + t.addCell(new Phrase(String.valueOf(entry.getDebit() ? entry.getAmount() : 0), normalFont)); + } + + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + } + + public Table createEntryBooksAmountTable(String title, Double credit, Double debit){ + Table t = null; + try { + t = new Table(3,1); + float[] widths = {0.7f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setWidth(100f); + t.setPadding(3f); + t.setOffset(0); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.RIGHT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.setDefaultCell(cell); + + t.addCell(new Phrase(title, boldFont)); + t.addCell(new Phrase(debit.toString(), boldFont)); + t.addCell(new Phrase(credit.toString(), boldFont)); + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + } + + //############## Balance ############## + + @Override + public void createBalanceDocuments(Date beginDate, Date endDate) throws LimaException { + Document document = new Document(PageSize.A4, 8, 8, 8, 8); + + BalanceTrial balanceTrial = + reportService.generateBalanceTrial(beginDate, endDate, null, false, false); + + List<ReportsDatas> list = (List<ReportsDatas>) balanceTrial.getReportsDatas(); + + try { + Date newDate = new Date(); + String dateS = dateFormat.format(newDate); + String hourS = hourFormat.format(newDate); + String fileDateS = filedateFormat.format(newDate); + + Double currentAmountDebit = 0.0; + Double currentAmountCredit = 0.0; + Double currentSoldeDebit = 0.0; + Double currentSoldeCredit = 0.0; + + PdfWriter pdfWriter = PdfWriter.getInstance(document, + new FileOutputStream("/balance_lima"+fileDateS+".pdf")); + HtmlWriter htmlWriter = HtmlWriter.getInstance(document, + new FileOutputStream("/balance_lima"+fileDateS+".html")); + document.open(); + int nbpages = 1; + Identity identity = identityService.getIdentity(); + + //create pages + String title = _("lima-business.document.balance"); + int i=0; + int n=list.size(); + int max = 26; + while (i<n){ + int j = i+max; + if (j>n){ + j = n; + } + List <ReportsDatas> subList = list.subList(i, j); + //create page : header + table + footer + Table headerPage = createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate)); + Table headerTable = createBalanceHeaderTable(); + //new page + Chapter chapter = new Chapter(0); + //headerPage + Paragraph paragraphHeaderPage = new Paragraph(); + paragraphHeaderPage.add(headerPage); + chapter.add(paragraphHeaderPage); + //n° page + Paragraph paragraphPage = new Paragraph(); + Table infos = new Table(2); + infos.setWidth(100f); + infos.setBorder(Rectangle.NO_BORDER); + infos.setOffset(2); + Cell c = new Cell(); + c.setBorder(Rectangle.NO_BORDER); + c.setHorizontalAlignment(Element.ALIGN_CENTER); + infos.setDefaultCell(c); + infos.addCell(new Phrase(_("lima-business.document.createdate1") + dateS + _("lima-business.document.createdate2") + hourS, normalFont)); + infos.addCell(new Phrase(_("lima-business.document.pagenumber") + nbpages, normalFont)); + paragraphPage.add(infos); + chapter.add(paragraphPage); + //headerTable + Paragraph paragraphHeaderTable = new Paragraph(); + paragraphHeaderTable.add(headerTable); + chapter.add(paragraphHeaderTable); + //backward amounts + if (n>max && nbpages>1){ + Paragraph backwardParagraph = new Paragraph(); + backwardParagraph.add(createBalanceAmountTable(_("lima-business.document.carryback"), currentAmountDebit, currentAmountCredit, currentSoldeDebit, currentSoldeCredit)); + chapter.add(backwardParagraph); + } + //table + Paragraph paragraphTable = new Paragraph(); + Table table = createBalanceTable(subList); + paragraphTable.add(table); + chapter.add(paragraphTable); + for (ReportsDatas reportsDatas : subList){ + currentAmountDebit += reportsDatas.getAmountDebit(); + currentAmountCredit += reportsDatas.getAmountCredit(); + currentSoldeDebit += reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0; + currentSoldeCredit += reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde(); + } + //forward amounts + if (n>max && i<=n-max){ + Paragraph forwardParagraph = new Paragraph(); + forwardParagraph.add(createBalanceAmountTable(_("lima-business.document.carryforward"), currentAmountDebit, currentAmountCredit, currentSoldeDebit, currentSoldeCredit)); + chapter.add(forwardParagraph); + } + //final amounts + if (i>=n-max){ + Paragraph finalAmountParagraph = new Paragraph(); + finalAmountParagraph.add(createBalanceAmountTable(_("lima-business.document.amounts"), currentAmountDebit, currentAmountCredit, currentSoldeDebit, currentSoldeCredit)); + chapter.add(finalAmountParagraph); + } + //add page + document.add(chapter); + i=i+max; + nbpages++; + } + document.close(); + + } catch (FileNotFoundException eeFNFE) { + log.error("Can't create pdf file", eeFNFE); + } catch (DocumentException eeDE) { + log.error("Can't create document", eeDE); + } + } + + public Table createBalanceHeaderTable(){ + Table t = null; + try { + t = new Table(6,1); + float[] widths = {0.07f, 0.33f, 0.15f, 0.15f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setWidth(100f); + t.setPadding(3.5f); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.LEFT); + cell.setHorizontalAlignment(Element.ALIGN_CENTER); + t.setDefaultCell(cell); + t.setOffset(8); + t.addCell(new Phrase(_("lima-business.document.accountnumber"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.description"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.movementdebit"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.movementcredit"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.soldedebit"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.soldecredit"), boldFont)); + + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + + } + + public Table createBalanceTable(List<ReportsDatas> subList){ + int nbrow = subList.size(); + Table t = null; + try { + //define table + t = new Table(6, nbrow); + t.setWidth(100f); + float[] widths = {0.07f, 0.33f, 0.15f, 0.15f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setPadding(1.5f); + t.setBorderWidth(1); + t.setOffset(0); + //define default cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.LEFT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.setDefaultCell(cell); + + for (ReportsDatas reportsDatas : subList) { + + String soldeDebit = String.valueOf(reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0); + String soldeCredit = String.valueOf(reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde()); + + t.addCell(new Phrase(reportsDatas.getAccount().getAccountNumber(), normalFont)); + t.addCell(new Phrase(reportsDatas.getAccount().getLabel(), normalFont)); + t.addCell(new Phrase(String.valueOf(reportsDatas.getAmountDebit()), normalFont)); + t.addCell(new Phrase(String.valueOf(reportsDatas.getAmountCredit()), normalFont)); + t.addCell(new Phrase(soldeDebit, normalFont)); + t.addCell(new Phrase(soldeCredit, normalFont)); + } + } catch (DocumentException eeDE) { + log.error("Can't create table", eeDE); + + } + return t; + } + + public Table createBalanceAmountTable(String title, Double amountDebit, Double amountCredit, Double soldeDebit, Double soldeCredit ){ + Table t = null; + try { + t = new Table(5,1); + float[] widths = {0.4f,0.15f, 0.15f, 0.15f, 0.15f}; + t.setWidths(widths); + t.setWidth(100f); + t.setPadding(3f); + t.setOffset(0); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.RIGHT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.setDefaultCell(cell); + + t.addCell(new Phrase(title, boldFont)); + t.addCell(new Phrase(amountDebit.toString(), boldFont)); + t.addCell(new Phrase(amountCredit.toString(), boldFont)); + t.addCell(new Phrase(soldeDebit.toString(), boldFont)); + t.addCell(new Phrase(soldeCredit.toString(), boldFont)); + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + } + + + protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database // TODO move it into JTA TopiaContext topiaTransaction; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -225,7 +225,7 @@ ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); - closedPeriodicEntryBook = closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod(entryBook, financialPeriod); + closedPeriodicEntryBook = closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod(entryBook, financialPeriod); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -1026,7 +1026,7 @@ .getCodeEntryBook(); EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDAO - .findbyEntryBookAndFinancialPeriod(entryBook, + .findByEntryBookAndFinancialPeriod(entryBook, financialPeriod); try { financialPeriodService 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 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -175,7 +175,7 @@ String queryAlias = "E"; if (beginDate != null && endDate != null){ try { - EntryDAO entryDAO= LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); TopiaQuery entriesQuery = createEntryQuery(account, beginDate, endDate, entryDAO, queryAlias); //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -21,10 +21,7 @@ import java.util.Date; import java.util.List; - import javax.ejb.Remote; - -import org.chorem.lima.beans.FinancialStatementAmounts; import org.chorem.lima.business.LimaException; /** @@ -36,6 +33,8 @@ @Remote public interface DocumentService { - public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts, Date beginDate, Date endDate) throws LimaException; + public void createFinancialStatementsDocuments(Date beginDate, Date endDate) throws LimaException; public void createLedgerDocuments(List<Object> objects, Date beginDate, Date endDate) throws LimaException; + public void createEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException; + public void createBalanceDocuments(Date beginDate, Date endDate) throws LimaException; } Modified: trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties 2010-08-02 16:54:10 UTC (rev 2992) @@ -3,7 +3,11 @@ An\ financialStatement\ already\ exists\ with\ this\ label\ \:\ %s= lima-business.config.configFileName.description= lima-business.config.rulesnationality= +lima-business.document.accountnubmer= +lima-business.document.accountnumber= lima-business.document.amount=Amout +lima-business.document.amounts= +lima-business.document.balance= lima-business.document.businessnumber= lima-business.document.carryback=Carry Back lima-business.document.carryforward=reporter\u00C0 @@ -19,12 +23,16 @@ lima-business.document.grossamount=Gross Amount lima-business.document.label=Label lima-business.document.ledger= +lima-business.document.movementcredit= +lima-business.document.movementdebit= lima-business.document.netamount=Net Amount lima-business.document.pagenumber= lima-business.document.period1= lima-business.document.period2= lima-business.document.provisiondeprecationamount=Provision Deprecation Amount lima-business.document.solde=Solde +lima-business.document.soldecredit= +lima-business.document.soldedebit= lima-business.document.vatnumber= lima-business.document.voucher=Voucher lima.business.document.date=Date Modified: trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties 2010-08-02 16:54:10 UTC (rev 2992) @@ -1,7 +1,9 @@ An\ EntryBook\ already\ exists\ with\ this\ label\ \:\ %s= An\ account\ already\ exists\ with\ this\ number\ \:\ %s= An\ financialStatement\ already\ exists\ with\ this\ label\ \:\ %s= -lima-business.document.amount=Total +lima-business.document.accountnumber=N\u00B0 Compte +lima-business.document.amounts=Totaux +lima-business.document.balance=Balance lima-business.document.businessnumber=N\u00B0 Siret lima-business.document.carryback=Report lima-business.document.carryforward=\u00C0 reporter @@ -16,12 +18,16 @@ lima-business.document.grossamount=Brut lima-business.document.label=Libell\u00E9 lima-business.document.ledger=Grand Livre +lima-business.document.movementcredit=Mouvement Cr\u00E9diteur +lima-business.document.movementdebit=Mouvement D\u00E9biteur lima-business.document.netamount=Net lima-business.document.pagenumber=N\u00B0 page lima-business.document.period1=P\u00E9riode du lima-business.document.period2=au lima-business.document.provisiondeprecationamount=Amortissements et provisions lima-business.document.solde=Solde +lima-business.document.soldecredit=Solde Cr\u00E9diteur +lima-business.document.soldedebit=Solde D\u00E9biteur lima-business.document.vatnumber=N\u00B0 TVA lima-business.document.voucher=Pi\u00E8ce comptable lima.config.configFileName.description= Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/ClosedPeriodicEntryBookDAOImpl.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -1,19 +1,28 @@ package org.chorem.lima.entity; +import java.util.Date; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.ClosedPeriodicEntryBookDAOAbstract; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; +import org.nuiton.topia.framework.TopiaQuery.Op; public class ClosedPeriodicEntryBookDAOImpl <E extends ClosedPeriodicEntryBook> extends ClosedPeriodicEntryBookDAOAbstract<E>{ + private static final Log log = LogFactory.getLog(ClosedPeriodicEntryBookDAOImpl.class); + + /** * Return ClosedPeriodicEntryBook by EntryBook and FinancialPeriod */ @Override - public ClosedPeriodicEntryBook findbyEntryBookAndFinancialPeriod( + public ClosedPeriodicEntryBook findByEntryBookAndFinancialPeriod( EntryBook entryBook, FinancialPeriod financialPeriod) throws TopiaException { @@ -27,4 +36,19 @@ return findByQuery(query); } + @Override + public List<ClosedPeriodicEntryBook> findAllByDates(Date beginDate, + Date endDate) throws TopiaException { + TopiaQuery query = createQuery(); + if (beginDate != null && endDate != null){ + String beginDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, FinancialPeriod.BEGIN_DATE); + String endDateProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.FINANCIAL_PERIOD, FinancialPeriod.BEGIN_DATE); + String entrybookProperty = TopiaQuery.getProperty(ClosedPeriodicEntryBook.ENTRY_BOOK, EntryBook.CODE); + query.addWhere(beginDateProperty, Op.GE, beginDate) + .addWhere(endDateProperty, Op.LE, endDate) + .addOrder(beginDateProperty, entrybookProperty); + } + return (List<ClosedPeriodicEntryBook>) findAllByQuery(query); + } + } Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2010-08-02 16:54:10 UTC (rev 2992) @@ -74,9 +74,12 @@ <JCheckBox id='movmentedFilter' text='lima.accountsreports.movmentedfilter' selected='false' onActionPerformed="getHandler().refresh()"/> </cell> + <cell> + <JButton text="lima.createPDF" onActionPerformed="getHandler().createPdf()"/> + </cell> </row> <row> - <cell fill="both" weightx="1" weighty="1" columns="7"> + <cell fill="both" weightx="1" weighty="1" columns="8"> <JScrollPane> <org.jdesktop.swingx.JXTable id="balanceTable" rowHeight="24" model="{getModelBalanceTable()}" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.BalanceTrial; +import org.chorem.lima.business.DocumentServiceMonitorable; import org.chorem.lima.business.FinancialTransactionServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaException; @@ -45,6 +46,7 @@ /** Services. */ protected ReportServiceMonitorable reportService; + protected DocumentServiceMonitorable documentService; /** DatePicker Begin Date. */ protected Date selectedBeginDate; @@ -63,6 +65,9 @@ reportService = LimaServiceFactory.getInstance().getService( ReportServiceMonitorable.class); + documentService = + LimaServiceFactory.getInstance().getService( + DocumentServiceMonitorable.class); LimaServiceFactory.getInstance().getService( ImportServiceMonitorable.class).addListener(this); LimaServiceFactory.getInstance().getService( @@ -136,6 +141,16 @@ } } + public void createPdf() { + try { + documentService.createBalanceDocuments(selectedBeginDate, selectedEndDate); + } catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't create PDF", eee); + } + } + } + @Override public void notifyMethod(String serviceName, String methodeName) { if (serviceName.contains("FinancialTransaction") || methodeName.contains("importAccount") || methodeName.contains("importAll")){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2010-08-02 16:54:10 UTC (rev 2992) @@ -74,9 +74,12 @@ editable="false" /> </cell> + <cell> + <JButton text="lima.createPDF" onActionPerformed="getHandler().createPdf()"/> + </cell> </row> <row> - <cell fill="both" weightx="1" weighty="1" columns="6"> + <cell fill="both" weightx="1" weighty="1" columns="7"> <JScrollPane> <org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTable id="table" sortable="false" rowHeight="24" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.beans.ReportsDatasImpl; +import org.chorem.lima.business.DocumentServiceMonitorable; import org.chorem.lima.business.FinancialTransactionServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaException; @@ -56,6 +57,7 @@ /** Services. */ protected ReportServiceMonitorable reportService; + protected DocumentServiceMonitorable documentService; /** Account. */ protected EntryBook selectedEntryBook; @@ -72,6 +74,9 @@ reportService = LimaServiceFactory.getInstance().getService( ReportServiceMonitorable.class); + documentService = + LimaServiceFactory.getInstance().getService( + DocumentServiceMonitorable.class); LimaServiceFactory.getInstance().getService( ImportServiceMonitorable.class).addListener(this); LimaServiceFactory.getInstance().getService( @@ -143,6 +148,16 @@ } } + public void createPdf() { + try { + documentService.createEntryBooksDocuments(selectedBeginDate, selectedEndDate); + } catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't create PDF", eee); + } + } + } + @Override public void notifyMethod(String serviceName, String methodeName) { if (serviceName.contains("FinancialTransaction") || methodeName.contains("importEntryBook") || methodeName.contains("importAll")){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2010-08-02 13:02:10 UTC (rev 2991) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2010-08-02 16:54:10 UTC (rev 2992) @@ -210,7 +210,7 @@ public void createDocuments(){ try { - documentService.createFinancialStatementsDocuments(cacheDataList, selectedBeginDate, selectedEndDate); + documentService.createFinancialStatementsDocuments(selectedBeginDate, selectedEndDate); } catch (LimaException e) { if (log.isDebugEnabled()){ log.debug("Error on create document",e);
participants (1)
-
jpepin@users.chorem.org