1 package org.paneris.jammyjoes.mvp; 2 3 import java.util.Date; 4 import java.util.Enumeration; 5 import java.util.List; 6 7 import org.melati.poem.Selectable; 8 import org.melati.poem.Table; 9 import org.paneris.jammyjoes.model.Affiliate; 10 import org.paneris.jammyjoes.model.ShopOrder; 11 import org.paneris.jammyjoes.util.JammyJoesUtil; 12 13 public class OrderSelection implements Selection { 14 15 private Table _orders; 16 private List _orderStatus; 17 private final Affiliate affiliate; 18 private final Date startDate; 19 private final Date endDate; 20 21 public OrderSelection(Selectable orders, List orderStatus, Affiliate affiliate, Date startDate, Date endDate) { 22 this.endDate = endDate; 23 _orders = (Table)orders; 24 _orderStatus = orderStatus; 25 this.affiliate = affiliate; 26 this.startDate = startDate; 27 } 28 29 public void visitEach(Command command) { 30 String selection = ""; 31 if (affiliate != null) { 32 selection += "affiliate="+ affiliate.getTroid(); 33 } 34 if (startDate != null) { 35 selection += " and date >= " + JammyJoesUtil.formatDateForPostgresSQL(startDate); 36 } 37 if (endDate != null) { 38 selection += " and date < " + JammyJoesUtil.formatDateForPostgresSQL(endDate); 39 } 40 Enumeration enumeration = _orders.selection(); 41 while (enumeration.hasMoreElements()) { 42 ShopOrder order = (ShopOrder) enumeration.nextElement(); 43 if (order.hasStatus(_orderStatus)) { 44 command.visit(order); 45 } 46 } 47 48 } 49 }