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 private CountingStock cs;
015 private String date;
016 private int nr;
017
018 /**
019 * @param date date of the order.
020 * @param nr order number, this parameter is necessary to distinguish between
021 * two or more orders placed on the same day.
022 * @param cs CountingStock with {@link CIArticle CIArticles} that are ordered.
023 */
024 public CIOpenPurchaseOrders(String date, int nr, CountingStock cs) {
025 super(date + " (" + new Integer(nr).toString() + ")");
026 this.date = date;
027 this.nr = nr;
028 this.cs = cs;
029 this.setValue(new IntegerValue(2 + new Double(4 * Math.random()).intValue()));
030 }
031
032 /**
033 * @return the date of the order.
034 */
035 public String getDate() {
036 return date;
037 }
038
039 /**
040 * @return the order number.
041 */
042 public int getOrderNumber() {
043 return nr;
044 }
045
046 /**
047 * @return the {@link CountingStock} with the orders.
048 */
049 public CountingStock getOrders() {
050 return cs;
051 }
052
053 /**
054 * @return the value of the orders.
055 */
056 public Double getOrdersValue() {
057 DoubleValue dv = new DoubleValue(0);
058 cs.sumStock(null, CatalogItemValue.EVALUATE_OFFER, dv);
059 return Conversions.valueToDouble(dv);
060 }
061
062 /**
063 * @return the number of days the market still has to wait for the delivery to arrive.
064 */
065 public int getDaysTillArrival() {
066 return new Integer(getValue().toString()).intValue();
067 }
068
069 /**
070 * Decreases the number of days the market has to wait for a delivery to arrive.
071 */
072 public void decreaseDaysTillArrival(int i) {
073 setValue(getValue().subtract(new IntegerValue(i)));
074 }
075
076 /**
077 * @return a clone of the given CatalogItemImpl.
078 */
079 protected CatalogItemImpl getShallowClone() {
080 return new CIOpenPurchaseOrders(date, nr, cs);
081 }
082 }