PMCORE-2399

This commit is contained in:
Paula Quispe
2020-12-07 17:07:26 -04:00
parent 54d05bd31f
commit edc5b59009
17 changed files with 493 additions and 1586 deletions

View File

@@ -23,5 +23,5 @@ return [
| directory. However, as usual, you are free to change this value.
|
*/
'compiled' => realpath(PATH_TRUNK . 'bootstrap/cache/views')
'compiled' => realpath(dirname(__DIR__) . '/' . 'bootstrap/cache/views')
];

View File

@@ -24,3 +24,62 @@ $factory->define(\ProcessMaker\Model\AppDelay::class, function (Faker $faker) {
'PRO_ID' => $faker->unique()->numberBetween(1000),
];
});
// Create a delegation with the foreign keys
$factory->state(\ProcessMaker\Model\AppDelay::class, 'paused_foreign_keys', function (Faker $faker) {
// Create values in the foreign key relations
$user = factory(\ProcessMaker\Model\User::class)->create();
$process = factory(\ProcessMaker\Model\Process::class)->create();
$task = factory(\ProcessMaker\Model\Task::class)->create([
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID
]);
$application = factory(\ProcessMaker\Model\Application::class)->create([
'PRO_UID' => $process->PRO_UID,
'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID
]);
$delegation1 = factory(\ProcessMaker\Model\Delegation::class)->create([
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'CLOSED',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'DEL_PREVIOUS' => 0,
'DEL_INDEX' => 1
]);
$delegation = factory(\ProcessMaker\Model\Delegation::class)->create([
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'DEL_PREVIOUS' => $delegation1->DEL_INDEX,
'DEL_INDEX' => $delegation1->DEL_INDEX++
]);
// Return with default values
return [
'APP_DELAY_UID' => G::generateUniqueID(),
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_DEL_INDEX' => $delegation->DEL_INDEX,
'APP_TYPE' => 'PAUSE',
'APP_STATUS' => $application->APP_STATUS,
'APP_DELEGATION_USER' => $user->USR_UID,
'APP_DELEGATION_USER_ID' => $user->USR_ID,
'APP_ENABLE_ACTION_USER' => G::generateUniqueID(),
'APP_ENABLE_ACTION_DATE' => $faker->dateTime(),
'APP_DISABLE_ACTION_USER' => 0,
];
});

View File

