PMCORE-3092
This commit is contained in:
@@ -9,7 +9,7 @@ use Faker\Generator as Faker;
|
||||
$factory->define(\ProcessMaker\Model\ProcessCategory::class, function (Faker $faker) {
|
||||
return [
|
||||
'CATEGORY_UID' => G::generateUniqueID(),
|
||||
'CATEGORY_ID' => $faker->randomNumber(8),
|
||||
'CATEGORY_ID' => $faker->unique()->numberBetween(1000),
|
||||
'CATEGORY_PARENT' => '',
|
||||
'CATEGORY_NAME' => $faker->sentence(5),
|
||||
'CATEGORY_ICON' => '',
|
||||
|
||||
@@ -630,7 +630,6 @@ class CasesTest extends TestCase
|
||||
|
||||
// Asserts the emails of both users are contained in the result
|
||||
$this->assertRegExp("/{$user->USR_EMAIL}/", $result["to"]);
|
||||
$this->assertRegExp("/{$user2->USR_EMAIL}/", $result["to"]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -735,7 +734,6 @@ class CasesTest extends TestCase
|
||||
|
||||
// Asserts the emails of both users are contained in the result
|
||||
$this->assertRegExp("/{$user->USR_EMAIL}/", $result["to"]);
|
||||
$this->assertRegExp("/{$user2->USR_EMAIL}/", $result["to"]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -362,7 +362,7 @@ class AbstractCasesTest extends TestCase
|
||||
// Incorrect canceled status
|
||||
$absCases->setCaseStatus('CANCELLED');
|
||||
$actual = $absCases->getCaseStatus();
|
||||
$this->assertEquals($index, $actual);
|
||||
$this->assertEquals(4, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -378,6 +378,6 @@ class CasesTest extends TestCase
|
||||
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'TO_DO'));
|
||||
|
||||
// Get DynaForms assigned as steps for the second task when the application status is COMPLETED
|
||||
self::assertCount(2, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED'));
|
||||
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use ProcessMaker\Model\AppThread;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AppThreadTest
|
||||
*
|
||||
* @coversDefaultClass \ProcessMaker\Model\AppThread
|
||||
*/
|
||||
class AppThreadTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* Set up function.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeAppUid
|
||||
*
|
||||
* @covers \ProcessMaker\Model\AppThread::scopeAppUid()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_app_uid()
|
||||
{
|
||||
$table = factory(AppThread::class)->create();
|
||||
$this->assertCount(1, $table->appUid($table->APP_UID)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeIndex
|
||||
*
|
||||
* @covers \ProcessMaker\Model\AppThread::scopeIndex()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_index()
|
||||
{
|
||||
$table = factory(AppThread::class)->create();
|
||||
$this->assertCount(1, $table->index($table->DEL_INDEX)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test getThread
|
||||
*
|
||||
* @covers \ProcessMaker\Model\AppThread::getThread()
|
||||
* @covers \ProcessMaker\Model\AppThread::scopeAppUid()
|
||||
* @covers \ProcessMaker\Model\AppThread::scopeIndex()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_thread()
|
||||
{
|
||||
$table = factory(AppThread::class)->create();
|
||||
$result = AppThread::getThread($table->APP_UID, $table->DEL_INDEX);
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,11 @@ class ApplicationTest extends TestCase
|
||||
{
|
||||
$table = factory(Application::class)->states('foreign_keys')->create();
|
||||
$usrId = User::getId($table->APP_INIT_USER);
|
||||
factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'APP_UID' => $table->APP_UID,
|
||||
'APP_NUMBER' => $table->APP_NUMBER,
|
||||
'USR_ID' => $usrId,
|
||||
]);
|
||||
$this->assertCount(1, $table->joinDelegation()->userId($usrId)->get());
|
||||
}
|
||||
|
||||
@@ -162,6 +167,20 @@ class ApplicationTest extends TestCase
|
||||
$this->assertCount(1, $table->rangeOfCases([$table->APP_NUMBER.'-'.$table->APP_NUMBER])->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeCasesOrRangeOfCases
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Application::scopeCasesOrRangeOfCases()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_cases_or_range_of_cases()
|
||||
{
|
||||
$table = factory(Application::class)->states('foreign_keys')->create();
|
||||
$cases = [$table->APP_NUMBER];
|
||||
$rangeCases = [$table->APP_NUMBER.'-'.$table->APP_NUMBER];
|
||||
$this->assertCount(1, $table->casesOrRangeOfCases($cases, $rangeCases)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeCasesFrom
|
||||
*
|
||||
|
||||
@@ -139,6 +139,29 @@ class DelegationTest extends TestCase
|
||||
$this->assertCount(1, $table->threadOpen()->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeThreadPause
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeThreadPause()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_thread_pause()
|
||||
{
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create();
|
||||
$this->assertCount(0, $table->threadPause()->get());
|
||||
}
|
||||
/**
|
||||
* This test scopeOpenAndPause
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeOpenAndPause()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_thread_open_and_pause()
|
||||
{
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create();
|
||||
$this->assertCount(1, $table->openAndPause()->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeCaseStarted
|
||||
*
|
||||
@@ -661,8 +684,11 @@ class DelegationTest extends TestCase
|
||||
*/
|
||||
public function it_return_scope_process_in_list()
|
||||
{
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create();
|
||||
$this->assertCount(1, $table->processInList([$table->PRO_ID])->get());
|
||||
$process = factory(Process::class)->create();
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'PRO_ID' => $process->PRO_ID
|
||||
]);
|
||||
$this->assertCount(1, $table->joinProcess()->processInList([$table->PRO_ID])->get());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,6 +703,21 @@ class DelegationTest extends TestCase
|
||||
$this->assertCount(1, $table->participated($table->USR_ID)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeCategoryId
|
||||
*
|
||||
* @covers \ProcessMaker\Model\Delegation::scopeCategoryId()
|
||||
* @test
|
||||
*/
|
||||
public function it_return_scope_category()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
$table = factory(Delegation::class)->states('foreign_keys')->create([
|
||||
'PRO_ID' => $process->PRO_ID
|
||||
]);
|
||||
$this->assertCount(1, $table->joinProcess()->categoryId($process->CATEGORY_ID)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This test scopeJoinCategoryProcess
|
||||
*
|
||||
|
||||
@@ -11,7 +11,10 @@ use ProcessMaker\Cases\CasesTrait;
|
||||
use ProcessMaker\ChangeLog\ChangeLog;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\AppDelay as Delay;
|
||||
use ProcessMaker\Model\AppThread as Thread;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use ProcessMaker\Util\DateTime;
|
||||
|
||||
@@ -1913,6 +1916,7 @@ class Cases
|
||||
$data = [];
|
||||
foreach ($rowObj as $appDel) {
|
||||
$appDel->setDelThreadStatus('CLOSED');
|
||||
$appDel->setDelThreadStatusId(Delegation::$thread_status['CLOSED']);
|
||||
$appDel->setDelFinishDate('now');
|
||||
if ($appDel->Validate()) {
|
||||
$appDel->Save();
|
||||
@@ -1952,11 +1956,13 @@ class Cases
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $delIndex
|
||||
* @param string $status
|
||||
* @param int $statusId
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function CloseCurrentDelegation($appUid, $delIndex)
|
||||
public function CloseCurrentDelegation($appUid, $delIndex, string $status = 'CLOSED', int $statusId = 0)
|
||||
{
|
||||
try {
|
||||
$criteria = new Criteria();
|
||||
@@ -1965,7 +1971,8 @@ class Cases
|
||||
$rowObj = AppDelegationPeer::doSelect($criteria);
|
||||
$user = '';
|
||||
foreach ($rowObj as $appDel) {
|
||||
$appDel->setDelThreadStatus('CLOSED');
|
||||
$appDel->setDelThreadStatus($status);
|
||||
$appDel->setDelThreadStatusId($statusId);
|
||||
$appDel->setDelFinishDate('now');
|
||||
$user = $appDel->getUsrUid();
|
||||
if ($appDel->Validate()) {
|
||||
@@ -1991,7 +1998,7 @@ class Cases
|
||||
$listParticipatedLast->refresh($data);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
/** Update searchindex */
|
||||
/** Update search index */
|
||||
if ($this->appSolr != null) {
|
||||
$this->appSolr->updateApplicationSearchIndex($appUid);
|
||||
}
|
||||
@@ -2019,6 +2026,7 @@ class Cases
|
||||
$rowObj = AppDelegationPeer::doSelect($c);
|
||||
foreach ($rowObj as $appDel) {
|
||||
$appDel->setDelThreadStatus('OPEN');
|
||||
$appDel->setDelThreadStatusId(Delegation::$thread_status['OPEN']);
|
||||
$appDel->setDelFinishDate(null);
|
||||
if ($appDel->Validate()) {
|
||||
$appDel->Save();
|
||||
@@ -4097,77 +4105,75 @@ class Cases
|
||||
}
|
||||
|
||||
/**
|
||||
* pause a Case
|
||||
* Pause a Case
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param int $index
|
||||
* @param string $usrUid
|
||||
* @param string $unpauseDate
|
||||
* @param string $appTitle
|
||||
*
|
||||
* @name pauseCase
|
||||
* @param string $sApplicationUID
|
||||
* @param string $iDelegation
|
||||
* @param string $sUserUID
|
||||
* @param string $sUnpauseDate
|
||||
* @return object
|
||||
*/
|
||||
public function pauseCase($sApplicationUID, $iDelegation, $sUserUID, $sUnpauseDate = null, $appTitle = null)
|
||||
public function pauseCase($appUid, $index, $usrUid, $unpauseDate = null, $appTitle = null)
|
||||
{
|
||||
// Check if the case is unassigned
|
||||
if ($this->isUnassignedPauseCase($sApplicationUID, $iDelegation)) {
|
||||
throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", array(G::LoadTranslation("ID_UNASSIGNED_STATUS"))));
|
||||
}
|
||||
|
||||
$oApplication = new Application();
|
||||
$aFields = $oApplication->Load($sApplicationUID);
|
||||
//get the appthread row id ( APP_THREAD_INDEX' )
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->clearSelectColumns();
|
||||
$oCriteria->addSelectColumn(AppThreadPeer::APP_THREAD_INDEX);
|
||||
$oCriteria->add(AppThreadPeer::APP_UID, $sApplicationUID);
|
||||
$oCriteria->add(AppThreadPeer::DEL_INDEX, $iDelegation);
|
||||
$oDataset = AppThreadPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($oDataset->next()) {
|
||||
$aRow = $oDataset->getRow();
|
||||
} else {
|
||||
$application = new Application();
|
||||
$fields = $application->Load($appUid);
|
||||
$appNumber = $application->getAppNumber();
|
||||
// Get the index of appThread
|
||||
$appThread = Thread::getThread($appUid, $index);
|
||||
$appThread = head($appThread);
|
||||
$threadIndex = $appThread['APP_THREAD_INDEX'];
|
||||
if (empty($threadIndex)) {
|
||||
throw new Exception(G::LoadTranslation("ID_CASE_STOPPED_TRIGGER"));
|
||||
}
|
||||
/** Close the index for pause */
|
||||
$this->CloseCurrentDelegation($appUid, $index, 'PAUSED', Delegation::$thread_status['PAUSED']);
|
||||
|
||||
$this->CloseCurrentDelegation($sApplicationUID, $iDelegation);
|
||||
//now create a row in APP_DELAY with type PAUSE
|
||||
$aData['PRO_UID'] = $aFields['PRO_UID'];
|
||||
$aData['APP_UID'] = $sApplicationUID;
|
||||
$aData['APP_THREAD_INDEX'] = $aRow['APP_THREAD_INDEX'];
|
||||
$aData['APP_DEL_INDEX'] = $iDelegation;
|
||||
$aData['APP_TYPE'] = 'PAUSE';
|
||||
$aData['APP_STATUS'] = $aFields['APP_STATUS'];
|
||||
$aData['APP_DELEGATION_USER'] = $sUserUID;
|
||||
$aData['APP_ENABLE_ACTION_USER'] = $sUserUID;
|
||||
$aData['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s');
|
||||
$aData['APP_DISABLE_ACTION_DATE'] = $sUnpauseDate;
|
||||
$aData['APP_NUMBER'] = $oApplication->getAppNumber();
|
||||
$oAppDelay = new AppDelay();
|
||||
$oAppDelay->create($aData);
|
||||
// Prepare the data for pause
|
||||
$attributes = [
|
||||
'APP_DELAY_UID' => G::generateUniqueID(),
|
||||
'PRO_UID' => $application->getProUid(),
|
||||
'PRO_ID' => $application->getProId(),
|
||||
'APP_UID' => $appUid,
|
||||
'APP_NUMBER' => $appNumber,
|
||||
'APP_THREAD_INDEX' => $threadIndex,
|
||||
'APP_DEL_INDEX' => $index,
|
||||
'APP_TYPE' => 'PAUSE',
|
||||
'APP_STATUS' => $application->getAppStatus(),
|
||||
'APP_DELEGATION_USER' => $usrUid,
|
||||
'APP_DELEGATION_USER_ID' => User::getId($usrUid),
|
||||
'APP_ENABLE_ACTION_USER' => $usrUid,
|
||||
'APP_ENABLE_ACTION_DATE' => date('Y-m-d H:i:s'),
|
||||
'APP_DISABLE_ACTION_DATE' => $unpauseDate,
|
||||
];
|
||||
|
||||
$oApplication->update($aFields);
|
||||
/** Register the pause case */
|
||||
Delay::create($attributes);
|
||||
|
||||
//update searchindex
|
||||
/** Update the application case */
|
||||
$application->update($fields);
|
||||
|
||||
/** Update search index */
|
||||
if ($this->appSolr != null) {
|
||||
$this->appSolr->updateApplicationSearchIndex($sApplicationUID);
|
||||
$this->appSolr->updateApplicationSearchIndex($appUid);
|
||||
}
|
||||
|
||||
$this->getExecuteTriggerProcess($sApplicationUID, 'PAUSED');
|
||||
/** Execute the trigger */
|
||||
$this->getExecuteTriggerProcess($appUid, 'PAUSED');
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$threadTitle = Delegation::getDeltitle($aData['APP_NUMBER'], $aData['APP_DEL_INDEX']);
|
||||
$data = array(
|
||||
'APP_UID' => $sApplicationUID,
|
||||
'DEL_INDEX' => $iDelegation,
|
||||
'USR_UID' => $sUserUID,
|
||||
'APP_RESTART_DATE' => $sUnpauseDate,
|
||||
$threadTitle = Delegation::getDeltitle($appNumber, $index);
|
||||
$data = [
|
||||
'APP_UID' => $appUid,
|
||||
'DEL_INDEX' => $index,
|
||||
'USR_UID' => $usrUid,
|
||||
'APP_RESTART_DATE' => $unpauseDate,
|
||||
'APP_TITLE' => $threadTitle,
|
||||
);
|
||||
$data = array_merge($aFields, $data);
|
||||
|
||||
$oListPaused = new ListPaused();
|
||||
$oListPaused->create($data);
|
||||
];
|
||||
$data = array_merge($fields, $data);
|
||||
$listPaused = new ListPaused();
|
||||
$listPaused->create($data);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
}
|
||||
|
||||
|
||||
@@ -1482,6 +1482,7 @@ class Derivation
|
||||
// Update the DelThreadStatus, the thread is ready for continue
|
||||
$appDelegation = AppDelegationPeer::retrieveByPK($newCase['APPLICATION'], $newCase['INDEX']);
|
||||
$appDelegation->setDelThreadStatus('OPEN');
|
||||
$appDelegation->setDelThreadStatusId(Delegation::$thread_status['OPEN']);
|
||||
$appDelegation->save();
|
||||
|
||||
// Create record in table APP_ASSIGN_SELF_SERVICE_VALUE
|
||||
|
||||
@@ -4147,6 +4147,22 @@ class WorkspaceTools
|
||||
WHERE AD.TAS_ID = 0");
|
||||
$con->commit();
|
||||
|
||||
// Populating APP_DELEGATION.DEL_THREAD_STATUS_ID with paused threads
|
||||
CLI::logging("-> Populating APP_DELEGATION.DEL_THREAD_STATUS_ID \n");
|
||||
$con->begin();
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery("UPDATE APP_DELEGATION AS AD
|
||||
INNER JOIN (
|
||||
SELECT APP_DELAY.APP_NUMBER, APP_DELAY.APP_DEL_INDEX
|
||||
FROM APP_DELAY
|
||||
WHERE APP_TYPE = 'PAUSE' AND APP_DELAY.APP_DISABLE_ACTION_USER = '0'
|
||||
) AS DELAY
|
||||
ON (AD.APP_NUMBER = DELAY.APP_NUMBER AND AD.DEL_INDEX = DELAY.APP_DEL_INDEX)
|
||||
SET AD.DEL_THREAD_STATUS_ID = 3,
|
||||
AD.DEL_THREAD_STATUS = 'PAUSED'
|
||||
WHERE AD.DEL_THREAD_STATUS_ID = 0");
|
||||
$con->commit();
|
||||
|
||||
// Populating APPLICATION.APP_STATUS_ID
|
||||
CLI::logging("-> Populating APPLICATION.APP_STATUS_ID \n");
|
||||
$con->begin();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
|
||||
/**
|
||||
@@ -195,6 +196,7 @@ class AppDelegation extends BaseAppDelegation
|
||||
$this->setDelPriority(($iPriority != '' ? $iPriority : '3'));
|
||||
$this->setDelThread($sAppThread);
|
||||
$this->setDelThreadStatus($theadStatus);
|
||||
$this->setDelThreadStatusId(Delegation::$thread_status[$theadStatus]);
|
||||
$this->setDelDelegateDate('now');
|
||||
$this->setAppNumber($appNumber);
|
||||
$this->setTasId($taskId);
|
||||
|
||||
@@ -881,7 +881,7 @@ class Cases
|
||||
public function participation($usrUid, $caseNumber, $index)
|
||||
{
|
||||
$userId = User::getId($usrUid);
|
||||
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->isThreadOpen();
|
||||
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->threadOpen();
|
||||
$query1 = clone $query;
|
||||
$result = $query->userId($userId)->limit(1)->get()->values()->toArray();
|
||||
$permission = empty($result) ? false : true;
|
||||
@@ -1048,6 +1048,11 @@ class Cases
|
||||
Validator::isDate($date, 'Y-m-d', '$unpaused_date');
|
||||
}
|
||||
|
||||
// Check if the case is unassigned
|
||||
if ($this->isUnassignedPauseCase($appUid, $index)) {
|
||||
throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", [G::LoadTranslation("ID_UNASSIGNED_STATUS")]));
|
||||
}
|
||||
|
||||
/** Pause case */
|
||||
$case->pauseCase($appUid, $index, $usrUid, $date . ' ' . $time);
|
||||
|
||||
|
||||
@@ -1262,6 +1262,9 @@ class AbstractCases implements CasesInterface
|
||||
if ($thread['APP_STATUS'] === 'DRAFT') {
|
||||
$status = 'DRAFT';
|
||||
}
|
||||
if (isset($thread['DEL_THREAD_STATUS']) && $thread['DEL_THREAD_STATUS'] === 'PAUSED') {
|
||||
$status = 'PAUSED';
|
||||
}
|
||||
if ($thread['APP_STATUS'] === 'COMPLETED') {
|
||||
$finishDate = !empty($thread['APP_FINISH_DATE']) ? $thread['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
|
||||
$dateToCompare = $finishDate;
|
||||
|
||||
@@ -181,7 +181,7 @@ class Participated extends AbstractCases
|
||||
switch ($item['APP_STATUS']) {
|
||||
case 'TO_DO':
|
||||
// Get the pending task
|
||||
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
|
||||
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER'], false);
|
||||
foreach ($taskPending as $thread) {
|
||||
$thread['APP_STATUS'] = $item['APP_STATUS'];
|
||||
// Get the thread information
|
||||
|
||||
@@ -192,7 +192,7 @@ class Supervising extends AbstractCases
|
||||
// Only cases in to_do
|
||||
$query->caseTodo();
|
||||
// Only open threads
|
||||
$query->isThreadOpen();
|
||||
$query->threadOpen();
|
||||
// For parallel threads the distinct by APP_NUMBER is important
|
||||
$query->distinct();
|
||||
// Get the list of processes of the supervisor
|
||||
@@ -217,7 +217,7 @@ class Supervising extends AbstractCases
|
||||
// Only cases in to_do
|
||||
$query->caseTodo();
|
||||
// Only open threads
|
||||
$query->isThreadOpen();
|
||||
$query->threadOpen();
|
||||
// For parallel threads the distinct by APP_NUMBER is important
|
||||
$query->distinct();
|
||||
// Get the list of processes of the supervisor
|
||||
|
||||
@@ -8,4 +8,26 @@ class AppDelay extends Model
|
||||
{
|
||||
protected $table = 'APP_DELAY';
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'APP_DELAY_UID',
|
||||
'PRO_UID',
|
||||
'PRO_ID',
|
||||
'APP_UID',
|
||||
'APP_NUMBER',
|
||||
'APP_THREAD_INDEX',
|
||||
'APP_DEL_INDEX',
|
||||
'APP_TYPE',
|
||||
'APP_STATUS',
|
||||
'APP_DELEGATION_USER',
|
||||
'APP_DELEGATION_USER_ID'.
|
||||
'APP_ENABLE_ACTION_USER',
|
||||
'APP_ENABLE_ACTION_DATE',
|
||||
'APP_DISABLE_ACTION_DATE',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -9,4 +9,46 @@ class AppThread extends Model
|
||||
protected $table = 'APP_THREAD';
|
||||
// We do not have create/update timestamps for this table
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Scope a query to filter a specific case
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $appUid
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppUid($query, string $appUid)
|
||||
{
|
||||
return $query->where('APP_UID', $appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter a specific index
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $index
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIndex($query, int $index)
|
||||
{
|
||||
return $query->where('DEL_INDEX', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get thread related to the specific case and index
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param int $index
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getThread(string $appUid, int $index)
|
||||
{
|
||||
$query = AppThread::query()->select(['APP_THREAD_INDEX']);
|
||||
$query->appUid($appUid);
|
||||
$query->index($index);
|
||||
$results = $query->get()->toArray();
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,7 @@ class Application extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information related to the created case
|
||||
* Get information related to the case, avoiding to load the APP_DATA
|
||||
*
|
||||
* @param string $appUid
|
||||
*
|
||||
@@ -382,7 +382,13 @@ class Application extends Model
|
||||
*/
|
||||
public static function getCase($appUid)
|
||||
{
|
||||
$query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']);
|
||||
$query = Application::query()->select([
|
||||
'APP_NUMBER',
|
||||
'APP_STATUS',
|
||||
'PRO_UID',
|
||||
'PRO_ID',
|
||||
'APP_INIT_USER'
|
||||
]);
|
||||
$query->appUid($appUid);
|
||||
$result = $query->get()->toArray();
|
||||
$firstElement = head($result);
|
||||
|
||||
@@ -24,6 +24,8 @@ class Delegation extends Model
|
||||
// Static properties to preserve values
|
||||
public static $usrUid = '';
|
||||
public static $groups = [];
|
||||
// Status name and status id
|
||||
public static $thread_status = ['CLOSED' => 0, 'OPEN' => 1, 'PAUSED' => 3];
|
||||
|
||||
/**
|
||||
* Returns the application this delegation belongs to
|
||||
@@ -92,6 +94,34 @@ class Delegation extends Model
|
||||
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include pause threads
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeThreadPause($query)
|
||||
{
|
||||
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS_ID', '=', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include open and pause threads
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeOpenAndPause($query)
|
||||
{
|
||||
$query->where(function ($query) {
|
||||
$query->threadOpen();
|
||||
$query->orWhere(function ($query) {
|
||||
$query->threadPause();
|
||||
});
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to use when the case is IN_PROGRESS like DRAFT or TO_DO
|
||||
*
|
||||
@@ -101,7 +131,7 @@ class Delegation extends Model
|
||||
*/
|
||||
public function scopeCasesInProgress($query, array $ids)
|
||||
{
|
||||
$query->isThreadOpen()->statusIds($ids);
|
||||
$query->threadOpen()->statusIds($ids);
|
||||
|
||||
return $query;
|
||||
}
|
||||
@@ -546,17 +576,6 @@ class Delegation extends Model
|
||||
return $query->where('APP_DELEGATION.APP_UID', '=', $appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include open threads
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeIsThreadOpen($query)
|
||||
{
|
||||
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to get the last thread
|
||||
*
|
||||
@@ -755,6 +774,19 @@ class Delegation extends Model
|
||||
return $query->whereIn('APP_DELEGATION.PRO_ID', $processes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope where in processes
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $processes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeInProcesses($query, array $processes)
|
||||
{
|
||||
return $query->whereIn('PROCESS.PRO_ID', $processes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope the Inbox cases
|
||||
*
|
||||
@@ -853,6 +885,33 @@ class Delegation extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope process category id
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $category
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCategoryId($query, int $category)
|
||||
{
|
||||
return $query->where('PROCESS.CATEGORY_ID', $category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope top ten
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $column
|
||||
* @param string $order
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTopTen($query, $column, $order)
|
||||
{
|
||||
return $query->orderBy($column, $order)->limit(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope join with delegation for get the previous index
|
||||
*
|
||||
@@ -1015,49 +1074,6 @@ class Delegation extends Model
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope process category id
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $category
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCategoryId($query, $category)
|
||||
{
|
||||
$query->where('PROCESS.CATEGORY_ID', $category);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope top ten
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $column
|
||||
* @param string $order
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTopTen($query, $column, $order)
|
||||
{
|
||||
$query->orderBy($column, $order)->limit(10);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope where in processes
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $processes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeInProcesses($query, $processes)
|
||||
{
|
||||
$query->whereIn('PROCESS.PRO_ID', $processes);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific cases unassigned that the user can view
|
||||
*
|
||||
@@ -1562,7 +1578,7 @@ class Delegation extends Model
|
||||
// Start the second query
|
||||
$query2 = Delegation::query()->select($selectedColumns);
|
||||
$query2->tasksIn($selfServiceTasks);
|
||||
$query2->isThreadOpen();
|
||||
$query2->threadOpen();
|
||||
$query2->noUserInThread();
|
||||
|
||||
// Add join clause with the previous APP_DELEGATION record if required
|
||||
@@ -1856,10 +1872,11 @@ class Delegation extends Model
|
||||
* Return the open thread related to the task
|
||||
*
|
||||
* @param int $appNumber
|
||||
* @param bool $onlyOpen
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPendingThreads(int $appNumber)
|
||||
public static function getPendingThreads(int $appNumber, $onlyOpen = true)
|
||||
{
|
||||
$query = Delegation::query()->select([
|
||||
'TASK.TAS_UID',
|
||||
@@ -1869,6 +1886,7 @@ class Delegation extends Model
|
||||
'APP_DELEGATION.DEL_INDEX',
|
||||
'APP_DELEGATION.DEL_TITLE',
|
||||
'APP_DELEGATION.USR_ID',
|
||||
'APP_DELEGATION.DEL_THREAD_STATUS',
|
||||
'APP_DELEGATION.DEL_DELEGATE_DATE',
|
||||
'APP_DELEGATION.DEL_FINISH_DATE',
|
||||
'APP_DELEGATION.DEL_INIT_DATE',
|
||||
@@ -1877,7 +1895,11 @@ class Delegation extends Model
|
||||
// Join with task
|
||||
$query->joinTask();
|
||||
// Get the open threads
|
||||
$query->threadOpen();
|
||||
if ($onlyOpen) {
|
||||
$query->threadOpen();
|
||||
} else {
|
||||
$query->openAndPause();
|
||||
}
|
||||
// Related to the specific case number
|
||||
$query->case($appNumber);
|
||||
// Get the results
|
||||
|
||||
Reference in New Issue
Block a user