Source Code Cross Referenced for PurchaseOrderAction.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » purap » web » struts » action » 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.web.struts.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2006-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.web.struts.action;
0017:
0018:        import java.io.ByteArrayOutputStream;
0019:        import java.sql.Date;
0020:        import java.util.HashMap;
0021:        import java.util.List;
0022:        import java.util.Map;
0023:
0024:        import javax.servlet.ServletOutputStream;
0025:        import javax.servlet.http.HttpServletRequest;
0026:        import javax.servlet.http.HttpServletResponse;
0027:
0028:        import org.apache.commons.lang.StringUtils;
0029:        import org.apache.struts.action.ActionForm;
0030:        import org.apache.struts.action.ActionForward;
0031:        import org.apache.struts.action.ActionMapping;
0032:        import org.apache.struts.action.ActionMessage;
0033:        import org.apache.struts.action.ActionMessages;
0034:        import org.kuali.RicePropertyConstants;
0035:        import org.kuali.core.bo.Note;
0036:        import org.kuali.core.document.authorization.DocumentAuthorizer;
0037:        import org.kuali.core.exceptions.ValidationException;
0038:        import org.kuali.core.question.ConfirmationQuestion;
0039:        import org.kuali.core.service.BusinessObjectService;
0040:        import org.kuali.core.service.DataDictionaryService;
0041:        import org.kuali.core.service.DateTimeService;
0042:        import org.kuali.core.service.DocumentAuthorizationService;
0043:        import org.kuali.core.service.DocumentService;
0044:        import org.kuali.core.service.KualiConfigurationService;
0045:        import org.kuali.core.util.GlobalVariables;
0046:        import org.kuali.core.util.ObjectUtils;
0047:        import org.kuali.core.web.struts.form.BlankFormFile;
0048:        import org.kuali.core.web.struts.form.KualiDocumentFormBase;
0049:        import org.kuali.core.workflow.service.KualiWorkflowDocument;
0050:        import org.kuali.kfs.KFSConstants;
0051:        import org.kuali.kfs.context.SpringContext;
0052:        import org.kuali.module.purap.PurapAuthorizationConstants;
0053:        import org.kuali.module.purap.PurapConstants;
0054:        import org.kuali.module.purap.PurapKeyConstants;
0055:        import org.kuali.module.purap.PurapPropertyConstants;
0056:        import org.kuali.module.purap.PurapConstants.PODocumentsStrings;
0057:        import org.kuali.module.purap.PurapConstants.PurchaseOrderDocTypes;
0058:        import org.kuali.module.purap.PurapConstants.PurchaseOrderStatuses;
0059:        import org.kuali.module.purap.bo.PurchaseOrderItem;
0060:        import org.kuali.module.purap.bo.PurchaseOrderQuoteList;
0061:        import org.kuali.module.purap.bo.PurchaseOrderQuoteListVendor;
0062:        import org.kuali.module.purap.bo.PurchaseOrderVendorQuote;
0063:        import org.kuali.module.purap.bo.PurchaseOrderVendorStipulation;
0064:        import org.kuali.module.purap.document.PurchaseOrderDocument;
0065:        import org.kuali.module.purap.question.SingleConfirmationQuestion;
0066:        import org.kuali.module.purap.service.PurapService;
0067:        import org.kuali.module.purap.service.PurchaseOrderService;
0068:        import org.kuali.module.purap.web.struts.form.PurchaseOrderForm;
0069:        import org.kuali.module.purap.web.struts.form.PurchasingFormBase;
0070:        import org.kuali.module.vendor.VendorConstants;
0071:        import org.kuali.module.vendor.VendorConstants.AddressTypes;
0072:        import org.kuali.module.vendor.bo.VendorAddress;
0073:        import org.kuali.module.vendor.bo.VendorDetail;
0074:        import org.kuali.module.vendor.bo.VendorPhoneNumber;
0075:        import org.kuali.module.vendor.service.VendorService;
0076:
0077:        import edu.iu.uis.eden.exception.WorkflowException;
0078:
0079:        /**
0080:         * Struts Action for Purchase Order document.
0081:         */
0082:        public class PurchaseOrderAction extends PurchasingActionBase {
0083:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
0084:                    .getLogger(PurchaseOrderAction.class);
0085:
0086:            /**
0087:             * @see org.kuali.core.web.struts.action.KualiAction#refresh(org.apache.struts.action.ActionMapping,
0088:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
0089:             */
0090:            @Override
0091:            public ActionForward refresh(ActionMapping mapping,
0092:                    ActionForm form, HttpServletRequest request,
0093:                    HttpServletResponse response) throws Exception {
0094:
0095:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
0096:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
0097:                        .getDocument();
0098:                BusinessObjectService businessObjectService = SpringContext
0099:                        .getBean(BusinessObjectService.class);
0100:
0101:                // Handling lookups for alternate vendor for escrow payment that are only specific to Purchase Order.
0102:                if (request
0103:                        .getParameter("document.alternateVendorHeaderGeneratedIdentifier") != null
0104:                        && request
0105:                                .getParameter("document.alternateVendorDetailAssignedIdentifier") != null) {
0106:                    Integer alternateVendorDetailAssignedId = document
0107:                            .getAlternateVendorDetailAssignedIdentifier();
0108:                    Integer alternateVendorHeaderGeneratedId = document
0109:                            .getAlternateVendorHeaderGeneratedIdentifier();
0110:                    VendorDetail refreshVendorDetail = new VendorDetail();
0111:                    refreshVendorDetail
0112:                            .setVendorDetailAssignedIdentifier(alternateVendorDetailAssignedId);
0113:                    refreshVendorDetail
0114:                            .setVendorHeaderGeneratedIdentifier(alternateVendorHeaderGeneratedId);
0115:                    refreshVendorDetail = (VendorDetail) businessObjectService
0116:                            .retrieve(refreshVendorDetail);
0117:                    document.templateAlternateVendor(refreshVendorDetail);
0118:                }
0119:
0120:                // Handling lookups for quote vendor search that is specific to Purchase Order.
0121:                if (request
0122:                        .getParameter("document.purchaseOrderQuoteListIdentifier") != null) {
0123:                    // do a lookup and add all the vendors!
0124:                    Integer poQuoteListIdentifier = document
0125:                            .getPurchaseOrderQuoteListIdentifier();
0126:                    PurchaseOrderQuoteList poQuoteList = new PurchaseOrderQuoteList();
0127:                    poQuoteList
0128:                            .setPurchaseOrderQuoteListIdentifier(poQuoteListIdentifier);
0129:                    poQuoteList = (PurchaseOrderQuoteList) businessObjectService
0130:                            .retrieve(poQuoteList);
0131:                    for (PurchaseOrderQuoteListVendor poQuoteListVendor : poQuoteList
0132:                            .getQuoteListVendors()) {
0133:                        VendorDetail newVendor = poQuoteListVendor
0134:                                .getVendorDetail();
0135:                        PurchaseOrderVendorQuote newPOVendorQuote = new PurchaseOrderVendorQuote();
0136:                        newPOVendorQuote.setVendorName(newVendor
0137:                                .getVendorName());
0138:                        newPOVendorQuote
0139:                                .setVendorHeaderGeneratedIdentifier(newVendor
0140:                                        .getVendorHeaderGeneratedIdentifier());
0141:                        newPOVendorQuote
0142:                                .setVendorDetailAssignedIdentifier(newVendor
0143:                                        .getVendorDetailAssignedIdentifier());
0144:                        newPOVendorQuote.setDocumentNumber(document
0145:                                .getDocumentNumber());
0146:                        for (VendorAddress address : newVendor
0147:                                .getVendorAddresses()) {
0148:                            if (AddressTypes.PURCHASE_ORDER.equals(address
0149:                                    .getVendorAddressTypeCode())) {
0150:                                newPOVendorQuote.setVendorCityName(address
0151:                                        .getVendorCityName());
0152:                                newPOVendorQuote.setVendorCountryCode(address
0153:                                        .getVendorCountryCode());
0154:                                newPOVendorQuote.setVendorLine1Address(address
0155:                                        .getVendorLine1Address());
0156:                                newPOVendorQuote.setVendorLine2Address(address
0157:                                        .getVendorLine2Address());
0158:                                newPOVendorQuote.setVendorPostalCode(address
0159:                                        .getVendorZipCode());
0160:                                newPOVendorQuote.setVendorStateCode(address
0161:                                        .getVendorStateCode());
0162:                                break;
0163:                            }
0164:                        }
0165:
0166:                        String tmpPhoneNumber = null;
0167:                        for (VendorPhoneNumber phone : newVendor
0168:                                .getVendorPhoneNumbers()) {
0169:                            if (VendorConstants.PhoneTypes.PO.equals(phone
0170:                                    .getVendorPhoneTypeCode())) {
0171:                                newPOVendorQuote.setVendorPhoneNumber(phone
0172:                                        .getVendorPhoneNumber());
0173:                            }
0174:                            if (VendorConstants.PhoneTypes.FAX.equals(phone
0175:                                    .getVendorPhoneTypeCode())) {
0176:                                newPOVendorQuote.setVendorFaxNumber(phone
0177:                                        .getVendorPhoneNumber());
0178:                            }
0179:                            if (VendorConstants.PhoneTypes.PHONE.equals(phone
0180:                                    .getVendorPhoneTypeCode())) {
0181:                                tmpPhoneNumber = phone.getVendorPhoneNumber();
0182:                            }
0183:                        }
0184:                        if (StringUtils.isEmpty(newPOVendorQuote
0185:                                .getVendorPhoneNumber())
0186:                                && !StringUtils.isEmpty(tmpPhoneNumber)) {
0187:                            newPOVendorQuote
0188:                                    .setVendorPhoneNumber(tmpPhoneNumber);
0189:                        }
0190:                        document.getPurchaseOrderVendorQuotes().add(
0191:                                newPOVendorQuote);
0192:                        document.refreshNonUpdateableReferences();
0193:                    }
0194:                }
0195:
0196:                // Handling lookups for quote vendor search that is specific to Purchase Order.
0197:                if (request
0198:                        .getParameter("document.newQuoteVendorHeaderGeneratedIdentifier") != null
0199:                        && request
0200:                                .getParameter("document.newQuoteVendorDetailAssignedIdentifier") != null) {
0201:                    // retrieve this vendor from DB and add it to the end of the list
0202:                    VendorDetail newVendor = SpringContext
0203:                            .getBean(VendorService.class)
0204:                            .getVendorDetail(
0205:                                    document
0206:                                            .getNewQuoteVendorHeaderGeneratedIdentifier(),
0207:                                    document
0208:                                            .getNewQuoteVendorDetailAssignedIdentifier());
0209:                    PurchaseOrderVendorQuote newPOVendorQuote = new PurchaseOrderVendorQuote();
0210:                    newPOVendorQuote.setVendorName(newVendor.getVendorName());
0211:                    newPOVendorQuote
0212:                            .setVendorHeaderGeneratedIdentifier(newVendor
0213:                                    .getVendorHeaderGeneratedIdentifier());
0214:                    newPOVendorQuote
0215:                            .setVendorDetailAssignedIdentifier(newVendor
0216:                                    .getVendorDetailAssignedIdentifier());
0217:                    newPOVendorQuote.setDocumentNumber(document
0218:                            .getDocumentNumber());
0219:                    for (VendorAddress address : newVendor.getVendorAddresses()) {
0220:                        if (AddressTypes.PURCHASE_ORDER.equals(address
0221:                                .getVendorAddressTypeCode())) {
0222:                            newPOVendorQuote.setVendorCityName(address
0223:                                    .getVendorCityName());
0224:                            newPOVendorQuote.setVendorCountryCode(address
0225:                                    .getVendorCountryCode());
0226:                            newPOVendorQuote.setVendorLine1Address(address
0227:                                    .getVendorLine1Address());
0228:                            newPOVendorQuote.setVendorLine2Address(address
0229:                                    .getVendorLine2Address());
0230:                            newPOVendorQuote.setVendorPostalCode(address
0231:                                    .getVendorZipCode());
0232:                            newPOVendorQuote.setVendorStateCode(address
0233:                                    .getVendorStateCode());
0234:                            break;
0235:                        }
0236:                    }
0237:
0238:                    String tmpPhoneNumber = null;
0239:                    for (VendorPhoneNumber phone : newVendor
0240:                            .getVendorPhoneNumbers()) {
0241:                        if (VendorConstants.PhoneTypes.PO.equals(phone
0242:                                .getVendorPhoneTypeCode())) {
0243:                            newPOVendorQuote.setVendorPhoneNumber(phone
0244:                                    .getVendorPhoneNumber());
0245:                        }
0246:                        if (VendorConstants.PhoneTypes.FAX.equals(phone
0247:                                .getVendorPhoneTypeCode())) {
0248:                            newPOVendorQuote.setVendorFaxNumber(phone
0249:                                    .getVendorPhoneNumber());
0250:                        }
0251:                        if (VendorConstants.PhoneTypes.PHONE.equals(phone
0252:                                .getVendorPhoneTypeCode())) {
0253:                            tmpPhoneNumber = phone.getVendorPhoneNumber();
0254:                        }
0255:                    }
0256:                    if (StringUtils.isEmpty(newPOVendorQuote
0257:                            .getVendorPhoneNumber())
0258:                            && !StringUtils.isEmpty(tmpPhoneNumber)) {
0259:                        newPOVendorQuote.setVendorPhoneNumber(tmpPhoneNumber);
0260:                    }
0261:
0262:                    document.getPurchaseOrderVendorQuotes().add(
0263:                            newPOVendorQuote);
0264:                }
0265:
0266:                String newStipulation = request
0267:                        .getParameter(RicePropertyConstants.DOCUMENT
0268:                                + "."
0269:                                + PurapPropertyConstants.VENDOR_STIPULATION_DESCRIPTION);
0270:                if (StringUtils.isNotEmpty(newStipulation)) {
0271:                    poForm.getNewPurchaseOrderVendorStipulationLine()
0272:                            .setVendorStipulationDescription(newStipulation);
0273:                }
0274:
0275:                return super .refresh(mapping, form, request, response);
0276:            }
0277:
0278:            /**
0279:             * Inactivate an item from the purchase order document.
0280:             * 
0281:             * @param mapping An ActionMapping
0282:             * @param form An ActionForm
0283:             * @param request The HttpServletRequest
0284:             * @param response The HttpServletResponse
0285:             * @throws Exception
0286:             * @return An ActionForward
0287:             */
0288:            public ActionForward inactivateItem(ActionMapping mapping,
0289:                    ActionForm form, HttpServletRequest request,
0290:                    HttpServletResponse response) throws Exception {
0291:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
0292:
0293:                PurchaseOrderDocument purDocument = (PurchaseOrderDocument) purchasingForm
0294:                        .getDocument();
0295:                PurchaseOrderItem item = (PurchaseOrderItem) purDocument
0296:                        .getItem(getSelectedLine(request));
0297:                item.setItemActiveIndicator(false);
0298:
0299:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
0300:            }
0301:
0302:            /**
0303:             * For use with a specific set of methods of this class that create new purchase order-derived document types in response to
0304:             * user actions, including <code>closePo</code>, <code>reopenPo</code>, <code>paymentHoldPo</code>,
0305:             * <code>removeHoldPo</code>, <code>amendPo</code>, and <code>voidPo</code>. It employs the question framework to ask
0306:             * the user for a reponse before creating and routing the new document. The response should consist of a note detailing a
0307:             * reason, and either yes or no. This method can be better understood if it is noted that it will be gone through twice (via the
0308:             * question vframework); when each question is originally asked, and again when the yes/no response is processed, for
0309:             * confirmation.
0310:             * 
0311:             * @param mapping These are boiler-plate.
0312:             * @param form "
0313:             * @param request "
0314:             * @param response "
0315:             * @param questionType A string identifying the type of question being asked.
0316:             * @param confirmType A string identifying which type of question is being confirmed.
0317:             * @param documentType A string, the type of document to create
0318:             * @param notePrefix A string to appear before the note in the BO Notes tab
0319:             * @param messageType A string to appear on the PO once the question framework is done, describing the action taken
0320:             * @param operation A string, the verb to insert in the original question describing the action to be taken
0321:             * @return An ActionForward
0322:             * @throws Exception
0323:             */
0324:            private ActionForward askQuestionsAndPerformDocumentAction(
0325:                    ActionMapping mapping, ActionForm form,
0326:                    HttpServletRequest request, HttpServletResponse response,
0327:                    String questionType, String confirmType,
0328:                    String documentType, String notePrefix, String messageType,
0329:                    String operation) throws Exception {
0330:                LOG.debug("askQuestionsAndPerformDocumentAction started.");
0331:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
0332:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
0333:                        .getDocument();
0334:                Object question = request
0335:                        .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
0336:                String reason = request
0337:                        .getParameter(KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME);
0338:                String noteText = "";
0339:
0340:                try {
0341:                    KualiConfigurationService kualiConfiguration = SpringContext
0342:                            .getBean(KualiConfigurationService.class);
0343:
0344:                    // Start in logic for confirming the close.
0345:                    if (ObjectUtils.isNull(question)) {
0346:                        String key = kualiConfiguration
0347:                                .getPropertyString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_DOCUMENT);
0348:                        String message = StringUtils.replace(key, "{0}",
0349:                                operation);
0350:
0351:                        // Ask question if not already asked.
0352:                        return this .performQuestionWithInput(mapping, form,
0353:                                request, response, questionType, message,
0354:                                KFSConstants.CONFIRMATION_QUESTION,
0355:                                questionType, "");
0356:                    } else {
0357:                        Object buttonClicked = request
0358:                                .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
0359:                        if (question.equals(questionType)
0360:                                && buttonClicked
0361:                                        .equals(ConfirmationQuestion.NO)) {
0362:
0363:                            // If 'No' is the button clicked, just reload the doc
0364:                            return returnToPreviousPage(mapping,
0365:                                    kualiDocumentFormBase);
0366:                        } else if (question.equals(confirmType)
0367:                                && buttonClicked
0368:                                        .equals(SingleConfirmationQuestion.OK)) {
0369:
0370:                            // This is the case when the user clicks on "OK" in the end.
0371:                            // After we inform the user that the close has been rerouted, we'll redirect to the portal page.
0372:                            return mapping
0373:                                    .findForward(KFSConstants.MAPPING_PORTAL);
0374:                        } else {
0375:                            // Have to check length on value entered.
0376:                            String introNoteMessage = notePrefix
0377:                                    + KFSConstants.BLANK_SPACE;
0378:
0379:                            // Build out full message.
0380:                            noteText = introNoteMessage + reason;
0381:                            int noteTextLength = noteText.length();
0382:
0383:                            // Get note text max length from DD.
0384:                            int noteTextMaxLength = SpringContext
0385:                                    .getBean(DataDictionaryService.class)
0386:                                    .getAttributeMaxLength(
0387:                                            Note.class,
0388:                                            KFSConstants.NOTE_TEXT_PROPERTY_NAME)
0389:                                    .intValue();
0390:
0391:                            if (StringUtils.isBlank(reason)
0392:                                    || (noteTextLength > noteTextMaxLength)) {
0393:                                // Figure out exact number of characters that the user can enter.
0394:                                int reasonLimit = noteTextMaxLength
0395:                                        - noteTextLength;
0396:
0397:                                if (ObjectUtils.isNull(reason)) {
0398:                                    // Prevent a NPE by setting the reason to a blank string.
0399:                                    reason = "";
0400:                                }
0401:
0402:                                return this 
0403:                                        .performQuestionWithInputAgainBecauseOfErrors(
0404:                                                mapping,
0405:                                                form,
0406:                                                request,
0407:                                                response,
0408:                                                questionType,
0409:                                                kualiConfiguration
0410:                                                        .getPropertyString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_DOCUMENT),
0411:                                                KFSConstants.CONFIRMATION_QUESTION,
0412:                                                questionType,
0413:                                                "",
0414:                                                reason,
0415:                                                PurapKeyConstants.ERROR_PURCHASE_ORDER_REASON_REQUIRED,
0416:                                                KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME,
0417:                                                new Integer(reasonLimit)
0418:                                                        .toString());
0419:                            }
0420:                        }
0421:                    }
0422:                    // below used as placeholder to allow code to specify actionForward to return if not a 'success question'
0423:                    ActionForward returnActionForward = null;
0424:                    if (!po.isPendingActionIndicator()) {
0425:                        /*
0426:                         * Below if-else code block calls PurchaseOrderService methods that will throw ValidationException objects if errors
0427:                         * occur during any process in the attempt to perform its actions. Assume, if these return successfully, that the
0428:                         * PurchaseOrderDocument object returned from each is the newly created document and that all actions in the method
0429:                         * were run correctly. NOTE: IF BELOW IF-ELSE IS EDITED THE NEW METHODS CALLED MUST THROW ValidationException OBJECT
0430:                         * IF AN ERROR IS ADDED TO THE GlobalVariables
0431:                         */
0432:                        String newStatus = null;
0433:                        if (documentType
0434:                                .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT)) {
0435:                            newStatus = PurchaseOrderStatuses.AMENDMENT;
0436:                            po = SpringContext.getBean(
0437:                                    PurchaseOrderService.class)
0438:                                    .createAndSavePotentialChangeDocument(
0439:                                            kualiDocumentFormBase.getDocument()
0440:                                                    .getDocumentNumber(),
0441:                                            documentType, newStatus);
0442:                            returnActionForward = mapping
0443:                                    .findForward(KFSConstants.MAPPING_BASIC);
0444:                        } else {
0445:                            if (documentType
0446:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT)) {
0447:                                newStatus = PurchaseOrderStatuses.PENDING_CLOSE;
0448:                            } else if (documentType
0449:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT)) {
0450:                                newStatus = PurchaseOrderStatuses.PENDING_REOPEN;
0451:                            } else if (documentType
0452:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
0453:                                newStatus = PurchaseOrderStatuses.PENDING_VOID;
0454:                            } else if (documentType
0455:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT)) {
0456:                                newStatus = PurchaseOrderStatuses.PENDING_PAYMENT_HOLD;
0457:                            } else if (documentType
0458:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT)) {
0459:                                newStatus = PurchaseOrderStatuses.PENDING_REOPEN;
0460:                            } else if (documentType
0461:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT)) {
0462:                                newStatus = PurchaseOrderStatuses.PENDING_REMOVE_HOLD;
0463:                            } else if (documentType
0464:                                    .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT)) {
0465:                                newStatus = PurchaseOrderStatuses.PENDING_RETRANSMIT;
0466:                            }
0467:                            po = SpringContext
0468:                                    .getBean(PurchaseOrderService.class)
0469:                                    .createAndRoutePotentialChangeDocument(
0470:                                            kualiDocumentFormBase.getDocument()
0471:                                                    .getDocumentNumber(),
0472:                                            documentType,
0473:                                            kualiDocumentFormBase
0474:                                                    .getAnnotation(),
0475:                                            combineAdHocRecipients(kualiDocumentFormBase),
0476:                                            newStatus);
0477:                        }
0478:                        if (!GlobalVariables.getErrorMap().isEmpty()) {
0479:                            throw new ValidationException(
0480:                                    "errors occurred during new PO creation");
0481:                        }
0482:
0483:                        String previousDocumentId = kualiDocumentFormBase
0484:                                .getDocId();
0485:                        // assume at this point document was created properly and 'po' variable is new PurchaseOrderDocument created
0486:                        kualiDocumentFormBase.setDocument(po);
0487:                        kualiDocumentFormBase.setDocId(po.getDocumentNumber());
0488:                        kualiDocumentFormBase.setDocTypeName(po
0489:                                .getDocumentHeader().getWorkflowDocument()
0490:                                .getDocumentType());
0491:
0492:                        Note newNote = new Note();
0493:                        if (documentType
0494:                                .equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT)) {
0495:                            noteText = noteText + " (Previous Document Id is "
0496:                                    + previousDocumentId + ")";
0497:                        }
0498:                        newNote.setNoteText(noteText);
0499:                        newNote
0500:                                .setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE
0501:                                        .getCode());
0502:                        kualiDocumentFormBase.setNewNote(newNote);
0503:                        // see KULPURAP-1984 for an explanation of why this is required and another way to do it.
0504:                        kualiDocumentFormBase
0505:                                .setAttachmentFile(new BlankFormFile());
0506:
0507:                        insertBONote(mapping, kualiDocumentFormBase, request,
0508:                                response);
0509:                        if (StringUtils.isNotEmpty(messageType)) {
0510:                            GlobalVariables.getMessageList().add(messageType);
0511:                        }
0512:                    }
0513:                    if (ObjectUtils.isNotNull(returnActionForward)) {
0514:                        addExtraButtons(kualiDocumentFormBase);
0515:
0516:                        return returnActionForward;
0517:                    } else {
0518:
0519:                        return this 
0520:                                .performQuestionWithoutInput(
0521:                                        mapping,
0522:                                        form,
0523:                                        request,
0524:                                        response,
0525:                                        confirmType,
0526:                                        kualiConfiguration
0527:                                                .getPropertyString(messageType),
0528:                                        PODocumentsStrings.SINGLE_CONFIRMATION_QUESTION,
0529:                                        questionType, "");
0530:                    }
0531:                } catch (ValidationException ve) {
0532:                    addExtraButtons(kualiDocumentFormBase);
0533:                    throw ve;
0534:                }
0535:            }
0536:
0537:            /**
0538:             * Invoked when the user pressed on the Close Order button on a Purchase Order page to Close the PO. It will
0539:             * display the question page to the user to ask whether the user really wants to close the PO and ask the user to enter a reason
0540:             * in the text area. If the user has entered the reason, it will invoke a service method to do the processing for closing a PO,
0541:             * then display a Single Confirmation page to inform the user that the PO Close Document has been routed.
0542:             * 
0543:             * @param mapping An ActionMapping
0544:             * @param form An ActionForm
0545:             * @param request The HttpServletRequest
0546:             * @param response The HttpServletResponse
0547:             * @throws Exception
0548:             * @return An ActionForward
0549:             */
0550:            public ActionForward closePo(ActionMapping mapping,
0551:                    ActionForm form, HttpServletRequest request,
0552:                    HttpServletResponse response) throws Exception {
0553:                LOG.debug("ClosePO started.");
0554:                String operation = "Close ";
0555:
0556:                return askQuestionsAndPerformDocumentAction(
0557:                        mapping,
0558:                        form,
0559:                        request,
0560:                        response,
0561:                        PODocumentsStrings.CLOSE_QUESTION,
0562:                        PODocumentsStrings.CLOSE_CONFIRM,
0563:                        PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT,
0564:                        PODocumentsStrings.CLOSE_NOTE_PREFIX,
0565:                        PurapKeyConstants.PURCHASE_ORDER_MESSAGE_CLOSE_DOCUMENT,
0566:                        operation);
0567:            }
0568:
0569:            /**
0570:             * Is invoked when the user pressed on the Payment Hold button on a Purchase Order page to put the PO on hold. It
0571:             * will display the question page to the user to ask whether the user really wants to put the PO on hold and ask the user to
0572:             * enter a reason in the text area. If the user has entered the reason, it will invoke a service method to do the processing for
0573:             * putting a PO on hold, then display a Single Confirmation page to inform the user that the PO Payment Hold Document has been
0574:             * routed.
0575:             * 
0576:             * @param mapping An ActionMapping
0577:             * @param form An ActionForm
0578:             * @param request The HttpServletRequest
0579:             * @param response The HttpServletResponse
0580:             * @throws Exception
0581:             * @return An ActionForward
0582:             */
0583:            public ActionForward paymentHoldPo(ActionMapping mapping,
0584:                    ActionForm form, HttpServletRequest request,
0585:                    HttpServletResponse response) throws Exception {
0586:                LOG.debug("PaymentHoldPO started.");
0587:                String operation = "Hold Payment ";
0588:
0589:                return askQuestionsAndPerformDocumentAction(
0590:                        mapping,
0591:                        form,
0592:                        request,
0593:                        response,
0594:                        PODocumentsStrings.PAYMENT_HOLD_QUESTION,
0595:                        PODocumentsStrings.PAYMENT_HOLD_CONFIRM,
0596:                        PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT,
0597:                        PODocumentsStrings.PAYMENT_HOLD_NOTE_PREFIX,
0598:                        PurapKeyConstants.PURCHASE_ORDER_MESSAGE_PAYMENT_HOLD,
0599:                        operation);
0600:            }
0601:
0602:            /**
0603:             * Is invoked when the user pressed on the Remove Hold button on a Payment Hold PO page to remove the PO from hold.
0604:             * It will display the question page to the user to ask whether the user really wants to remove the PO from hold and ask the
0605:             * user to enter a reason in the text area. If the user has entered the reason, it will invoke a service method to do the
0606:             * processing for removing a PO from hold, then display a Single Confirmation page to inform the user that the PO Remove Hold
0607:             * Document has been routed.
0608:             * 
0609:             * @param mapping An ActionMapping
0610:             * @param form An ActionForm
0611:             * @param request The HttpServletRequest
0612:             * @param response The HttpServletResponse
0613:             * @throws Exception
0614:             * @return An ActionForward
0615:             */
0616:            public ActionForward removeHoldPo(ActionMapping mapping,
0617:                    ActionForm form, HttpServletRequest request,
0618:                    HttpServletResponse response) throws Exception {
0619:                LOG.debug("RemoveHoldPO started.");
0620:                String operation = "Remove Payment Hold ";
0621:                ActionForward forward = askQuestionsAndPerformDocumentAction(
0622:                        mapping,
0623:                        form,
0624:                        request,
0625:                        response,
0626:                        PODocumentsStrings.REMOVE_HOLD_QUESTION,
0627:                        PODocumentsStrings.REMOVE_HOLD_CONFIRM,
0628:                        PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT,
0629:                        PODocumentsStrings.REMOVE_HOLD_NOTE_PREFIX,
0630:                        PurapKeyConstants.PURCHASE_ORDER_MESSAGE_REMOVE_HOLD,
0631:                        operation);
0632:
0633:                // Also need to send an FYI to the AP workgroup.
0634:                // KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
0635:                // PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument();
0636:                // WorkgroupVO workgroupVO =
0637:                // SpringContext.getBean(WorkflowGroupService.class).getWorkgroupByGroupName(PurapConstants.Workgroups.WORKGROUP_ACCOUNTS_PAYABLE);
0638:                // SpringContext.getBean(PurchaseOrderService.class).sendFYItoWorkgroup(po, kualiDocumentFormBase.getAnnotation(),
0639:                // workgroupVO.getWorkgroupId() );
0640:
0641:                return forward;
0642:            }
0643:
0644:            /**
0645:             * Is invoked when the user pressed on the Open Order button on a Purchase Order page that has status "Close" to
0646:             * reopen the PO. It will display the question page to the user to ask whether the user really wants to reopen the PO and ask
0647:             * the user to enter a reason in the text area. If the user has entered the reason, it will invoke the a service method to do
0648:             * the processing for reopening a PO, then display a Single Confirmation page to inform the user that the
0649:             * <code>PurchaseOrderReopenDocument</code> has been routed.
0650:             * 
0651:             * @param mapping An ActionMapping
0652:             * @param form An ActionForm
0653:             * @param request The HttpServletRequest
0654:             * @param response The HttpServletResponse
0655:             * @throws Exception
0656:             * @return An ActionForward
0657:             * @see org.kuali.module.purap.document.PurchaseOrderReopenDocument
0658:             */
0659:            public ActionForward reopenPo(ActionMapping mapping,
0660:                    ActionForm form, HttpServletRequest request,
0661:                    HttpServletResponse response) throws Exception {
0662:                LOG.debug("Reopen PO started");
0663:                String operation = "Reopen ";
0664:
0665:                return askQuestionsAndPerformDocumentAction(
0666:                        mapping,
0667:                        form,
0668:                        request,
0669:                        response,
0670:                        PODocumentsStrings.REOPEN_PO_QUESTION,
0671:                        PODocumentsStrings.CONFIRM_REOPEN_QUESTION,
0672:                        PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT,
0673:                        PODocumentsStrings.REOPEN_NOTE_PREFIX,
0674:                        PurapKeyConstants.PURCHASE_ORDER_MESSAGE_REOPEN_DOCUMENT,
0675:                        operation);
0676:            }
0677:
0678:            /**
0679:             * Is invoked when the user pressed on the Amend button on a Purchase Order page to amend the PO. It will display
0680:             * the question page to the user to ask whether the user really wants to amend the PO and ask the user to enter a reason in the
0681:             * text area. If the user has entered the reason, it will invoke a service method to do the processing for amending the PO, then
0682:             * display a Single Confirmation page to inform the user that the <code>PurchaseOrderAmendmentDocument</code> has been routed.
0683:             * 
0684:             * @param mapping An ActionMapping
0685:             * @param form An ActionForm
0686:             * @param request The HttpServletRequest
0687:             * @param response The HttpServletResponse
0688:             * @throws Exception
0689:             * @return An ActionForward
0690:             * @see org.kuali.module.purap.document.PurchaseOrderAmendmentDocument
0691:             */
0692:            public ActionForward amendPo(ActionMapping mapping,
0693:                    ActionForm form, HttpServletRequest request,
0694:                    HttpServletResponse response) throws Exception {
0695:                LOG.debug("Amend PO started");
0696:                String operation = "Amend ";
0697:
0698:                return askQuestionsAndPerformDocumentAction(
0699:                        mapping,
0700:                        form,
0701:                        request,
0702:                        response,
0703:                        PODocumentsStrings.AMENDMENT_PO_QUESTION,
0704:                        PODocumentsStrings.CONFIRM_AMENDMENT_QUESTION,
0705:                        PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT,
0706:                        PODocumentsStrings.AMENDMENT_NOTE_PREFIX, null,
0707:                        operation);
0708:            }
0709:
0710:            /**
0711:             * Is invoked when the user pressed on the Void button on a Purchase Order page to void the PO. It will display the
0712:             * question page to the user to ask whether the user really wants to void the PO and ask the user to enter a reason in the text
0713:             * area. If the user has entered the reason, it will invoke a service method to do the processing for voiding the PO, then
0714:             * display a Single Confirmation page to inform the user that the <code>PurchaseOrderVoidDocument</code> has been routed.
0715:             * 
0716:             * @param mapping An ActionMapping
0717:             * @param form An ActionForm
0718:             * @param request The HttpServletRequest
0719:             * @param response The HttpServletResponse
0720:             * @throws Exception
0721:             * @return An ActionForward
0722:             * @see org.kuali.module.purap.document.PurchaseOrderVoidDocument
0723:             */
0724:            public ActionForward voidPo(ActionMapping mapping, ActionForm form,
0725:                    HttpServletRequest request, HttpServletResponse response)
0726:                    throws Exception {
0727:                LOG.debug("Void PO started");
0728:                String operation = "Void ";
0729:
0730:                return askQuestionsAndPerformDocumentAction(mapping, form,
0731:                        request, response, PODocumentsStrings.VOID_QUESTION,
0732:                        PODocumentsStrings.VOID_CONFIRM,
0733:                        PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT,
0734:                        PODocumentsStrings.VOID_NOTE_PREFIX,
0735:                        PurapKeyConstants.PURCHASE_ORDER_MESSAGE_VOID_DOCUMENT,
0736:                        operation);
0737:            }
0738:
0739:            /**
0740:             * This is a utility method used to prepare to and to return to a previous page, making sure that the buttons will be restored
0741:             * in the process.
0742:             * 
0743:             * @param kualiDocumentFormBase The Form, considered as a KualiDocumentFormBase, as it typically is here.
0744:             * @return An actionForward mapping back to the original page.
0745:             */
0746:            protected ActionForward returnToPreviousPage(ActionMapping mapping,
0747:                    KualiDocumentFormBase kualiDocumentFormBase) {
0748:                addExtraButtons(kualiDocumentFormBase);
0749:
0750:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
0751:            }
0752:
0753:            /**
0754:             * Add the buttons to the form that need to be present besides the default buttons.
0755:             * 
0756:             * @param kualiDocumentFormBase A KualiDocumentFormBase that must be a PurchaseOrderForm
0757:             */
0758:            private void addExtraButtons(
0759:                    KualiDocumentFormBase kualiDocumentFormBase) {
0760:                ((PurchaseOrderForm) kualiDocumentFormBase).addButtons();
0761:            }
0762:
0763:            /**
0764:             * @see org.kuali.module.purap.web.struts.action.PurchasingAccountsPayableActionBase#refreshAccountSummary(org.apache.struts.action.ActionMapping,
0765:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
0766:             */
0767:            @Override
0768:            public ActionForward refreshAccountSummary(ActionMapping mapping,
0769:                    ActionForm form, HttpServletRequest request,
0770:                    HttpServletResponse response) throws Exception {
0771:                ActionForward forward = super .refreshAccountSummary(mapping,
0772:                        form, request, response);
0773:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
0774:                addExtraButtons(kualiDocumentFormBase);
0775:
0776:                return forward;
0777:            }
0778:
0779:            /**
0780:             * Is executed when the user clicks on the "print" button on a Purchase Order Print Document page. On a non
0781:             * javascript enabled browser, it will display a page with 2 buttons. One is to display the PDF, the other is to view the PO
0782:             * tabbed page where the PO document statuses, buttons, etc have already been updated (the updates of those occurred while the
0783:             * <code>performPurchaseOrderFirstTransmitViaPrinting</code> method is invoked. On a javascript enabled browser, it will
0784:             * display both the PO tabbed page containing the updated PO document info and the pdf on the next window/tab of the browser.
0785:             * 
0786:             * @param mapping An ActionMapping
0787:             * @param form An ActionForm
0788:             * @param request The HttpServletRequest
0789:             * @param response The HttpServletResponse
0790:             * @throws Exception
0791:             * @return An ActionForward
0792:             */
0793:            public ActionForward firstTransmitPrintPo(ActionMapping mapping,
0794:                    ActionForm form, HttpServletRequest request,
0795:                    HttpServletResponse response) throws Exception {
0796:                String poDocId = request.getParameter("docId");
0797:                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
0798:                try {
0799:                    SpringContext.getBean(PurchaseOrderService.class)
0800:                            .performPurchaseOrderFirstTransmitViaPrinting(
0801:                                    poDocId, baosPDF);
0802:                } finally {
0803:                    if (baosPDF != null) {
0804:                        baosPDF.reset();
0805:                    }
0806:                }
0807:                String basePath = getBasePath(request);
0808:                String docId = ((PurchaseOrderForm) form).getDocId();
0809:                String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
0810:                String methodToCallDocHandler = "docHandler";
0811:                String printPOPDFUrl = getUrlForPrintPO(basePath, docId,
0812:                        methodToCallPrintPurchaseOrderPDF);
0813:                String displayPOTabbedPageUrl = getUrlForPrintPO(basePath,
0814:                        docId, methodToCallDocHandler);
0815:                request.setAttribute("printPOPDFUrl", printPOPDFUrl);
0816:                request.setAttribute("displayPOTabbedPageUrl",
0817:                        displayPOTabbedPageUrl);
0818:                String label = SpringContext.getBean(
0819:                        DataDictionaryService.class).getDocumentLabelByClass(
0820:                        PurchaseOrderDocument.class);
0821:                request.setAttribute("purchaseOrderLabel", label);
0822:
0823:                return mapping.findForward("printPurchaseOrderPDF");
0824:            }
0825:
0826:            /**
0827:             * Creates a URL to be used in printing the purchase order.
0828:             * 
0829:             * @param basePath String: The base path of the current URL
0830:             * @param docId String: The document ID of the document to be printed
0831:             * @param methodToCall String: The name of the method that will be invoked to do this particular print
0832:             * @return The URL
0833:             */
0834:            private String getUrlForPrintPO(String basePath, String docId,
0835:                    String methodToCall) {
0836:                StringBuffer result = new StringBuffer(basePath);
0837:                result.append("/purapPurchaseOrder.do?methodToCall=");
0838:                result.append(methodToCall);
0839:                result.append("&docId=");
0840:                result.append(docId);
0841:                result.append("&command=displayDocSearchView");
0842:
0843:                return result.toString();
0844:            }
0845:
0846:            /**
0847:             * Prints the PDF only, as opposed to <code>firstTransmitPrintPo</code>, which calls this method (indirectly) to print the
0848:             * PDF, and calls the doc handler to display the PO tabbed page.
0849:             * 
0850:             * @param mapping An ActionMapping
0851:             * @param form An ActionForm
0852:             * @param request The HttpServletRequest
0853:             * @param response The HttpServletResponse
0854:             * @throws Exception
0855:             * @return An ActionForward
0856:             */
0857:            public ActionForward printPurchaseOrderPDFOnly(
0858:                    ActionMapping mapping, ActionForm form,
0859:                    HttpServletRequest request, HttpServletResponse response)
0860:                    throws Exception {
0861:                String poDocId = request.getParameter("docId");
0862:                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
0863:                try {
0864:                    // will throw validation exception if errors occur
0865:                    SpringContext.getBean(PurchaseOrderService.class)
0866:                            .performPrintPurchaseOrderPDFOnly(poDocId, baosPDF);
0867:
0868:                    response.setHeader("Cache-Control", "max-age=30");
0869:                    response.setContentType("application/pdf");
0870:                    StringBuffer sbContentDispValue = new StringBuffer();
0871:                    String useJavascript = request
0872:                            .getParameter("useJavascript");
0873:                    if (useJavascript == null
0874:                            || useJavascript.equalsIgnoreCase("false")) {
0875:                        sbContentDispValue.append("attachment");
0876:                    } else {
0877:                        sbContentDispValue.append("inline");
0878:                    }
0879:                    StringBuffer sbFilename = new StringBuffer();
0880:                    sbFilename.append("PURAP_PO_");
0881:                    sbFilename.append(poDocId);
0882:                    sbFilename.append("_");
0883:                    sbFilename.append(System.currentTimeMillis());
0884:                    sbFilename.append(".pdf");
0885:                    sbContentDispValue.append("; filename=");
0886:                    sbContentDispValue.append(sbFilename);
0887:
0888:                    response.setHeader("Content-disposition",
0889:                            sbContentDispValue.toString());
0890:
0891:                    response.setContentLength(baosPDF.size());
0892:
0893:                    ServletOutputStream sos;
0894:
0895:                    sos = response.getOutputStream();
0896:
0897:                    baosPDF.writeTo(sos);
0898:
0899:                    sos.flush();
0900:
0901:                } finally {
0902:                    if (baosPDF != null) {
0903:                        baosPDF.reset();
0904:                    }
0905:                }
0906:
0907:                return null;
0908:            }
0909:
0910:            /**
0911:             * Print a particular selected PO Quote as a PDF.
0912:             * 
0913:             * @param mapping An ActionMapping
0914:             * @param form An ActionForm -- The PO Quote must be selected here.
0915:             * @param request The HttpServletRequest
0916:             * @param response The HttpServletResponse
0917:             * @throws Exception
0918:             * @return An ActionForward
0919:             */
0920:            public ActionForward printPoQuote(ActionMapping mapping,
0921:                    ActionForm form, HttpServletRequest request,
0922:                    HttpServletResponse response) throws Exception {
0923:                // String poDocId = request.getParameter("docId");
0924:                // PurchaseOrderDocument po = (PurchaseOrderDocument)
0925:                // SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(poDocId);
0926:                // Integer poSelectedVendorId = new Integer(request.getParameter("quoteVendorId"));
0927:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
0928:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
0929:                        .getDocument();
0930:                PurchaseOrderVendorQuote poVendorQuote = po
0931:                        .getPurchaseOrderVendorQuotes().get(
0932:                                getSelectedLine(request));
0933:                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
0934:                poVendorQuote.setTransmitPrintDisplayed(false);
0935:                try {
0936:                    StringBuffer sbFilename = new StringBuffer();
0937:                    sbFilename.append("PURAP_PO_QUOTE_");
0938:                    sbFilename.append(po.getPurapDocumentIdentifier());
0939:                    sbFilename.append("_");
0940:                    sbFilename.append(System.currentTimeMillis());
0941:                    sbFilename.append(".pdf");
0942:
0943:                    boolean success = SpringContext.getBean(
0944:                            PurchaseOrderService.class)
0945:                            .printPurchaseOrderQuotePDF(po, poVendorQuote,
0946:                                    baosPDF);
0947:
0948:                    if (!success) {
0949:                        poVendorQuote.setTransmitPrintDisplayed(true);
0950:                        if (baosPDF != null) {
0951:                            baosPDF.reset();
0952:                        }
0953:                        return mapping.findForward(KFSConstants.MAPPING_BASIC);
0954:                    }
0955:                    response.setHeader("Cache-Control", "max-age=30");
0956:                    response.setContentType("application/pdf");
0957:                    StringBuffer sbContentDispValue = new StringBuffer();
0958:                    // sbContentDispValue.append("inline");
0959:                    sbContentDispValue.append("attachment");
0960:                    sbContentDispValue.append("; filename=");
0961:                    sbContentDispValue.append(sbFilename);
0962:
0963:                    response.setHeader("Content-disposition",
0964:                            sbContentDispValue.toString());
0965:
0966:                    response.setContentLength(baosPDF.size());
0967:
0968:                    ServletOutputStream sos;
0969:
0970:                    sos = response.getOutputStream();
0971:
0972:                    baosPDF.writeTo(sos);
0973:
0974:                    sos.flush();
0975:
0976:                } finally {
0977:                    if (baosPDF != null) {
0978:                        baosPDF.reset();
0979:                    }
0980:                }
0981:
0982:                return null;
0983:            }
0984:
0985:            /**
0986:             * Print the list of PO Quote requests.
0987:             * 
0988:             * @param mapping An ActionMapping
0989:             * @param form An ActionForm
0990:             * @param request The HttpServletRequest
0991:             * @param response The HttpServletResponse
0992:             * @throws Exception
0993:             * @return An ActionForward
0994:             */
0995:            public ActionForward printPoQuoteList(ActionMapping mapping,
0996:                    ActionForm form, HttpServletRequest request,
0997:                    HttpServletResponse response) throws Exception {
0998:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
0999:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1000:                        .getDocument();
1001:                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
1002:                try {
1003:                    StringBuffer sbFilename = new StringBuffer();
1004:                    sbFilename.append("PURAP_PO_QUOTE_LIST_");
1005:                    sbFilename.append(po.getPurapDocumentIdentifier());
1006:                    sbFilename.append("_");
1007:                    sbFilename.append(System.currentTimeMillis());
1008:                    sbFilename.append(".pdf");
1009:
1010:                    boolean success = SpringContext
1011:                            .getBean(PurchaseOrderService.class)
1012:                            .printPurchaseOrderQuoteRequestsListPDF(po, baosPDF);
1013:
1014:                    if (!success) {
1015:                        if (baosPDF != null) {
1016:                            baosPDF.reset();
1017:                        }
1018:                        return mapping.findForward(KFSConstants.MAPPING_PORTAL);
1019:                    }
1020:                    response.setHeader("Cache-Control", "max-age=30");
1021:                    response.setContentType("application/pdf");
1022:                    StringBuffer sbContentDispValue = new StringBuffer();
1023:                    // sbContentDispValue.append("inline");
1024:                    sbContentDispValue.append("attachment");
1025:                    sbContentDispValue.append("; filename=");
1026:                    sbContentDispValue.append(sbFilename);
1027:
1028:                    response.setHeader("Content-disposition",
1029:                            sbContentDispValue.toString());
1030:
1031:                    response.setContentLength(baosPDF.size());
1032:
1033:                    ServletOutputStream sos;
1034:
1035:                    sos = response.getOutputStream();
1036:
1037:                    baosPDF.writeTo(sos);
1038:
1039:                    sos.flush();
1040:
1041:                } finally {
1042:                    if (baosPDF != null) {
1043:                        baosPDF.reset();
1044:                    }
1045:                }
1046:
1047:                return null;
1048:            }
1049:
1050:            /**
1051:             * Initiates transmission of a PO Quote request.
1052:             * 
1053:             * @param mapping An ActionMapping
1054:             * @param form An ActionForm
1055:             * @param request The HttpServletRequest
1056:             * @param response The HttpServletResponse
1057:             * @throws Exception
1058:             * @return An ActionForward
1059:             */
1060:            public ActionForward transmitPurchaseOrderQuote(
1061:                    ActionMapping mapping, ActionForm form,
1062:                    HttpServletRequest request, HttpServletResponse response)
1063:                    throws Exception {
1064:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1065:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1066:                        .getDocument();
1067:                PurchaseOrderVendorQuote vendorQuote = (PurchaseOrderVendorQuote) po
1068:                        .getPurchaseOrderVendorQuotes().get(
1069:                                getSelectedLine(request));
1070:                if (PurapConstants.QuoteTransmitTypes.PRINT.equals(vendorQuote
1071:                        .getPurchaseOrderQuoteTransmitTypeCode())) {
1072:                    vendorQuote
1073:                            .setPurchaseOrderQuoteTransmitDate(SpringContext
1074:                                    .getBean(DateTimeService.class)
1075:                                    .getCurrentSqlDate());
1076:                    vendorQuote.setTransmitPrintDisplayed(true);
1077:                    SpringContext.getBean(PurchaseOrderService.class)
1078:                            .saveDocumentNoValidation(po);
1079:                } else {
1080:                    GlobalVariables
1081:                            .getErrorMap()
1082:                            .putError(
1083:                                    PurapPropertyConstants.VENDOR_QUOTES,
1084:                                    PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_TRANSMIT_TYPE_NOT_SELECTED);
1085:                }
1086:
1087:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1088:            }
1089:
1090:            /**
1091:             * Is invoked when the user clicks on the Select All button on a Purchase Order Retransmit document. It will select
1092:             * the checkboxes of all the items to be included in the retransmission of the PO.
1093:             * 
1094:             * @param mapping An ActionMapping
1095:             * @param form An ActionForm
1096:             * @param request The HttpServletRequest
1097:             * @param response The HttpServletResponse
1098:             * @throws Exception
1099:             * @return An ActionForward
1100:             */
1101:            public ActionForward selectAllForRetransmit(ActionMapping mapping,
1102:                    ActionForm form, HttpServletRequest request,
1103:                    HttpServletResponse response) throws Exception {
1104:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1105:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1106:                        .getDocument();
1107:                List<PurchaseOrderItem> items = po.getItems();
1108:                for (PurchaseOrderItem item : items) {
1109:                    item.setItemSelectedForRetransmitIndicator(true);
1110:                }
1111:
1112:                return returnToPreviousPage(mapping, kualiDocumentFormBase);
1113:            }
1114:
1115:            /**
1116:             * Is invoked when the user clicks on the Deselect All button on a Purchase Order Retransmit document. It will
1117:             * uncheck the checkboxes of all the items to be excluded from the retransmission of the PO.
1118:             * 
1119:             * @param mapping An ActionMapping
1120:             * @param form An ActionForm
1121:             * @param request The HttpServletRequest
1122:             * @param response The HttpServletResponse
1123:             * @throws Exception
1124:             * @return An ActionForward
1125:             */
1126:            public ActionForward deselectAllForRetransmit(
1127:                    ActionMapping mapping, ActionForm form,
1128:                    HttpServletRequest request, HttpServletResponse response)
1129:                    throws Exception {
1130:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1131:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1132:                        .getDocument();
1133:                List<PurchaseOrderItem> items = po.getItems();
1134:                for (PurchaseOrderItem item : items) {
1135:                    item.setItemSelectedForRetransmitIndicator(false);
1136:                }
1137:
1138:                return returnToPreviousPage(mapping, kualiDocumentFormBase);
1139:            }
1140:
1141:            /**
1142:             * Is invoked when the user clicks on the Retransmit button on both the PO tabbed page and on the Purchase Order
1143:             * Retransmit Document page, which is essentially a PO tabbed page with the other irrelevant tabs being hidden. If it was
1144:             * invoked from the PO tabbed page, if the PO's pending indicator is false, this method will invoke a method in the
1145:             * PurchaseOrderService to update the flags, create the PurchaseOrderRetransmitDocument and route it. If the routing was
1146:             * successful, we'll display the Purchase Order Retransmit Document page to the user, containing the newly created and routed
1147:             * PurchaseOrderRetransmitDocument and a retransmit button as well as a list of items that the user can select to be
1148:             * retransmitted. If it was invoked from the Purchase Order Retransmit Document page, we'll invoke the
1149:             * retransmitPurchaseOrderPDF method to create a PDF document based on the PO information and the items that were selected by
1150:             * the user on the Purchase Order Retransmit Document page to be retransmitted, then display the PDF to the browser.
1151:             * 
1152:             * @param mapping An ActionMapping
1153:             * @param form An ActionForm
1154:             * @param request The HttpServletRequest
1155:             * @param response The HttpServletResponse
1156:             * @throws Exception
1157:             * @return An ActionForward
1158:             */
1159:            public ActionForward retransmitPo(ActionMapping mapping,
1160:                    ActionForm form, HttpServletRequest request,
1161:                    HttpServletResponse response) throws Exception {
1162:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1163:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1164:                        .getDocument();
1165:
1166:                boolean success;
1167:                if (po.isPendingActionIndicator()) {
1168:                    success = false;
1169:                    GlobalVariables.getErrorMap().putError(
1170:                            PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER,
1171:                            PurapKeyConstants.ERROR_PURCHASE_ORDER_IS_PENDING);
1172:                } else {
1173:                    po = SpringContext
1174:                            .getBean(PurchaseOrderService.class)
1175:                            .createAndRoutePotentialChangeDocument(
1176:                                    kualiDocumentFormBase.getDocument()
1177:                                            .getDocumentNumber(),
1178:                                    PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT,
1179:                                    kualiDocumentFormBase.getAnnotation(),
1180:                                    combineAdHocRecipients(kualiDocumentFormBase),
1181:                                    PurchaseOrderStatuses.PENDING_RETRANSMIT);
1182:                }
1183:
1184:                kualiDocumentFormBase.setDocument(po);
1185:                // we only need to set the editing mode to displayRetransmitTab if it's not yet
1186:                // in the editingMode.
1187:                if (!kualiDocumentFormBase
1188:                        .getEditingMode()
1189:                        .containsKey(
1190:                                PurapAuthorizationConstants.PurchaseOrderEditMode.DISPLAY_RETRANSMIT_TAB)) {
1191:                    DocumentAuthorizer documentAuthorizer = SpringContext
1192:                            .getBean(DocumentAuthorizationService.class)
1193:                            .getDocumentAuthorizer(po);
1194:                    kualiDocumentFormBase
1195:                            .populateAuthorizationFields(documentAuthorizer);
1196:                }
1197:
1198:                return returnToPreviousPage(mapping, kualiDocumentFormBase);
1199:            }
1200:
1201:            /**
1202:             * Creates a PDF document based on the PO information and the items that were selected by the user on the Purchase Order
1203:             * Retransmit Document page to be retransmitted, then display the PDF to the browser.
1204:             * 
1205:             * @param mapping An ActionMapping
1206:             * @param form An ActionForm
1207:             * @param request The HttpServletRequest
1208:             * @param response The HttpServletResponse
1209:             * @throws Exception
1210:             * @return An ActionForward
1211:             */
1212:            public ActionForward printingRetransmitPo(ActionMapping mapping,
1213:                    ActionForm form, HttpServletRequest request,
1214:                    HttpServletResponse response) throws Exception {
1215:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1216:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1217:                        .getDocument();
1218:
1219:                List items = po.getItems();
1220:                String retransmitHeader = po.getRetransmitHeader();
1221:                po = SpringContext.getBean(PurchaseOrderService.class)
1222:                        .getPurchaseOrderByDocumentNumber(
1223:                                po.getDocumentNumber());
1224:                // setting the isItemSelectedForRetransmitIndicator items of the PO obtained from the database based on its value from
1225:                // the po from the form
1226:                setItemSelectedForRetransmitIndicatorFromPOInForm(items, po
1227:                        .getItems());
1228:                po.setRetransmitHeader(retransmitHeader);
1229:                ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
1230:                try {
1231:                    StringBuffer sbFilename = new StringBuffer();
1232:                    sbFilename.append("PURAP_PO_");
1233:                    sbFilename.append(po.getPurapDocumentIdentifier());
1234:                    sbFilename.append("_");
1235:                    sbFilename.append(System.currentTimeMillis());
1236:                    sbFilename.append(".pdf");
1237:
1238:                    // below method will throw ValidationException if errors are found
1239:                    SpringContext.getBean(PurchaseOrderService.class)
1240:                            .retransmitPurchaseOrderPDF(po, baosPDF);
1241:
1242:                    response.setHeader("Cache-Control", "max-age=30");
1243:                    response.setContentType("application/pdf");
1244:                    StringBuffer sbContentDispValue = new StringBuffer();
1245:                    sbContentDispValue.append("inline");
1246:                    sbContentDispValue.append("; filename=");
1247:                    sbContentDispValue.append(sbFilename);
1248:
1249:                    response.setHeader("Content-disposition",
1250:                            sbContentDispValue.toString());
1251:
1252:                    response.setContentLength(baosPDF.size());
1253:
1254:                    ServletOutputStream sos;
1255:
1256:                    sos = response.getOutputStream();
1257:
1258:                    baosPDF.writeTo(sos);
1259:
1260:                    sos.flush();
1261:
1262:                } catch (ValidationException e) {
1263:                    LOG
1264:                            .warn("Caught ValidationException while trying to retransmit PO with doc id "
1265:                                    + po.getDocumentNumber());
1266:                    return mapping.findForward(KFSConstants.MAPPING_ERROR);
1267:                } finally {
1268:                    if (baosPDF != null) {
1269:                        baosPDF.reset();
1270:                    }
1271:                }
1272:
1273:                return null;
1274:            }
1275:
1276:            /**
1277:             * Sets the <code>isItemSelectedForRetransmitIndicator</code> on items of the purchase order obtained from the database, based
1278:             * on the indicator's value from the form.
1279:             * 
1280:             * @param itemsFromForm A List<PurchaseOrderItem> obtained from the form
1281:             * @param itemsFromDB A List<PurchaseOrderItem> obtained from the database.
1282:             */
1283:            private void setItemSelectedForRetransmitIndicatorFromPOInForm(
1284:                    List itemsFromForm, List itemsFromDB) {
1285:                int i = 0;
1286:                for (PurchaseOrderItem itemFromForm : (List<PurchaseOrderItem>) itemsFromForm) {
1287:                    ((PurchaseOrderItem) (itemsFromDB.get(i)))
1288:                            .setItemSelectedForRetransmitIndicator(itemFromForm
1289:                                    .isItemSelectedForRetransmitIndicator());
1290:                    i++;
1291:                }
1292:            }
1293:
1294:            /**
1295:             * Checks on a few conditions that would cause a warning message to be displayed on top of the Purchase Order page.
1296:             * 
1297:             * @param po the PurchaseOrderDocument whose status and indicators are to be checked in the conditions
1298:             * @return boolean true if the Purchase Order doesn't have any warnings and false otherwise.
1299:             */
1300:            private void checkForPOWarnings(PurchaseOrderDocument po,
1301:                    ActionMessages messages) {
1302:                // "This is not the current version of this Purchase Order." (curr_ind = N and doc status is not enroute)
1303:                if (!po.isPurchaseOrderCurrentIndicator()
1304:                        && !po.getDocumentHeader().getWorkflowDocument()
1305:                                .stateIsEnroute()) {
1306:                    GlobalVariables
1307:                            .getMessageList()
1308:                            .add(
1309:                                    PurapKeyConstants.WARNING_PURCHASE_ORDER_NOT_CURRENT);
1310:                }
1311:                // "This document is a pending action. This is not the current version of this Purchase Order" (curr_ind = N and doc status
1312:                // is enroute)
1313:                if (!po.isPurchaseOrderCurrentIndicator()
1314:                        && po.getDocumentHeader().getWorkflowDocument()
1315:                                .stateIsEnroute()) {
1316:                    GlobalVariables
1317:                            .getMessageList()
1318:                            .add(
1319:                                    PurapKeyConstants.WARNING_PURCHASE_ORDER_PENDING_ACTION_NOT_CURRENT);
1320:                }
1321:                // "There is a pending action on this Purchase Order." (pend_action = Y)
1322:                if (po.isPendingActionIndicator()) {
1323:                    GlobalVariables
1324:                            .getMessageList()
1325:                            .add(
1326:                                    PurapKeyConstants.WARNING_PURCHASE_ORDER_PENDING_ACTION);
1327:                }
1328:
1329:                if (!po.isPurchaseOrderCurrentIndicator()) {
1330:                    ActionMessage noteMessage = new ActionMessage(
1331:                            PurapKeyConstants.WARNING_PURCHASE_ORDER_ALL_NOTES);
1332:                    messages.add(PurapConstants.NOTE_TAB_WARNING, noteMessage);
1333:                }
1334:            }
1335:
1336:            /**
1337:             * Add a stipulation to the document.
1338:             * 
1339:             * @param mapping An ActionMapping
1340:             * @param form An ActionForm
1341:             * @param request The HttpServletRequest
1342:             * @param response The HttpServletResponse
1343:             * @throws Exception
1344:             * @return An ActionForward
1345:             */
1346:            public ActionForward addStipulation(ActionMapping mapping,
1347:                    ActionForm form, HttpServletRequest request,
1348:                    HttpServletResponse response) throws Exception {
1349:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1350:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1351:                        .getDocument();
1352:
1353:                if (StringUtils.isBlank(poForm
1354:                        .getNewPurchaseOrderVendorStipulationLine()
1355:                        .getVendorStipulationDescription())) {
1356:                    GlobalVariables.getErrorMap().putError(
1357:                            PurapPropertyConstants.VENDOR_STIPULATION,
1358:                            PurapKeyConstants.ERROR_STIPULATION_DESCRIPTION);
1359:                } else {
1360:                    PurchaseOrderVendorStipulation newStipulation = poForm
1361:                            .getAndResetNewPurchaseOrderVendorStipulationLine();
1362:                    document.getPurchaseOrderVendorStipulations().add(
1363:                            newStipulation);
1364:                }
1365:
1366:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1367:            }
1368:
1369:            /**
1370:             * Delete a stipulation from the document.
1371:             * 
1372:             * @param mapping An ActionMapping
1373:             * @param form An ActionForm
1374:             * @param request The HttpServletRequest
1375:             * @param response The HttpServletResponse
1376:             * @throws Exception
1377:             * @return An ActionForward
1378:             */
1379:            public ActionForward deleteStipulation(ActionMapping mapping,
1380:                    ActionForm form, HttpServletRequest request,
1381:                    HttpServletResponse response) throws Exception {
1382:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1383:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1384:                        .getDocument();
1385:                document.getPurchaseOrderVendorStipulations().remove(
1386:                        getSelectedLine(request));
1387:
1388:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1389:            }
1390:
1391:            /**
1392:             * Overrides the docHandler method in the superclass. In addition to doing the normal process in the superclass and returning
1393:             * its action forward from the superclass, it also invokes the <code>checkForPOWarnings</code> method to check on a few
1394:             * conditions that could have caused warning messages to be displayed on top of Purchase Order page.
1395:             * 
1396:             * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#docHandler(org.apache.struts.action.ActionMapping,
1397:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
1398:             */
1399:            @Override
1400:            public ActionForward docHandler(ActionMapping mapping,
1401:                    ActionForm form, HttpServletRequest request,
1402:                    HttpServletResponse response) throws Exception {
1403:                ActionForward forward = super .docHandler(mapping, form,
1404:                        request, response);
1405:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1406:                addExtraButtons(kualiDocumentFormBase);
1407:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1408:                        .getDocument();
1409:                ActionMessages messages = new ActionMessages();
1410:                checkForPOWarnings(po, messages);
1411:                saveMessages(request, messages);
1412:
1413:                return forward;
1414:            }
1415:
1416:            /**
1417:             * Sets up the PO document for Quote processing.
1418:             * 
1419:             * @param mapping An ActionMapping
1420:             * @param form An ActionForm
1421:             * @param request The HttpServletRequest
1422:             * @param response The HttpServletResponse
1423:             * @throws Exception
1424:             * @return An ActionForward
1425:             */
1426:            public ActionForward initiateQuote(ActionMapping mapping,
1427:                    ActionForm form, HttpServletRequest request,
1428:                    HttpServletResponse response) throws Exception {
1429:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1430:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1431:                        .getDocument();
1432:                if (!PurapConstants.PurchaseOrderStatuses.IN_PROCESS
1433:                        .equals(document.getStatusCode())) {
1434:                    // PO must be "in process" in order to initiate a quote
1435:                    GlobalVariables
1436:                            .getErrorMap()
1437:                            .putError(
1438:                                    PurapPropertyConstants.VENDOR_QUOTES,
1439:                                    PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_NOT_IN_PROCESS);
1440:
1441:                    return mapping.findForward(KFSConstants.MAPPING_BASIC);
1442:                }
1443:                document
1444:                        .setStatusCode(PurapConstants.PurchaseOrderStatuses.QUOTE);
1445:                Date currentSqlDate = SpringContext.getBean(
1446:                        DateTimeService.class).getCurrentSqlDate();
1447:                Date expDate = new Date(currentSqlDate.getTime()
1448:                        + (10 * 24 * 60 * 60 * 1000)); // add 10 days 
1449:                document.setPurchaseOrderQuoteDueDate(expDate);
1450:                document.getPurchaseOrderVendorQuotes().clear();
1451:                SpringContext.getBean(PurchaseOrderService.class)
1452:                        .saveDocumentNoValidation(document);
1453:
1454:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1455:            }
1456:
1457:            /**
1458:             * Add to the Quotes a line to contain a Vendor.
1459:             * 
1460:             * @param mapping An ActionMapping
1461:             * @param form An ActionForm
1462:             * @param request The HttpServletRequest
1463:             * @param response The HttpServletResponse
1464:             * @throws Exception
1465:             * @return An ActionForward
1466:             */
1467:            public ActionForward addVendor(ActionMapping mapping,
1468:                    ActionForm form, HttpServletRequest request,
1469:                    HttpServletResponse response) throws Exception {
1470:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1471:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1472:                        .getDocument();
1473:                poForm.getNewPurchaseOrderVendorQuote().setDocumentNumber(
1474:                        document.getDocumentNumber());
1475:                document.getPurchaseOrderVendorQuotes().add(
1476:                        poForm.getNewPurchaseOrderVendorQuote());
1477:                poForm
1478:                        .setNewPurchaseOrderVendorQuote(new PurchaseOrderVendorQuote());
1479:                document.refreshNonUpdateableReferences();
1480:
1481:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1482:            }
1483:
1484:            /**
1485:             * Deletes a Vendor from the list of those from which a Quote should be obtained.
1486:             * 
1487:             * @param mapping An ActionMapping
1488:             * @param form An ActionForm
1489:             * @param request The HttpServletRequest
1490:             * @param response The HttpServletResponse
1491:             * @throws Exception
1492:             * @return An ActionForward
1493:             */
1494:            public ActionForward deleteVendor(ActionMapping mapping,
1495:                    ActionForm form, HttpServletRequest request,
1496:                    HttpServletResponse response) throws Exception {
1497:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1498:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1499:                        .getDocument();
1500:                document.getPurchaseOrderVendorQuotes().remove(
1501:                        getSelectedLine(request));
1502:                document.refreshNonUpdateableReferences();
1503:
1504:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1505:            }
1506:
1507:            /**
1508:             * Once an awarded Vendor number is present on the PO, verifies the fact, asks the user for confirmation to complete the quoting
1509:             * process with the awarded Vendor, and sets the Vendor information on the purchase order, if confirmation is obtained.
1510:             * 
1511:             * @param mapping An ActionMapping
1512:             * @param form An ActionForm
1513:             * @param request The HttpServletRequest
1514:             * @param response The HttpServletResponse
1515:             * @throws Exception
1516:             * @return An ActionForward
1517:             */
1518:            public ActionForward completeQuote(ActionMapping mapping,
1519:                    ActionForm form, HttpServletRequest request,
1520:                    HttpServletResponse response) throws Exception {
1521:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1522:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1523:                        .getDocument();
1524:                PurchaseOrderVendorQuote awardedQuote = new PurchaseOrderVendorQuote();
1525:                // verify quote status fields
1526:                if (poForm.getAwardedVendorNumber() == null) {
1527:                    GlobalVariables
1528:                            .getErrorMap()
1529:                            .putError(
1530:                                    PurapPropertyConstants.VENDOR_QUOTES,
1531:                                    PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_NO_VENDOR_AWARDED);
1532:
1533:                    return mapping.findForward(KFSConstants.MAPPING_BASIC);
1534:                } else {
1535:                    awardedQuote = document.getPurchaseOrderVendorQuote(poForm
1536:                            .getAwardedVendorNumber().intValue());
1537:                    if (awardedQuote.getPurchaseOrderQuoteStatusCode() == null) {
1538:                        GlobalVariables
1539:                                .getErrorMap()
1540:                                .putError(
1541:                                        PurapPropertyConstants.VENDOR_QUOTES,
1542:                                        PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_NOT_TRANSMITTED);
1543:
1544:                        return mapping.findForward(KFSConstants.MAPPING_BASIC);
1545:                    }
1546:                }
1547:
1548:                // use question framework to make sure they REALLY want to complete the quote...
1549:                String message = SpringContext
1550:                        .getBean(KualiConfigurationService.class)
1551:                        .getPropertyString(
1552:                                PurapKeyConstants.PURCHASE_ORDER_QUESTION_CONFIRM_AWARD);
1553:                String vendorRow = SpringContext
1554:                        .getBean(KualiConfigurationService.class)
1555:                        .getPropertyString(
1556:                                PurapKeyConstants.PURCHASE_ORDER_QUESTION_CONFIRM_AWARD_ROW);
1557:
1558:                String tempRows = "";
1559:                for (PurchaseOrderVendorQuote poQuote : document
1560:                        .getPurchaseOrderVendorQuotes()) {
1561:                    String tempRow = vendorRow;
1562:                    tempRow = StringUtils.replace(tempRow, "{0}", poQuote
1563:                            .getVendorName());
1564:                    if (poQuote.getPurchaseOrderQuoteAwardDate() == null) {
1565:                        if (awardedQuote.getVendorNumber().equals(
1566:                                poQuote.getVendorNumber())) {
1567:                            tempRow = StringUtils.replace(tempRow, "{1}",
1568:                                    SpringContext
1569:                                            .getBean(DateTimeService.class)
1570:                                            .getCurrentSqlDate().toString());
1571:                        } else {
1572:                            tempRow = StringUtils.replace(tempRow, "{1}", "");
1573:                        }
1574:                    } else {
1575:                        tempRow = StringUtils.replace(tempRow, "{1}", poQuote
1576:                                .getPurchaseOrderQuoteAwardDate().toString());
1577:                    }
1578:                    if (poQuote.getPurchaseOrderQuoteStatusCode() != null) {
1579:                        tempRow = StringUtils.replace(tempRow, "{2}", poQuote
1580:                                .getPurchaseOrderQuoteStatusCode());
1581:                    } else {
1582:                        tempRow = StringUtils.replace(tempRow, "{2}", "N/A");
1583:                    }
1584:                    if (poQuote.getPurchaseOrderQuoteRankNumber() != null) {
1585:                        tempRow = StringUtils.replace(tempRow, "{3}", poQuote
1586:                                .getPurchaseOrderQuoteRankNumber());
1587:                    } else {
1588:                        tempRow = StringUtils.replace(tempRow, "{3}", "N/A");
1589:                    }
1590:                    tempRows += tempRow;
1591:                }
1592:                message = StringUtils.replace(message, "{0}", tempRows);
1593:
1594:                Object question = request
1595:                        .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
1596:
1597:                if (question == null) {
1598:
1599:                    // ask question if not already asked
1600:                    return performQuestionWithoutInput(mapping, form, request,
1601:                            response,
1602:                            PODocumentsStrings.CONFIRM_AWARD_QUESTION, message,
1603:                            KFSConstants.CONFIRMATION_QUESTION,
1604:                            PODocumentsStrings.CONFIRM_AWARD_RETURN, "");
1605:                } else {
1606:                    Object buttonClicked = request
1607:                            .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
1608:                    if ((PODocumentsStrings.CONFIRM_AWARD_QUESTION
1609:                            .equals(question))
1610:                            && ConfirmationQuestion.YES.equals(buttonClicked)) {
1611:                        // set awarded date
1612:                        awardedQuote
1613:                                .setPurchaseOrderQuoteAwardDate(SpringContext
1614:                                        .getBean(DateTimeService.class)
1615:                                        .getCurrentSqlDate());
1616:
1617:                        // PO vendor information updated with awarded vendor
1618:                        document.setVendorName(awardedQuote.getVendorName());
1619:                        document
1620:                                .setVendorNumber(awardedQuote.getVendorNumber());
1621:                        document
1622:                                .setVendorHeaderGeneratedIdentifier(awardedQuote
1623:                                        .getVendorHeaderGeneratedIdentifier());
1624:                        document.setVendorDetailAssignedIdentifier(awardedQuote
1625:                                .getVendorDetailAssignedIdentifier());
1626:                        // document.setVendorDetail(poQuote.getVendorDetail());
1627:                        document.setVendorLine1Address(awardedQuote
1628:                                .getVendorLine1Address());
1629:                        document.setVendorLine2Address(awardedQuote
1630:                                .getVendorLine2Address());
1631:                        document.setVendorCityName(awardedQuote
1632:                                .getVendorCityName());
1633:                        document.setVendorStateCode(awardedQuote
1634:                                .getVendorStateCode());
1635:                        document.setVendorCountryCode(awardedQuote
1636:                                .getVendorCountryCode());
1637:                        document.setVendorPhoneNumber(awardedQuote
1638:                                .getVendorPhoneNumber());
1639:                        document.setVendorFaxNumber(awardedQuote
1640:                                .getVendorFaxNumber());
1641:
1642:                        document
1643:                                .setStatusCode(PurapConstants.PurchaseOrderStatuses.IN_PROCESS);
1644:                    }
1645:                }
1646:                SpringContext.getBean(PurchaseOrderService.class)
1647:                        .saveDocumentNoValidation(document);
1648:
1649:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1650:            }
1651:
1652:            /**
1653:             * Cancels the process of obtaining quotes. Checks whether any of the quote requests have been transmitted. If none have, tries
1654:             * to obtain confirmation from the user for the cancellation. If confirmation is obtained, clears out the list of Vendors from
1655:             * which to obtain quotes and writes the given reason to a note on the PO.
1656:             * 
1657:             * @param mapping An ActionMapping
1658:             * @param form An ActionForm
1659:             * @param request The HttpServletRequest
1660:             * @param response The HttpServletResponse
1661:             * @throws Exception
1662:             * @return An ActionForward
1663:             */
1664:            public ActionForward cancelQuote(ActionMapping mapping,
1665:                    ActionForm form, HttpServletRequest request,
1666:                    HttpServletResponse response) throws Exception {
1667:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1668:                PurchaseOrderDocument document = (PurchaseOrderDocument) poForm
1669:                        .getDocument();
1670:
1671:                for (PurchaseOrderVendorQuote quotedVendors : document
1672:                        .getPurchaseOrderVendorQuotes()) {
1673:                    if (quotedVendors.getPurchaseOrderQuoteTransmitDate() != null) {
1674:                        GlobalVariables
1675:                                .getErrorMap()
1676:                                .putError(
1677:                                        PurapPropertyConstants.QUOTE_TRANSMITTED,
1678:                                        PurapKeyConstants.ERROR_STIPULATION_DESCRIPTION);
1679:
1680:                        return mapping.findForward(KFSConstants.MAPPING_BASIC);
1681:                    }
1682:                }
1683:
1684:                String message = SpringContext
1685:                        .getBean(KualiConfigurationService.class)
1686:                        .getPropertyString(
1687:                                PurapKeyConstants.PURCHASE_ORDER_QUESTION_CONFIRM_CANCEL_QUOTE);
1688:                Object question = request
1689:                        .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
1690:
1691:                if (question == null) {
1692:
1693:                    // ask question if not already asked
1694:                    return performQuestionWithInput(mapping, form, request,
1695:                            response,
1696:                            PODocumentsStrings.CONFIRM_CANCEL_QUESTION,
1697:                            message, KFSConstants.CONFIRMATION_QUESTION,
1698:                            PODocumentsStrings.CONFIRM_CANCEL_RETURN, "");
1699:                } else {
1700:                    Object buttonClicked = request
1701:                            .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
1702:                    if ((PODocumentsStrings.CONFIRM_CANCEL_QUESTION
1703:                            .equals(question))
1704:                            && ConfirmationQuestion.YES.equals(buttonClicked)) {
1705:                        String reason = request
1706:                                .getParameter(KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME);
1707:
1708:                        if (StringUtils.isEmpty(reason)) {
1709:
1710:                            return performQuestionWithInputAgainBecauseOfErrors(
1711:                                    mapping,
1712:                                    form,
1713:                                    request,
1714:                                    response,
1715:                                    PODocumentsStrings.CONFIRM_CANCEL_QUESTION,
1716:                                    message,
1717:                                    KFSConstants.CONFIRMATION_QUESTION,
1718:                                    PODocumentsStrings.CONFIRM_CANCEL_RETURN,
1719:                                    "",
1720:                                    "",
1721:                                    PurapKeyConstants.ERROR_PURCHASE_ORDER_REASON_REQUIRED,
1722:                                    KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME,
1723:                                    "250");
1724:                        }
1725:                        document.getPurchaseOrderVendorQuotes().clear();
1726:                        Note cancelNote = new Note();
1727:                        cancelNote.setAuthorUniversalIdentifier(GlobalVariables
1728:                                .getUserSession().getUniversalUser()
1729:                                .getPersonUniversalIdentifier());
1730:                        String reasonPrefix = SpringContext
1731:                                .getBean(KualiConfigurationService.class)
1732:                                .getPropertyString(
1733:                                        PurapKeyConstants.PURCHASE_ORDER_CANCEL_QUOTE_NOTE_TEXT);
1734:                        cancelNote.setNoteText(reasonPrefix + reason);
1735:                        document.addNote(cancelNote);
1736:                        document
1737:                                .setStatusCode(PurapConstants.PurchaseOrderStatuses.IN_PROCESS);
1738:                    }
1739:                }
1740:
1741:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
1742:            }
1743:
1744:            /**
1745:             * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#cancel(org.apache.struts.action.ActionMapping,
1746:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
1747:             */
1748:            @Override
1749:            public ActionForward cancel(ActionMapping mapping, ActionForm form,
1750:                    HttpServletRequest request, HttpServletResponse response)
1751:                    throws Exception {
1752:                Object question = request
1753:                        .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
1754:                // this should probably be moved into a private instance variable
1755:                KualiConfigurationService kualiConfiguration = SpringContext
1756:                        .getBean(KualiConfigurationService.class);
1757:
1758:                // logic for cancel question
1759:                if (question == null) {
1760:
1761:                    // ask question if not already asked
1762:                    return this 
1763:                            .performQuestionWithoutInput(
1764:                                    mapping,
1765:                                    form,
1766:                                    request,
1767:                                    response,
1768:                                    KFSConstants.DOCUMENT_CANCEL_QUESTION,
1769:                                    kualiConfiguration
1770:                                            .getPropertyString("document.question.cancel.text"),
1771:                                    KFSConstants.CONFIRMATION_QUESTION,
1772:                                    KFSConstants.MAPPING_CANCEL, "");
1773:                } else {
1774:                    Object buttonClicked = request
1775:                            .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
1776:                    if ((KFSConstants.DOCUMENT_CANCEL_QUESTION.equals(question))
1777:                            && ConfirmationQuestion.NO.equals(buttonClicked)) {
1778:
1779:                        // if no button clicked just reload the doc
1780:                        return mapping.findForward(KFSConstants.MAPPING_BASIC);
1781:                    }
1782:                    // else go to cancel logic below
1783:                }
1784:
1785:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1786:                SpringContext.getBean(DocumentService.class).cancelDocument(
1787:                        kualiDocumentFormBase.getDocument(),
1788:                        kualiDocumentFormBase.getAnnotation());
1789:
1790:                return returnToSender(mapping, kualiDocumentFormBase);
1791:            }
1792:
1793:            /**
1794:             * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#save(org.apache.struts.action.ActionMapping,
1795:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
1796:             */
1797:            @Override
1798:            public ActionForward save(ActionMapping mapping, ActionForm form,
1799:                    HttpServletRequest request, HttpServletResponse response)
1800:                    throws Exception {
1801:                PurchaseOrderForm poForm = (PurchaseOrderForm) form;
1802:                PurchaseOrderDocument po = poForm.getPurchaseOrderDocument();
1803:
1804:                if (StringUtils.isNotBlank(po.getStatusCode())
1805:                        && StringUtils.isNotBlank(po.getStatusChange())
1806:                        && (!StringUtils.equals(po.getStatusCode(), po
1807:                                .getStatusChange()))) {
1808:
1809:                    KualiWorkflowDocument workflowDocument = po
1810:                            .getDocumentHeader().getWorkflowDocument();
1811:                    if (ObjectUtils.isNull(workflowDocument)
1812:                            || workflowDocument.stateIsInitiated()
1813:                            || workflowDocument.stateIsSaved()) {
1814:
1815:                        return this 
1816:                                .askSaveQuestions(
1817:                                        mapping,
1818:                                        form,
1819:                                        request,
1820:                                        response,
1821:                                        PODocumentsStrings.MANUAL_STATUS_CHANGE_QUESTION);
1822:                    }
1823:                }
1824:
1825:                return super .save(mapping, form, request, response);
1826:            }
1827:
1828:            /**
1829:             * Obtains confirmation and records reasons for the manual status changes which can take place before the purchase order has
1830:             * been routed. If confirmation is given, changes the status, saves, and records the given reason in an note on the purchase
1831:             * order.
1832:             * 
1833:             * @param mapping An ActionMapping
1834:             * @param form An ActionForm
1835:             * @param request The HttpServletRequest
1836:             * @param response The HttpServletResponse
1837:             * @return An ActionForward
1838:             */
1839:            private ActionForward askSaveQuestions(ActionMapping mapping,
1840:                    ActionForm form, HttpServletRequest request,
1841:                    HttpServletResponse response, String questionType) {
1842:                KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1843:                PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase
1844:                        .getDocument();
1845:                Object question = request
1846:                        .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
1847:                String reason = request
1848:                        .getParameter(KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME);
1849:                KualiConfigurationService kualiConfiguration = SpringContext
1850:                        .getBean(KualiConfigurationService.class);
1851:                ActionForward forward = mapping
1852:                        .findForward(KFSConstants.MAPPING_BASIC);
1853:                String notePrefix = "";
1854:
1855:                if (StringUtils.equals(questionType,
1856:                        PODocumentsStrings.MANUAL_STATUS_CHANGE_QUESTION)
1857:                        && ObjectUtils.isNull(question)) {
1858:                    String message = kualiConfiguration
1859:                            .getPropertyString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_MANUAL_STATUS_CHANGE);
1860:                    try {
1861:
1862:                        return this .performQuestionWithInput(mapping, form,
1863:                                request, response, questionType, message,
1864:                                KFSConstants.CONFIRMATION_QUESTION,
1865:                                questionType, "");
1866:                    } catch (Exception e) {
1867:                        throw new RuntimeException(e);
1868:                    }
1869:                } else {
1870:                    Object buttonClicked = request
1871:                            .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
1872:                    if (question.equals(questionType)
1873:                            && buttonClicked.equals(ConfirmationQuestion.NO)) {
1874:                        // If 'No' is the button clicked, just reload the doc
1875:                        addExtraButtons(kualiDocumentFormBase);
1876:
1877:                        return forward;
1878:                    }
1879:
1880:                    // Build out full message.
1881:                    if (StringUtils.equals(questionType,
1882:                            PODocumentsStrings.MANUAL_STATUS_CHANGE_QUESTION)) {
1883:                        Map<String, String> manuallyChangeableStatuses = new HashMap<String, String>();
1884:                        manuallyChangeableStatuses.put(
1885:                                PurchaseOrderStatuses.IN_PROCESS, "In Process");
1886:                        manuallyChangeableStatuses.put(
1887:                                PurchaseOrderStatuses.WAITING_FOR_VENDOR,
1888:                                "Waiting for Vendor");
1889:                        manuallyChangeableStatuses.put(
1890:                                PurchaseOrderStatuses.WAITING_FOR_DEPARTMENT,
1891:                                "Waiting for Department");
1892:
1893:                        String key = kualiConfiguration
1894:                                .getPropertyString(PurapKeyConstants.PURCHASE_ORDER_MANUAL_STATUS_CHANGE_NOTE_PREFIX);
1895:                        String oldStatus = manuallyChangeableStatuses.get(po
1896:                                .getStatusCode());
1897:                        String newStatus = manuallyChangeableStatuses.get(po
1898:                                .getStatusChange());
1899:                        key = StringUtils.replace(key, "{0}", (StringUtils
1900:                                .isBlank(oldStatus) ? " " : oldStatus));
1901:                        notePrefix = StringUtils.replace(key, "{1}",
1902:                                (StringUtils.isBlank(newStatus) ? " "
1903:                                        : newStatus));
1904:                    }
1905:                    String noteText = notePrefix + KFSConstants.BLANK_SPACE
1906:                            + reason;
1907:                    int noteTextLength = noteText.length();
1908:
1909:                    // Get note text max length from DD.
1910:                    int noteTextMaxLength = SpringContext.getBean(
1911:                            DataDictionaryService.class).getAttributeMaxLength(
1912:                            Note.class, KFSConstants.NOTE_TEXT_PROPERTY_NAME)
1913:                            .intValue();
1914:
1915:                    if (StringUtils.isBlank(reason)
1916:                            || (noteTextLength > noteTextMaxLength)) {
1917:                        // Figure out exact number of characters that the user can enter.
1918:                        int reasonLimit = noteTextMaxLength - noteTextLength;
1919:
1920:                        if (ObjectUtils.isNull(reason)) {
1921:                            // Prevent a NPE by setting the reason to a blank string.
1922:                            reason = "";
1923:                        }
1924:
1925:                        try {
1926:                            if (StringUtils
1927:                                    .equals(
1928:                                            questionType,
1929:                                            PODocumentsStrings.MANUAL_STATUS_CHANGE_QUESTION)) {
1930:
1931:                                return this 
1932:                                        .performQuestionWithInputAgainBecauseOfErrors(
1933:                                                mapping,
1934:                                                form,
1935:                                                request,
1936:                                                response,
1937:                                                questionType,
1938:                                                kualiConfiguration
1939:                                                        .getPropertyString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_MANUAL_STATUS_CHANGE),
1940:                                                KFSConstants.CONFIRMATION_QUESTION,
1941:                                                questionType,
1942:                                                "",
1943:                                                reason,
1944:                                                PurapKeyConstants.ERROR_PURCHASE_ORDER_REASON_REQUIRED,
1945:                                                KFSConstants.QUESTION_REASON_ATTRIBUTE_NAME,
1946:                                                new Integer(reasonLimit)
1947:                                                        .toString());
1948:                            }
1949:                        } catch (Exception e) {
1950:                            throw new RuntimeException(e);
1951:                        }
1952:                    } else if (StringUtils.equals(questionType,
1953:                            PODocumentsStrings.MANUAL_STATUS_CHANGE_QUESTION)) {
1954:                        executeManualStatusChange(po);
1955:                        try {
1956:                            forward = super .save(mapping, form, request,
1957:                                    response);
1958:                        } catch (Exception e) {
1959:                            throw new RuntimeException(e);
1960:                        }
1961:                    }
1962:                    Note newNote = new Note();
1963:                    newNote.setNoteText(noteText);
1964:                    newNote
1965:                            .setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE
1966:                                    .getCode());
1967:                    kualiDocumentFormBase.setNewNote(newNote);
1968:                    try {
1969:                        insertBONote(mapping, kualiDocumentFormBase, request,
1970:                                response);
1971:                    } catch (Exception e) {
1972:                        throw new RuntimeException(e);
1973:                    }
1974:                }
1975:                addExtraButtons(kualiDocumentFormBase);
1976:
1977:                return forward;
1978:            }
1979:
1980:            /**
1981:             * Applies a manual change of status to the given purchase order document.
1982:             * 
1983:             * @param po A PurchaseOrderDocument
1984:             */
1985:            private void executeManualStatusChange(PurchaseOrderDocument po) {
1986:                try {
1987:                    SpringContext.getBean(PurapService.class).updateStatus(po,
1988:                            po.getStatusChange());
1989:                } catch (Exception e) {
1990:                    throw new RuntimeException(e);
1991:                }
1992:            }
1993:
1994:            /**
1995:             * @see org.kuali.module.purap.web.struts.action.PurchasingAccountsPayableActionBase#loadDocument(org.kuali.core.web.struts.form.KualiDocumentFormBase)
1996:             */
1997:            @Override
1998:            protected void loadDocument(
1999:                    KualiDocumentFormBase kualiDocumentFormBase)
2000:                    throws WorkflowException {
2001:                super .loadDocument(kualiDocumentFormBase);
2002:                PurchaseOrderForm form = (PurchaseOrderForm) kualiDocumentFormBase;
2003:                PurchaseOrderDocument po = (PurchaseOrderDocument) form
2004:                        .getDocument();
2005:                form
2006:                        .setPurchaseOrderIdentifier(po
2007:                                .getPurapDocumentIdentifier());
2008:
2009:                po.setInternalPurchasingLimit(SpringContext.getBean(
2010:                        PurchaseOrderService.class)
2011:                        .getInternalPurchasingDollarLimit(po));
2012:            }
2013:
2014:        }
ww__w_.ja___v__a2__s.___co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.