We have two dates, the status date: rcareviewdate and Etc date:rcainprgdate. The script below calculates the duration in Hours excluding weekends between these two dates based on attribute status date change.
When we change the status it will calculate overdue for previous status ETC date and current status change date.
Launch Point Type: Attribute Launch Point
Attribute: CHANGEDATE
#Imports
from java.util import Datefrom java.text import SimpleDateFormatfrom psdi.mbo import MboConstantsfrom psdi.server import MXServerfrom java.util import Calendarfrom psdi.app.common import DateUtility#Milliseconds ConstantsMILLISECONDS_DAY= 86400000MILLISECONDS_HOUR = 3600000MILLISECONDS_MINUTE = 60000#Default hours and minutes valuesdays = 0hours = 0#calculate Estimated Durationif not mbo.isNull('CHANGEDATE') and mbo.getString("STATUS") in ["RCAREVIEW"] :FRACSet = MXServer.getMXServer().getMboSet("FRACSTATUS", mbo.getUserInfo())FRACSet.setWhere("FRACASNUM='"+ mbo.getString("FRACASNUM")+"' and STATUS='RCAINPROG' ")rcainprg = FRACSet.moveLast()rcainprgdate=rcainprg.getDate('FRACASETC')rcareviewdate=mbo.getDate('CHANGEDATE')if rcareviewdate >= rcainprgdate:cal2 = Calendar.getInstance();cal = Calendar.getInstance();cal2.setTime(rcareviewdate)etcdate=rcainprgdate.getTime()cal.setTime(rcainprgdate)if (cal2.get(cal2.DAY_OF_WEEK)) in [cal2.FRIDAY]:rcareviewdate = DateUtility.getDate(rcareviewdate)if (cal2.get(cal2.DAY_OF_WEEK)) in [cal2.SATURDAY]:rcareviewdate = DateUtility.addDays(rcareviewdate,-1)rcareviewdate = DateUtility.getDate(rcareviewdate)cal = Calendar.getInstance();cal2.setTime(rcareviewdate)cal.setTime(rcainprgdate)diff = rcareviewdate.getTime() - rcainprgdate.getTime()#Gets the days hours and minutes from the milliseconds differencedays= long(diff)/MILLISECONDS_DAYhours = long(diff) / MILLISECONDS_HOURminutes = (long(diff) / MILLISECONDS_MINUTE) - (long(hours) * 60)loop=1days=abs(days)overdue=hourswhile (loop<=days):cal.add(cal.DATE, +1)if (cal.get(cal.DAY_OF_WEEK)) in [cal.FRIDAY,cal.SATURDAY] :overdue=overdue-24#Sets Estimated Duration value as String without access checkloop=loop+1if SimpleDateFormat("MM/dd/yyyy").format(rcareviewdate) ==SimpleDateFormat("MM/dd/yyyy").format(rcainprgdate):rcainprg.setValue("OVERDUEDURATION",str(hours) + ':' + str(minutes), MboConstants.NOACCESSCHECK)else:rcainprg.setValue("OVERDUEDURATION",str(overdue) + ':' + str(minutes), MboConstants.NOACCESSCHECK)rcainprg.setValue("ISOVERDUE","1", MboConstants.NOACCESSCHECK)FRACSet.save()
This comment has been removed by a blog administrator.
ReplyDeleteThanks you very much Umar
ReplyDelete