| 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 | 0 | public OrderSelection(Selectable orders, List orderStatus, Affiliate affiliate, Date startDate, Date endDate) { |
| 22 | 0 | this.endDate = endDate; |
| 23 | 0 | _orders = (Table)orders; |
| 24 | 0 | _orderStatus = orderStatus; |
| 25 | 0 | this.affiliate = affiliate; |
| 26 | 0 | this.startDate = startDate; |
| 27 | 0 | } |
| 28 | |
|
| 29 | |
public void visitEach(Command command) { |
| 30 | 0 | String selection = ""; |
| 31 | 0 | if (affiliate != null) { |
| 32 | 0 | selection += "affiliate="+ affiliate.getTroid(); |
| 33 | |
} |
| 34 | 0 | if (startDate != null) { |
| 35 | 0 | selection += " and date >= " + JammyJoesUtil.formatDateForPostgresSQL(startDate); |
| 36 | |
} |
| 37 | 0 | if (endDate != null) { |
| 38 | 0 | selection += " and date < " + JammyJoesUtil.formatDateForPostgresSQL(endDate); |
| 39 | |
} |
| 40 | 0 | Enumeration enumeration = _orders.selection(); |
| 41 | 0 | while (enumeration.hasMoreElements()) { |
| 42 | 0 | ShopOrder order = (ShopOrder) enumeration.nextElement(); |
| 43 | 0 | if (order.hasStatus(_orderStatus)) { |
| 44 | 0 | command.visit(order); |
| 45 | |
} |
| 46 | 0 | } |
| 47 | |
|
| 48 | 0 | } |
| 49 | |
} |