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