001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.module.purap.pdf;
017:
018: import java.io.ByteArrayOutputStream;
019: import java.io.FileNotFoundException;
020: import java.io.FileOutputStream;
021: import java.sql.Date;
022: import java.text.NumberFormat;
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.HashMap;
026: import java.util.List;
027: import java.util.Locale;
028: import java.util.Map;
029:
030: import org.apache.commons.lang.StringUtils;
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033: import org.kuali.core.service.BusinessObjectService;
034: import org.kuali.core.util.ObjectUtils;
035: import org.kuali.kfs.KFSConstants;
036: import org.kuali.kfs.KFSPropertyConstants;
037: import org.kuali.kfs.context.SpringContext;
038: import org.kuali.module.purap.PurapConstants;
039: import org.kuali.module.purap.PurapPropertyConstants;
040: import org.kuali.module.purap.bo.CampusParameter;
041: import org.kuali.module.purap.bo.PurchaseOrderItem;
042: import org.kuali.module.purap.bo.PurchaseOrderQuoteLanguage;
043: import org.kuali.module.purap.bo.PurchaseOrderVendorQuote;
044: import org.kuali.module.purap.bo.PurchaseOrderVendorStipulation;
045: import org.kuali.module.purap.document.PurchaseOrderDocument;
046: import org.kuali.module.purap.exceptions.PurError;
047: import org.kuali.module.vendor.bo.ContractManager;
048:
049: import com.lowagie.text.Chunk;
050: import com.lowagie.text.Document;
051: import com.lowagie.text.DocumentException;
052: import com.lowagie.text.Element;
053: import com.lowagie.text.ExceptionConverter;
054: import com.lowagie.text.Font;
055: import com.lowagie.text.Image;
056: import com.lowagie.text.Paragraph;
057: import com.lowagie.text.Phrase;
058: import com.lowagie.text.pdf.BaseFont;
059: import com.lowagie.text.pdf.PdfPCell;
060: import com.lowagie.text.pdf.PdfPTable;
061: import com.lowagie.text.pdf.PdfWriter;
062:
063: /**
064: *
065: * THIS CODE IS NOT USED IN RELEASE 2 BUT THE CODE WAS LEFT IN TO
066: * FACILITATE TURNING IT BACK ON EARLY IN THE DEVELOPMENT CYCLE OF RELEASE 3.
067: *
068: */
069: public class PurchaseOrderQuotePdf extends PurapPdf {
070: private static Log LOG = LogFactory
071: .getLog(PurchaseOrderQuotePdf.class);
072:
073: public PurchaseOrderQuotePdf() {
074: super ();
075: }
076:
077: /**
078: * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable with relevant contents
079: * and set its logo image if there is a logoImage to be used.
080: *
081: * @param writer The PdfWriter for this document.
082: * @param document The document.
083: * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
084: */
085: public void onOpenDocument(PdfWriter writer, Document document) {
086: LOG.debug("onOpenDocument() started.");
087: try {
088: float[] headerWidths = { 0.20f, 0.60f, 0.20f };
089: headerTable = new PdfPTable(headerWidths);
090: headerTable.setWidthPercentage(100);
091: headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);
092:
093: headerTable.getDefaultCell().setBorderWidth(0);
094: headerTable.getDefaultCell().setHorizontalAlignment(
095: Element.ALIGN_CENTER);
096: headerTable.getDefaultCell().setVerticalAlignment(
097: Element.ALIGN_CENTER);
098:
099: if (StringUtils.isNotBlank(logoImage)) {
100: logo = Image.getInstance(logoImage);
101: logo.scalePercent(3, 3);
102: headerTable.addCell(new Phrase(new Chunk(logo, 0, 0)));
103: } else {
104: // if we don't use images
105: headerTable.addCell(new Phrase(new Chunk("")));
106: }
107: PdfPCell cell;
108: cell = new PdfPCell(new Paragraph(
109: "REQUEST FOR QUOTATION\nTHIS IS NOT AN ORDER",
110: ver_17_normal));
111: cell.setBorderWidth(0);
112: cell.setHorizontalAlignment(Element.ALIGN_CENTER);
113: headerTable.addCell(cell);
114:
115: Paragraph p = new Paragraph();
116: p.add(new Chunk("\n R.Q. Number: ", ver_8_bold));
117: p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n",
118: cour_10_normal));
119: cell = new PdfPCell(p);
120: cell.setBorderWidth(0);
121: headerTable.addCell(cell);
122:
123: // initialization of the template
124: tpl = writer.getDirectContent().createTemplate(100, 100);
125: // initialization of the font
126: helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
127: false);
128: } catch (Exception e) {
129: throw new ExceptionConverter(e);
130: }
131: }
132:
133: /**
134: * Gets a PageEvents object.
135: *
136: * @return a new PageEvents object
137: */
138: public PurchaseOrderQuotePdf getPageEvents() {
139: LOG.debug("getPageEvents() started.");
140: return new PurchaseOrderQuotePdf();
141: }
142:
143: /**
144: * Generates the purchase order quote pdf document based on the data in the given input parameters,
145: * creates a pdf writer using the given byteArrayOutputStream then write the pdf document into the writer.
146: *
147: * @param po The PurchaseOrderDocument to be used to generate the pdf.
148: * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
149: * @param campusName The campus name to be used to generate the pdf.
150: * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
151: * @param logoImage The logo image file name to be used to generate the pdf.
152: * @param byteArrayOutputStream The ByteArrayOutputStream to print the pdf to.
153: * @param environment The current environment used (e.g. DEV if it is a development environment).
154: */
155: public void generatePOQuotePDF(PurchaseOrderDocument po,
156: PurchaseOrderVendorQuote poqv, String campusName,
157: String contractManagerCampusCode, String logoImage,
158: ByteArrayOutputStream byteArrayOutputStream,
159: String environment) {
160: LOG.debug("generatePOQuotePDF() started for po number "
161: + po.getPurapDocumentIdentifier());
162:
163: Collection errors = new ArrayList();
164:
165: try {
166: Document doc = getDocument(9, 9, 70, 36);
167: PdfWriter writer = PdfWriter.getInstance(doc,
168: byteArrayOutputStream);
169: this .createPOQuotePdf(po, poqv, campusName,
170: contractManagerCampusCode, logoImage, doc, writer,
171: environment);
172: } catch (DocumentException de) {
173: LOG.error(de.getMessage(), de);
174: throw new PurError(
175: "Document Exception when trying to save a Purchase Order Quote PDF",
176: de);
177: }
178: }
179:
180: /**
181: * Invokes the createPOQuotePDF method to create a purchase order quote pdf document and saves it into a file
182: * which name and location are specified in the pdfParameters.
183: *
184: * @param po The PurchaseOrderDocument to be used to generate the pdf.
185: * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
186: * @param pdfFileLocation The location to save the pdf file.
187: * @param pdfFilename The name for the pdf file.
188: * @param campusName The campus name to be used to generate the pdf.
189: * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
190: * @param logoImage The logo image file name to be used to generate the pdf.
191: * @param environment The current environment used (e.g. DEV if it is a development environment).
192: */
193: public void savePOQuotePDF(PurchaseOrderDocument po,
194: PurchaseOrderVendorQuote poqv, String pdfFileLocation,
195: String pdfFilename, String campusName,
196: String contractManagerCampusCode, String logoImage,
197: String environment) {
198: LOG.debug("savePOQuotePDF() started for po number "
199: + po.getPurapDocumentIdentifier());
200:
201: try {
202: Document doc = this .getDocument(9, 9, 70, 36);
203: PdfWriter writer = PdfWriter
204: .getInstance(doc, new FileOutputStream(
205: pdfFileLocation + pdfFilename));
206: this .createPOQuotePdf(po, poqv, campusName,
207: contractManagerCampusCode, logoImage, doc, writer,
208: environment);
209: } catch (DocumentException de) {
210: LOG.error(de.getMessage(), de);
211: throw new PurError(
212: "Document Exception when trying to save a Purchase Order Quote PDF",
213: de);
214: } catch (FileNotFoundException f) {
215: LOG.error(f.getMessage(), f);
216: throw new PurError(
217: "FileNotFound Exception when trying to save a Purchase Order Quote PDF",
218: f);
219: }
220: }
221:
222: /**
223: * Create a PDF using the given input parameters.
224: *
225: * @param po The PurchaseOrderDocument to be used to create the pdf.
226: * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
227: * @param campusName The campus name to be used to generate the pdf.
228: * @param contractManagerCampusCode The contract manager campus code to be used to generate the pdf.
229: * @param logoImage The logo image file name to be used to generate the pdf.
230: * @param document The pdf document whose margins have already been set.
231: * @param writer The PdfWriter to write the pdf document into.
232: * @param environment The current environment used (e.g. DEV if it is a development environment).
233: * @throws DocumentException
234: */
235: private void createPOQuotePdf(PurchaseOrderDocument po,
236: PurchaseOrderVendorQuote poqv, String campusName,
237: String contractManagerCampusCode, String logoImage,
238: Document document, PdfWriter writer, String environment)
239: throws DocumentException {
240: LOG.debug("createQuotePdf() started for po number "
241: + po.getPurapDocumentIdentifier());
242: // These have to be set because they are used by the onOpenDocument() and onStartPage() methods.
243: this .campusName = campusName;
244: this .po = po;
245: this .logoImage = logoImage;
246: this .environment = environment;
247:
248: NumberFormat numberFormat = NumberFormat
249: .getCurrencyInstance(Locale.US);
250:
251: CampusParameter campusParameter = getCampusParameter(contractManagerCampusCode);
252: String purchasingAddressFull = getPurchasingAddressFull(campusParameter);
253: // Used at the bottom - "All material to be shipped to"
254: String purchasingAddressPartial = getPurchasingAddressPartial(campusParameter);
255:
256: // Turn on the page events that handle the header and page numbers.
257: PurchaseOrderQuotePdf events = new PurchaseOrderQuotePdf()
258: .getPageEvents();
259: writer.setPageEvent(this ); // Passing in "this" lets it know about the po, campusName, etc.
260:
261: document.open();
262:
263: PdfPCell cell;
264: Paragraph p = new Paragraph();
265:
266: // ***** Info table (address, vendor, other info) *****
267: LOG.debug("createQuotePdf() info table started.");
268: float[] infoWidths = { 0.45f, 0.55f };
269: PdfPTable infoTable = new PdfPTable(infoWidths);
270: infoTable.setWidthPercentage(100);
271: infoTable.setHorizontalAlignment(Element.ALIGN_CENTER);
272: infoTable.setSplitLate(false);
273:
274: p = new Paragraph();
275: ContractManager contractManager = po.getContractManager();
276: p.add(new Chunk("\n Return this form to:\n", ver_8_bold));
277: p.add(new Chunk(purchasingAddressFull + "\n", cour_10_normal));
278: p.add(new Chunk("\n", cour_10_normal));
279: p.add(new Chunk(" Fax #: ", ver_6_normal));
280: p.add(new Chunk(contractManager.getContractManagerFaxNumber()
281: + "\n", cour_10_normal));
282: p.add(new Chunk(" Contract Manager: ", ver_6_normal));
283: p.add(new Chunk(contractManager.getContractManagerName() + " "
284: + contractManager.getContractManagerPhoneNumber()
285: + "\n", cour_10_normal));
286: p.add(new Chunk("\n", cour_10_normal));
287: p.add(new Chunk(" To:\n", ver_6_normal));
288: StringBuffer vendorInfo = new StringBuffer();
289: if (StringUtils.isNotBlank(poqv.getVendorAttentionName())) {
290: vendorInfo.append(" Attention: "
291: + poqv.getVendorAttentionName().trim() + "\n");
292: }
293: vendorInfo.append(" " + poqv.getVendorName() + "\n");
294: if (StringUtils.isNotBlank(poqv.getVendorLine1Address())) {
295: vendorInfo.append(" " + poqv.getVendorLine1Address()
296: + "\n");
297: }
298: if (StringUtils.isNotBlank(poqv.getVendorLine2Address())) {
299: vendorInfo.append(" " + poqv.getVendorLine2Address()
300: + "\n");
301: }
302: if (StringUtils.isNotBlank(poqv.getVendorCityName())) {
303: vendorInfo.append(" " + poqv.getVendorCityName());
304: }
305: if ((StringUtils.isNotBlank(poqv.getVendorStateCode()))
306: && (!poqv.getVendorStateCode().equals("--"))) {
307: vendorInfo.append(", " + poqv.getVendorStateCode());
308: }
309: if (StringUtils.isNotBlank(poqv.getVendorPostalCode())) {
310: vendorInfo.append(" " + poqv.getVendorPostalCode() + "\n");
311: } else {
312: vendorInfo.append("\n");
313: }
314:
315: if (!KFSConstants.COUNTRY_CODE_UNITED_STATES
316: .equalsIgnoreCase(poqv.getVendorCountryCode())
317: && poqv.getVendorCountryCode() != null) {
318: vendorInfo.append(" "
319: + poqv.getVendorCountry().getPostalCountryName()
320: + "\n\n");
321: } else {
322: vendorInfo.append(" \n\n");
323: }
324:
325: p.add(new Chunk(vendorInfo.toString(), cour_10_normal));
326: cell = new PdfPCell(p);
327: cell.setHorizontalAlignment(Element.ALIGN_LEFT);
328: infoTable.addCell(cell);
329:
330: p = new Paragraph();
331: p.add(new Chunk("\n R.Q. Number: ", ver_8_bold));
332: p.add(new Chunk(po.getPurapDocumentIdentifier() + "\n",
333: cour_10_normal));
334: String requestDate = getDateTimeService().getCurrentSqlDate()
335: .toString();
336: if (poqv.getPurchaseOrderQuoteTransmitDate() != null) {
337: requestDate = (new Date(poqv
338: .getPurchaseOrderQuoteTransmitDate().getTime()))
339: .toString();
340: }
341: p.add(new Chunk(" R.Q. Date: ", ver_8_bold));
342: p.add(new Chunk(requestDate + "\n", cour_10_normal));
343: p.add(new Chunk(" RESPONSE MUST BE RECEIVED BY: ",
344: ver_8_bold));
345: if (po.getPurchaseOrderQuoteDueDate() != null) {
346: String dueDate = (new Date(po
347: .getPurchaseOrderQuoteDueDate().getTime()))
348: .toString();
349: p.add(new Chunk(dueDate + "\n\n", cour_10_normal));
350: } else {
351: p.add(new Chunk("N/A\n\n", cour_10_normal));
352: }
353:
354: // retrieve the quote stipulations
355: StringBuffer quoteStipulations = getPoQuoteLanguage();
356:
357: p.add(new Chunk(quoteStipulations.toString(), ver_6_normal));
358: p
359: .add(new Chunk("\n ALL QUOTES MUST BE TOTALED",
360: ver_12_normal));
361: cell = new PdfPCell(p);
362: infoTable.addCell(cell);
363:
364: document.add(infoTable);
365:
366: // ***** Notes and Stipulations table *****
367: // The notes and stipulations table is type Table instead of PdfPTable
368: // because Table has the method setCellsFitPage and I can't find an equivalent
369: // in PdfPTable. Long notes or stipulations would break to the next page, leaving
370: // a large white space on the previous page.
371: PdfPTable notesStipulationsTable = new PdfPTable(1);
372: notesStipulationsTable.setWidthPercentage(100);
373: notesStipulationsTable.setSplitLate(false);
374:
375: p = new Paragraph();
376: p.add(new Chunk(" Vendor Stipulations and Information\n\n",
377: ver_6_normal));
378: if ((po.getPurchaseOrderBeginDate() != null)
379: && (po.getPurchaseOrderEndDate() != null)) {
380: p.add(new Chunk(" Order in effect from "
381: + po.getPurchaseOrderBeginDate() + " to "
382: + po.getPurchaseOrderEndDate() + ".\n",
383: cour_10_normal));
384: }
385: Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po
386: .getPurchaseOrderVendorStipulations();
387: if (vendorStipulationsList.size() > 0) {
388: StringBuffer vendorStipulations = new StringBuffer();
389: for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) {
390: vendorStipulations
391: .append(" "
392: + povs
393: .getVendorStipulationDescription()
394: + "\n");
395: }
396: p.add(new Chunk(" " + vendorStipulations.toString(),
397: cour_10_normal));
398: }
399:
400: PdfPCell tableCell = new PdfPCell(p);
401: tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
402: tableCell.setVerticalAlignment(Element.ALIGN_TOP);
403: notesStipulationsTable.addCell(tableCell);
404: document.add(notesStipulationsTable);
405:
406: // ***** Items table *****
407: LOG.debug("createQuotePdf() items table started.");
408: float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f };
409: PdfPTable itemsTable = new PdfPTable(6);
410: // itemsTable.setCellsFitPage(false); With this set to true a large cell will
411: // skip to the next page. The default Table behaviour seems to be what we want:
412: // start the large cell on the same page and continue it to the next.
413: itemsTable.setWidthPercentage(100);
414: itemsTable.setWidths(itemsWidths);
415: itemsTable.setSplitLate(false);
416:
417: tableCell = createCell("Item\nNo.", false, false, false, false,
418: Element.ALIGN_CENTER, ver_6_normal);
419: itemsTable.addCell(tableCell);
420: tableCell = createCell("Quantity", false, false, false, false,
421: Element.ALIGN_CENTER, ver_6_normal);
422: itemsTable.addCell(tableCell);
423: tableCell = createCell("UOM", false, false, false, false,
424: Element.ALIGN_CENTER, ver_6_normal);
425: itemsTable.addCell(tableCell);
426: tableCell = createCell("Description", false, false, false,
427: false, Element.ALIGN_CENTER, ver_6_normal);
428: itemsTable.addCell(tableCell);
429: tableCell = createCell("Unit Cost\n(Required)", false, false,
430: false, false, Element.ALIGN_CENTER, ver_6_normal);
431: itemsTable.addCell(tableCell);
432: tableCell = createCell("Extended Cost\n(Required)", false,
433: false, false, false, Element.ALIGN_CENTER, ver_6_normal);
434: itemsTable.addCell(tableCell);
435:
436: if (StringUtils.isNotBlank(po
437: .getPurchaseOrderQuoteVendorNoteText())) {
438: // Vendor notes line.
439: itemsTable.addCell(" ");
440: itemsTable.addCell(" ");
441: itemsTable.addCell(" ");
442: tableCell = createCell(po
443: .getPurchaseOrderQuoteVendorNoteText(), false,
444: false, false, false, Element.ALIGN_LEFT,
445: cour_10_normal);
446: itemsTable.addCell(tableCell);
447: itemsTable.addCell(" ");
448: itemsTable.addCell(" ");
449: }
450:
451: for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) po
452: .getItems()) {
453: if ((poi.getItemType() != null)
454: && (StringUtils
455: .isNotBlank(poi.getItemDescription()))
456: && (poi.getItemType()
457: .isItemTypeAboveTheLineIndicator()
458: || poi
459: .getItemTypeCode()
460: .equals(
461: PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)
462: || poi
463: .getItemTypeCode()
464: .equals(
465: PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE)
466: || poi
467: .getItemTypeCode()
468: .equals(
469: PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi
470: .getItemTypeCode()
471: .equals(
472: PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) {
473: // "ITEM"s display the line number; other types don't.
474: String description = "";
475: description = (StringUtils.isNotBlank(poi
476: .getItemCatalogNumber())) ? poi
477: .getItemCatalogNumber().trim()
478: + " - " : "";
479: description = description
480: + ((StringUtils.isNotBlank(poi
481: .getItemDescription())) ? poi
482: .getItemDescription().trim() : "");
483:
484: // If this is a full order discount item or trade in item, we add the
485: // itemType description and a dash to the purchase order item description.
486: if (StringUtils.isNotBlank(poi.getItemDescription())) {
487: if (poi
488: .getItemTypeCode()
489: .equals(
490: PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)
491: || poi
492: .getItemTypeCode()
493: .equals(
494: PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)) {
495: description = poi.getItemDescription() + " - "
496: + description;
497: }
498: }
499:
500: // We can do the normal table now because description is not too long.
501: String itemLineNumber = new String();
502: if (poi.getItemType().isItemTypeAboveTheLineIndicator()) {
503: itemLineNumber = poi.getItemLineNumber().toString();
504: } else {
505: itemLineNumber = "";
506: }
507: tableCell = createCell(itemLineNumber, false, false,
508: false, false, Element.ALIGN_CENTER,
509: cour_10_normal);
510: itemsTable.addCell(tableCell);
511: String quantity = (poi.getItemQuantity() != null) ? poi
512: .getItemQuantity().toString() : " ";
513: tableCell = createCell(quantity, false, false, false,
514: false, Element.ALIGN_CENTER, cour_10_normal);
515: itemsTable.addCell(tableCell);
516: tableCell = createCell(poi.getItemUnitOfMeasureCode(),
517: false, false, false, false,
518: Element.ALIGN_CENTER, cour_10_normal);
519: itemsTable.addCell(tableCell);
520:
521: tableCell = createCell(description, false, false,
522: false, false, Element.ALIGN_LEFT,
523: cour_10_normal);
524: itemsTable.addCell(tableCell);
525: itemsTable.addCell(" ");
526: itemsTable.addCell(" ");
527:
528: }
529: }
530:
531: // Blank line before totals
532: createBlankRowInItemsTable(itemsTable);
533:
534: // Totals line.
535: itemsTable.addCell(" ");
536: itemsTable.addCell(" ");
537: itemsTable.addCell(" ");
538: tableCell = createCell("Total: ", false, false, false, false,
539: Element.ALIGN_RIGHT, ver_10_normal);
540: itemsTable.addCell(tableCell);
541: itemsTable.addCell(" ");
542: itemsTable.addCell(" ");
543: // Blank line after totals
544: createBlankRowInItemsTable(itemsTable);
545:
546: document.add(itemsTable);
547:
548: LOG.debug("createQuotePdf() vendorFillsIn table started.");
549: float[] vendorFillsInWidths = { 0.50f, 0.50f };
550: PdfPTable vendorFillsInTable = new PdfPTable(
551: vendorFillsInWidths);
552: vendorFillsInTable.setWidthPercentage(100);
553: vendorFillsInTable.setHorizontalAlignment(Element.ALIGN_CENTER);
554: vendorFillsInTable.setSplitLate(false);
555: vendorFillsInTable.getDefaultCell().setBorderWidth(0);
556: vendorFillsInTable.getDefaultCell().setHorizontalAlignment(
557: Element.ALIGN_CENTER);
558: vendorFillsInTable.getDefaultCell().setVerticalAlignment(
559: Element.ALIGN_CENTER);
560:
561: // New row
562: String important = new String(
563: "\nIMPORTANT: The information and signature below MUST BE COMPLETED or your offer may be rejected.\n");
564: cell = createCell(important, true, false, false, false,
565: Element.ALIGN_LEFT, ver_8_normal);
566: cell.setColspan(2);
567: vendorFillsInTable.addCell(cell);
568: // New row
569: String cashDiscount = new String(
570: "Terms of Payment: Cash discount_________%_________Days-Net________Days\n");
571: cell = createCell(cashDiscount, true, false, false, false,
572: Element.ALIGN_LEFT, ver_8_normal);
573: cell.setColspan(2);
574: vendorFillsInTable.addCell(cell);
575: // New row
576: String fob = new String(" FOB: __ Destination (Title)\n");
577: cell = createCell(fob, true, false, false, false,
578: Element.ALIGN_LEFT, ver_8_normal);
579: vendorFillsInTable.addCell(cell);
580: String freightVendor = new String(
581: " __ Freight Vendor Paid (Allowed)\n");
582: cell = createCell(freightVendor, true, false, false, false,
583: Element.ALIGN_LEFT, ver_8_normal);
584: vendorFillsInTable.addCell(cell);
585: // New row
586: String shipping = new String(
587: " __ Shipping Point (Title)\n");
588: cell = createCell(shipping, true, false, false, false,
589: Element.ALIGN_LEFT, ver_8_normal);
590: vendorFillsInTable.addCell(cell);
591: String freightPrepaid = new String(
592: " __ Freight Prepaid & Added Amount $_________\n");
593: cell = createCell(freightPrepaid, true, false, false, false,
594: Element.ALIGN_LEFT, ver_8_normal);
595: vendorFillsInTable.addCell(cell);
596: // New row
597: String commonCarrier = new String(
598: " If material will ship common carrier, please provide the following:\n");
599: cell = createCell(commonCarrier, true, false, false, false,
600: Element.ALIGN_LEFT, ver_8_bold);
601: cell.setColspan(2);
602: vendorFillsInTable.addCell(cell);
603: // New row
604: String origin = new String(
605: " Point of origin and zip code: ______________________ Weight: _________ Class: _________\n");
606: cell = createCell(origin, true, false, false, false,
607: Element.ALIGN_LEFT, ver_8_bold);
608: cell.setColspan(2);
609: vendorFillsInTable.addCell(cell);
610: // New row
611: p = new Paragraph();
612: p
613: .add(new Chunk(
614: " Unless otherwise stated, all material to be shipped to ",
615: ver_8_normal));
616: purchasingAddressPartial = po.getDeliveryCityName() + ", "
617: + po.getDeliveryStateCode() + " "
618: + po.getDeliveryPostalCode();
619: p
620: .add(new Chunk(purchasingAddressPartial + "\n",
621: cour_10_normal));
622: cell = new PdfPCell(p);
623: cell.setColspan(2);
624: cell.setHorizontalAlignment(Element.ALIGN_LEFT);
625: cell.setBorderWidth(0);
626: vendorFillsInTable.addCell(cell);
627: // New row
628: String offerEffective = new String(
629: " Offer effective until (Date):_____________\n");
630: cell = createCell(offerEffective, true, false, false, false,
631: Element.ALIGN_LEFT, ver_8_normal);
632: vendorFillsInTable.addCell(cell);
633: String deliverBy = new String(
634: " Delivery can be made by (Date):_____________\n");
635: cell = createCell(deliverBy, true, false, false, false,
636: Element.ALIGN_LEFT, ver_8_normal);
637: vendorFillsInTable.addCell(cell);
638: // New row
639: String sign = new String(
640: " SIGN HERE:____________________________\n");
641: cell = createCell(sign, true, false, false, false,
642: Element.ALIGN_RIGHT, ver_10_bold);
643: vendorFillsInTable.addCell(cell);
644: String date = new String(" DATE:____________________________\n");
645: cell = createCell(date, true, false, false, false,
646: Element.ALIGN_RIGHT, ver_10_bold);
647: vendorFillsInTable.addCell(cell);
648: // New row
649: String name = new String(
650: " PRINT NAME:____________________________\n");
651: cell = createCell(name, true, false, false, false,
652: Element.ALIGN_RIGHT, ver_10_bold);
653: vendorFillsInTable.addCell(cell);
654: String phone = new String(
655: " PHONE:____________________________\n");
656: cell = createCell(phone, true, false, false, false,
657: Element.ALIGN_RIGHT, ver_10_bold);
658: vendorFillsInTable.addCell(cell);
659: // New row
660: String company = new String(
661: " COMPANY:____________________________\n");
662: cell = createCell(company, true, false, false, false,
663: Element.ALIGN_RIGHT, ver_10_bold);
664: vendorFillsInTable.addCell(cell);
665: String fax = new String(" FAX:____________________________\n");
666: cell = createCell(fax, true, false, false, false,
667: Element.ALIGN_RIGHT, ver_10_bold);
668: vendorFillsInTable.addCell(cell);
669:
670: document.add(vendorFillsInTable);
671: document.close();
672: LOG.debug("createQuotePdf()pdf document closed.");
673: } // End of createQuotePdf()
674:
675: /**
676: * Creates and returns a string buffer of the quote language descriptions from the database, ordered by the quote language
677: * identifier and appended with carriage returns after each line.
678: *
679: * @return The StringBuffer of the purchase order quote language.
680: */
681: private StringBuffer getPoQuoteLanguage() {
682:
683: StringBuffer quoteLanguage = new StringBuffer();
684: Map<String, Object> criteria = new HashMap<String, Object>();
685:
686: // retrieve list of purchase order quote language objects sorted by PO Quote Language Identifier
687: Collection<PurchaseOrderQuoteLanguage> poqlList = SpringContext
688: .getBean(BusinessObjectService.class)
689: .findMatchingOrderBy(
690: PurchaseOrderQuoteLanguage.class,
691: criteria,
692: PurapPropertyConstants.PURCHASE_ORDER_QUOTE_LANGUAGE_ID,
693: true);
694:
695: // append in string buffer
696: for (PurchaseOrderQuoteLanguage poql : poqlList) {
697: quoteLanguage.append(poql
698: .getPurchaseOrderQuoteLanguageDescription());
699: quoteLanguage.append("\n");
700: }
701:
702: return quoteLanguage;
703:
704: }
705:
706: /**
707: * A helper method to create a blank row of 6 cells in the items table.
708: *
709: * @param itemsTable
710: */
711: private void createBlankRowInItemsTable(PdfPTable itemsTable) {
712: // We're adding 6 cells because each row in the items table
713: // contains 6 columns.
714: for (int i = 0; i < 6; i++) {
715: itemsTable.addCell(" ");
716: }
717: }
718:
719: /**
720: * A helper method to create a PdfPCell. We can specify the content, font, horizontal alignment, border (borderless, no
721: * bottom border, no right border, no top border, etc.
722: *
723: * @param content The text content to be displayed in the cell.
724: * @param borderless boolean true if the cell should be borderless.
725: * @param noBottom boolean true if the cell should have borderWidthBottom = 0.
726: * @param noRight boolean true if the cell should have borderWidthRight = 0.
727: * @param noTop boolean true if the cell should have borderWidthTop = 0.
728: * @param horizontalAlignment The desired horizontal alignment for the cell.
729: * @param font The font type to be used in the cell.
730: * @return An instance of PdfPCell which content and attributes were set by the input parameters.
731: */
732: private PdfPCell createCell(String content, boolean borderless,
733: boolean noBottom, boolean noRight, boolean noTop,
734: int horizontalAlignment, Font font) {
735: PdfPCell tableCell = new PdfPCell(new Paragraph(content, font));
736: if (borderless) {
737: tableCell.setBorder(0);
738: }
739: if (noBottom) {
740: tableCell.setBorderWidthBottom(0);
741: }
742: if (noTop) {
743: tableCell.setBorderWidthTop(0);
744: }
745: if (noRight) {
746: tableCell.setBorderWidthRight(0);
747: }
748: tableCell.setHorizontalAlignment(horizontalAlignment);
749: return tableCell;
750: }
751:
752: /**
753: * Obtains the CampusParameter based on the delivery campus code of the purchase order.
754: *
755: * @param contractManagerCampusCode This is not used anymore.
756: * @return The CampusParameter whose delivery campus code matches with the
757: * purchase order's delivery campus code.
758: */
759: private CampusParameter getCampusParameter(
760: String contractManagerCampusCode) {
761: Map<String, Object> criteria = new HashMap<String, Object>();
762: criteria.put(KFSPropertyConstants.CAMPUS_CODE, po
763: .getDeliveryCampusCode());
764: CampusParameter campusParameter = (CampusParameter) ((List) SpringContext
765: .getBean(BusinessObjectService.class).findMatching(
766: CampusParameter.class, criteria)).get(0);
767:
768: return campusParameter;
769: }
770:
771: /**
772: * Creates and returns the full purchasing address given the campus parameter.
773: *
774: * @param campusParameter The CampusParameter object to be used to create the full purchasing address.
775: * @return The String containing the full purchasing address.
776: */
777: private String getPurchasingAddressFull(
778: CampusParameter campusParameter) {
779: String indent = " ";
780: StringBuffer addressBuffer = new StringBuffer();
781: addressBuffer
782: .append(indent
783: + campusParameter
784: .getPurchasingInstitutionName() + "\n");
785: addressBuffer.append(indent
786: + campusParameter.getPurchasingDepartmentName() + "\n");
787: addressBuffer.append(indent
788: + campusParameter.getPurchasingDepartmentLine1Address()
789: + "\n");
790: addressBuffer.append(indent
791: + campusParameter.getPurchasingDepartmentLine2Address()
792: + "\n");
793: addressBuffer.append(indent
794: + campusParameter.getPurchasingDepartmentCityName()
795: + ", ");
796: addressBuffer.append(indent
797: + campusParameter.getPurchasingDepartmentStateCode()
798: + " ");
799: addressBuffer.append(indent
800: + campusParameter.getPurchasingDepartmentZipCode()
801: + " ");
802: addressBuffer
803: .append(indent
804: + (ObjectUtils.isNotNull(campusParameter
805: .getPurchasingDepartmentCountryCode()) ? campusParameter
806: .getPurchasingDepartmentCountryCode()
807: : ""));
808:
809: return addressBuffer.toString();
810: }
811:
812: /**
813: * Creates and returns the partial purchasing address given the campus parameter.
814: *
815: * @param campusParameter The CampusParameter object to be used to create the partial purchasing address.
816: * @return The String containing the partial purchasing address.
817: */
818: private String getPurchasingAddressPartial(
819: CampusParameter campusParameter) {
820: StringBuffer purchasingAddressPartial = new StringBuffer();
821:
822: purchasingAddressPartial.append(campusParameter
823: .getPurchasingInstitutionName()
824: + ", ");
825: purchasingAddressPartial.append(campusParameter
826: .getPurchasingDepartmentCityName()
827: + ", ");
828: purchasingAddressPartial.append(campusParameter
829: .getPurchasingDepartmentStateCode()
830: + " ");
831: purchasingAddressPartial.append(campusParameter
832: .getPurchasingDepartmentZipCode());
833:
834: return purchasingAddressPartial.toString();
835: }
836: }
|