1 4 package com.nightlabs.ipanema.trade; 5 6 import java.util.Iterator ; 7 8 import javax.jdo.JDOHelper; 9 import javax.jdo.PersistenceManager; 10 11 import com.nightlabs.ipanema.accounting.Accounting; 12 import com.nightlabs.ipanema.accounting.AccountingPriceConfig; 13 import com.nightlabs.ipanema.accounting.PriceFragment; 14 15 16 30 public class OfferItemPrice extends com.nightlabs.ipanema.accounting.Price 31 { 32 33 private com.nightlabs.ipanema.accounting.Price origPrice; 34 35 protected OfferItemPrice() { } 36 37 41 public OfferItemPrice( 42 com.nightlabs.ipanema.accounting.Price origPrice, 43 String organisationID, long priceConfigID, 44 long priceID, boolean refund) 45 { 46 super(organisationID, priceConfigID, priceID, origPrice.getCurrency()); 47 48 this.origPrice = origPrice; 49 assign(origPrice); 50 51 if (refund) 52 negate(); 53 } 54 55 60 protected void assign(com.nightlabs.ipanema.accounting.Price origPrice) 61 { 62 if (!getCurrency().getCurrencyID().equals(origPrice.getCurrency().getCurrencyID())) 63 throw new IllegalArgumentException ("Currencies do not match!"); 64 65 this.setAmount(origPrice.getAmount()); 66 67 for (Iterator it = origPrice.getFragments().iterator(); it.hasNext(); ) { 68 PriceFragment origpf = (PriceFragment)it.next(); 69 PriceFragment pf = new PriceFragment(this, origpf); 70 } 74 } 75 76 protected void negate() 77 { 78 this.setAmount(-this.getAmount()); 79 for (Iterator it = this.getFragments().iterator(); it.hasNext(); ) { 80 PriceFragment pf = (PriceFragment)it.next(); 81 pf.setAmount(-pf.getAmount()); 82 } 83 } 84 85 95 public OfferItemPrice createRefundPrice() 96 { 97 PersistenceManager pm = JDOHelper.getPersistenceManager(this); 98 if (pm == null) 99 throw new IllegalStateException ("This instance of OfferItemPrice is currently not persistent!"); 100 101 Accounting accounting = Accounting.getAccounting(pm); 102 AccountingPriceConfig accountingPriceConfig = accounting.getAccountingPriceConfig(); 103 104 OfferItemPrice offerItemPrice = new OfferItemPrice( 105 this, 106 accounting.getOrganisationID(), 107 accountingPriceConfig.getPriceConfigID(), 108 accountingPriceConfig.createPriceID(), true); 109 return offerItemPrice; 110 } 111 112 } 113 | Popular Tags |