Adding the new changes in AppDelegation.php

This commit is contained in:
jennylee
2015-03-27 17:10:11 -04:00
parent 052ddc3759
commit 9325a1ec99

View File

@@ -179,6 +179,19 @@ class AppDelegation extends BaseAppDelegation
$data->USR_UID = $sUsrUid;
$oPluginRegistry = &PMPluginRegistry::getSingleton();
$oPluginRegistry->executeTriggers(PM_CREATE_NEW_DELEGATION, $data);
/*----------------------------------********---------------------------------*/
// this section evaluates the actions by email trigger execution please
// modify this section carefully, the if evaluation checks if the license has been
// activated in order to send the mail according to the configuration table
if (PMLicensedFeatures
::getSingleton()
->verifyfeature('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=')) {
G::LoadClass('actionsByEmail');
$actionsByEmail = new actionsByEmailClass();
$actionsByEmail->sendActionsByEmail($data);
}
/*----------------------------------********---------------------------------*/
}
return $delIndex;
@@ -224,6 +237,10 @@ class AppDelegation extends BaseAppDelegation
$c->addSelectColumn( AppDelegationPeer::PRO_UID );
$c->addSelectColumn( AppDelegationPeer::TAS_UID );
$c->addSelectColumn( AppDelegationPeer::USR_UID );
$c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
$c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
$c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
$c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
$c->add( AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN' );
$c->add( AppDelegationPeer::APP_UID, $AppUid );
@@ -238,6 +255,12 @@ class AppDelegation extends BaseAppDelegation
$case = array();
$case['TAS_UID'] = $row['TAS_UID'];
$case['USR_UID'] = $row['USR_UID'];
$case['DEL_INDEX'] = $row['DEL_INDEX'];
$case['TAS_UID'] = $row['TAS_UID'];
$case['DEL_DELEGATE_DATE'] = $row['DEL_DELEGATE_DATE'];
$case['DEL_INIT_DATE'] = $row['DEL_INIT_DATE'];
$case['DEL_TASK_DUE_DATE'] = $row['DEL_TASK_DUE_DATE'];
$case['DEL_FINISH_DATE'] = $row['DEL_FINISH_DATE'];
$aCases[] = $case;
$rs->next();
$row = $rs->getRow();
@@ -344,6 +367,7 @@ class AppDelegation extends BaseAppDelegation
/*$iDueDate = $calendar->calculateDate( $this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'] //hours or days, ( we only accept this two types or maybe weeks
);*/
$iDueDate = $calendar->dashCalculateDate($this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'], $calData);
return $iDueDate;
}
@@ -477,7 +501,6 @@ class AppDelegation extends BaseAppDelegation
$delayDuration = $calendar->dashCalculateDurationWithCalendar( $iDueDate, date("Y-m-d H:i:s"), $calData );
$delayDuration = $delayDuration / (24 * 60 * 60); //Days
$oAppDel->setDelDelayDuration( $delayDuration );
if ($fTaskDuration != 0) {
$overduePercentage = $delayDuration / $fTaskDuration;
$oAppDel->setAppOverduePercentage( $overduePercentage );
@@ -495,14 +518,12 @@ class AppDelegation extends BaseAppDelegation
$oAppDel->setDelFinished( 1 );
//$delDuration = $this->getDiffDate( $iFinishDate, $iInitDate );
$delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_INIT_DATE'], $row['DEL_FINISH_DATE'], $calData );
$delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns segs.
$delDuration = $this->calculateDurationWithCalendar($row['DEL_INIT_DATE'], $row['DEL_FINISH_DATE'], $calData );//by jen
$delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
$oAppDel->setDelDuration( $delDuration );
//calculate due date if correspond
$dueDate = strtotime($iDueDate);
$finishDate = strtotime($iFinishDate);
if ($dueDate < $finishDate) {
if ($iDueDate < $iFinishDate) {
$oAppDel->setDelDelayed( 1 );
//$delayDuration = $this->getDiffDate( $iFinishDate, $iDueDate );
$delayDuration = $calendar->dashCalculateDurationWithCalendar( $iDueDate, $row['DEL_FINISH_DATE'], $calData );
@@ -516,11 +537,11 @@ class AppDelegation extends BaseAppDelegation
//the task was not completed
if ($row['DEL_INIT_DATE'] != null && $row['DEL_INIT_DATE'] != '') {
//$delDuration = $this->getDiffDate( $now, $iInitDate );
$delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_INIT_DATE'], date("Y-m-d H:i:s"), $calData );
$delDuration = $this->calculateDurationWithCalendar($row['DEL_INIT_DATE'], date("Y-m-d H:i:s"), $calData );//by jen
$delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
} else {
//$delDuration = $this->getDiffDate( $now, $iDelegateDate );
$delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_DELEGATE_DATE'], date("Y-m-d H:i:s"), $calData );
$delDuration = $this->calculateDurationWithCalendar($row['DEL_DELEGATE_DATE'], date("Y-m-d H:i:s"), $calData ); //byJen
$delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
}
$oAppDel->setDelDuration( $delDuration );
@@ -556,6 +577,232 @@ class AppDelegation extends BaseAppDelegation
}
}
//Calculate the duration betwen two dates with a calendar
public function calculateDurationWithCalendar ($iniDate, $finDate = null, $calendarData = array())
{
if ((is_null($finDate)) || ($finDate == '')) {
$finDate = date('Y-m-d H:i:s');
}
$secondDuration = 0.00;
if ( (strtotime($iniDate)) < (strtotime($finDate)) ) {
$timeIniDate = strtotime($iniDate);
$timeFinDate = strtotime($finDate);
} elseif ( (strtotime($finDate)) < (strtotime($iniDate)) ) {
$timeIniDate = strtotime($finDate);
$timeFinDate = strtotime($iniDate);
$auxDate = $iniDate;
$iniDate = $finDate;
$finDate = $auxDate;
} else {
return $secondDuration;
}
$finDate = $this->getIniDate($finDate, $calendarData);
$newDate = $iniDate;
while ($timeIniDate < $timeFinDate) {
//$dataLog = array();
$newDate = $this->getIniDate($newDate, $calendarData);
//$dataLog[] = $hoursDuration;
//$dataLog[] = $newDate;
$rangeWorkHour = $this->getRangeWorkHours($newDate, $calendarData['BUSINESS_DAY']);
$onlyDate = (date('Y-m-d',strtotime($newDate))) . ' ' . $rangeWorkHour['END'];
//$dataLog[] = date('l',strtotime($newDate));
//$dataLog[] = $rangeWorkHour['START'] . ' / ' . $rangeWorkHour['END'];
//$dataLog[] = $rangeWorkHour['TOTAL'];
if ( (strtotime($finDate)) < (strtotime($onlyDate)) ) {
$secondRes = ( ((float)strtotime($finDate)) - ((float)strtotime($newDate)) );
$timeIniDate = strtotime($finDate);
$secondDuration += (float)$secondRes;
} else {
$secondRes = ( ((float)strtotime($onlyDate)) - ((float)strtotime($newDate)) );
$newDate = $onlyDate;
$timeIniDate = strtotime($onlyDate);
$secondDuration += (float)$secondRes;
}
//$dataLog[] = $newDate;
//$log[] = $dataLog;
}
return $secondDuration;
}
public function getIniDate ($iniDate, $calendarData = array())
{
$flagIniDate = true;
while ($flagIniDate) {
// 1 if it's a work day
$weekDay = date('w',strtotime($iniDate));
if ( !(in_array($weekDay, $calendarData['CALENDAR_WORK_DAYS_A'])) ) {
$iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
continue;
}
// 2 if it's a holiday
$iniDateHolidayDay = $this->is_holiday($iniDate, $calendarData['HOLIDAY']);
if ($iniDateHolidayDay) {
$iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
continue;
}
// 3 if it's work time
$workHours = $this->nextWorkHours($iniDate, $weekDay, $calendarData['BUSINESS_DAY']);
if ( !($workHours['STATUS']) ) {
$iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
continue;
} else {
$iniDate = $workHours['DATE'];
}
$flagIniDate = false;
}
return $iniDate;
}
public function nextWorkHours ($date, $weekDay, $workHours = array())
{
$auxIniDate = explode(' ', $date);
$timeDate = $auxIniDate['1'];
$timeDate = (float)str_replace(':', '', ((strlen($timeDate) == 8) ? $timeDate : $timeDate.':00') );
$nextWorkHours = array();
$workHoursDay = array();
$tempWorkHoursDay = array();
foreach ($workHours as $value) {
if ($value['CALENDAR_BUSINESS_DAY'] == $weekDay) {
$rangeWorkHour = array();
$timeStart = $value['CALENDAR_BUSINESS_START'];
$timeEnd = $value['CALENDAR_BUSINESS_END'];
$rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
$rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
$workHoursDay[] = $rangeWorkHour;
}
if ($value['CALENDAR_BUSINESS_DAY'] == '7') {
$rangeWorkHour = array();
$timeStart = $value['CALENDAR_BUSINESS_START'];
$timeEnd = $value['CALENDAR_BUSINESS_END'];
$rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
$rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
$tempWorkHoursDay[] = $rangeWorkHour;
}
}
if ( !(count($workHoursDay)) ) {
$workHoursDay = $tempWorkHoursDay;
}
$countHours = count($workHoursDay);
if ($countHours) {
for ($i = 1; $i < $countHours; $i++) {
for ($j = 0; $j < $countHours-$i; $j++) {
$dataft = (float)str_replace(':', '', $workHoursDay[$j]['START']);
$datasc = (float)str_replace(':', '', $workHoursDay[$j+1]['END']);
if ($dataft > $datasc) {
$aux = $workHoursDay[$j+1];
$workHoursDay[$j+1] = $workHoursDay[$j];
$workHoursDay[$j] = $aux;
}
}
}
foreach ($workHoursDay as $value) {
$iniTime = (float)str_replace(':', '', ((strlen($value['START']) == 8) ? $value['START'] : $value['START'].':00'));
$finTime = (float)str_replace(':', '', ((strlen($value['END']) == 8) ? $value['END'] : $value['END'].':00'));
if ( $timeDate <= $iniTime ) {
$nextWorkHours['STATUS'] = true;
$nextWorkHours['DATE'] = $auxIniDate['0'] . ' ' . ((strlen($value['START']) == 8) ? $value['START'] : $value['START'].':00');
return $nextWorkHours;
} elseif ( ($iniTime <= $timeDate) && ($timeDate < $finTime) ) {
$nextWorkHours['STATUS'] = true;
$nextWorkHours['DATE'] = $date;
return $nextWorkHours;
}
}
}
$nextWorkHours['STATUS'] = false;
return $nextWorkHours;
}
public function is_holiday ($date, $holidays = array())
{
$auxIniDate = explode(' ', $date);
$iniDate = $auxIniDate['0'];
$iniDate = strtotime($iniDate);
foreach ($holidays as $value) {
$holidayStartDate = strtotime(date('Y-m-d',strtotime($value['CALENDAR_HOLIDAY_START'])));
$holidayEndDate = strtotime(date('Y-m-d',strtotime($value['CALENDAR_HOLIDAY_END'])));
if ( ($holidayStartDate <= $iniDate) && ($iniDate <= $holidayEndDate) ) {
return true;
}
}
return false;
}
public function getRangeWorkHours ($date, $workHours)
{
$auxIniDate = explode(' ', $date);
$timeDate = $auxIniDate['1'];
$timeDate = (float)str_replace(':', '', ((strlen($timeDate) == 8) ? $timeDate : $timeDate.':00') );
$weekDay = date('w',strtotime($date));
$workHoursDay = array();
$tempWorkHoursDay = array();
foreach ($workHours as $value) {
if ($value['CALENDAR_BUSINESS_DAY'] == $weekDay) {
$rangeWorkHour = array();
$timeStart = $value['CALENDAR_BUSINESS_START'];
$timeEnd = $value['CALENDAR_BUSINESS_END'];
$rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
$rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
$workHoursDay[] = $rangeWorkHour;
}
if ($value['CALENDAR_BUSINESS_DAY'] == '7') {
$rangeWorkHour = array();
$timeStart = $value['CALENDAR_BUSINESS_START'];
$timeEnd = $value['CALENDAR_BUSINESS_END'];
$rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
$rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
$tempWorkHoursDay[] = $rangeWorkHour;
}
}
if ( !(count($workHoursDay)) ) {
$workHoursDay = $tempWorkHoursDay;
}
foreach ($workHoursDay as $value) {
$iniTime = (float)str_replace(':', '', $value['START']);
$finTime = (float)str_replace(':', '', $value['END']);
if ( ($iniTime <= $timeDate) && ($timeDate <= $finTime) ) {
//pr($finTime .' menos '.$iniTime .' = '.($finTime-$iniTime));
$value['TOTAL'] = (($finTime-$iniTime)/10000);
return $value;
}
}
return false;
}
public function getLastDeleration ($APP_UID)
{
$c = new Criteria( 'workflow' );