r3610 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/resources/i18n lima-business-api/src/main/java/org/chorem/lima/business/api lima-swing/src/main/java/org/chorem/lima/ui lima-swing/src/main/java/org/chorem/lima/ui/accountsreports lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports lima-swing/src/main/resources lima-swing/src/main/resources/i18n
Author: mallon Date: 2012-08-17 13:03:36 +0200 (Fri, 17 Aug 2012) New Revision: 3610 Url: http://chorem.org/repositories/revision/lima/3610 Log: refs #769 Modification du jaxx, et mise en place de l affichage html des donnees filtrees, pour l edition des journaux et du journal general. Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTableModel.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 trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties trunk/lima-swing/src/main/resources/log4j.properties 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -28,7 +28,6 @@ import com.lowagie.text.BadElementException; import com.lowagie.text.Cell; import com.lowagie.text.Chapter; -import com.lowagie.text.DocWriter; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; @@ -129,8 +128,6 @@ private static final Font bolditalicFont = new Font(Font.HELVETICA, 9, Font.BOLDITALIC, Color.BLACK); - private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("dd-MM-yyyy"); - public DocumentServiceImpl() { path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); @@ -730,160 +727,102 @@ } @Override - public void createEntryBooksDocuments(Date beginDate, - Date endDate, - FormatsEnum format) throws LimaException { - Document document = new Document(PageSize.A4, 8, 8, 8, 8); - + public String createEntryBooksDocuments(Date beginDate, + Date endDate) throws LimaException { + String entryBookReport; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMMM yyyy"); try { - Date newDate = new Date(); + entryBookReport = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + + "<html>\n"; - String filePath = path + File.separator + DocumentsEnum.ENTRYBOOKS.getFileName(); - FileOutputStream fileOut = new FileOutputStream(filePath + format.getExtension()); - DocWriter writer = null; - switch (format) { - case HTML: - writer = HtmlWriter.getInstance(document, fileOut); - break; - case PDF: - writer = PdfWriter.getInstance(document, fileOut); - break; - } - document.open(); - int nbpages = 1; + String titre = _("lima-business.document.entrybooks"); + entryBookReport += constructHeadHtml(titre); - Identity identity = identityService.getIdentity(); + if (beginDate != null && endDate != null) { - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - getDaoHelper().getClosedPeriodicEntryBookDAO(); - EntryDAO entryDAO = getDaoHelper().getEntryDAO(); - //Split list by financialstatement type - List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = - closedPeriodicEntryBookDAO.findAllByDates(beginDate, endDate); - for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + getDaoHelper().getClosedPeriodicEntryBookDAO(); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); - // TODO echatellier 20120509, was not about only - // balanced transaction here, normal ? - List<Entry> entries = entryDAO.findAllEntryByDateForEntryBook(closedPeriodicEntryBook.getEntryBook(), - closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), - closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); + //Split list by financialstatement type + List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = + closedPeriodicEntryBookDAO.findAllByDates(beginDate, endDate); - List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), - closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), - closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); - BigDecimal debit = BigDecimal.ZERO; - BigDecimal credit = BigDecimal.ZERO; - int nbAmount = results.size(); - if (nbAmount == 2) { - debit = (BigDecimal) results.get(0)[1]; - credit = (BigDecimal) results.get(1)[1]; - } - if (nbAmount == 1) { - if ((Boolean) results.get(0)[0]) { - debit = (BigDecimal) results.get(0)[1]; - } else { - credit = (BigDecimal) results.get(0)[1]; - } - } + entryBookReport += "<body>\n"; + String journal = ""; + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { - //create pages - String title = _("lima-business.document.entrybooktitle", - closedPeriodicEntryBook.getEntryBook().getLabel(), - closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); + // TODO echatellier 20120509, was not about only + // balanced transaction here, normal ? + List<Entry> entries = entryDAO.findAllEntryByDateForEntryBook(closedPeriodicEntryBook.getEntryBook(), + closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), + closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); - //create page - Table table = createEntryBooksTable(entries, debit, credit); - //new page - Chapter chapter = new Chapter(0); - //headerPage - chapter.add(createHeaderPage(title, identity, - beginDate, endDate)); - //n° page - chapter.add(createNumberPage(nbpages, newDate)); - //table - Paragraph paragraphTable = new Paragraph(); - paragraphTable.add(table); - chapter.add(paragraphTable); - //add page - document.add(chapter); + if (entries.size() > 0) { + List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), + closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), + closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); + BigDecimal debit = BigDecimal.ZERO; + BigDecimal credit = BigDecimal.ZERO; + int nbAmount = results.size(); + if (nbAmount == 2) { + debit = (BigDecimal) results.get(0)[1]; + credit = (BigDecimal) results.get(1)[1]; + } + if (nbAmount == 1) { + if ((Boolean) results.get(0)[0]) { + debit = (BigDecimal) results.get(0)[1]; + } else { + credit = (BigDecimal) results.get(0)[1]; + } + } - nbpages++; - } + String subTitleSecPart = _("lima-business.document.date") + " : " + + simpleDateFormat.format(closedPeriodicEntryBook.getFinancialPeriod().getBeginDate()); + if (!journal.equals(closedPeriodicEntryBook.getEntryBook().getLabel())) { + entryBookReport += constructSubTitleHtml(_("lima-business.document.entrybook") + + " : " + closedPeriodicEntryBook.getEntryBook().getLabel(), + subTitleSecPart); + journal = closedPeriodicEntryBook.getEntryBook().getLabel(); + } else { + entryBookReport += constructSubTitleHtml("", subTitleSecPart); + } - document.close(); - writer.close(); - } catch (Exception ex) { - throw new LimaException("Can't create document", ex); - } - } - - protected Table createEntryBooksTable(List<Entry> entries, BigDecimal debit, BigDecimal credit) { - int nbrow = entries.size(); - Table t = null; - try { - //define table - t = new Table(6, nbrow + 1); - t.setWidth(100f); - float[] widths = {0.1f, 0.1f, 0.1f, 0.4f, 0.15f, 0.15f}; - t.setWidths(widths); - t.setPadding(1.5f); - t.setBorderWidth(1); - t.setOffset(0); - - Cell cell1 = new Cell(_("lima-business.document.date")); - cell1.setHeader(true); - t.addCell(cell1); - Cell cell2 = new Cell(_("lima-business.document.accountnumber")); - cell2.setHeader(true); - t.addCell(cell2); - Cell cell3 = new Cell(_("lima-business.document.voucher")); - cell3.setHeader(true); - t.addCell(cell3); - Cell cell4 = new Cell(_("lima-business.document.description")); - cell4.setHeader(true); - t.addCell(cell4); - Cell cell5 = new Cell(_("lima-business.document.debit")); - cell5.setHeader(true); - t.addCell(cell5); - Cell cell6 = new Cell(_("lima-business.document.credit")); - cell6.setHeader(true); - t.addCell(cell6); - t.endHeaders(); + entryBookReport += "<p><table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n" + + "<tr align=\"center\">\n"; - //define default cell - Cell cell = new Cell(); - cell.setBorder(Rectangle.LEFT); - cell.setHorizontalAlignment(Element.ALIGN_RIGHT); - t.setDefaultCell(cell); + String [] columnNames = {_("lima-business.document.date"), _("lima-business.document.accountnumber"), + _("lima-business.document.voucher"), _("lima-business.document.description"), + _("lima-business.document.debit"), + _("lima-business.document.credit")}; - for (Entry entry : entries) { - t.addCell(new Phrase(_("lima-business.document.dateformat", - entry.getFinancialTransaction().getTransactionDate()), normalFont)); - String account = ""; - if (entry.getAccount() != null) { - account = entry.getAccount().getAccountNumber(); + entryBookReport += constructColumnsHtml(columnNames); + + for (Entry entry : entries) { + String numaccount = null; + if (entry.getAccount() != null) { + numaccount = entry.getAccount().getAccountNumber(); + } + String [] columnData = {_("lima-business.document.dateformat", entry.getFinancialTransaction().getTransactionDate()), + (StringUtils.isBlank(numaccount)?"":numaccount), (StringUtils.isBlank(entry.getVoucher())?"":entry.getVoucher()), + (StringUtils.isBlank(entry.getDescription())?"":entry.getDescription()), + (entry.getDebit() ? entry.getAmount() : BigDecimal.ZERO).toString(), + (entry.getDebit() ? BigDecimal.ZERO : entry.getAmount()).toString()}; + + entryBookReport += constructColumnsHtml(columnData); + } + String [] columnDataTotal = {"", "", "", _("lima-business.document.amounts"), debit.toString(), credit.toString()}; + entryBookReport += constructColumnsHtml(columnDataTotal); + entryBookReport += "</table></p>\n"; + } } - t.addCell(new Phrase(account, 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)); + entryBookReport += "</body>\n"; } - - // total - Cell cellTotal = new Cell(new Phrase(_("lima-business.document.amounts"), boldFont)); - cellTotal.setColspan(4); - cellTotal.setHorizontalAlignment(Element.ALIGN_RIGHT); - t.addCell(cellTotal); - t.addCell(new Phrase(debit.toString(), boldFont)); - t.addCell(new Phrase(credit.toString(), boldFont)); - - } catch (BadElementException eeBEE) { - log.error("Can't create table", eeBEE); + } catch (Exception ex) { + throw new LimaException("Can't create document", ex); } - return t; + + return entryBookReport; } //############## Balance ############## @@ -1102,221 +1041,143 @@ @Override - public void createGeneralEntryBooksDocuments(Date beginDate, - Date endDate, - FormatsEnum format) throws LimaException { + public String createGeneralEntryBooksDocuments(Date beginDate, + Date endDate) throws LimaException { - Document document = new Document(PageSize.A4, 8, 8, 8, 8); - + String entryBookReport; try { + entryBookReport = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + + "<html>\n"; - Date newDate = new Date(); + String titre = _("lima-business.document.entrybook"); + entryBookReport += constructHeadHtml(titre); - String filePath = path + File.separator + DocumentsEnum.GENERAL_ENTRYBOOK.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; + if (beginDate != null && endDate != null) { - Identity identity = identityService.getIdentity(); + FinancialPeriodDAO financialPeriodDAO = + getDaoHelper().getFinancialPeriodDAO(); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = + getDaoHelper().getClosedPeriodicEntryBookDAO(); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); - FinancialPeriodDAO financialPeriodDAO = - getDaoHelper().getFinancialPeriodDAO(); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - getDaoHelper().getClosedPeriodicEntryBookDAO(); - EntryDAO entryDAO = getDaoHelper().getEntryDAO(); + List<FinancialPeriod> financialPeriods = + financialPeriodDAO.findByDates(beginDate, endDate); - List<FinancialPeriod> financialPeriods = - financialPeriodDAO.findByDates(beginDate, endDate); + List<GeneralEntryBooksDatas> list = new ArrayList<GeneralEntryBooksDatas>(); + BigDecimal amountDebit = new BigDecimal(0); + BigDecimal amountCredit = new BigDecimal(0); + for (FinancialPeriod financialPeriod : financialPeriods) { + List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = + closedPeriodicEntryBookDAO.findAllByDates( + financialPeriod.getBeginDate(), financialPeriod.getEndDate()); - List<GeneralEntryBooksDatas> list = new ArrayList<GeneralEntryBooksDatas>(); - BigDecimal amountDebit = new BigDecimal(0); - BigDecimal amountCredit = new BigDecimal(0); - for (FinancialPeriod financialPeriod : financialPeriods) { - List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = - closedPeriodicEntryBookDAO.findAllByDates( - financialPeriod.getBeginDate(), financialPeriod.getEndDate()); + BigDecimal subAmountDebit = new BigDecimal(0); + BigDecimal subAmountCredit = new BigDecimal(0); + for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { - BigDecimal subAmountDebit = new BigDecimal(0); - BigDecimal subAmountCredit = new BigDecimal(0); - for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBookList) { + BigDecimal debit = BigDecimal.ZERO; + BigDecimal credit = BigDecimal.ZERO; - BigDecimal debit = BigDecimal.ZERO; - BigDecimal credit = BigDecimal.ZERO; + List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), + closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), + closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); - List<Object[]> results = entryDAO.getDebitCreditOfTransaction(closedPeriodicEntryBook.getEntryBook(), - closedPeriodicEntryBook.getFinancialPeriod().getBeginDate(), - closedPeriodicEntryBook.getFinancialPeriod().getEndDate()); - - int nbAmount = results.size(); - if (nbAmount == 2) { - debit = (BigDecimal) results.get(0)[1]; - credit = (BigDecimal) results.get(1)[1]; - } - if (nbAmount == 1) { - if ((Boolean) results.get(0)[0]) { + int nbAmount = results.size(); + if (nbAmount == 2) { debit = (BigDecimal) results.get(0)[1]; - } else { - credit = (BigDecimal) results.get(0)[1]; + credit = (BigDecimal) results.get(1)[1]; } + if (nbAmount == 1) { + if ((Boolean) results.get(0)[0]) { + debit = (BigDecimal) results.get(0)[1]; + } else { + credit = (BigDecimal) results.get(0)[1]; + } + } + GeneralEntryBooksDatas generalEntryBooksDatas = + new GeneralEntryBooksDatasImpl(); + generalEntryBooksDatas.setCode( + closedPeriodicEntryBook.getEntryBook().getCode()); + generalEntryBooksDatas.setDescription( + closedPeriodicEntryBook.getEntryBook().getLabel()); + + if (log.isDebugEnabled()) { + log.debug("Entrybook code added : " + closedPeriodicEntryBook.getEntryBook().getCode()); + log.debug("Entrybook desc. added : " + closedPeriodicEntryBook.getEntryBook().getLabel()); + } + + generalEntryBooksDatas.setPeriod(financialPeriod.getBeginDate()); + generalEntryBooksDatas.setCredit(credit); + generalEntryBooksDatas.setDebit(debit); + list.add(generalEntryBooksDatas); + subAmountCredit = subAmountCredit.add(credit); + subAmountDebit = subAmountDebit.add(debit); } GeneralEntryBooksDatas generalEntryBooksDatas = new GeneralEntryBooksDatasImpl(); - generalEntryBooksDatas.setCode( - closedPeriodicEntryBook.getEntryBook().getCode()); - generalEntryBooksDatas.setDescription( - closedPeriodicEntryBook.getEntryBook().getLabel()); + generalEntryBooksDatas.setSubAmount(true); + generalEntryBooksDatas.setCredit(subAmountCredit); + generalEntryBooksDatas.setDebit(subAmountDebit); generalEntryBooksDatas.setPeriod(financialPeriod.getBeginDate()); - generalEntryBooksDatas.setCredit(credit); - generalEntryBooksDatas.setDebit(debit); list.add(generalEntryBooksDatas); - subAmountCredit = subAmountCredit.add(credit); - subAmountDebit = subAmountDebit.add(debit); + amountCredit = amountCredit.add(subAmountCredit); + amountDebit = amountDebit.add(subAmountDebit); } GeneralEntryBooksDatas generalEntryBooksDatas = new GeneralEntryBooksDatasImpl(); - generalEntryBooksDatas.setSubAmount(true); - generalEntryBooksDatas.setCredit(subAmountCredit); - generalEntryBooksDatas.setDebit(subAmountDebit); - generalEntryBooksDatas.setPeriod(financialPeriod.getBeginDate()); + generalEntryBooksDatas.setAmount(true); + generalEntryBooksDatas.setCredit(amountCredit); + generalEntryBooksDatas.setDebit(amountDebit); list.add(generalEntryBooksDatas); - amountCredit = amountCredit.add(subAmountCredit); - amountDebit = amountDebit.add(subAmountDebit); - } - GeneralEntryBooksDatas generalEntryBooksDatas = - new GeneralEntryBooksDatasImpl(); - generalEntryBooksDatas.setAmount(true); - generalEntryBooksDatas.setCredit(amountCredit); - generalEntryBooksDatas.setDebit(amountDebit); - list.add(generalEntryBooksDatas); + entryBookReport += "<body>\n" + + "<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n" + + "<tr align=\"center\">\n"; - //create pages - Table headerTable = createGeneralEntryBooksHeaderTable(); - Table table = createGeneralEntryBooksTable(list); - //new page - Chapter chapter = new Chapter(0); - //headerPage - chapter.add(createHeaderPage( - DocumentsEnum.GENERAL_ENTRYBOOK.getDescription(), - identity, beginDate, - endDate)); - //n° page - chapter.add(createNumberPage(nbpages, newDate)); - //headerTable - Paragraph paragraphHeaderTable = new Paragraph(); - paragraphHeaderTable.add(headerTable); - chapter.add(paragraphHeaderTable); - //table - Paragraph paragraphTable = new Paragraph(); - paragraphTable.add(table); - chapter.add(paragraphTable); - //add page - document.add(chapter); - nbpages++; + String[] columnNames = {_("lima-business.document.entrybook"), _("lima-business.document.label"), + _("lima-business.document.date"), _("lima-business.document.debit"), + _("lima-business.document.credit")}; - document.close(); + entryBookReport += constructColumnsHtml(columnNames); + String entryBookCode = ""; - } catch (Exception ex) { - throw new LimaException("Can't generate document", ex); - } - } - - protected 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; - - } - - protected 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(_("lima-business.document.monthformat", generalEntryBooksDatas.getPeriod()), normalFont)); - t.addCell(new Phrase( - String.valueOf(generalEntryBooksDatas.getDebit()), - normalFont)); - t.addCell(new Phrase( - String.valueOf(generalEntryBooksDatas.getCredit()), - normalFont)); - } else { - Phrase phrase; - if (generalEntryBooksDatas.getAmount()) { - phrase = new Phrase(_("lima-business.document.amounts"), - boldFont); - } else { - phrase = new Phrase(_("lima-business.document.amountsperiod", generalEntryBooksDatas.getPeriod()), - boldFont); + for (GeneralEntryBooksDatas generalEntryBooksDataInList : list) { + if (!generalEntryBooksDataInList.getDebit().equals(BigDecimal.ZERO) && !generalEntryBooksDataInList.getCredit().equals(BigDecimal.ZERO)) { + if (!generalEntryBooksDataInList.getAmount() && !generalEntryBooksDataInList.getSubAmount()) { + String code; + String description; + if (!entryBookCode.equals(generalEntryBooksDataInList.getCode())) { + entryBookCode = generalEntryBooksDataInList.getCode(); + code = entryBookCode; + description = generalEntryBooksDataInList.getDescription(); + } else { + code = ""; + description = ""; + } + String[] columnData = {code, description, + _("lima-business.document.monthformat", generalEntryBooksDataInList.getPeriod()), + generalEntryBooksDataInList.getDebit().toString(), + generalEntryBooksDataInList.getCredit().toString()}; + entryBookReport += constructColumnsHtml(columnData); + } else { + String amount; + if (generalEntryBooksDataInList.getAmount()) { + amount = _("lima-business.document.amounts"); + } else { + amount = _("lima-business.document.amountsperiod", generalEntryBooksDataInList.getPeriod()); + } + String[] columnDataTotal = {"", "", "<b>"+ (StringUtils.isBlank(amount)?"":amount) + "</b>", + generalEntryBooksDataInList.getDebit().toString(), + generalEntryBooksDataInList.getCredit().toString()}; + entryBookReport += constructColumnsHtml(columnDataTotal); + } } - 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); + } catch (Exception ex) { + throw new LimaException("Can't generate document", ex); } - return t; + return entryBookReport; } //############## VAT ############## @@ -1397,66 +1258,55 @@ Account accountFormat = accountDAO.findByTopiaId(account); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMMM yyyy"); - accountReport = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + - "<html>\n" + - "<head>\n" + - "<title>"+_("lima.reports.accounts")+"</title>\n" + - "</head>\n" + - "<p align=\"center\">" + - "<font size=5>\n" + - _("lima.reports.accounts") + - "</font>\n" + - "</p>\n" + - "<p>"; + accountReport += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + + "<html>\n"; + String title = _("lima.reports.accounts"); + accountReport = constructHeadHtml(title); + ReportsDatas results; if (beginDate != null && endDate != null && account != null) { - accountReport += "<font size=3>\n" + - _("lima.ui.fiscalperiod.fiscalperiod") + " : " + simpleDateFormat.format(beginDate) + " - " + simpleDateFormat.format(endDate) + - "</p>\n" + - "<p>" + - _("lima.ui.financialtransaction.account") + " : " + accountFormat.getAccountNumber() + " - " + accountFormat.getLabel() + - "</font>"+ - "</p>" + - "<body>\n"; + String subTitleFirstpart = _("lima.ui.fiscalperiod.fiscalperiod") + " : " + simpleDateFormat.format(beginDate) + " - " + simpleDateFormat.format(endDate); + String subTitleSecPart = _("lima.ui.financialtransaction.account") + " : " + accountFormat.getAccountNumber() + " - " + accountFormat.getLabel(); + accountReport += constructSubTitleHtml(subTitleFirstpart, subTitleSecPart); + results = reportService.generateAccountsReports(accountFormat, true, beginDate, endDate); List<Entry> entries = results.getListEntry(); - accountReport += "<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n"; - accountReport += "<tr align=\"center\">\n"; - accountReport +="<td>" + _("lima.table.number") + "</td>\n"; - accountReport +="<td>" + _("lima.table.date") + "</td>\n"; - accountReport +="<td>" + _("lima.table.entrybook") + "</td>\n"; - accountReport +="<td>" + _("lima.table.voucher") + "</td>\n"; - accountReport +="<td>" + _("lima.table.description") + "</td>\n"; - accountReport +="<td>" + _("lima.table.letter") + "</td>\n"; - accountReport +="<td>" + _("lima.table.debit") + "</td>\n"; - accountReport +="<td>" + _("lima.table.credit") + "</td>\n"; - accountReport += "<tr>\n"; + String[] columnNames = {_("lima.table.number"), _("lima.table.date"), _("lima.table.entrybook"), + _("lima.table.voucher"), _("lima.table.decription"), _("lima.table.letter"), + _("lima.table.debit"), _("lima.table.credit")}; + + accountReport += "<body>\n" + + "<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n" + + "<tr align=\"center\">\n"; + + accountReport += constructColumnsHtml(columnNames); + for(Entry entry : entries) { - accountReport += "<tr align=\"center\">\n"; String accountNumber = entry.getAccount().getAccountNumber(); - accountReport += "<td>" + (StringUtils.isBlank(accountNumber)?"":accountNumber) + "</td>\n"; String transactionDate = simpleDateFormat.format(entry.getFinancialTransaction().getTransactionDate()); - accountReport += "<td>" + (StringUtils.isBlank(transactionDate)?"":transactionDate) + "</td>\n"; + String code = ""; if (entry.getFinancialTransaction().getEntryBook() != null) { - String code = entry.getFinancialTransaction().getEntryBook().getCode(); - accountReport += "<td>" + (StringUtils.isBlank(code)?"":code) + "</td>\n"; + code = entry.getFinancialTransaction().getEntryBook().getCode(); } String voucher = entry.getVoucher(); - accountReport += "<td>" + (StringUtils.isBlank(voucher)?"":voucher) + "</td>\n"; String description = entry.getDescription(); - accountReport += "<td>" + (StringUtils.isBlank(description)?"":description) + "</td>\n"; String lettering = entry.getLettering(); - accountReport += "<td>" + (StringUtils.isBlank(lettering)?"":lettering) + "</td>\n"; - accountReport += "<td>" + (entry.getDebit() ? entry.getAmount() : BigDecimal.ZERO) + "</td>\n"; - accountReport += "<td>" + (entry.getDebit() ? BigDecimal.ZERO : entry.getAmount()) + "</td>\n"; - accountReport += "</tr>\n"; + + String[] columnData = {(StringUtils.isBlank(accountNumber)?"":accountNumber), (StringUtils.isBlank(transactionDate)?"":transactionDate), + (StringUtils.isBlank(code)?"":code), (StringUtils.isBlank(voucher)?"":voucher), + (StringUtils.isBlank(description)?"":description), (StringUtils.isBlank(lettering)?"":lettering), + (entry.getDebit() ? entry.getAmount() : BigDecimal.ZERO).toString(), + (entry.getDebit() ? BigDecimal.ZERO : entry.getAmount()).toString()}; + + accountReport += constructColumnsHtml(columnData); } + accountReport += "</table>\n" + "</body>\n"; @@ -1475,4 +1325,44 @@ return accountReport; } + + protected String constructHeadHtml(String title) { + String head = + "<head>\n" + + "<title>"+title+"</title>\n" + + "</head>\n" + + "<p align=\"center\">" + + "<font size=5>\n" + + title + + "</font>\n" + + "</p>\n" + + "<p>"; + + return head; + } + + protected String constructSubTitleHtml(String subTitleFirstpart, String subTitleSecPart) { + String subTitle = "<font size=3>\n" + + subTitleFirstpart + + "</p>\n" + + "<p>" + + subTitleSecPart + + "</font>"+ + "</p>"; + + return subTitle; + } + + protected String constructColumnsHtml(String[] columnsNames) { + + String columns = ""; + + for (String name : columnsNames) { + columns += "<td>" + name + "</td>\n"; + } + columns += "<tr>\n"; + + return columns; + } + } 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -49,6 +49,7 @@ import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -142,7 +143,8 @@ String beginDate = req.getParameter("beginDate"); String endDate = req.getParameter("endDate"); String autocomplete = req.getParameter("autocomplete"); - String account = URLDecoder.decode(req.getParameter("account"), "UTF-8"); + String account = (StringUtils.isBlank(req.getParameter("account"))?null:URLDecoder.decode(req.getParameter("account"), "UTF-8")); + String entryBook = (StringUtils.isBlank(req.getParameter("entryBook"))?null:URLDecoder.decode(req.getParameter("entryBook"), "UTF-8")); //if image if (imageParam != null) { @@ -158,6 +160,8 @@ else if (model != null && format != null && beginDate != null && endDate != null) { FormatsEnum formatsEnum = FormatsEnum.valueOfExtension(format); String accountReport = null; + String entryBooksReport = null; + String generalEntryBooksReport = null; //create docs try { @@ -170,29 +174,27 @@ beginDateFormat, endDateFormat, formatsEnum); break; case ACCOUNT: - if (log.isDebugEnabled()) { - log.debug("Account"); - } - /*AccountDAO accountDAO = new AccountDAO(); - Account accountFormat = accountDAO.findByTopiaId(account);*/ accountReport = documentService.createAccountDocument( beginDateFormat, endDateFormat, account); + break; + case ENTRYBOOKS: + entryBooksReport = documentService.createEntryBooksDocuments( + beginDateFormat, endDateFormat); if (log.isDebugEnabled()) { - log.debug("After creating account document"); + log.debug("EntryBookReport :" + entryBooksReport); } break; - case ENTRYBOOKS: - documentService.createEntryBooksDocuments( - beginDateFormat, endDateFormat, formatsEnum); + case GENERAL_ENTRYBOOK: + generalEntryBooksReport = documentService.createGeneralEntryBooksDocuments( + beginDateFormat, endDateFormat); + if (log.isDebugEnabled()) { + log.debug("GeneralEntryBooksReport :" + generalEntryBooksReport); + } break; case FINANCIALSTATEMENT: documentService.createFinancialStatementsDocuments( beginDateFormat, endDateFormat, formatsEnum); break; - case GENERAL_ENTRYBOOK: - documentService.createGeneralEntryBooksDocuments( - beginDateFormat, endDateFormat, formatsEnum); - break; case LEDGER: documentService.createLedgerDocuments( beginDateFormat, endDateFormat, formatsEnum); @@ -219,16 +221,29 @@ log.debug(accountReport); } resp.setContentType(formatsEnum.getMimeType()); -// InputStream in = doc.openStream(); OutputStream out = resp.getOutputStream(); - if (accountReport != null) { - IOUtils.write(accountReport, out, Charsets.UTF_8); -// out.write(accountReport.getBytes()); + if (accountReport != null || entryBooksReport != null || generalEntryBooksReport != null) { + String report = null; + if (accountReport != null) { + report = accountReport; + } else if (entryBooksReport != null) { + report = entryBooksReport; + } else { + report = generalEntryBooksReport; + } + IOUtils.write(report, out, Charsets.UTF_8); + } else { + InputStream in = doc.openStream(); + IOUtils.copy(in, out); } -// IOUtils.copy(in, out); } // else return home html else { + + if (log.isDebugEnabled()) { + log.debug("Home html"); + } + resp.setContentType(FormatsEnum.HTML.getMimeType()); StringBuilder pageContent = new StringBuilder(); String serverAdress = "http://"; @@ -251,30 +266,30 @@ DateUtils.truncate(beginDatePicker, Calendar.YEAR); pageContent.append("<!DOCTYPE html>\n" - + "<html lang=\"fr\">\n" - + "<head>\n" - + "<title>LIMA Documents Report</title>\n" - + "<style type=\"text/css\">" - + "body { font: 14px sans-serif; }" - + "h1 { font: 20px sans-serif; text-align: center; }" - + "table.padding td {padding-right:20px;}" - + ".tdright {text-align: right;}" - + "</style>" - + "</head>\n" - + "<body>\n" - + "<table class=\"padding\">\n" - + "<tr><td><img src=\"?img=puzzle_icon_mini.png\"/></td>\n" - + "<td><h1>LIMA Documents Report</h1></td></tr>\n" - + "<tr><td class=\"tdright\"><img src=\"?img=identity.png\"/></td>\n" - + "<td rowspan=3><form method=GET action=" - + serverAdress + ">\n" - + _("lima-business.document.date.begin") - + "<input value=\"" + DATEFORMAT.format(beginDatePicker) - + "\" type=\"date\" name=\"beginDate\">\n" - + _("lima-business.document.date.end") - + "<input value=\"" + DATEFORMAT.format(endDatePicker) - + "\" type=\"date\" name=\"endDate\">\n<br/><br/>" - + "Format : <select name=\"format\">"); + + "<html lang=\"fr\">\n" + + "<head>\n" + + "<title>LIMA Documents Report</title>\n" + + "<style type=\"text/css\">" + + "body { font: 14px sans-serif; }" + + "h1 { font: 20px sans-serif; text-align: center; }" + + "table.padding td {padding-right:20px;}" + + ".tdright {text-align: right;}" + + "</style>" + + "</head>\n" + + "<body>\n" + + "<table class=\"padding\">\n" + + "<tr><td><img src=\"?img=puzzle_icon_mini.png\"/></td>\n" + + "<td><h1>LIMA Documents Report</h1></td></tr>\n" + + "<tr><td class=\"tdright\"><img src=\"?img=identity.png\"/></td>\n" + + "<td rowspan=3><form method=GET action=" + + serverAdress + ">\n" + + _("lima-business.document.date.begin") + + "<input value=\"" + DATEFORMAT.format(beginDatePicker) + + "\" type=\"date\" name=\"beginDate\">\n" + + _("lima-business.document.date.end") + + "<input value=\"" + DATEFORMAT.format(endDatePicker) + + "\" type=\"date\" name=\"endDate\">\n<br/><br/>" + + "Format : <select name=\"format\">"); for (FormatsEnum formatsEnum : FormatsEnum.values()) { pageContent.append("<option value=\"" 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2012-08-17 11:03:36 UTC (rev 3610) @@ -35,6 +35,7 @@ lima-business.document.debit=Debit lima-business.document.description=Description lima-business.document.entrybook=EntryBook +lima-business.document.entrybooks= lima-business.document.entrybooktitle=%s\n%2$tB %2$tY lima-business.document.financialstatement=FinancialStatement lima-business.document.generalentrybook=General EntryBook @@ -103,4 +104,15 @@ lima.config.serveraddress.description=Server Address lima.reports.account.noaccount= lima.reports.account.noaccounttitle= +lima.reports.accounts= +lima.table.credit= +lima.table.date= +lima.table.debit= +lima.table.decription= +lima.table.entrybook= +lima.table.letter= +lima.table.number= +lima.table.voucher= +lima.ui.financialtransaction.account= +lima.ui.fiscalperiod.fiscalperiod= lima.ui.lettering.accountRegularization= 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2012-08-17 11:03:36 UTC (rev 3610) @@ -35,6 +35,7 @@ lima-business.document.debit=Débit lima-business.document.description=Description lima-business.document.entrybook=Journal +lima-business.document.entrybooks=Journaux lima-business.document.entrybooktitle=%s\n%2$tB %2$tY lima-business.document.financialstatement=Bilan et compte de résultat lima-business.document.generalentrybook=Journal Général @@ -103,4 +104,15 @@ lima.config.serveraddress.description=Addresse serveur lima.reports.account.noaccount= lima.reports.account.noaccounttitle= +lima.reports.accounts= +lima.table.credit= +lima.table.date= +lima.table.debit= +lima.table.decription= +lima.table.entrybook= +lima.table.letter= +lima.table.number= +lima.table.voucher= +lima.ui.financialtransaction.account= +lima.ui.fiscalperiod.fiscalperiod= lima.ui.lettering.accountRegularization= 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/DocumentService.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -27,7 +27,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.business.utils.FormatsEnum; -import org.chorem.lima.entity.Account; import java.util.Date; @@ -43,12 +42,12 @@ void createLedgerDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; - void createEntryBooksDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; - void createBalanceDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; - void createGeneralEntryBooksDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException; + String createEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException; + String createGeneralEntryBooksDocuments(Date beginDate, Date endDate) throws LimaException; + void createVatDocuments(Date beginDate, Date endDate, FormatsEnum format, String autocomplete) throws LimaException; String createAccountDocument(Date beginDate, Date endDate, String account) 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-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -492,6 +492,10 @@ String address = LimaConfig.getInstance().getHostAdress(); String url = "http://" + address + ":" + port + "/"; + if (log.isDebugEnabled()) { + log.debug("URL : " + url); + } + SwingUtil.openLink(url); } Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTable.java 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTable.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -1,97 +0,0 @@ -/* - * #%L - * Lima :: Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2011 CodeLutin - * %% - * 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.accountsreports; - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.math.BigDecimal; - -import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; -import org.jdesktop.swingx.JXTable; - -public class AccountsReportsTable extends JXTable - implements KeyListener, MouseListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 6093850347322834480L; - - public AccountsReportsTable() { - - addKeyListener(this); - addMouseListener(this); - - //Get new BigDecimal renderer - setDefaultRenderer(BigDecimal.class, new BigDecimalTableCellRenderer()); - - } - - @Override - public void mouseClicked(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - if (rowAtPoint(e.getPoint()) == -1) { - clearSelection(); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void keyTyped(KeyEvent e) { - } - - /** - * for each action combination key are think - * for extend keyboard and laptop keyboard - */ - @Override - public void keyPressed(KeyEvent e) { - // clear row selection with the key: escape - if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - if (!isEditing()) { - clearSelection(); - } - } - } - - @Override - public void keyReleased(KeyEvent e) { - } - -} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTableModel.java 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsTableModel.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -1,196 +0,0 @@ -/* - * #%L - * Lima Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * 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.accountsreports; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.ReportsDatas; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.Entry; - -import javax.swing.table.AbstractTableModel; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static org.nuiton.i18n.I18n._; - -/** - * Entry book table model. - * By : $Author$ - */ -public class AccountsReportsTableModel extends AbstractTableModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = 1L; - - /** log. */ - private static final Log log = LogFactory.getLog(AccountsReportsTableModel.class); - - /** data cache */ - protected ReportsDatas reportDatas; - - @Override - public int getRowCount() { - int result = 0; - - // just prevent too much result - if (reportDatas != null) { - if (reportDatas.getListEntry() != null) { - result = reportDatas.getListEntry().size(); - } - } - - return result; - } - - @Override - public int getColumnCount() { - return 8; - } - - @Override - public Class<?> getColumnClass(int column) { - - Class<?> result = null; - - switch (column) { - case 0: - result = Account.class; - break; - case 1: - result = Date.class; - break; - case 2: - result = Entry.class; - break; - case 3: - result = String.class; - break; - case 4: - result = String.class; - break; - case 5: - result = String.class; - break; - case 6: - result = BigDecimal.class; - break; - case 7: - result = BigDecimal.class; - break; - } - - return result; - } - - - @Override - public String getColumnName(int column) { - String res = "n/a"; - switch (column) { - case 0: - res = _("lima.table.account"); //Account Number - break; - case 1: - res = _("lima.table.date"); //Date - break; - case 2: - res = _("lima.table.entrybook"); //EntryBook - break; - case 3: - res = _("lima.table.voucher"); // Voucher - break; - case 4: - res = _("lima.table.description"); //Description - break; - case 5: - res = _("lima.table.letter"); //Letter - break; - case 6: - res = _("lima.table.debit"); //Debit - break; - case 7: - res = _("lima.table.credit"); //Credit - break; - } - return res; - } - - @Override - public Object getValueAt(int row, int column) { - Object result = null; - if (reportDatas != null) { - Entry currentRow = reportDatas.getListEntry().get(row); - // FIXME echatellier 20120515, move it to renderer - SimpleDateFormat simpleDateFormat - = new SimpleDateFormat("dd MMMMM yyyy"); - - switch (column) { - case 0: - result = currentRow.getAccount().getAccountNumber(); - break; - case 1: - result = simpleDateFormat. - format(currentRow.getFinancialTransaction().getTransactionDate()); - break; - case 2: - if (currentRow.getFinancialTransaction().getEntryBook() != null) { - result = currentRow.getFinancialTransaction().getEntryBook().getCode(); - } else { - result = null; - } - break; - case 3: - result = currentRow.getVoucher(); - break; - case 4: - result = currentRow.getDescription(); - break; - case 5: - result = currentRow.getLettering(); - break; - case 6: - result = currentRow.getDebit() ? currentRow.getAmount() : BigDecimal.ZERO; - break; - case 7: - result = currentRow.getDebit() ? BigDecimal.ZERO : currentRow.getAmount(); - break; - } - } else { - if (log.isDebugEnabled()) { - log.debug("No Account selected skip table model update"); - } - } - - return result; - } - - public void setReportDatas(ReportsDatas reportDatas) { - this.reportDatas = reportDatas; - fireTableDataChanged(); - } -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2012-08-17 11:03:36 UTC (rev 3610) @@ -23,7 +23,7 @@ #L% --> -<Table> +<Table constraints='BorderLayout.NORTH'> <import> javax.swing.ListSelectionModel org.chorem.lima.ui.common.IntervalPanel @@ -37,71 +37,30 @@ } ]]></script> - <row weightx="1" weighty="0" anchor="center"> - <cell fill='both'> - <IntervalPanel id="intervalPanel" onIntervalChanged="handler.intervalChanged()" /> - </cell> - <cell anchor="east"> - <JLabel id="entryBookSelectorLabel" text="lima.common.entrybook"/> - </cell> - <cell anchor="west"> - <org.chorem.lima.ui.common.EntryBookComboBoxModel id="entryBookModel" /> - <EntryBookComboBox id="entryBookCombo" model="{entryBookModel}" - renderer="{new org.chorem.lima.ui.common.EntryBookListRenderer()}" - onItemStateChanged="handler.entryBookChanged(event)"/> - </cell> - <cell> - <JButton id="back" text="lima.common.buttonback" - onActionPerformed="entryBookCombo.back()"/> - </cell> - <cell> - <JButton id="next" text="lima.common.buttonnext" - onActionPerformed="entryBookCombo.next()"/> - </cell> - <cell> - <EnumEditor id='DocumentEditor' - constructorParams='org.chorem.lima.business.utils.FormatsEnum.class'/> - </cell> - <cell> - <JButton text="lima.common.ok" - onActionPerformed="getHandler().createDocument()"/> - </cell> - </row> <row> - <cell fill="both" weightx="1" weighty="1" columns="7"> - <JScrollPane> - <EntryBooksReportsTableModel id="entryBookReportsTableModel" /> - <EntryBooksReportsTable id="reportTable" sortable="false" rowHeight="24" - constructorParams="entryBookReportsTableModel" - model="{entryBookReportsTableModel}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}"/> - </JScrollPane> - </cell> + <cell columns="3"> + <Table> + <row> + <cell anchor="center"> + <JLabel text="lima-business.document.entrybooks"/> + </cell> + <cell anchor="center"> + <JLabel text=" - "/> + </cell> + <cell anchor="center"> + <JLabel text="lima-business.document.generalentrybook"/> + </cell> + </row> + </Table> + </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 id="soldeLabel" text="lima.common.solde"/> - </cell> - <cell> - <JLabel id="amountSoldeLabel"/> - </cell> - </row> - </Table> + <cell columns="2"> + <IntervalPanel id="intervalPanel"/> </cell> + <cell columns="1"> + <JButton text="lima.common.ok" + onActionPerformed="getHandler().createDocument()"/> + </cell> </row> -</Table> \ No newline at end of file +</Table> 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 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-08-17 11:03:36 UTC (rev 3610) @@ -25,36 +25,24 @@ package org.chorem.lima.ui.entrybooksreports; -import static org.nuiton.i18n.I18n._; - import java.awt.Desktop; -import java.awt.event.ItemEvent; 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.ReportsDatas; -import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.DocumentService; import org.chorem.lima.business.api.EntryBookService; 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.EntryBook; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; @@ -64,7 +52,7 @@ * * By : $Author$ */ -public class EntryBooksReportsViewHandler implements ServiceListener { +public class EntryBooksReportsViewHandler{ /** log. */ private static final Log log = LogFactory.getLog(EntryBooksReportsViewHandler.class); @@ -90,81 +78,19 @@ entryBookService = LimaServiceFactory.getService(EntryBookService.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); - LimaServiceFactory.addServiceListener(ImportService.class, this); - LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this); + /*LimaServiceFactory.addServiceListener(ImportService.class, this); + LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this);*/ } /** * Init data models and displayed objects. */ public void init() { - - // init data models - List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); - view.getEntryBookModel().setObjects(entryBooks); - List<FiscalPeriod> fiscalPeriod = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); List<FinancialPeriod> financialPeriod = financialPeriodService.getUnblockedFinancialPeriods(); - view.getIntervalPanel().init(fiscalPeriod, financialPeriod); + view.getIntervalPanel().init(blockedFiscalPeriods, financialPeriod); } - - public void intervalChanged() { - refreshData(); - } - protected void entryBookChanged(ItemEvent event) { - if (event.getStateChange() == ItemEvent.SELECTED) { - refreshData(); - } - } - - /** - * Refresh table data depending on item selected on combo boxes. - */ - protected void refreshData() { - - Date beginDate = view.getIntervalPanel().getBeginDate(); - Date endDate = view.getIntervalPanel().getEndDate(); - - EntryBook entryBook = (EntryBook)view.getEntryBookCombo().getModel().getSelectedItem(); - - if (beginDate != null && endDate != null && entryBook != null) { - ReportsDatas results = reportService.generateEntryBooksReports(entryBook, - beginDate, endDate); - - EntryBooksReportsTableModel dataModel = view.getEntryBookReportsTableModel(); - dataModel.setReportDatas(results); - - updateFooter(results); - } - } - - /** - * Update footer labels containing reports total sum fields. - * - * @param reportsDatas result to render - */ - protected void updateFooter(ReportsDatas reportsDatas) { - // set amounts credit and debit and solde - view.amountCreditLabel.setText( - reportsDatas.getAmountCredit().toString()); - view.amountDebitLabel.setText( - reportsDatas.getAmountDebit().toString()); - BigDecimal amountSolde = reportsDatas.getAmountSolde(); - view.amountSoldeLabel.setText(amountSolde.toString()); - - - if (BigDecimal.ZERO.equals(amountSolde)) { - view.soldeLabel.setText(_("lima.common.solde")); - } else { - // set label solde: credit or debit - if (reportsDatas.getSoldeDebit()) { - view.soldeLabel.setText(_("lima.common.soldedebit")); - } else { - view.soldeLabel.setText(_("lima.common.soldecredit")); - } - } - } - public void createDocument() { Date beginDate = view.getIntervalPanel().getBeginDate(); @@ -172,61 +98,29 @@ if (beginDate != null && endDate != null) { - //looks for all blocked fiscal periods - List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); + int port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); + String address = LimaConfig.getInstance().getHostAdress(); - //tells if the fiscaPeriod as been found and is blocked - boolean error = true; + try { + String url = "http://" + address + ":" + port + "/?beginDate=" + + dateFormat.format(beginDate) + + "&endDate=" + dateFormat.format(endDate) + + "&format=.html&model=" + + DocumentsEnum.ENTRYBOOKS.getFileName(); + Desktop.getDesktop().browse(new URI(url)); - for (FiscalPeriod blockedFiscalPeriod : blockedFiscalPeriods) { - if (blockedFiscalPeriod.getBeginDate().equals(beginDate) - && blockedFiscalPeriod.getEndDate().equals(endDate) - && blockedFiscalPeriod.getLocked()) { - error = false; - } - } + String url2 = "http://" + address + ":" + port + "/?beginDate=" + + dateFormat.format(beginDate) + + "&endDate=" + dateFormat.format(endDate) + + "&format=.html&model=" + + DocumentsEnum.GENERAL_ENTRYBOOK.getFileName(); + Desktop.getDesktop().browse(new URI(url2)); - //shows error message to user if the fiscalPeriod is unblocked - if (error) { - JOptionPane.showMessageDialog( - view, - _("lima.entrybooksreports.documentcreationfiscalerror"), - _("lima.entrybooksreports.documentcreationfiscaltitle"), - JOptionPane.ERROR_MESSAGE); - } else { - - int port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); - FormatsEnum selectedEnum = (FormatsEnum) view.getDocumentEditor().getSelectedItem(); - String address = LimaConfig.getInstance().getHostAdress(); - - try { - String url = "http://" + address + ":" + port + "/?beginDate=" - + dateFormat.format(beginDate) - + "&endDate=" + dateFormat.format(endDate) - + "&format=" + selectedEnum.getExtension() + "&model=" - + DocumentsEnum.ENTRYBOOKS.getFileName(); - Desktop.getDesktop().browse(new URI(url)); - - String url2 = "http://" + address + ":" + port + "/?beginDate=" - + dateFormat.format(beginDate) - + "&endDate=" + dateFormat.format(endDate) - + "&format=" + selectedEnum.getExtension() + "&model=" - + DocumentsEnum.GENERAL_ENTRYBOOK.getFileName(); - Desktop.getDesktop().browse(new URI(url2)); - - } catch (IOException e) { - log.error("Can't open browser", e); - } catch (URISyntaxException e) { - log.error("Can't create news URI", e); - } + } 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("importEntryBook") || methodName.contains("importAll")) { - refreshData(); - } - } } Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-08-17 11:03:36 UTC (rev 3610) @@ -1,4 +1,7 @@ = +-= +lima-business.document.entrybooks= +lima-business.document.generalentrybook= lima.accountsreports.listerror=Can't get entries list lima.action.commandline.help=Show help in console lima.action.fullscreen=Full screen Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-08-17 11:03:36 UTC (rev 3610) @@ -1,4 +1,7 @@ = +-= +lima-business.document.entrybooks= +lima-business.document.generalentrybook= lima.accountsreports.listerror=Erreur lors de la récupération des données de la liste lima.action.commandline.help=Afficher l'aide en console lima.action.fullscreen=Plein Ecran Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-08-16 14:31:59 UTC (rev 3609) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-08-17 11:03:36 UTC (rev 3610) @@ -59,4 +59,5 @@ log4j.logger.org.chorem.lima.business.ejb.DocumentServiceImpl=DEBUG log4j.logger.org.chorem.lima.business.ejb.HttpServerServiceImpl=DEBUG log4j.logger.org.chorem.lima.ui.accountsreports.AccountsReportsViewHandler=DEBUG -log4j.logger.org.chorem.lima.business.ejb.ReportServiceImpl=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.business.ejb.ReportServiceImpl=DEBUG +log4j.logger.org.chorem.lima.ui.MainViewHandler=DEBUG \ No newline at end of file
participants (1)
-
mallon@users.chorem.org