}
private void addTable(final Document document, final Boolean skipEmptyRecords) throws DocumentException {
double progressValue = 20;
progress.setValue((int)progressValue);
// columns are: date, duration, rate, total, description
final PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
table.setWidths(new int[] {30, 30, 30, 40, 150});
table.addCell(new Paragraph("Date", getDefaultBoldFont()));
table.addCell(new Paragraph("Duration (hr)", getDefaultBoldFont()));
table.addCell(new Paragraph("Rate per Hour", getDefaultBoldFont()));
table.addCell(new Paragraph("Total", getDefaultBoldFont()));
table.addCell(new Paragraph("Description", getDefaultBoldFont()));
final double increment = map.size() / 80d;
double sumDuration=0;
double sumTotal=0;
for (final Date d : map.keySet()) {
progressValue+=increment;
progress.setValue((int)progressValue);
if (skipEmptyRecords && map.get(d).isEmpty()) {
continue;
}
final PdfPCell dateCell = new PdfPCell(new Paragraph(Util.ReportDateFormat.format(d), getDefaultFont()));
dateCell.setHorizontalAlignment(Element.ALIGN_CENTER);
if (!map.get(d).isEmpty()) {
dateCell.setRowspan(map.get(d).size());
}
table.addCell(dateCell);
double tempSumDuration=0;
double tempSumTotal=0;
for (final RecordEntity r : map.get(d)) {
PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(r.getDuration()),getDefaultFont()));
duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell rate = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(r.getRate()),getDefaultFont()));
rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(r.getDuration()*r.getRate()),getDefaultFont()));
total.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell desc = new PdfPCell(new Paragraph(r.getDescription(),getDefaultFont()));
desc.setHorizontalAlignment(Element.ALIGN_LEFT);
tempSumDuration+=r.getDuration();
tempSumTotal+=(r.getDuration()*r.getRate());
table.addCell(duration);
table.addCell(rate);
table.addCell(total);
table.addCell(desc);
}
if (map.get(d).isEmpty()) {
table.addCell(new Paragraph(""));
table.addCell(new Paragraph(""));
table.addCell(new Paragraph(""));
table.addCell(new Paragraph(""));
} else {
PdfPCell totalText = new PdfPCell(new Paragraph("Sum",getDefaultBoldFont()));
totalText.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(tempSumDuration),getDefaultBoldFont()));
duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell rate = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(tempSumTotal),getDefaultBoldFont()));
total.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell desc = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
desc.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(totalText);
table.addCell(duration);
table.addCell(rate);
table.addCell(total);
table.addCell(desc);
if (!d.equals(end)) {
PdfPCell separator = new PdfPCell(new Paragraph("\n\n", getDefaultFont()));
separator.setColspan(5);
table.addCell(separator);
}
}
sumDuration+=tempSumDuration;
sumTotal+=tempSumTotal;
}
// adds total
PdfPCell totalText = new PdfPCell(new Paragraph("Total",getDefaultBoldFont()));
totalText.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell duration = new PdfPCell(new Paragraph(Util.DecimalFormat.format(sumDuration),getDefaultBoldFont()));
duration.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell rate = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
rate.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell total = new PdfPCell(new Paragraph(Util.CurrencyFormat.format(sumTotal),getDefaultBoldFont()));
total.setHorizontalAlignment(Element.ALIGN_RIGHT);
PdfPCell desc = new PdfPCell(new Paragraph("",getDefaultBoldFont()));
desc.setHorizontalAlignment(Element.ALIGN_LEFT);
totalText.setBorder(Rectangle.NO_BORDER);
duration.setBorder(Rectangle.NO_BORDER);
rate.setBorder(Rectangle.NO_BORDER);
total.setBorder(Rectangle.NO_BORDER);
desc.setBorder(Rectangle.NO_BORDER);
table.addCell(totalText);
table.addCell(duration);
table.addCell(rate);
table.addCell(total);
table.addCell(desc);
document.add(table);
}