public void reversalDateVCE(ValueChangeEvent vce) {
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
try {
Row rHdr = CommonCode.getCurrentRowByIteratorName("FaTransHdr1Iterator");
oracle.jbo.domain.Date vchDT = (oracle.jbo.domain.Date)rHdr.getAttribute("VchDt");
oracle.jbo.domain.Date reversalDT = (oracle.jbo.domain.Date)rHdr.getAttribute("AutoReversalDt");
/* oracle.jbo.domain.Date thirtyDaysAfter = CommonCode.addDayToOracleDate(vchDT, 30);
// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYYY");
System.out.println("reversaldt@ : " + reversalDT + " thirtyDaysAfter: " + thirtyDaysAfter);
java.util.Date vchDTUtil = CommonCode.convertOracleDateToJavaUtilDate(vchDT);
java.util.Date thirtyDaysAfterUtil = CommonCode.convertOracleDateToJavaUtilDate(thirtyDaysAfter); */
/* if (vchDTUtil.after(thirtyDaysAfterUtil)) {
CommonCode.infomsg(reversalDT + " is greater than 30 days!","");
} */
Long daysDiff =CommonCode.getDifferenceDaysBetweenTwoDates(reversalDT,vchDT);
System.out.println(reversalDT+ " :reversalDT - vchDT : "+vchDT + "daysDiff = "+daysDiff);
if(daysDiff > 30){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date d1 = null;
try {
d1 = sdf.parse(reversalDT.toString());
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd/MMM/yyyy");
String date = dateFormat2.format(d1);
CommonCode.infomsg(date+ " is greater than 30 days!","");
}
} catch (NullPointerException npe) {
CommonCode.showExceptionMessage(npe);
} catch (Exception e) {
CommonCode.showExceptionMessage(e);
}
}
/
//added by Naren
public static java.util.Date convertOracleDateToJavaUtilDate(oracle.jbo.domain.Date oracleDate) {
if (oracleDate == null)
return null;
java.sql.Date javaSqlDate = oracleDate.dateValue();
long javaMilliSeconds = javaSqlDate.getTime();
return new java.util.Date(javaMilliSeconds);
}
//added by Naren
public static oracle.jbo.domain.Date addDayToOracleDate(oracle.jbo.domain.Date date, int days) {
if (date != null) {
Calendar c1 = Calendar.getInstance();
c1.setTime(date.getValue());
c1.add(Calendar.DATE, days);
java.util.Date javaUtilDate = c1.getTime();
long javaMilliseconds = javaUtilDate.getTime();
java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
return new oracle.jbo.domain.Date(javaSqlDate);
}
return null;
}
public static long getDifferenceDaysBetweenTwoDates(oracle.jbo.domain.Date d1, oracle.jbo.domain.Date d2)
{
if(d1 != null && d2 != null)
{
return (d1.getValue().getTime() - d2.getValue().getTime())/(24 * 60 * 60 * 1000);
}
return 0;
}
/
[15:57] NARENDRA ENAMALA
public void frmDtChange(ValueChangeEvent vce) {
Date d1;
if(vce.getNewValue()!=null){
d1 = (Date)vce.getNewValue();
if (this.getId2().getValue() != null) {
Date d2 = (Date)this.getId2().getValue();
if (d1.getValue().after(d2.getValue())) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("From Date cannot be greater than To Date");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(this.getId1().getClientId(), fm);
}
}
}
}
[15:57] NARENDRA ENAMALA
public void toDtChange(ValueChangeEvent vce) {
Date d1;
if(vce.getNewValue()!=null){
d1 = (Date)vce.getNewValue();
if (this.getId1().getValue() != null) {
Date d2 = (Date)this.getId1().getValue();
if (d1.getValue().before(d2.getValue())) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("To Date cannot be less than From Date");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(this.getId2().getClientId(), fm);
}
}
}
}
---- from dt and To date timestamp validations
public void fromDateVce(ValueChangeEvent vce) {
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
/* if (vce.getNewValue() != null) {
Row hdrRow = ReusableMethodsClass.getCurrentRowFromVO("PrCancelHdrVo1");
Timestamp frmDt = (Timestamp) hdrRow.getAttribute("PrFromDate");
Timestamp toDt = (Timestamp) hdrRow.getAttribute("PrToDate");
if (frmDt !=null && toDt != null && frmDt.compareTo(toDt)==1 ) {
CommonCode.errmsg("From Date should not be greater than To Date.", "");
return ;
}
} */
oracle.jbo.domain.Date d1;
if(vce.getNewValue()!=null){
java.sql.Timestamp tmpFrom = (java.sql.Timestamp)getId1().getValue();
java.util.Date dateUtilFrom = new java.util.Date(tmpFrom.getTime());
System.out.println(vce.getNewValue()+":from vce.getNewValue() this.getId1().getValue():"+this.getId1().getValue()+" dateUtilFrom :"+dateUtilFrom);
d1 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilFrom); //vce.getNewValue();
System.out.println("from Job Domine Date D1 : "+d1);
if (this.getId2().getValue() != null) {
//oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)this.getId2().getValue();
java.sql.Timestamp tmpTo = (java.sql.Timestamp)getId2().getValue();
java.util.Date dateUtilTo = new java.util.Date(tmpTo.getTime());
oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilTo);
System.out.println("from Job Domine Date D2 : "+d2);
if (d1.getValue().after(d2.getValue())) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("From Date cannot be greater than To Date");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(this.getId1().getClientId(), fm);
}
}
}
}
public void toDateVce(ValueChangeEvent vce) {
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
oracle.jbo.domain.Date d1;
if(vce.getNewValue()!=null){
System.out.println(vce.getNewValue()+":to vce.getNewValue() this.getId2().getValue():"+this.getId2().getValue());
// java.sql.Date javaSqlDate = new java.sql.Date(vce.getNewValue());
// d1 = (oracle.jbo.domain.Date)this.getId2().getValue();
java.sql.Timestamp tmpTo = (java.sql.Timestamp)getId2().getValue();
java.util.Date dateUtilTo = new java.util.Date(tmpTo.getTime());
System.out.println(vce.getNewValue()+":@to vce.getNewValue() this.getId1().getValue():"+this.getId1().getValue()+" dateUtilFrom :"+dateUtilTo);
d1 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilTo);
System.out.println("to Job Domine Date D1 : "+d1);
if (this.getId1().getValue() != null) {
// oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)this.getId1().getValue();
java.sql.Timestamp tmpFrom = (java.sql.Timestamp)getId1().getValue();
java.util.Date dateUtilFrom = new java.util.Date(tmpFrom.getTime());
oracle.jbo.domain.Date d2 = (oracle.jbo.domain.Date)convertJavaUtilDateToOracleDate(dateUtilFrom);
System.out.println(" @to Job Domine Date D2 : "+d2);
if (d1.getValue().before(d2.getValue())) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("To Date cannot be less than From Date");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(this.getId2().getClientId(), fm);
}
oracle.jbo.domain.Date currdate = getCurrentOracleDate();
System.out.println("currdate.getValue() :"+currdate.getValue()+" currdate :"+currdate);
if (d1.getValue().after(currdate.getValue())) {
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("To Date cannot be Future Date");
fm.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(this.getId2().getClientId(), fm);
}
}
}
}
/** function receive java.util date and convert it to oracle date then return oracle date */
public static Date convertJavaUtilDateToOracleDate(java.util.Date javaUtilDate)
{
if(javaUtilDate == null)
return null;
long javaMilliseconds = javaUtilDate.getTime();
java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
return new oracle.jbo.domain.Date(javaSqlDate);
}
/** function will return current date as an oracle Date object */
public static oracle.jbo.domain.Date getCurrentOracleDate()
{
return new oracle.jbo.domain.Date(oracle.jbo.domain.Date.getCurrentDate());
}
/
public static oracle.jbo.domain.Date castToJBODate(String aDate) {
DateFormat formatter;
SimpleDateFormat dateFormat;
java.util.Date date;
if (aDate != null) {
try {
//formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss ");
dateFormat = new SimpleDateFormat("dd/MM/yyyy");
//date = formatter.parse(aDate);
date = (java.util.Date)dateFormat.parse(aDate);
System.out.println("Sql Date:" + date.getTime() + " : " + date);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
java.sql.Date timestamp = new java.sql.Date(date.getTime());
System.out.println("Date after :" + sqlDate);
//oracle.jbo.domain.Timestamp jboDate = new oracle.jbo.domain.Timestamp(sqlDate);
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(timestamp);
System.out.println("Jbo Date:" + jboDate);
return jboDate;
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}