PMCORE-1213

This commit is contained in:
Paula Quispe
2020-11-11 10:38:08 -04:00
parent 50b5eaec39
commit 4120a8ca9f
21 changed files with 888 additions and 431 deletions

View File

@@ -2,6 +2,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use Datetime;
use Exception;
use ProcessMaker\BusinessModel\Interfaces\CasesInterface;
use ProcessMaker\BusinessModel\Validator;
@@ -10,13 +11,19 @@ class AbstractCases implements CasesInterface
{
// Constants for validate values
const INBOX_STATUSES = ['', 'ALL', 'READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['', 'ALL', 'STARTED', 'COMPLETED'];
const PARTICIPATED_STATUSES = ['', 'ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['', 'ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
const CASE_STATUSES = ['', 'ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED', 'CANCELED'];
const ORDER_DIRECTIONS = ['DESC', 'ASC'];
const CORRECT_CANCELED_STATUS = 'CANCELED';
const INCORRECT_CANCELED_STATUS = 'CANCELLED';
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;
const COLOR_DRAFT = 3;
const COLOR_PAUSED = 4;
const COLOR_UNASSIGNED = 5;
// Filter by category from a process, know as "$category" in the old lists classes
private $categoryUid = '';
@@ -70,9 +77,6 @@ class AbstractCases implements CasesInterface
// Filter by specific cases using the case numbers
private $casesNumbers = [];
// Filter by taskId
private $taskId = '';
// Filter recent cases starting by a specific date, know as "newestthan" in the old lists classes
private $newestThan = '';
@@ -99,7 +103,7 @@ class AbstractCases implements CasesInterface
*
* @param string $categoryUid
*/
public function setCategoryUid($categoryUid)
public function setCategoryUid(string $categoryUid)
{
$this->categoryUid = $categoryUid;
}
@@ -119,7 +123,7 @@ class AbstractCases implements CasesInterface
*
* @param string $processUid
*/
public function setProcessUid($processUid)
public function setProcessUid(string $processUid)
{
$this->processUid = $processUid;
}
@@ -139,7 +143,7 @@ class AbstractCases implements CasesInterface
*
* @param int $processId
*/
public function setProcessId($processId)
public function setProcessId(int $processId)
{
$this->processId = $processId;
}
@@ -179,7 +183,7 @@ class AbstractCases implements CasesInterface
*
* @param string $userUid
*/
public function setUserUid($userUid)
public function setUserUid(string $userUid)
{
$this->userUid = $userUid;
}
@@ -199,7 +203,7 @@ class AbstractCases implements CasesInterface
*
* @param int $userId
*/
public function setUserId($userId)
public function setUserId(int $userId)
{
$this->userId = $userId;
}
@@ -219,7 +223,7 @@ class AbstractCases implements CasesInterface
*
* @param string $valueToSearch
*/
public function setValueToSearch($valueToSearch)
public function setValueToSearch(string $valueToSearch)
{
$this->valueToSearch = $valueToSearch;
}
@@ -241,7 +245,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setInboxStatus($inboxStatus)
public function setInboxStatus(string $inboxStatus)
{
// Convert the value to upper case
$inboxStatus = strtoupper($inboxStatus);
@@ -276,7 +280,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setParticipatedStatus($participatedStatus)
public function setParticipatedStatus(string $participatedStatus)
{
// Convert the value to upper case
$participatedStatus = strtoupper($participatedStatus);
@@ -311,7 +315,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setRiskStatus($riskStatus)
public function setRiskStatus(string $riskStatus)
{
// Convert the value to upper case
$riskStatus = strtoupper($riskStatus);
@@ -380,7 +384,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setCaseStatus($caseStatus)
public function setCaseStatus(string $caseStatus)
{
// Convert the value to upper case
$caseStatus = strtoupper($caseStatus);
@@ -418,7 +422,7 @@ class AbstractCases implements CasesInterface
*
* @param string $caseUid
*/
public function setCaseUid($caseUid)
public function setCaseUid(string $caseUid)
{
$this->caseUid = $caseUid;
}
@@ -438,7 +442,7 @@ class AbstractCases implements CasesInterface
*
* @param int $caseNumber
*/
public function setCaseNumber($caseNumber)
public function setCaseNumber(int $caseNumber)
{
$this->caseNumber = $caseNumber;
}
@@ -525,26 +529,6 @@ class AbstractCases implements CasesInterface
return $this->casesNumbers;
}
/**
* Set taskId value
*
* @param int $taskId
*/
public function setTaskId($taskId)
{
$this->taskId = (int) $taskId;
}
/**
* Get taskId value
*
* @return int
*/
public function getTaskId()
{
return $this->taskId;
}
/**
* Set Newest Than value
*
@@ -552,7 +536,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setNewestThan($newestThan)
public function setNewestThan(string $newestThan)
{
if (!Validator::isDate($newestThan, 'Y-m-d')) {
throw new Exception("Value '{$newestThan}' is not a valid date.");
@@ -577,7 +561,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setOldestThan($oldestThan)
public function setOldestThan(string $oldestThan)
{
if (!Validator::isDate($oldestThan, 'Y-m-d')) {
throw new Exception("Value '{$oldestThan}' is not a valid date.");
@@ -600,7 +584,7 @@ class AbstractCases implements CasesInterface
*
* @param string $orderByColumn
*/
public function setOrderByColumn($orderByColumn)
public function setOrderByColumn(string $orderByColumn)
{
// Convert the value to upper case
$orderByColumn = strtoupper($orderByColumn);
@@ -625,7 +609,7 @@ class AbstractCases implements CasesInterface
*
* @throws Exception
*/
public function setOrderDirection($orderDirection)
public function setOrderDirection(string $orderDirection)
{
// Convert the value to upper case
$orderDirection = strtoupper($orderDirection);
@@ -653,7 +637,7 @@ class AbstractCases implements CasesInterface
*
* @param bool $paged
*/
public function setPaged($paged)
public function setPaged(bool $paged)
{
$this->paged = (bool) $paged;
}
@@ -673,7 +657,7 @@ class AbstractCases implements CasesInterface
*
* @param int $offset
*/
public function setOffset($offset)
public function setOffset(int $offset)
{
$this->offset = (int) $offset;
}
@@ -693,7 +677,7 @@ class AbstractCases implements CasesInterface
*
* @param int $limit
*/
public function setLimit($limit)
public function setLimit(int $limit)
{
$this->limit = (int) $limit;
}
@@ -708,6 +692,35 @@ class AbstractCases implements CasesInterface
return $this->limit;
}
/**
* Get task color according the due date
*
* @param string $dueDate
*
* @return int
*/
public function getTaskColor(string $dueDate)
{
$currentDate = new DateTime('now');
$dueDate = new DateTime($dueDate);
if ($dueDate > $currentDate) {
$taskColor = self::COLOR_OVERDUE;
} else {
$taskColor = self::COLOR_ON_TIME;
if (get_class($this) === Draft::class) {
$taskColor = self::COLOR_DRAFT;
}
if (get_class($this) === Paused::class) {
$taskColor = self::COLOR_PAUSED;
}
if (get_class($this) === Unassigned::class) {
$taskColor = self::COLOR_UNASSIGNED;
}
}
return $taskColor;
}
/**
* Set all properties
*
@@ -715,86 +728,83 @@ class AbstractCases implements CasesInterface
*/
public function setProperties(array $properties)
{
// Filter by category
if (!empty($properties['category'])) {
$this->setCategoryUid($properties['category']);
}
// Filter by process
if (!empty($properties['process'])) {
$this->setProcessUid($properties['process']);
$this->setProcessId($properties['process']);
}
// Filter by task
if (!empty($properties['task'])) {
$this->setTaskId($properties['task']);
}
// Filter by user
if (!empty($properties['user'])) {
$this->setUserUid($properties['user']);
$this->setUserId($properties['user']);
}
// Filter by priority
if (!empty($properties['priority'])) {
$this->setPriority($properties['priority']);
}
// Filter by case number
if (!empty($properties['caseNumber'])) {
$this->setCaseNumber($properties['caseNumber']);
}
// Filter by range of case number
if (!empty($properties['caseNumberFrom']) && !empty($properties['caseNumberTo'])) {
$this->setRangeCaseNumber($properties['caseNumberFrom'], $properties['caseNumberTo']);
}
// Filter by search
if (!empty($properties['search'])) {
$this->setValueToSearch($properties['search']);
}
if (!empty($properties['filter']) && get_class($this) === Inbox::class) {
$this->setInboxStatus($properties['filter']);
}
if (!empty($properties['filter']) && get_class($this) === Participated::class) {
// My cases filter: started, in-progress, completed, supervising
if (!empty($properties['filter']) && get_class($this) === MyCases::class) {
$this->setParticipatedStatus($properties['filter']);
}
if (!empty($properties['filterStatus']) && get_class($this) === Inbox::class) {
$this->setRiskStatus($properties['filterStatus']);
}
if (!empty($properties['filterStatus']) && get_class($this) === Participated::class) {
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === MyCases::class) {
$this->setCaseStatus($properties['filterStatus']);
}
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === Search::class) {
$this->setCaseStatus($properties['filterStatus']);
}
// Filter by case uid
if (!empty($properties['caseLink'])) {
$this->setCaseUid($properties['caseLink']);
}
// Filter by array of case uids
if (!empty($properties['appUidCheck'])) {
$this->setCasesUids($properties['appUidCheck']);
}
// Filter date newest related to delegation date
if (!empty($properties['newestthan'])) {
$this->setNewestThan($properties['newestthan']);
}
// Filter date oldest related to delegation date
if (!empty($properties['oldestthan'])) {
$this->setOldestThan($properties['oldestthan']);
}
// Sort column
if (!empty($properties['sort'])) {
$this->setOrderByColumn($properties['sort']);
}
// Direction column
if (!empty($properties['dir'])) {
$this->setOrderDirection($properties['dir']);
}
// Paged
if (!empty($properties['paged'])) {
$this->setPaged($properties['paged']);
}
// Start
if (!empty($properties['start'])) {
$this->setOffset($properties['start']);
}
// Limit
if (!empty($properties['limit'])) {
$this->setLimit($properties['limit']);
}

View File

@@ -2,10 +2,34 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Delegation;
class Draft extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Get data self-services cases by user
*
@@ -13,15 +37,13 @@ class Draft extends AbstractCases
*/
public function getData()
{
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with application for add the initial scope for DRAFT cases
$query->draft($this->getUserId());
// Add join with task
$query->specificTaskTypes(['NORMAL', 'ADHOC']);
// Add join for process, but only for certain scenarios such as category or process
if ($this->getCategoryUid() || $this->getProcessUid() || $this->getOrderByColumn() === 'PRO_TITLE') {
$query->categoryProcess($this->getCategoryUid());
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
@@ -42,6 +64,20 @@ class Draft extends AbstractCases
$query->offset($this->getOffset())->limit($this->getLimit());
// Get the data
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
return $item;
});
return $results->values()->toArray();
}

View File

@@ -2,10 +2,37 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Delegation;
class Inbox extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Get the data corresponding to List Inbox
*
@@ -14,14 +41,14 @@ class Inbox extends AbstractCases
public function getData()
{
// Start the query for get the cases related to the user
$query = Delegation::query()->select();
// Scope that sets the queries for List Inbox
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with users
$query->joinUser();
// Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId());
// Scope that joins with the process and/or for an specific category in the process
$query->categoryProcess($this->getCategoryUid());
// Define a specific risk
switch ($this->getRiskStatus()) {
case 'ON_TIME':
// Scope that search for the ON_TIME cases
@@ -36,21 +63,31 @@ class Inbox extends AbstractCases
$query->overdue();
break;
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
// Scope to search for an specific process
$query->processId($this->getProcessId());
}
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
return $item;
});
//Return the values as an array format
return $results->values()->toArray();
}

View File

@@ -0,0 +1,62 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
class MyCases extends AbstractCases
{
/**
* Gets the data for the Cases list My Cases
*
* @return array
*/
public function getData()
{
$filter = $this->getParticipatedStatus();
$result = [];
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$result = $list->getData();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$result = $list->getData();
break;
}
}
return $result;
}
/**
* Gets the total of My Cases
*
* @return int
*/
public function getCounter()
{
$filter = $this->getParticipatedStatus();
$count = 0;
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$count = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$count = $list->getCounter();
break;
}
}
return $count;
}
}

View File

@@ -7,6 +7,30 @@ use ProcessMaker\Model\Delegation;
class Participated extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Get the data corresponding to Participated
*
@@ -16,54 +40,67 @@ class Participated extends AbstractCases
{
// Start the query for get the cases related to the user
$query = Delegation::query()->select();
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Scope to Participated
$query->participated($this->getUserId());
// Add filter
$filter = $this->getParticipatedStatus();
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED
$query->caseStarted();
break;
case 'IN-PROGRESS':
// Scope that search for the TO_DO
$query->caseInProgress();
break;
case 'COMPLETED':
// Scope that search for the COMPLETED
$query->caseCompleted();
break;
}
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// Scope the specific category
$category = $this->getCategoryUid();
if (!empty($category)) {
$query->categoryProcess($category);
}
// Scope the specific case status
$status = $this->getCaseStatus();
if (array_key_exists($status, Application::$app_status_values)) {
$statusId = Application::$app_status_values[$status];
$query->appStatusId($statusId);
}
// Add filter
$filter = $this->getParticipatedStatus();
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED cases by specific user
$query->caseStarted();
break;
case 'COMPLETED':
// Scope that search for the COMPLETED cases by specific user
$query->caseCompleted();
break;
}
}
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$result = $query->get();
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null;
// Calculate duration
$startDate = $item['DEL_DELEGATE_DATE'];
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
//Return the values as an array format
return $result->values()->toArray();
return $item;
});
return $results->values()->toArray();
}
/**
* Get the number of rows corresponding to the Participate
*

View File

@@ -2,10 +2,37 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Delegation;
class Paused extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Gets the data for the paused cases list
*
@@ -13,16 +40,37 @@ class Paused extends AbstractCases
*/
public function getData()
{
$query = Delegation::query()->select();
$query->paused($this->getUserId(), $this->getCategoryUid(), $this->getTaskId(), $this->getCaseNumber());
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber());
// Join with delegation for get the previous index
$query->joinPreviousIndex();
// Join with delegation for get the previous user
$query->joinPreviousUser();
// Add any sort if needed
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
$result = $query->get()->values()->toArray();
return $item;
});
return $result;
return $results->values()->toArray();
}
/**
@@ -32,8 +80,10 @@ class Paused extends AbstractCases
*/
public function getCounter()
{
$total = $this->getData();
$query = Delegation::query()->select();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber());
return count($total);
return $query->count();
}
}

