View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.pdf;
17  
18  import com.lowagie.text.*;
19  import com.lowagie.text.pdf.BaseFont;
20  import com.lowagie.text.pdf.PdfPCell;
21  import com.lowagie.text.pdf.PdfPTable;
22  import com.lowagie.text.pdf.PdfWriter;
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.kuali.ole.module.purap.PurapConstants;
27  import org.kuali.ole.module.purap.PurapPropertyConstants;
28  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
29  import org.kuali.ole.module.purap.businessobject.PurchaseOrderQuoteLanguage;
30  import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote;
31  import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorStipulation;
32  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
33  import org.kuali.ole.module.purap.exception.PurError;
34  import org.kuali.ole.module.purap.util.PurApDateFormatUtils;
35  import org.kuali.ole.sys.OLEConstants;
36  import org.kuali.ole.sys.OLEPropertyConstants;
37  import org.kuali.ole.sys.context.SpringContext;
38  import org.kuali.ole.vnd.businessobject.CampusParameter;
39  import org.kuali.ole.vnd.businessobject.ContractManager;
40  import org.kuali.rice.krad.service.BusinessObjectService;
41  import org.kuali.rice.krad.util.ObjectUtils;
42  
43  import java.io.ByteArrayOutputStream;
44  import java.io.FileNotFoundException;
45  import java.io.FileOutputStream;
46  import java.text.NumberFormat;
47  import java.text.ParseException;
48  import java.text.SimpleDateFormat;
49  import java.util.*;
50  import java.util.List;
51  
52  /**
53   *
54   *
55   */
56  public class PurchaseOrderQuotePdf extends PurapPdf {
57      private static Log LOG = LogFactory.getLog(PurchaseOrderQuotePdf.class);
58  
59      public PurchaseOrderQuotePdf() {
60          super();
61      }
62  
63      /**
64       * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable with relevant contents
65       * and set its logo image if there is a logoImage to be used.
66       *
67       * @param writer   The PdfWriter for this document.
68       * @param document The document.
69       * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
70       */
71      public void onOpenDocument(PdfWriter writer, Document document) {
72          LOG.debug("onOpenDocument() started.");
73          try {
74              float[] headerWidths = {0.20f, 0.60f, 0.20f};
75              headerTable = new PdfPTable(headerWidths);
76              headerTable.setWidthPercentage(100);
77              headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);
78  
79              headerTable.getDefaultCell().setBorderWidth(0);
80              headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
81              headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
82  
83              if (StringUtils.isNotBlank(logoImage)) {
84                  logo = Image.getInstance(logoImage);
85                  logo.scalePercent(3, 3);
86                  headerTable.addCell(new Phrase(new Chunk(logo, 0, 0)));
87              } else {
88                  // if we don't use images
89                  headerTable.addCell(new Phrase(new Chunk("")));
90              }
91              PdfPCell cell;
92              cell = new PdfPCell(new Paragraph("REQUEST FOR QUOTATION\nTHIS IS NOT AN ORDER", ver_17_normal));
93              cell.setBorderWidth(0);
94              cell.setHorizontalAlignment(Element.ALIGN_CENTER);
95              headerTable.addCell(cell);
96  
97              Paragraph p = new Paragraph();
98              p.add(new Chunk("\n     R.Q. Number: ", ver_8_bold));
99              p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal));
100             cell = new PdfPCell(p);
101             cell.setBorderWidth(0);
102             headerTable.addCell(cell);
103 
104             // initialization of the template
105             tpl = writer.getDirectContent().createTemplate(100, 100);
106             // initialization of the font
107             helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
108         } catch (Exception e) {
109             throw new ExceptionConverter(e);
110         }
111     }
112 
113     /**
114      * Gets a PageEvents object.
115      *
116      * @return a new PageEvents object
117      */
118     public PurchaseOrderQuotePdf getPageEvents() {
119         LOG.debug("getPageEvents() started.");
120         return new PurchaseOrderQuotePdf();
121     }
122 
123     /**
124      * Generates the purchase order quote pdf document based on the data in the given input parameters,
125      * creates a pdf writer using the given byteArrayOutputStream then write the pdf document into the writer.
126      *
127      * @param po                        The PurchaseOrderDocument to be used to generate the pdf.
128      * @param poqv                      The PurchaseOrderVendorQuote to be used to generate the pdf.
129      * @param campusName                The campus name to be used to generate the pdf.
130      * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
131      * @param logoImage                 The logo image file name to be used to generate the pdf.
132      * @param byteArrayOutputStream     The ByteArrayOutputStream to print the pdf to.
133      * @param environment               The current environment used (e.g. DEV if it is a development environment).
134      */
135     public void generatePOQuotePDF(PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, String campusName, String contractManagerCampusCode, String logoImage, ByteArrayOutputStream byteArrayOutputStream, String environment) {
136         if (LOG.isDebugEnabled()) {
137             LOG.debug("generatePOQuotePDF() started for po number " + po.getPurapDocumentIdentifier());
138         }
139 
140         Collection errors = new ArrayList();
141 
142         try {
143             Document doc = getDocument(9, 9, 70, 36);
144             PdfWriter writer = PdfWriter.getInstance(doc, byteArrayOutputStream);
145             this.createPOQuotePdf(po, poqv, campusName, contractManagerCampusCode, logoImage, doc, writer, environment);
146         } catch (DocumentException de) {
147             LOG.error(de.getMessage(), de);
148             throw new PurError("Document Exception when trying to save a Purchase Order Quote PDF", de);
149         }
150     }
151 
152     /**
153      * Invokes the createPOQuotePDF method to create a purchase order quote pdf document and saves it into a file
154      * which name and location are specified in the pdfParameters.
155      *
156      * @param po                        The PurchaseOrderDocument to be used to generate the pdf.
157      * @param poqv                      The PurchaseOrderVendorQuote to be used to generate the pdf.
158      * @param pdfFileLocation           The location to save the pdf file.
159      * @param pdfFilename               The name for the pdf file.
160      * @param campusName                The campus name to be used to generate the pdf.
161      * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
162      * @param logoImage                 The logo image file name to be used to generate the pdf.
163      * @param environment               The current environment used (e.g. DEV if it is a development environment).
164      */
165     public void savePOQuotePDF(PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, PurchaseOrderParameters transmitParameters, String environment) {
166         if (LOG.isDebugEnabled()) {
167             LOG.debug("savePOQuotePDF() started for po number " + po.getPurapDocumentIdentifier());
168         }
169 
170         try {
171             PurchaseOrderTransmitParameters orderTransmitParameters = (PurchaseOrderTransmitParameters) transmitParameters;
172             CampusParameter deliveryCampus = orderTransmitParameters.getCampusParameter();
173             if (deliveryCampus == null) {
174                 throw new RuntimeException(" delivery campus is null");
175             }
176             String campusName = deliveryCampus.getCampus().getName();
177             if (campusName == null) {
178 
179                 throw new RuntimeException("Campus Information is missing - campusName: " + campusName);
180             }
181             Document doc = this.getDocument(9, 9, 70, 36);
182             PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(orderTransmitParameters.getPdfFileLocation() + orderTransmitParameters.getPdfFileName()));
183             this.createPOQuotePdf(po, poqv, campusName, orderTransmitParameters.getContractManagerCampusCode(), orderTransmitParameters.getLogoImage(), doc, writer, environment);
184         } catch (DocumentException de) {
185             LOG.error(de.getMessage(), de);
186             throw new PurError("Document Exception when trying to save a Purchase Order Quote PDF", de);
187         } catch (FileNotFoundException f) {
188             LOG.error(f.getMessage(), f);
189             throw new PurError("FileNotFound Exception when trying to save a Purchase Order Quote PDF", f);
190         }
191     }
192 
193     /**
194      * Create a PDF using the given input parameters.
195      *
196      * @param po                        The PurchaseOrderDocument to be used to create the pdf.
197      * @param poqv                      The PurchaseOrderVendorQuote to be used to generate the pdf.
198      * @param campusName                The campus name to be used to generate the pdf.
199      * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
200      * @param logoImage                 The logo image file name to be used to generate the pdf.
201      * @param document                  The pdf document whose margins have already been set.
202      * @param writer                    The PdfWriter to write the pdf document into.
203      * @param environment               The current environment used (e.g. DEV if it is a development environment).
204      * @throws DocumentException
205      */
206     private void createPOQuotePdf(PurchaseOrderDocument po, PurchaseOrderVendorQuote poqv, String campusName, String contractManagerCampusCode, String logoImage, Document document, PdfWriter writer, String environment) throws DocumentException {
207         if (LOG.isDebugEnabled()) {
208             LOG.debug("createQuotePdf() started for po number " + po.getPurapDocumentIdentifier());
209         }
210 
211         // These have to be set because they are used by the onOpenDocument() and onStartPage() methods.
212         this.campusName = campusName;
213         this.po = po;
214         this.logoImage = logoImage;
215         this.environment = environment;
216 
217         NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US);
218         // Date format pattern: MM-dd-yyyy
219         SimpleDateFormat sdf = PurApDateFormatUtils.getSimpleDateFormat(PurapConstants.NamedDateFormats.KUALI_SIMPLE_DATE_FORMAT_2);
220 
221         CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode);
222         String purchasingAddressFull = getPurchasingAddressFull(campusParameter);
223 
224         // Turn on the page events that handle the header and page numbers.
225         PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf().getPageEvents();
226         writer.setPageEvent(this); // Passing in "this" lets it know about the po, campusName, etc.
227 
228         document.open();
229 
230         PdfPCell cell;
231         Paragraph p = new Paragraph();
232 
233         // ***** Info table (address, vendor, other info) *****
234         LOG.debug("createQuotePdf() info table started.");
235         float[] infoWidths = {0.45f, 0.55f};
236         PdfPTable infoTable = new PdfPTable(infoWidths);
237         infoTable.setWidthPercentage(100);
238         infoTable.setHorizontalAlignment(Element.ALIGN_CENTER);
239         infoTable.setSplitLate(false);
240 
241         p = new Paragraph();
242         ContractManager contractManager = po.getContractManager();
243         p.add(new Chunk("\n Return this form to:\n", ver_8_bold));
244         p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal));
245         p.add(new Chunk("\n", cour_10_normal));
246         p.add(new Chunk(" Fax #: ", ver_6_normal));
247         p.add(new Chunk(contractManager.getContractManagerFaxNumber() + "\n", cour_10_normal));
248         p.add(new Chunk(" Contract Manager: ", ver_6_normal));
249         p.add(new Chunk(contractManager.getContractManagerName() + " " + contractManager.getContractManagerPhoneNumber() + "\n", cour_10_normal));
250         p.add(new Chunk("\n", cour_10_normal));
251         p.add(new Chunk(" To:\n", ver_6_normal));
252         StringBuffer vendorInfo = new StringBuffer();
253         if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) {
254             vendorInfo.append("     ATTN: " + poqv.getVendorAttentionName().trim() + "\n");
255         }
256         vendorInfo.append("     " + poqv.getVendorName() + "\n");
257         if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) {
258             vendorInfo.append("     " + poqv.getVendorLine1Address() + "\n");
259         }
260         if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) {
261             vendorInfo.append("     " + poqv.getVendorLine2Address() + "\n");
262         }
263         if (StringUtils.isNotBlank(poqv.getVendorCityName())) {
264             vendorInfo.append("     " + poqv.getVendorCityName());
265         }
266         if ((StringUtils.isNotBlank(poqv.getVendorStateCode())) && (!poqv.getVendorStateCode().equals("--"))) {
267             vendorInfo.append(", " + poqv.getVendorStateCode());
268         }
269         if (StringUtils.isNotBlank(poqv.getVendorAddressInternationalProvinceName())) {
270             vendorInfo.append(", " + poqv.getVendorAddressInternationalProvinceName());
271         }
272         if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) {
273             vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n");
274         } else {
275             vendorInfo.append("\n");
276         }
277 
278         if (!OLEConstants.COUNTRY_CODE_UNITED_STATES.equalsIgnoreCase(poqv.getVendorCountryCode()) && poqv.getVendorCountryCode() != null) {
279             vendorInfo.append("     " + poqv.getVendorCountry().getName() + "\n\n");
280         } else {
281             vendorInfo.append("     \n\n");
282         }
283 
284         p.add(new Chunk(vendorInfo.toString(), cour_10_normal));
285         cell = new PdfPCell(p);
286         cell.setHorizontalAlignment(Element.ALIGN_LEFT);
287         infoTable.addCell(cell);
288 
289         p = new Paragraph();
290         p.add(new Chunk("\n     R.Q. Number: ", ver_8_bold));
291         p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n", cour_10_normal));
292         java.sql.Date requestDate = getDateTimeService().getCurrentSqlDate();
293         if (poqv.getPurchaseOrderQuoteTransmitTimestamp() != null) {
294             try {
295                 requestDate = getDateTimeService().convertToSqlDate(poqv.getPurchaseOrderQuoteTransmitTimestamp());
296             } catch (ParseException e) {
297                 throw new RuntimeException("ParseException thrown when trying to convert from Timestamp to SqlDate.", e);
298             }
299         }
300         p.add(new Chunk("     R.Q. Date: ", ver_8_bold));
301         p.add(new Chunk(sdf.format(requestDate) + "\n", cour_10_normal));
302         p.add(new Chunk("     RESPONSE MUST BE RECEIVED BY: ", ver_8_bold));
303         if (po.getPurchaseOrderQuoteDueDate() != null) {
304             p.add(new Chunk(sdf.format(po.getPurchaseOrderQuoteDueDate()) + "\n\n", cour_10_normal));
305         } else {
306             p.add(new Chunk("N/A\n\n", cour_10_normal));
307         }
308 
309         // retrieve the quote stipulations
310         StringBuffer quoteStipulations = getPoQuoteLanguage();
311 
312         p.add(new Chunk(quoteStipulations.toString(), ver_6_normal));
313         p.add(new Chunk("\n ALL QUOTES MUST BE TOTALED", ver_12_normal));
314         cell = new PdfPCell(p);
315         infoTable.addCell(cell);
316 
317         document.add(infoTable);
318 
319         // ***** Notes and Stipulations table *****
320         // The notes and stipulations table is type Table instead of PdfPTable
321         // because Table has the method setCellsFitPage and I can't find an equivalent
322         // in PdfPTable. Long notes or stipulations would break to the next page, leaving
323         // a large white space on the previous page.
324         PdfPTable notesStipulationsTable = new PdfPTable(1);
325         notesStipulationsTable.setWidthPercentage(100);
326         notesStipulationsTable.setSplitLate(false);
327 
328         p = new Paragraph();
329         p.add(new Chunk("  Vendor Stipulations and Information\n\n", ver_6_normal));
330         if ((po.getPurchaseOrderBeginDate() != null) && (po.getPurchaseOrderEndDate() != null)) {
331             p.add(new Chunk("     Order in effect from " + sdf.format(po.getPurchaseOrderBeginDate()) + " to " + sdf.format(po.getPurchaseOrderEndDate()) + ".\n", cour_10_normal));
332         }
333         Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po.getPurchaseOrderVendorStipulations();
334         if (vendorStipulationsList.size() > 0) {
335             StringBuffer vendorStipulations = new StringBuffer();
336             for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) {
337                 vendorStipulations.append("     " + povs.getVendorStipulationDescription() + "\n");
338             }
339             p.add(new Chunk("     " + vendorStipulations.toString(), cour_10_normal));
340         }
341 
342         PdfPCell tableCell = new PdfPCell(p);
343         tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
344         tableCell.setVerticalAlignment(Element.ALIGN_TOP);
345         notesStipulationsTable.addCell(tableCell);
346         document.add(notesStipulationsTable);
347 
348         // ***** Items table *****
349         LOG.debug("createQuotePdf() items table started.");
350         float[] itemsWidths = {0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f};
351         PdfPTable itemsTable = new PdfPTable(6);
352         // itemsTable.setCellsFitPage(false); With this set to true a large cell will
353         // skip to the next page. The default Table behaviour seems to be what we want:
354         // start the large cell on the same page and continue it to the next.
355         itemsTable.setWidthPercentage(100);
356         itemsTable.setWidths(itemsWidths);
357         itemsTable.setSplitLate(false);
358 
359         tableCell = createCell("Item\nNo.", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
360         itemsTable.addCell(tableCell);
361         tableCell = createCell("Quantity", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
362         itemsTable.addCell(tableCell);
363         tableCell = createCell("UOM", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
364         itemsTable.addCell(tableCell);
365         tableCell = createCell("Description", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
366         itemsTable.addCell(tableCell);
367         tableCell = createCell("Unit Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
368         itemsTable.addCell(tableCell);
369         tableCell = createCell("Extended Cost\n(Required)", false, false, false, false, Element.ALIGN_CENTER, ver_6_normal);
370         itemsTable.addCell(tableCell);
371 
372         if (StringUtils.isNotBlank(po.getPurchaseOrderQuoteVendorNoteText())) {
373             // Vendor notes line.
374             itemsTable.addCell(" ");
375             itemsTable.addCell(" ");
376             itemsTable.addCell(" ");
377             tableCell = createCell(po.getPurchaseOrderQuoteVendorNoteText(), false, false, false, false, Element.ALIGN_LEFT, cour_10_normal);
378             itemsTable.addCell(tableCell);
379             itemsTable.addCell(" ");
380             itemsTable.addCell(" ");
381         }
382 
383         for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po.getItems()) {
384             if ((poi.getItemType() != null) && (StringUtils.isNotBlank(poi.getItemDescription())) && (poi.getItemType().isLineItemIndicator() || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) {
385                 // "ITEM"s display the line number; other types don't.
386                 String description = "";
387                 description = (StringUtils.isNotBlank(poi.getItemCatalogNumber())) ? poi.getItemCatalogNumber().trim() + " - " : "";
388                 description = description + ((StringUtils.isNotBlank(poi.getItemDescription())) ? poi.getItemDescription().trim() : "");
389 
390                 // If this is a full order discount item or trade in item, we add the
391                 // itemType description and a dash to the purchase order item description.
392                 if (StringUtils.isNotBlank(poi.getItemDescription())) {
393                     if (poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
394                         description = poi.getItemType().getItemTypeDescription() + " - " + description;
395                     }
396                 }
397 
398                 // We can do the normal table now because description is not too long.
399                 String itemLineNumber = new String();
400                 if (poi.getItemType().isLineItemIndicator()) {
401                     itemLineNumber = poi.getItemLineNumber().toString();
402                 } else {
403                     itemLineNumber = "";
404                 }
405                 tableCell = createCell(itemLineNumber, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal);
406                 itemsTable.addCell(tableCell);
407                 String quantity = (poi.getItemQuantity() != null) ? poi.getItemQuantity().toString() : " ";
408                 tableCell = createCell(quantity, false, false, false, false, Element.ALIGN_CENTER, cour_10_normal);
409                 itemsTable.addCell(tableCell);
410                 tableCell = createCell(poi.getItemUnitOfMeasureCode(), false, false, false, false, Element.ALIGN_CENTER, cour_10_normal);
411                 itemsTable.addCell(tableCell);
412 
413                 tableCell = createCell(description, false, false, false, false, Element.ALIGN_LEFT, cour_10_normal);
414                 itemsTable.addCell(tableCell);
415                 itemsTable.addCell(" ");
416                 itemsTable.addCell(" ");
417 
418             }
419         }
420 
421         // Blank line before totals
422         createBlankRowInItemsTable(itemsTable);
423 
424         // Totals line.
425         itemsTable.addCell(" ");
426         itemsTable.addCell(" ");
427         itemsTable.addCell(" ");
428         tableCell = createCell("Total: ", false, false, false, false, Element.ALIGN_RIGHT, ver_10_normal);
429         itemsTable.addCell(tableCell);
430         itemsTable.addCell(" ");
431         itemsTable.addCell(" ");
432         // Blank line after totals
433         createBlankRowInItemsTable(itemsTable);
434 
435         document.add(itemsTable);
436 
437         LOG.debug("createQuotePdf() vendorFillsIn table started.");
438         float[] vendorFillsInWidths = {0.50f, 0.50f};
439         PdfPTable vendorFillsInTable = new PdfPTable(vendorFillsInWidths);
440         vendorFillsInTable.setWidthPercentage(100);
441         vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER);
442         vendorFillsInTable.setSplitLate(false);
443         vendorFillsInTable.getDefaultCell().setBorderWidth(0);
444         vendorFillsInTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
445         vendorFillsInTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);
446 
447         // New row
448         String important = new String("\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n");
449         cell = createCell(important, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
450         cell.setColspan(2);
451         vendorFillsInTable.addCell(cell);
452         // New row
453         String cashDiscount = new String("Terms of Payment:  Cash discount_________%_________Days-Net________Days\n");
454         cell = createCell(cashDiscount, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
455         cell.setColspan(2);
456         vendorFillsInTable.addCell(cell);
457         // New row
458         String fob = new String(" FOB: __ Destination (Title)\n");
459         cell = createCell(fob, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
460         vendorFillsInTable.addCell(cell);
461         String freightVendor = new String(" __ Freight Vendor Paid (Allowed)\n");
462         cell = createCell(freightVendor, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
463         vendorFillsInTable.addCell(cell);
464         // New row
465         String shipping = new String("          __ Shipping Point (Title)\n");
466         cell = createCell(shipping, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
467         vendorFillsInTable.addCell(cell);
468         String freightPrepaid = new String(" __ Freight Prepaid & Added Amount $_________\n");
469         cell = createCell(freightPrepaid, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
470         vendorFillsInTable.addCell(cell);
471         // New row
472         String commonCarrier = new String("      If material will ship common carrier, please provide the following:\n");
473         cell = createCell(commonCarrier, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold);
474         cell.setColspan(2);
475         vendorFillsInTable.addCell(cell);
476         // New row
477         String origin = new String("      Point of origin and zip code: ______________________ Weight: _________ Class: _________\n");
478         cell = createCell(origin, true, false, false, false, Element.ALIGN_LEFT, ver_8_bold);
479         cell.setColspan(2);
480         vendorFillsInTable.addCell(cell);
481         // New row
482         p = new Paragraph();
483         p.add(new Chunk(" Unless otherwise stated, all material to be shipped to ", ver_8_normal));
484         String purchasingAddressPartial;
485         if (po.getAddressToVendorIndicator())  // use receiving address
486             purchasingAddressPartial = po.getReceivingCityName() + ", " + po.getReceivingStateCode() + " " + po.getReceivingPostalCode();
487         else  // use final delivery address
488             purchasingAddressPartial = po.getDeliveryCityName() + ", " + po.getDeliveryStateCode() + " " + po.getDeliveryPostalCode();
489         p.add(new Chunk(purchasingAddressPartial + "\n", cour_10_normal));
490         cell = new PdfPCell(p);
491         cell.setColspan(2);
492         cell.setHorizontalAlignment(Element.ALIGN_LEFT);
493         cell.setBorderWidth(0);
494         vendorFillsInTable.addCell(cell);
495         // New row
496         String offerEffective = new String(" Offer effective until (Date):_____________\n");
497         cell = createCell(offerEffective, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
498         vendorFillsInTable.addCell(cell);
499         String deliverBy = new String(" Delivery can be made by (Date):_____________\n");
500         cell = createCell(deliverBy, true, false, false, false, Element.ALIGN_LEFT, ver_8_normal);
501         vendorFillsInTable.addCell(cell);
502         // New row
503         String sign = new String(" SIGN HERE:____________________________\n");
504         cell = createCell(sign, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
505         vendorFillsInTable.addCell(cell);
506         String date = new String(" DATE:____________________________\n");
507         cell = createCell(date, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
508         vendorFillsInTable.addCell(cell);
509         // New row
510         String name = new String(" PRINT NAME:____________________________\n");
511         cell = createCell(name, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
512         vendorFillsInTable.addCell(cell);
513         String phone = new String(" PHONE:____________________________\n");
514         cell = createCell(phone, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
515         vendorFillsInTable.addCell(cell);
516         // New row
517         String company = new String(" COMPANY:____________________________\n");
518         cell = createCell(company, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
519         vendorFillsInTable.addCell(cell);
520         String fax = new String(" FAX:____________________________\n");
521         cell = createCell(fax, true, false, false, false, Element.ALIGN_RIGHT, ver_10_bold);
522         vendorFillsInTable.addCell(cell);
523 
524         document.add(vendorFillsInTable);
525         document.close();
526         LOG.debug("createQuotePdf()pdf document closed.");
527     } // End of createQuotePdf()
528 
529 
530     /**
531      * Creates and returns a string buffer of the quote language descriptions from the database, ordered by the quote language
532      * identifier and appended with carriage returns after each line.
533      *
534      * @return The StringBuffer of the purchase order quote language.
535      */
536     private StringBuffer getPoQuoteLanguage() {
537 
538         StringBuffer quoteLanguage = new StringBuffer();
539         Map<String, Object> criteria = new HashMap<String, Object>();
540 
541         // retrieve list of purchase order quote language objects sorted by PO Quote Language Identifier
542         Collection<PurchaseOrderQuoteLanguage> poqlList = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(PurchaseOrderQuoteLanguage.class, criteria, PurapPropertyConstants.PURCHASE_ORDER_QUOTE_LANGUAGE_ID, true);
543 
544         // append in string buffer
545         for (PurchaseOrderQuoteLanguage poql : poqlList) {
546             quoteLanguage.append(poql.getPurchaseOrderQuoteLanguageDescription());
547             quoteLanguage.append("\n");
548         }
549 
550         return quoteLanguage;
551 
552     }
553 
554     /**
555      * A helper method to create a blank row of 6 cells in the items table.
556      *
557      * @param itemsTable
558      */
559     private void createBlankRowInItemsTable(PdfPTable itemsTable) {
560         // We're adding 6 cells because each row in the items table
561         // contains 6 columns.
562         for (int i = 0; i < 6; i++) {
563             itemsTable.addCell(" ");
564         }
565     }
566 
567     /**
568      * A helper method to create a PdfPCell. We can specify the content, font, horizontal alignment, border (borderless, no
569      * bottom border, no right border, no top border, etc.
570      *
571      * @param content             The text content to be displayed in the cell.
572      * @param borderless          boolean true if the cell should be borderless.
573      * @param noBottom            boolean true if the cell should have borderWidthBottom = 0.
574      * @param noRight             boolean true if the cell should have borderWidthRight = 0.
575      * @param noTop               boolean true if the cell should have borderWidthTop = 0.
576      * @param horizontalAlignment The desired horizontal alignment for the cell.
577      * @param font                The font type to be used in the cell.
578      * @return An instance of PdfPCell which content and attributes were set by the input parameters.
579      */
580     private PdfPCell createCell(String content, boolean borderless, boolean noBottom, boolean noRight, boolean noTop, int horizontalAlignment, Font font) {
581         PdfPCell tableCell = new PdfPCell(new Paragraph(content, font));
582         if (borderless) {
583             tableCell.setBorder(0);
584         }
585         if (noBottom) {
586             tableCell.setBorderWidthBottom(0);
587         }
588         if (noTop) {
589             tableCell.setBorderWidthTop(0);
590         }
591         if (noRight) {
592             tableCell.setBorderWidthRight(0);
593         }
594         tableCell.setHorizontalAlignment(horizontalAlignment);
595         return tableCell;
596     }
597 
598     /**
599      * Obtains the CampusParameter based on the delivery campus code of the purchase order.
600      *
601      * @param contractManagerCampusCode This is not used anymore.
602      * @return The CampusParameter whose delivery campus code matches with the
603      *         purchase order's delivery campus code.
604      */
605     private CampusParameter getCampusParameter(String contractManagerCampusCode) {
606         Map<String, Object> criteria = new HashMap<String, Object>();
607         criteria.put(OLEPropertyConstants.CAMPUS_CODE, po.getDeliveryCampusCode());
608         CampusParameter campusParameter = (CampusParameter) ((List) SpringContext.getBean(BusinessObjectService.class).findMatching(CampusParameter.class, criteria)).get(0);
609 
610         return campusParameter;
611     }
612 
613     /**
614      * Creates and returns the full purchasing address given the campus parameter.
615      *
616      * @param campusParameter The CampusParameter object to be used to create the full purchasing address.
617      * @return The String containing the full purchasing address.
618      */
619     private String getPurchasingAddressFull(CampusParameter campusParameter) {
620         String indent = "     ";
621         StringBuffer addressBuffer = new StringBuffer();
622         addressBuffer.append(indent + campusParameter.getPurchasingInstitutionName() + "\n");
623         addressBuffer.append(indent + campusParameter.getPurchasingDepartmentName() + "\n");
624         addressBuffer.append(indent + campusParameter.getPurchasingDepartmentLine1Address() + "\n");
625         if (ObjectUtils.isNotNull(campusParameter.getPurchasingDepartmentLine2Address()))
626             addressBuffer.append(indent + campusParameter.getPurchasingDepartmentLine2Address() + "\n");
627         addressBuffer.append(indent + campusParameter.getPurchasingDepartmentCityName() + ", ");
628         addressBuffer.append(campusParameter.getPurchasingDepartmentStateCode() + " ");
629         addressBuffer.append(campusParameter.getPurchasingDepartmentZipCode() + " ");
630         addressBuffer.append((ObjectUtils.isNotNull(campusParameter.getPurchasingDepartmentCountryCode()) ? campusParameter.getPurchasingDepartmentCountryCode() : ""));
631 
632         return addressBuffer.toString();
633     }
634 
635     /**
636      * Creates and returns the partial purchasing address given the campus parameter.
637      *
638      * @param campusParameter The CampusParameter object to be used to create the partial purchasing address.
639      * @return The String containing the partial purchasing address.
640      */
641     private String getPurchasingAddressPartial(CampusParameter campusParameter) {
642         StringBuffer purchasingAddressPartial = new StringBuffer();
643 
644         purchasingAddressPartial.append(campusParameter.getPurchasingInstitutionName() + ", ");
645         purchasingAddressPartial.append(campusParameter.getPurchasingDepartmentCityName() + ", ");
646         purchasingAddressPartial.append(campusParameter.getPurchasingDepartmentStateCode() + " ");
647         purchasingAddressPartial.append(campusParameter.getPurchasingDepartmentZipCode());
648 
649         return purchasingAddressPartial.toString();
650     }
651 }