001/* 002 * Copyright 2007 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.module.purap.pdf; 017 018import com.lowagie.text.*; 019import com.lowagie.text.pdf.BaseFont; 020import com.lowagie.text.pdf.PdfPCell; 021import com.lowagie.text.pdf.PdfPTable; 022import com.lowagie.text.pdf.PdfWriter; 023import org.apache.commons.lang.ArrayUtils; 024import org.apache.commons.lang.StringUtils; 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.kuali.ole.module.purap.PurapConstants; 028import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem; 029import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorStipulation; 030import org.kuali.ole.module.purap.document.PurchaseOrderDocument; 031import org.kuali.ole.module.purap.document.PurchaseOrderRetransmitDocument; 032import org.kuali.ole.module.purap.exception.PurError; 033import org.kuali.ole.module.purap.util.PurApDateFormatUtils; 034import org.kuali.ole.select.businessobject.OleNoteType; 035import org.kuali.ole.select.businessobject.OleNotes; 036import org.kuali.ole.sys.OLEConstants; 037import org.kuali.ole.sys.context.SpringContext; 038import org.kuali.rice.core.api.util.type.KualiDecimal; 039import org.kuali.rice.krad.service.BusinessObjectService; 040import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 041 042import java.io.ByteArrayOutputStream; 043import java.io.FileNotFoundException; 044import java.io.FileOutputStream; 045import java.io.IOException; 046import java.math.BigDecimal; 047import java.text.NumberFormat; 048import java.text.SimpleDateFormat; 049import java.util.*; 050import java.util.List; 051 052/** 053 * Base class to handle pdf for purchase order documents. 054 */ 055public class PurchaseOrderPdf extends PurapPdf { 056 private static Log LOG = LogFactory.getLog(PurchaseOrderPdf.class); 057 058 /** 059 * headerTable pieces need to be public 060 */ 061 062 public PurchaseOrderPdf() { 063 super(); 064 } 065 066 /** 067 * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if 068 * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content. 069 * 070 * @param writer The PdfWriter for this document. 071 * @param document The document. 072 * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) 073 */ 074 @Override 075 public void onOpenDocument(PdfWriter writer, Document document) { 076 if (LOG.isDebugEnabled()) { 077 LOG.debug("onOpenDocument() started. isRetransmit is " + isRetransmit); 078 } 079 try { 080 float[] headerWidths = {0.20f, 0.80f}; 081 headerTable = new PdfPTable(headerWidths); 082 headerTable.setWidthPercentage(100); 083 headerTable.setHorizontalAlignment(Element.ALIGN_CENTER); 084 headerTable.setSplitLate(false); 085 headerTable.getDefaultCell().setBorderWidth(0); 086 headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 087 headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); 088 089 Image logo = null; 090 if (StringUtils.isNotBlank(logoImage)) { 091 LOG.info(" Logo Image in open document :" + logoImage); 092 try { 093 logo = Image.getInstance(logoImage); 094 } catch (FileNotFoundException e) { 095 LOG.info("The logo image [" + logoImage + "] is not available. Defaulting to the default image."); 096 } 097 } 098 099 if (logo == null) { 100 // if we don't use images 101 headerTable.addCell(new Phrase(new Chunk(""))); 102 } else { 103 logo.scalePercent(3, 3); 104 headerTable.addCell(new Phrase(new Chunk(logo, 0, 0))); 105 } 106 // Nested table for titles, etc. 107 float[] nestedHeaderWidths = {0.70f, 0.30f}; 108 nestedHeaderTable = new PdfPTable(nestedHeaderWidths); 109 nestedHeaderTable.setSplitLate(false); 110 PdfPCell cell; 111 112 // New nestedHeaderTable row 113 cell = new PdfPCell(new Paragraph(po.getBillingName(), ver_15_normal)); 114 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 115 cell.setBorderWidth(0); 116 nestedHeaderTable.addCell(cell); 117 cell = new PdfPCell(new Paragraph(" ", ver_15_normal)); 118 cell.setBorderWidth(0); 119 nestedHeaderTable.addCell(cell); 120 // New nestedHeaderTable row 121 if (isRetransmit) { 122 cell = new PdfPCell(new Paragraph(po.getRetransmitHeader(), ver_15_normal)); 123 } else { 124 cell = new PdfPCell(new Paragraph("PURCHASE ORDER", ver_15_normal)); 125 } 126 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 127 cell.setBorderWidth(0); 128 nestedHeaderTable.addCell(cell); 129 Paragraph p = new Paragraph(); 130 p.add(new Chunk("PO Number: ", ver_11_normal)); 131 p.add(new Chunk(po.getPurapDocumentIdentifier().toString(), cour_7_normal)); 132 133 cell = new PdfPCell(p); 134 cell.setHorizontalAlignment(Element.ALIGN_RIGHT); 135 cell.setBorderWidth(0); 136 nestedHeaderTable.addCell(cell); 137 if (!po.getPurchaseOrderAutomaticIndicator()) { // Contract manager name goes on non-APOs. 138 // New nestedHeaderTable row, spans both columns 139 p = new Paragraph(); 140 p.add(new Chunk("Contract Manager: ", ver_11_normal)); 141 p.add(new Chunk(po.getContractManager().getContractManagerName(), cour_7_normal)); 142 cell = new PdfPCell(p); 143 cell.setColspan(2); 144 cell.setHorizontalAlignment(Element.ALIGN_RIGHT); 145 cell.setBorderWidth(0); 146 nestedHeaderTable.addCell(cell); 147 } 148 // Add the nestedHeaderTable to the headerTable 149 cell = new PdfPCell(nestedHeaderTable); 150 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 151 cell.setBorderWidth(0); 152 headerTable.addCell(cell); 153 154 // initialization of the template 155 tpl = writer.getDirectContent().createTemplate(100, 100); 156 // initialization of the font 157 helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); 158 } catch (Exception e) { 159 throw new ExceptionConverter(e); 160 } 161 } 162 163 /** 164 * Gets a PageEvents object. 165 * 166 * @return a new PageEvents object 167 */ 168 @Override 169 public PurchaseOrderPdf getPageEvents() { 170 LOG.debug("getPageEvents() started."); 171 return new PurchaseOrderPdf(); 172 } 173 174 /** 175 * Generates the pdf document based on the data in the given PurchaseOrderDocument, the pdf parameters, 176 * environment, retransmit items, creates a pdf writer using the given byteArrayOutputStream then 177 * write the pdf document into the writer. 178 * 179 * @param po The PurchaseOrderDocument to be used to generate the pdf. 180 * @param pdfParameters The PurchaseOrderPdfParameters to be used to generate the pdf. 181 * @param byteArrayOutputStream The ByteArrayOutputStream where the pdf document will be written to. 182 * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. 183 * @param environment The current environment used (e.g. DEV if it is a development environment). 184 * @param retransmitItems The items selected by the user to be retransmitted. 185 */ 186 public void generatePdf(PurchaseOrderDocument po, PurchaseOrderTransmitParameters pdfParameters, ByteArrayOutputStream byteArrayOutputStream, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) { 187 if (LOG.isDebugEnabled()) { 188 LOG.debug("generatePdf() started for po number " + po.getPurapDocumentIdentifier()); 189 } 190 191 this.isRetransmit = isRetransmit; 192 String statusInquiryUrl = pdfParameters.getStatusInquiryUrl(); 193 String campusName = pdfParameters.getCampusParameter().getCampus().getName(); 194 String contractLanguage = pdfParameters.getContractLanguage(); 195 String logoImage = pdfParameters.getLogoImage(); 196 logoImage = getImageLocations(logoImage); 197 String directorSignatureImage = pdfParameters.getDirectorSignatureImage(); 198 directorSignatureImage = getImageLocations(directorSignatureImage); 199 String directorName = pdfParameters.getCampusParameter().getCampusPurchasingDirectorName() != null ? pdfParameters.getCampusParameter().getCampusPurchasingDirectorName() : ""; 200 String directorTitle = pdfParameters.getCampusParameter().getCampusPurchasingDirectorTitle() != null ? pdfParameters.getCampusParameter().getCampusPurchasingDirectorTitle() : ""; 201 String contractManagerSignatureImage = pdfParameters.getContractManagerSignatureImage(); 202 contractManagerSignatureImage = getImageLocations(contractManagerSignatureImage); 203 204 if (LOG.isInfoEnabled()) { 205 LOG.info("PDF parameters" + "isRetransmit:" + this.isRetransmit + "statusInquiryUrl:" + statusInquiryUrl 206 + "campusName:" + campusName + "contractLanguage:" + contractLanguage + "logoImage:" + logoImage 207 + "directorSignatureImage:" + directorSignatureImage + "directorName:" + directorName 208 + "directorTitle:" + directorTitle + "contractManagerSignatureImage:" 209 + contractManagerSignatureImage + "isRetransmit" + isRetransmit + "retransmitItems:" 210 + retransmitItems); 211 } 212 try { 213 Document doc = this.getDocument(9, 9, 70, 36); 214 PdfWriter writer = PdfWriter.getInstance(doc, byteArrayOutputStream); 215 this.createPdf(po, doc, writer, statusInquiryUrl, campusName, contractLanguage, logoImage, directorSignatureImage, directorName, directorTitle, contractManagerSignatureImage, isRetransmit, environment, retransmitItems); 216 } catch (DocumentException de) { 217 LOG.error("generatePdf() DocumentException: " + de.getMessage(), de); 218 throw new PurError("Document Exception when trying to save a Purchase Order PDF", de); 219 } catch (IOException i) { 220 LOG.error("generatePdf() IOException: " + i.getMessage(), i); 221 throw new PurError("IO Exception when trying to save a Purchase Order PDF", i); 222 } catch (Exception t) { 223 LOG.error("generatePdf() EXCEPTION: " + t.getMessage(), t); 224 throw new PurError("Exception when trying to save a Purchase Order PDF", t); 225 } 226 } 227 228 /** 229 * Invokes the createPdf method to create a pdf document and saves it into a file 230 * which name and location are specified in the pdfParameters. 231 * 232 * @param po The PurchaseOrderDocument to be used to create the pdf. 233 * @param pdfParameters The pdfParameters containing some of the parameters information needed by the pdf for example, the pdf file name and pdf file location, purchasing director name, etc. 234 * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. 235 * @param environment The current environment used (e.g. DEV if it is a development environment). 236 */ 237 public void savePdf(PurchaseOrderDocument po, PurchaseOrderParameters pdfParameters, boolean isRetransmit, String environment) { 238 if (LOG.isDebugEnabled()) { 239 LOG.debug("savePdf() started for po number " + po.getPurapDocumentIdentifier()); 240 } 241 242 PurchaseOrderTransmitParameters pdfTransmitParameters = (PurchaseOrderTransmitParameters) pdfParameters; 243 244 this.isRetransmit = isRetransmit; 245 String statusInquiryUrl = pdfTransmitParameters.getStatusInquiryUrl(); 246 String campusName = pdfTransmitParameters.getCampusParameter().getCampus().getName(); 247 String contractLanguage = pdfTransmitParameters.getContractLanguage(); 248 String logoImage = pdfTransmitParameters.getLogoImage(); 249 logoImage = getImageLocations(logoImage); 250 String directorSignatureImage = pdfTransmitParameters.getDirectorSignatureImage(); 251 directorSignatureImage = getImageLocations(directorSignatureImage); 252 String directorName = pdfTransmitParameters.getCampusParameter().getCampusPurchasingDirectorName(); 253 String directorTitle = pdfTransmitParameters.getCampusParameter().getCampusPurchasingDirectorTitle(); 254 String contractManagerSignatureImage = pdfTransmitParameters.getContractManagerSignatureImage(); 255 contractManagerSignatureImage = getImageLocations(contractManagerSignatureImage); 256 String pdfFileLocation = pdfTransmitParameters.getPdfFileLocation(); 257 String pdfFileName = pdfTransmitParameters.getPdfFileName(); 258 259 try { 260 Document doc = this.getDocument(9, 9, 70, 36); 261 PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(pdfFileLocation + pdfFileName)); 262 this.createPdf(po, doc, writer, statusInquiryUrl, campusName, contractLanguage, logoImage, directorSignatureImage, directorName, directorTitle, contractManagerSignatureImage, isRetransmit, environment); 263 } catch (DocumentException de) { 264 LOG.error("savePdf() DocumentException: " + de.getMessage(), de); 265 throw new PurError("Document Exception when trying to save a Purchase Order PDF", de); 266 } catch (FileNotFoundException f) { 267 LOG.error("savePdf() FileNotFoundException: " + f.getMessage(), f); 268 throw new PurError("FileNotFound Exception when trying to save a Purchase Order PDF", f); 269 } catch (IOException i) { 270 LOG.error("savePdf() IOException: " + i.getMessage(), i); 271 throw new PurError("IO Exception when trying to save a Purchase Order PDF", i); 272 } catch (Exception t) { 273 LOG.error("savePdf() EXCEPTION: " + t.getMessage(), t); 274 throw new PurError("Exception when trying to save a Purchase Order PDF", t); 275 } 276 } 277 278 /** 279 * Creates the purchase order pdf, and pass in null as the retransmitItems List because it doesn't need retransmit. 280 * 281 * @param po The PurchaseOrderDocument to be used to create the pdf. 282 * @param document The pdf document whose margins have already been set. 283 * @param writer The PdfWriter to write the pdf document into. 284 * @param statusInquiryUrl The status inquiry url to be displayed on the pdf document. 285 * @param campusName The campus name to be displayed on the pdf document. 286 * @param contractLanguage The contract language to be displayed on the pdf document. 287 * @param logoImage The logo image file name to be displayed on the pdf document. 288 * @param directorSignatureImage The director signature image to be displayed on the pdf document. 289 * @param directorName The director name to be displayed on the pdf document. 290 * @param directorTitle The director title to be displayed on the pdf document. 291 * @param contractManagerSignatureImage The contract manager signature image to be displayed on the pdf document. 292 * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. 293 * @param environment The current environment used (e.g. DEV if it is a development environment). 294 * @throws DocumentException 295 * @throws IOException 296 */ 297 private void createPdf(PurchaseOrderDocument po, Document document, PdfWriter writer, String statusInquiryUrl, String campusName, String contractLanguage, String logoImage, String directorSignatureImage, String directorName, String directorTitle, String contractManagerSignatureImage, boolean isRetransmit, String environment) throws DocumentException, IOException { 298 createPdf(po, document, writer, statusInquiryUrl, campusName, contractLanguage, logoImage, directorSignatureImage, directorName, directorTitle, contractManagerSignatureImage, isRetransmit, environment, null); 299 } 300 301 /** 302 * Create a PDF using the given input parameters. 303 * 304 * @param po The PurchaseOrderDocument to be used to create the pdf. 305 * @param document The pdf document whose margins have already been set. 306 * @param writer The PdfWriter to write the pdf document into. 307 * @param statusInquiryUrl The status inquiry url to be displayed on the pdf document. 308 * @param campusName The campus name to be displayed on the pdf document. 309 * @param contractLanguage The contract language to be displayed on the pdf document. 310 * @param logoImage The logo image file name to be displayed on the pdf document. 311 * @param directorSignatureImage The director signature image to be displayed on the pdf document. 312 * @param directorName The director name to be displayed on the pdf document. 313 * @param directorTitle The director title to be displayed on the pdf document. 314 * @param contractManagerSignatureImage The contract manager signature image to be displayed on the pdf document. 315 * @param isRetransmit The boolean to indicate whether this is for a retransmit purchase order document. 316 * @param environment The current environment used (e.g. DEV if it is a development environment). 317 * @param retransmitItems The items selected by the user to be retransmitted. 318 * @throws DocumentException 319 * @throws IOException 320 */ 321 private void createPdf(PurchaseOrderDocument po, Document document, PdfWriter writer, String statusInquiryUrl, String campusName, String contractLanguage, String logoImage, String directorSignatureImage, String directorName, String directorTitle, String contractManagerSignatureImage, boolean isRetransmit, String environment, List<PurchaseOrderItem> retransmitItems) throws DocumentException, IOException { 322 if (LOG.isInfoEnabled()) { 323 LOG.info("Inside createPdf statement" + "PO:" + po + "Document:" + document + "PdfWriter:" + writer 324 + "StatusInquiryUrl:" + statusInquiryUrl + "Campus Name:" + campusName + "Contract Language" 325 + contractLanguage + "Logo Image:" + logoImage + "Director Signature Image:" 326 + directorSignatureImage + "Director Name" + directorName + "Director Title:" + directorTitle 327 + "Contract Manager Signature Image :" + contractManagerSignatureImage + "isRetransmit" 328 + isRetransmit + "Environment" + environment + "retransmitItems" + retransmitItems); 329 } 330 if (LOG.isDebugEnabled()) { 331 LOG.debug("createPdf() started for po number " + po.getPurapDocumentIdentifier().toString()); 332 } 333 334 // These have to be set because they are used by the onOpenDocument() and onStartPage() methods. 335 this.campusName = campusName; 336 this.po = po; 337 this.logoImage = logoImage; 338 this.environment = environment; 339 340 NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US); 341 Collection errors = new ArrayList(); 342 343 // Date format pattern: MM-dd-yyyy 344 SimpleDateFormat sdf = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2); 345 346 // This turns on the page events that handle the header and page numbers. 347 PurchaseOrderPdf events = new PurchaseOrderPdf().getPageEvents(); 348 writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc. 349 350 document.open(); 351 352 PdfPCell cell; 353 Paragraph p = new Paragraph(); 354 355 // ***** Info table (vendor, address info) ***** 356 LOG.debug("createPdf() info table started."); 357 float[] infoWidths = {0.50f, 0.50f}; 358 PdfPTable infoTable = new PdfPTable(infoWidths); 359 360 infoTable.setWidthPercentage(100); 361 infoTable.setHorizontalAlignment(Element.ALIGN_CENTER); 362 infoTable.setSplitLate(false); 363 364 StringBuffer vendorInfo = new StringBuffer(); 365 vendorInfo.append("\n"); 366 if (StringUtils.isNotBlank(po.getVendorName())) { 367 vendorInfo.append(" " + po.getVendorName() + "\n"); 368 } 369 370 vendorInfo.append(" ATTN: " + po.getVendorAttentionName() + "\n"); 371 372 if (StringUtils.isNotBlank(po.getVendorLine1Address())) { 373 vendorInfo.append(" " + po.getVendorLine1Address() + "\n"); 374 } 375 if (StringUtils.isNotBlank(po.getVendorLine2Address())) { 376 vendorInfo.append(" " + po.getVendorLine2Address() + "\n"); 377 } 378 if (StringUtils.isNotBlank(po.getVendorCityName())) { 379 vendorInfo.append(" " + po.getVendorCityName()); 380 } 381 if (StringUtils.isNotBlank(po.getVendorStateCode())) { 382 vendorInfo.append(", " + po.getVendorStateCode()); 383 } 384 if (StringUtils.isNotBlank(po.getVendorAddressInternationalProvinceName())) { 385 vendorInfo.append(", " + po.getVendorAddressInternationalProvinceName()); 386 } 387 if (StringUtils.isNotBlank(po.getVendorPostalCode())) { 388 vendorInfo.append(" " + po.getVendorPostalCode() + "\n"); 389 } else { 390 vendorInfo.append("\n"); 391 } 392 if (!OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getVendorCountryCode()) && po.getVendorCountry() != null) { 393 vendorInfo.append(" " + po.getVendorCountry().getName() + "\n\n"); 394 } else { 395 vendorInfo.append("\n\n"); 396 } 397 p = new Paragraph(); 398 p.add(new Chunk(" Vendor", ver_5_normal)); 399 p.add(new Chunk(vendorInfo.toString(), cour_7_normal)); 400 cell = new PdfPCell(p); 401 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 402 infoTable.addCell(cell); 403 404 StringBuffer shipToInfo = new StringBuffer(); 405 shipToInfo.append("\n"); 406 407 if (po.getAddressToVendorIndicator()) { // use receiving address 408 shipToInfo.append(" " + po.getReceivingName() + "\n"); 409 shipToInfo.append(" " + po.getReceivingLine1Address() + "\n"); 410 if (StringUtils.isNotBlank(po.getReceivingLine2Address())) { 411 shipToInfo.append(" " + po.getReceivingLine2Address() + "\n"); 412 } 413 shipToInfo.append(" " + po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode() + "\n"); 414 if (StringUtils.isNotBlank(po.getReceivingCountryCode()) && !OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getReceivingCountryCode())) { 415 shipToInfo.append(" " + po.getReceivingCountryName() + "\n"); 416 } 417 } else { // use delivery address 418 shipToInfo.append(" " + po.getDeliveryToName() + "\n"); 419 // extra space needed below to separate other text going on same PDF line 420 String deliveryBuildingName = po.getDeliveryBuildingName() + " "; 421 if (po.isDeliveryBuildingOtherIndicator()) { 422 deliveryBuildingName = ""; 423 } 424 shipToInfo.append(" " + deliveryBuildingName + "Room #" + po.getDeliveryBuildingRoomNumber() + "\n"); 425 shipToInfo.append(" " + po.getDeliveryBuildingLine1Address() + "\n"); 426 if (StringUtils.isNotBlank(po.getDeliveryBuildingLine2Address())) { 427 shipToInfo.append(" " + po.getDeliveryBuildingLine2Address() + "\n"); 428 } 429 shipToInfo.append(" " + po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode() + "\n"); 430 if (StringUtils.isNotBlank(po.getDeliveryCountryCode()) && !OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(po.getDeliveryCountryCode())) { 431 shipToInfo.append(" " + po.getDeliveryCountryName() + "\n"); 432 } 433 } 434 // display deliveryToPhoneNumber disregard of whether receiving or delivery address is used 435 shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); 436 /* 437 // display deliveryToPhoneNumber based on the parameter indicator, disregard of whether receiving or delivery address is used 438 boolean displayDeliveryPhoneNumber = SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_DELIVERY_PHONE_NUMBER_ON_PDF_IND); 439 if (displayDeliveryPhoneNumber && StringUtils.isNotBlank(po.getDeliveryToPhoneNumber())) { 440 shipToInfo.append(" " + po.getDeliveryToPhoneNumber()); 441 } 442 */ 443 444 p = new Paragraph(); 445 p.add(new Chunk(" Shipping Address", ver_5_normal)); 446 p.add(new Chunk(shipToInfo.toString(), cour_7_normal)); 447 cell = new PdfPCell(p); 448 infoTable.addCell(cell); 449 450 p = new Paragraph(); 451 p.add(new Chunk(" Shipping Terms\n", ver_5_normal)); 452 if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() != null) { 453 p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); 454 p.add(new Chunk(" - " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); 455 } else if (po.getVendorShippingPaymentTerms() != null && po.getVendorShippingTitle() == null) { 456 p.add(new Chunk(" " + po.getVendorShippingPaymentTerms().getVendorShippingPaymentTermsDescription(), cour_7_normal)); 457 } else if (po.getVendorShippingTitle() != null && po.getVendorShippingPaymentTerms() == null) { 458 p.add(new Chunk(" " + po.getVendorShippingTitle().getVendorShippingTitleDescription(), cour_7_normal)); 459 } 460 cell = new PdfPCell(p); 461 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 462 infoTable.addCell(cell); 463 464 p = new Paragraph(); 465 p.add(new Chunk(" Payment Terms\n", ver_5_normal)); 466 if (po.getVendorPaymentTerms() != null) { 467 p.add(new Chunk(" " + po.getVendorPaymentTerms().getVendorPaymentTermsDescription(), cour_7_normal)); 468 } 469 cell = new PdfPCell(p); 470 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 471 infoTable.addCell(cell); 472 473 p = new Paragraph(); 474 p.add(new Chunk(" Delivery Required By\n", ver_5_normal)); 475 476 if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() != null) { 477 p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); 478 p.add(new Chunk(" - " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); 479 } else if (po.getDeliveryRequiredDate() != null && po.getDeliveryRequiredDateReason() == null) { 480 p.add(new Chunk(" " + sdf.format(po.getDeliveryRequiredDate()), cour_7_normal)); 481 } else if (po.getDeliveryRequiredDate() == null && po.getDeliveryRequiredDateReason() != null) { 482 p.add(new Chunk(" " + po.getDeliveryRequiredDateReason().getDeliveryRequiredDateReasonDescription(), cour_7_normal)); 483 } 484 cell = new PdfPCell(p); 485 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 486 infoTable.addCell(cell); 487 488 p = new Paragraph(); 489 p.add(new Chunk(" ", ver_5_normal)); 490 cell = new PdfPCell(p); 491 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 492 infoTable.addCell(cell); 493 494 // Nested table for Order Date, etc. 495 float[] nestedInfoWidths = {0.50f, 0.50f}; 496 PdfPTable nestedInfoTable = new PdfPTable(nestedInfoWidths); 497 nestedInfoTable.setSplitLate(false); 498 499 p = new Paragraph(); 500 p.add(new Chunk(" Order Date\n", ver_5_normal)); 501 502 String orderDate = ""; 503 if (po.getPurchaseOrderInitialOpenTimestamp() != null) { 504 orderDate = sdf.format(po.getPurchaseOrderInitialOpenTimestamp()); 505 } else { 506 // This date isn't set until the first time this document is printed, so will be null the first time; use today's date. 507 orderDate = sdf.format(getDateTimeService().getCurrentSqlDate()); 508 } 509 510 p.add(new Chunk(" " + orderDate, cour_7_normal)); 511 cell = new PdfPCell(p); 512 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 513 nestedInfoTable.addCell(cell); 514 515 p = new Paragraph(); 516 p.add(new Chunk(" Customer #\n", ver_5_normal)); 517 if (po.getVendorCustomerNumber() != null) { 518 p.add(new Chunk(" " + po.getVendorCustomerNumber(), cour_7_normal)); 519 } 520 cell = new PdfPCell(p); 521 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 522 nestedInfoTable.addCell(cell); 523 524 p = new Paragraph(); 525 p.add(new Chunk(" Delivery Instructions\n", ver_5_normal)); 526 if (StringUtils.isNotBlank(po.getDeliveryInstructionText())) { 527 p.add(new Chunk(" " + po.getDeliveryInstructionText(), cour_7_normal)); 528 } 529 cell = new PdfPCell(p); 530 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 531 nestedInfoTable.addCell(cell); 532 533 p = new Paragraph(); 534 p.add(new Chunk(" Contract ID\n", ver_5_normal)); 535 if (po.getVendorContract() != null) { 536 p.add(new Chunk(po.getVendorContract().getVendorContractName(), cour_7_normal)); 537 } 538 cell = new PdfPCell(p); 539 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 540 nestedInfoTable.addCell(cell); 541 542 // Add the nestedInfoTable to the infoTable 543 cell = new PdfPCell(nestedInfoTable); 544 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 545 infoTable.addCell(cell); 546 547 StringBuffer billToInfo = new StringBuffer(); 548 billToInfo.append("\n"); 549 billToInfo.append(" " + po.getBillingName() + "\n"); 550 billToInfo.append(" " + po.getBillingLine1Address() + "\n"); 551 if (po.getBillingLine2Address() != null) { 552 billToInfo.append(" " + po.getBillingLine2Address() + "\n"); 553 } 554 billToInfo.append(" " + po.getBillingCityName() + ", " + po.getBillingStateCode() + " " + po.getBillingPostalCode() + "\n"); 555 if (po.getBillingPhoneNumber() != null) { 556 billToInfo.append(" " + po.getBillingPhoneNumber()); 557 } 558 if (po.getBillingEmailAddress() != null) { 559 billToInfo.append("\n " + po.getBillingEmailAddress()); 560 } 561 p = new Paragraph(); 562 p.add(new Chunk(" Billing Address", ver_5_normal)); 563 p.add(new Chunk(" " + billToInfo.toString(), cour_7_normal)); 564 p.add(new Chunk("\n Invoice status inquiry: " + statusInquiryUrl, ver_6_normal)); 565 cell = new PdfPCell(p); 566 cell.setHorizontalAlignment(Element.ALIGN_LEFT); 567 infoTable.addCell(cell); 568 569 document.add(infoTable); 570 571 PdfPTable notesStipulationsTable = new PdfPTable(1); 572 notesStipulationsTable.setWidthPercentage(100); 573 notesStipulationsTable.setSplitLate(false); 574 575 p = new Paragraph(); 576 p.add(new Chunk(" Vendor Note(s)\n", ver_5_normal)); 577 if (po.getVendorNoteText() != null) { 578 p.add(new Chunk(" " + po.getVendorNoteText() + "\n", cour_7_normal)); 579 } 580 581 PdfPCell tableCell = new PdfPCell(p); 582 tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); 583 tableCell.setVerticalAlignment(Element.ALIGN_TOP); 584 585 notesStipulationsTable.addCell(tableCell); 586 587 p = new Paragraph(); 588 p.add(new Chunk(" Vendor Stipulations and Information\n", ver_5_normal)); 589 if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) { 590 p.add(new Chunk(" Order in effect from " + sdf.format(po.getPurchaseOrderBeginDate()) + " to " + sdf.format(po.getPurchaseOrderEndDate()) + ".\n", cour_7_normal)); 591 592 } 593 Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po.getPurchaseOrderVendorStipulations(); 594 if (vendorStipulationsList.size() > 0) { 595 StringBuffer vendorStipulations = new StringBuffer(); 596 for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) { 597 vendorStipulations.append(" " + povs.getVendorStipulationDescription() + "\n"); 598 } 599 p.add(new Chunk(" " + vendorStipulations.toString(), cour_7_normal)); 600 } 601 602 tableCell = new PdfPCell(p); 603 tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); 604 tableCell.setVerticalAlignment(Element.ALIGN_TOP); 605 notesStipulationsTable.addCell(tableCell); 606 607 document.add(notesStipulationsTable); 608 609 // ***** Items table ***** 610 LOG.debug("createPdf() items table started."); 611 612 float[] itemsWidths = {0.07f, 0.1f, 0.07f, 0.25f, 0.25f, 0.10f, 0.10f}; 613 614 if (!po.isUseTaxIndicator()) { 615 itemsWidths = ArrayUtils.add(itemsWidths, 0.14f); 616 itemsWidths = ArrayUtils.add(itemsWidths, 0.15f); 617 } 618 619 PdfPTable itemsTable = new PdfPTable(itemsWidths.length); 620 621 // itemsTable.setCellsFitPage(false); With this set to true a large cell will 622 // skip to the next page. The default Table behaviour seems to be what we want: 623 // start the large cell on the same page and continue it to the next. 624 itemsTable.setWidthPercentage(100); 625 itemsTable.setWidths(itemsWidths); 626 itemsTable.setSplitLate(false); 627 628 tableCell = new PdfPCell(new Paragraph("Item\nNo.", ver_5_normal)); 629 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 630 itemsTable.addCell(tableCell); 631 tableCell = new PdfPCell(new Paragraph("Quantity", ver_5_normal)); 632 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 633 itemsTable.addCell(tableCell); 634 tableCell = new PdfPCell(new Paragraph("UOM", ver_5_normal)); 635 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 636 itemsTable.addCell(tableCell); 637 tableCell = new PdfPCell(new Paragraph("Description", ver_5_normal)); 638 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 639 itemsTable.addCell(tableCell); 640 tableCell = new PdfPCell(new Paragraph("Special Instructions", ver_5_normal)); 641 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 642 itemsTable.addCell(tableCell); 643 tableCell = new PdfPCell(new Paragraph("Unit Cost", ver_5_normal)); 644 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 645 itemsTable.addCell(tableCell); 646 tableCell = new PdfPCell(new Paragraph("Extended Cost", ver_5_normal)); 647 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 648 itemsTable.addCell(tableCell); 649 650 if (!po.isUseTaxIndicator()) { 651 tableCell = new PdfPCell(new Paragraph("Tax Amount", ver_5_normal)); 652 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 653 itemsTable.addCell(tableCell); 654 655 tableCell = new PdfPCell(new Paragraph("Total Amount", ver_5_normal)); 656 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 657 itemsTable.addCell(tableCell); 658 } 659 660 Collection<PurchaseOrderItem> itemsList = new ArrayList(); 661 if (isRetransmit) { 662 itemsList = retransmitItems; 663 } else { 664 itemsList = po.getItems(); 665 } 666 for (PurchaseOrderItem poi : itemsList) { 667 if ((poi.getItemType() != null) && (poi.getItemType().isLineItemIndicator() || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) && lineItemDisplaysOnPdf(poi)) { 668 boolean noteFlag = true; 669 String description = (poi.getItemCatalogNumber() != null) ? poi.getItemCatalogNumber().trim() + " - " : ""; 670 String vendorNotes = ""; 671 if (poi.getNotes().size() > 0) { 672 for(OleNotes oleNotes : poi.getNotes()){ 673 String note = getNoteType(oleNotes.getNoteTypeId()); 674 if ((note != null && note.equals(OLEConstants.VENDOR_TYPE)) && noteFlag) { 675 vendorNotes = oleNotes.getNote(); 676 noteFlag = false; 677 } 678 } 679 } 680 681 description = description + ((poi.getItemDescription() != null) ? poi.getItemDescription().trim() : ""); 682 if (StringUtils.isNotBlank(description)) { 683 if (poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)) { 684 // If this is a full order discount or trade-in item, we add the item type description to the description. 685 description = poi.getItemType().getItemTypeDescription() + " - " + description; 686 } 687 } 688 689 // Above the line item types items display the line number; other types don't. 690 if (poi.getItemType().isLineItemIndicator()) { 691 tableCell = new PdfPCell(new Paragraph(poi.getItemLineNumber().toString(), cour_7_normal)); 692 } else { 693 tableCell = new PdfPCell(new Paragraph(" ", cour_7_normal)); 694 } 695 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 696 itemsTable.addCell(tableCell); 697 String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " "; 698 tableCell = new PdfPCell(new Paragraph(quantity, cour_7_normal)); 699 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 700 tableCell.setNoWrap(true); 701 itemsTable.addCell(tableCell); 702 tableCell = new PdfPCell(new Paragraph(poi.getItemUnitOfMeasureCode(), cour_7_normal)); 703 tableCell.setHorizontalAlignment(Element.ALIGN_CENTER); 704 itemsTable.addCell(tableCell); 705 706 tableCell = new PdfPCell(new Paragraph(" " + description, cour_7_normal)); 707 tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); 708 itemsTable.addCell(tableCell); 709 tableCell = new PdfPCell(new Paragraph(" " + vendorNotes, cour_7_normal)); 710 tableCell.setHorizontalAlignment(Element.ALIGN_LEFT); 711 itemsTable.addCell(tableCell); 712 String unitPrice = poi.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); 713 tableCell = new PdfPCell(new Paragraph(unitPrice + " ", cour_7_normal)); 714 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 715 tableCell.setNoWrap(true); 716 itemsTable.addCell(tableCell); 717 tableCell = new PdfPCell(new Paragraph(numberFormat.format(poi.getExtendedPrice()) + " ", cour_7_normal)); 718 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 719 tableCell.setNoWrap(true); 720 itemsTable.addCell(tableCell); 721 722 if (!po.isUseTaxIndicator()) { 723 KualiDecimal taxAmount = poi.getItemTaxAmount(); 724 taxAmount = taxAmount == null ? KualiDecimal.ZERO : taxAmount; 725 tableCell = new PdfPCell(new Paragraph(numberFormat.format(taxAmount) + " ", cour_7_normal)); 726 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 727 tableCell.setNoWrap(true); 728 itemsTable.addCell(tableCell); 729 730 tableCell = new PdfPCell(new Paragraph(numberFormat.format(poi.getTotalAmount()) + " ", cour_7_normal)); 731 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 732 tableCell.setNoWrap(true); 733 itemsTable.addCell(tableCell); 734 } 735 736 } 737 } 738 // Blank line before totals 739 itemsTable.addCell(" "); 740 itemsTable.addCell(" "); 741 itemsTable.addCell(" "); 742 itemsTable.addCell(" "); 743 itemsTable.addCell(" "); 744 itemsTable.addCell(" "); 745 746 if (!po.isUseTaxIndicator()) { 747 itemsTable.addCell(" "); 748 itemsTable.addCell(" "); 749 } 750 751 //Next Line 752 if (!po.isUseTaxIndicator()) { 753 754 //Print Total Prior to Tax 755 itemsTable.addCell(" "); 756 itemsTable.addCell(" "); 757 itemsTable.addCell(" "); 758 itemsTable.addCell(" "); 759 itemsTable.addCell(" "); 760 761 tableCell = new PdfPCell(new Paragraph("Total Prior to Tax: ", ver_10_normal)); 762 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 763 itemsTable.addCell(tableCell); 764 itemsTable.addCell(" "); 765 KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); 766 if (po instanceof PurchaseOrderRetransmitDocument) { 767 totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalPreTaxDollarAmountForRetransmit(); 768 } else { 769 totalDollarAmount = po.getTotalPreTaxDollarAmount(); 770 } 771 tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); 772 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 773 tableCell.setNoWrap(true); 774 itemsTable.addCell(tableCell); 775 776 //Print Total Tax 777 itemsTable.addCell(" "); 778 itemsTable.addCell(" "); 779 itemsTable.addCell(" "); 780 itemsTable.addCell(" "); 781 itemsTable.addCell(" "); 782 783 tableCell = new PdfPCell(new Paragraph("Total Tax: ", ver_10_normal)); 784 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 785 itemsTable.addCell(tableCell); 786 itemsTable.addCell(" "); 787 totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); 788 if (po instanceof PurchaseOrderRetransmitDocument) { 789 totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalTaxDollarAmountForRetransmit(); 790 } else { 791 totalDollarAmount = po.getTotalTaxAmount(); 792 } 793 tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); 794 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 795 tableCell.setNoWrap(true); 796 itemsTable.addCell(tableCell); 797 798 } 799 800 // Totals line; first 5 cols empty 801 itemsTable.addCell(" "); 802 itemsTable.addCell(" "); 803 itemsTable.addCell(" "); 804 itemsTable.addCell(" "); 805 itemsTable.addCell(" "); 806 807 if (!po.isUseTaxIndicator()) { 808 itemsTable.addCell(" "); 809 itemsTable.addCell(" "); 810 } 811 812 tableCell = new PdfPCell(new Paragraph("Total order amount: ", ver_10_normal)); 813 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 814 itemsTable.addCell(tableCell); 815 itemsTable.addCell(" "); 816 KualiDecimal totalDollarAmount = new KualiDecimal(BigDecimal.ZERO); 817 if (po instanceof PurchaseOrderRetransmitDocument) { 818 totalDollarAmount = ((PurchaseOrderRetransmitDocument) po).getTotalDollarAmountForRetransmit(); 819 } else { 820 totalDollarAmount = po.getTotalDollarAmount(); 821 } 822 tableCell = new PdfPCell(new Paragraph(numberFormat.format(totalDollarAmount) + " ", cour_7_normal)); 823 tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT); 824 tableCell.setNoWrap(true); 825 itemsTable.addCell(tableCell); 826 // Blank line after totals 827 itemsTable.addCell(" "); 828 itemsTable.addCell(" "); 829 itemsTable.addCell(" "); 830 itemsTable.addCell(" "); 831 itemsTable.addCell(" "); 832 itemsTable.addCell(" "); 833 834 if (!po.isUseTaxIndicator()) { 835 itemsTable.addCell(" "); 836 itemsTable.addCell(" "); 837 } 838 839 document.add(itemsTable); 840 841 // Contract language. 842 LOG.debug("createPdf() contract language started."); 843 document.add(new Paragraph(contractLanguage, ver_6_normal)); 844 document.add(new Paragraph("\n", ver_6_normal)); 845 846 // ***** Signatures table ***** 847 LOG.debug("createPdf() signatures table started."); 848 float[] signaturesWidths = {0.30f, 0.70f}; 849 PdfPTable signaturesTable = new PdfPTable(signaturesWidths); 850 signaturesTable.setWidthPercentage(100); 851 signaturesTable.setHorizontalAlignment(Element.ALIGN_CENTER); 852 signaturesTable.setSplitLate(false); 853 854 // Director signature and "for more info" line; only on APOs 855 if (po.getPurchaseOrderAutomaticIndicator()) { 856 // Empty cell. 857 cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); 858 cell.setBorderWidth(0); 859 signaturesTable.addCell(cell); 860 861 //boolean displayRequestorEmail = true; //SpringContext.getBean(ParameterService.class).getIndicatorParameter(PurchaseOrderDocument.class, PurapParameterConstants.DISPLAY_REQUESTOR_EMAIL_ADDRESS_ON_PDF_IND); 862 if (StringUtils.isBlank(po.getInstitutionContactName()) || StringUtils.isBlank(po.getInstitutionContactPhoneNumber()) || StringUtils.isBlank(po.getInstitutionContactEmailAddress())) { 863 //String emailAddress = displayRequestorEmail ? " " + po.getRequestorPersonEmailAddress() : ""; 864 //p = new Paragraph("For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + emailAddress, cour_7_normal); 865 p = new Paragraph("For more information contact: " + po.getRequestorPersonName() + " " + po.getRequestorPersonPhoneNumber() + " " + po.getRequestorPersonEmailAddress(), cour_7_normal); 866 } else { 867 //String emailAddress = displayRequestorEmail ? " " + po.getInstitutionContactEmailAddress() : ""; 868 //p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + emailAddress, cour_7_normal); 869 p = new Paragraph("For more information contact: " + po.getInstitutionContactName() + " " + po.getInstitutionContactPhoneNumber() + " " + po.getInstitutionContactEmailAddress(), cour_7_normal); 870 } 871 cell = new PdfPCell(p); 872 cell.setHorizontalAlignment(Element.ALIGN_RIGHT); 873 cell.setVerticalAlignment(Element.ALIGN_CENTER); 874 cell.setBorderWidth(0); 875 signaturesTable.addCell(cell); 876 877 Image directorSignature = null; 878 if (StringUtils.isNotBlank(directorSignatureImage)) { 879 try { 880 directorSignature = Image.getInstance(directorSignatureImage); 881 } catch (FileNotFoundException e) { 882 LOG.info("The director signature image [" + directorSignatureImage + "] is not available. Defaulting to the default image."); 883 } 884 } 885 886 if (directorSignature == null) { 887 // an empty cell if the contract manager signature image is not available. 888 cell = new PdfPCell(); 889 } else { 890 directorSignature.scalePercent(30, 30); 891 cell = new PdfPCell(directorSignature, false); 892 } 893 894 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 895 cell.setVerticalAlignment(Element.ALIGN_BOTTOM); 896 cell.setBorderWidth(0); 897 signaturesTable.addCell(cell); 898 899 // Empty cell. 900 cell = new PdfPCell(new Paragraph(" ", cour_7_normal)); 901 cell.setBorderWidth(0); 902 signaturesTable.addCell(cell); 903 } 904 905 // Director name and title; on every pdf. 906 p = new Paragraph(); 907 if (LOG.isDebugEnabled()) { 908 LOG.debug("createPdf() directorName parameter: " + directorName); 909 } 910 if (po.getPurchaseOrderAutomaticIndicator()) { // The signature is on the pdf; use small font. 911 p.add(new Chunk(directorName, ver_6_normal)); 912 } else { // The signature isn't on the pdf; use larger font. 913 p.add(new Chunk(directorName, ver_10_normal)); 914 } 915 p.add(new Chunk("\n" + directorTitle, ver_4_normal)); 916 cell = new PdfPCell(p); 917 cell.setHorizontalAlignment(Element.ALIGN_CENTER); 918 cell.setVerticalAlignment(Element.ALIGN_TOP); 919 cell.setBorderWidth(0); 920 signaturesTable.addCell(cell); 921 922 // Contract manager signature, name and phone; only on non-APOs 923 if (!po.getPurchaseOrderAutomaticIndicator()) { 924 925 Image contractManagerSignature = null; 926 if (StringUtils.isNotBlank(contractManagerSignatureImage)) { 927 try { 928 contractManagerSignature = Image.getInstance(contractManagerSignatureImage); 929 } catch (FileNotFoundException e) { 930 LOG.info("The contract manager image [" + contractManagerSignatureImage + "] is not available. Defaulting to the default image."); 931 } 932 } 933 934 if (contractManagerSignature == null) { 935 // an empty cell if the contract manager signature image is not available. 936 cell = new PdfPCell(); 937 } else { 938 contractManagerSignature.scalePercent(15, 15); 939 cell = new PdfPCell(contractManagerSignature, false); 940 } 941 cell.setHorizontalAlignment(Element.ALIGN_RIGHT); 942 cell.setVerticalAlignment(Element.ALIGN_BOTTOM); 943 cell.setBorderWidth(0); 944 signaturesTable.addCell(cell); 945 946 // Empty cell. 947 cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); 948 cell.setBorderWidth(0); 949 signaturesTable.addCell(cell); 950 951 cell = new PdfPCell(new Paragraph(po.getContractManager().getContractManagerName() + " " + po.getContractManager().getContractManagerPhoneNumber(), cour_7_normal)); 952 cell.setHorizontalAlignment(Element.ALIGN_RIGHT); 953 cell.setVerticalAlignment(Element.ALIGN_TOP); 954 cell.setBorderWidth(0); 955 signaturesTable.addCell(cell); 956 } else { // Empty cell. 957 cell = new PdfPCell(new Paragraph(" ", ver_10_normal)); 958 cell.setBorderWidth(0); 959 signaturesTable.addCell(cell); 960 } 961 document.add(signaturesTable); 962 963 document.close(); 964 LOG.debug("createPdf()pdf document closed."); 965 } // End of createPdf() 966 967 /** 968 * Determines whether the item should be displayed on the pdf. 969 * 970 * @param poi The PurchaseOrderItem to be determined whether it should be displayed on the pdf. 971 * @return boolean true if it should be displayed on the pdf. 972 */ 973 private boolean lineItemDisplaysOnPdf(PurchaseOrderItem poi) { 974 LOG.debug("lineItemDisplaysOnPdf() started"); 975 976 // Shipping, freight, full order discount and trade in items. 977 if ((poi.getItemType() != null) && (poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) { 978 979 // If the unit price is not null and either the unit price > 0 or the item type is full order discount or trade in, 980 // we'll display this line item on pdf. 981 if ((poi.getItemUnitPrice() != null) && ((poi.getItemUnitPrice().compareTo(zero.bigDecimalValue()) == 1) || (poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) || (poi.getItemType().getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)))) { 982 if (LOG.isDebugEnabled()) { 983 LOG.debug("lineItemDisplaysOnPdf() Item type is " + poi.getItemType().getItemTypeCode() + ". Unit price is " + poi.getItemUnitPrice() + ". Display on pdf."); 984 } 985 return true; 986 } 987 if (LOG.isDebugEnabled()) { 988 LOG.debug("lineItemDisplaysOnPdf() Item type is " + poi.getItemType().getItemTypeCode() + ". Unit price is " + poi.getItemUnitPrice() + ". Don't display on pdf."); 989 } 990 return false; 991 } else if ((poi.getItemType() != null) && poi.getItemType().isLineItemIndicator()) { 992 if (poi.getItemQuantity() == null && poi.getItemUnitPrice() == null) { 993 if (LOG.isDebugEnabled()) { 994 LOG.debug("lineItemDisplaysOnPdf() Item type is " + poi.getItemType().getItemTypeCode() + " OrderQuantity and unit price are both null. Display on pdf."); 995 } 996 return true; 997 } 998 if ((poi.getItemType().isAmountBasedGeneralLedgerIndicator() && ((poi.getItemUnitPrice() != null) && (poi.getItemUnitPrice().compareTo(zero.bigDecimalValue()) >= 0))) || (((poi.getItemType().isQuantityBasedGeneralLedgerIndicator()) && (poi.getItemQuantity().isGreaterThan(zero))) && (poi.getItemUnitPrice() != null))) { 999 if (LOG.isDebugEnabled()) { 1000 LOG.debug("lineItemDisplaysOnPdf() Item type is " + poi.getItemType().getItemTypeCode() + " OrderQuantity is " + poi.getItemQuantity() + ". Unit price is " + poi.getItemUnitPrice() + ". Display on pdf."); 1001 } 1002 return true; 1003 } else { 1004 if (LOG.isDebugEnabled()) { 1005 LOG.debug("lineItemDisplaysOnPdf() Item type is " + poi.getItemType().getItemTypeCode() + " and item order quantity is " + poi.getItemQuantity() + " and item unit price is " + poi.getItemUnitPrice() + ". Don't display on pdf."); 1006 } 1007 } 1008 } 1009 return false; 1010 } 1011 1012 1013 public String getImageLocations(String existingLocation) { 1014 LOG.info("In Get Image Location"); 1015 String filesPathAndName = getClass().getClassLoader().getResource("/").getPath(); 1016 filesPathAndName = filesPathAndName.replace("WEB-INF/classes/", "static/images/"); 1017 try { 1018 String[] imageNameList = existingLocation.split("/"); 1019 LOG.info("File Name" + imageNameList[(imageNameList.length - 1)]); 1020 filesPathAndName = filesPathAndName + (imageNameList[(imageNameList.length - 1)]); 1021 } catch (Exception e) { 1022 LOG.info("Exception when getting the Image Location" + e.getMessage()); 1023 } 1024 return filesPathAndName; 1025 } 1026 1027 public String getNoteType(Integer noteTypeId) { 1028 Map criteriaMap = new HashMap(); 1029 criteriaMap.put(OLEConstants.NOTE_ID, noteTypeId); 1030 OleNoteType oleNoteType = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleNoteType.class, criteriaMap); 1031 if (oleNoteType != null) { 1032 return oleNoteType.getNoteType(); 1033 } 1034 return ""; 1035 } 1036 1037}