use of org.compiere.model.MResourceUnAvailable in project adempiere by adempiere.
the class CRPReasoner method getAvailableDate.
/**
* @param r resource
* @param dateTime
* @return next available date
*/
public Timestamp getAvailableDate(I_S_Resource r, Timestamp dateTime, boolean isScheduleBackward) {
MResourceType t = MResourceType.get(getCtx(r), r.getS_ResourceType_ID());
Timestamp date = dateTime;
ArrayList<Object> params = new ArrayList<Object>();
String whereClause;
String orderByClause;
int direction;
if (isScheduleBackward) {
whereClause = MResourceUnAvailable.COLUMNNAME_DateFrom + " <= ?";
params.add(date);
orderByClause = MResourceUnAvailable.COLUMNNAME_DateFrom + " DESC";
direction = 1;
} else {
whereClause = MResourceUnAvailable.COLUMNNAME_DateTo + " >= ?";
params.add(date);
orderByClause = MResourceUnAvailable.COLUMNNAME_DateTo;
direction = -1;
}
whereClause += " AND " + MResourceUnAvailable.COLUMNNAME_S_Resource_ID + "=? AND AD_Client_ID=?";
params.add(r.getS_Resource_ID());
params.add(r.getAD_Client_ID());
POResultSet<MResourceUnAvailable> rs = new Query(getCtx(r), MResourceUnAvailable.Table_Name, whereClause, null).setOrderBy(orderByClause).setParameters(params).scroll();
try {
while (rs.hasNext()) {
MResourceUnAvailable rua = rs.next();
if (rua.isUnAvailable(date)) {
date = TimeUtil.addDays(rua.getDateTo(), 1 * direction);
}
date = getAvailableDate(t, dateTime, isScheduleBackward);
}
} finally {
DB.close(rs);
}
//
date = getAvailableDate(t, dateTime, isScheduleBackward);
return date;
}
Aggregations