Author: echatellier Date: 2012-06-06 17:32:14 +0200 (Wed, 06 Jun 2012) New Revision: 3451 Url: http://chorem.org/repositories/revision/lima/3451 Log: Correction des 3 trois tableaux diff?\195?\169rents qui causait un probl?\195?\168me d'alignement des colonnes. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 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 2012-06-06 14:08:42 UTC (rev 3450) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-06-06 15:32:14 UTC (rev 3451) @@ -75,6 +75,7 @@ import com.lowagie.text.BadElementException; import com.lowagie.text.Cell; import com.lowagie.text.Chapter; +import com.lowagie.text.DocWriter; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; @@ -728,12 +729,13 @@ String filePath = path + File.separator + DocumentsEnum.ENTRYBOOKS.getFileName(); FileOutputStream fileOut = new FileOutputStream(filePath + format.getExtension()); + DocWriter writer = null; switch (format) { case HTML: - HtmlWriter htmlWriter = HtmlWriter.getInstance(document, fileOut); + writer = HtmlWriter.getInstance(document, fileOut); break; case PDF: - PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOut); + writer = PdfWriter.getInstance(document, fileOut); break; } document.open(); @@ -758,8 +760,8 @@ List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); - BigDecimal debit = null; - BigDecimal credit = null; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal credit = BigDecimal.ZERO; int nbAmount = results.size(); if (nbAmount == 2) { debit = (BigDecimal) results.get(0)[1]; @@ -792,9 +794,8 @@ } List<Entry> subEntries = entries.subList(i, j); - //create page : header + table + footer - Table headerTable = createEntryBooksHeaderTable(); - Table table = createEntryBooksTable(subEntries); + //create page + Table table = createEntryBooksTable(subEntries, debit, credit); //new page Chapter chapter = new Chapter(0); //headerPage @@ -802,21 +803,10 @@ beginDate, endDate)); //n° page chapter.add(createNumberPage(nbpages, newDate)); - //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; @@ -825,52 +815,45 @@ } document.close(); - + writer.close(); } catch (Exception ex) { throw new LimaException("Can't create document", ex); } } - - protected 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; - - } - - protected Table createEntryBooksTable(List<Entry> entries) { + + protected Table createEntryBooksTable(List<Entry> entries, BigDecimal debit, BigDecimal credit) { int nbrow = entries.size(); Table t = null; try { //define table - t = new Table(6, nbrow); + t = new Table(6, nbrow + 1); 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); + + Cell cell1 = new Cell(_("lima-business.document.date")); + cell1.setHeader(true); + t.addCell(cell1); + Cell cell2 = new Cell(_("lima-business.document.accountnumber")); + cell2.setHeader(true); + t.addCell(cell2); + Cell cell3 = new Cell(_("lima-business.document.voucher")); + cell3.setHeader(true); + t.addCell(cell3); + Cell cell4 = new Cell(_("lima-business.document.description")); + cell4.setHeader(true); + t.addCell(cell4); + Cell cell5 = new Cell(_("lima-business.document.debit")); + cell5.setHeader(true); + t.addCell(cell5); + Cell cell6 = new Cell(_("lima-business.document.credit")); + cell6.setHeader(true); + t.addCell(cell6); + t.endHeaders(); + //define default cell Cell cell = new Cell(); cell.setBorder(Rectangle.LEFT); @@ -892,33 +875,15 @@ t.addCell(new Phrase(String.valueOf( !entry.getDebit() ? entry.getAmount() : 0), normalFont)); } - - } catch (BadElementException eeBEE) { - log.error("Can't create table", eeBEE); - } - return t; - } - - protected Table createEntryBooksAmountTable(String title, - BigDecimal credit, - BigDecimal 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)); + + // total + Cell cellTotal = new Cell(new Phrase(_("lima-business.document.amounts"), boldFont)); + cellTotal.setColspan(4); + cellTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); + t.addCell(cellTotal); t.addCell(new Phrase(debit.toString(), boldFont)); t.addCell(new Phrase(credit.toString(), boldFont)); + } catch (BadElementException eeBEE) { log.error("Can't create table", eeBEE); } @@ -1187,8 +1152,8 @@ BigDecimal subAmountCredit = new BigDecimal(0); for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { - BigDecimal debit = null; - BigDecimal credit = null; + BigDecimal debit = BigDecimal.ZERO; + BigDecimal credit = BigDecimal.ZERO; List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(),