PMCORE-3878
This commit is contained in:
@@ -27,6 +27,7 @@ $factory->define(\ProcessMaker\Model\Delegation::class, function(Faker $faker) {
|
||||
'DEL_TYPE' => 'NORMAL',
|
||||
'DEL_THREAD' => 1,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_THREAD_STATUS_ID' => 1,
|
||||
'DEL_PRIORITY' => 3,
|
||||
'DEL_DELEGATE_DATE' => $faker->dateTime(),
|
||||
'DEL_INIT_DATE' => $faker->dateTime(),
|
||||
@@ -79,6 +80,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function
|
||||
'DEL_TYPE' => 'NORMAL',
|
||||
'DEL_THREAD' => 1,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_THREAD_STATUS_ID' => 1,
|
||||
'DEL_PRIORITY' => 3,
|
||||
'DEL_DELEGATE_DATE' => $delegateDate,
|
||||
'DEL_INIT_DATE' => $initDate,
|
||||
@@ -125,6 +127,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'web_entry', function (Fa
|
||||
'DEL_TYPE' => 'NORMAL',
|
||||
'DEL_THREAD' => 1,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_THREAD_STATUS_ID' => 1,
|
||||
'DEL_PRIORITY' => 3,
|
||||
'DEL_DELEGATE_DATE' => $faker->dateTime(),
|
||||
'DEL_INIT_DATE' => $faker->dateTime(),
|
||||
@@ -148,6 +151,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'open', function (Faker $
|
||||
|
||||
return [
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_THREAD_STATUS_ID' => 1,
|
||||
'DEL_DELEGATE_DATE' => $delegateDate,
|
||||
'DEL_INIT_DATE' => $initDate,
|
||||
'DEL_RISK_DATE' => $riskDate,
|
||||
|
||||
@@ -143,6 +143,18 @@ class DelegationTest extends TestCase
|
||||
$this->assertCount(1, $table->threadOpen()->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeThreadIdOpen
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeThreadIdOpen()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_thread_id_open()
|
||||
{
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create();
|
||||
$this->assertCount(1, $table->threadIdOpen()->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeThreadPause
|
||||
*
|
||||
|
||||
@@ -94,6 +94,17 @@ class Delegation extends Model
|
||||
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include open threads
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeThreadIdOpen($query)
|
||||
{
|
||||
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS_ID', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include pause threads
|
||||
*
|
||||
@@ -2182,6 +2193,15 @@ class Delegation extends Model
|
||||
$query = Delegation::query()->select(['APP_NUMBER']);
|
||||
// Filter the title
|
||||
$query->title($search);
|
||||
// Get open or last thread
|
||||
$query->where(function ($query) {
|
||||
// Get open threads
|
||||
$query->threadIdOpen();
|
||||
// Get last
|
||||
$query->orWhere(function ($query) {
|
||||
$query->lastThread();
|
||||
});
|
||||
});
|
||||
// Group by
|
||||
$query->groupBy('APP_NUMBER');
|
||||
// Get the result
|
||||
|
||||
Reference in New Issue
Block a user