Coverage Report - org.paneris.jammyjoes.model.ShopOrder
 
Classes in this File Line Coverage Branch Coverage Complexity
ShopOrder
0%
0/50
0%
0/30
2.385
 
 1  
 package org.paneris.jammyjoes.model;
 2  
 
 3  
 import java.sql.Timestamp;
 4  
 import java.util.Enumeration;
 5  
 import java.util.HashSet;
 6  
 import java.util.Iterator;
 7  
 import java.util.List;
 8  
 import java.util.Set;
 9  
 
 10  
 import org.melati.poem.AccessPoemException;
 11  
 import org.paneris.jammyjoes.model.generated.ShopOrderBase;
 12  
 import org.paneris.jammyjoes.mvp.AffiliateTotals;
 13  
 import org.paneris.jammyjoes.util.JammyJoesUtil;
 14  
 
 15  
 public class ShopOrder extends ShopOrderBase implements Graphable {
 16  0
   public ShopOrder() {
 17  0
   }
 18  
 
 19  
   public void total(AffiliateTotals totals) {
 20  0
     totals.total(getAmountForGraph());
 21  0
     totals.commission(getComissionAmount());
 22  0
     if (getAffiliatepaid().booleanValue()) {
 23  0
       totals.paidCommission(getComissionAmount());
 24  
     } else {
 25  0
       totals.outstandingCommission(getComissionAmount());
 26  
     }
 27  0
   }
 28  
   
 29  
   public double getComissionAmount() {
 30  0
     if (getComission() == null) {
 31  0
       return 0d;
 32  
     }
 33  0
     return JammyJoesUtil.roundTo2dp(getAmountForGraph() * getComission().doubleValue() / 100);
 34  
   }
 35  
 
 36  
   public double getWrappingAmount() {
 37  0
     if (getHasWrapping()) {
 38  0
       return WrappingTable.WRAPPING_COST;
 39  
     } else {
 40  0
       return 0d;
 41  
     }
 42  
   }
 43  
 
 44  
   public boolean getHasWrapping() {
 45  0
     if (getWrapping() == null)
 46  0
       return false;
 47  0
     WrappingTable wrappingTable = getJammyjoesDatabaseTables().getWrappingTable();
 48  0
     if (getWrapping().equals(wrappingTable.getNoWrapping()))
 49  0
       return false;
 50  0
     return true;
 51  
   }
 52  
 
 53  
   public double getAmountForGraph() {
 54  0
     return getAmountUK().doubleValue() - getDeliveryUK().doubleValue();
 55  
   }
 56  
 
 57  
   public Enumeration getItems() {
 58  0
     return getJammyjoesDatabaseTables().getShopOrderItemTable().getOrderColumn().selectionWhereEq(
 59  
       troid());
 60  
   }
 61  
 
 62  
   public boolean hasStatus(List statuses) {
 63  0
     Iterator iter = statuses.iterator();
 64  0
     while (iter.hasNext()) {
 65  0
       OrderStatus status = (OrderStatus) iter.next();
 66  0
       if (getStatus().equals(status))
 67  0
         return true;
 68  0
     }
 69  0
     return false;
 70  
   }
 71  
 
 72  
   // get rid of any previously failed orders and purchases
 73  
   public void removeItems() {
 74  0
     if (troid() != null) {
 75  0
       Set toRemove = new HashSet();
 76  0
       for (Enumeration en = getItems(); en.hasMoreElements();) {
 77  0
         toRemove.add(en.nextElement());
 78  
       }
 79  0
       for (Iterator it = toRemove.iterator(); it.hasNext();) {
 80  0
         ShopOrderItem item = (ShopOrderItem) it.next();
 81  0
         item.deleteAndCommit();
 82  0
       }
 83  
     }
 84  0
   }
 85  
 
 86  
   protected void writeLock() {
 87  0
     super.writeLock();
 88  0
     if (getDate_unsafe() == null) {
 89  0
       setDate_unsafe(now());
 90  
     }
 91  0
   }
 92  
 
 93  
   private static java.sql.Timestamp now() {
 94  0
     return new java.sql.Timestamp(new java.util.Date().getTime());
 95  
   }
 96  
 
 97  
   public void setStatus(OrderStatus cooked) throws AccessPoemException {
 98  0
     if (getFufilleddate_unsafe() == null
 99  
       && cooked == getJammyjoesDatabaseTables().getOrderStatusTable().getFufilled()) {
 100  0
       setFufilleddate_unsafe(now());
 101  
     }
 102  0
     super.setStatus(cooked);
 103  0
   }
 104  
 
 105  
   public void setFufilleddate_unsafe(Timestamp cooked) {
 106  
     // avoid nulling it if the flag is set
 107  0
     if (getStatus() != getJammyjoesDatabaseTables().getOrderStatusTable().getFufilled()
 108  
       || cooked != null) {
 109  0
       super.setFufilleddate_unsafe(cooked);
 110  
     }
 111  0
   }
 112  
 
 113  
 }