001 package market; 002 003 import data.CatalogItemValue; 004 import data.CountingStock; 005 import data.DoubleValue; 006 import data.IntegerValue; 007 import data.ooimpl.CatalogItemImpl; 008 009 /** 010 * A purchase order placed by the manager, which has not yet arrived. 011 */ 012 public class CIOpenPurchaseOrders extends CatalogItemImpl { 013 014 /** 015 * ID for serialization. 016 */ 017 private static final long serialVersionUID = -2036308093034056202L; 018 019 private CountingStock cs; 020 private String date; 021 private int nr; 022 023 /** 024 * @param date date of the order. 025 * @param nr order number, this parameter is necessary to distinguish between 026 * two or more orders placed on the same day. 027 * @param cs CountingStock with {@link CIArticle CIArticles} that are ordered. 028 */ 029 public CIOpenPurchaseOrders(String date, int nr, CountingStock cs) { 030 super(date + " (" + new Integer(nr).toString() + ")"); 031 this.date = date; 032 this.nr = nr; 033 this.cs = cs; 034 this.setValue(new IntegerValue(2 + new Double(4 * Math.random()).intValue())); 035 } 036 037 /** 038 * @return the date of the order. 039 */ 040 public String getDate() { 041 return date; 042 } 043 044 /** 045 * @return the order number. 046 */ 047 public int getOrderNumber() { 048 return nr; 049 } 050 051 /** 052 * @return the {@link CountingStock} with the orders. 053 */ 054 public CountingStock getOrders() { 055 return cs; 056 } 057 058 /** 059 * @return the value of the orders. 060 */ 061 public Double getOrdersValue() { 062 DoubleValue dv = new DoubleValue(0); 063 cs.sumStock(null, CatalogItemValue.EVALUATE_OFFER, dv); 064 return Conversions.valueToDouble(dv); 065 } 066 067 /** 068 * @return the number of days the market still has to wait for the delivery to arrive. 069 */ 070 public int getDaysTillArrival() { 071 return new Integer(getValue().toString()).intValue(); 072 } 073 074 /** 075 * Decreases the number of days the market has to wait for a delivery to arrive. 076 */ 077 public void decreaseDaysTillArrival(int i) { 078 setValue(getValue().subtract(new IntegerValue(i))); 079 } 080 081 /** 082 * @return a clone of the given CatalogItemImpl. 083 */ 084 protected CatalogItemImpl getShallowClone() { 085 return new CIOpenPurchaseOrders(date, nr, cs); 086 } 087 }