Author: jpepin Date: 2010-08-03 12:41:31 +0200 (Tue, 03 Aug 2010) New Revision: 2993 Url: http://chorem.org/repositories/revision/lima/2993 Log: Sortie document pdf journal g?\195?\169n?\195?\169ral. 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-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/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.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-08-02 16:54:10 UTC (rev 2992) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-08-03 10:41:31 UTC (rev 2993) @@ -25,6 +25,7 @@ import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import javax.ejb.EJB; @@ -33,6 +34,8 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.FinancialStatementAmounts; +import org.chorem.lima.beans.GeneralEntryBooksDatas; +import org.chorem.lima.beans.GeneralEntryBooksDatasImpl; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; @@ -42,12 +45,15 @@ 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.business.utils.EntryComparator; 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.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodDAO; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -131,7 +137,8 @@ - public Table createHeaderPage(String title, Identity identity, String beginDate, String endDate){ + public Paragraph createHeaderPage(String title, Identity identity, String beginDate, String endDate){ + Paragraph paragraphHeaderPage = new Paragraph(); Table t = null; try { @@ -154,34 +161,61 @@ titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); titleCell.setRowspan(2); t.addCell(titleCell); - t.addCell(new Phrase(_("lima-business.document.businessnumber"), bolditalicFont)); + t.addCell(new Phrase(_("lima-business.document.businessnumber"), + bolditalicFont)); t.addCell(new Phrase(identity.getBusinessNumber(), italicFont)); //line 2 t.addCell(new Phrase(identity.getDescription(), italicFont)); - t.addCell(new Phrase(_("lima-business.document.classificationcode"), bolditalicFont)); + t.addCell(new Phrase(_("lima-business.document.classificationcode"), + bolditalicFont)); t.addCell(new Phrase(identity.getClassificationCode(), italicFont)); //line 3 t.addCell(new Phrase(identity.getAddress(), italicFont)); t.addCell(""); - t.addCell(new Phrase(_("lima-business.document.vatnumber"), bolditalicFont)); + t.addCell(new Phrase(_("lima-business.document.vatnumber"), + bolditalicFont)); t.addCell(new Phrase(identity.getVatNumber(), italicFont)); //line 4 t.addCell(new Phrase(identity.getAddress2(), italicFont)); t.addCell(""); - t.addCell(new Phrase(_("lima-business.document.period1"), bolditalicFont)); + t.addCell(new Phrase(_("lima-business.document.period1"), + bolditalicFont)); t.addCell(new Phrase(beginDate, italicFont)); //line 5 - t.addCell(new Phrase(identity.getZipCode() + " " + identity.getCity(), italicFont)); + t.addCell(new Phrase(identity.getZipCode() + " " + identity.getCity(), + italicFont)); t.addCell(""); - t.addCell(new Phrase(_("lima-business.document.period2"), bolditalicFont)); + t.addCell(new Phrase(_("lima-business.document.period2"), + bolditalicFont)); t.addCell(new Phrase(endDate, italicFont)); } catch (BadElementException eeBEE) { log.error("Can't create table", eeBEE); } - return t; + + paragraphHeaderPage.add(t); + return paragraphHeaderPage; } + public Paragraph createNumberPage (int nbPages, String dateS, String hourS) throws BadElementException{ + //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)); + return paragraphPage; + } + //############## FinancialStatements ############## @@ -189,7 +223,8 @@ 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); + List<FinancialStatementAmounts> financialStatementAmounts = + financialStatementService.financialStatementReport(beginDate, endDate); try { Date newDate = new Date(); @@ -207,12 +242,14 @@ Identity identity = identityService.getIdentity(); //Split list by financialstatement type - List<List<FinancialStatementAmounts>> listList = new ArrayList<List<FinancialStatementAmounts>>(); + 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++) { - FinancialStatementAmounts fStatementAmounts = financialStatementAmounts.get(i); + FinancialStatementAmounts fStatementAmounts = + financialStatementAmounts.get(i); if (fStatementAmounts.getLevel() == 1 && fStatementAmounts.getSubAmount() == false){ if (first){ first=false; @@ -239,29 +276,16 @@ List <FinancialStatementAmounts> subFinancialStatementAmounts = list.subList(i, j); //create page : header + table + footer - Table headerPage = createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate)); Table headerTable = createFinancialStatementsHeaderTable(); - Table table = createFinancialStatementsTable(subFinancialStatementAmounts); + Table table = createFinancialStatementsTable( + subFinancialStatementAmounts); //new page Chapter chapter = new Chapter(0); //headerPage - Paragraph paragraphHeaderPage = new Paragraph(); - paragraphHeaderPage.add(headerPage); - chapter.add(paragraphHeaderPage); + chapter.add(createHeaderPage(title, identity, + dateFormat.format(beginDate), dateFormat.format(endDate))); //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); + chapter.add(createNumberPage(nbpages, dateS, hourS)); //headerTable Paragraph paragraphHeaderTable = new Paragraph(); paragraphHeaderTable.add(headerTable); @@ -300,10 +324,14 @@ cell.setHorizontalAlignment(Element.ALIGN_CENTER); t.setDefaultCell(cell); t.setOffset(8); - t.addCell(new Phrase(_("lima-business.document.label"), boldFont)); - t.addCell(new Phrase(_("lima-business.document.grossamount"), boldFont)); - t.addCell(new Phrase(_("lima-business.document.provisiondeprecationamount"), boldFont)); - t.addCell(new Phrase(_("lima-business.document.netamount"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.label"), + boldFont)); + t.addCell(new Phrase(_("lima-business.document.grossamount"), + boldFont)); + t.addCell(new Phrase(_("lima-business.document.provisiondeprecationamount"), + boldFont)); + t.addCell(new Phrase(_("lima-business.document.netamount"), + boldFont)); } catch (BadElementException eeBEE) { log.error("Can't create table", eeBEE); @@ -334,10 +362,11 @@ String label = financialStatementAmount.getLabel(); int level = financialStatementAmount.getLevel(); - Double grossAmount = financialStatementAmount.getGrossAmount(); - Double provisionDeprecationAmount = financialStatementAmount.getProvisionDeprecationAmount(); + Double grossAmount = + financialStatementAmount.getGrossAmount(); + Double provisionDeprecationAmount = + financialStatementAmount.getProvisionDeprecationAmount(); - log.debug(label +" "+ level); if (financialStatementAmount.getSubAmount() && level==1){ cell.setGrayFill(0.88f); } @@ -371,7 +400,8 @@ t.addCell(c); //cell2 if (grossAmount != 0.0){ - phrase = new Phrase(String.valueOf(grossAmount), normalFont); + phrase = new Phrase(String.valueOf( + grossAmount), normalFont); } else { phrase = new Phrase(""); @@ -379,7 +409,8 @@ t.addCell(phrase); //cell 3 if (provisionDeprecationAmount != 0.0){ - phrase = new Phrase(String.valueOf(provisionDeprecationAmount), normalFont); + phrase = new Phrase(String.valueOf( + provisionDeprecationAmount), normalFont); } else { phrase = new Phrase(""); @@ -387,7 +418,8 @@ t.addCell(phrase); //cell 4 if (grossAmount-provisionDeprecationAmount != 0.0){ - phrase = new Phrase(String.valueOf(grossAmount-provisionDeprecationAmount), normalFont); + phrase = new Phrase(String.valueOf( + grossAmount-provisionDeprecationAmount), normalFont); } else { phrase = new Phrase(""); @@ -408,10 +440,23 @@ @Override - public void createLedgerDocuments(List<Object> list, Date beginDate, Date endDate) throws LimaException { + public void createLedgerDocuments(Date beginDate, Date endDate) throws LimaException { Document document = new Document(PageSize.A4, 8, 8, 8, 8); - + List<Object> list = new ArrayList<Object>(); try { + + BalanceTrial balanceTrial = reportService.generateLedger(beginDate, endDate, true); + if (balanceTrial.getReportsDatas() != null){ + for (ReportsDatas reportsDatas : balanceTrial.getReportsDatas()) { + list.add(reportsDatas); + List<Entry> entries = (List<Entry>) reportsDatas.getListEntry(); + if (entries != null){ + Collections.sort(entries, new EntryComparator()); + list.addAll(entries); + } + } + } + Date newDate = new Date(); String dateS = dateFormat.format(newDate); String hourS = hourFormat.format(newDate); @@ -441,28 +486,14 @@ } List <Object> subList = list.subList(i, j); //create page : header + table + footer - Table headerPage = createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate)); Table headerTable = createLedgerHeaderTable(); //new page Chapter chapter = new Chapter(0); //headerPage - Paragraph paragraphHeaderPage = new Paragraph(); - paragraphHeaderPage.add(headerPage); - chapter.add(paragraphHeaderPage); + chapter.add(createHeaderPage(title, identity, + dateFormat.format(beginDate), dateFormat.format(endDate))); //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); + chapter.add(createNumberPage(nbpages, dateS, hourS)); //headerTable Paragraph paragraphHeaderTable = new Paragraph(); paragraphHeaderTable.add(headerTable); @@ -470,7 +501,9 @@ //backward amounts if (n>max && nbpages>1){ Paragraph backwardParagraph = new Paragraph(); - backwardParagraph.add(createLedgerAmountTable(accountcarry, _("lima-business.document.carryback"), currentAmountDebit, currentAmountCredit)); + backwardParagraph.add(createLedgerAmountTable( + accountcarry, _("lima-business.document.carryback"), + currentAmountDebit, currentAmountCredit)); chapter.add(backwardParagraph); } //table @@ -488,21 +521,25 @@ ReportsDatas reportsDatas = (ReportsDatas) object; Account account = reportsDatas.getAccount(); if ( account != null){ - accountcarry = account.getAccountNumber()+" "+account.getLabel()+" "; - log.debug(accountcarry); + accountcarry = account.getAccountNumber() + + " " + account.getLabel() + " "; } } } //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.amounts"), currentAmountDebit, currentAmountCredit)); + finalAmountParagraph.add(createLedgerAmountTable("", + _("lima-business.document.amounts"), + currentAmountDebit, currentAmountCredit)); chapter.add(finalAmountParagraph); } //add page @@ -599,13 +636,18 @@ Double amountDebit = entry.getDebit() ? entry.getAmount() : 0; Double amountCredit = entry.getDebit() ? 0 : entry.getAmount(); - t.addCell(new Phrase(dateFormat.format(entry.getFinancialTransaction().getTransactionDate()), normalFont)); + t.addCell(new Phrase(dateFormat.format( + entry.getFinancialTransaction().getTransactionDate()), + normalFont)); t.addCell(new Phrase(entryBookCode, normalFont)); t.addCell(new Phrase(entry.getVoucher(), normalFont)); t.addCell(new Phrase(entry.getDescription(), normalFont)); - t.addCell(new Phrase(String.valueOf(amountDebit), normalFont)); - t.addCell(new Phrase(String.valueOf(amountCredit), normalFont)); - t.addCell(new Phrase(String.valueOf(amountDebit-amountCredit), normalFont)); + t.addCell(new Phrase(String.valueOf(amountDebit), + normalFont)); + t.addCell(new Phrase(String.valueOf(amountCredit), + normalFont)); + t.addCell(new Phrase(String.valueOf(amountDebit-amountCredit), + normalFont)); } } @@ -672,17 +714,25 @@ Identity identity = identityService.getIdentity(); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); //Split list by financialstatement type - List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = closedPeriodicEntryBookDAO.findAllByDates(beginDate, endDate); + 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()); + 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); @@ -707,7 +757,9 @@ } //create pages - String title = closedPeriodicEntryBook.getEntryBook().getLabel() + "\n" + monthYearFormat.format(closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); + String title = closedPeriodicEntryBook.getEntryBook().getLabel() + + "\n" + monthYearFormat.format( + closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); //list = list.subList(1, list.size()); int i=0; int n=entries.size(); @@ -720,29 +772,15 @@ 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); + //headerPage + chapter.add(createHeaderPage(title, identity, + dateFormat.format(beginDate), dateFormat.format(endDate))); + //n° page + chapter.add(createNumberPage(nbpages, dateS, hourS)); //headerTable Paragraph paragraphHeaderTable = new Paragraph(); paragraphHeaderTable.add(headerTable); @@ -754,7 +792,8 @@ //final amounts if (i>=n-max){ Paragraph finalAmountParagraph = new Paragraph(); - finalAmountParagraph.add(createEntryBooksAmountTable(_("lima-business.document.amounts"), debit, credit)); + finalAmountParagraph.add(createEntryBooksAmountTable( + _("lima-business.document.amounts"), debit, credit)); chapter.add(finalAmountParagraph); } //add page @@ -824,12 +863,16 @@ t.setDefaultCell(cell); for (Entry entry : entries) { - t.addCell(new Phrase(dateFormat.format(entry.getFinancialTransaction().getTransactionDate()), normalFont)); + 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)); + 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) { @@ -869,7 +912,7 @@ Document document = new Document(PageSize.A4, 8, 8, 8, 8); BalanceTrial balanceTrial = - reportService.generateBalanceTrial(beginDate, endDate, null, false, false); + reportService.generateBalanceTrial(beginDate, endDate, null, false, true); List<ReportsDatas> list = (List<ReportsDatas>) balanceTrial.getReportsDatas(); @@ -904,28 +947,13 @@ } 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); + chapter.add(createHeaderPage(title, identity, dateFormat.format(beginDate), dateFormat.format(endDate))); //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); + chapter.add(createNumberPage(nbpages, dateS, hourS)); //headerTable Paragraph paragraphHeaderTable = new Paragraph(); paragraphHeaderTable.add(headerTable); @@ -933,7 +961,10 @@ //backward amounts if (n>max && nbpages>1){ Paragraph backwardParagraph = new Paragraph(); - backwardParagraph.add(createBalanceAmountTable(_("lima-business.document.carryback"), currentAmountDebit, currentAmountCredit, currentSoldeDebit, currentSoldeCredit)); + backwardParagraph.add(createBalanceAmountTable( + _("lima-business.document.carryback"), + currentAmountDebit, currentAmountCredit, + currentSoldeDebit, currentSoldeCredit)); chapter.add(backwardParagraph); } //table @@ -944,19 +975,27 @@ for (ReportsDatas reportsDatas : subList){ currentAmountDebit += reportsDatas.getAmountDebit(); currentAmountCredit += reportsDatas.getAmountCredit(); - currentSoldeDebit += reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0; - currentSoldeCredit += reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde(); + 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)); + 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)); + finalAmountParagraph.add(createBalanceAmountTable( + _("lima-business.document.amounts"), + currentAmountDebit, currentAmountCredit, + currentSoldeDebit, currentSoldeCredit)); chapter.add(finalAmountParagraph); } //add page @@ -1064,7 +1103,267 @@ return t; } + //############## General EntryBook ############## + + @Override + public void createGeneralEntryBooksDocuments(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_Gebs"+fileDateS+".pdf")); + HtmlWriter htmlWriter = HtmlWriter.getInstance(document, + new FileOutputStream("/lima_Gebs"+fileDateS+".html")); + document.open(); + int nbpages = 1; + + Identity identity = identityService.getIdentity(); + + FinancialPeriodDAO financialPeriodDAO = + LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); + EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + + + TopiaQuery financialPeriodsQuery = financialPeriodDAO.createQuery(); + String beginDateProperty = TopiaQuery.getProperty(FinancialPeriod.BEGIN_DATE); + String endDateProperty = TopiaQuery.getProperty(FinancialPeriod.BEGIN_DATE); + financialPeriodsQuery.addWhere(beginDateProperty, Op.GE, beginDate) + .addWhere(endDateProperty, Op.LE, endDate) + .addOrder(beginDateProperty); + List<FinancialPeriod> financialPeriods = + financialPeriodDAO.findAllByQuery(financialPeriodsQuery); + + List<GeneralEntryBooksDatas> list = new ArrayList<GeneralEntryBooksDatas>(); + Double amountDebit = 0.0; + Double amountCredit = 0.0; + for (FinancialPeriod financialPeriod : financialPeriods) { + List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = + closedPeriodicEntryBookDAO.findAllByDates( + financialPeriod.getBeginDate(), financialPeriod.getEndDate()); + + Double subAmountDebit = 0.0; + Double subAmountCredit = 0.0; + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { + + List<Object[]> results = new ArrayList<Object[]>(); + TopiaQuery query = entryDAO.createQuery(); + Double debit = 0.0; + Double credit = 0.0; + + 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()) + .setSelect(Entry.DEBIT, "SUM("+Entry.AMOUNT+")") + .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]; + } + } + GeneralEntryBooksDatas generalEntryBooksDatas = + new GeneralEntryBooksDatasImpl(); + generalEntryBooksDatas.setCode( + closedPeriodicEntryBook.getEntryBook().getCode()); + generalEntryBooksDatas.setDescription( + closedPeriodicEntryBook.getEntryBook().getLabel()); + generalEntryBooksDatas.setPeriod( + monthYearFormat.format(financialPeriod.getBeginDate())); + generalEntryBooksDatas.setCredit(credit); + generalEntryBooksDatas.setDebit(debit); + list.add(generalEntryBooksDatas); + subAmountCredit += credit; + subAmountDebit += debit; + } + GeneralEntryBooksDatas generalEntryBooksDatas = + new GeneralEntryBooksDatasImpl(); + generalEntryBooksDatas.setSubAmount(true); + generalEntryBooksDatas.setCredit(subAmountCredit); + generalEntryBooksDatas.setDebit(subAmountDebit); + generalEntryBooksDatas.setPeriod( + monthYearFormat.format(financialPeriod.getBeginDate())); + list.add(generalEntryBooksDatas); + amountCredit += subAmountCredit; + amountDebit += subAmountDebit; + } + GeneralEntryBooksDatas generalEntryBooksDatas = + new GeneralEntryBooksDatasImpl(); + generalEntryBooksDatas.setAmount(true); + generalEntryBooksDatas.setCredit(amountCredit); + generalEntryBooksDatas.setDebit(amountDebit); + list.add(generalEntryBooksDatas); + + + //create pages + int i=0; + int n=list.size(); + int max=35; + while (i<n){ + int j=i+max; + if (j>n){ + j = n; + } + List <GeneralEntryBooksDatas> subList = + list.subList(i, j); + //create page : header + table + footer + Table headerTable = createGeneralEntryBooksHeaderTable(); + Table table = createGeneralEntryBooksTable(subList); + //new page + Chapter chapter = new Chapter(0); + //headerPage + chapter.add(createHeaderPage( + _("lima-business.document.generalentrybook"), + identity, dateFormat.format(beginDate), + dateFormat.format(endDate))); + //n° page + chapter.add(createNumberPage(nbpages, dateS, hourS)); + //headerTable + Paragraph paragraphHeaderTable = new Paragraph(); + paragraphHeaderTable.add(headerTable); + chapter.add(paragraphHeaderTable); + //table + Paragraph paragraphTable = new Paragraph(); + paragraphTable.add(table); + chapter.add(paragraphTable); + //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 createGeneralEntryBooksHeaderTable(){ + Table t = null; + try { + t = new Table(5,1); + float[] widths = {0.1f, 0.45f, 0.15f, 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.entrybook"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.label"), boldFont)); + t.addCell(new Phrase(_("lima-business.document.date"), 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 createGeneralEntryBooksTable(List <GeneralEntryBooksDatas> list){ + int nbrow = list.size(); + Table t = null; + try { + //define table + t = new Table(5,nbrow); + t.setWidth(100f); + float[] widths = {0.1f, 0.45f, 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 (GeneralEntryBooksDatas generalEntryBooksDatas : list) { + if (!generalEntryBooksDatas.getAmount() && !generalEntryBooksDatas.getSubAmount()){ + t.addCell(new Phrase( + generalEntryBooksDatas.getCode(), normalFont)); + t.addCell(new Phrase( + generalEntryBooksDatas.getDescription(), normalFont)); + t.addCell(new Phrase( + generalEntryBooksDatas.getPeriod(), normalFont)); + t.addCell(new Phrase( + String.valueOf(generalEntryBooksDatas.getDebit()), + normalFont)); + t.addCell(new Phrase( + String.valueOf(generalEntryBooksDatas.getCredit()), + normalFont)); + } + else { + Phrase phrase = null; + if (generalEntryBooksDatas.getAmount()){ + phrase = new Phrase(_("lima-business.document.amounts"), + boldFont); + } + else { + phrase = new Phrase(_("lima-business.document.amounts") + + " " + generalEntryBooksDatas.getPeriod(), + boldFont); + } + Cell cell2 = new Cell(phrase); + cell2.setBorder(Rectangle.TOP+Rectangle.BOTTOM); + cell2.setColspan(3); + t.addCell(cell2); + cell2 = new Cell(new Phrase( + String.valueOf(generalEntryBooksDatas.getDebit()), + boldFont)); + cell2.setBorder(Rectangle.TOP+Rectangle.BOTTOM); + t.addCell(cell2); + cell2 = new Cell(new Phrase( + String.valueOf(generalEntryBooksDatas.getCredit()), + boldFont)); + cell2.setBorder(Rectangle.TOP+Rectangle.BOTTOM); + t.addCell(cell2); + } + } + + } 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 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 16:54:10 UTC (rev 2992) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/DocumentService.java 2010-08-03 10:41:31 UTC (rev 2993) @@ -34,7 +34,9 @@ public interface DocumentService { public void createFinancialStatementsDocuments(Date beginDate, Date endDate) throws LimaException; - public void createLedgerDocuments(List<Object> objects, Date beginDate, Date endDate) throws LimaException; + public void createLedgerDocuments(Date beginDate, Date endDate) throws LimaException; public void createEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException; public void createBalanceDocuments(Date beginDate, Date endDate) throws LimaException; + public void createGeneralEntryBooksDocuments(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 16:54:10 UTC (rev 2992) +++ trunk/lima-business/src/main/resources/i18n/lima-business-en_GB.properties 2010-08-03 10:41:31 UTC (rev 2993) @@ -20,6 +20,7 @@ lima-business.document.debit=Debit lima-business.document.description=Description lima-business.document.entrybook=EntryBook +lima-business.document.generalentrybook= lima-business.document.grossamount=Gross Amount lima-business.document.label=Label lima-business.document.ledger= 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 16:54:10 UTC (rev 2992) +++ trunk/lima-business/src/main/resources/i18n/lima-business-fr_FR.properties 2010-08-03 10:41:31 UTC (rev 2993) @@ -15,6 +15,7 @@ lima-business.document.debit=D\u00E9bit lima-business.document.description=Description lima-business.document.entrybook=Journal +lima-business.document.generalentrybook=Journal G\u00E9n\u00E9ral lima-business.document.grossamount=Brut lima-business.document.label=Libell\u00E9 lima-business.document.ledger=Grand Livre Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) 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 16:54:10 UTC (rev 2992) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2010-08-03 10:41:31 UTC (rev 2993) @@ -151,6 +151,7 @@ public void createPdf() { try { documentService.createEntryBooksDocuments(selectedBeginDate, selectedEndDate); + documentService.createGeneralEntryBooksDocuments(selectedBeginDate, selectedEndDate); } catch (LimaException eee) { if(log.isDebugEnabled()){ log.debug("Can't create PDF", eee); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java 2010-08-02 16:54:10 UTC (rev 2992) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java 2010-08-03 10:41:31 UTC (rev 2993) @@ -160,7 +160,7 @@ public void createPdf() { try { - documentService.createLedgerDocuments(cachedatasList, selectedBeginDate, selectedEndDate); + documentService.createLedgerDocuments(selectedBeginDate, selectedEndDate); } catch (LimaException eee) { if(log.isDebugEnabled()){ log.debug("Can't create PDF", eee);