Author: mallon Date: 2012-08-17 16:41:36 +0200 (Fri, 17 Aug 2012) New Revision: 3611 Url: http://chorem.org/repositories/revision/lima/3611 Log: refs #769 Modification du jaxx, et mise en place de l affichage html des donnees filtrees, pour l edition de la balance. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsViewHandler.java Removed: 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 Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/DocumentService.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/HttpServerServiceImpl.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-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.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-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -816,7 +816,7 @@ entryBookReport += "</table></p>\n"; } } - entryBookReport += "</body>\n"; + entryBookReport += "</body>\n</html>"; } } catch (Exception ex) { throw new LimaException("Can't create document", ex); @@ -828,213 +828,177 @@ //############## Balance ############## @Override - public void createBalanceDocuments(Date beginDate, - Date endDate, - FormatsEnum format) throws LimaException { - Document document = new Document(PageSize.A4, 8, 8, 8, 8); + public String createBalanceDocuments(Date beginDate, + Date endDate) throws LimaException { BalanceTrial balanceTrial = reportService.generateBalanceTrial(beginDate, endDate, null, false, true); List<ReportsDatas> list = (List<ReportsDatas>) balanceTrial.getReportsDatas(); - try { - Date newDate = new Date(); + String balanceReport = ""; + balanceReport += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + + "<html>\n"; - BigDecimal currentAmountDebit = new BigDecimal(0); - BigDecimal currentAmountCredit = new BigDecimal(0); - BigDecimal currentSoldeDebit = new BigDecimal(0); - BigDecimal currentSoldeCredit = new BigDecimal(0); + if (beginDate != null && endDate != null) { + try{ + BigDecimal currentAmountDebit = new BigDecimal(0); + BigDecimal currentAmountCredit = new BigDecimal(0); + BigDecimal currentSoldeDebit = new BigDecimal(0); + BigDecimal currentSoldeCredit = new BigDecimal(0); - String filePath = path + File.separator + DocumentsEnum.BALANCE.getFileName(); - FileOutputStream fileOut = new FileOutputStream(filePath + format.getExtension()); - switch (format) { - case HTML: - HtmlWriter htmlWriter = HtmlWriter.getInstance(document, fileOut); - break; - case PDF: - PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOut); - break; - } - document.open(); - int nbpages = 1; - Identity identity = identityService.getIdentity(); + Identity identity = identityService.getIdentity(); - //create pages - int i = 0; - int n = list.size(); - int max = n; - // alloc nb rows max for pdf documents on one page - if (format == FormatsEnum.PDF) { - 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 headerTable = createBalanceHeaderTable(); - //new page - Chapter chapter = new Chapter(0); - //headerPage - chapter.add(createHeaderPage(DocumentsEnum.BALANCE.getDescription(), - identity, beginDate, endDate)); - //n° page - chapter.add(createNumberPage(nbpages, newDate)); - //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 = currentAmountDebit.add(reportsDatas.getAmountDebit()); - currentAmountCredit = currentAmountCredit.add(reportsDatas.getAmountCredit()); - if (reportsDatas.getSoldeDebit()) { - currentSoldeDebit = currentSoldeDebit.add(reportsDatas.getAmountSolde()); - } else { - currentSoldeCredit = currentSoldeCredit.add(reportsDatas.getAmountSolde()); + //create pages + int i = 0; + int n = list.size(); + int max = n; + + while (i < n) { + int j = i + max; + if (j > n) { + j = n; } - } - //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(); + List<ReportsDatas> subList = list.subList(i, j); - } catch (FileNotFoundException eeFNFE) { - log.error("Can't create pdf file", eeFNFE); - } catch (DocumentException eeDE) { - log.error("Can't create document", eeDE); - } - } + balanceReport += "<body>\n" + + "<table>" + + "<tr> " + + "<td>" + + "<table align=\"left\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" style=\"font-size:13px;\" >\n" + + "<tr>\n"; - 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)); + String boldItalicBegin = "<b>" + "<i>"; + String boldItalicEnd = "</i>" + "</b>"; - } catch (BadElementException eeBEE) { - log.error("Can't create table", eeBEE); - } - return t; + String [] columnsNameSociety = {boldItalicBegin + _("lima-business.document.society") + + boldItalicEnd, "<i>" + identity.getName()+ "</i>"}; + balanceReport += constructColumnsHtml(columnsNameSociety); - } + balanceReport += "<tr>\n"; + String [] columnsBusinessNumber = {boldItalicBegin + _("lima-business.document.businessnumber") + + boldItalicEnd, "<i>" + identity.getBusinessNumber()+ "</i>"}; + balanceReport += constructColumnsHtml(columnsBusinessNumber); - 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); + balanceReport += "<tr>\n"; + String [] columnsDescription = {boldItalicBegin + _("lima-business.document.description") + boldItalicEnd, + "<i>" + identity.getDescription()+ "</i>"}; + balanceReport += constructColumnsHtml(columnsDescription); - for (ReportsDatas reportsDatas : subList) { + balanceReport += "<tr>\n"; + String [] columnsClassifCode = {boldItalicBegin + _("lima-business.document.classificationcode") + + boldItalicEnd, "<i>" + identity.getClassificationCode()+ "</i>"}; + balanceReport += constructColumnsHtml(columnsClassifCode); - String soldeDebit = String.valueOf(reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0); - String soldeCredit = String.valueOf(reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde()); + balanceReport += "<tr>\n"; + String [] columnsVatNumber = {boldItalicBegin + _("lima-business.document.vatnumber") + boldItalicEnd, + "<i>" + identity.getVatNumber()+ "</i>", }; + balanceReport += constructColumnsHtml(columnsVatNumber); - 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); + balanceReport += "<tr>\n"; + String [] columnsAdressOne = {boldItalicBegin + _("lima-business.document.adress") + boldItalicEnd, + "<i>" + identity.getAddress() + "</i>"}; + balanceReport += constructColumnsHtml(columnsAdressOne); - } - return t; - } + balanceReport += "<tr>\n"; + String [] columnsAdressTwo = {boldItalicBegin + _("lima-business.document.adresssuite") + boldItalicEnd, + "<i>" + identity.getAddress2() + "</i>"}; + balanceReport += constructColumnsHtml(columnsAdressTwo); - public Table createBalanceAmountTable(String title, - BigDecimal amountDebit, - BigDecimal amountCredit, - BigDecimal soldeDebit, - BigDecimal 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); + balanceReport += "<tr>\n"; + String [] columnsZipCode = {boldItalicBegin + _("lima-business.document.zipcode") + boldItalicEnd, + "<i>" + identity.getZipCode() + "</i>"}; + balanceReport += constructColumnsHtml(columnsZipCode); - 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); + balanceReport += "<tr>\n"; + String [] columnsCity = {boldItalicBegin + _("lima-business.document.city") + boldItalicEnd, + "<i>" + identity.getCity()+ "</i>"}; + balanceReport += constructColumnsHtml(columnsCity); + + balanceReport += "<tr>\n"; + String [] columnsPeriodOne = {boldItalicBegin + _("lima-business.document.period1") + boldItalicEnd, "<i>" + + _("lima-business.document.period1format", beginDate)+ "</i>"}; + balanceReport += constructColumnsHtml(columnsPeriodOne); + + balanceReport += "<tr>\n"; + String [] columnsPeriodTwo = {boldItalicBegin + _("lima-business.document.period2") + boldItalicEnd, "<i>" + + _("lima-business.document.period2format", endDate)+ "</i>"}; + balanceReport += constructColumnsHtml(columnsPeriodTwo); + + balanceReport += "</table>\n" + + "</td>" + + "<td valign=\"middle\" align=\"center\" style=\"width:100%\">" + + "<p style=\"font-size:30px;\">" + _("lima-business.document.balance") + "</p>" + + "</td>" + + "<tr>" + + "</table>" + + "<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n" + + "<tr align=\"center\">\n"; + + String [] columnsNames = {_("lima-business.document.accountnumber"), _("lima-business.document.description"), + _("lima-business.document.movementdebit"), _("lima-business.document.movementcredit"), + _("lima-business.document.soldedebit"), _("lima-business.document.soldecredit")}; + balanceReport += constructColumnsHtml(columnsNames); + + if (n > max) { + String boldBegin = "<b>"; + String boldEnd = "</b>"; + String [] columnsBalanceAmount = {"", boldBegin + _("lima-business.document.carryback") + boldEnd, + boldBegin + currentAmountDebit.toString() + boldEnd, boldBegin + currentAmountCredit.toString() + boldEnd, + boldBegin + currentSoldeDebit.toString() + boldEnd,boldBegin + currentSoldeCredit.toString() + boldEnd}; + balanceReport += constructColumnsHtml(columnsBalanceAmount); + balanceReport += "</table>\n"; + } + + for (ReportsDatas reportsDatas : subList) { + String soldeDebit = String.valueOf(reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0); + String soldeCredit = String.valueOf(reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde()); + + String [] columnsBalanceAmount = {reportsDatas.getAccount().getAccountNumber(), reportsDatas.getAccount().getLabel(), + reportsDatas.getAmountDebit().toString(), reportsDatas.getAmountCredit().toString(), + soldeDebit, soldeCredit}; + balanceReport += constructColumnsHtml(columnsBalanceAmount); + } + + for (ReportsDatas reportsDatas : subList) { + currentAmountDebit = currentAmountDebit.add(reportsDatas.getAmountDebit()); + currentAmountCredit = currentAmountCredit.add(reportsDatas.getAmountCredit()); + if (reportsDatas.getSoldeDebit()) { + currentSoldeDebit = currentSoldeDebit.add(reportsDatas.getAmountSolde()); + } else { + currentSoldeCredit = currentSoldeCredit.add(reportsDatas.getAmountSolde()); + } + } + + if (n > max && i <= n - max) { + String boldBegin = "<b>"; + String boldEnd = "</b>"; + String [] columnsBalanceAmount = {"", boldBegin + _("lima-business.document.carryforward") + boldEnd, + boldBegin + currentAmountDebit.toString() + boldEnd, boldBegin + currentAmountCredit.toString() + boldEnd, + boldBegin + currentSoldeDebit.toString() + boldEnd,boldBegin + currentSoldeCredit.toString() + boldEnd}; + balanceReport += constructColumnsHtml(columnsBalanceAmount); + balanceReport += "</table>\n"; + } + + //final amounts + if (i >= n - max) { + String boldBegin = "<b>"; + String boldEnd = "</b>"; + String [] columnsBalanceAmount = {"", boldBegin + _("lima-business.document.amounts") + boldEnd, + boldBegin + currentAmountDebit.toString() + boldEnd, boldBegin + currentAmountCredit.toString() + boldEnd, + boldBegin + currentSoldeDebit.toString() + boldEnd,boldBegin + currentSoldeCredit.toString() + boldEnd}; + balanceReport += constructColumnsHtml(columnsBalanceAmount); + balanceReport += "</table>\n"; + } + i = i + max; + } + balanceReport += "</body>\n</html>"; + } catch (Exception ex) { + log.error("Can't create document", ex); + } } - return t; + + return balanceReport; } //############## General EntryBook ############## Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -162,6 +162,7 @@ String accountReport = null; String entryBooksReport = null; String generalEntryBooksReport = null; + String balanceReport = null; //create docs try { @@ -170,8 +171,8 @@ switch (DocumentsEnum.valueOfLink(model)) { case BALANCE: - documentService.createBalanceDocuments( - beginDateFormat, endDateFormat, formatsEnum); + balanceReport = documentService.createBalanceDocuments( + beginDateFormat, endDateFormat); break; case ACCOUNT: accountReport = documentService.createAccountDocument( @@ -222,14 +223,17 @@ } resp.setContentType(formatsEnum.getMimeType()); OutputStream out = resp.getOutputStream(); - if (accountReport != null || entryBooksReport != null || generalEntryBooksReport != null) { + if (accountReport != null || entryBooksReport != null || generalEntryBooksReport != null + || balanceReport != null) { String report = null; if (accountReport != null) { report = accountReport; } else if (entryBooksReport != null) { report = entryBooksReport; + } else if (generalEntryBooksReport != null) { + report = generalEntryBooksReport; } else { - report = generalEntryBooksReport; + report = balanceReport; } IOUtils.write(report, out, Charsets.UTF_8); } else { 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 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2012-08-17 14:41:36 UTC (rev 3611) @@ -19,12 +19,15 @@ lima-business.defaultaccountingrules.missingentrybook=Can't block financialperiod / missing EntryBook in transactions lima-business.document.account= lima-business.document.accountnumber=Account N° +lima-business.document.adress= +lima-business.document.adresssuite= lima-business.document.amounts=Amounts lima-business.document.amountsperiod=Amounts %1$tB %1$tY lima-business.document.balance=Balance lima-business.document.businessnumber=Business N° lima-business.document.carryback=Carry Back lima-business.document.carryforward=reporterÀ +lima-business.document.city= lima-business.document.classificationcode=Classification Code lima-business.document.createdate=Editing Date %1$tm/%1$te/%1$tY at %1$tH\:%1$tM lima-business.document.credit=Credit @@ -52,12 +55,14 @@ lima-business.document.period2=to lima-business.document.period2format=%1$tm/%1$te/%1$tY lima-business.document.provisiondeprecationamount=Provision Deprecation Amount +lima-business.document.society= lima-business.document.solde=Solde lima-business.document.soldecredit=Credit solde lima-business.document.soldedebit=Debit solde lima-business.document.vat=VAT form lima-business.document.vatnumber=VAT N° lima-business.document.voucher=Voucher +lima-business.document.zipcode= lima-business.entrybook.entrybookalreadyexist=An EntryBook already exists with this label \: %s lima-business.financialstatement.check.nothing=Not found \: %s - %s \n lima-business.financialstatement.check.warn=Warning this function is just an help.\n Many accounts must no calculate on Financial statement.\n Some account marked not found is normally.\n\n 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 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2012-08-17 14:41:36 UTC (rev 3611) @@ -19,12 +19,15 @@ lima-business.defaultaccountingrules.missingentrybook=Impossible de bloquer la période financière / il manque un journal dans une transaction (%1$te/%1$tm/%1$tY) lima-business.document.account= lima-business.document.accountnumber=N° Compte +lima-business.document.adress=Adresse +lima-business.document.adresssuite=Adresse - suite lima-business.document.amounts=Totaux lima-business.document.amountsperiod=Totaux %1$tB %1$tY lima-business.document.balance=Balance lima-business.document.businessnumber=N° Siret lima-business.document.carryback=Report lima-business.document.carryforward=À reporter +lima-business.document.city=Ville lima-business.document.classificationcode=NAF lima-business.document.createdate=Date de tirage %1$te/%1$tm/%1$tY à %1$tH\:%1$tM lima-business.document.credit=Crédit @@ -52,12 +55,14 @@ lima-business.document.period2=au lima-business.document.period2format=%1$te/%1$tm/%1$tY lima-business.document.provisiondeprecationamount=Amortissements et provisions +lima-business.document.society=Nom lima-business.document.solde=Solde lima-business.document.soldecredit=Solde Créditeur lima-business.document.soldedebit=Solde Débiteur lima-business.document.vat=Déclaration de TVA lima-business.document.vatnumber=N° TVA lima-business.document.voucher=Pièce comptable +lima-business.document.zipcode=Code postal lima-business.entrybook.entrybookalreadyexist=Un journal existe déjà avec ce libellé \: %s lima-business.financialstatement.check.nothing=Introuvable \: %s - %s \n lima-business.financialstatement.check.warn=Attention cette fonctionnalité n'est qu'une aide utilisateur.\n Certains comptes ne doivent pas être présent au bilan et compte de résultat.\n Il est donc normal que des comptes sont marqués comme introuvable.\n\n Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/DocumentService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/DocumentService.java 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/DocumentService.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -42,7 +42,7 @@ void createLedgerDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; - void createBalanceDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; + String createBalanceDocuments(Date beginDate, Date endDate) throws LimaException; String createEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -38,7 +38,7 @@ import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.accountsreports.AccountsReportsView; -import org.chorem.lima.ui.balance.BalanceView; +import org.chorem.lima.ui.balance.BalanceReportsView; import org.chorem.lima.ui.entrybook.EntryBookView; import org.chorem.lima.ui.entrybooksreports.EntryBooksReportsView; import org.chorem.lima.ui.financialperiod.FinancialPeriodView; @@ -451,7 +451,7 @@ public void showBalanceView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - BalanceView balanceView = new BalanceView(mainView); + BalanceReportsView balanceView = new BalanceReportsView(mainView); showTab(mainView, _("lima.reports.balance"), balanceView); swingSession.add(balanceView); } Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsView.jaxx (from rev 3587, trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsView.jaxx 2012-08-17 14:41:36 UTC (rev 3611) @@ -0,0 +1,56 @@ +<!-- + #%L + Lima Swing + + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> + +<Table> + + <import> + javax.swing.ListSelectionModel + javax.swing.text.Document + org.jdesktop.swingx.decorator.HighlighterFactory + org.chorem.lima.business.utils.FormatsEnum + org.chorem.lima.enums.ComboBoxDatesEnum + org.chorem.lima.ui.common.IntervalPanel + </import> + + <BalanceReportsViewHandler id="handler" constructorParams="this"/> + + <script> + <![CDATA[ + void $afterCompleteSetup() { + handler.init(); + } + + ]]> + </script> + <row> + <cell columns="1"> + <IntervalPanel id="intervalPanel"/> + </cell> + <cell> + <JButton text="lima.common.ok" + onActionPerformed="getHandler().createDocument()"/> + </cell> + </row> +</Table> \ No newline at end of file Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsView.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsViewHandler.java (from rev 3587, trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsViewHandler.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -0,0 +1,110 @@ +/* + * #%L + * Lima Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.ui.balance; + +import java.awt.Desktop; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaConfig; +import org.chorem.lima.business.api.FinancialPeriodService; +import org.chorem.lima.business.api.FiscalPeriodService; +import org.chorem.lima.business.api.HttpServerService; +import org.chorem.lima.business.api.ReportService; +import org.chorem.lima.business.utils.DocumentsEnum; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; + +/** + * Handler associated with accounts reports view. + * By : $Author$ + */ +public class BalanceReportsViewHandler { + + protected BalanceReportsView view; + + /** log. */ + private static final Log log = LogFactory.getLog(BalanceReportsViewHandler.class); + + /** Services. */ + protected ReportService reportService; + protected HttpServerService httpServerServiceMonitorable; + protected FiscalPeriodService fiscalPeriodService; + protected FinancialPeriodService financialPeriodService; + + private static SimpleDateFormat dateFormat = + new SimpleDateFormat("yyyy-MM-dd"); + + protected BalanceReportsViewHandler(BalanceReportsView view) { + this.view = view; + + reportService = LimaServiceFactory.getService(ReportService.class); + fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); + financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); + } + + /** + * Init data models and displayed objects. + */ + public void init() { + + // init data models + List<FiscalPeriod> fiscalPeriod = fiscalPeriodService.getAllBlockedFiscalPeriods(); + List<FinancialPeriod> financialPeriod = financialPeriodService.getUnblockedFinancialPeriods(); + view.getIntervalPanel().init(fiscalPeriod, financialPeriod); + } + + public void createDocument() { + + Date beginDate = view.getIntervalPanel().getBeginDate(); + Date endDate = view.getIntervalPanel().getEndDate(); + + if (beginDate != null & endDate != null) { + String address = LimaConfig.getInstance().getHostAdress(); + + try { + int port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); + String url = "http://" + address + ":" + port + "/?beginDate=" + + dateFormat.format(beginDate) + + "&endDate=" + dateFormat.format(endDate) + "&format=.html&model=" + + DocumentsEnum.BALANCE.getFileName(); + Desktop.getDesktop().browse(new URI(url)); + } catch (IOException e) { + log.error("Can't open browser", e); + } catch (URISyntaxException e) { + log.error("Can't create news URI", e); + } + } + } + +} Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceReportsViewHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: 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 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceView.jaxx 2012-08-17 14:41:36 UTC (rev 3611) @@ -1,113 +0,0 @@ -<!-- - #%L - Lima Swing - - $Id$ - $HeadURL$ - %% - Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU 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 Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> - -<Table> - - <import> - javax.swing.ListSelectionModel - javax.swing.text.Document - org.jdesktop.swingx.decorator.HighlighterFactory - org.chorem.lima.business.utils.FormatsEnum - org.chorem.lima.enums.ComboBoxDatesEnum - org.chorem.lima.ui.common.IntervalPanel - </import> - - <BalanceViewHandler id="handler" constructorParams="this"/> - - <script> - <![CDATA[ - void $afterCompleteSetup() { - handler.init(); - } - - ]]> - </script> - <row weightx="1" weighty="0" anchor="center"> - <cell fill='both'> - <IntervalPanel id="intervalPanel" onIntervalChanged="handler.intervalChanged()" /> - </cell> - <cell anchor="east"> - <JLabel text="lima.common.filter"/> - </cell> - <cell anchor="west"> - <JTextField id='balanceFilter' toolTipText="lima.tooltip.filter" - minimumSize='{balanceFilter.getPreferredSize()}'/> - <Document javaBean="balanceFilter.getDocument()" - onInsertUpdate='handler.accountFilterChanged()' - onRemoveUpdate='handler.accountFilterChanged()'/> - </cell> - <cell anchor="center"> - <JCheckBox id='movmentedFilter' text='lima.common.movmentedfilter' - selected='false' - onActionPerformed="getHandler().movmentedFilterChanged()"/> - </cell> - <cell> - <EnumEditor id='DocumentEditor' constructorParams='FormatsEnum.class'/> - </cell> - <cell> - <JButton text="lima.common.ok" - onActionPerformed="getHandler().createDocument()"/> - </cell> - </row> - <row> - <cell fill="both" weightx="1" weighty="1" columns="8"> - <JScrollPane> - <BalanceTableModel id="balanceTableModel" /> - <BalanceTable id="balanceTable" - rowHeight="24" - model="{balanceTableModel}" - highlighters="{HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - columnControlVisible="true"/> - </JScrollPane> - </cell> - </row> - <row> - <cell fill="horizontal" weightx="1" columns="7"> - <Table> - <row fill="horizontal" weightx="1"> - <cell> - <JLabel text="lima.common.amountdebit"/> - </cell> - <cell> - <JLabel id="amountDebitLabel"/> - </cell> - <cell> - <JLabel text="lima.common.amountcredit"/> - </cell> - <cell> - <JLabel id="amountCreditLabel"/> - </cell> - <cell> - <JLabel text="lima.common.solde"/> - </cell> - <cell> - <JLabel id="amountSoldeLabel"/> - </cell> - </row> - </Table> - </cell> - </row> -</Table> \ No newline at end of file Deleted: 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 2012-08-17 11:03:36 UTC (rev 3610) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2012-08-17 14:41:36 UTC (rev 3611) @@ -1,216 +0,0 @@ -/* - * #%L - * Lima Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.ui.balance; - -import static org.nuiton.i18n.I18n._; - -import java.awt.Desktop; -import java.io.IOException; -import java.math.BigDecimal; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; - -import javax.swing.JOptionPane; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.LimaConfig; -import org.chorem.lima.beans.BalanceTrial; -import org.chorem.lima.business.ServiceListener; -import org.chorem.lima.business.api.FinancialPeriodService; -import org.chorem.lima.business.api.FinancialTransactionService; -import org.chorem.lima.business.api.FiscalPeriodService; -import org.chorem.lima.business.api.HttpServerService; -import org.chorem.lima.business.api.ImportService; -import org.chorem.lima.business.api.ReportService; -import org.chorem.lima.business.utils.DocumentsEnum; -import org.chorem.lima.business.utils.FormatsEnum; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.service.LimaServiceFactory; - -/** - * Handler associated with accounts reports view. - * By : $Author$ - */ -public class BalanceViewHandler implements ServiceListener { - - protected BalanceView view; - - /** log. */ - private static final Log log = LogFactory.getLog(BalanceViewHandler.class); - - /** Services. */ - protected ReportService reportService; - protected HttpServerService httpServerServiceMonitorable; - protected FiscalPeriodService fiscalPeriodService; - protected FinancialPeriodService financialPeriodService; - - private static SimpleDateFormat dateFormat = - new SimpleDateFormat("yyyy-MM-dd"); - - protected BalanceViewHandler(BalanceView view) { - this.view = view; - - reportService = LimaServiceFactory.getService(ReportService.class); - fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); - financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); - LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this); - } - - /** - * Init data models and displayed objects. - */ - public void init() { - - // init data models - List<FiscalPeriod> fiscalPeriod = fiscalPeriodService.getAllUnblockedFiscalPeriods(); - List<FinancialPeriod> financialPeriod = financialPeriodService.getUnblockedFinancialPeriods(); - view.getIntervalPanel().init(fiscalPeriod, financialPeriod); - } - - public void intervalChanged() { - refreshData(); - } - - public void accountFilterChanged() { - refreshData(); - } - - public void movmentedFilterChanged() { - refreshData(); - } - - /** - * Refresh table data depending on item selected on combo boxes. - */ - protected void refreshData() { - - Date beginDate = view.getIntervalPanel().getBeginDate(); - Date endDate = view.getIntervalPanel().getEndDate(); - - String account = view.getBalanceFilter().getText().trim(); - - if (beginDate != null && endDate != null) { - BalanceTrial balanceTrial = reportService.generateBalanceTrial(beginDate, - endDate, account, false, view.getMovmentedFilter().isSelected()); - - BalanceTableModel dataModel = view.getBalanceTableModel(); - dataModel.setBalanceTrial(balanceTrial); - - updateFooter(balanceTrial); - } - } - - /** - * Update footer labels containing reports total sum fields. - * - * @param balanceTrial result to render - */ - protected void updateFooter(BalanceTrial balanceTrial) { - // set amounts credit and debit and solde - view.amountCreditLabel.setText( - balanceTrial.getAmountCredit().toString()); - view.amountDebitLabel.setText( - balanceTrial.getAmountDebit().toString()); - BigDecimal amountSolde = balanceTrial.getAmountSolde(); - view.amountSoldeLabel.setText(amountSolde.toString()); - - - if (BigDecimal.ZERO.equals(amountSolde)) { - view.amountSoldeLabel.setText(_("lima.common.solde")); - } else { - // set label solde: credit or debit - if (balanceTrial.getSoldeDebit()) { - view.amountSoldeLabel.setText(_("lima.common.soldedebit")); - } else { - view.amountSoldeLabel.setText(_("lima.common.soldecredit")); - } - } - } - - public void createDocument() { - - Date beginDate = view.getIntervalPanel().getBeginDate(); - Date endDate = view.getIntervalPanel().getEndDate(); - - if (beginDate != null & endDate != null) { - - //looks for all blocked fiscal periods - List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); - - //tells if the fiscaPeriod as been found and is blocked - boolean error = true; - - for (FiscalPeriod blockedFiscalPeriod : blockedFiscalPeriods) { - if (blockedFiscalPeriod.getBeginDate().equals(beginDate) - && blockedFiscalPeriod.getEndDate().equals(endDate) - && blockedFiscalPeriod.getLocked()) { - error = false; - } - } - - //shows error message to user if the fiscalPeriod is unblocked - if (error) { - JOptionPane.showMessageDialog( - view, - _("lima.balance.documentcreationfiscalerror"), - _("lima.common.error"), - JOptionPane.ERROR_MESSAGE); - } else { - - FormatsEnum selectedEnum = - (FormatsEnum) view.getDocumentEditor().getSelectedItem(); - String address = LimaConfig.getInstance().getHostAdress(); - - try { - int port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); - String url = "http://" + address + ":" + port + "/?beginDate=" - + dateFormat.format(beginDate) - + "&endDate=" + dateFormat.format(endDate) + "&format=" - + selectedEnum.getExtension() + "&model=" - + DocumentsEnum.BALANCE.getFileName(); - Desktop.getDesktop().browse(new URI(url)); - } catch (IOException e) { - log.error("Can't open browser", e); - } catch (URISyntaxException e) { - log.error("Can't create news URI", e); - } - } - } - } - - @Override - public void notifyMethod(String serviceName, String methodName) { - if (serviceName.contains("FinancialTransaction") || methodName.contains("importAccount") || methodName.contains("importAll")) { - refreshData(); - } - } -}