View File

@@ -2,10 +2,37 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Delegation;
class Search extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Get the data corresponding to advanced search
*
@@ -13,11 +40,17 @@ class Search extends AbstractCases
*/
public function getData()
{
$query = Delegation::query()->select();
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Filter by case number
$query->case($this->getCaseNumber());
if ($this->getCaseNumber() > 0) {
$query->case($this->getCaseNumber());
}
// Filter by case number: from and to
if ($this->getFromCaseNumber() > 0 && $this->getToCaseNumber() > 0) {
$query->rangeOfCases($this->getFromCaseNumber(), $this->getToCaseNumber());
@@ -25,39 +58,43 @@ class Search extends AbstractCases
// @todo: Filter by case title, pending from other PRD
// Filter by category
$query->categoryProcess($this->getCategoryUid());
// Filter by priority
if ($this->getPriority() > 0) {
$query->priority($this->getPriority());
}
// Filter by process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// Filter by user
if (!empty($this->getUserId())) {
$query->userId($this->getUserId());
}
// Filter by task
if (!empty($this->getTaskId())) {
$query->task($this->getTaskId());
}
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
return $item;
});
//Return the values as an array format
return $results->values()->toArray();
}

View File

@@ -7,6 +7,30 @@ use ProcessMaker\Model\ProcessUser;
class Supervising extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Gets the data for the Cases list Review
*
@@ -14,37 +38,53 @@ class Supervising extends AbstractCases
*/
public function getData()
{
//Get the list of processes of the supervisor
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Start tthe query for get the cases related to the user
$query = Delegation::query()->select();
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with users
$query->joinUser();
// Join with task and scope that sets the queries for List Inbox
$query->inbox($this->getUserId());
$query->categoryProcess($this->getCategoryUid());
// Scope the specific array of processes supervising
$query->processInList($processes);
// Join with delegation for get the previous index
$query->joinPreviousIndex();
// Join with delegation for get the previous user
$query->joinPreviousUser();
// Scope to search for an specific case
if (!empty($this->getCaseNumber())) {
$query->case($this->getCaseNumber());
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
//The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
//The limit clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null;
// Calculate duration
$startDate = $item['DEL_DELEGATE_DATE'];
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
return $query->get()->values()->toArray();
return $item;
});
return $results->values()->toArray();
}
/**
@@ -54,7 +94,12 @@ class Supervising extends AbstractCases
*/
public function getCounter()
{
$quantity = $this->getData();
return count($quantity);
$query = Delegation::query()->select();
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Scope the specific array of processes supervising
$query->processInList($processes);
return $query->count();
}
}

