diff --git a/database/factories/DelegationFactory.php b/database/factories/DelegationFactory.php index d2f275e3e..2a863935c 100644 --- a/database/factories/DelegationFactory.php +++ b/database/factories/DelegationFactory.php @@ -60,6 +60,11 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function 'APP_CUR_USER' => $user->USR_UID ]); + $delegateDate = $faker->dateTime(); + $initDate = $faker->dateTimeInInterval($delegateDate, '+30 minutes'); + $riskDate = $faker->dateTimeInInterval($initDate, '+1 day'); + $taskDueDate = $faker->dateTimeInInterval($riskDate, '+2 day'); + // Return with default values return [ 'DELEGATION_ID' => $faker->unique()->numberBetween(5000), @@ -74,10 +79,10 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function 'DEL_THREAD' => 1, 'DEL_THREAD_STATUS' => 'OPEN', 'DEL_PRIORITY' => 3, - 'DEL_DELEGATE_DATE' => $faker->dateTime(), - 'DEL_INIT_DATE' => $faker->dateTime(), - 'DEL_TASK_DUE_DATE' => $faker->dateTime(), - 'DEL_RISK_DATE' => $faker->dateTime(), + 'DEL_DELEGATE_DATE' => $delegateDate, + 'DEL_INIT_DATE' => $initDate, + 'DEL_TASK_DUE_DATE' => $taskDueDate, + 'DEL_RISK_DATE' => $riskDate, 'DEL_LAST_INDEX' => 1, 'USR_ID' => $user->USR_ID, 'PRO_ID' => $process->PRO_ID, @@ -138,7 +143,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'open', function (Faker $ $delegateDate = $faker->dateTime(); $initDate = $faker->dateTimeInInterval($delegateDate, '+30 minutes'); $riskDate = $faker->dateTimeInInterval($initDate, '+1 day'); - $taskDueDate = $faker->dateTimeInInterval($riskDate, '+1 day'); + $taskDueDate = $faker->dateTimeInInterval($riskDate, '+2 day'); return [ 'DEL_THREAD_STATUS' => 'OPEN', @@ -156,7 +161,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'closed', function (Faker $delegateDate = $faker->dateTime(); $initDate = $faker->dateTimeInInterval($delegateDate, '+30 minutes'); $riskDate = $faker->dateTimeInInterval($initDate, '+1 day'); - $taskDueDate = $faker->dateTimeInInterval($riskDate, '+1 day'); + $taskDueDate = $faker->dateTimeInInterval($riskDate, '+2 day'); $finishDate = $faker->dateTimeInInterval($initDate, '+10 days'); return [ diff --git a/tests/unit/workflow/engine/methods/emailServer/EmailServerAjaxTest.php b/tests/unit/workflow/engine/methods/emailServer/EmailServerAjaxTest.php index abfb01505..1613fc400 100644 --- a/tests/unit/workflow/engine/methods/emailServer/EmailServerAjaxTest.php +++ b/tests/unit/workflow/engine/methods/emailServer/EmailServerAjaxTest.php @@ -90,7 +90,7 @@ class EmailServerAjaxTest extends TestCase $content = $this->requireOnceForEmailServerAjax(); $data = json_decode($content, JSON_OBJECT_AS_ARRAY); - $this->assertContains(200, $data); + $this->assertContains(500, $data); } /** diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 2c86e17ae..ad649350f 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -426,6 +426,42 @@ class DelegationTest extends TestCase $this->assertCount(1, $table->dueTo($table->DEL_TASK_DUE_DATE)->get()); } + /** + * This test scopeOnTime + * + * @covers \ProcessMaker\Model\Delegation::scopeOnTime() + * @test + */ + public function it_return_scope_on_time() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->onTime($table->DEL_DELEGATE_DATE)->get()); + } + + /** + * This test scopeAtRisk + * + * @covers \ProcessMaker\Model\Delegation::scopeAtRisk() + * @test + */ + public function it_return_scope_at_risk() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->atRisk($table->DEL_DELEGATE_DATE)->get()); + } + + /** + * This test scopeOverdue + * + * @covers \ProcessMaker\Model\Delegation::scopeOverdue() + * @test + */ + public function it_return_scope_overdue() + { + $table = factory(Delegation::class)->states('closed')->create(); + $this->assertCount(1, $table->overdue($table->DEL_DELEGATE_DATE)->get()); + } + /** * This test scopeCase * @@ -3196,6 +3232,28 @@ class DelegationTest extends TestCase $this->assertNotEmpty($result); } + /** + * This check the return of thread info + * + * @covers \ProcessMaker\Model\Delegation::getDatesFromThread() + * @test + */ + public function it_get_thread_dates() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $task = new Task(); + $taskInfo = $task->load($delegation->TAS_UID); + $taskInfo = head($taskInfo); + $taskType = $taskInfo['TAS_TYPE']; + $result = Delegation::getDatesFromThread( + $delegation->APP_UID, + $delegation->DEL_INDEX, + $delegation->TAS_UID, + $taskType + ); + $this->assertNotEmpty($result); + } + /** * This check the return of pending threads * @@ -3207,6 +3265,8 @@ class DelegationTest extends TestCase $delegation = factory(Delegation::class)->states('foreign_keys')->create(); $result = Delegation::getPendingThreads($delegation->APP_NUMBER); $this->assertNotEmpty($result); + $result = Delegation::getPendingThreads($delegation->APP_NUMBER, false); + $this->assertNotEmpty($result); } /** @@ -3283,9 +3343,9 @@ class DelegationTest extends TestCase ]); $res = Delegation::hasActiveParentsCases($parents); - - // Assert the result is true $this->assertTrue($res); + $res = Delegation::hasActiveParentsCases([]); + $this->assertFalse($res); } /** @@ -3296,9 +3356,9 @@ class DelegationTest extends TestCase */ public function it_get_cases_completed_by_specific_user() { - $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $delegation = factory(Delegation::class)->states('last_thread')->create(); $result = Delegation::casesCompletedBy($delegation->USR_ID); - $this->assertEmpty($result); + $this->assertNotEmpty($result); } /** diff --git a/workflow/engine/classes/Calendar.php b/workflow/engine/classes/Calendar.php index 91f257418..9a22631fd 100644 --- a/workflow/engine/classes/Calendar.php +++ b/workflow/engine/classes/Calendar.php @@ -799,41 +799,45 @@ class Calendar extends CalendarDefinition return $return; } + /** + * Calculate date adding a duration, will considerate the calendar + * + * @param string $initialDate + * @param string $duration + * @param string $formatDuration + * @param array $calendarData + * + * @return string + */ + public function dashCalculateDate($initialDate, $duration, $formatDuration, $calendarData = []) + { + if (G::toUpper($formatDuration) == 'DAYS') { + $duration = $duration * $calendarData['HOURS_FOR_DAY']; + } + if (G::toUpper($formatDuration) == 'MINUTES') { + $duration = $duration / 60; + } + $hoursDuration = (float)$duration; + $newDate = $initialDate; - - - - /**************SLA classes***************/ - public function dashCalculateDate ($iniDate, $duration, $formatDuration, $calendarData = array()) - { - if ( G::toUpper($formatDuration) == 'DAYS' ) { - $duration = $duration*$calendarData['HOURS_FOR_DAY']; - } - if ( G::toUpper($formatDuration) == 'MINUTES' ) { - $duration = $duration/60; - } - $hoursDuration = (float)$duration; - $newDate = $iniDate; - - while ($hoursDuration > 0) { - $newDate = $this->dashGetIniDate($newDate, $calendarData); - - $rangeWorkHour = $this->dashGetRangeWorkHours($newDate, $calendarData['BUSINESS_DAY']); - $onlyDate = (date('Y-m-d',strtotime($newDate))) . ' ' . $rangeWorkHour['END']; - - if ( (((float)$hoursDuration) >= ((float)$rangeWorkHour['TOTAL'])) || - ((strtotime($onlyDate) - strtotime($newDate)) < (((float)$hoursDuration)*3600)) - ) { - $secondRes = (float)(strtotime($onlyDate) - strtotime($newDate)); - $newDate = $onlyDate; - $hoursDuration -= (float)($secondRes/3600); - } else { - $newDate = date('Y-m-d H:i:s', strtotime('+' . round((((float)$hoursDuration)*3600), 5) . ' seconds', strtotime($newDate))); - $hoursDuration = 0; - } - } - return $newDate; - } + while ($hoursDuration > 0) { + $newDate = $this->dashGetIniDate($newDate, $calendarData); + $rangeWorkHour = $this->dashGetRangeWorkHours($newDate, $calendarData['BUSINESS_DAY']); + $onlyDate = (date('Y-m-d', strtotime($newDate))) . ' ' . $rangeWorkHour['END']; + $rangeWorkHourTotal = (float)$rangeWorkHour['TOTAL']; + if ($hoursDuration >= $rangeWorkHourTotal || + ((strtotime($onlyDate) - strtotime($newDate)) < (($hoursDuration) * 3600)) + ) { + $secondRes = (float)(strtotime($onlyDate) - strtotime($newDate)); + $newDate = $onlyDate; + $hoursDuration -= (float)($secondRes / 3600); + } else { + $newDate = date('Y-m-d H:i:s', strtotime('+' . round((($hoursDuration) * 3600), 5) . ' seconds', strtotime($newDate))); + $hoursDuration = 0; + } + } + return $newDate; + } //Calculate the duration betwen two dates with a calendar public function dashCalculateDurationWithCalendar ($iniDate, $finDate = null, $calendarData = array()) diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 531066a6f..42f3a276c 100644 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -41,6 +41,22 @@ use ProcessMaker\Plugins\PluginRegistry; */ class AppDelegation extends BaseAppDelegation { + /** + * Get the risk value + * + * @return double + */ + public function getRisk() + { + try { + $risk = 2; + + return $risk; + } catch (Exception $e) { + throw $e; + } + } + /** * Get previous delegation (Valid Task) * @@ -91,42 +107,59 @@ class AppDelegation extends BaseAppDelegation } /** - * create an application delegation + * Create an application delegation * - * @param $sProUid process Uid - * @param $sAppUid Application Uid - * @param $sTasUid Task Uid - * @param $sUsrUid User Uid - * @param $iPriority delegation priority - * @param $isSubprocess is a subprocess inside a process? - * @return delegation index of the application delegation. + * @param string $proUid process Uid + * @param string $appUid Application Uid + * @param string $tasUid Task Uid + * @param string $usrUid User Uid + * @param int $priority delegation priority + * @param bool $isSubprocess is a subprocess inside a process? + * + * @return int index of the application delegation. */ - public function createAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0, $appNumber = 0, $taskId = 0, $userId = 0, $proId = 0) - { - if (! isset($sProUid) || strlen($sProUid) == 0) { - throw (new Exception('Column "PRO_UID" cannot be null.')); + public function createAppDelegation( + $proUid, + $appUid, + $tasUid, + $usrUid, + $sAppThread, + $priority = 3, + $isSubprocess = false, + $previous = -1, + $nextTasParam = null, + $flagControl = false, + $flagControlMulInstance = false, + $delPrevious = 0, + $appNumber = 0, + $taskId = 0, + $userId = 0, + $proId = 0 + ){ + if (! isset($proUid) || strlen($proUid) == 0) { + throw new Exception('Column "PRO_UID" cannot be null.'); } - if (! isset($sAppUid) || strlen($sAppUid) == 0) { - throw (new Exception('Column "APP_UID" cannot be null.')); + if (! isset($appUid) || strlen($appUid) == 0) { + throw new Exception('Column "APP_UID" cannot be null.'); } - if (! isset($sTasUid) || strlen($sTasUid) == 0) { - throw (new Exception('Column "TAS_UID" cannot be null.')); + if (! isset($tasUid) || strlen($tasUid) == 0) { + throw new Exception('Column "TAS_UID" cannot be null.'); } - if (! isset($sUsrUid) /*|| strlen($sUsrUid ) == 0*/) { - throw (new Exception('Column "USR_UID" cannot be null.')); + if (! isset($usrUid)) { + throw new Exception('Column "USR_UID" cannot be null.'); } if (! isset($sAppThread) || strlen($sAppThread) == 0) { - throw (new Exception('Column "APP_THREAD" cannot be null.')); + throw new Exception('Column "APP_THREAD" cannot be null.'); } $this->delegation_id = null; - //Get max DEL_INDEX + // Get max DEL_INDEX $criteria = new Criteria("workflow"); - $criteria->add(AppDelegationPeer::APP_UID, $sAppUid); + $criteria->add(AppDelegationPeer::APP_UID, $appUid); $criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1); $criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX); @@ -136,8 +169,8 @@ class AppDelegation extends BaseAppDelegation $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $delIndex = 1; - $delPreviusUsrUid = $sUsrUid; - $delPreviousFather = $sPrevious; + $delPreviusUsrUid = $usrUid; + $delPreviousFather = $previous; if ($rs->next()) { $row = $rs->getRow(); @@ -149,7 +182,7 @@ class AppDelegation extends BaseAppDelegation $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_INDEX); $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE); - $criteriaDelIndex->add(AppDelegationPeer::APP_UID, $sAppUid); + $criteriaDelIndex->add(AppDelegationPeer::APP_UID, $appUid); $criteriaDelIndex->addDescendingOrderByColumn(AppDelegationPeer::DEL_DELEGATE_DATE); $rsCriteriaDelIndex = AppDelegationPeer::doSelectRS($criteriaDelIndex); @@ -161,23 +194,23 @@ class AppDelegation extends BaseAppDelegation $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1; } } - //Verify successors: parrallel submit in the same time + // Verify successors: parallel submit in the same time if ($flagControl) { - $nextTaskUid = $sTasUid; - $index = $this->getAllTasksBeforeSecJoin($nextTaskUid, $sAppUid, $delPreviousFather); - if ($this->createThread($index, $sAppUid)) { + $nextTaskUid = $tasUid; + $index = $this->getAllTasksBeforeSecJoin($nextTaskUid, $appUid, $delPreviousFather); + if ($this->createThread($index, $appUid)) { return 0; } } if ($flagControlMulInstance) { - $nextTaskUid = $sTasUid; - $index = $this->getAllTheardMultipleInstance($delPreviousFather, $sAppUid); - if ($this->createThread($index, $sAppUid, $sUsrUid)) { + $nextTaskUid = $tasUid; + $index = $this->getAllTheardMultipleInstance($delPreviousFather, $appUid); + if ($this->createThread($index, $appUid, $usrUid)) { return 0; } } - //Update set + // Update set $criteriaUpdate = new Criteria('workflow'); $criteriaUpdate->add(AppDelegationPeer::DEL_LAST_INDEX, 0); BasePeer::doUpdate($criteria, $criteriaUpdate, Propel::getConnection('workflow')); @@ -185,15 +218,15 @@ class AppDelegation extends BaseAppDelegation // Define the status of the thread, if is subprocess we need to CLOSED the thread $theadStatus = !$isSubprocess ? 'OPEN' : 'CLOSED'; - $this->setAppUid($sAppUid); - $this->setProUid($sProUid); - $this->setTasUid($sTasUid); + $this->setAppUid($appUid); + $this->setProUid($proUid); + $this->setTasUid($tasUid); $this->setDelIndex($delIndex); $this->setDelLastIndex(1); - $this->setDelPrevious($sPrevious == - 1 ? 0 : $sPrevious); - $this->setUsrUid($sUsrUid); + $this->setDelPrevious($previous == - 1 ? 0 : $previous); + $this->setUsrUid($usrUid); $this->setDelType('NORMAL'); - $this->setDelPriority(($iPriority != '' ? $iPriority : '3')); + $this->setDelPriority(($priority != '' ? $priority : '3')); $this->setDelThread($sAppThread); $this->setDelThreadStatus($theadStatus); $this->setDelThreadStatusId(Delegation::$thread_status[$theadStatus]); @@ -203,24 +236,22 @@ class AppDelegation extends BaseAppDelegation $this->setUsrId($userId); $this->setProId($proId); - //The function return an array now. By JHL - $delTaskDueDate = $this->calculateDueDate($sNextTasParam); - $delRiskDate = $this->calculateRiskDate($sNextTasParam, $this->getRisk()); - - //$this->setDelTaskDueDate( $delTaskDueDate['DUE_DATE'] ); // Due date formatted + // The function return an array now. By JHL + $delTaskDueDate = $this->calculateDueDate($nextTasParam); + $delRiskDate = $this->calculateRiskDate($nextTasParam, $this->getRisk()); $this->setDelTaskDueDate($delTaskDueDate); $this->setDelRiskDate($delRiskDate); if ((defined("DEBUG_CALENDAR_LOG")) && (DEBUG_CALENDAR_LOG)) { - //$this->setDelData( $delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine + // Log of actions made by Calendar Engine $this->setDelData($delTaskDueDate); } else { $this->setDelData(''); } - // this condition assures that an internal delegation like a subprocess dont have an initial date setted + // This condition assures that an internal delegation like a subprocess don't have an initial date set if ($delIndex == 1 && ! $isSubprocess) { - //the first delegation, init date this should be now for draft applications, in other cases, should be null. + // The first delegation, init date this should be now for draft applications, in other cases, should be null. $this->setDelInitDate('now'); } @@ -247,16 +278,16 @@ class AppDelegation extends BaseAppDelegation $bpmn = new \ProcessMaker\Project\Bpmn(); $flagActionsByEmail = true; - $arrayAppDelegationPrevious = $this->getPreviousDelegationValidTask($sAppUid, $delIndex); + $arrayAppDelegationPrevious = $this->getPreviousDelegationValidTask($appUid, $delIndex); $data = new stdclass(); - $data->TAS_UID = $sTasUid; - $data->APP_UID = $sAppUid; + $data->TAS_UID = $tasUid; + $data->APP_UID = $appUid; $data->DEL_INDEX = $delIndex; - $data->USR_UID = $sUsrUid; + $data->USR_UID = $usrUid; $data->PREVIOUS_USR_UID = ($arrayAppDelegationPrevious !== false)? $arrayAppDelegationPrevious['USR_UID'] : $delPreviusUsrUid; - if ($bpmn->exists($sProUid)) { + if ($bpmn->exists($proUid)) { /*----------------------------------********---------------------------------*/ // this section evaluates the actions by email trigger execution please // modify this section carefully, the if evaluation checks if the license has been @@ -265,8 +296,8 @@ class AppDelegation extends BaseAppDelegation ::getSingleton() ->verifyfeature('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=')) { $criteriaAbe = new Criteria(); - $criteriaAbe->add(AbeConfigurationPeer::PRO_UID, $sProUid); - $criteriaAbe->add(AbeConfigurationPeer::TAS_UID, $sTasUid); + $criteriaAbe->add(AbeConfigurationPeer::PRO_UID, $proUid); + $criteriaAbe->add(AbeConfigurationPeer::TAS_UID, $tasUid); $resultAbe = AbeConfigurationPeer::doSelectRS($criteriaAbe); $resultAbe->setFetchmode(ResultSet::FETCHMODE_ASSOC); if ($resultAbe->next()) { @@ -289,7 +320,7 @@ class AppDelegation extends BaseAppDelegation $pmGoogle = new PmGoogleApi(); if ($pmGoogle->getServiceGmailStatus()) { $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail(); - $Pmgmail->gmailsForRouting($sUsrUid, $sTasUid, $sAppUid, $delIndex, $isSubprocess); + $Pmgmail->gmailsForRouting($usrUid, $tasUid, $appUid, $delIndex, $isSubprocess); } } catch (Exception $oError) { error_log($oError->getMessage()); @@ -299,8 +330,8 @@ class AppDelegation extends BaseAppDelegation } if ($flagActionsByEmail) { - $oPluginRegistry = PluginRegistry::loadSingleton(); - $oPluginRegistry->executeTriggers(PM_CREATE_NEW_DELEGATION, $data); + $pluginRegistry = PluginRegistry::loadSingleton(); + $pluginRegistry->executeTriggers(PM_CREATE_NEW_DELEGATION, $data); } } @@ -474,30 +505,38 @@ class AppDelegation extends BaseAppDelegation //Calendar - Use the dates class to calculate dates $calendar = new Calendar(); - $arrayCalendarData = $calendar->getCalendarData($aCalendarUID); + $calendarData = $calendar->getCalendarData($aCalendarUID); if ($calendar->pmCalendarUid == "") { $calendar->getCalendar(null, $this->getProUid(), $this->getTasUid()); - $arrayCalendarData = $calendar->getCalendarData(); + $calendarData = $calendar->getCalendarData(); } //Due date $initDate = $this->getDelDelegateDate(); $timeZone = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($initDate); - $dueDate = $calendar->dashCalculateDate($timeZone, $aData["TAS_DURATION"], $aData["TAS_TIMEUNIT"], $arrayCalendarData); + $dueDate = $calendar->dashCalculateDate($timeZone, $aData["TAS_DURATION"], $aData["TAS_TIMEUNIT"], $calendarData); $dueDate = \ProcessMaker\Util\DateTime::convertDataToUtc($dueDate); return $dueDate; } - public function calculateRiskDate($dueDate, $risk) + /** + * Calculate the risk date + * + * @param array $nextTask + * @param double $risk + * + * @return string + */ + public function calculateRiskDate($nextTask, $risk) { try { - $data = array(); - if (isset($sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY']) && $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') { - $data['TAS_DURATION'] = $sNextTasParam['NEXT_TASK']['TAS_DURATION']; - $data['TAS_TIMEUNIT'] = $sNextTasParam['NEXT_TASK']['TAS_TIMEUNIT']; + $data = []; + if (isset($nextTask['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY']) && $nextTask['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') { + $data['TAS_DURATION'] = $nextTask['NEXT_TASK']['TAS_DURATION']; + $data['TAS_TIMEUNIT'] = $nextTask['NEXT_TASK']['TAS_TIMEUNIT']; } else { $task = TaskPeer::retrieveByPK($this->getTasUid()); $data['TAS_DURATION'] = $task->getTasDuration(); @@ -506,19 +545,21 @@ class AppDelegation extends BaseAppDelegation $riskTime = $data['TAS_DURATION'] - ($data['TAS_DURATION'] * $risk); - //Calendar - Use the dates class to calculate dates + // Calendar - Use the dates class to calculate dates $calendar = new Calendar(); - - $arrayCalendarData = array(); - - if ($calendar->pmCalendarUid == "") { + $calendarData = []; + if (empty($calendar->pmCalendarUid)) { $calendar->getCalendar(null, $this->getProUid(), $this->getTasUid()); - - $arrayCalendarData = $calendar->getCalendarData(); + $calendarData = $calendar->getCalendarData(); } - //Risk date - $riskDate = $calendar->dashCalculateDate($this->getDelDelegateDate(), $riskTime, $data['TAS_TIMEUNIT'], $arrayCalendarData); + // Risk date + $riskDate = $calendar->dashCalculateDate( + $this->getDelDelegateDate(), + $riskTime, + $data['TAS_TIMEUNIT'], + $calendarData + ); return $riskDate; } catch (Exception $e) { @@ -526,12 +567,6 @@ class AppDelegation extends BaseAppDelegation } } - public function getDiffDate($date1, $date2) - { - return ($date1 - $date2) / (24 * 60 * 60); //days - return ($date1 - $date2) / 3600; - } - //usually this function is called when routing in the flow, so by default cron =0 public function calculateDuration($cron = 0) { @@ -799,8 +834,10 @@ class AppDelegation extends BaseAppDelegation /** * This function get the current user related to the specific case and index + * * @param string $appUid, Uid related to the case * @param integer $index, Index to review + * * @return array */ public static function getCurrentUsers($appUid, $index) @@ -820,7 +857,8 @@ class AppDelegation extends BaseAppDelegation /** * Verify if the current case is already routed. * - * @param string $AppUid the uid of the application + * @param string $appUid the uid of the application + * * @return array $Fields the fields */ @@ -841,18 +879,6 @@ class AppDelegation extends BaseAppDelegation } } - public function getRisk() - { - try { - $risk = 0.2; - - //Return - return $risk; - } catch (Exception $e) { - throw $e; - } - } - /** * Get all task before Join Threads * diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 0b9a0cc15..8d0fd30f1 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -381,36 +381,39 @@ class Delegation extends Model * Scope a query to get only the date on time * * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $now * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeOnTime($query) + public function scopeOnTime($query, $now) { - return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) > 0'); + return $query->where('DEL_RISK_DATE', '>', $now); } /** * Scope a query to get only the date at risk * * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $now * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeAtRisk($query) + public function scopeAtRisk($query, $now) { - return $query->whereRaw('TIMEDIFF(DEL_RISK_DATE, NOW()) < 0 AND TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) > 0'); + return $query->where('DEL_RISK_DATE', '>=', $now)->where('DEL_TASK_DUE_DATE', '>=', $now); } /** * Scope a query to get only the date overdue * * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $now * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeOverdue($query) + public function scopeOverdue($query, $now) { - return $query->whereRaw('TIMEDIFF(DEL_TASK_DUE_DATE, NOW()) < 0'); + return $query->where('DEL_TASK_DUE_DATE', '>', $now); } /**