addMonthsSQLDate(String dbType, String dateField, int months) method returns a script which adds the given number of months to the given date field. It works for both SQL and Hibernate queries.
public ArrayList<CRMDO> loadEffectiveAfterAMonth(Date asOfDate){
ArrayList<Object> values = new ArrayList<Object>();
String dbType = getCRMSession().getDbtype();
if(expirationDate!=null)
{
values.add(asOfDate);
criteria+= " and " + DateUtil.addMonthsSQLDate(dbType, DateUtil.getSelectSQLDate(dbType, getDOName().toLowerCase() + ".effectiveDate"),1)+"<=:p"+values.size();
criteria+= " and " + DateUtil.addMonthsSQLDate(dbType, DateUtil.getSelectSQLDate(dbType, getDOName().toLowerCase() + ".expirationDate"),1)+">:p"+values.size();
}
return load(getDOName().toLowerCase() + ".isDeleted=0" +criteria,
values,
getDefaultAssociations(),
null,
null);
}
public Boolean isEffectiveAfterAMonth(CUSTOMCRMDORentalType rentalType, CRMDODate asOfDate){
String dbtype = getCRMSession().getDbtype();
String sql =
"\n SELECT RENTTYPEID FROM TRN_RENTALTYPES RT " +
"\n WHERE RT.RENTTYPEID = ?" +
"\n AND PV.PRODVALIDITYDELETED = 0 " +
"\n AND " + DateUtil.addMonthsSQLDate(dbType,DateUtil.getSelectSQLDate(dbtype, "RT.RENTTYPEEFFECTIVEDATE"),1) + " <= " + DateUtil.getSQLDate(dbtype, asOfDate) +
"\n AND " + DateUtil.addMonthsSQLDate(dbType,DateUtil.getSelectSQLDate(dbtype, "RT.RENTTYPEEXPIRATIONDATE"),1) + " > " + DateUtil.getSQLDate(dbtype, asOfDate) +
ArrayList<Object> parameters = new ArrayList<Object>();
parameters.add(rentalType.getId());
if (SQLUtil.queryReturnedRows(sql, getOrganisationID(), parameters, dbType))
{
return new Boolean(true);
}
return new Boolean(false);
}
The following method works in a corresponding way:
addDaysSQLDate(String dbType, String dateField, int days) method returns a script which adds the given number of days to the given date field. It works for both SQL and Hibernate queries.