001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.util;
017:
018: import java.io.FileOutputStream;
019: import java.text.DecimalFormat;
020: import java.text.SimpleDateFormat;
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Collections;
024: import java.util.Date;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.SortedMap;
029: import java.util.TreeMap;
030:
031: import org.kuali.core.util.KualiDecimal;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.module.gl.bo.OriginEntryGroup;
034: import org.kuali.module.gl.bo.Transaction;
035: import org.kuali.module.gl.service.OriginEntryService;
036:
037: import com.lowagie.text.Document;
038: import com.lowagie.text.Element;
039: import com.lowagie.text.ExceptionConverter;
040: import com.lowagie.text.Font;
041: import com.lowagie.text.FontFactory;
042: import com.lowagie.text.PageSize;
043: import com.lowagie.text.Paragraph;
044: import com.lowagie.text.Phrase;
045: import com.lowagie.text.Rectangle;
046: import com.lowagie.text.pdf.PdfPCell;
047: import com.lowagie.text.pdf.PdfPTable;
048: import com.lowagie.text.pdf.PdfPageEventHelper;
049: import com.lowagie.text.pdf.PdfWriter;
050:
051: /**
052: * This class represents the functionality need to generate the year end transaction report
053: */
054: public class YearEndTransactionReport {
055: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
056: .getLogger(YearEndTransactionReport.class);
057: private static float SECTION_MARGIN = 15.0f; // what does iText measure units in? Pixels? Inches? Centimeters? I don't
058: // know...so this number is really a wild guess but it looks okay
059:
060: private Font headerFont;
061: private Font textFont;
062: private Font totalFieldFont;
063: private YearEndReportType reportType;
064:
065: public enum YearEndReportType {
066: NOMINAL_ACTIVITY_CLOSE_REPORT, FORWARD_BALANCES_REPORT, FORWARD_ENCUMBERANCES_REPORT, ORGANIZATION_REVERSION_PROCESS_REPORT
067: }
068:
069: class PageHelper extends PdfPageEventHelper {
070: public Date runDate;
071: public Font headerFont;
072: public String title;
073:
074: /**
075: * Generates end page information for year end transaction report
076: *
077: * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
078: */
079: public void onEndPage(PdfWriter writer, Document document) {
080: try {
081: Rectangle page = document.getPageSize();
082: PdfPTable head = new PdfPTable(3);
083: SimpleDateFormat sdf = new SimpleDateFormat(
084: "MM/dd/yyyy HH:mm:ss");
085: PdfPCell cell = new PdfPCell(new Phrase(sdf
086: .format(runDate), headerFont));
087: cell.setBorder(Rectangle.NO_BORDER);
088: head.addCell(cell);
089:
090: cell = new PdfPCell(new Phrase(title, headerFont));
091: cell.setBorder(Rectangle.NO_BORDER);
092: cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
093: head.addCell(cell);
094:
095: cell = new PdfPCell(new Phrase("Page: "
096: + new Integer(writer.getPageNumber()),
097: headerFont));
098: cell.setBorder(Rectangle.NO_BORDER);
099: cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
100: head.addCell(cell);
101:
102: head.setTotalWidth(page.width() - document.leftMargin()
103: - document.rightMargin());
104: head.writeSelectedRows(0, -1, document.leftMargin(),
105: page.height() - document.topMargin()
106: + head.getTotalHeight(), writer
107: .getDirectContent());
108: } catch (Exception e) {
109: throw new ExceptionConverter(e);
110: }
111: }
112: }
113:
114: public YearEndTransactionReport(YearEndReportType reportType) {
115: super ();
116: this .reportType = reportType;
117: totalFieldFont = FontFactory.getFont(FontFactory.COURIER, 8,
118: Font.BOLD);
119: this .headerFont = FontFactory.getFont(FontFactory.COURIER, 8,
120: Font.BOLD);
121: this .textFont = FontFactory.getFont(FontFactory.COURIER, 8,
122: Font.NORMAL);
123: }
124:
125: /**
126: * Generates year end transaction report
127: *
128: * @param jobParameters map containing all related job parameters
129: * @param reportErrors map containing all report errors
130: * @param reportSummary list of summary objects for report
131: * @param runDate date report is run
132: * @param title title of the report
133: * @param fileprefix file prefix for report
134: * @param destinationDirectory directory where report file will reside
135: */
136: public void generateReport(Map jobParameters, Map reportErrors,
137: List reportSummary, Date runDate, String title,
138: String fileprefix, String destinationDirectory,
139: Object[] originEntryGroupsAndNames) {
140: LOG.debug("generateReport() started");
141:
142: Document document = new Document(PageSize.A4.rotate());
143:
144: PageHelper helper = new PageHelper();
145: helper.runDate = runDate;
146: helper.headerFont = headerFont;
147: helper.title = title;
148:
149: // This flag tells us whether or not an error was thrown before document.open() could be called
150: // successfully.
151: boolean isDocumentOpen = false;
152:
153: try {
154: String filename = destinationDirectory + "/" + fileprefix
155: + "_";
156: SimpleDateFormat sdf = new SimpleDateFormat(
157: "yyyyMMdd_HHmmss");
158: filename = filename + sdf.format(runDate);
159: filename = filename + ".pdf";
160: PdfWriter writer = PdfWriter.getInstance(document,
161: new FileOutputStream(filename));
162: writer.setPageEvent(helper);
163:
164: document.open();
165:
166: // Indicate that document.close() should be called.
167: isDocumentOpen = true;
168:
169: // Sort what we get
170: Collections.sort(reportSummary);
171: Paragraph paragraph;
172:
173: if (this .reportType == YearEndReportType.FORWARD_ENCUMBERANCES_REPORT
174: || this .reportType == YearEndReportType.NOMINAL_ACTIVITY_CLOSE_REPORT
175: || this .reportType == YearEndReportType.ORGANIZATION_REVERSION_PROCESS_REPORT) {
176: paragraph = new Paragraph();
177: paragraph.setSpacingBefore(SECTION_MARGIN);
178: paragraph.setSpacingAfter(SECTION_MARGIN);
179: paragraph.add(generateParametersSection(jobParameters));
180: document.add(paragraph);
181: }
182:
183: paragraph = new Paragraph();
184: paragraph.setSpacingBefore(SECTION_MARGIN);
185: paragraph.setSpacingAfter(SECTION_MARGIN);
186: paragraph.add(generateStatisticsSection(reportSummary));
187: document.add(paragraph);
188:
189: if (reportErrors != null && reportErrors.size() > 0) {
190: document.add(generateWarningsSection(reportErrors));
191: }
192: for (Object o : originEntryGroupsAndNames) {
193: Object[] groupAndName = (Object[]) o;
194: OriginEntryGroup group = (OriginEntryGroup) groupAndName[0];
195: String reportName = (String) groupAndName[1];
196: Collection groups = new ArrayList();
197: groups.add(group);
198: LedgerEntryHolder ledgerEntryHolder = SpringContext
199: .getBean(OriginEntryService.class)
200: .getSummaryByGroupId(groups);
201: paragraph = new Paragraph();
202: paragraph.setSpacingBefore(SECTION_MARGIN);
203: paragraph.setSpacingAfter(SECTION_MARGIN);
204: paragraph.add(generateLedgerSection(ledgerEntryHolder,
205: reportName));
206: document.add(paragraph);
207: }
208: } catch (Exception de) {
209: LOG.error("generateReport() Error creating PDF report", de);
210: throw new RuntimeException("Report Generation Failed");
211: }
212:
213: if (isDocumentOpen) {
214:
215: document.close();
216:
217: }
218:
219: }
220:
221: /**
222: * Returns PdfPTable representing parameters section of report
223: *
224: * @param jobParameters map of job related parameters
225: * @return PdfPTable representing parameters section of report
226: */
227: private PdfPTable generateParametersSection(Map jobParameters) {
228: // Job Parameter Summary
229: float[] summaryWidths = { 70, 30 };
230: PdfPTable summary = new PdfPTable(summaryWidths);
231: summary.setWidthPercentage(40);
232: PdfPCell cell = new PdfPCell(new Phrase(
233: "J O B P A R A M E T E R S", headerFont));
234: cell.setColspan(2);
235: cell.setBorder(Rectangle.NO_BORDER);
236: cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
237: summary.addCell(cell);
238:
239: for (Iterator iter = jobParameters.keySet().iterator(); iter
240: .hasNext();) {
241: String s = (String) iter.next();
242:
243: cell = new PdfPCell(new Phrase(s, textFont));
244: cell.setBorder(Rectangle.NO_BORDER);
245: summary.addCell(cell);
246:
247: if ("".equals(s)) {
248: cell = new PdfPCell(new Phrase("", textFont));
249: cell.setBorder(Rectangle.NO_BORDER);
250: summary.addCell(cell);
251: } else {
252: // DecimalFormat nf = new DecimalFormat("###,###,##0");
253: cell = new PdfPCell(new Phrase(jobParameters.get(s)
254: .toString(), textFont));
255: cell.setBorder(Rectangle.NO_BORDER);
256: cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
257: summary.addCell(cell);
258: }
259: }
260: cell = new PdfPCell(new Phrase(""));
261: cell.setColspan(2);
262: cell.setBorder(Rectangle.NO_BORDER);
263: summary.addCell(cell);
264:
265: return summary;
266: }
267:
268: /**
269: * Returns PdfPTable representing statistics section of report
270: *
271: * @param reportSummary list of summary objects related to the report
272: * @return PdfPTable representing statistics section of report
273: */
274: private PdfPTable generateStatisticsSection(List reportSummary) {
275: // Statistics report
276: float[] summaryWidths = { 70, 30 };
277: PdfPTable summary = new PdfPTable(summaryWidths);
278: summary.setWidthPercentage(40);
279: PdfPCell cell = new PdfPCell(new Phrase("S T A T I S T I C S",
280: headerFont));
281: cell.setColspan(2);
282: cell.setBorder(Rectangle.NO_BORDER);
283: cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
284: summary.addCell(cell);
285:
286: for (Iterator iter = reportSummary.iterator(); iter.hasNext();) {
287: Summary s = (Summary) iter.next();
288:
289: cell = new PdfPCell(
290: new Phrase(s.getDescription(), textFont));
291: cell.setBorder(Rectangle.NO_BORDER);
292: summary.addCell(cell);
293:
294: if ("".equals(s.getDescription())) {
295: cell = new PdfPCell(new Phrase("", textFont));
296: cell.setBorder(Rectangle.NO_BORDER);
297: summary.addCell(cell);
298: } else {
299: DecimalFormat nf = new DecimalFormat("###,###,##0");
300: cell = new PdfPCell(new Phrase(nf.format(s.getCount()),
301: textFont));
302: cell.setBorder(Rectangle.NO_BORDER);
303: cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
304: summary.addCell(cell);
305: }
306: }
307: cell = new PdfPCell(new Phrase(""));
308: cell.setColspan(2);
309: cell.setBorder(Rectangle.NO_BORDER);
310: summary.addCell(cell);
311:
312: return summary;
313: }
314:
315: /**
316: * Returns PdfPTable representing warnings section of report
317: *
318: * @param reportErrors map containing all report related errors
319: * @return PdfPTable representing warnings section of report
320: */
321: private PdfPTable generateWarningsSection(Map reportErrors) {
322: float[] warningWidths = { 4, 3, 6, 5, 5, 4, 5, 5, 4, 5, 5, 9,
323: 4, 36 };
324: PdfPTable warnings = new PdfPTable(warningWidths);
325: warnings.setHeaderRows(2);
326: warnings.setWidthPercentage(100);
327: PdfPCell cell = new PdfPCell(new Phrase("W A R N I N G S",
328: headerFont));
329: cell.setColspan(14);
330: cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
331: warnings.addCell(cell);
332:
333: // Add headers
334: cell = new PdfPCell(new Phrase("Year", headerFont));
335: warnings.addCell(cell);
336: cell = new PdfPCell(new Phrase("COA", headerFont));
337: warnings.addCell(cell);
338: cell = new PdfPCell(new Phrase("Account", headerFont));
339: warnings.addCell(cell);
340: cell = new PdfPCell(new Phrase("Sacct", headerFont));
341: warnings.addCell(cell);
342: cell = new PdfPCell(new Phrase("Obj", headerFont));
343: warnings.addCell(cell);
344: cell = new PdfPCell(new Phrase("SObj", headerFont));
345: warnings.addCell(cell);
346: cell = new PdfPCell(new Phrase("BalTyp", headerFont));
347: warnings.addCell(cell);
348: cell = new PdfPCell(new Phrase("ObjTyp", headerFont));
349: warnings.addCell(cell);
350: cell = new PdfPCell(new Phrase("Prd", headerFont));
351: warnings.addCell(cell);
352: cell = new PdfPCell(new Phrase("DocType", headerFont));
353: warnings.addCell(cell);
354: cell = new PdfPCell(new Phrase("Origin", headerFont));
355: warnings.addCell(cell);
356: cell = new PdfPCell(new Phrase("DocNbr", headerFont));
357: warnings.addCell(cell);
358: cell = new PdfPCell(new Phrase("Seq", headerFont));
359: warnings.addCell(cell);
360: cell = new PdfPCell(new Phrase("Warning", headerFont));
361: warnings.addCell(cell);
362:
363: for (Iterator errorIter = reportErrors.keySet().iterator(); errorIter
364: .hasNext();) {
365: Transaction tran = (Transaction) errorIter.next();
366: boolean first = true;
367:
368: List errors = (List) reportErrors.get(tran);
369: for (Iterator listIter = errors.iterator(); listIter
370: .hasNext();) {
371: String msg = (String) listIter.next();
372:
373: if (first) {
374: first = false;
375:
376: if (tran.getUniversityFiscalYear() == null) {
377: cell = new PdfPCell(
378: new Phrase("NULL", textFont));
379: } else {
380: cell = new PdfPCell(new Phrase(tran
381: .getUniversityFiscalYear().toString(),
382: textFont));
383: }
384: warnings.addCell(cell);
385: cell = new PdfPCell(new Phrase(tran
386: .getChartOfAccountsCode(), textFont));
387: warnings.addCell(cell);
388: cell = new PdfPCell(new Phrase(tran
389: .getAccountNumber(), textFont));
390: warnings.addCell(cell);
391: cell = new PdfPCell(new Phrase(tran
392: .getSubAccountNumber(), textFont));
393: warnings.addCell(cell);
394: cell = new PdfPCell(new Phrase(tran
395: .getFinancialObjectCode(), textFont));
396: warnings.addCell(cell);
397: cell = new PdfPCell(new Phrase(tran
398: .getFinancialSubObjectCode(), textFont));
399: warnings.addCell(cell);
400: cell = new PdfPCell(new Phrase(tran
401: .getFinancialBalanceTypeCode(), textFont));
402: warnings.addCell(cell);
403: cell = new PdfPCell(new Phrase(tran
404: .getFinancialObjectTypeCode(), textFont));
405: warnings.addCell(cell);
406: cell = new PdfPCell(new Phrase(tran
407: .getUniversityFiscalPeriodCode(), textFont));
408: warnings.addCell(cell);
409: cell = new PdfPCell(new Phrase(tran
410: .getFinancialDocumentTypeCode(), textFont));
411: warnings.addCell(cell);
412: cell = new PdfPCell(new Phrase(tran
413: .getFinancialSystemOriginationCode(),
414: textFont));
415: warnings.addCell(cell);
416: cell = new PdfPCell(new Phrase(tran
417: .getDocumentNumber(), textFont));
418: warnings.addCell(cell);
419: if (tran.getTransactionLedgerEntrySequenceNumber() == null) {
420: cell = new PdfPCell(
421: new Phrase("NULL", textFont));
422: } else {
423: cell = new PdfPCell(
424: new Phrase(
425: tran
426: .getTransactionLedgerEntrySequenceNumber()
427: .toString(), textFont));
428: }
429: warnings.addCell(cell);
430: } else {
431: cell = new PdfPCell(new Phrase("", textFont));
432: cell.setColspan(13);
433: warnings.addCell(cell);
434: }
435: cell = new PdfPCell(new Phrase(msg, textFont));
436: warnings.addCell(cell);
437: }
438: }
439:
440: return warnings;
441: }
442:
443: /**
444: * Draw a PDF table from ledger entry holder
445: *
446: * @param ledgerEntryHolder ledger entry holder
447: * @param reportName name of report
448: * @return
449: */
450: private PdfPTable generateLedgerSection(
451: LedgerEntryHolder ledgerEntryHolder, String reportName) {
452: SortedMap ledgerEntries = new TreeMap(ledgerEntryHolder
453: .getLedgerEntries());
454: Collection entryCollection = ledgerEntries.values();
455: Map subtotalMap = ledgerEntryHolder.getSubtotals();
456:
457: if (entryCollection == null || entryCollection.size() <= 0) {
458: return this .buildEmptyLedgerSectionTable();
459: }
460:
461: float[] warningWidths = { 3, 3, 6, 3, 8, 10, 8, 10, 8, 10, 8 };
462: PdfPTable ledgerEntryTable = new PdfPTable(warningWidths);
463: ledgerEntryTable.setHeaderRows(2);
464: ledgerEntryTable.setWidthPercentage(100);
465:
466: PdfPCell titleCell = new PdfPCell(new Phrase(
467: capAndSpacerize(reportName), headerFont));
468: titleCell.setColspan(11);
469: titleCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
470: ledgerEntryTable.addCell(titleCell);
471:
472: this .addLedgerSectionHeader(ledgerEntryTable, headerFont);
473:
474: String tempBalanceType = "--";
475: for (Iterator reportIter = entryCollection.iterator(); reportIter
476: .hasNext();) {
477: LedgerEntry ledgerEntry = (LedgerEntry) reportIter.next();
478:
479: // add the subtotal rows
480: if (!ledgerEntry.getBalanceType().equals(tempBalanceType)) {
481: if (subtotalMap.containsKey(tempBalanceType)) {
482: LedgerEntry subtotal = (LedgerEntry) subtotalMap
483: .get(tempBalanceType);
484: this .addLedgerSectionRow(ledgerEntryTable,
485: subtotal, totalFieldFont, true);
486: }
487: tempBalanceType = ledgerEntry.getBalanceType();
488: }
489: this .addLedgerSectionRow(ledgerEntryTable, ledgerEntry,
490: textFont, false);
491:
492: // deal with the subtotal after adding the last row
493: if (!reportIter.hasNext()
494: && subtotalMap.containsKey(tempBalanceType)) {
495: LedgerEntry subtotal = (LedgerEntry) subtotalMap
496: .get(tempBalanceType);
497: this .addLedgerSectionRow(ledgerEntryTable, subtotal,
498: totalFieldFont, true);
499: }
500: }
501: this .addLedgerSectionRow(ledgerEntryTable, ledgerEntryHolder
502: .getGrandTotal(), totalFieldFont, true);
503:
504: return ledgerEntryTable;
505: }
506:
507: //
508: /**
509: * Draw a table an empty ledger section table
510: *
511: * @return PdfPTable represents a empty ledger section table
512: */
513: private PdfPTable buildEmptyLedgerSectionTable() {
514: float[] tableWidths = { 100 };
515:
516: PdfPTable ledgerEntryTable = new PdfPTable(tableWidths);
517: ledgerEntryTable.setWidthPercentage(100);
518: PdfPCell cell = new PdfPCell(new Phrase("No entries found!",
519: headerFont));
520: ledgerEntryTable.addCell(cell);
521:
522: return ledgerEntryTable;
523: }
524:
525: /**
526: * Add a table header
527: *
528: * @param ledgerEntryTable ledger entry table
529: * @param headerFont font for header
530: */
531: private void addLedgerSectionHeader(PdfPTable ledgerEntryTable,
532: Font headerFont) {
533:
534: PdfPCell cell = new PdfPCell(new Phrase("BAL TYP", headerFont));
535: ledgerEntryTable.addCell(cell);
536:
537: cell = new PdfPCell(new Phrase("ORIG", headerFont));
538: ledgerEntryTable.addCell(cell);
539:
540: cell = new PdfPCell(new Phrase("YEAR", headerFont));
541: ledgerEntryTable.addCell(cell);
542:
543: cell = new PdfPCell(new Phrase("PRD", headerFont));
544: ledgerEntryTable.addCell(cell);
545:
546: cell = new PdfPCell(new Phrase("Record Count", headerFont));
547: ledgerEntryTable.addCell(cell);
548:
549: cell = new PdfPCell(new Phrase("Debit Amount", headerFont));
550: ledgerEntryTable.addCell(cell);
551:
552: cell = new PdfPCell(new Phrase("Debit Count", headerFont));
553: ledgerEntryTable.addCell(cell);
554:
555: cell = new PdfPCell(new Phrase("Credit Amount", headerFont));
556: ledgerEntryTable.addCell(cell);
557:
558: cell = new PdfPCell(new Phrase("Credit Count", headerFont));
559: ledgerEntryTable.addCell(cell);
560:
561: cell = new PdfPCell(
562: new Phrase("No D/C Code Amount", headerFont));
563: ledgerEntryTable.addCell(cell);
564:
565: cell = new PdfPCell(new Phrase("No D/C Code Count", headerFont));
566: ledgerEntryTable.addCell(cell);
567: }
568:
569: /**
570: * Add a row with the given ledger entry into PDF table
571: *
572: * @param ledgerEntryTable ledger entry table
573: * @param ledgerEntry ledger entry
574: * @param textFont font for text
575: * @param isTotal used to determine if total row is added
576: */
577: private void addLedgerSectionRow(PdfPTable ledgerEntryTable,
578: LedgerEntry ledgerEntry, Font textFont, boolean isTotal) {
579: PdfPCell cell = null;
580: if (isTotal) {
581: String balanceType = ledgerEntry.getBalanceType() != null ? "("
582: + ledgerEntry.getBalanceType() + ")"
583: : "";
584: String totalDescription = ledgerEntry.getOriginCode()
585: + balanceType + ":";
586:
587: cell = new PdfPCell(new Phrase(totalDescription, textFont));
588: cell.setColspan(4);
589: ledgerEntryTable.addCell(cell);
590: } else {
591: cell = new PdfPCell(new Phrase(
592: ledgerEntry.getBalanceType(), textFont));
593: ledgerEntryTable.addCell(cell);
594:
595: cell = new PdfPCell(new Phrase(ledgerEntry.getOriginCode(),
596: textFont));
597: ledgerEntryTable.addCell(cell);
598:
599: String fiscalYear = (ledgerEntry.getFiscalYear() != null) ? ledgerEntry
600: .getFiscalYear().toString()
601: : "";
602: cell = new PdfPCell(new Phrase(fiscalYear, textFont));
603: ledgerEntryTable.addCell(cell);
604:
605: cell = new PdfPCell(new Phrase(ledgerEntry.getPeriod(),
606: textFont));
607: ledgerEntryTable.addCell(cell);
608: }
609:
610: cell = new PdfPCell(new Phrase(this .formatNumber(new Integer(
611: ledgerEntry.getRecordCount())), textFont));
612: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
613: ledgerEntryTable.addCell(cell);
614:
615: cell = new PdfPCell(new Phrase(this .formatNumber(ledgerEntry
616: .getDebitAmount()), textFont));
617: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
618: ledgerEntryTable.addCell(cell);
619:
620: cell = new PdfPCell(new Phrase(this .formatNumber(new Integer(
621: ledgerEntry.getDebitCount())), textFont));
622: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
623: ledgerEntryTable.addCell(cell);
624:
625: cell = new PdfPCell(new Phrase(this .formatNumber(ledgerEntry
626: .getCreditAmount()), textFont));
627: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
628: ledgerEntryTable.addCell(cell);
629:
630: cell = new PdfPCell(new Phrase(this .formatNumber(new Integer(
631: ledgerEntry.getCreditCount())), textFont));
632: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
633: ledgerEntryTable.addCell(cell);
634:
635: cell = new PdfPCell(new Phrase(this .formatNumber(ledgerEntry
636: .getNoDCAmount()), textFont));
637: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
638: ledgerEntryTable.addCell(cell);
639:
640: cell = new PdfPCell(new Phrase(this .formatNumber(new Integer(
641: ledgerEntry.getNoDCCount())), textFont));
642: cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
643: ledgerEntryTable.addCell(cell);
644: }
645:
646: /**
647: * Format the given number based on its type: Integer or BigDecimal
648: *
649: * @param number Integer or BigDecimal to convert to STring
650: * @return Integer or BigDecimal in number form
651: */
652: private String formatNumber(Number number) {
653: DecimalFormat decimalFormat = new DecimalFormat();
654:
655: if (number instanceof Integer) {
656: decimalFormat.applyPattern("###,###");
657: } else if (number instanceof KualiDecimal) {
658: decimalFormat.applyPattern("###,###,###,##0.00");
659: }
660: return decimalFormat.format(number);
661: }
662:
663: /**
664: * This method capitalizes words and replaces whitespaces with ' '
665: *
666: * @param word to be modified
667: * @return capitalize and "spacerized" string
668: */
669: private String capAndSpacerize(String word) {
670: StringBuilder spacedWord = new StringBuilder();
671: String updatedWord = word.trim().toUpperCase();
672: for (int i = 0; i < updatedWord.length(); i++) {
673: if (!Character.isWhitespace(updatedWord.charAt(i))) {
674: spacedWord.append(' ');
675: }
676: spacedWord.append(updatedWord.charAt(i));
677: }
678: return spacedWord.toString();
679: }
680: }
|