r2985 - 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/financialstatementreport
Author: jpepin Date: 2010-07-23 12:42:24 +0200 (Fri, 23 Jul 2010) New Revision: 2985 Url: http://chorem.org/repositories/revision/lima/2985 Log: Mise ?\195?\160 jour formattage du pdf, ajout date et identit?\195?\169. Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.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/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-07-22 16:25:57 UTC (rev 2984) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-07-23 10:42:24 UTC (rev 2985) @@ -23,7 +23,9 @@ import java.awt.Color; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.ejb.Stateless; import org.apache.commons.logging.Log; @@ -77,18 +79,21 @@ } @Override - public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts) throws LimaException { - Document document = new Document(PageSize.A4, 5, 5, 5, 5); + public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts, Date beginDate, Date endDate) throws LimaException { + Document document = new Document(PageSize.A4, 8, 8, 8, 8); TopiaContext topiaContext = null; try { topiaContext = beginTransaction(); - PdfWriter pdfWriter = PdfWriter.getInstance(document, + SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); + SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm"); + + PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("/test_lima.pdf")); HtmlWriter htmlWriter = HtmlWriter.getInstance(document, new FileOutputStream("/test_lima.html")); - Font numpageFont = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK); + Font numpageFont = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK); document.open(); int nbpages = 1; @@ -106,21 +111,23 @@ int min=0; int size = financialStatementAmounts.size(); for (int i=0;i<size;i++) { - if (financialStatementAmounts.get(i).getLevel()==1){ + FinancialStatementAmounts fStatementAmounts = financialStatementAmounts.get(i); + if (fStatementAmounts.getLevel() == 1 && fStatementAmounts.getSubAmount() == false){ if (first){ first=false; } else{ - listList.add(financialStatementAmounts.subList(min+1, i-1)); + listList.add(financialStatementAmounts.subList(min, i-1)); } min=i; } } - listList.add(financialStatementAmounts.subList(min+1, size)); + listList.add(financialStatementAmounts.subList(min, size)); //create pages for (List<FinancialStatementAmounts> list : listList) { String title = list.get(0).getLabel(); + //list = list.subList(1, list.size()); int i=0; int n=list.size(); while (i<n){ @@ -131,19 +138,34 @@ List <FinancialStatementAmounts> subFinancialStatementAmounts = list.subList(i, j); //create page : header + table + footer - Table header = createHeader(title, identity, "01/01/2010", "31/12/2010"); + Table headerPage = createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate)); + Table headerTable = createHeaderTable(); Table table = createTable(subFinancialStatementAmounts); //new page Chapter chapter = new Chapter(0); + //headerPage + Paragraph paragraphHeaderPage = new Paragraph(); + paragraphHeaderPage.add(headerPage); + chapter.add(paragraphHeaderPage); //n° page Paragraph paragraphPage = new Paragraph(); - paragraphPage.setAlignment(Element.ALIGN_RIGHT); - paragraphPage.add(new Phrase("Page n° "+nbpages, numpageFont)); + 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); + Date newDate = new Date(); + infos.addCell(new Phrase("Date de tirage " + dateFormat.format(newDate) + " à " + hourFormat.format(newDate), numpageFont)); + infos.addCell(new Phrase("Page n° "+nbpages, numpageFont)); + paragraphPage.add(infos); chapter.add(paragraphPage); - //header - Paragraph paragraphHeader = new Paragraph(); - paragraphHeader.add(header); - chapter.add(paragraphHeader); + //headerTable + Paragraph paragraphHeaderTable = new Paragraph(); + paragraphHeaderTable.add(headerTable); + chapter.add(paragraphHeaderTable); //table Paragraph paragraphTable = new Paragraph(); paragraphTable.add(table); @@ -166,15 +188,16 @@ } } - public Table createHeader(String title, Identity identity, String beginDate, String endDate){ + public Table createHeaderPage(String title, Identity identity, String beginDate, String endDate){ Table t = null; try { //define table t = new Table(4, 5); + t.setWidth(100f); float[] widths = {0.25f, 0.45f, 0.12f, 0.18f}; t.setWidths(widths); - t.setPadding(3); + t.setPadding(1.5f); //define font Font headerFont = new Font(Font.HELVETICA, 9, Font.ITALIC, Color.BLACK); Font headerFontB = new Font(Font.HELVETICA, 9, Font.BOLDITALIC, Color.BLACK); @@ -207,7 +230,7 @@ t.addCell(new Phrase("Période du", headerFontB)); t.addCell(new Phrase(beginDate, headerFont)); //line 5 - t.addCell(new Phrase(identity.getCity(), headerFont)); + t.addCell(new Phrase(identity.getZipCode() + " " + identity.getCity(), headerFont)); t.addCell(""); t.addCell(new Phrase("au", headerFontB)); t.addCell(new Phrase(endDate, headerFont)); @@ -217,37 +240,54 @@ return t; } + public Table createHeaderTable(){ + Table t = null; + try { + t = new Table(4,1); + float[] widths = {0.4f, 0.2f, 0.2f, 0.2f}; + 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); + Font headerFont = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK); + t.addCell(new Phrase(_("lima.table.label"), headerFont)); + t.addCell(new Phrase(_("lima.table.grossamount"), headerFont)); + t.addCell(new Phrase(_("lima.table.provisiondeprecationamount"), headerFont)); + t.addCell(new Phrase(_("lima.table.netamount"), headerFont)); + + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + return t; + + } + public Table createTable(List<FinancialStatementAmounts> financialStatementAmounts){ int nbrow = financialStatementAmounts.size(); Table t = null; try { //define table t = new Table(4,nbrow); + t.setWidth(100f); float[] widths = {0.4f, 0.2f, 0.2f, 0.2f}; t.setWidths(widths); - t.setPadding(0.5f); - t.setSpacing(0); + t.setPadding(1.5f); t.setBorderWidth(1); - t.setBorder(Rectangle.BOTTOM); + t.setOffset(0); //define default cell Cell cell = new Cell(); cell.setBorder(Rectangle.LEFT); + cell.setHorizontalAlignment(Element.ALIGN_RIGHT); t.setDefaultCell(cell); - Font headerFont = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK); + Font tabFontBold = new Font(Font.HELVETICA, 9, Font.BOLD, Color.BLACK); Font tabFont = new Font(Font.HELVETICA, 9, Font.NORMAL, Color.BLACK); - Cell headerCell = new Cell(new Phrase(_("lima.table.label"), headerFont)); - headerCell.setBorderWidth(1); - headerCell.setHeader(true); - t.addCell(headerCell); - headerCell = new Cell(new Phrase(_("lima.table.grossamount"), headerFont)); - t.addCell(headerCell); - headerCell = new Cell(new Phrase(_("lima.table.provisiondeprecationamount"), headerFont)); - t.addCell(headerCell); - headerCell = new Cell(new Phrase(_("lima.table.netamount"), headerFont)); - t.addCell(headerCell); - for (FinancialStatementAmounts financialStatementAmount : financialStatementAmounts) { String label = financialStatementAmount.getLabel(); @@ -255,13 +295,16 @@ Double grossAmount = financialStatementAmount.getGrossAmount(); Double provisionDeprecationAmount = financialStatementAmount.getProvisionDeprecationAmount(); - if (financialStatementAmount.getSubAmount()){ - cell.setGrayFill(0.9f); + log.debug(label +" "+ level); + if (financialStatementAmount.getSubAmount() && level==1){ + cell.setGrayFill(0.88f); } + else if (financialStatementAmount.getSubAmount()){ + cell.setGrayFill(0.94f); + } else { cell.setGrayFill(1f); } - if (label == null){ t.addCell(""); t.addCell(""); @@ -276,12 +319,14 @@ } Phrase phrase = null; if (financialStatementAmount.getHeader()){ - phrase = new Phrase(tab+label, headerFont); + phrase = new Phrase(tab+label, tabFontBold); } else { phrase = new Phrase(tab+label, tabFont); } - t.addCell(phrase); + Cell c = new Cell(phrase); + c.setHorizontalAlignment(Element.ALIGN_LEFT); + t.addCell(c); //cell2 if (grossAmount != 0.0){ phrase = new Phrase(String.valueOf(grossAmount), tabFont); @@ -315,51 +360,6 @@ return t; } - public void example (){ - //FIRST PAGE - /*document.add(new Paragraph("First page of the document.")); - document.add(new Paragraph("Some more text on the \n" - + "first page with different color and font type.", - FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, - new Color(255, 150, 200)))); - - //SECOND PAGE - Paragraph title1 = new Paragraph("Chapter 1", - FontFactory.getFont(FontFactory.HELVETICA, 18, - Font.BOLDITALIC, new Color(0, 0, 255))); - Chapter chapter1 = new Chapter(title1, 1); - chapter1.setNumberDepth(0); - //SECTION 1 - Paragraph title11 = new Paragraph("This is Section 1 in Chapter 1", - FontFactory.getFont(FontFactory.HELVETICA, 16, - Font.BOLD, new Color(255, 0, 0))); - Section section1 = chapter1.addSection(title11); - Paragraph someSectionText = new Paragraph("This text comes as part of section 1 of chapter 1."); - section1.add(someSectionText); - someSectionText = new Paragraph("Following is a 3 X 2 table."); - section1.add(someSectionText); - //TABLE - Table t = new Table(3,2); - t.setBorderColor(new Color(220, 255, 100)); - t.setPadding(5); - t.setSpacing(5); - t.setBorderWidth(1); - Cell c1 = new Cell("header1"); - c1.setHeader(true); - t.addCell(c1); - c1 = new Cell("Header2"); - t.addCell(c1); - c1 = new Cell("Header3"); - t.addCell(c1); - t.endHeaders(); - t.addCell("1.1"); - t.addCell("1.2"); - t.addCell("1.3"); - - section1.add(t); - - document.add(chapter1);*/ - } protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database 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-07-22 16:25:57 UTC (rev 2984) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java 2010-07-23 10:42:24 UTC (rev 2985) @@ -19,6 +19,7 @@ package org.chorem.lima.business.ejbinterface; +import java.util.Date; import java.util.List; import javax.ejb.Remote; @@ -35,6 +36,6 @@ @Remote public interface DocumentService { - public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts) throws LimaException; + public void createFinancialStatementsDocuments(List<FinancialStatementAmounts> financialStatementAmounts, Date beginDate, Date endDate) throws LimaException; } 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-07-22 16:25:57 UTC (rev 2984) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2010-07-23 10:42:24 UTC (rev 2985) @@ -210,7 +210,7 @@ public void createDocuments(){ try { - documentService.createFinancialStatementsDocuments(cacheDataList); + documentService.createFinancialStatementsDocuments(cacheDataList, selectedBeginDate, selectedEndDate); } catch (LimaException e) { if (log.isDebugEnabled()){ log.debug("Error on create document",e);
participants (1)
-
jpepin@users.chorem.org