Source Code Cross Referenced for PurchaseOrderPdf.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » purap » pdf » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.module.purap.pdf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2007 The Kuali Foundation.
0003:         * 
0004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0005:         * you may not use this file except in compliance with the License.
0006:         * You may obtain a copy of the License at
0007:         * 
0008:         * http://www.opensource.org/licenses/ecl1.php
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:        package org.kuali.module.purap.pdf;
0017:
0018:        import java.io.ByteArrayOutputStream;
0019:        import java.io.FileNotFoundException;
0020:        import java.io.FileOutputStream;
0021:        import java.io.IOException;
0022:        import java.math.BigDecimal;
0023:        import java.text.NumberFormat;
0024:        import java.util.ArrayList;
0025:        import java.util.Collection;
0026:        import java.util.List;
0027:        import java.util.Locale;
0028:
0029:        import org.apache.commons.lang.StringUtils;
0030:        import org.apache.commons.logging.Log;
0031:        import org.apache.commons.logging.LogFactory;
0032:        import org.kuali.core.util.KualiDecimal;
0033:        import org.kuali.kfs.KFSConstants;
0034:        import org.kuali.module.purap.PurapConstants;
0035:        import org.kuali.module.purap.bo.PurchaseOrderItem;
0036:        import org.kuali.module.purap.bo.PurchaseOrderVendorStipulation;
0037:        import org.kuali.module.purap.document.PurchaseOrderDocument;
0038:        import org.kuali.module.purap.document.PurchaseOrderRetransmitDocument;
0039:        import org.kuali.module.purap.exceptions.PurError;
0040:
0041:        import com.lowagie.text.Chunk;
0042:        import com.lowagie.text.Document;
0043:        import com.lowagie.text.DocumentException;
0044:        import com.lowagie.text.Element;
0045:        import com.lowagie.text.ExceptionConverter;
0046:        import com.lowagie.text.Image;
0047:        import com.lowagie.text.Paragraph;
0048:        import com.lowagie.text.Phrase;
0049:        import com.lowagie.text.pdf.BaseFont;
0050:        import com.lowagie.text.pdf.PdfPCell;
0051:        import com.lowagie.text.pdf.PdfPTable;
0052:        import com.lowagie.text.pdf.PdfWriter;
0053:
0054:        /**
0055:         * Base class to handle pdf for purchase order documents.
0056:         */
0057:        public class PurchaseOrderPdf extends PurapPdf {
0058:            private static Log LOG = LogFactory.getLog(PurchaseOrderPdf.class);
0059:
0060:            /** headerTable pieces need to be public */
0061:
0062:            public PurchaseOrderPdf() {
0063:                super ();
0064:            }
0065:
0066:            /**
0067:             * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if 
0068:             * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content.
0069:             * 
0070:             * @param writer    The PdfWriter for this document.
0071:             * @param document  The document.
0072:             * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
0073:             */
0074:            public void onOpenDocument(PdfWriter writer, Document document) {
0075:                LOG.debug("onOpenDocument() started. isRetransmit is "
0076:                        + isRetransmit);
0077:                try {
0078:                    float[] headerWidths = { 0.20f, 0.80f };
0079:                    headerTable = new PdfPTable(headerWidths);
0080:                    headerTable.setWidthPercentage(100);
0081:                    headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);
0082:                    headerTable.setSplitLate(false);
0083:                    headerTable.getDefaultCell().setBorderWidth(0);
0084:                    headerTable.getDefaultCell().setHorizontalAlignment(
0085:                            Element.ALIGN_CENTER);
0086:                    headerTable.getDefaultCell().setVerticalAlignment(
0087:                            Element.ALIGN_CENTER);
0088:                    if (StringUtils.isNotBlank(logoImage)) {
0089:                        logo = Image.getInstance(logoImage);
0090:                        logo.scalePercent(3, 3);
0091:                        headerTable.addCell(new Phrase(new Chunk(logo, 0, 0)));
0092:                    } else {
0093:                        // if we don't use images
0094:                        headerTable.addCell(new Phrase(new Chunk("")));
0095:                    }
0096:                    // Nested table for titles, etc.
0097:                    float[] nestedHeaderWidths = { 0.70f, 0.30f };
0098:                    nestedHeaderTable = new PdfPTable(nestedHeaderWidths);
0099:                    nestedHeaderTable.setSplitLate(false);
0100:                    PdfPCell cell;
0101:
0102:                    // New nestedHeaderTable row
0103:                    cell = new PdfPCell(new Paragraph(po.getBillingName(),
0104:                            ver_15_normal));
0105:                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0106:                    cell.setBorderWidth(0);
0107:                    nestedHeaderTable.addCell(cell);
0108:                    cell = new PdfPCell(new Paragraph(" ", ver_15_normal));
0109:                    cell.setBorderWidth(0);
0110:                    nestedHeaderTable.addCell(cell);
0111:                    // New nestedHeaderTable row
0112:                    if (isRetransmit) {
0113:                        cell = new PdfPCell(new Paragraph(po
0114:                                .getRetransmitHeader(), ver_15_normal));
0115:                    } else {
0116:                        cell = new PdfPCell(new Paragraph("PURCHASE ORDER",
0117:                                ver_15_normal));
0118:                    }
0119:                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0120:                    cell.setBorderWidth(0);
0121:                    nestedHeaderTable.addCell(cell);
0122:                    Paragraph p = new Paragraph();
0123:                    p.add(new Chunk("PO Number: ", ver_11_normal));
0124:                    p.add(new Chunk(po.getPurapDocumentIdentifier().toString(),
0125:                            cour_10_normal));
0126:
0127:                    cell = new PdfPCell(p);
0128:                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0129:                    cell.setBorderWidth(0);
0130:                    nestedHeaderTable.addCell(cell);
0131:                    if (!po.getPurchaseOrderAutomaticIndicator()) { // Contract manager name goes on non-APOs.
0132:                        // New nestedHeaderTable row, spans both columns
0133:                        p = new Paragraph();
0134:                        p.add(new Chunk("Contract Manager: ", ver_11_normal));
0135:                        p.add(new Chunk(po.getContractManager()
0136:                                .getContractManagerName(), cour_10_normal));
0137:                        cell = new PdfPCell(p);
0138:                        cell.setColspan(2);
0139:                        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0140:                        cell.setBorderWidth(0);
0141:                        nestedHeaderTable.addCell(cell);
0142:                    }
0143:                    // Add the nestedHeaderTable to the headerTable
0144:                    cell = new PdfPCell(nestedHeaderTable);
0145:                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0146:                    cell.setBorderWidth(0);
0147:                    headerTable.addCell(cell);
0148:
0149:                    // initialization of the template
0150:                    tpl = writer.getDirectContent().createTemplate(100, 100);
0151:                    // initialization of the font
0152:                    helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
0153:                            false);
0154:                } catch (Exception e) {
0155:                    throw new ExceptionConverter(e);
0156:                }
0157:            }
0158:
0159:            /**
0160:             * Gets a PageEvents object.
0161:             * 
0162:             * @return a new PageEvents object
0163:             */
0164:            public PurchaseOrderPdf getPageEvents() {
0165:                LOG.debug("getPageEvents() started.");
0166:                return new PurchaseOrderPdf();
0167:            }
0168:
0169:            /**
0170:             * Generates the pdf document based on the data in the given PurchaseOrderDocument, the pdf parameters, 
0171:             * environment, retransmit items, creates a pdf writer using the given byteArrayOutputStream then
0172:             * write the pdf document into the writer.
0173:             * 
0174:             * @param po                     The PurchaseOrderDocument to be used to generate the pdf.
0175:             * @param pdfParameters          The PurchaseOrderPdfParameters to be used to generate the pdf.
0176:             * @param byteArrayOutputStream  The ByteArrayOutputStream where the pdf document will be written to.
0177:             * @param isRetransmit           The boolean to indicate whether this is for a retransmit purchase order document.
0178:             * @param environment            The current environment used (e.g. DEV if it is a development environment).
0179:             * @param retransmitItems        The items selected by the user to be retransmitted.
0180:             */
0181:            public void generatePdf(PurchaseOrderDocument po,
0182:                    PurchaseOrderPdfParameters pdfParameters,
0183:                    ByteArrayOutputStream byteArrayOutputStream,
0184:                    boolean isRetransmit, String environment,
0185:                    List<PurchaseOrderItem> retransmitItems) {
0186:                LOG.debug("generatePdf() started for po number "
0187:                        + po.getPurapDocumentIdentifier());
0188:
0189:                this .isRetransmit = isRetransmit;
0190:                String statusInquiryUrl = pdfParameters.getStatusInquiryUrl();
0191:                String campusName = pdfParameters.getCampusParameter()
0192:                        .getCampus().getCampusName();
0193:                String contractLanguage = pdfParameters.getContractLanguage();
0194:                String logoImage = pdfParameters.getLogoImage();
0195:                String directorSignatureImage = pdfParameters
0196:                        .getDirectorSignatureImage();
0197:                String directorName = pdfParameters.getCampusParameter()
0198:                        .getCampusPurchasingDirectorName();
0199:                String directorTitle = pdfParameters.getCampusParameter()
0200:                        .getCampusPurchasingDirectorTitle();
0201:                String contractManagerSignatureImage = pdfParameters
0202:                        .getContractManagerSignatureImage();
0203:
0204:                try {
0205:                    Document doc = this .getDocument(9, 9, 70, 36);
0206:                    PdfWriter writer = PdfWriter.getInstance(doc,
0207:                            byteArrayOutputStream);
0208:                    this .createPdf(po, doc, writer, statusInquiryUrl,
0209:                            campusName, contractLanguage, logoImage,
0210:                            directorSignatureImage, directorName,
0211:                            directorTitle, contractManagerSignatureImage,
0212:                            isRetransmit, environment, retransmitItems);
0213:                } catch (DocumentException de) {
0214:                    LOG.error("generatePdf() DocumentException: "
0215:                            + de.getMessage(), de);
0216:                    throw new PurError(
0217:                            "Document Exception when trying to save a Purchase Order PDF",
0218:                            de);
0219:                } catch (IOException i) {
0220:                    LOG
0221:                            .error("generatePdf() IOException: "
0222:                                    + i.getMessage(), i);
0223:                    throw new PurError(
0224:                            "IO Exception when trying to save a Purchase Order PDF",
0225:                            i);
0226:                } catch (Exception t) {
0227:                    LOG.error("generatePdf() EXCEPTION: " + t.getMessage(), t);
0228:                    throw new PurError(
0229:                            "Exception when trying to save a Purchase Order PDF",
0230:                            t);
0231:                }
0232:            }
0233:
0234:            /**
0235:             * Invokes the createPdf method to create a pdf document and saves it into a file 
0236:             * which name and location are specified in the pdfParameters.
0237:             * 
0238:             * @param po             The PurchaseOrderDocument to be used to create the pdf.
0239:             * @param pdfParameters  The pdfParameters containing some of the parameters information needed by the pdf for example, the pdf file name and pdf file location, purchasing director name, etc.
0240:             * @param isRetransmit   The boolean to indicate whether this is for a retransmit purchase order document.
0241:             * @param environment    The current environment used (e.g. DEV if it is a development environment).
0242:             */
0243:            public void savePdf(PurchaseOrderDocument po,
0244:                    PurchaseOrderPdfParameters pdfParameters,
0245:                    boolean isRetransmit, String environment) {
0246:                LOG.debug("savePdf() started for po number "
0247:                        + po.getPurapDocumentIdentifier());
0248:
0249:                this .isRetransmit = isRetransmit;
0250:                String statusInquiryUrl = pdfParameters.getStatusInquiryUrl();
0251:                String campusName = pdfParameters.getCampusParameter()
0252:                        .getCampus().getCampusName();
0253:                String contractLanguage = pdfParameters.getContractLanguage();
0254:                String logoImage = pdfParameters.getLogoImage();
0255:                String directorSignatureImage = pdfParameters
0256:                        .getDirectorSignatureImage();
0257:                String directorName = pdfParameters.getCampusParameter()
0258:                        .getCampusPurchasingDirectorName();
0259:                String directorTitle = pdfParameters.getCampusParameter()
0260:                        .getCampusPurchasingDirectorTitle();
0261:                String contractManagerSignatureImage = pdfParameters
0262:                        .getContractManagerSignatureImage();
0263:                String pdfFileLocation = pdfParameters.getPdfFileLocation();
0264:                String pdfFileName = pdfParameters.getPdfFileName();
0265:
0266:                try {
0267:                    Document doc = this .getDocument(9, 9, 70, 36);
0268:                    PdfWriter writer = PdfWriter
0269:                            .getInstance(doc, new FileOutputStream(
0270:                                    pdfFileLocation + pdfFileName));
0271:                    this .createPdf(po, doc, writer, statusInquiryUrl,
0272:                            campusName, contractLanguage, logoImage,
0273:                            directorSignatureImage, directorName,
0274:                            directorTitle, contractManagerSignatureImage,
0275:                            isRetransmit, environment);
0276:                } catch (DocumentException de) {
0277:                    LOG.error(
0278:                            "savePdf() DocumentException: " + de.getMessage(),
0279:                            de);
0280:                    throw new PurError(
0281:                            "Document Exception when trying to save a Purchase Order PDF",
0282:                            de);
0283:                } catch (FileNotFoundException f) {
0284:                    LOG.error("savePdf() FileNotFoundException: "
0285:                            + f.getMessage(), f);
0286:                    throw new PurError(
0287:                            "FileNotFound Exception when trying to save a Purchase Order PDF",
0288:                            f);
0289:                } catch (IOException i) {
0290:                    LOG.error("savePdf() IOException: " + i.getMessage(), i);
0291:                    throw new PurError(
0292:                            "IO Exception when trying to save a Purchase Order PDF",
0293:                            i);
0294:                } catch (Exception t) {
0295:                    LOG.error("savePdf() EXCEPTION: " + t.getMessage(), t);
0296:                    throw new PurError(
0297:                            "Exception when trying to save a Purchase Order PDF",
0298:                            t);
0299:                }
0300:            }
0301:
0302:            /**
0303:             * Creates the purchase order pdf, and pass in null as the retransmitItems List because it doesn't need retransmit.
0304:             * 
0305:             * @param po                             The PurchaseOrderDocument to be used to create the pdf.
0306:             * @param document                       The pdf document whose margins have already been set.
0307:             * @param writer                         The PdfWriter to write the pdf document into.
0308:             * @param statusInquiryUrl               The status inquiry url to be displayed on the pdf document.
0309:             * @param campusName                     The campus name to be displayed on the pdf document.
0310:             * @param contractLanguage               The contract language to be displayed on the pdf document.
0311:             * @param logoImage                      The logo image file name to be displayed on the pdf document.
0312:             * @param directorSignatureImage         The director signature image to be displayed on the pdf document.
0313:             * @param directorName                   The director name to be displayed on the pdf document.
0314:             * @param directorTitle                  The director title to be displayed on the pdf document.
0315:             * @param contractManagerSignatureImage  The contract manager signature image to be displayed on the pdf document.
0316:             * @param isRetransmit                   The boolean to indicate whether this is for a retransmit purchase order document.
0317:             * @param environment                    The current environment used (e.g. DEV if it is a development environment).
0318:             * @throws DocumentException
0319:             * @throws IOException
0320:             */
0321:            private void createPdf(PurchaseOrderDocument po, Document document,
0322:                    PdfWriter writer, String statusInquiryUrl,
0323:                    String campusName, String contractLanguage,
0324:                    String logoImage, String directorSignatureImage,
0325:                    String directorName, String directorTitle,
0326:                    String contractManagerSignatureImage, boolean isRetransmit,
0327:                    String environment) throws DocumentException, IOException {
0328:                createPdf(po, document, writer, statusInquiryUrl, campusName,
0329:                        contractLanguage, logoImage, directorSignatureImage,
0330:                        directorName, directorTitle,
0331:                        contractManagerSignatureImage, isRetransmit,
0332:                        environment, null);
0333:            }
0334:
0335:            /**
0336:             * Create a PDF using the given input parameters.
0337:             * 
0338:             * @param po                             The PurchaseOrderDocument to be used to create the pdf.
0339:             * @param document                       The pdf document whose margins have already been set.
0340:             * @param writer                         The PdfWriter to write the pdf document into.
0341:             * @param statusInquiryUrl               The status inquiry url to be displayed on the pdf document.
0342:             * @param campusName                     The campus name to be displayed on the pdf document.
0343:             * @param contractLanguage               The contract language to be displayed on the pdf document.
0344:             * @param logoImage                      The logo image file name to be displayed on the pdf document.
0345:             * @param directorSignatureImage         The director signature image to be displayed on the pdf document.
0346:             * @param directorName                   The director name to be displayed on the pdf document.
0347:             * @param directorTitle                  The director title to be displayed on the pdf document.
0348:             * @param contractManagerSignatureImage  The contract manager signature image to be displayed on the pdf document.
0349:             * @param isRetransmit                   The boolean to indicate whether this is for a retransmit purchase order document.
0350:             * @param environment                    The current environment used (e.g. DEV if it is a development environment).
0351:             * @param retransmitItems                The items selected by the user to be retransmitted.
0352:             * @throws DocumentException
0353:             * @throws IOException
0354:             */
0355:            private void createPdf(PurchaseOrderDocument po, Document document,
0356:                    PdfWriter writer, String statusInquiryUrl,
0357:                    String campusName, String contractLanguage,
0358:                    String logoImage, String directorSignatureImage,
0359:                    String directorName, String directorTitle,
0360:                    String contractManagerSignatureImage, boolean isRetransmit,
0361:                    String environment, List<PurchaseOrderItem> retransmitItems)
0362:                    throws DocumentException, IOException {
0363:                LOG.debug("createPdf() started for po number "
0364:                        + po.getPurapDocumentIdentifier().toString());
0365:
0366:                // These have to be set because they are used by the onOpenDocument() and onStartPage() methods.
0367:                this .campusName = campusName;
0368:                this .po = po;
0369:                this .logoImage = logoImage;
0370:                this .environment = environment;
0371:
0372:                NumberFormat numberFormat = NumberFormat
0373:                        .getCurrencyInstance(Locale.US);
0374:                Collection errors = new ArrayList();
0375:
0376:                // This turns on the page events that handle the header and page numbers.
0377:                PurchaseOrderPdf events = new PurchaseOrderPdf()
0378:                        .getPageEvents();
0379:                writer.setPageEvent(this ); // Passing in "this" lets it know about the po, campusName, etc.
0380:
0381:                document.open();
0382:
0383:                PdfPCell cell;
0384:                Paragraph p = new Paragraph();
0385:
0386:                // ***** Info table (vendor, address info) *****
0387:                LOG.debug("createPdf() info table started.");
0388:                float[] infoWidths = { 0.50f, 0.50f };
0389:                PdfPTable infoTable = new PdfPTable(infoWidths);
0390:
0391:                infoTable.setWidthPercentage(100);
0392:                infoTable.setHorizontalAlignment(Element.ALIGN_CENTER);
0393:                infoTable.setSplitLate(false);
0394:
0395:                StringBuffer vendorInfo = new StringBuffer();
0396:                vendorInfo.append("\n");
0397:                if (StringUtils.isNotBlank(po.getVendorName())) {
0398:                    vendorInfo.append("     " + po.getVendorName() + "\n");
0399:                }
0400:                if (StringUtils.isNotBlank(po.getVendorLine1Address())) {
0401:                    vendorInfo.append("     " + po.getVendorLine1Address()
0402:                            + "\n");
0403:                }
0404:                if (StringUtils.isNotBlank(po.getVendorLine2Address())) {
0405:                    vendorInfo.append("     " + po.getVendorLine2Address()
0406:                            + "\n");
0407:                }
0408:                if (StringUtils.isNotBlank(po.getVendorCityName())) {
0409:                    vendorInfo.append("     " + po.getVendorCityName());
0410:                }
0411:                if (StringUtils.isNotBlank(po.getVendorStateCode())) {
0412:                    vendorInfo.append(", " + po.getVendorStateCode());
0413:                }
0414:                if (StringUtils.isNotBlank(po.getVendorPostalCode())) {
0415:                    vendorInfo.append(" " + po.getVendorPostalCode() + "\n");
0416:                } else {
0417:                    vendorInfo.append("\n");
0418:                }
0419:                if (!KFSConstants.COUNTRY_CODE_UNITED_STATES
0420:                        .equalsIgnoreCase(po.getVendorCountryCode())
0421:                        && po.getVendorCountry() != null) {
0422:                    vendorInfo.append("     "
0423:                            + po.getVendorCountry().getPostalCountryName()
0424:                            + "\n\n");
0425:                } else {
0426:                    vendorInfo.append("\n\n");
0427:                }
0428:                p = new Paragraph();
0429:                p.add(new Chunk(" Vendor", ver_5_normal));
0430:                p.add(new Chunk(vendorInfo.toString(), cour_10_normal));
0431:                cell = new PdfPCell(p);
0432:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0433:                infoTable.addCell(cell);
0434:
0435:                StringBuffer shipToInfo = new StringBuffer();
0436:                shipToInfo.append("\n");
0437:                if (StringUtils.isNotBlank(po.getDeliveryToName())) {
0438:                    shipToInfo.append("     " + po.getDeliveryToName() + "\n");
0439:                }
0440:                // extra space needed below to separate other text going on same PDF line
0441:                String deliveryBuildingName = po.getDeliveryBuildingName()
0442:                        + " ";
0443:                if (po.isDeliveryBuildingOther()) {
0444:                    deliveryBuildingName = "";
0445:                }
0446:
0447:                shipToInfo.append("     " + deliveryBuildingName + "Room #"
0448:                        + po.getDeliveryBuildingRoomNumber() + "\n");
0449:                shipToInfo.append("     "
0450:                        + po.getDeliveryBuildingLine1Address() + "\n");
0451:                if (StringUtils
0452:                        .isNotBlank(po.getDeliveryBuildingLine2Address())) {
0453:                    shipToInfo.append("     "
0454:                            + po.getDeliveryBuildingLine2Address() + "\n");
0455:                }
0456:                shipToInfo.append("     " + po.getDeliveryCityName() + ", "
0457:                        + po.getDeliveryStateCode() + " "
0458:                        + po.getDeliveryPostalCode() + "\n\n");
0459:                p = new Paragraph();
0460:                p.add(new Chunk("  Ship to address", ver_5_normal));
0461:                p.add(new Chunk(shipToInfo.toString(), cour_10_normal));
0462:                cell = new PdfPCell(p);
0463:                infoTable.addCell(cell);
0464:
0465:                p = new Paragraph();
0466:                p.add(new Chunk("  Shipping Terms\n", ver_5_normal));
0467:                if (po.getVendorShippingPaymentTerms() != null
0468:                        && po.getVendorShippingTitle() != null) {
0469:                    p
0470:                            .add(new Chunk(
0471:                                    "     "
0472:                                            + po
0473:                                                    .getVendorShippingPaymentTerms()
0474:                                                    .getVendorShippingPaymentTermsDescription(),
0475:                                    cour_10_normal));
0476:                    p.add(new Chunk(" - "
0477:                            + po.getVendorShippingTitle()
0478:                                    .getVendorShippingTitleDescription(),
0479:                            cour_10_normal));
0480:                } else if (po.getVendorShippingPaymentTerms() != null
0481:                        && po.getVendorShippingTitle() == null) {
0482:                    p
0483:                            .add(new Chunk(
0484:                                    "     "
0485:                                            + po
0486:                                                    .getVendorShippingPaymentTerms()
0487:                                                    .getVendorShippingPaymentTermsDescription(),
0488:                                    cour_10_normal));
0489:                } else if (po.getVendorShippingTitle() != null
0490:                        && po.getVendorShippingPaymentTerms() == null) {
0491:                    p.add(new Chunk("     "
0492:                            + po.getVendorShippingTitle()
0493:                                    .getVendorShippingTitleDescription(),
0494:                            cour_10_normal));
0495:                }
0496:                cell = new PdfPCell(p);
0497:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0498:                infoTable.addCell(cell);
0499:
0500:                p = new Paragraph();
0501:                p.add(new Chunk("  Payment Terms\n", ver_5_normal));
0502:                if (po.getVendorPaymentTerms() != null) {
0503:                    p.add(new Chunk("     "
0504:                            + po.getVendorPaymentTerms()
0505:                                    .getVendorPaymentTermsDescription(),
0506:                            cour_10_normal));
0507:                }
0508:                cell = new PdfPCell(p);
0509:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0510:                infoTable.addCell(cell);
0511:
0512:                p = new Paragraph();
0513:                p.add(new Chunk("  Delivery Required By\n", ver_5_normal));
0514:
0515:                if (po.getDeliveryRequiredDate() != null
0516:                        && po.getDeliveryRequiredDateReason() != null) {
0517:                    p.add(new Chunk("     " + po.getDeliveryRequiredDate(),
0518:                            cour_10_normal));
0519:                    p
0520:                            .add(new Chunk(
0521:                                    " - "
0522:                                            + po
0523:                                                    .getDeliveryRequiredDateReason()
0524:                                                    .getDeliveryRequiredDateReasonDescription(),
0525:                                    cour_10_normal));
0526:                } else if (po.getDeliveryRequiredDate() != null
0527:                        && po.getDeliveryRequiredDateReason() == null) {
0528:                    p.add(new Chunk("     " + po.getDeliveryRequiredDate(),
0529:                            cour_10_normal));
0530:                } else if (po.getDeliveryRequiredDate() == null
0531:                        && po.getDeliveryRequiredDateReason() != null) {
0532:                    p
0533:                            .add(new Chunk(
0534:                                    "     "
0535:                                            + po
0536:                                                    .getDeliveryRequiredDateReason()
0537:                                                    .getDeliveryRequiredDateReasonDescription(),
0538:                                    cour_10_normal));
0539:                }
0540:                cell = new PdfPCell(p);
0541:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0542:                infoTable.addCell(cell);
0543:
0544:                p = new Paragraph();
0545:                p.add(new Chunk("  ", ver_5_normal));
0546:                cell = new PdfPCell(p);
0547:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0548:                infoTable.addCell(cell);
0549:
0550:                // Nested table for Order Date, etc.
0551:                float[] nestedInfoWidths = { 0.50f, 0.50f };
0552:                PdfPTable nestedInfoTable = new PdfPTable(nestedInfoWidths);
0553:                nestedInfoTable.setSplitLate(false);
0554:
0555:                p = new Paragraph();
0556:                p.add(new Chunk("  Order date\n", ver_5_normal));
0557:
0558:                String orderDate = "";
0559:                if (po.getPurchaseOrderInitialOpenDate() != null) {
0560:                    orderDate = po.getPurchaseOrderInitialOpenDate().toString();
0561:                } else { // This date isn't set until the first time this document is printed, so will be null
0562:                    // the first time; use today's date.
0563:                    orderDate = getDateTimeService().getCurrentSqlDate()
0564:                            .toString();
0565:                }
0566:
0567:                p.add(new Chunk("     " + orderDate, cour_10_normal));
0568:                cell = new PdfPCell(p);
0569:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0570:                nestedInfoTable.addCell(cell);
0571:
0572:                p = new Paragraph();
0573:                p.add(new Chunk("  I.U. customer no.\n", ver_5_normal));
0574:                if (po.getVendorCustomerNumber() != null) {
0575:                    p.add(new Chunk("     " + po.getVendorCustomerNumber(),
0576:                            cour_10_normal));
0577:                }
0578:                cell = new PdfPCell(p);
0579:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0580:                nestedInfoTable.addCell(cell);
0581:
0582:                p = new Paragraph();
0583:                p.add(new Chunk("  Delivery instructions\n", ver_5_normal));
0584:                if (StringUtils.isNotBlank(po.getDeliveryInstructionText())) {
0585:                    p.add(new Chunk("     " + po.getDeliveryInstructionText(),
0586:                            cour_10_normal));
0587:                }
0588:                cell = new PdfPCell(p);
0589:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0590:                nestedInfoTable.addCell(cell);
0591:
0592:                p = new Paragraph();
0593:                p.add(new Chunk("  Contract ID\n", ver_5_normal));
0594:                if (po.getVendorContract() != null) {
0595:                    p.add(new Chunk(po.getVendorContract()
0596:                            .getVendorContractGeneratedIdentifier().toString(),
0597:                            cour_10_normal));
0598:                }
0599:                cell = new PdfPCell(p);
0600:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0601:                nestedInfoTable.addCell(cell);
0602:
0603:                // Add the nestedInfoTable to the infoTable
0604:                cell = new PdfPCell(nestedInfoTable);
0605:                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0606:                infoTable.addCell(cell);
0607:
0608:                StringBuffer billToInfo = new StringBuffer();
0609:                billToInfo.append("\n");
0610:                billToInfo.append("     " + po.getBillingName() + "\n");
0611:                billToInfo.append("     " + po.getBillingLine1Address() + "\n");
0612:                if (po.getBillingLine2Address() != null) {
0613:                    billToInfo.append("     " + po.getBillingLine2Address()
0614:                            + "\n");
0615:                }
0616:                billToInfo.append("     " + po.getBillingCityName() + ", "
0617:                        + po.getBillingStateCode() + " "
0618:                        + po.getBillingPostalCode() + "\n");
0619:                if (po.getBillingPhoneNumber() != null) {
0620:                    billToInfo.append("     " + po.getBillingPhoneNumber());
0621:                }
0622:                p = new Paragraph();
0623:                p.add(new Chunk("  Bill to address", ver_5_normal));
0624:                p
0625:                        .add(new Chunk("     " + billToInfo.toString(),
0626:                                cour_10_normal));
0627:                p.add(new Chunk("\n Invoice status inquiry: "
0628:                        + statusInquiryUrl, ver_6_normal));
0629:                cell = new PdfPCell(p);
0630:                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
0631:                infoTable.addCell(cell);
0632:
0633:                document.add(infoTable);
0634:
0635:                PdfPTable notesStipulationsTable = new PdfPTable(1);
0636:                notesStipulationsTable.setWidthPercentage(100);
0637:                notesStipulationsTable.setSplitLate(false);
0638:
0639:                p = new Paragraph();
0640:                p.add(new Chunk("  Vendor Note(s)\n", ver_5_normal));
0641:                if (po.getVendorNoteText() != null) {
0642:                    p.add(new Chunk("     " + po.getVendorNoteText() + "\n",
0643:                            cour_10_normal));
0644:                }
0645:
0646:                PdfPCell tableCell = new PdfPCell(p);
0647:                tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
0648:                tableCell.setVerticalAlignment(Element.ALIGN_TOP);
0649:
0650:                notesStipulationsTable.addCell(tableCell);
0651:
0652:                p = new Paragraph();
0653:                p.add(new Chunk("  Vendor Stipulations and Information\n",
0654:                        ver_5_normal));
0655:                if ((po.getPurchaseOrderBeginDate() != null)
0656:                        && (po.getPurchaseOrderEndDate() != null)) {
0657:                    p.add(new Chunk("     Order in effect from "
0658:                            + po.getPurchaseOrderBeginDate() + " to "
0659:                            + po.getPurchaseOrderEndDate() + ".\n",
0660:                            cour_10_normal));
0661:
0662:                }
0663:                Collection<PurchaseOrderVendorStipulation> vendorStipulationsList = po
0664:                        .getPurchaseOrderVendorStipulations();
0665:                if (vendorStipulationsList.size() > 0) {
0666:                    StringBuffer vendorStipulations = new StringBuffer();
0667:                    for (PurchaseOrderVendorStipulation povs : vendorStipulationsList) {
0668:                        vendorStipulations
0669:                                .append("     "
0670:                                        + povs
0671:                                                .getVendorStipulationDescription()
0672:                                        + "\n");
0673:                    }
0674:                    p.add(new Chunk("     " + vendorStipulations.toString(),
0675:                            cour_10_normal));
0676:                }
0677:
0678:                tableCell = new PdfPCell(p);
0679:                tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
0680:                tableCell.setVerticalAlignment(Element.ALIGN_TOP);
0681:                notesStipulationsTable.addCell(tableCell);
0682:
0683:                document.add(notesStipulationsTable);
0684:
0685:                // ***** Items table *****
0686:                LOG.debug("createPdf() items table started.");
0687:                float[] itemsWidths = { 0.07f, 0.1f, 0.07f, 0.50f, 0.13f, 0.13f };
0688:                PdfPTable itemsTable = new PdfPTable(6);
0689:                // itemsTable.setCellsFitPage(false); With this set to true a large cell will
0690:                // skip to the next page. The default Table behaviour seems to be what we want:
0691:                // start the large cell on the same page and continue it to the next.
0692:                itemsTable.setWidthPercentage(100);
0693:                itemsTable.setWidths(itemsWidths);
0694:                itemsTable.setSplitLate(false);
0695:
0696:                tableCell = new PdfPCell(new Paragraph("Item\nNo.",
0697:                        ver_5_normal));
0698:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0699:                itemsTable.addCell(tableCell);
0700:                tableCell = new PdfPCell(
0701:                        new Paragraph("Quantity", ver_5_normal));
0702:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0703:                itemsTable.addCell(tableCell);
0704:                tableCell = new PdfPCell(new Paragraph("UOM", ver_5_normal));
0705:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0706:                itemsTable.addCell(tableCell);
0707:                tableCell = new PdfPCell(new Paragraph("Description",
0708:                        ver_5_normal));
0709:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0710:                itemsTable.addCell(tableCell);
0711:                tableCell = new PdfPCell(new Paragraph("Unit Cost",
0712:                        ver_5_normal));
0713:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0714:                itemsTable.addCell(tableCell);
0715:                tableCell = new PdfPCell(new Paragraph("Extended Cost",
0716:                        ver_5_normal));
0717:                tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0718:                itemsTable.addCell(tableCell);
0719:
0720:                Collection<PurchaseOrderItem> itemsList = new ArrayList();
0721:                if (isRetransmit) {
0722:                    itemsList = retransmitItems;
0723:                } else {
0724:                    itemsList = po.getItems();
0725:                }
0726:                for (PurchaseOrderItem poi : itemsList) {
0727:                    if ((poi.getItemType() != null)
0728:                            && (poi.getItemType()
0729:                                    .isItemTypeAboveTheLineIndicator()
0730:                                    || poi
0731:                                            .getItemType()
0732:                                            .getItemTypeCode()
0733:                                            .equals(
0734:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)
0735:                                    || poi
0736:                                            .getItemType()
0737:                                            .getItemTypeCode()
0738:                                            .equals(
0739:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE)
0740:                                    || poi
0741:                                            .getItemType()
0742:                                            .getItemTypeCode()
0743:                                            .equals(
0744:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi
0745:                                    .getItemType()
0746:                                    .getItemTypeCode()
0747:                                    .equals(
0748:                                            PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))
0749:                            && lineItemDisplaysOnPdf(poi)) {
0750:
0751:                        String description = (poi.getItemCatalogNumber() != null) ? poi
0752:                                .getItemCatalogNumber().trim()
0753:                                + " - "
0754:                                : "";
0755:                        description = description
0756:                                + ((poi.getItemDescription() != null) ? poi
0757:                                        .getItemDescription().trim() : "");
0758:                        if (StringUtils.isNotBlank(description)) {
0759:                            if (poi
0760:                                    .getItemType()
0761:                                    .getItemTypeCode()
0762:                                    .equals(
0763:                                            PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)
0764:                                    || poi
0765:                                            .getItemType()
0766:                                            .getItemTypeCode()
0767:                                            .equals(
0768:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)
0769:                                    || poi
0770:                                            .getItemType()
0771:                                            .getItemTypeCode()
0772:                                            .equals(
0773:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE)
0774:                                    || poi
0775:                                            .getItemType()
0776:                                            .getItemTypeCode()
0777:                                            .equals(
0778:                                                    PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)) {
0779:                                // If this is a full order discount or trade-in item, we add the item type description to the description.
0780:                                description = poi.getItemType()
0781:                                        .getItemTypeDescription()
0782:                                        + " - " + description;
0783:                            }
0784:                        }
0785:
0786:                        // Above the line item types items display the line number; other types don't.
0787:                        if (poi.getItemType().isItemTypeAboveTheLineIndicator()) {
0788:                            tableCell = new PdfPCell(new Paragraph(poi
0789:                                    .getItemLineNumber().toString(),
0790:                                    cour_10_normal));
0791:                        } else {
0792:                            tableCell = new PdfPCell(new Paragraph(" ",
0793:                                    cour_10_normal));
0794:                        }
0795:                        tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0796:                        itemsTable.addCell(tableCell);
0797:                        String quantity = (poi.getItemQuantity() != null) ? poi
0798:                                .getItemQuantity().toString() : " ";
0799:                        tableCell = new PdfPCell(new Paragraph(quantity,
0800:                                cour_10_normal));
0801:                        tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0802:                        itemsTable.addCell(tableCell);
0803:                        tableCell = new PdfPCell(new Paragraph(poi
0804:                                .getItemUnitOfMeasureCode(), cour_10_normal));
0805:                        tableCell.setHorizontalAlignment(Element.ALIGN_CENTER);
0806:                        itemsTable.addCell(tableCell);
0807:
0808:                        tableCell = new PdfPCell(new Paragraph(" "
0809:                                + description, cour_10_normal));
0810:                        tableCell.setHorizontalAlignment(Element.ALIGN_LEFT);
0811:                        itemsTable.addCell(tableCell);
0812:                        String unitPrice = poi.getItemUnitPrice().setScale(4,
0813:                                BigDecimal.ROUND_HALF_UP).toString();
0814:                        tableCell = new PdfPCell(new Paragraph(unitPrice + " ",
0815:                                cour_10_normal));
0816:                        tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0817:                        itemsTable.addCell(tableCell);
0818:                        tableCell = new PdfPCell(new Paragraph(numberFormat
0819:                                .format(poi.getExtendedPrice())
0820:                                + " ", cour_10_normal));
0821:                        tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0822:                        itemsTable.addCell(tableCell);
0823:
0824:                    }
0825:                }
0826:                // Blank line before totals
0827:                itemsTable.addCell(" ");
0828:                itemsTable.addCell(" ");
0829:                itemsTable.addCell(" ");
0830:                itemsTable.addCell(" ");
0831:                itemsTable.addCell(" ");
0832:                itemsTable.addCell(" ");
0833:                // Totals line; first 3 cols empty
0834:                itemsTable.addCell(" ");
0835:                itemsTable.addCell(" ");
0836:                itemsTable.addCell(" ");
0837:                tableCell = new PdfPCell(new Paragraph("Total order amount: ",
0838:                        ver_10_normal));
0839:                tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0840:                itemsTable.addCell(tableCell);
0841:                itemsTable.addCell(" ");
0842:                KualiDecimal totalDollarAmount = new KualiDecimal(
0843:                        BigDecimal.ZERO);
0844:                if (po instanceof  PurchaseOrderRetransmitDocument) {
0845:                    totalDollarAmount = ((PurchaseOrderRetransmitDocument) po)
0846:                            .getTotalDollarAmountForRetransmit();
0847:                } else {
0848:                    totalDollarAmount = po.getTotalDollarAmount();
0849:                }
0850:                tableCell = new PdfPCell(new Paragraph(numberFormat
0851:                        .format(totalDollarAmount)
0852:                        + " ", cour_10_normal));
0853:                tableCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0854:                itemsTable.addCell(tableCell);
0855:                // Blank line after totals
0856:                itemsTable.addCell(" ");
0857:                itemsTable.addCell(" ");
0858:                itemsTable.addCell(" ");
0859:                itemsTable.addCell(" ");
0860:                itemsTable.addCell(" ");
0861:                itemsTable.addCell(" ");
0862:
0863:                document.add(itemsTable);
0864:
0865:                // Contract language.
0866:                LOG.debug("createPdf() contract language started.");
0867:                document.add(new Paragraph(contractLanguage, ver_6_normal));
0868:                document.add(new Paragraph("\n", ver_6_normal));
0869:
0870:                // ***** Signatures table *****
0871:                LOG.debug("createPdf() signatures table started.");
0872:                float[] signaturesWidths = { 0.30f, 0.70f };
0873:                PdfPTable signaturesTable = new PdfPTable(signaturesWidths);
0874:                signaturesTable.setWidthPercentage(100);
0875:                signaturesTable.setHorizontalAlignment(Element.ALIGN_CENTER);
0876:                signaturesTable.setSplitLate(false);
0877:
0878:                // Director signature and "for more info" line; only on APOs
0879:                if (po.getPurchaseOrderAutomaticIndicator()) {
0880:                    // Empty cell.
0881:                    cell = new PdfPCell(new Paragraph(" ", cour_10_normal));
0882:                    cell.setBorderWidth(0);
0883:                    signaturesTable.addCell(cell);
0884:
0885:                    if (StringUtils.isBlank(po.getInstitutionContactName())
0886:                            || StringUtils.isBlank(po
0887:                                    .getInstitutionContactPhoneNumber())) {
0888:                        p = new Paragraph("For more information contact: "
0889:                                + po.getRequestorPersonName() + "  "
0890:                                + po.getRequestorPersonPhoneNumber(),
0891:                                cour_10_normal);
0892:                    } else {
0893:                        p = new Paragraph("For more information contact: "
0894:                                + po.getInstitutionContactName() + "  "
0895:                                + po.getInstitutionContactPhoneNumber(),
0896:                                cour_10_normal);
0897:                    }
0898:                    cell = new PdfPCell(p);
0899:                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0900:                    cell.setVerticalAlignment(Element.ALIGN_CENTER);
0901:                    cell.setBorderWidth(0);
0902:                    signaturesTable.addCell(cell);
0903:                    if (StringUtils.isNotBlank(directorSignatureImage)) {
0904:                        Image directorSignature = Image
0905:                                .getInstance(directorSignatureImage);
0906:                        directorSignature.scalePercent(30, 30);
0907:                        cell = new PdfPCell(directorSignature, false);
0908:                    } else {
0909:                        // if the director signature image is empty
0910:                        cell = new PdfPCell();
0911:                    }
0912:                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0913:                    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
0914:                    cell.setBorderWidth(0);
0915:                    signaturesTable.addCell(cell);
0916:
0917:                    // Empty cell.
0918:                    cell = new PdfPCell(new Paragraph(" ", cour_10_normal));
0919:                    cell.setBorderWidth(0);
0920:                    signaturesTable.addCell(cell);
0921:                }
0922:
0923:                // Director name and title; on every pdf.
0924:                p = new Paragraph();
0925:                LOG
0926:                        .debug("createPdf() directorName parameter: "
0927:                                + directorName);
0928:                if (po.getPurchaseOrderAutomaticIndicator()) { // The signature is on the pdf; use small font.
0929:                    p.add(new Chunk(directorName, ver_6_normal));
0930:                } else { // The signature isn't on the pdf; use larger font.
0931:                    p.add(new Chunk(directorName, ver_10_normal));
0932:                }
0933:                p.add(new Chunk("\n" + directorTitle, ver_4_normal));
0934:                cell = new PdfPCell(p);
0935:                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
0936:                cell.setVerticalAlignment(Element.ALIGN_TOP);
0937:                cell.setBorderWidth(0);
0938:                signaturesTable.addCell(cell);
0939:
0940:                // Contract manager signature, name and phone; only on non-APOs
0941:                if (!po.getPurchaseOrderAutomaticIndicator()) {
0942:                    if (StringUtils.isNotBlank(contractManagerSignatureImage)) {
0943:                        Image contractManagerSignature = Image
0944:                                .getInstance(contractManagerSignatureImage);
0945:                        contractManagerSignature.scalePercent(15, 15);
0946:                        cell = new PdfPCell(contractManagerSignature, false);
0947:                    } else {
0948:                        // an empty cell if the contract manager signature image is not available.
0949:                        cell = new PdfPCell();
0950:                    }
0951:                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0952:                    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
0953:                    cell.setBorderWidth(0);
0954:                    signaturesTable.addCell(cell);
0955:
0956:                    // Empty cell.
0957:                    cell = new PdfPCell(new Paragraph(" ", ver_10_normal));
0958:                    cell.setBorderWidth(0);
0959:                    signaturesTable.addCell(cell);
0960:
0961:                    cell = new PdfPCell(new Paragraph(po.getContractManager()
0962:                            .getContractManagerName()
0963:                            + "  "
0964:                            + po.getContractManager()
0965:                                    .getContractManagerPhoneNumber(),
0966:                            cour_10_normal));
0967:                    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
0968:                    cell.setVerticalAlignment(Element.ALIGN_TOP);
0969:                    cell.setBorderWidth(0);
0970:                    signaturesTable.addCell(cell);
0971:                } else { // Empty cell.
0972:                    cell = new PdfPCell(new Paragraph(" ", ver_10_normal));
0973:                    cell.setBorderWidth(0);
0974:                    signaturesTable.addCell(cell);
0975:                }
0976:                document.add(signaturesTable);
0977:
0978:                document.close();
0979:                LOG.debug("createPdf()pdf document closed.");
0980:            } // End of createPdf()
0981:
0982:            /**
0983:             * Determines whether the item should be displayed on the pdf.
0984:             * 
0985:             * @param poi  The PurchaseOrderItem to be determined whether it should be displayed on the pdf.
0986:             * @return     boolean true if it should be displayed on the pdf.
0987:             */
0988:            private boolean lineItemDisplaysOnPdf(PurchaseOrderItem poi) {
0989:                LOG.debug("lineItemDisplaysOnPdf() started");
0990:
0991:                // Shipping, freight, full order discount and trade in items.
0992:                if ((poi.getItemType() != null)
0993:                        && (poi
0994:                                .getItemType()
0995:                                .getItemTypeCode()
0996:                                .equals(
0997:                                        PurapConstants.ItemTypeCodes.ITEM_TYPE_SHIP_AND_HAND_CODE)
0998:                                || poi
0999:                                        .getItemType()
1000:                                        .getItemTypeCode()
1001:                                        .equals(
1002:                                                PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE)
1003:                                || poi
1004:                                        .getItemType()
1005:                                        .getItemTypeCode()
1006:                                        .equals(
1007:                                                PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE) || poi
1008:                                .getItemType()
1009:                                .getItemTypeCode()
1010:                                .equals(
1011:                                        PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE))) {
1012:
1013:                    // If the unit price is not null and either the unit price > 0 or the item type is full order discount or trade in,
1014:                    // we'll display this line item on pdf.
1015:                    if ((poi.getItemUnitPrice() != null)
1016:                            && ((poi.getItemUnitPrice().compareTo(
1017:                                    zero.bigDecimalValue()) == 1)
1018:                                    || (poi.getItemType().getItemTypeCode()
1019:                                            .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE)) || (poi
1020:                                    .getItemType().getItemTypeCode()
1021:                                    .equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE)))) {
1022:                        LOG.debug("lineItemDisplaysOnPdf() Item type is "
1023:                                + poi.getItemType().getItemTypeCode()
1024:                                + ". Unit price is " + poi.getItemUnitPrice()
1025:                                + ". Display on pdf.");
1026:                        return true;
1027:                    }
1028:                    LOG.debug("lineItemDisplaysOnPdf() Item type is "
1029:                            + poi.getItemType().getItemTypeCode()
1030:                            + ". Unit price is " + poi.getItemUnitPrice()
1031:                            + ". Don't display on pdf.");
1032:                    return false;
1033:                } else if ((poi.getItemType() != null)
1034:                        && poi.getItemType().isItemTypeAboveTheLineIndicator()) {
1035:                    if (poi.getItemQuantity() == null
1036:                            && poi.getItemUnitPrice() == null) {
1037:                        LOG
1038:                                .debug("lineItemDisplaysOnPdf() Item type is "
1039:                                        + poi.getItemType().getItemTypeCode()
1040:                                        + " OrderQuantity and unit price are both null. Display on pdf.");
1041:                        return true;
1042:                    }
1043:                    if ((poi.getItemType()
1044:                            .isAmountBasedGeneralLedgerIndicator() && ((poi
1045:                            .getItemUnitPrice() != null) && (poi
1046:                            .getItemUnitPrice().compareTo(
1047:                                    zero.bigDecimalValue()) >= 0)))
1048:                            || (((poi.getItemType()
1049:                                    .isQuantityBasedGeneralLedgerIndicator()) && (poi
1050:                                    .getItemQuantity().isGreaterThan(zero))) && (poi
1051:                                    .getItemUnitPrice() != null))) {
1052:                        LOG.debug("lineItemDisplaysOnPdf() Item type is "
1053:                                + poi.getItemType().getItemTypeCode()
1054:                                + " OrderQuantity is " + poi.getItemQuantity()
1055:                                + ". Unit price is " + poi.getItemUnitPrice()
1056:                                + ". Display on pdf.");
1057:                        return true;
1058:                    } else {
1059:                        LOG.debug("lineItemDisplaysOnPdf() Item type is "
1060:                                + poi.getItemType().getItemTypeCode()
1061:                                + " and item order quantity is "
1062:                                + poi.getItemQuantity()
1063:                                + " and item unit price is "
1064:                                + poi.getItemUnitPrice()
1065:                                + ". Don't display on pdf.");
1066:                    }
1067:                }
1068:                return false;
1069:            }
1070:
1071:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.