Search in sources :

Example 1 with MResourceUnAvailable

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;
}
Also used : Query(org.compiere.model.Query) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MResourceType(org.compiere.model.MResourceType) MResourceUnAvailable(org.compiere.model.MResourceUnAvailable)

Aggregations

Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 MResourceType (org.compiere.model.MResourceType)1 MResourceUnAvailable (org.compiere.model.MResourceUnAvailable)1 Query (org.compiere.model.Query)1