@@ -103,7 +103,7 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_priority()
{
$absCases = new AbstractCases();
$arguments = ['ALL', 'VL', 'L', 'N', 'H', 'VH'];
$arguments = ['VL', 'L', 'N', 'H', 'VH'];
$index = array_rand($arguments);
$absCases->setPriority($arguments[$index]);
$actual = $absCases->getPriority();
@@ -120,7 +120,7 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_priorities()
{
$absCases = new AbstractCases();
$arguments = ['ALL', 'VL', 'L', 'N', 'H', 'VH'];
$arguments = ['VL', 'L', 'N', 'H', 'VH'];
$index = array_rand($arguments);
$absCases->setPriorities([$arguments[$index]]);
$actual = $absCases->getPriorities();
@@ -276,15 +276,11 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_case_statuses()
{
$absCases = new AbstractCases();
$arguments = ['ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED'];
$arguments = ['DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED'];
$index = array_rand($arguments);
$absCases->setCaseStatuses([$arguments[$index]]);
$actual = $absCases->getCaseStatuses();
if ($arguments[$index] === 'ALL') {
$this->assertEquals([], $actual);
} else {
$this->assertEquals([$index], $actual);
}
$this->assertEquals([$index], $actual);
}
/**
@@ -407,11 +403,91 @@ class AbstractCasesTest extends TestCase
$actual = $absCases->getLimit();
$this->assertEquals($number, $actual);
}
/**
* This check the setter by default related to the properties
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setProperties()
* @test
*/
public function it_return_set_get_properties_default()
{
$absCases = new AbstractCases();
$properties = [];
$absCases->setProperties($properties);
$actual = $absCases->getProcessId();
$this->assertEquals(0, $actual);
$actual = $absCases->getTaskId();
$this->assertEquals(0, $actual);
$actual = $absCases->getTaskId();
$this->assertEquals(0, $actual);
$actual = $absCases->getUserId();
$this->assertEquals(0, $actual);
$actual = $absCases->getCaseNumber();
$this->assertEquals(0, $actual);
$actual = $absCases->getOrderDirection();
$this->assertEquals('DESC', $actual);
$actual = $absCases->getOrderByColumn();
$this->assertEquals('APP_NUMBER', $actual);
$actual = $absCases->getOffset();
$this->assertEquals(0, $actual);
$actual = $absCases->getLimit();
$this->assertEquals(15, $actual);
// Home - Search
$actual = $absCases->getPriorities();
$this->assertEmpty($actual);
$actual = $absCases->getCaseStatuses();
$this->assertEmpty($actual);
$actual = $absCases->getFilterCases();
$this->assertEmpty($actual);
$actual = $absCases->getDelegateFrom();
$this->assertEmpty($actual);
$actual = $absCases->getDelegateTo();
$this->assertEmpty($actual);
// Home - My cases
$actual = $absCases->getParticipatedStatus();
$this->assertEmpty($actual);
$actual = $absCases->getCaseNumberFrom();
$this->assertEmpty($actual);
$actual = $absCases->getCaseNumberTo();
$this->assertEmpty($actual);
$actual = $absCases->getFinishCaseFrom();
$this->assertEmpty($actual);
$actual = $absCases->getFinishCaseTo();
$this->assertEmpty($actual);
}
/**
* This check the setter related all the properties
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setProperties()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setProcessId()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setTaskId()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setUserId()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseNumber()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseTitle()
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setParticipatedStatus()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseStatus()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setStartCaseFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setStartCaseTo()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setFinishCaseFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setFinishCaseTo()
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setFilterCases()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseStatuses()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setProperties()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDelegateFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDelegateTo()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDueFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDueTo()
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseUid()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCasesUids()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setOrderByColumn()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setOrderDirection()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setPaged()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setOffset()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setLimit()
* @test
*/
public function it_return_set_get_properties()
@@ -431,7 +507,7 @@ class AbstractCasesTest extends TestCase
'delegationDateFrom' => date('Y-m-d'),
'delegationDateTo' => date('Y-m-d'),
// Home - My cases
'filter'=> 'ALL',
'filter'=> 'STARTED',
'caseStatus' => 'TO_DO',
'startCaseFrom' => date('Y-m-d'),
'startCaseTo' => date('Y-m-d'),
@@ -461,9 +537,31 @@ class AbstractCasesTest extends TestCase
// Home - Search
$actual = $absCases->getPriorities();
$this->assertNotEmpty($actual);
$actual = $absCases->getCaseStatuses();
$this->assertNotEmpty($actual);
$actual = $absCases->getFilterCases();
$this->assertEquals([1,8], $actual);
$actual = $absCases->getCasesNumbers();
$this->assertEquals(['3-5','10-15'], $actual);
$actual = $absCases->getRangeCasesFromTo();
$this->assertNotEmpty($actual);
$actual = $absCases->getDelegateFrom();
$this->assertEquals($properties['delegationDateFrom'], $actual);
$actual = $absCases->getDelegateTo();
$this->assertEquals($properties['delegationDateTo'], $actual);
// Home - My cases
$actual = $absCases->getParticipatedStatus();
$this->assertEmpty($actual);
$actual = $absCases->getCaseStatus();
$this->assertEquals(2, $actual);
$actual = $absCases->getStartCaseFrom();
$this->assertEquals($properties['startCaseFrom'], $actual);
$actual = $absCases->getStartCaseTo();
$this->assertEquals($properties['startCaseTo'], $actual);
$actual = $absCases->getFinishCaseFrom();
$this->assertEquals($properties['finishCaseFrom'], $actual);
$actual = $absCases->getFinishCaseTo();
$this->assertEquals($properties['finishCaseTo'], $actual);
// Other
$actual = $absCases->getValueToSearch();
$this->assertEquals($properties['search'], $actual);

View File

@@ -109,7 +109,7 @@ class DelegationTest extends TestCase
public function it_return_scope_delegate_date_from()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->delegateDateFrom($table->DEL_DELEGATE_DATE)->get());
$this->assertCount(1, $table->delegateDateFrom($table->DEL_DELEGATE_DATE->format("Y-m-d"))->get());
}
/**
@@ -121,7 +121,7 @@ class DelegationTest extends TestCase
public function it_return_scope_delegate_date_to()
{
$table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE)->get());
$this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE->format("Y-m-d"))->get());
}
/**

View File

@@ -15,11 +15,11 @@ class AbstractCases implements CasesInterface
const INBOX_STATUSES = ['ALL', 'READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
const CASE_STATUSES = [0 => 'ALL', 1 => 'DRAFT', 2 => 'TO_DO', 3 => 'COMPLETED', 4 => 'CANCELED'];
const CASE_STATUSES = [1 => 'DRAFT', 2 => 'TO_DO', 3 => 'COMPLETED', 4 => 'CANCELED'];
const ORDER_DIRECTIONS = ['DESC', 'ASC'];
const CORRECT_CANCELED_STATUS = 'CANCELED';
const INCORRECT_CANCELED_STATUS = 'CANCELLED';
const PRIORITIES = [0 => 'ALL', 1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
const PRIORITIES = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray'];
const COLOR_OVERDUE = 1;
const COLOR_ON_TIME = 2;
@@ -1164,56 +1164,56 @@ class AbstractCases implements CasesInterface
}
/** Apply filters related to MY CASES */
// My cases filter: started, in-progress, completed, supervising
if (!empty($properties['filter']) && get_class($this) === Participated::class) {
if (get_class($this) === Participated::class && !empty($properties['filter'])) {
$this->setParticipatedStatus($properties['filter']);
}
// Filter by one case status
if (!empty($properties['caseStatus']) && get_class($this) === Participated::class) {
if (get_class($this) === Participated::class && !empty($properties['caseStatus'])) {
$this->setCaseStatus($properties['caseStatus']);
}
// Filter date related to started date from
if (!empty($properties['startCaseFrom'] && (get_class($this) === Participated::class || get_class($this) === Supervising::class))) {
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['startCaseFrom'])) {
$this->setStartCaseFrom($properties['startCaseFrom']);
}
// Filter date related to started date to
if (!empty($properties['startCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['startCaseTo'])) {
$this->setStartCaseTo($properties['startCaseTo']);
}
// Filter date related to finish date from
if (!empty($properties['finishCaseFrom']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['finishCaseFrom'])) {
$this->setFinishCaseFrom($properties['finishCaseFrom']);
}
// Filter date related to finish date to
if (!empty($properties['finishCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['finishCaseTo'])) {
$this->setFinishCaseTo($properties['finishCaseTo']);
}
/** Apply filters related to SEARCH */
// Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15'
if (!empty($properties['filterCases']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['filterCases'])) {
$this->setFilterCases($properties['filterCases']);
}
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
if (!empty($properties['caseStatuses']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['caseStatuses'])) {
$this->setCaseStatuses($properties['caseStatuses']);
}
// Filter by more than one priorities like ['VL', 'L', 'N']
if (!empty($properties['priorities']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['priorities'])) {
$this->setProperties($properties['priorities']);
}
// Filter date newest related to delegation/started date
if (!empty($properties['delegationDateFrom'] && get_class($this) === Search::class)) {
if (get_class($this) === Search::class && !empty($properties['delegationDateFrom'])) {
$this->setDelegateFrom($properties['delegationDateFrom']);
}
// Filter date oldest related to delegation/started date
if (!empty($properties['delegationDateTo']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['delegationDateTo'])) {
$this->setDelegateTo($properties['delegationDateTo']);
}
// Filter date newest related to due date
if (!empty($properties['dueDateFrom']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['dueDateFrom'])) {
$this->setDueFrom($properties['dueDateFrom']);
}
// Filter date oldest related to due date
if (!empty($properties['dueDateTo']) && get_class($this) === Search::class) {
if (get_class($this) === Search::class && !empty($properties['dueDateTo'])) {
$this->setDueTo($properties['dueDateTo']);
}
// Filter by case uid

View File

@@ -20,6 +20,8 @@ class Draft extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**

View File

@@ -23,6 +23,8 @@ class Inbox extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**

View File

@@ -22,6 +22,8 @@ class Participated extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**
@@ -107,16 +109,15 @@ class Participated extends AbstractCases
$query->participated($this->getUserId());
// Add filter
$filter = $this->getParticipatedStatus();
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED by user
$query->caseStarted();
break;
case 'IN_PROGRESS':
// Scope that search for the TO_DO
$query->selectRaw(
'CONCAT(
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED by user
$query->caseStarted();
break;
case 'IN_PROGRESS':
// Scope that search for the TO_DO
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
@@ -131,17 +132,18 @@ class Participated extends AbstractCases
),
\']\'
) AS PENDING'
);
$query->caseInProgress();
$query->groupBy('APP_NUMBER');
break;
case 'COMPLETED':
// Scope that search for the COMPLETED
$query->caseCompleted();
// Scope to set the last thread
$query->lastThread();
break;
}
);
// Only cases in progress
$query->caseInProgress();
// Group by AppNumber
$query->groupBy('APP_NUMBER');
break;
case 'COMPLETED':
// Scope that search for the COMPLETED
$query->caseCompleted();
// Scope to set the last thread
$query->lastThread();
break;
}
/** Apply filters */
$this->filters($query);

View File

@@ -23,6 +23,8 @@ class Paused extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**

View File

@@ -25,6 +25,8 @@ class Search extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**

View File

@@ -21,6 +21,8 @@ class Supervising extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**
@@ -98,6 +100,23 @@ class Supervising extends AbstractCases
if (!empty($processes)) {
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
\'{"tas_id":\',
APP_DELEGATION.TAS_ID,
\', "user_id":\',
APP_DELEGATION.USR_ID,
\', "due_date":"\',
APP_DELEGATION.DEL_TASK_DUE_DATE,
\'"}\'
)
),
\']\'
) AS PENDING'
);
// Join with process
$query->joinProcess();
// Join with task
@@ -112,6 +131,8 @@ class Supervising extends AbstractCases
$query->userId($this->getUserId());
// Scope the specific array of processes supervising
$query->processInList($processes);
// Group by appNumber
$query->groupBy('APP_NUMBER');
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
@@ -133,6 +154,10 @@ class Supervising extends AbstractCases
$startDate = (string)$item['APP_CREATE_DATE'];
$endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
// Get the detail related to the open thread
if (!empty($item['PENDING'])) {
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
}
return $item;
});

View File

@@ -24,6 +24,8 @@ class Unassigned extends AbstractCases
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
];
/**

View File

@@ -457,7 +457,8 @@ class Home extends Api
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
// We will to enable always the pagination
$result['total'] = $list->getLimit() + 1;
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());