PMCORE-3188
This commit is contained in:
@@ -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 [
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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())
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user