Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.hris.payroll.reports; import com.hris.common.CommonUtil; import com.hris.employee.serviceprovider.EmployeePositionHistoryServiceImpl; import com.hris.employee.serviceprovider.EmployeeServiceImpl; import com.hris.model.Employee; import com.hris.model.PayrollRegister; import com.hris.payroll.serviceprovider.AdvancesServiceImpl; import com.hris.payroll.serviceprovider.PayrollServiceImpl; import com.hris.payroll.serviceprovider.UserBranchAccessServiceImpl; import com.hris.service.AdvancesService; import com.hris.service.EmployeePositionHistoryService; import com.hris.service.EmployeeService; import com.hris.service.PayrollService; import com.hris.service.UserBranchAccessService; import com.hris.service.UserService; import com.hris.serviceprovider.UserServiceImpl; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.vaadin.server.StreamResource.StreamSource; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author jetdario */ public class PayslipReportPDF implements StreamSource { EmployeeService es = new EmployeeServiceImpl(); PayrollService ps = new PayrollServiceImpl(); AdvancesService as = new AdvancesServiceImpl(); UserBranchAccessService ubas = new UserBranchAccessServiceImpl(); UserService us = new UserServiceImpl(); EmployeePositionHistoryService ephs = new EmployeePositionHistoryServiceImpl(); private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); private int branchId; private Date payrollDate; Font header = FontFactory.getFont("Times-Roman", 10, Font.BOLD); Font content = FontFactory.getFont("Times-Roman", 8); Font cellContent = FontFactory.getFont("Times-Roman", 8); Font boldFont = FontFactory.getFont("Times-Roman", 8, Font.BOLD); Font smallFont = FontFactory.getFont("Times-Roman", 7); Font smallerFont = FontFactory.getFont("Times-Roman", 6); float halfMonthRate = 15; float allowances = 30; int cellBorder = 0; public PayslipReportPDF(int branchId, Date payrollDate) { this.branchId = branchId; this.payrollDate = payrollDate; Document document = null; Rectangle pageSize = new Rectangle(318, 825); try { // document = new Document(PageSize.A4, 50, 50, 48, 40); document = new Document(pageSize, 37, 37, 37, 37); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); PdfPTable mainTable = new PdfPTable(1); // mainTable.setTotalWidth(new float[]{ 120, 120 }); mainTable.setWidthPercentage(100); mainTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL); // mainTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // mainTable.setLockedWidth(true); // leftColumnTable(mainTable); // rightColumnTable(mainTable); // for(Employee e : es.findEmployeeByBranch(getBranchId())){ for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) { document.add(leftColumnTable(pr, getPayrollDate())); document.newPage(); } } catch (DocumentException ex) { Logger.getLogger(PayslipReportPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { document.close(); } } @Override public InputStream getStream() { return new ByteArrayInputStream(outputStream.toByteArray()); } private int getBranchId() { return branchId; } private Date getPayrollDate() { return payrollDate; } private PdfPTable leftColumnTable(PayrollRegister pr, Date payrollDate) throws DocumentException { PdfPTable table = new PdfPTable(3); table.setTotalWidth(new float[] { 120, 20, 103 }); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setLockedWidth(true); PdfPCell cellTitle = new PdfPCell(); cellTitle.setColspan(3); Paragraph parTitle = new Paragraph(); parTitle.add(new Phrase("Payslip: ", header)); parTitle.setAlignment(Element.ALIGN_CENTER); cellTitle.addElement(parTitle); cellTitle.setBorder(cellBorder); table.addCell(cellTitle); PdfPCell cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); Paragraph parLabel = new Paragraph(); parLabel.add( new Phrase("Payroll Date: " + CommonUtil.convertDateFormat(getPayrollDate().toString()), content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // Paragraph parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(getPayrollDate().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); parLabel.add( new Phrase( "Cut-off Date: " + CommonUtil.changeDateFormat(pr.getAttendancePeriodFrom().toString()) + " - " + CommonUtil.changeDateFormat(pr.getAttendancePeriodTo().toString()), content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // Paragraph parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString())+" - "+CommonUtil.convertDateFormat(pr.getAttendancePeriodFrom().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); String middlename; if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) { middlename = " "; } else { middlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". "; } String name = pr.getLastname().toUpperCase() + ", " + pr.getFirstname().toUpperCase() + " " + middlename; parLabel.add(new Phrase("Employee Name: " + name, content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // cellValue = new PdfPCell(); //// cellValue.setUseAscender(true); // parValue = new Paragraph(); // parValue.add(new Phrase(pr.getLastname().toUpperCase()+", "+pr.getFirstname().toUpperCase()+" "+pr.getMiddlename().toUpperCase().charAt(0)+".", employeeName)); //// parValue.add(new Phrase("NAME", content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(3); parLabel = new Paragraph(); String position = (ephs.findByEmployee(pr.getEmployeeId()).getPosition() == null) ? "N/A" : ephs.findByEmployee(pr.getEmployeeId()).getPosition().toUpperCase(); parLabel.add(new Phrase("POSITION: " + position, smallerFont)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); // cellValue = new PdfPCell(); // cellValue.setUseAscender(true); // parValue = new Paragraph(); // parValue.add(new Phrase(CommonUtil.convertDateFormat(new Date().toString()), content)); // parValue.setAlignment(Element.ALIGN_RIGHT); // cellValue.addElement(parValue); // cellValue.setBorder(cellBorder); // table.addCell(cellValue); cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("Monthly/Daily Rate: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); PdfPCell cellValue = new PdfPCell(); // cellValue.setUseAscender(true); Paragraph parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getRate()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("Half-month Rate: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getHalfMonthSalary()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Overtime: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getOvertimePay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Holiday Premium: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double premium = (pr.getLegalHolidayPay() + pr.getSpecialHolidayPay()) - (pr.getTotalLatesHolidayDeduction() + pr.getTotalUndertimeHolidayDeduction()); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(premium)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Working Day-off: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getWorkingDayOffPay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Night Differential: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getNightDifferential())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Absences/Lates/Undertime: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double alu = pr.getAbsences() + pr.getTotalLatesDeduction() + pr.getTotalUndertimeDeduction(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(alu)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("GROSS PAY: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getGrossPay())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Allowances: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("COLA: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getColaAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Meal Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getMealAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("AFL: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getAllowanceForLiquidation()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Transportation Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); cellLabel.setColspan(2); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getTransportationAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Housing Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getOtherAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Communications Allowance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(pr.getCommunicationAllowance()), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL PAY: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double totalPay = pr.getGrossPay() + pr.getCommunicationAllowance() + pr.getTransportationAllowance() + pr.getColaAllowance() + pr.getPerDiemAllowance() + pr.getMealAllowance() + pr.getOtherAllowance() + pr.getAllowanceForLiquidation(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalPay)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("DEDUCTIONS: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("SSS Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getSss())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("PHIC Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getPhic())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("HDMF Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getHdmf())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Withholoding Taxes: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getTax())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("SSS Loan: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "sss loan"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("HDMF Loan: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "hdmf loan"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Additional HDMF Contribution: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase( String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces( as.findAdvancesTotalAmount(pr.getPayrollId(), "additional HDMF contribution"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("PAG-IBIG 2: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "pag-ibig ii"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Advances to O/E: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(" ", content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Bond: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash bond"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Advance: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash advance"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Lending: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "lending"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Jewelry: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "jewelry"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Staffhouse: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase( String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "staffhouse"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Hotel and Restaurant Charges: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase( String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces( as.findAdvancesTotalAmount(pr.getPayrollId(), "hotel and restaurant charges"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Cash Shortages: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "cash shortages"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Employee Charges: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "employee charges"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("ATM Initial Deposit: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil .roundOffToTwoDecimalPlaces(as.findAdvancesTotalAmount(pr.getPayrollId(), "atm initial deposit"))), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.setIndentationLeft(allowances); parLabel.add(new Phrase("Others__________________: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double otherCharges = as.findAdvancesTotalAmount(pr.getPayrollId(), "advances to o/e") + as.findAdvancesTotalAmount(pr.getPayrollId(), "other charges"); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(otherCharges)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL DEDUCTIONS:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double totalDeductions = as.findAdvancesTotalAmount(pr.getPayrollId()) + pr.getTax() + pr.getPhic() + pr.getHdmf() + pr.getSss(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(totalDeductions)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); cellLabel.setColspan(2); parLabel = new Paragraph(); parLabel.add(new Phrase("NET PAY:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); double netPay = CommonUtil.roundOffToTwoDecimalPlaces(totalPay - totalDeductions); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay)), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("Adjustments:", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add( new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(pr.getAdjustments())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); // parLabel.add(new Phrase("_____________________________", content)); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); // parValue.add(new Phrase(String.valueOf(totalPay - totalDeductions), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("TOTAL AMOUNT TO BE RECEIVED:", smallFont)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase(String.valueOf(CommonUtil.roundOffToTwoDecimalPlaces(netPay + pr.getAdjustments())), content)); parValue.setAlignment(Element.ALIGN_RIGHT); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.TOP | Rectangle.BOTTOM); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase("Prepared By: ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); // cellLabel.setUseAscender(true); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); // cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase("Conforme: ", content)); parValue.setAlignment(Element.ALIGN_LEFT); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); /***************************************************************************/ int userId = ubas.findUserByBranch(getBranchId()); String employeeId = us.findEmployeeIdByUserId(userId); Employee e = es.findEmployeeById(employeeId); String payrollClerkMiddlename; if (e.getMiddlename() == null || e.getMiddlename().isEmpty()) { payrollClerkMiddlename = " "; } else { payrollClerkMiddlename = String.valueOf(e.getMiddlename().toUpperCase().charAt(0)) + ". "; } String payrollClerk = e.getFirstname().toUpperCase() + " " + payrollClerkMiddlename + e.getLastname().toUpperCase(); String employeeMiddlename; if (pr.getMiddlename() == null || pr.getMiddlename().isEmpty()) { employeeMiddlename = " "; } else { employeeMiddlename = String.valueOf(pr.getMiddlename().toUpperCase().charAt(0)) + ". "; } String employee = pr.getFirstname().toUpperCase() + " " + employeeMiddlename + pr.getLastname().toUpperCase(); cellLabel = new PdfPCell(); cellLabel.setPaddingTop(30); parLabel = new Paragraph(); parLabel.add(new Phrase(payrollClerk, smallerFont)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(Rectangle.BOTTOM); table.addCell(cellLabel); cellLabel = new PdfPCell(); cellLabel.setPaddingTop(30); parLabel = new Paragraph(); parLabel.add(new Phrase(" ", content)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setPaddingTop(30); parValue = new Paragraph(); parValue.add(new Phrase(employee, smallerFont)); parValue.setAlignment(Element.ALIGN_CENTER); cellValue.addElement(parValue); cellValue.setBorder(Rectangle.BOTTOM); table.addCell(cellValue); /***************************************************************************/ cellLabel = new PdfPCell(); cellLabel.setUseAscender(true); parLabel = new Paragraph(); // parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("Payroll Clerk", content)); parLabel.setAlignment(Element.ALIGN_CENTER); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellLabel = new PdfPCell(); parLabel = new Paragraph(); // parLabel.setIndentationLeft(halfMonthRate); parLabel.add(new Phrase("", content)); parLabel.setAlignment(Element.ALIGN_LEFT); cellLabel.addElement(parLabel); cellLabel.setBorder(cellBorder); table.addCell(cellLabel); cellValue = new PdfPCell(); cellValue.setUseAscender(true); parValue = new Paragraph(); parValue.add(new Phrase("Employee", content)); parValue.setAlignment(Element.ALIGN_CENTER); cellValue.addElement(parValue); cellValue.setBorder(cellBorder); table.addCell(cellValue); return table; } }