Source Code Cross Referenced for PurchasingActionBase.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) 


001:        /*
002:         * Copyright 2006-2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.purap.web.struts.action;
017:
018:        import java.math.BigDecimal;
019:        import java.util.Map;
020:
021:        import javax.servlet.http.HttpServletRequest;
022:        import javax.servlet.http.HttpServletResponse;
023:
024:        import org.apache.commons.lang.StringUtils;
025:        import org.apache.struts.action.ActionForm;
026:        import org.apache.struts.action.ActionForward;
027:        import org.apache.struts.action.ActionMapping;
028:        import org.kuali.RicePropertyConstants;
029:        import org.kuali.core.question.ConfirmationQuestion;
030:        import org.kuali.core.service.BusinessObjectService;
031:        import org.kuali.core.service.KualiConfigurationService;
032:        import org.kuali.core.service.KualiRuleService;
033:        import org.kuali.core.service.PersistenceService;
034:        import org.kuali.core.util.GlobalVariables;
035:        import org.kuali.core.util.ObjectUtils;
036:        import org.kuali.kfs.KFSConstants;
037:        import org.kuali.kfs.bo.SourceAccountingLine;
038:        import org.kuali.kfs.context.SpringContext;
039:        import org.kuali.module.purap.PurapConstants;
040:        import org.kuali.module.purap.PurapKeyConstants;
041:        import org.kuali.module.purap.PurapPropertyConstants;
042:        import org.kuali.module.purap.bo.BillingAddress;
043:        import org.kuali.module.purap.bo.PurApAccountingLine;
044:        import org.kuali.module.purap.bo.PurApItem;
045:        import org.kuali.module.purap.bo.PurchaseOrderItem;
046:        import org.kuali.module.purap.document.PurchasingAccountsPayableDocument;
047:        import org.kuali.module.purap.document.PurchasingDocument;
048:        import org.kuali.module.purap.rule.event.AddPurchasingAccountsPayableItemEvent;
049:        import org.kuali.module.purap.web.struts.form.PurchasingAccountsPayableFormBase;
050:        import org.kuali.module.purap.web.struts.form.PurchasingFormBase;
051:        import org.kuali.module.vendor.VendorConstants;
052:        import org.kuali.module.vendor.bo.VendorAddress;
053:        import org.kuali.module.vendor.bo.VendorContract;
054:        import org.kuali.module.vendor.service.PhoneNumberService;
055:        import org.kuali.module.vendor.service.VendorService;
056:
057:        /**
058:         * Struts Action for Purchasing documents.
059:         */
060:        public class PurchasingActionBase extends
061:                PurchasingAccountsPayableActionBase {
062:            private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
063:                    .getLogger(PurchasingActionBase.class);
064:
065:            /**
066:             * @see org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
067:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
068:             */
069:            @Override
070:            public ActionForward refresh(ActionMapping mapping,
071:                    ActionForm form, HttpServletRequest request,
072:                    HttpServletResponse response) throws Exception {
073:                PurchasingFormBase baseForm = (PurchasingFormBase) form;
074:                PurchasingDocument document = (PurchasingDocument) baseForm
075:                        .getDocument();
076:                String refreshCaller = baseForm.getRefreshCaller();
077:                BusinessObjectService businessObjectService = SpringContext
078:                        .getBean(BusinessObjectService.class);
079:                PhoneNumberService phoneNumberService = SpringContext
080:                        .getBean(PhoneNumberService.class);
081:
082:                // Format phone numbers
083:                document.setInstitutionContactPhoneNumber(phoneNumberService
084:                        .formatNumberIfPossible(document
085:                                .getInstitutionContactPhoneNumber()));
086:                document.setRequestorPersonPhoneNumber(phoneNumberService
087:                        .formatNumberIfPossible(document
088:                                .getRequestorPersonPhoneNumber()));
089:                document.setDeliveryToPhoneNumber(phoneNumberService
090:                        .formatNumberIfPossible(document
091:                                .getDeliveryToPhoneNumber()));
092:
093:                // Refreshing the fields after returning from a vendor lookup in the vendor tab
094:                if (StringUtils.equals(refreshCaller,
095:                        VendorConstants.VENDOR_LOOKUPABLE_IMPL)
096:                        && document.getVendorDetailAssignedIdentifier() != null
097:                        && document.getVendorHeaderGeneratedIdentifier() != null) {
098:                    document.setVendorContractGeneratedIdentifier(null);
099:                    document.setVendorContractName(null);
100:
101:                    // retrieve vendor based on selection from vendor lookup
102:                    document.refreshReferenceObject("vendorDetail");
103:                    document.templateVendorDetail(document.getVendorDetail());
104:
105:                    // populate default address based on selected vendor
106:                    VendorAddress defaultAddress = SpringContext.getBean(
107:                            VendorService.class).getVendorDefaultAddress(
108:                            document.getVendorDetail().getVendorAddresses(),
109:                            document.getVendorDetail().getVendorHeader()
110:                                    .getVendorType().getAddressType()
111:                                    .getVendorAddressTypeCode(), "");
112:                    document.templateVendorAddress(defaultAddress);
113:                }
114:
115:                // Refreshing the fields after returning from a contract lookup in the vendor tab
116:                if (StringUtils.equals(refreshCaller,
117:                        VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL)) {
118:                    if (StringUtils
119:                            .isNotEmpty(request
120:                                    .getParameter(RicePropertyConstants.DOCUMENT
121:                                            + "."
122:                                            + PurapPropertyConstants.VENDOR_CONTRACT_ID))) {
123:                        // retrieve Contract based on selection from contract lookup
124:                        VendorContract refreshVendorContract = new VendorContract();
125:                        refreshVendorContract
126:                                .setVendorContractGeneratedIdentifier(document
127:                                        .getVendorContractGeneratedIdentifier());
128:                        refreshVendorContract = (VendorContract) businessObjectService
129:                                .retrieve(refreshVendorContract);
130:                        document.templateVendorContract(refreshVendorContract);
131:
132:                        // Need to reset the vendor header and detail id of the document from the refreshVendorContract as well
133:                        // so that we can continue to do the other lookups (address, customer number) using the correct vendor ids.
134:                        document
135:                                .setVendorHeaderGeneratedIdentifier(refreshVendorContract
136:                                        .getVendorHeaderGeneratedIdentifier());
137:                        document
138:                                .setVendorDetailAssignedIdentifier(refreshVendorContract
139:                                        .getVendorDetailAssignedIdentifier());
140:
141:                        // Need to clear out the Customer Number (see comments on KULPURAP-832).
142:                        document.setVendorCustomerNumber(null);
143:
144:                        // retrieve Vendor based on selected contract
145:                        document
146:                                .setVendorDetailAssignedIdentifier(refreshVendorContract
147:                                        .getVendorDetailAssignedIdentifier());
148:                        document
149:                                .setVendorHeaderGeneratedIdentifier(refreshVendorContract
150:                                        .getVendorHeaderGeneratedIdentifier());
151:                        document.refreshReferenceObject("vendorDetail");
152:                        document.templateVendorDetail(document
153:                                .getVendorDetail());
154:
155:                        // populate default address from selected vendor
156:                        VendorAddress defaultAddress = SpringContext
157:                                .getBean(VendorService.class)
158:                                .getVendorDefaultAddress(
159:                                        document.getVendorDetail()
160:                                                .getVendorAddresses(),
161:                                        document.getVendorDetail()
162:                                                .getVendorHeader()
163:                                                .getVendorType()
164:                                                .getAddressType()
165:                                                .getVendorAddressTypeCode(), "");
166:                        document.templateVendorAddress(defaultAddress);
167:
168:                        // populate cost source from the selected contract
169:                        if (refreshVendorContract != null) {
170:                            String costSourceCode = refreshVendorContract
171:                                    .getPurchaseOrderCostSourceCode();
172:                            if (StringUtils.isNotBlank(costSourceCode)) {
173:                                document
174:                                        .setPurchaseOrderCostSourceCode(costSourceCode);
175:                                document
176:                                        .refreshReferenceObject(PurapPropertyConstants.PURCHASE_ORDER_COST_SOURCE);
177:                            }
178:                        }
179:                    }
180:                }
181:
182:                // Refreshing the fields after returning from an address lookup in the vendor tab
183:                if (StringUtils.equals(refreshCaller,
184:                        VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
185:                    if (StringUtils
186:                            .isNotEmpty(request
187:                                    .getParameter(RicePropertyConstants.DOCUMENT
188:                                            + "."
189:                                            + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
190:                        // retrieve address based on selection from address lookup
191:                        VendorAddress refreshVendorAddress = new VendorAddress();
192:                        refreshVendorAddress
193:                                .setVendorAddressGeneratedIdentifier(document
194:                                        .getVendorAddressGeneratedIdentifier());
195:                        refreshVendorAddress = (VendorAddress) businessObjectService
196:                                .retrieve(refreshVendorAddress);
197:                        document.templateVendorAddress(refreshVendorAddress);
198:                    }
199:                }
200:
201:                // We're supposed to refresh vendor again based on the vendor header and detail id on the requisition, unless if
202:                // this was a refresh for contract lookup or refresh for vendor lookup
203:                if (!(StringUtils.equals(refreshCaller,
204:                        VendorConstants.VENDOR_CONTRACT_LOOKUPABLE_IMPL) || (StringUtils
205:                        .equalsIgnoreCase(refreshCaller,
206:                                VendorConstants.VENDOR_LOOKUPABLE_IMPL)))) {
207:                    document.refreshReferenceObject("vendorDetail");
208:                    document.templateVendorDetail(document.getVendorDetail());
209:                }
210:
211:                // Refreshing the fields after returning from a building lookup on the delivery tab (update billing address)
212:                if (StringUtils.equals(refreshCaller,
213:                        KFSConstants.KUALI_LOOKUPABLE_IMPL)) {
214:                    BillingAddress billingAddress = new BillingAddress();
215:                    billingAddress.setBillingCampusCode(document
216:                            .getDeliveryCampusCode());
217:                    Map keys = SpringContext.getBean(PersistenceService.class)
218:                            .getPrimaryKeyFieldValues(billingAddress);
219:                    billingAddress = (BillingAddress) SpringContext.getBean(
220:                            BusinessObjectService.class).findByPrimaryKey(
221:                            BillingAddress.class, keys);
222:                    document.templateBillingAddress(billingAddress);
223:                }
224:
225:                return super .refresh(mapping, form, request, response);
226:            }
227:
228:            /**
229:             * Intended to be used by the refresh button that appears in the delivery tab to refresh the delivery building. Since this is a
230:             * refresh method, it is calling the general refresh method when it's done.
231:             * 
232:             * @param mapping An ActionMapping
233:             * @param form An ActionForm
234:             * @param request A HttpServletRequest
235:             * @param response A HttpServletResponse
236:             * @return An ActionForward
237:             * @throws Exception
238:             */
239:            public ActionForward refreshDeliveryBuilding(ActionMapping mapping,
240:                    ActionForm form, HttpServletRequest request,
241:                    HttpServletResponse response) throws Exception {
242:                PurchasingFormBase baseForm = (PurchasingFormBase) form;
243:                PurchasingDocument document = (PurchasingDocument) baseForm
244:                        .getDocument();
245:                if (ObjectUtils.isNotNull(document.isDeliveryBuildingOther())) {
246:                    if (document.isDeliveryBuildingOther()) {
247:                        document
248:                                .setDeliveryBuildingName(PurapConstants.DELIVERY_BUILDING_OTHER);
249:                        document
250:                                .setDeliveryBuildingCode(PurapConstants.DELIVERY_BUILDING_OTHER_CODE);
251:                        document.setDeliveryBuildingLine1Address(null);
252:                        document.setDeliveryBuildingLine2Address(null);
253:                        document.setDeliveryBuildingRoomNumber(null);
254:                        document.setDeliveryCityName(null);
255:                        document.setDeliveryStateCode(null);
256:                        document.setDeliveryCountryCode(null);
257:                        document.setDeliveryPostalCode(null);
258:                        baseForm.setNotOtherDeliveryBuilding(false);
259:                    } else {
260:                        document.setDeliveryBuildingName(null);
261:                        document.setDeliveryBuildingCode(null);
262:                        document.setDeliveryBuildingLine1Address(null);
263:                        document.setDeliveryBuildingLine2Address(null);
264:                        document.setDeliveryBuildingRoomNumber(null);
265:                        document.setDeliveryCityName(null);
266:                        document.setDeliveryStateCode(null);
267:                        document.setDeliveryCountryCode(null);
268:                        document.setDeliveryPostalCode(null);
269:                        baseForm.setNotOtherDeliveryBuilding(true);
270:                    }
271:                }
272:
273:                return refresh(mapping, form, request, response);
274:            }
275:
276:            /**
277:             * Add a new item to the document.
278:             * 
279:             * @param mapping An ActionMapping
280:             * @param form An ActionForm
281:             * @param request The HttpServletRequest
282:             * @param response The HttpServletResponse
283:             * @throws Exception
284:             * @return An ActionForward
285:             */
286:            public ActionForward addItem(ActionMapping mapping,
287:                    ActionForm form, HttpServletRequest request,
288:                    HttpServletResponse response) throws Exception {
289:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
290:                PurApItem item = purchasingForm.getNewPurchasingItemLine();
291:                PurchasingDocument purDocument = (PurchasingDocument) purchasingForm
292:                        .getDocument();
293:                boolean rulePassed = SpringContext.getBean(
294:                        KualiRuleService.class).applyRules(
295:                        new AddPurchasingAccountsPayableItemEvent("",
296:                                purDocument, item));
297:
298:                if (rulePassed) {
299:                    item = purchasingForm.getAndResetNewPurchasingItemLine();
300:                    purDocument.addItem(item);
301:                }
302:
303:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
304:            }
305:
306:            /**
307:             * Delete an item from the document.
308:             * 
309:             * @param mapping An ActionMapping
310:             * @param form An ActionForm
311:             * @param request The HttpServletRequest
312:             * @param response The HttpServletResponse
313:             * @throws Exception
314:             * @return An ActionForward
315:             */
316:            public ActionForward deleteItem(ActionMapping mapping,
317:                    ActionForm form, HttpServletRequest request,
318:                    HttpServletResponse response) throws Exception {
319:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
320:
321:                PurchasingDocument purDocument = (PurchasingDocument) purchasingForm
322:                        .getDocument();
323:                purDocument.deleteItem(getSelectedLine(request));
324:
325:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
326:            }
327:
328:            /**
329:             * Moves the selected item up one position.
330:             * 
331:             * @param mapping An ActionMapping
332:             * @param form An ActionForm
333:             * @param request The HttpServletRequest
334:             * @param response The HttpServletResponse
335:             * @throws Exception
336:             * @return An ActionForward
337:             */
338:            public ActionForward upItem(ActionMapping mapping, ActionForm form,
339:                    HttpServletRequest request, HttpServletResponse response)
340:                    throws Exception {
341:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
342:                PurchasingDocument purDocument = (PurchasingDocument) purchasingForm
343:                        .getDocument();
344:                int line = getSelectedLine(request);
345:                purDocument.itemSwap(line, line - 1);
346:
347:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
348:            }
349:
350:            /**
351:             * Moves the selected item down one position (These two methods up/down could easily be consolidated. For now, it seems more
352:             * straightforward to keep them separate.)
353:             * 
354:             * @param mapping An ActionMapping
355:             * @param form An ActionForm
356:             * @param request The HttpServletRequest
357:             * @param response The HttpServletResponse
358:             * @throws Exception
359:             * @return An ActionForward
360:             */
361:            public ActionForward downItem(ActionMapping mapping,
362:                    ActionForm form, HttpServletRequest request,
363:                    HttpServletResponse response) throws Exception {
364:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
365:                PurchasingDocument purDocument = (PurchasingDocument) purchasingForm
366:                        .getDocument();
367:                int line = getSelectedLine(request);
368:                purDocument.itemSwap(line, line + 1);
369:
370:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
371:            }
372:
373:            /**
374:             * Reveals the account distribution section.
375:             * 
376:             * @param mapping An ActionMapping
377:             * @param form An ActionForm
378:             * @param request The HttpServletRequest
379:             * @param response The HttpServletResponse
380:             * @throws Exception
381:             * @return An ActionForward
382:             */
383:            public ActionForward setupAccountDistribution(
384:                    ActionMapping mapping, ActionForm form,
385:                    HttpServletRequest request, HttpServletResponse response)
386:                    throws Exception {
387:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
388:
389:                purchasingForm.setHideDistributeAccounts(false);
390:
391:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
392:            }
393:
394:            /**
395:             * Clear out the accounting lines from all the items.
396:             * 
397:             * @param mapping An ActionMapping
398:             * @param form An ActionForm
399:             * @param request The HttpServletRequest
400:             * @param response The HttpServletResponse
401:             * @throws Exception
402:             * @return An ActionForward
403:             */
404:            public ActionForward removeAccounts(ActionMapping mapping,
405:                    ActionForm form, HttpServletRequest request,
406:                    HttpServletResponse response) throws Exception {
407:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
408:
409:                Object question = request
410:                        .getParameter(PurapConstants.QUESTION_INDEX);
411:                Object buttonClicked = request
412:                        .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
413:
414:                if (question == null) {
415:                    String questionText = SpringContext.getBean(
416:                            KualiConfigurationService.class).getPropertyString(
417:                            PurapConstants.QUESTION_REMOVE_ACCOUNTS);
418:
419:                    return this .performQuestionWithoutInput(mapping, form,
420:                            request, response,
421:                            PurapConstants.REMOVE_ACCOUNTS_QUESTION,
422:                            questionText, KFSConstants.CONFIRMATION_QUESTION,
423:                            KFSConstants.ROUTE_METHOD, "0");
424:                } else if (ConfirmationQuestion.YES.equals(buttonClicked)) {
425:                    for (PurApItem item : ((PurchasingAccountsPayableDocument) purchasingForm
426:                            .getDocument()).getItems()) {
427:                        item.getSourceAccountingLines().clear();
428:                    }
429:
430:                    GlobalVariables.getMessageList().add(
431:                            PurapKeyConstants.PURAP_GENERAL_ACCOUNTS_REMOVED);
432:                }
433:
434:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
435:            }
436:
437:            /**
438:             * Distribute accounting line(s) to the item(s). Does not distribute the accounting line(s) to an item if the item if there are
439:             * already accounting lines associated with that item, if the item is a below-the-line item and has no unit cost, or if the item
440:             * is inactive.
441:             * 
442:             * @param mapping An ActionMapping
443:             * @param form An ActionForm
444:             * @param request The HttpServletRequest
445:             * @param response The HttpServletResponse
446:             * @throws Exception
447:             * @return An ActionForward
448:             */
449:            public ActionForward doAccountDistribution(ActionMapping mapping,
450:                    ActionForm form, HttpServletRequest request,
451:                    HttpServletResponse response) throws Exception {
452:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
453:
454:                if (((PurchasingAccountsPayableDocument) purchasingForm
455:                        .getDocument()).getItems().size() > 0) {
456:                    if (purchasingForm
457:                            .getAccountDistributionsourceAccountingLines()
458:                            .size() > 0) {
459:                        for (PurApItem item : ((PurchasingAccountsPayableDocument) purchasingForm
460:                                .getDocument()).getItems()) {
461:                            BigDecimal zero = new BigDecimal(0);
462:                            boolean itemIsActive = true;
463:                            if (item instanceof  PurchaseOrderItem) {
464:                                // if item is PO item... only validate active items
465:                                itemIsActive = ((PurchaseOrderItem) item)
466:                                        .isItemActiveIndicator();
467:                            }
468:                            // We should be distributing accounting lines to above the line items all the time;
469:                            // but only to the below the line items when there is a unit cost.
470:                            boolean unitCostNotZeroForBelowLineItems = item
471:                                    .getItemType()
472:                                    .isItemTypeAboveTheLineIndicator() ? true
473:                                    : item.getItemUnitPrice() != null
474:                                            && zero.compareTo(item
475:                                                    .getItemUnitPrice()) < 0;
476:                            if (item.getSourceAccountingLines().size() == 0
477:                                    && unitCostNotZeroForBelowLineItems
478:                                    && itemIsActive) {
479:                                item
480:                                        .getSourceAccountingLines()
481:                                        .addAll(
482:                                                purchasingForm
483:                                                        .getAccountDistributionsourceAccountingLines());
484:                            }
485:                        }
486:                        purchasingForm
487:                                .getAccountDistributionsourceAccountingLines()
488:                                .clear();
489:                        GlobalVariables
490:                                .getMessageList()
491:                                .add(
492:                                        PurapKeyConstants.PURAP_GENERAL_ACCOUNTS_DISTRIBUTED);
493:                        purchasingForm.setHideDistributeAccounts(true);
494:                    } else {
495:                        GlobalVariables
496:                                .getErrorMap()
497:                                .putError(
498:                                        PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY,
499:                                        PurapKeyConstants.PURAP_GENERAL_NO_ACCOUNTS_TO_DISTRIBUTE);
500:                    }
501:                } else {
502:                    GlobalVariables
503:                            .getErrorMap()
504:                            .putError(
505:                                    PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY,
506:                                    PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO);
507:                }
508:
509:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
510:            }
511:
512:            /**
513:             * Simply hides the account distribution section.
514:             * 
515:             * @param mapping An ActionMapping
516:             * @param form An ActionForm
517:             * @param request The HttpServletRequest
518:             * @param response The HttpServletResponse
519:             * @throws Exception
520:             * @return An ActionForward
521:             */
522:            public ActionForward cancelAccountDistribution(
523:                    ActionMapping mapping, ActionForm form,
524:                    HttpServletRequest request, HttpServletResponse response)
525:                    throws Exception {
526:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
527:                purchasingForm.setHideDistributeAccounts(true);
528:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
529:            }
530:
531:            /**
532:             * @see org.kuali.module.purap.web.struts.action.PurchasingAccountsPayableActionBase#processCustomInsertAccountingLine(org.kuali.module.purap.web.struts.form.PurchasingAccountsPayableFormBase)
533:             */
534:            @Override
535:            public boolean processCustomInsertAccountingLine(
536:                    PurchasingAccountsPayableFormBase purapForm,
537:                    HttpServletRequest request) {
538:                boolean success = false;
539:                PurchasingFormBase purchasingForm = (PurchasingFormBase) purapForm;
540:
541:                // index of item selected
542:                int itemIndex = getSelectedLine(request);
543:                PurApItem item = null;
544:
545:                if (itemIndex == -2) {
546:                    PurApAccountingLine line = purchasingForm
547:                            .getAccountDistributionnewSourceLine();
548:                    purchasingForm
549:                            .addAccountDistributionsourceAccountingLine(line);
550:                    success = true;
551:                }
552:
553:                return success;
554:            }
555:
556:            /**
557:             * @see org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase#deleteSourceLine(org.apache.struts.action.ActionMapping,
558:             *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
559:             */
560:            @Override
561:            public ActionForward deleteSourceLine(ActionMapping mapping,
562:                    ActionForm form, HttpServletRequest request,
563:                    HttpServletResponse response) throws Exception {
564:                PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
565:
566:                String[] indexes = getSelectedLineForAccounts(request);
567:                int itemIndex = Integer.parseInt(indexes[0]);
568:                int accountIndex = Integer.parseInt(indexes[1]);
569:                if (itemIndex == -2) {
570:                    purchasingForm
571:                            .getAccountDistributionsourceAccountingLines()
572:                            .remove(accountIndex);
573:                } else {
574:                    PurApItem item = (PurApItem) ((PurchasingAccountsPayableDocument) purchasingForm
575:                            .getDocument()).getItem((itemIndex));
576:                    item.getSourceAccountingLines().remove(accountIndex);
577:                }
578:
579:                return mapping.findForward(KFSConstants.MAPPING_BASIC);
580:            }
581:
582:            /**
583:             * Sets the line for account distribution.
584:             * 
585:             * @param accountIndex The index of the account into the request parameter
586:             * @param purchasingAccountsPayableForm A form which inherits from PurchasingAccountsPayableFormBase
587:             * @return A SourceAccountingLine
588:             */
589:            protected SourceAccountingLine customAccountRetrieval(
590:                    int accountIndex,
591:                    PurchasingAccountsPayableFormBase purchasingAccountsPayableForm) {
592:                PurchasingFormBase purchasingForm = (PurchasingFormBase) purchasingAccountsPayableForm;
593:                SourceAccountingLine line;
594:                line = (SourceAccountingLine) ObjectUtils
595:                        .deepCopy(purchasingForm
596:                                .getAccountDistributionsourceAccountingLines()
597:                                .get(accountIndex));
598:                return line;
599:            }
600:        }
w___ww__.___j___a___v__a2___s_.__c_o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.