r2976 - trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport
Author: jpepin Date: 2010-07-20 12:29:28 +0200 (Tue, 20 Jul 2010) New Revision: 2976 Url: http://chorem.org/repositories/revision/lima/2976 Log: Cr?\195?\169ation document PDF et HTML pour le bilan et compte de r?\195?\169sultat. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementDocument.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementDocument.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementDocument.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementDocument.java 2010-07-20 10:29:28 UTC (rev 2976) @@ -0,0 +1,317 @@ +/* + * *##% Lima Main + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.ui.financialstatementreport; + +import static org.nuiton.i18n.I18n._; +import java.awt.Color; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.beans.FinancialStatementAmounts; +import com.lowagie.text.BadElementException; +import com.lowagie.text.Cell; +import com.lowagie.text.Chapter; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.Font; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Phrase; +import com.lowagie.text.Rectangle; +import com.lowagie.text.Table; +import com.lowagie.text.html.HtmlWriter; +import com.lowagie.text.pdf.PdfWriter; + +public class FinancialStatementDocument { + + private static final Log log = + LogFactory.getLog(FinancialStatementReportTable.class); + + public void createDocuments(List<FinancialStatementAmounts> financialStatementAmounts) { + Document document = new Document(PageSize.A4, 5, 5, 5, 5); + + try { + + 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); + document.open(); + int nbpages = 1; + + + //Split list by financialstatement type + List<List<FinancialStatementAmounts>> listList = new ArrayList<List<FinancialStatementAmounts>>(); + Boolean first = true; + int min=0; + int size = financialStatementAmounts.size(); + for (int i=0;i<size;i++) { + if (financialStatementAmounts.get(i).getLevel()==1){ + if (first){ + first=false; + } + else{ + listList.add(financialStatementAmounts.subList(min, i-1)); + } + min=i; + } + } + listList.add(financialStatementAmounts.subList(min, size)); + + //create pages + for (List<FinancialStatementAmounts> list : listList) { + String title = list.get(0).getLabel(); + int i=0; + int n=list.size(); + while (i<n){ + int j=i+40; + if (j>n){ + j = n; + } + List <FinancialStatementAmounts> subFinancialStatementAmounts = + list.subList(i, j); + //create page : header + table + footer + Table header = createHeader(title, "01/01/2010", "31/12/2010"); + Table table = createTable(subFinancialStatementAmounts); + //new page + Chapter chapter = new Chapter(0); + //n° page + Paragraph paragraphPage = new Paragraph(); + paragraphPage.setAlignment(Element.ALIGN_RIGHT); + paragraphPage.add(new Phrase("Page n° "+nbpages, numpageFont)); + chapter.add(paragraphPage); + //header + Paragraph paragraphHeader = new Paragraph(); + paragraphHeader.add(header); + chapter.add(paragraphHeader); + //table + Paragraph paragraphTable = new Paragraph(); + paragraphTable.add(table); + chapter.add(paragraphTable); + //add page + document.add(chapter); + i=i+40; + 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 createHeader(String title, String beginDate, String endDate){ + Table t = null; + try { + //define table + t = new Table(4, 5); + float[] widths = {0.25f, 0.45f, 0.12f, 0.18f}; + t.setWidths(widths); + t.setPadding(3); + //define font + Font headerFont = new Font(Font.HELVETICA, 9, Font.ITALIC, Color.BLACK); + Font headerFontB = new Font(Font.HELVETICA, 9, Font.BOLDITALIC, Color.BLACK); + //defaut cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.NO_BORDER); + t.setDefaultCell(cell); + + //line 1 + t.addCell(new Phrase("Code Lutin SA", headerFontB)); + Cell titleCell = new Cell(new Phrase(title, new Font(Font.HELVETICA, 14, Font.BOLD, Color.BLACK))); + titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE); + titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); + titleCell.setRowspan(2); + t.addCell(titleCell); + t.addCell(new Phrase("N° Siret", headerFontB)); + t.addCell(new Phrase("442116703", headerFont)); + //line 2 + t.addCell(new Phrase("SSL", headerFont)); + t.addCell(new Phrase("NAF :", headerFontB)); + t.addCell(new Phrase("6201Z", headerFont)); + //line 3 + t.addCell(new Phrase("44 bd des Pas Enchantés", headerFont)); + t.addCell(""); + t.addCell(new Phrase("n°TVA", headerFontB)); + t.addCell(new Phrase("FR 57 442116703", headerFont)); + //line 4 + t.addCell(new Phrase("44230 St Séb/Loire", headerFont)); + t.addCell(""); + t.addCell(new Phrase("Période du", headerFontB)); + t.addCell(new Phrase(beginDate, headerFont)); + //line 5 + t.addCell(""); + t.addCell(""); + t.addCell(new Phrase("au", headerFontB)); + t.addCell(new Phrase(endDate, 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); + float[] widths = {0.4f, 0.2f, 0.2f, 0.2f}; + t.setWidths(widths); + t.setPadding(0.5f); + t.setSpacing(0); + t.setBorderWidth(1); + t.setBorder(Rectangle.BOTTOM); + //define default cell + Cell cell = new Cell(); + cell.setBorder(Rectangle.LEFT); + t.setDefaultCell(cell); + + Font headerFont = 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(); + int level = financialStatementAmount.getLevel(); + Double grossAmount = financialStatementAmount.getGrossAmount(); + Double provisionDeprecationAmount = financialStatementAmount.getProvisionDeprecationAmount(); + + if (financialStatementAmount.getSubAmount()){ + cell.setGrayFill(0.9f); + } + else { + cell.setGrayFill(1f); + } + + if (label == null){ + t.addCell(""); + t.addCell(""); + t.addCell(""); + t.addCell(""); + } + else { + //cell1 + String tab = ""; + for (int i = 0; i <= level; i++) { + tab += "\t"; + } + Phrase phrase = new Phrase(tab+label, tabFont); + t.addCell(phrase); + //cell2 + if (grossAmount != 0.0){ + phrase = new Phrase(String.valueOf(grossAmount), tabFont); + } + else { + phrase = new Phrase(""); + } + t.addCell(phrase); + //cell 3 + if (provisionDeprecationAmount != 0.0){ + phrase = new Phrase(String.valueOf(provisionDeprecationAmount), tabFont); + } + else { + phrase = new Phrase(""); + } + t.addCell(phrase); + //cell 4 + if (grossAmount-provisionDeprecationAmount != 0.0){ + phrase = new Phrase(String.valueOf(grossAmount-provisionDeprecationAmount), tabFont); + } + else { + phrase = new Phrase(""); + } + t.addCell(phrase); + } + } + + } catch (BadElementException eeBEE) { + log.error("Can't create table", eeBEE); + } + 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);*/ + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTable.java 2010-07-19 13:53:24 UTC (rev 2975) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTable.java 2010-07-20 10:29:28 UTC (rev 2976) @@ -29,8 +29,9 @@ import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; + public class FinancialStatementReportTable extends JXTable { - + private static final long serialVersionUID = 154211277688304679L; protected FinancialStatementReportViewHandler handler; @@ -60,7 +61,6 @@ for (int i = 0; i < getColumnModel().getColumnCount(); i++) { getColumnModel().getColumn(i).setCellRenderer(renderer); } - } /* @@ -110,5 +110,5 @@ new ColorHighlighter(predicate, new Color(244,244,244), null); addHighlighter(colorTransaction); } - + } 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-19 13:53:24 UTC (rev 2975) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2010-07-20 10:29:28 UTC (rev 2976) @@ -196,4 +196,9 @@ fireTableDataChanged(); } + public void createDocuments(){ + FinancialStatementDocument financialStatementDocument = new FinancialStatementDocument(); + financialStatementDocument.createDocuments(cacheDataList); + } + } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportView.jaxx 2010-07-19 13:53:24 UTC (rev 2975) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportView.jaxx 2010-07-20 10:29:28 UTC (rev 2976) @@ -68,9 +68,12 @@ onActionPerformed="getModelTable().setEndDate(endDatePicker.getDate()); 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.chorem.lima.ui.financialstatementreport.FinancialStatementReportTable id="table" rowHeight="24" constructorParams="getHandler()" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java 2010-07-19 13:53:24 UTC (rev 2975) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java 2010-07-20 10:29:28 UTC (rev 2976) @@ -83,4 +83,7 @@ return view; } + public void createPdf() { + model.createDocuments(); + } }
participants (1)
-
jpepin@users.chorem.org