| 1 | |
package org.paneris.jammyjoes.model; |
| 2 | |
|
| 3 | |
import java.util.Enumeration; |
| 4 | |
|
| 5 | |
import org.paneris.jammyjoes.model.generated.DeliveryZoneBase; |
| 6 | |
import org.paneris.jammyjoes.util.JammyJoesUtil; |
| 7 | |
|
| 8 | |
public class DeliveryZone extends DeliveryZoneBase { |
| 9 | 0 | public DeliveryZone() { |
| 10 | 0 | } |
| 11 | |
|
| 12 | |
public String quote(String in) { |
| 13 | 0 | return getDatabase().getDbms().getQuotedName(in); |
| 14 | |
} |
| 15 | |
|
| 16 | |
public DeliveryCharge getMaxCharge() { |
| 17 | 0 | Enumeration e = |
| 18 | |
getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( |
| 19 | |
quote("zone") + " = " + this.getTroid(), |
| 20 | |
quote("weight") + " desc", |
| 21 | |
true); |
| 22 | 0 | if (e.hasMoreElements()) |
| 23 | 0 | return (DeliveryCharge) e.nextElement(); |
| 24 | 0 | return null; |
| 25 | |
} |
| 26 | |
|
| 27 | |
public DeliveryCharge getCharge(double weight) { |
| 28 | 0 | Enumeration e = |
| 29 | |
getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( |
| 30 | |
quote("zone") + " = " + this.getTroid() + " AND " + quote("weight") + " > " + weight, |
| 31 | |
quote("weight") + " asc", |
| 32 | |
true); |
| 33 | 0 | if (e.hasMoreElements()) |
| 34 | 0 | return (DeliveryCharge) e.nextElement(); |
| 35 | 0 | return null; |
| 36 | |
} |
| 37 | |
|
| 38 | |
public DeliveryCharge getChargeValue(double v) { |
| 39 | 0 | double value = JammyJoesUtil.roundTo2dp(v); |
| 40 | 0 | Enumeration e = |
| 41 | |
getJammyjoesDatabaseTables().getDeliveryChargeTable().selection( |
| 42 | |
quote("zone") + " = " + this.getTroid() + " AND " + quote("weight") + " < " + value, |
| 43 | |
quote("weight") + " desc", |
| 44 | |
true); |
| 45 | 0 | if (e.hasMoreElements()) |
| 46 | 0 | return (DeliveryCharge) e.nextElement(); |
| 47 | 0 | return null; |
| 48 | |
} |
| 49 | |
} |