View File

@@ -2,14 +2,38 @@
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\AppAssignSelfServiceValue;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\TaskUser;
class Unassigned extends AbstractCases
{
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
/**
* Get data self-services cases by user
*
@@ -17,15 +41,15 @@ class Unassigned extends AbstractCases
*/
public function getData()
{
$query = Delegation::query()->select();
// Add the initial scope for unassigned cases
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with users
$query->joinUser();
// Join with application for add the initial scope for unassigned cases
$query->selfService($this->getUserUid());
// Add join for application, for get the case title when the case status is TO_DO
$query->appStatusId(Application::STATUS_TODO);
// Add join for process, but only for certain scenarios such as category or process
if ($this->getCategoryUid() || $this->getProcessUid() || $this->getOrderByColumn() === 'PRO_TITLE') {
$query->categoryProcess($this->getCategoryUid());
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
@@ -53,6 +77,20 @@ class Unassigned extends AbstractCases
$query->offset($this->getOffset())->limit($this->getLimit());
// Get the data
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = 1; // green - onTime
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
return $item;
});
return $results->values()->toArray();
}

View File

@@ -102,6 +102,18 @@ class Delegation extends Model
return $query->where('DEL_INDEX', '=', 1);
}
/**
* Scope a query to get the in-progress
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseInProgress($query)
{
return $query->appStatusId(2);
}
/**
* Scope a query to get the completed by me
*
@@ -434,7 +446,7 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategoryProcess($query, $category = '')
public function scopeJoinCategoryProcess($query, $category = '')
{
$query->join('PROCESS', function ($join) use ($category) {
$join->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID');
@@ -549,7 +561,7 @@ class Delegation extends Model
}
/**
* Scope delegation table
* Scope join with delegation for get the previous index
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
@@ -566,7 +578,7 @@ class Delegation extends Model
}
/**
* Scope users table as previous
* Scope join with user for get the previous user
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
@@ -581,6 +593,68 @@ class Delegation extends Model
return $query;
}
/**
* Scope join with process
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinProcess($query)
{
$query->leftJoin('PROCESS', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.PRO_ID', '=', 'PROCESS.PRO_ID');
});
return $query;
}
/**
* Scope join with task
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinTask($query)
{
$query->leftJoin('TASK', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID');
});
return $query;
}
/**
* Scope join with user
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinUser($query)
{
$query->leftJoin('USERS', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.USR_ID', '=', 'USERS.USR_ID');
});
return $query;
}
/**
* Scope join with application
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeJoinApplication($query)
{
$query->leftJoin('APPLICATION', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
}
/**
* Scope the Process is in list
*
@@ -589,41 +663,42 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProcessInList($query, $processes)
public function scopeProcessInList($query, array $processes)
{
$query->whereIn('PROCESS.PRO_ID', $processes);
$query->whereIn('APP_DELEGATION.PRO_ID', $processes);
return $query;
}
/**
* Scope AppDelay and AppDelegation
*
* Scope join with AppDelay
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $type
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAppDelayPaused($query)
public function scopeJoinAppDelay($query, $type = 'PAUSE')
{
$query->leftJoin('APP_DELAY', function ($leftJoin) {
$query->leftJoin('APP_DELAY', function ($leftJoin) use ($type) {
$leftJoin->on('APP_DELAY.APP_NUMBER', '=', 'APP_DELEGATION.APP_NUMBER')
->on('APP_DELEGATION.DEL_INDEX', '=', 'APP_DELAY.APP_DEL_INDEX');
});
$query->where('APP_DELAY.APP_DISABLE_ACTION_USER', '=', '0');
$query->where('APP_DELAY.APP_TYPE', '=', 'PAUSE');
$query->where('APP_DELAY.APP_TYPE', '=', $type);
return $query;
}
/**
* Scope Users and AppDelay
* Scope join with AppDelay and users
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $userId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAppDelayUserDel($query, $userId)
public function scopeJoinAppDelayUsers($query, int $userId)
{
$query->leftJoin('USERS', function ($leftJoin) {
$leftJoin->on('APP_DELAY.APP_DELEGATION_USER', '=', 'USERS.USR_UID');
@@ -635,78 +710,34 @@ class Delegation extends Model
return $query;
}
/**
* Scope Application and AppDelegation
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeApplication($query)
{
$query->leftJoin('APPLICATION', function ($leftJoin) {
$leftJoin->on('APP_DELEGATION.APP_NUMBER', '=', 'APPLICATION.APP_NUMBER');
});
}
/**
* Scope paused cases list
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $userId
* @param string $categoryUid
* @param int $taskId
* @param int $caseNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePaused($query, $userId, $categoryUid, $taskId, $caseNumber)
public function scopePaused($query, int $userId, int $taskId, int $caseNumber)
{
$query->appDelayPaused();
$query->appDelayUserDel($userId);
$query->application();
$query->caseNumberFilter($caseNumber);
$query->categoryProcess($categoryUid);
$query->joinAppDelay('PAUSE');
$query->joinAppDelayUsers($userId);
$query->joinApplication();
// Specific case number
if (!empty($caseNumber)) {
$query->case($caseNumber);
}
$query->excludeTaskTypes(Task::DUMMY_TASKS);
$query->taskIdFilter($taskId);
return $query;
}
/**
* Scope taskId filter
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $taskId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTaskIdFilter($query, $taskId)
{
if ($taskId) {
$query->where('TASK.TAS_ID', $taskId);
// Specific task
if (!empty($taskId)) {
$query->task($taskId);
}
return $query;
}
/**
* Scope CaseNumber Filter
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $caseNumber
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseNumberFilter($query, $caseNumber)
{
if ($caseNumber) {
$query->where('APP_DELEGATION.APP_NUMBER', $caseNumber);
}
return $query;
}
/**
* Get specific cases unassigned that the user can view
*

View File

@@ -1,6 +1,5 @@
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@@ -602,6 +601,55 @@ function getMysqlVersion()
return $mysqlVersion;
}
/**
* Get the version of the mysql
*
* @param string $date in the format <Y-m-d H:m:d>
* @param string $mask
*
* @return string
*/
function applyMaskDateEnvironment(string $date, $mask = '')
{
$result = '';
if (empty($mask)) {
$systemConf = new Configurations();
$systemConf->loadConfig($obj, 'ENVIRONMENT_SETTINGS', '');
$mask = isset($systemConf->aConfig['dateFormat']) ? $systemConf->aConfig['dateFormat'] : '';
}
if (!empty($date)) {
$date = new DateTime($date);
$result = $date->format($mask);
}
return $result;
}
/**
* Get the difference between two dates
*
* @param string $startDate
* @param string $endDate
*
* @return string
*/
function getDiffBetweenDates(string $startDate, string $endDate)
{
$result = '';
if (!empty($startDate) && !empty($endDate)) {
$initDate = new DateTime($startDate);
$finishDate = new DateTime($endDate);
$diff = $initDate->diff($finishDate);
$format = ' %a ' . G::LoadTranslation('ID_DAY_DAYS');
$format .= ' %H ' . G::LoadTranslation('ID_HOUR_ABBREVIATE');
$format .= ' %I ' . G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$format .= ' %S ' . G::LoadTranslation('ID_SECOND_ABBREVIATE');
$result = $diff->format($format);
}
return $result;
}
/**
* Move the uploaded file to the documents folder
*