Coverage Report - org.paneris.bibliomania.shopping.BibliomaniaShoppingTrolleyItem
 
Classes in this File Line Coverage Branch Coverage Complexity
BibliomaniaShoppingTrolleyItem
0%
0/49
0%
0/18
2.111
 
 1  
 package org.paneris.bibliomania.shopping;
 2  
 
 3  
 import java.util.Enumeration;
 4  
 
 5  
 import org.melati.Melati;
 6  
 import org.paneris.bibliomania.BibliomaniaDatabase;
 7  
 import org.paneris.bibliomania.Book;
 8  
 import org.paneris.bibliomania.DeliveryCharge;
 9  
 import org.paneris.bibliomania.DeliveryChargeBand;
 10  
 import org.paneris.bibliomania.Product;
 11  
 import org.paneris.bibliomania.ShopOrder;
 12  
 import org.paneris.bibliomania.ShopOrderItem;
 13  
 import org.paneris.melati.shopping.ShoppingTrolley;
 14  
 import org.paneris.melati.shopping.ShoppingTrolleyItem;
 15  
 
 16  0
 public class BibliomaniaShoppingTrolleyItem extends ShoppingTrolleyItem {
 17  
 
 18  
   private Product product;
 19  0
   private DeliveryCharge charge = null;
 20  0
   private boolean gotCharge = false;
 21  
   //private boolean download = false; // when we sell downloads
 22  
   private BibliomaniaShoppingTrolley bibShoppingTrolley;
 23  
   
 24  
   public void initialise(ShoppingTrolley trolleyP, Melati melatiP,
 25  
                          Integer idP, String descriptionP, Double priceP) {
 26  0
     super.initialise(trolleyP, melatiP, idP, descriptionP, priceP);
 27  0
     bibShoppingTrolley = (BibliomaniaShoppingTrolley)trolley;
 28  0
   }  
 29  
   
 30  
  /**
 31  
   * Load in information about this product given an id.  
 32  
   * Perhaps this id represents a poem troid?
 33  
   */
 34  
   protected void load(Integer idP){
 35  0
     BibliomaniaDatabase db = (BibliomaniaDatabase)melati.getDatabase();
 36  0
     product = (Product)db.getProductTable().getIdColumn().firstWhereEq(idP);
 37  0
     description = product.getName();
 38  0
     if ((description == null || description.equals("")) && product.getBook() != null)
 39  0
       description = product.getBook().getTitle();
 40  0
     price = 0;
 41  0
     if (product.getPrice() != null) price = product.getPrice().doubleValue();
 42  
     //if (product.getDownload() != null) download = true;
 43  0
   }
 44  
     
 45  
   protected void save(BibliomaniaDatabase db, ShopOrder order){
 46  0
     ShopOrderItem item = (ShopOrderItem)db.getShopOrderItemTable().newPersistent();
 47  0
     item.setUser(order.getUser());
 48  0
     item.setOrder(order);
 49  0
     item.setProduct(product);
 50  0
     item.setQuantity((new Double(getQuantity())).intValue());
 51  0
     item.setAmount(bibShoppingTrolley.convertFromUK(price * quantity));
 52  0
     item.setDelivery(bibShoppingTrolley.convertFromUK(getDeliveryValue()));
 53  0
     item.setAmountUK(price * quantity);
 54  0
     item.setDeliveryUK(getDeliveryValue());
 55  0
     item.setStatus(db.getOrderStatusTable().getNotAuthorised());
 56  0
     item.setSupplierTroid(new Integer(0));
 57  0
     db.getShopOrderItemTable().create(item);
 58  0
   }
 59  
     
 60  
  /**
 61  
   * Work out the cost of delivery.
 62  
   * Returns null if a charge cannot be calculated - an error should be displayed.
 63  
   */
 64  
   public double getDeliveryValue() {
 65  0
     getDeliveryCharge();
 66  0
     double cost = 0;
 67  
     // can't get a charge - indicate error by returning null
 68  0
     if (charge != null) {
 69  0
       cost = charge.getCharge().doubleValue();
 70  
     }
 71  0
     return cost * quantity;
 72  
   }
 73  
     
 74  
     
 75  
  /**
 76  
   * Work out the cost of delivery.
 77  
   * Returns null if a charge cannot be calculated - an error should be displayed.
 78  
   */
 79  
   public DeliveryCharge getDeliveryCharge() {
 80  0
     if (gotCharge) return charge;
 81  0
     charge = null;
 82  0
     if (bibShoppingTrolley.countryCode != null) {
 83  0
       DeliveryChargeBand band = bibShoppingTrolley.countryCode.getDeliverycharge();
 84  0
       if (band != null) {
 85  0
         BibliomaniaDatabase db = (BibliomaniaDatabase)melati.getDatabase();
 86  0
         String whereClause = "band = " + band.getTroid() + " and supplier in " +
 87  
         " (select supplier from supplierproduct where product = " + product.getTroid() + ")";
 88  0
         String orderClause = "charge";
 89  0
         Enumeration them = db.getDeliveryChargeTable().selection
 90  
                  (whereClause, orderClause, false);
 91  0
         if (them.hasMoreElements()) charge = (DeliveryCharge)them.nextElement();
 92  
       }
 93  
     }
 94  0
     gotCharge = true;
 95  0
     return charge;
 96  
   }
 97  
 
 98  
   public void setGotCharge(boolean c) {
 99  0
     gotCharge = c;
 100  0
   }
 101  
   
 102  
   public Book getBook() {
 103  0
     return product.getBook();
 104  
   }
 105  
   
 106  
   public Product getProduct() {
 107  0
     return product;
 108  
   }
 109  
 
 110  
   public String displayCurrency(double value) {
 111  0
     return bibShoppingTrolley.convertFromUKandFormat(value);
 112  
   }
 113  
 
 114  
 }
 115