List of usage examples for com.lowagie.text.pdf PdfPTable setWidths
public void setWidths(int relativeWidths[]) throws DocumentException
From source file:com.krawler.spring.hrms.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public PdfPCell getSalaryDetails(User user, Empprofile empprofile, Useraccount useraccount, Company company, PayrollHistory payrollHistory, DateFormat sdf, int border, HttpServletRequest request) { PdfPTable mainTable = new PdfPTable(1); PdfPCell mainCell = null;//from ww w . j av a 2 s . com try { String currencySymbol = getCurrencySymbol(request, false); int paddingTop = 2; int paddingBottom = 2; double net = 0; double earningAmount = 0; double deductionAmount = 0; String val = null; String accno = useraccount != null ? useraccount.getAccno() : " "; accno = StringUtil.isNullOrEmpty(accno) ? " " : accno; mainTable.setWidths(new float[] { 100 }); PdfPTable mainTable1 = new PdfPTable(3); PdfPCell mainCell1 = null; mainTable1.setWidths(new float[] { 45, 10, 45 }); PdfPTable mainTable2 = new PdfPTable(3); PdfPCell mainCell2 = null; mainTable2.setWidths(new float[] { 45, 10, 45 }); //####################Earnings########################## PdfPTable leftTable1 = new PdfPTable(2); leftTable1.setWidths(new float[] { 60, 40 }); PdfPCell leftCell1 = null; leftTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.payments", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, 7, 7, border)); leftTable1.addCell( getPdfPCellInstance("( " + currencySymbol + " )", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 7, 7, border)); List<ComponentResourceMappingHistory> list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_EARNING, HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_OTHER_REMUNERATION); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); earningAmount += currencyFormat.parse(val).doubleValue(); leftTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } leftCell1 = new PdfPCell(leftTable1); leftCell1.setBorder(border); mainTable1.addCell(leftCell1); PdfPTable leftTable2 = new PdfPTable(2); leftTable2.setWidths(new float[] { 60, 40 }); PdfPCell leftCell2 = null; leftTable2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance("------------", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.subtotal", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftTable2.addCell(getPdfPCellInstance(currencyFormat.format(earningAmount), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); leftCell2 = new PdfPCell(leftTable2); leftCell2.setBorder(border); mainTable2.addCell(leftCell2); //####################Earnings########################## PdfPCell centerCell1 = new PdfPCell(); centerCell1.setBorder(border); mainTable1.addCell(centerCell1); PdfPCell centerCell2 = new PdfPCell(); centerCell2.setBorder(border); mainTable2.addCell(centerCell2); //####################Deductions And Tax########################## PdfPTable rigthTable1 = new PdfPTable(2); rigthTable1.setWidths(new float[] { 60, 40 }); PdfPCell rigthCell1 = null; rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Deduction", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, 7, 7, border)); rigthTable1.addCell( getPdfPCellInstance("( " + currencySymbol + " )", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, 7, 7, border)); list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_DEDUCTION, null); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } list = hrmsPayrollDAOObj.getSalaryDetails(user.getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), HrmsPayrollConstants.PAYROLL_COMPONENT_TYPE_TAX, null); for (ComponentResourceMappingHistory crm : list) { val = currencyFormat.format(crm.getAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance(crm.getComponent().getDescription(), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } //###############Unpaid Leaves START########## if (payrollHistory.getUnpaidleavesAmount() > 0) { val = currencyFormat.format(payrollHistory.getUnpaidleavesAmount()); deductionAmount += currencyFormat.parse(val).doubleValue(); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Unpaidleaves", null, RequestContextUtils.getLocale(request)) + " (" + payrollHistory.getUnpaidleaves() + ")", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); } //###############Unpaid Leaves START########## //###############Income Tax START########## if (payrollHistory.getIncometaxAmount() > 0) { val = currencyFormat.format(payrollHistory.getIncometaxAmount()); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.income.tax", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); deductionAmount += currencyFormat.parse(val).doubleValue(); } //###############Income Tax END########## //###############EPF START################ Map<String, Double> map = getIncomTaxBenefits(request, payrollHistory.getUser().getUserID(), payrollHistory.getPaycycleenddate(), Integer.parseInt(payrollHistory.getFrequency()), payrollHistory); if (map != null && map.get("epf") != null && map.get("epf") > 0) { val = currencyFormat.format(map.get("epf")); rigthTable1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.epf", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable1.addCell(getPdfPCellInstance(val, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); deductionAmount += currencyFormat.parse(val).doubleValue(); } //###############EPF END################ rigthCell1 = new PdfPCell(rigthTable1); rigthCell1.setBorder(border); mainTable1.addCell(rigthCell1); PdfPTable rigthTable2 = new PdfPTable(2); rigthTable2.setWidths(new float[] { 60, 40 }); PdfPCell rigthCell2 = null; rigthTable2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance("------------", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.subtotal", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell(getPdfPCellInstance(currencyFormat.format(deductionAmount), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); net = earningAmount - deductionAmount; rigthTable2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.net", null, RequestContextUtils.getLocale(request)) + "(a/c:" + accno + ")", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthTable2.addCell( getPdfPCellInstance(currencyFormat.format(net), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_RIGHT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); rigthCell2 = new PdfPCell(rigthTable2); rigthCell2.setBorder(border); mainTable2.addCell(rigthCell2); //####################Deductions And Tax########################## mainCell1 = new PdfPCell(mainTable1); mainCell1.setBorder(border); mainCell2 = new PdfPCell(mainTable2); mainCell2.setBorder(border); mainTable.addCell(mainCell1); mainTable.addCell(mainCell2); mainCell = new PdfPCell(mainTable); mainCell.setBorder(border); mainCell.setPaddingBottom(20); } catch (Exception e) { e.printStackTrace(); } return mainCell; }
From source file:com.krawler.spring.hrms.payroll.salaryslip.ExportSalarySlipService.java
License:Open Source License
public PdfPCell getEmployeeAndEmployerDetails(User user, Empprofile empprofile, Useraccount useraccount, Company company, PayrollHistory payrollHistory, DateFormat sdf, int border, List<PayrollHistory> list, Map<String, Double> mapEPF, HttpServletRequest request) { PdfPTable mainTable = new PdfPTable(1); PdfPCell mainCell = null;/*from w w w.j a v a 2 s. com*/ try { String currencySymbol = getCurrencySymbol(request, false); int paddingTop = 5; int paddingBottom = 5; mainTable.setWidths(new float[] { 100 }); PdfPCell cell1 = null; PdfPTable table1 = new PdfPTable(4); table1.setWidths(new float[] { 14, 36, 25, 25 }); table1.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.reference.no", null, RequestContextUtils.getLocale(request)) + ".", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.this.period", null, RequestContextUtils.getLocale(request)) + " ( " + currencySymbol + " )", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table1.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.common.year.to.date", null, RequestContextUtils.getLocale(request)) + " ( " + currencySymbol + " )", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell1 = new PdfPCell(table1); mainTable.addCell(cell1); cell1.setBorder(border); PdfPCell cell2 = null; PdfPTable table2 = new PdfPTable(7); table2.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table2.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.Employee", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table2.addCell(getPdfPCellInstance( messageSource.getMessage("hrms.payroll.employer", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN, Element.ALIGN_CENTER, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell2 = new PdfPCell(table2); mainTable.addCell(cell2); cell2.setBorder(border); String paidEPF = " "; String currentEPF = " "; if (mapEPF != null) { if (mapEPF.get("paidEPF") > 0) { paidEPF = currencyFormat.format(mapEPF.get("paidEPF")); } if (mapEPF.get("currentEPF") > 0) { currentEPF = currencyFormat.format(mapEPF.get("currentEPF")); } } PdfPCell cell3 = null; PdfPTable table3 = new PdfPTable(7); table3.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table3.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.common.epf", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(currentEPF, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(paidEPF, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table3.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell3 = new PdfPCell(table3); mainTable.addCell(cell3); cell3.setBorder(border); PdfPCell cell4 = null; PdfPTable table4 = new PdfPTable(7); table4.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table4.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.common.socso", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table4.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell4 = new PdfPCell(table4); mainTable.addCell(cell4); cell4.setBorder(border); double currenttax = payrollHistory.getIncometaxAmount(); String currentTax = " "; if (currenttax > 0) { currentTax = currencyFormat.format(currenttax); } HrmsCommonPayroll hrmsCommonPayroll = new HrmsCommonPayroll(); double paidtax = hrmsCommonPayroll.getPaidTax(list, payrollHistory); String paidTax = " "; if (paidtax > 0) { paidTax = currencyFormat.format(paidtax); } PdfPCell cell5 = null; PdfPTable table5 = new PdfPTable(7); table5.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table5.addCell(getPdfPCellInstance( " " + messageSource.getMessage("hrms.payroll.tax", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(currentTax, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(paidTax, FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table5.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell5 = new PdfPCell(table5); mainTable.addCell(cell5); cell5.setBorder(border); PdfPCell cell6 = null; PdfPTable table6 = new PdfPTable(7); table6.setWidths(new float[] { 14, 18, 18, 12, 13, 12, 13 }); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); table6.addCell(getPdfPCellInstance(" ", FontContext.REGULAR_NORMAL_TIMES_NEW_ROMAN, Element.ALIGN_LEFT, Element.ALIGN_CENTER, paddingTop, paddingBottom, border)); cell6 = new PdfPCell(table6); mainTable.addCell(cell6); cell6.setBorder(border); mainCell = new PdfPCell(mainTable); mainCell.setBorder(Rectangle.NO_BORDER); } catch (Exception e) { e.printStackTrace(); } return mainCell; }
From source file:com.krawler.spring.hrms.printreport.PrintAppraisalReportDAOImp.java
License:Open Source License
public void createPDFPriview(HttpServletRequest request, HttpServletResponse response, JSONArray obj, Map<String, String> personalData) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4.rotate(), 25, 25, 25, 25); PdfWriter writer = null;// w w w .j a v a 2s . c o m try { HashMap<String, Object> requestParams = new HashMap<String, Object>(); boolean isQuestion = request.getParameter("question").equals("true") ? true : false; boolean promotion = request.getParameter("promotion").equals("false") ? false : true; Boolean isMyAppraisal = Boolean.parseBoolean(personalData.get("isMyAppraisal")); CompanyPreferences companyPreferences = (CompanyPreferences) hibernateTemplate .get(CompanyPreferences.class, sessionHandlerImplObj.getCompanyid(request)); writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage()); document.open(); java.awt.Color tColor = new Color(9, 9, 9); //fontSmallBold.setColor(tColor); //heading PdfPTable headTable = new PdfPTable(1); headTable.setTotalWidth(90); headTable.setWidthPercentage(100); headTable.setSpacingBefore(20); PdfPCell headcell = new PdfPCell( new Paragraph(fontFamilySelector.process(messageSource.getMessage("hrms.common.AppraisalForm", null, RequestContextUtils.getLocale(request)), FontContext.REGULAR_BOLD_HELVETICA))); headcell.setBackgroundColor(new Color(0xEEEEEE)); headcell.setPadding(5); headTable.addCell(headcell); document.add(headTable); //heading //Details int flag = 0; String appDetailsParam[] = { messageSource.getMessage("hrms.performance.appraisal.cycle.name", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.common.employee.name", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.appraisal.cycle.period", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.Masters.Designation", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.performance.rating", null, RequestContextUtils.getLocale(request)) + "*: " }; String appDetailsValue[] = { personalData.get("appcycname"), personalData.get("empname"), messageSource.getMessage("hrms.common.form", null, RequestContextUtils.getLocale(request)) + ": " + personalData.get("startdate") + " " + messageSource.getMessage("hrms.common.to", null, RequestContextUtils.getLocale(request)) + ": " + personalData.get("enddate"), personalData.get("desgname"), personalData.get("performance") }; requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "promotion"); if (!hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { flag = 1; } PdfPTable appDetailsTable = new PdfPTable(2); appDetailsTable.setWidthPercentage(100); appDetailsTable.setWidths(new float[] { 55, 75 }); if (isMyAppraisal) { flag = 1; } for (int i = 0; i < (appDetailsParam.length - flag); i++) { PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(appDetailsParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph( fontFamilySelector.process(appDetailsValue[i], FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "overallcomments"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( (isMyAppraisal ? messageSource.getMessage("hrms.performance.self.overall.comment", null, RequestContextUtils.getLocale(request)) + ": " : messageSource.getMessage("hrms.performance.overall.appraiser.comments", null, RequestContextUtils.getLocale(request)) + ": "), FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( (isMyAppraisal ? personalData.get("selfcomment") : personalData.get("empcomment")), FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "promotion"); if (!isMyAppraisal && hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.promotion.recommendation", null, RequestContextUtils.getLocale(request)) + ": ", FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( (promotion ? messageSource.getMessage("hrms.MasterData.Yes", null, RequestContextUtils.getLocale(request)) : messageSource.getMessage("hrms.MasterData.No", null, RequestContextUtils.getLocale(request))), FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } if (promotion && !isMyAppraisal && hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { String[] appDetaisPromotionParam = { messageSource.getMessage("hrms.performance.new.department", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.new.designation", null, RequestContextUtils.getLocale(request)) + ": ", messageSource.getMessage("hrms.performance.salary.increment", null, RequestContextUtils.getLocale(request)) + "(%): " }; String[] appDetaisPromotionValue = { personalData.get("newDept") != null ? personalData.get("newDept") : "", personalData.get("newDesig") != null ? personalData.get("newDesig") : "", personalData.get("salInc") != null ? personalData.get("salInc") : "" }; for (int i = 0; i < appDetaisPromotionParam.length; i++) { PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector .process(appDetaisPromotionParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pcell.setBorder(0); pcell.setPaddingTop(10); pcell.setPaddingLeft(15); pcell.setPaddingBottom(4); pcell.setBorderColor(new Color(0xF2F2F2)); pcell.setHorizontalAlignment(Element.ALIGN_LEFT); pcell.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell); PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process(appDetaisPromotionValue[i], FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(0); pcell1.setPaddingTop(10); pcell1.setPaddingLeft(15); pcell1.setPaddingBottom(4); pcell1.setBorderColor(new Color(0xF2F2F2)); pcell1.setHorizontalAlignment(Element.ALIGN_LEFT); pcell1.setVerticalAlignment(Element.ALIGN_LEFT); appDetailsTable.addCell(pcell1); } } document.add(appDetailsTable); //Details //Comp requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "competency"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { try { if (!isQuestion) { JSONArray jsonComp = obj.getJSONArray(0); if (!isMyAppraisal) { String[] compParam = { messageSource.getMessage("hrms.performance.competency", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competency.description", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comment", null, RequestContextUtils.getLocale(request)) }; String[] colParam = { "cmptname", "cmptdesc", "cmptwt", "manrat", "mancompcomment" }; PdfPTable questionTable = null; if (companyPreferences.isWeightage()) { questionTable = new PdfPTable(5); questionTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { questionTable = new PdfPTable(4); questionTable.setWidths(new float[] { 50, 60, 30, 42 }); } questionTable.setWidthPercentage(100); questionTable.setSpacingBefore(20); questionTable.setHeaderRows(1); for (int i = 0; i < compParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(compParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pgcell); } } for (int i = 0; i < jsonComp.length(); i++) { for (int j = 0; j < colParam.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell = null; if (j != 3) pcell = new PdfPCell( new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? jsonComp .getJSONObject(i).getString(colParam[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else { pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? (jsonComp.getJSONObject(i).getString(colParam[j]) .equals("0") ? "" : jsonComp.getJSONObject(i) .getString(colParam[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); } pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pcell); } } } document.add(questionTable); } else { String[] compParam = { messageSource.getMessage("hrms.performance.competency", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.competency.description", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.comments", null, RequestContextUtils.getLocale(request)) }; String[] colParam = { "cmptname", "cmptdesc", "cmptwt", "emprat", "empcompcomment" }; PdfPTable questionTable = null; if (companyPreferences.isWeightage()) { questionTable = new PdfPTable(5); questionTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { questionTable = new PdfPTable(4); questionTable.setWidths(new float[] { 50, 60, 30, 42 }); } questionTable.setWidthPercentage(100); questionTable.setSpacingBefore(20); questionTable.setHeaderRows(1); for (int i = 0; i < compParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(compParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pgcell); } } for (int i = 0; i < jsonComp.length(); i++) { for (int j = 0; j < colParam.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? jsonComp .getJSONObject(i).getString(colParam[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonComp.getJSONObject(i).has(colParam[j]) ? (jsonComp.getJSONObject(i).getString(colParam[j]) .equals("0") ? "" : jsonComp.getJSONObject(i) .getString(colParam[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); questionTable.addCell(pcell); } } } document.add(questionTable); } } else {//Questions try { JSONArray jsonQues = obj.getJSONArray(1); JSONArray jsonAnsTemp = obj.getJSONArray(2); JSONArray jsonAns = new JSONArray(); PdfPTable quesMainTable = new PdfPTable(1); quesMainTable.setTotalWidth(90); quesMainTable.setWidthPercentage(100); quesMainTable.setSpacingBefore(20); quesMainTable.setSkipFirstHeader(true); PdfPCell quesHeadcell = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.qualitative.appraisal", null, RequestContextUtils.getLocale(request)), FontContext.MEDIUM_BOLD_HELVETICA))); quesHeadcell.setPadding(5); quesMainTable.addCell(quesHeadcell); document.add(quesMainTable); PdfPTable[] quesTable = new PdfPTable[jsonQues.length()]; try { for (int i = 0; i < jsonQues.length(); i++) { String qid = (String) jsonQues.getJSONObject(i).get("qdescription"); for (int j = 0; j < jsonAnsTemp.length(); j++) { try { if (qid.equals((String) jsonAnsTemp.getJSONObject(j).get("question"))) { jsonAns.put(jsonAnsTemp.getJSONObject(j)); break; } } catch (JSONException e) { jsonAns.put(""); } } } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < jsonQues.length(); i++) { quesTable[i] = new PdfPTable(2); quesTable[i].setWidthPercentage(90); quesTable[i].setWidths(new float[] { 10, 80 }); quesTable[i].setSpacingBefore(20); quesTable[i].setHeaderRows(1); PdfPCell pgcell1 = new PdfPCell(new Paragraph(fontFamilySelector.process( messageSource.getMessage("hrms.performance.que", null, RequestContextUtils.getLocale(request)) + ".", FontContext.SMALL_NORMAL_HELVETICA))); pgcell1.setBorder(0); pgcell1.setBorder(PdfPCell.BOX); pgcell1.setPadding(4); pgcell1.setHorizontalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pgcell1); PdfPCell pgcell2 = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonQues.getJSONObject(i).has("qdesc") ? jsonQues .getJSONObject(i).getString("qdesc") : "", FontContext.SMALL_NORMAL_HELVETICA))); pgcell2.setBorder(0); pgcell2.setBorder(PdfPCell.BOX); pgcell2.setPadding(4); pgcell2.setHorizontalAlignment(Element.ALIGN_LEFT); quesTable[i].addCell(pgcell2); int cnt = 0; try { cnt = jsonQues.getJSONObject(i).has("qans") ? Integer.parseInt(jsonQues.getJSONObject(i).getString("qans")) : 0; } catch (NumberFormatException e) { e.printStackTrace(); } if (jsonAns.length() > 0) { JSONArray arr = jsonAns.getJSONObject(i).getJSONArray("answer"); for (int j = 0; j < arr.length(); j++) { PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process((j + 1) + "", FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell1.setBorderColor(Color.GRAY); pcell1.setPadding(4); pcell1.setHorizontalAlignment(Element.ALIGN_CENTER); pcell1.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell1); PdfPCell pcell2 = new PdfPCell(new Paragraph(fontFamilySelector.process( arr.getJSONObject(j).getString("" + j + ""), FontContext.SMALL_NORMAL_HELVETICA))); pcell2.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell2.setBorderColor(Color.GRAY); pcell2.setPadding(4); pcell2.setHorizontalAlignment(Element.ALIGN_LEFT); pcell2.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell2); } } else { for (int j = 0; j < cnt; j++) { PdfPCell pcell1 = new PdfPCell(new Paragraph(fontFamilySelector .process((j + 1) + "", FontContext.SMALL_NORMAL_HELVETICA))); pcell1.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell1.setBorderColor(Color.GRAY); pcell1.setPadding(4); pcell1.setHorizontalAlignment(Element.ALIGN_CENTER); pcell1.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell1); PdfPCell pcell = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); quesTable[i].addCell(pcell); } } PdfPCell pcell = new PdfPCell(new Paragraph( fontFamilySelector.process(" ", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); //questionTable.addCell(pcell); document.add(quesTable[i]); } //document.add(questionTable); } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } } //Comp //Goals requestParams.clear(); requestParams.put("companyid", sessionHandlerImplObj.getCompanyid(request)); requestParams.put("checklink", "goal"); if (hrmsCommonDAOObj.checkModule(requestParams).isSuccessFlag()) { try { JSONArray jsonGoals = obj.getJSONArray(3); if (!isMyAppraisal) { String goalParam[] = { messageSource.getMessage("hrms.performance.goals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.percent.completed", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.goal.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.appraiser.comment", null, RequestContextUtils.getLocale(request)) }; String colHeader[] = { "gname", "gcomplete", "gwth", "gmanrat", "mangoalcomment" }; PdfPTable goalTable = null; if (companyPreferences.isWeightage()) { goalTable = new PdfPTable(5); goalTable.setWidths(new float[] { 50, 60, 30, 30, 42 }); } else { goalTable = new PdfPTable(4); goalTable.setWidths(new float[] { 50, 60, 30, 42 }); } goalTable.setWidthPercentage(100); goalTable.setSpacingBefore(20); goalTable.setHeaderRows(1); for (int i = 0; i < goalParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(goalParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pgcell); } } for (int i = 0; i < jsonGoals.length(); i++) { for (int j = 0; j < colHeader.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? jsonGoals.getJSONObject(i) .getString(colHeader[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? (jsonGoals.getJSONObject(i).getString(colHeader[j]) .equals("0") ? "" : jsonGoals.getJSONObject(i) .getString(colHeader[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pcell); } } } document.add(goalTable); } else { String goalParam[] = { messageSource.getMessage("hrms.performance.goals", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.percent.completed", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.goal.weightage", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.rating", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.performance.self.comments", null, RequestContextUtils.getLocale(request)), messageSource.getMessage("hrms.common.assigned.by", null, RequestContextUtils.getLocale(request)) }; String colHeader[] = { "gname", "gcomplete", "gwth", "gemprat", "empgoalcomment", "assignedby" }; PdfPTable goalTable = null; if (companyPreferences.isWeightage()) { goalTable = new PdfPTable(6); goalTable.setWidths(new float[] { 50, 60, 30, 50, 42, 60 }); } else { goalTable = new PdfPTable(5); goalTable.setWidths(new float[] { 50, 60, 50, 42, 60 }); } goalTable.setWidthPercentage(100); goalTable.setSpacingBefore(20); goalTable.setHeaderRows(1); for (int i = 0; i < goalParam.length; i++) { if (!(!companyPreferences.isWeightage() && i == 2)) { PdfPCell pgcell = new PdfPCell(new Paragraph(fontFamilySelector .process(goalParam[i], FontContext.MEDIUM_BOLD_HELVETICA))); pgcell.setBorder(0); pgcell.setBorder(PdfPCell.BOX); pgcell.setPadding(4); pgcell.setBorderColor(Color.GRAY); pgcell.setHorizontalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pgcell); } } for (int i = 0; i < jsonGoals.length(); i++) { for (int j = 0; j < colHeader.length; j++) { if (!(!companyPreferences.isWeightage() && j == 2)) { PdfPCell pcell; if (j != 3) pcell = new PdfPCell( new Paragraph( fontFamilySelector .process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? jsonGoals.getJSONObject(i) .getString(colHeader[j]) : "", FontContext.SMALL_NORMAL_HELVETICA))); else pcell = new PdfPCell(new Paragraph(fontFamilySelector.process( jsonGoals.getJSONObject(i).has(colHeader[j]) ? (jsonGoals.getJSONObject(i).getString(colHeader[j]) .equals("0") ? "" : jsonGoals.getJSONObject(i) .getString(colHeader[j])) : "", FontContext.SMALL_NORMAL_HELVETICA))); pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT); pcell.setBorderColor(Color.GRAY); pcell.setPadding(4); pcell.setHorizontalAlignment(Element.ALIGN_CENTER); pcell.setVerticalAlignment(Element.ALIGN_CENTER); goalTable.addCell(pcell); } } } document.add(goalTable); } } catch (JSONException e) { e.printStackTrace(); } } //Goals document.newPage(); document.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "App_Form" + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(baos.size()); response.getOutputStream().write(baos.toByteArray()); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { writer.close(); } }
From source file:com.prime.report.template.TableHeader.java
/** * Adds a header to every page/*from w ww .j ava2s . c o m*/ * * @param writer * @param document * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage( * com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(4); try { table.setWidths(new int[] { 10, 11, 9, 1 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); Image img = Image.getInstance(logo); table.addCell(Image.getInstance(img)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase("New South West Facility Center", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLDITALIC, Color.BLACK))); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Page %d of", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } catch (IOException ex) { Logger.getLogger(TableHeader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java
License:Open Source License
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *//*from w w w.j a v a 2 s.c o m*/ public ActionForward executeAction() throws PureException { int nYear = request.getRequiredInt("year", ""); Rectangle rectPageSize = new Rectangle(PageSize.A4); rectPageSize.setBackgroundColor(Color.WHITE); rectPageSize.setBorderColor(Color.BLACK); rectPageSize = rectPageSize.rotate(); Document doc = new Document(rectPageSize, 10, 10, 10, 10); doc.addTitle(nYear + ""); doc.addAuthor("PureInfo"); try { BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL); Paragraph paraTitle = new Paragraph(nYear + "", fontTitle); paraTitle.setAlignment(ElementTags.ALIGN_CENTER); BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontContent = new Font(bfontContent, 10, Font.NORMAL); FileFactory fileFactory = FileFactory.getInstance(); String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath(); FileUtil.insurePathExists(sPath); PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf"))); doc.open(); doc.add(paraTitle); doc.add(new Paragraph(" ")); String[] arrTitles = new String[] { "", "", "", "", "", "", "", "", "" }; PdfPTable pTable = new PdfPTable(arrTitles.length); pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 }); for (int i = 0; i < arrTitles.length; i++) { PdfPCell pCell = new PdfPCell(); Paragraph para = new Paragraph(arrTitles[i], fontContent); para.setAlignment(ElementTags.ALIGN_CENTER); pCell.addElement(para); pTable.addCell(pCell); } /** * */ IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class); List patents = mgr.findAllAuthorizedOf(nYear); int i = 0; for (Iterator iter = patents.iterator(); iter.hasNext(); i++) { Patent patent = (Patent) iter.next(); this.addPatentCell(pTable, String.valueOf(i + 1), fontContent); this.addPatentCell(pTable, patent.getPatentSid(), fontContent); this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent); this.addPatentCell(pTable, patent.getWarrantDate() == null ? "" : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent); this.addPatentCell(pTable, patent.getName(), fontContent); this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent); this.addPatentCell(pTable, patent.getRightPerson(), fontContent); this.addPatentCell(pTable, getCollegeName(patent), fontContent); this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent); } doc.add(pTable); doc.close(); } catch (DocumentException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } catch (IOException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } List list = new ArrayList(); list.add(new Pair("/download/patent.pdf", "")); request.setAttribute("forward", list); return mapping.findForward("success"); }
From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java
License:Open Source License
public PdfPTable addMaterialsTable(final Entity costCalculation, final Locale locale) { List<String> materialsTableHeader = Lists.newArrayList(); Map<String, HeaderAlignment> alignments = Maps.newHashMap(); for (String translate : Arrays.asList( L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, "costCalculation.costCalculationDetails.report.columnHeader.quantity", "costCalculation.costCalculationDetails.report.columnHeader.unit", "costCalculation.costCalculationDetails.report.columnHeader.costs", "costCalculation.costCalculationDetails.report.columnHeader.margin", "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) { materialsTableHeader.add(translationService.translate(translate, locale)); }/*from w w w . j a v a2s . c om*/ alignments.put(translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.number", locale), HeaderAlignment.LEFT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.quantity", locale), HeaderAlignment.RIGHT); alignments.put(translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.unit", locale), HeaderAlignment.LEFT); alignments.put(translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.costs", locale), HeaderAlignment.RIGHT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale), HeaderAlignment.RIGHT); alignments.put( translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale), HeaderAlignment.RIGHT); PdfPTable materialsTable = pdfHelper.createTableWithHeader(materialsTableHeader.size(), materialsTableHeader, false, alignments); try { float[] columnWidths = { 1f, 1f, 0.5f, 1f, 1f, 1.5f }; materialsTable.setWidths(columnWidths); } catch (DocumentException e) { throw new IllegalStateException(e.getMessage(), e); } Entity technology; Entity order = costCalculation.getBelongsToField(CostCalculationFields.ORDER); if (order == null) { technology = costCalculation.getBelongsToField(CostCalculationFields.TECHNOLOGY); } else { technology = costCalculation.getBelongsToField(CostCalculationFields.ORDER) .getBelongsToField(CostCalculationFields.TECHNOLOGY); } BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY); Map<Long, BigDecimal> neededProductQuantities = getNeededProductQuantities(costCalculation, technology, quantity, MrpAlgorithm.COMPONENTS_AND_SUBCONTRACTORS_PRODUCTS); // TODO LUPO fix comparator // neededProductQuantities = SortUtil.sortMapUsingComparator(neededProductQuantities, new EntityNumberComparator()); MathContext mathContext = numberService.getMathContext(); for (Entry<Long, BigDecimal> neededProductQuantity : neededProductQuantities.entrySet()) { Entity product = productQuantitiesService.getProduct(neededProductQuantity.getKey()); Entity productEntity = productsCostCalculationService.getAppropriateCostNormForProduct(product, order, costCalculation.getStringField(CostCalculationFields.SOURCE_OF_MATERIAL_COSTS)); BigDecimal productQuantity = neededProductQuantity.getValue(); materialsTable.addCell( new Phrase(product.getStringField(ProductFields.NUMBER), FontUtils.getDejavuRegular7Dark())); materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); materialsTable .addCell(new Phrase(numberService.format(productQuantity), FontUtils.getDejavuRegular7Dark())); materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); materialsTable.addCell( new Phrase(product.getStringField(ProductFields.UNIT), FontUtils.getDejavuRegular7Dark())); materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); BigDecimal costForGivenQuantity = productsCostCalculationService.calculateProductCostForGivenQuantity( productEntity, productQuantity, costCalculation.getStringField(CostCalculationFields.CALCULATE_MATERIAL_COSTS_MODE)); materialsTable.addCell( new Phrase(numberService.format(costForGivenQuantity), FontUtils.getDejavuRegular7Dark())); BigDecimal materialCostMargin = costCalculation .getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN); if (materialCostMargin == null) { materialsTable.addCell(new Phrase(numberService.format(0.0), FontUtils.getDejavuRegular7Dark())); materialsTable.addCell( new Phrase(numberService.format(costForGivenQuantity), FontUtils.getDejavuRegular7Dark())); } else { BigDecimal toAdd = costForGivenQuantity .multiply(materialCostMargin.divide(new BigDecimal(100), mathContext), mathContext); BigDecimal totalCosts = costForGivenQuantity.add(toAdd, mathContext); materialsTable.addCell(new Phrase(numberService.format(toAdd), FontUtils.getDejavuRegular7Dark())); materialsTable .addCell(new Phrase(numberService.format(totalCosts), FontUtils.getDejavuRegular7Dark())); } materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); } BigDecimal totalMaterialCosts = costCalculation.getDecimalField(CostCalculationFields.TOTAL_MATERIAL_COSTS); BigDecimal materialCostsMarginValue = costCalculation .getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN_VALUE); BigDecimal totalCostOfMaterialValue = totalMaterialCosts.add(materialCostsMarginValue, mathContext); String totalMaterialCostsToString = numberService.format(totalMaterialCosts); String materialCostMarginValueToString = numberService.format(materialCostsMarginValue); String totalCostOfMaterialToString = numberService.format(totalCostOfMaterialValue); materialsTable.addCell(new Phrase( translationService.translate("costCalculation.costCalculation.report.totalMaterial", locale), FontUtils.getDejavuRegular7Dark())); materialsTable.addCell(""); materialsTable.addCell(""); materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); materialsTable.addCell(new Phrase(totalMaterialCostsToString, FontUtils.getDejavuRegular7Dark())); materialsTable.addCell(new Phrase(materialCostMarginValueToString, FontUtils.getDejavuRegular7Dark())); materialsTable.addCell(new Phrase(totalCostOfMaterialToString, FontUtils.getDejavuRegular7Dark())); materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); return materialsTable; }
From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java
License:Open Source License
private PdfPTable addHourlyCostsTable(final Entity costCalculation, final Locale locale) { List<String> hourlyCostsTableHeader = Lists.newArrayList(); for (String translate : Arrays.asList("costCalculation.costCalculationDetails.report.columnHeader.level", L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, "costCalculation.costCalculationDetails.report.columnHeader.machDuration", "costCalculation.costCalculationDetails.report.columnHeader.machCosts", "costCalculation.costCalculationDetails.report.columnHeader.labDuration", "costCalculation.costCalculationDetails.report.columnHeader.labCosts", "costCalculation.costCalculationDetails.report.columnHeader.margin", "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) { hourlyCostsTableHeader.add(translationService.translate(translate, locale)); }/*from w ww .j a va 2s .c om*/ Map<String, HeaderAlignment> alignments = Maps.newHashMap(); alignments.put(translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT); alignments.put( translationService .translate(L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale), HeaderAlignment.LEFT); alignments.put( translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.machDuration", locale), HeaderAlignment.RIGHT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.machCosts", locale), HeaderAlignment.RIGHT); alignments.put( translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.labDuration", locale), HeaderAlignment.RIGHT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.labCosts", locale), HeaderAlignment.RIGHT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale), HeaderAlignment.RIGHT); alignments.put( translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale), HeaderAlignment.RIGHT); List<Entity> calculationOperationComponents = costCalculation .getHasManyField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS); PdfPTable hourlyCostsTable = pdfHelper.createTableWithHeader(hourlyCostsTableHeader.size(), hourlyCostsTableHeader, false, alignments); try { float[] columnWidths = { 1f, 0.75f, 1f, 1f, 1f, 1f, 1f, 1.25f }; hourlyCostsTable.setWidths(columnWidths); } catch (DocumentException e) { throw new IllegalStateException(e.getMessage(), e); } if (calculationOperationComponents != null && !calculationOperationComponents.isEmpty()) { Integer totalMachineWorkTimeSummary = Integer.valueOf(0); Integer totalLaborWorkTimeSummary = Integer.valueOf(0); BigDecimal totalOperationCostSummary = BigDecimal.ZERO; MathContext mathContext = numberService.getMathContext(); for (Entity calculationOperationComponent : calculationOperationComponents) { Integer machineWorkTime = calculationOperationComponent .getIntegerField(CalculationOperationComponentFields.MACHINE_WORK_TIME); Integer laborWorkTime = calculationOperationComponent .getIntegerField(CalculationOperationComponentFields.LABOR_WORK_TIME); BigDecimal totalMachineOperationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST); BigDecimal totalLaborOperationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST); BigDecimal operationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.OPERATION_COST); BigDecimal operationMarginCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.OPERATION_MARGIN_COST); BigDecimal totalOperationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.TOTAL_OPERATION_COST); hourlyCostsTable .addCell(new Phrase( calculationOperationComponent .getField(CalculationOperationComponentFields.NODE_NUMBER).toString(), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase( calculationOperationComponent.getBelongsToField(TechnologiesConstants.MODEL_OPERATION) .getStringField(OperationFields.NUMBER), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); hourlyCostsTable.addCell(new Phrase(timeConverterService.convertTimeToString(machineWorkTime), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(numberService.format(totalMachineOperationCost), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(timeConverterService.convertTimeToString(laborWorkTime), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(numberService.format(totalLaborOperationCost), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell( new Phrase(numberService.format(operationMarginCost), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell( new Phrase(numberService.format(totalOperationCost), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); totalMachineWorkTimeSummary += IntegerUtils.convertNullToZero(machineWorkTime); totalLaborWorkTimeSummary += IntegerUtils.convertNullToZero(laborWorkTime); // BigDecimal totalMachineOperationCostWithMargin = // BigDecimalUtils.convertNullToZero(calculationOperationComponent // .getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST_WITH_MARGIN)); // // BigDecimal totalLaborOperationCostWithMargin = BigDecimalUtils.convertNullToZero(calculationOperationComponent // .getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST_WITH_MARGIN)); // BigDecimal totalOperationCostSummary = // totalMachineOperationCostWithMargin.add(totalLaborOperationCostWithMargin, // mathContext); // // totalOperationCostWithMarginSummary = totalOperationCostWithMarginSummary.add(totalOperationCostWithMargin, // mathContext); totalOperationCostSummary = totalOperationCostSummary.add(operationCost, mathContext); } BigDecimal productionCostMarginValue = costCalculation .getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE); BigDecimal totalOperationCost = totalOperationCostSummary.add(productionCostMarginValue, mathContext); String totalMachineWorkTimeToString = timeConverterService .convertTimeToString(totalMachineWorkTimeSummary); String totalMachineHourlyCosts = numberService .format(costCalculation.getDecimalField(CostCalculationFields.TOTAL_MACHINE_HOURLY_COSTS)); String totalLaborWorkTimeToString = timeConverterService.convertTimeToString(totalLaborWorkTimeSummary); String totalLaborHourlyCosts = numberService .format(costCalculation.getDecimalField(CostCalculationFields.TOTAL_LABOR_HOURLY_COSTS)); String totalProductionCostMarginValue = numberService.format(productionCostMarginValue); String totalOperationCostToString = numberService.format(totalOperationCost); hourlyCostsTable.addCell(new Phrase( translationService.translate("costCalculation.costCalculation.report.totalOperation", locale), FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); hourlyCostsTable.addCell(new Phrase(totalMachineWorkTimeToString, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(totalMachineHourlyCosts, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(totalLaborWorkTimeToString, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(totalLaborHourlyCosts, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(totalProductionCostMarginValue, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.addCell(new Phrase(totalOperationCostToString, FontUtils.getDejavuRegular7Dark())); hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); } return hourlyCostsTable; }
From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java
License:Open Source License
private PdfPTable addTableAboutPieceworkCost(final Entity costCalculation, final Locale locale) { List<String> pieceworkCostsTableHeader = Lists.newArrayList(); Map<String, HeaderAlignment> alignments = Maps.newHashMap(); for (String translate : Arrays.asList("costCalculation.costCalculationDetails.report.columnHeader.level", L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, "costCalculation.costCalculationDetails.report.columnHeader.pieces", "costCalculation.costCalculationDetails.report.columnHeader.operationCost", "costCalculation.costCalculationDetails.report.columnHeader.margin", "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) { pieceworkCostsTableHeader.add(translationService.translate(translate, locale)); }//from w w w .j av a 2 s . c o m alignments.put(translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT); alignments.put( translationService .translate(L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale), HeaderAlignment.LEFT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.pieces", locale), HeaderAlignment.RIGHT); alignments.put( translationService.translate( "costCalculation.costCalculationDetails.report.columnHeader.operationCost", locale), HeaderAlignment.RIGHT); alignments.put(translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale), HeaderAlignment.RIGHT); alignments.put( translationService .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale), HeaderAlignment.RIGHT); List<Entity> calculationOperationComponents = costCalculation .getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS); PdfPTable pieceworkCostsTable = pdfHelper.createTableWithHeader(pieceworkCostsTableHeader.size(), pieceworkCostsTableHeader, false, alignments); try { float[] columnWidths = { 1f, 0.75f, 1f, 1f, 1f, 1.25f }; pieceworkCostsTable.setWidths(columnWidths); } catch (DocumentException e) { throw new IllegalStateException(e.getMessage(), e); } if (!calculationOperationComponents.isEmpty()) { BigDecimal totalOperationCostSummary = BigDecimal.ZERO; BigDecimal totalPieces = BigDecimal.ZERO; MathContext mathContext = numberService.getMathContext(); for (Entity calculationOperationComponent : calculationOperationComponents) { BigDecimal pieces = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.PIECES); BigDecimal operationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.OPERATION_COST); BigDecimal operationMarginCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.OPERATION_MARGIN_COST); BigDecimal totalOperationCost = calculationOperationComponent .getDecimalField(CalculationOperationComponentFields.TOTAL_OPERATION_COST); pieceworkCostsTable .addCell(new Phrase( calculationOperationComponent .getField(CalculationOperationComponentFields.NODE_NUMBER).toString(), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell(new Phrase( calculationOperationComponent.getBelongsToField(TechnologiesConstants.MODEL_OPERATION) .getStringField(OperationFields.NUMBER), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); pieceworkCostsTable .addCell(new Phrase(numberService.format(pieces), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell( new Phrase(numberService.format(operationCost), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell( new Phrase(numberService.format(operationMarginCost), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell( new Phrase(numberService.format(totalOperationCost), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); totalPieces = totalPieces.add(pieces, mathContext); totalOperationCostSummary = totalOperationCostSummary.add(operationCost, mathContext); } BigDecimal productionCostMarginValue = costCalculation .getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE); BigDecimal totalOperationCost = totalOperationCostSummary.add(productionCostMarginValue, mathContext); String totalPiecesToString = numberService.format(totalPieces); String totalOperationCostSummaryToString = numberService.format(totalOperationCostSummary); String productionCostMarginValueToString = numberService.format(productionCostMarginValue); String totalOperationCostToString = numberService.format(totalOperationCost); pieceworkCostsTable.addCell(new Phrase( translationService.translate("costCalculation.costCalculation.report.totalOperation", locale), FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); pieceworkCostsTable.addCell(new Phrase(totalPiecesToString, FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable .addCell(new Phrase(totalOperationCostSummaryToString, FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable .addCell(new Phrase(productionCostMarginValueToString, FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.addCell(new Phrase(totalOperationCostToString, FontUtils.getDejavuRegular7Dark())); pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); } return pieceworkCostsTable; }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addOperationTable(PdfWriter pdfWriter, GroupingContainer groupingContainer, Document document, OrderOperationComponent orderOperationComponent, Locale locale) throws DocumentException { Map<Long, Map<OperationProductColumn, ColumnAlignment>> outputProductsMap = groupingContainer .getOperationComponentIdProductOutColumnToAlignment(); Map<Long, Map<OperationProductColumn, ColumnAlignment>> inputProductsMap = groupingContainer .getOperationComponentIdProductInColumnToAlignment(); Entity operationComponent = orderOperationComponent.getOperationComponent(); Entity order = orderOperationComponent.getOrder(); Entity product = order.getBelongsToField(OrderFields.PRODUCT); Map<OperationProductColumn, ColumnAlignment> inputProductColumnAlignmentMap = inputProductsMap .get(operationComponent.getId()); Map<OperationProductColumn, ColumnAlignment> outputProductColumnAlignmentMap = outputProductsMap .get(operationComponent.getId()); PdfPTable table = pdfHelper.createPanelTable(3); PdfPCell headerCell = new PdfPCell(); headerCell.setBorder(Rectangle.NO_BORDER); headerCell.setColspan(2);/*from w w w . j ava2 s. c o m*/ PdfPCell inputCell = new PdfPCell(); inputCell.setBorder(Rectangle.NO_BORDER); PdfPCell outputCell = new PdfPCell(); outputCell.setBorder(Rectangle.NO_BORDER); PdfPCell codeCell = new PdfPCell(); codeCell.setBorder(Rectangle.NO_BORDER); codeCell.setHorizontalAlignment(Element.ALIGN_CENTER); codeCell.setVerticalAlignment(Element.ALIGN_TOP); codeCell.setRowspan(2); // addOperationSummary(headerCell, operationComponent); addOrderSummary(headerCell, order, product, operationComponent); addOperationProductsTable(inputCell, operationProductInComponents(operationComponent, order), inputProductColumnAlignmentMap, ProductDirection.IN, locale); addOperationProductsTable(outputCell, operationProductOutComponents(operationComponent, order), outputProductColumnAlignmentMap, ProductDirection.OUT, locale); codeCell.addElement(createBarcode(pdfWriter, operationComponent)); float[] tableColumnWidths = new float[] { 70f, 70f, 10f }; table.setWidths(tableColumnWidths); table.setTableEvent(null); table.addCell(headerCell); table.addCell(codeCell); table.addCell(inputCell); table.addCell(outputCell); table.setKeepTogether(true); document.add(table); }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addOrderSummary(PdfPCell cell, Entity order, Entity product, Entity operationComponent) throws DocumentException { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); PdfPTable orderTable = pdfHelper.createPanelTable(3); PdfPCell operationCell = new PdfPCell(); operationCell.setBorder(Rectangle.NO_BORDER); Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - " + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark()); operationCell.addElement(operationName); PdfPCell numberCell = new PdfPCell(); numberCell.setBorder(Rectangle.NO_BORDER); Paragraph number = new Paragraph(order.getStringField(OrderFields.NUMBER), FontUtils.getDejavuBold7Dark()); number.setAlignment(Element.ALIGN_RIGHT); numberCell.addElement(number);// w ww.j av a2s . c o m PdfPCell quantityCell = new PdfPCell(); quantityCell.setBorder(Rectangle.NO_BORDER); Paragraph quantity = new Paragraph( numberService.formatWithMinimumFractionDigits(order.getDecimalField(OrderFields.PLANNED_QUANTITY), 0) + " " + product.getStringField(ProductFields.UNIT), FontUtils.getDejavuBold7Dark()); quantity.setAlignment(Element.ALIGN_CENTER); quantityCell.addElement(quantity); PdfPCell descriptionCell = new PdfPCell(); descriptionCell.setBorder(Rectangle.NO_BORDER); descriptionCell.setColspan(3); String comment = operationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); Paragraph description = null; if (!StringUtils.isEmpty(comment)) { description = new Paragraph(comment, FontUtils.getDejavuBold7Dark()); } float[] tableColumnWidths = new float[] { 160f, 30f, 10f }; orderTable.setWidths(tableColumnWidths); orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); orderTable.setTableEvent(null); orderTable.addCell(operationCell); orderTable.addCell(numberCell); orderTable.addCell(quantityCell); if (description != null) { descriptionCell.addElement(description); orderTable.addCell(descriptionCell); } cell.addElement(orderTable); }