Coverage Report - edu.sampleu.bookstore.document.web.BookOrderAction
 
Classes in this File Line Coverage Branch Coverage Complexity
BookOrderAction
0%
0/39
0%
0/24
5
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package edu.sampleu.bookstore.document.web;
 17  
 
 18  
 import edu.sampleu.bookstore.bo.Book;
 19  
 import edu.sampleu.bookstore.bo.BookOrder;
 20  
 import edu.sampleu.bookstore.document.BookOrderDocument;
 21  
 import org.apache.struts.action.ActionForm;
 22  
 import org.apache.struts.action.ActionForward;
 23  
 import org.apache.struts.action.ActionMapping;
 24  
 import org.kuali.rice.core.api.util.type.KualiDecimal;
 25  
 import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
 26  
 import org.kuali.rice.kns.web.struts.form.KualiForm;
 27  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 28  
 
 29  
 import javax.servlet.http.HttpServletRequest;
 30  
 import javax.servlet.http.HttpServletResponse;
 31  
 
 32  
 /*
 33  
  * BookOrderAction class file for BookOrder maintenance Object
 34  
  * Actions prior to submit and post-Submit processes are handled.  
 35  
  */
 36  
 
 37  0
 public class BookOrderAction extends KualiTransactionalDocumentActionBase {
 38  
 
 39  
         public ActionForward addBookOrder(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 40  0
                 BookOrderForm form = (BookOrderForm) actionForm;
 41  0
         BookOrderDocument document = form.getBookOrderDocument();
 42  
 
 43  0
         BookOrder newBookEntry = form.getNewBookOrder();       
 44  0
         document.addBookOrder(newBookEntry);
 45  
         
 46  0
                 for (BookOrder entry : document.getBookOrders()) {
 47  0
                         if (entry.getBookId() != null) {
 48  0
                                 Book book = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(Book.class, entry.getBookId());
 49  
 
 50  0
                                 entry.setUnitPrice(book.getPrice());
 51  0
                                 Double totalPrice = 0.0d;
 52  0
                                 if (book.getPrice() != null && entry.getQuantity() != null) {
 53  0
                                         totalPrice = book.getPrice().doubleValue() * entry.getQuantity().intValue();
 54  0
                                         if (entry.getDiscount() != null        && entry.getDiscount().doubleValue() > 0) {
 55  0
                                                 totalPrice = totalPrice - (totalPrice * entry.getDiscount().doubleValue() / 100);
 56  
                                         }
 57  
                                 }
 58  0
                                 entry.setTotalPrice(new KualiDecimal(totalPrice));
 59  0
                         }
 60  
                 }
 61  
 
 62  
         // clear the used book order entry
 63  0
         form.setNewBookOrder(new BookOrder());
 64  
 
 65  0
         return mapping.findForward("basic");
 66  
     }
 67  
         
 68  
         public ActionForward deleteBookOrder(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
 69  0
         BookOrderForm form = (BookOrderForm) actionForm;
 70  0
         BookOrderDocument document = form.getBookOrderDocument();
 71  
         
 72  0
         int deleteIndex = getLineToDelete(request);
 73  0
         document.removeBookOrder(deleteIndex);
 74  
 
 75  0
         return mapping.findForward("basic");        
 76  
     }
 77  
 
 78  
         @Override
 79  
         protected void doProcessingAfterPost(KualiForm actionForm, HttpServletRequest request) {
 80  0
                 super.doProcessingAfterPost(actionForm, request);
 81  0
                 BookOrderForm form = (BookOrderForm) actionForm;
 82  0
         BookOrderDocument document = form.getBookOrderDocument();
 83  0
         for (BookOrder entry : document.getBookOrders()) {
 84  0
                 if(entry.getBookId() != null){
 85  0
                 Book book = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(Book.class, entry.getBookId());
 86  0
                 entry.setUnitPrice(book.getPrice());
 87  0
                         Double totalPrice = 0.0d;
 88  0
                         if (book.getPrice() != null && entry.getQuantity() != null) {
 89  0
                                 totalPrice = book.getPrice().doubleValue() * entry.getQuantity().intValue();
 90  0
                                 if (entry.getDiscount() != null && entry.getDiscount().doubleValue() > 0) {
 91  0
                                         totalPrice = totalPrice        - (totalPrice * entry.getDiscount().doubleValue() / 100);
 92  
                                 }
 93  
                         }
 94  0
                         entry.setTotalPrice(new KualiDecimal(totalPrice));
 95  0
                 entry.setBook(book);
 96  0
                 }
 97  
         }
 98  0
         }
 99  
 
 100  
         
 101  
     
 102  
     
 103  
         
 104  
 }