PMCORE-2381

This commit is contained in:
Paula Quispe
2020-11-25 18:11:22 -04:00
parent a00593696d
commit 6bdadfd59c
21 changed files with 1925 additions and 731 deletions

View File

@@ -6,18 +6,20 @@ use Datetime;
use Exception;
use ProcessMaker\BusinessModel\Interfaces\CasesInterface;
use ProcessMaker\BusinessModel\Validator;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
class AbstractCases implements CasesInterface
{
// Constants for validate values
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 = ['', 'ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED', 'CANCELED'];
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 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 PRIORITIES = [0 => 'ALL', 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;
@@ -58,33 +60,62 @@ class AbstractCases implements CasesInterface
// Filter by specific priority
private $priority = 0;
// Filter by specific priorities
private $priorities = [];
// Filter by case status, know as "$filterStatus" in the old "participated last" class
private $caseStatus = '';
// Filter by case statuses
private $caseStatuses = [1, 2, 3, 4];
// Filter by a specific case, know as "$caseLink" in the old lists classes
private $caseUid = '';
// Filter by a specific case using case number
private $caseNumber = 0;
// Filter by a specific range of case number
private $fromCaseNumber = 0;
private $toCaseNumber = 0;
// Filter by specific cases using the case numbers like [1,4,8]
private $casesNumbers = [];
// Filter by only one range of case number
private $caseNumberFrom = 0;
private $caseNumberTo = 0;
// Filter more than one range of case number
private $rangeCasesFromTo = [];
// Filter by a specific cases like 1,3-5,8,10-15
private $filterCases = '';
// Filter by a specific case title
private $caseTitle = '';
// Filter by specific cases, know as "$appUidCheck" in the old lists classes
private $casesUids = [];
// Filter by specific cases using the case numbers
private $casesNumbers = [];
// Filter range related to the start case date
private $startCaseFrom = '';
private $startCaseTo = '';
// Filter recent cases starting by a specific date, know as "newestthan" in the old lists classes
private $newestThan = '';
// Filter range related to the finish case date
private $finishCaseFrom = '';
private $finishCaseTo = '';
// Filter old cases ending by a specific date, know as "oldestthan" in the old lists classes
private $oldestThan = '';
// Filter range related to the delegate date
private $delegateFrom = '';
private $delegateTo = '';
// Filter range related to the finish date
private $finishFrom = '';
private $finishTo = '';
// Filter range related to the due date
private $dueFrom = '';
private $dueTo = '';
// Column by which the results will be sorted, know as "$sort" in the old lists classes
private $orderByColumn = 'APP_DELEGATION.APP_NUMBER';
private $orderByColumn = 'APP_NUMBER';
// Sorts the data in descending or ascending order, know as "$dir" in the old lists classes
private $orderDirection = 'DESC';
@@ -96,7 +127,7 @@ class AbstractCases implements CasesInterface
private $offset = 0;
// Number of rows to return
private $limit = 25;
private $limit = 15;
/**
* Set Category Uid value
@@ -290,9 +321,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Participated status '{$participatedStatus}' is not valid.");
}
// If empty string is sent, use value 'ALL'
if ($participatedStatus === '') {
$participatedStatus = 'ALL';
// If empty string will not apply the filter
if ($participatedStatus === 'ALL') {
$participatedStatus = '';
}
$this->participatedStatus = $participatedStatus;
@@ -325,9 +356,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Risk status '{$riskStatus}' is not valid.");
}
// If empty string is sent, use value 'ALL'
if ($riskStatus === '') {
$riskStatus = 'ALL';
// If empty string will not apply the filter
if ($riskStatus === 'ALL') {
$riskStatus = '';
}
$this->riskStatus = $riskStatus;
@@ -346,17 +377,16 @@ class AbstractCases implements CasesInterface
/**
* Set priority value
*
* @param int $priority
* @param string $priority
*
* @throws Exception
*/
public function setPriority(int $priority)
public function setPriority(string $priority)
{
// Validate the priority value
if (!empty($priority)) {
if (!empty(self::PRIORITIES[$priority])) {
$priorityCode = $priority;
} else {
$priorityCode = array_search($priority, self::PRIORITIES);
if (empty($priorityCode) && $priorityCode !== 0) {
throw new Exception("Priority value {$priority} is not valid.");
}
} else {
@@ -378,45 +408,109 @@ class AbstractCases implements CasesInterface
}
/**
* Set Case status
* Set priorities
*
* @param string $caseStatus
* @param array $priorities
*
* @throws Exception
*/
public function setCaseStatus(string $caseStatus)
public function setPriorities(array $priorities)
{
// Convert the value to upper case
$caseStatus = strtoupper($caseStatus);
// Validate the case status
if (!in_array($caseStatus, self::CASE_STATUSES)) {
throw new Exception("Case status '{$caseStatus}' is not valid.");
$prioritiesCode = [];
foreach ($priorities as $priority) {
// Validate the priority value
$priorityCode = array_search($priority, self::PRIORITIES);
if (empty($priorityCode) && $priorityCode !== 0) {
throw new Exception("Priority value {$priority} is not valid.");
} else {
array_push($prioritiesCode, $priorityCode);
}
}
$this->priorities = $prioritiesCode;
}
// If empty string is sent, use value 'ALL'
if ($caseStatus === '') {
$caseStatus = 'ALL';
}
/**
* Get priorities
*
* @return array
*/
public function getPriorities()
{
return $this->priorities;
}
/**
* Set Case status
*
* @param string $status
*
* @throws Exception
*/
public function setCaseStatus(string $status)
{
// Fix the canceled status, this is a legacy code error
if ($caseStatus === self::INCORRECT_CANCELED_STATUS) {
$caseStatus = self::CORRECT_CANCELED_STATUS;
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
$this->caseStatus = $caseStatus;
$statusCode = 0;
// Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
}
}
$this->caseStatus = $statusCode;
}
/**
* Get Case Status
*
* @return string
* @return int
*/
public function getCaseStatus()
{
return $this->caseStatus;
}
/**
* Set Case statuses
*
* @param array $statuses
*
* @throws Exception
*/
public function setCaseStatuses(array $statuses)
{
$statusCodes = [];
foreach ($statuses as $status) {
// Fix the canceled status, this is a legacy code error
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
// Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
} else {
array_push($statusCodes, $statusCode);
}
}
}
$this->caseStatuses = $statusCodes;
}
/**
* Get Case Statuses
*
* @return array
*/
public function getCaseStatuses()
{
return $this->caseStatuses;
}
/**
* Set Case Uid
*
@@ -458,15 +552,13 @@ class AbstractCases implements CasesInterface
}
/**
* Set range of Case Number
* Set range of case number from
*
* @param int $from
* @param int $to
*/
public function setRangeCaseNumber(int $from, int $to)
public function setCaseNumberFrom(int $from)
{
$this->fromCaseNumber = $from;
$this->toCaseNumber = $to;
$this->caseNumberFrom = $from;
}
/**
@@ -474,9 +566,19 @@ class AbstractCases implements CasesInterface
*
* @return int
*/
public function getFromCaseNumber()
public function getCaseNumberFrom()
{
return $this->fromCaseNumber;
return $this->caseNumberFrom;
}
/**
* Set range of case number to
*
* @param int $to
*/
public function setCaseNumberTo(int $to)
{
$this->caseNumberTo = $to;
}
/**
@@ -484,9 +586,82 @@ class AbstractCases implements CasesInterface
*
* @return int
*/
public function getToCaseNumber()
public function getCaseNumberTo()
{
return $this->toCaseNumber;
return $this->caseNumberTo;
}
/**
* Set more than one range of cases
*
* @param array $rangeCases
*/
public function setRangeCasesFromTo(array $rangeCases)
{
$this->rangeCasesFromTo = $rangeCases;
}
/**
* Get more than one range of cases
*
* @return array
*/
public function getRangeCasesFromTo()
{
return $this->rangeCasesFromTo;
}
/**
* Set filter of cases like '1,3-5,8,10-15'
*
* @param string $filterCases
*/
public function setFilterCases(string $filterCases)
{
$this->filterCases = $filterCases;
// Review the cases defined in the filter
$rangeOfCases = explode(",", $filterCases);
$specificCases = [];
$rangeCases = [];
foreach ($rangeOfCases as $cases) {
if(is_numeric($cases)) {
array_push($specificCases,$cases);
} else {
array_push($rangeCases,$cases);
}
}
$this->setCasesNumbers($specificCases);
$this->setRangeCasesFromTo($rangeCases);
}
/**
* Get filter of cases
*
* @return string
*/
public function getFilterCases()
{
return $this->filterCases;
}
/**
* Set Case Title
*
* @param string $caseTitle
*/
public function setCaseTitle(string $caseTitle)
{
$this->caseTitle = $caseTitle;
}
/**
* Get Case Title
*
* @return string
*/
public function getCaseTitle()
{
return $this->caseTitle;
}
/**
@@ -530,18 +705,118 @@ class AbstractCases implements CasesInterface
}
/**
* Set Newest Than value
* Set start case from
*
* @param string $newestThan
* @param string $from
*
* @throws Exception
*/
public function setNewestThan(string $newestThan)
public function setStartCaseFrom(string $from)
{
if (!Validator::isDate($newestThan, 'Y-m-d')) {
throw new Exception("Value '{$newestThan}' is not a valid date.");
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->newestThan = $newestThan;
$this->startCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getStartCaseFrom()
{
return $this->startCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setStartCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->startCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getStartCaseTo()
{
return $this->startCaseTo;
}
/**
* Set finish case from
*
* @param string $from
*
* @throws Exception
*/
public function setFinishCaseFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getFinishCaseFrom()
{
return $this->finishCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setFinishCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getFinishCaseTo()
{
return $this->finishCaseTo;
}
/**
* Set Newest Than value
*
* @param string $delegateFrom
*
* @throws Exception
*/
public function setDelegateFrom(string $delegateFrom)
{
if (!Validator::isDate($delegateFrom, 'Y-m-d')) {
throw new Exception("Value '{$delegateFrom}' is not a valid date.");
}
$this->delegateFrom = $delegateFrom;
}
/**
@@ -549,24 +824,24 @@ class AbstractCases implements CasesInterface
*
* @return string
*/
public function getNewestThan()
public function getDelegateFrom()
{
return $this->newestThan;
return $this->delegateFrom;
}
/**
* Set Oldest Than value
*
* @param string $oldestThan
* @param string $delegateTo
*
* @throws Exception
*/
public function setOldestThan(string $oldestThan)
public function setDelegateTo(string $delegateTo)
{
if (!Validator::isDate($oldestThan, 'Y-m-d')) {
throw new Exception("Value '{$oldestThan}' is not a valid date.");
if (!Validator::isDate($delegateTo, 'Y-m-d')) {
throw new Exception("Value '{$delegateTo}' is not a valid date.");
}
$this->oldestThan = $oldestThan;
$this->delegateTo = $delegateTo;
}
/**
@@ -574,11 +849,112 @@ class AbstractCases implements CasesInterface
*
* @return string
*/
public function getOldestThan()
public function getDelegateTo()
{
return $this->oldestThan;
return $this->delegateTo;
}
/**
* Set finish date value
*
* @param string $from
*
* @throws Exception
*/
public function setFinishFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishFrom = $from;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishFrom()
{
return $this->finishFrom;
}
/**
* Set finish date value
*
* @param string $to
*
* @throws Exception
*/
public function setFinishTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishTo = $to;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishTo()
{
return $this->finishTo;
}
/**
* Set due date from
*
* @param string $dueFrom
*
* @throws Exception
*/
public function setDueFrom(string $dueFrom)
{
if (!Validator::isDate($dueFrom, 'Y-m-d')) {
throw new Exception("Value '{$dueFrom}' is not a valid date.");
}
$this->dueFrom = $dueFrom;
}
/**
* Get due date from
*
* @return string
*/
public function getDueFrom()
{
return $this->dueFrom;
}
/**
* Set due date to
*
* @param string $dueTo
*
* @throws Exception
*/
public function setDueTo(string $dueTo)
{
if (!Validator::isDate($dueTo, 'Y-m-d')) {
throw new Exception("Value '{$dueTo}' is not a valid date.");
}
$this->dueTo = $dueTo;
}
/**
* Get due date to
*
* @return string
*/
public function getDueTo()
{
return $this->dueTo;
}
/**
* Set order by column
*
@@ -721,6 +1097,40 @@ class AbstractCases implements CasesInterface
return $taskColor;
}
/**
* Get task color according the due date
*
* @param string $pending
*
* @return int
*/
public function prepareTaskPending($pending)
{
$taskPending = json_decode($pending, true);
$result = [];
$i = 0;
foreach ($taskPending as $thread) {
foreach ($thread as $key => $row) {
if($key === 'tas_id') {
$result[$i][$key] = $row;
$result[$i]['tas_title'] = (!empty($row)) ? Task::where('TAS_ID', $row)->first()->TAS_TITLE : '';
}
if($key === 'user_id') {
$result[$i][$key] = $row;
}
if($key === 'due_date') {
$result[$i][$key] = $row;
// Get task color label
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($row) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
}
}
$i ++;
}
return $result;
}
/**
* Set all properties
*
@@ -744,33 +1154,67 @@ class AbstractCases implements CasesInterface
if (!empty($properties['user'])) {
$this->setUserId($properties['user']);
}
// Filter by priority
if (!empty($properties['priority'])) {
$this->setPriority($properties['priority']);
}
// Filter by case number
// Filter by one 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']);
// Filter by case title
if (!empty($properties['caseTitle'])) {
$this->setCaseTitle($properties['caseTitle']);
}
/** Apply filters related to MY CASES */
// My cases filter: started, in-progress, completed, supervising
if (!empty($properties['filter']) && get_class($this) === MyCases::class) {
if (!empty($properties['filter']) && get_class($this) === Participated::class) {
$this->setParticipatedStatus($properties['filter']);
}
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === MyCases::class) {
$this->setCaseStatus($properties['filterStatus']);
// Filter by one case status
if (!empty($properties['caseStatus']) && get_class($this) === Participated::class) {
$this->setCaseStatus($properties['caseStatus']);
}
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === Search::class) {
$this->setCaseStatus($properties['filterStatus']);
// Filter date related to started date from
if (!empty($properties['startCaseFrom'] && (get_class($this) === Participated::class || get_class($this) === Supervising::class))) {
$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)) {
$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)) {
$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)) {
$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) {
$this->setFilterCases($properties['filterCases']);
}
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
if (!empty($properties['caseStatuses']) && get_class($this) === Search::class) {
$this->setCaseStatuses($properties['caseStatuses']);
}
// Filter by more than one priorities like ['VL', 'L', 'N']
if (!empty($properties['priorities']) && get_class($this) === Search::class) {
$this->setProperties($properties['priorities']);
}
// Filter date newest related to delegation/started date
if (!empty($properties['delegationDateFrom'] && get_class($this) === Search::class)) {
$this->setDelegateFrom($properties['delegationDateFrom']);
}
// Filter date oldest related to delegation/started date
if (!empty($properties['delegationDateTo']) && get_class($this) === Search::class) {
$this->setDelegateTo($properties['delegationDateTo']);
}
// Filter date newest related to due date
if (!empty($properties['dueDateFrom']) && get_class($this) === Search::class) {
$this->setDueFrom($properties['dueDateFrom']);
}
// Filter date oldest related to due date
if (!empty($properties['dueDateTo']) && get_class($this) === Search::class) {
$this->setDueTo($properties['dueDateTo']);
}
// Filter by case uid
if (!empty($properties['caseLink'])) {
@@ -780,14 +1224,6 @@ class AbstractCases implements CasesInterface
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']);

View File

@@ -18,7 +18,8 @@ class Draft extends AbstractCases
'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
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -30,6 +31,39 @@ class Draft extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Get data self-services cases by user
*
@@ -44,18 +78,9 @@ class Draft extends AbstractCases
$query->joinTask();
// Join with application for add the initial scope for DRAFT cases
$query->draft($this->getUserId());
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
@@ -92,6 +117,7 @@ class Draft extends AbstractCases
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
$this->filters($query);
return $query->count();
}

View File

@@ -21,7 +21,8 @@ class Inbox extends AbstractCases
'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
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +34,39 @@ class Inbox extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Get the data corresponding to List Inbox
*
@@ -48,30 +82,16 @@ class Inbox extends AbstractCases
$query->joinUser();
// Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId());
// Define a specific risk
switch ($this->getRiskStatus()) {
case 'ON_TIME':
// Scope that search for the ON_TIME cases
$query->onTime();
break;
case 'AT_RISK':
// Scope that search for the AT_RISK cases
$query->atRisk();
break;
case 'OVERDUE':
// Scope that search for the OVERDUE cases
$query->overdue();
break;
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
}
// 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 by clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
// Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {

View File

@@ -1,62 +0,0 @@
<?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

@@ -2,8 +2,8 @@
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
class Participated extends AbstractCases
{
@@ -15,11 +15,13 @@ class Participated extends AbstractCases
'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
'APPLICATION.APP_CREATE_DATE', // Start Date
'APPLICATION.APP_FINISH_DATE', // Finish Date
'USERS.USR_ID', // Current UserId
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -31,6 +33,59 @@ class Participated extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Scope to search for an specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific status
if ($this->getCaseStatus()) {
$query->status($this->getCaseStatus());
}
// Specific start case date from
if (!empty($this->getStartCaseFrom())) {
$query->startDateFrom($this->getStartCaseFrom());
}
// Specific by start case date to
if (!empty($this->getStartCaseTo())) {
$query->startDateTo($this->getStartCaseTo());
}
// Specific finish case date from
if (!empty($this->getFinishCaseFrom())) {
$query->finishCaseFrom($this->getFinishCaseFrom());
}
// Filter by finish case date to
if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Get the data corresponding to Participated
*
@@ -39,13 +94,15 @@ class Participated extends AbstractCases
public function getData()
{
// Start the query for get the cases related to the user
$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();
// Join with application
$query->joinApplication();
// Scope to Participated
$query->participated($this->getUserId());
// Add filter
@@ -53,29 +110,42 @@ class Participated extends AbstractCases
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED
// Scope that search for the STARTED by user
$query->caseStarted();
break;
case 'IN-PROGRESS':
case 'IN_PROGRESS':
// Scope that search for the TO_DO
$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'
);
$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;
}
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// 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);
}
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
@@ -83,17 +153,57 @@ class Participated extends AbstractCases
//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']];
$results->transform(function ($item, $key) use ($filter) {
// 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;
$item['APP_CREATE_DATE_LABEL'] = !empty($item['APP_CREATE_DATE']) ? applyMaskDateEnvironment($item['APP_CREATE_DATE']): null;
$item['APP_FINISH_DATE_LABEL'] = !empty($item['APP_FINISH_DATE']) ? applyMaskDateEnvironment($item['APP_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");
$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']);
}
switch ($filter) {
case 'STARTED':
$result = [];
$i = 0;
if ($item['APP_STATUS'] === 'TO_DO') {
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
foreach ($taskPending as $thread) {
// todo this need to review
$result[$i]['tas_title'] = $thread['TAS_TITLE'];
$result[$i]['user_id'] = $thread['USR_ID'];
$result[$i]['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$i++;
}
$item['PENDING'] = $result;
} else {
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
}
break;
case 'IN_PROGRESS':
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
break;
case 'COMPLETED':
$result = [];
$i = 0;
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
break;
}
return $item;
});

View File

@@ -21,7 +21,8 @@ class Paused extends AbstractCases
'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
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +34,39 @@ class Paused extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Gets the data for the paused cases list
*
@@ -44,11 +78,10 @@ class Paused extends AbstractCases
// 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();
$query->paused($this->getUserId(), $this->getTaskId());
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// Add pagination to the query

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
class Search extends AbstractCases
@@ -14,6 +15,7 @@ class Search extends AbstractCases
'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
'APPLICATION.APP_STATUS', // Status
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
@@ -21,7 +23,8 @@ class Search extends AbstractCases
'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
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +36,101 @@ class Search extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Filter case by case number
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Filter cases by specific cases like [1,3,5]
if (!empty($this->getCasesNumbers())) {
$query->specificCases($this->getCasesNumbers());
}
// Filter cases by range of cases like ['1-5', '10-15']
if (!empty($this->getRangeCasesFromTo())) {
$query->rangeOfCases($this->getRangeCasesFromTo());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Filter by process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Filter by user
if ($this->getUserId()) {
$query->userId($this->getUserId());
}
// Filter by task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Filter one or more priorities like ['VL', 'L', 'N']
if (!empty($this->getPriorities())) {
$query->priorities($this->getPriorities());
}
// Filter by delegate from
if (!empty($this->getDelegateFrom())) {
$query->delegateDateFrom($this->getDelegateFrom());
}
// Filter by delegate to
if (!empty($this->getDelegateTo())) {
$query->delegateDateTo($this->getDelegateTo());
}
// Filter by due from
if (!empty($this->getDueFrom())) {
$query->dueFrom($this->getDueFrom());
}
// Filter by due to
if (!empty($this->getDueTo())) {
$query->dueTo($this->getDueTo());
}
/** This filter define the UNION */
// Filter related to the case status like ['DRAFT', 'TO_DO']
if (!empty($this->getCaseStatuses())) {
$statuses = $this->getCaseStatuses();
$casesOpen = [];
$casesClosed = [];
foreach ($statuses as $row) {
if ($row === Application::STATUS_DRAFT or $row === Application::STATUS_TODO) {
$casesOpen[] = $row;
} else {
$casesClosed[] = $row;
}
}
if (!empty($casesOpen) && !empty($casesClosed)) {
// Only in this case need to clone the same query for the union
$cloneQuery = clone $query;
// Get the open threads
$query->casesInProgress($casesOpen);
// Get the last thread
$cloneQuery->casesDone($casesClosed);
// Union
$query->union($cloneQuery);
} else {
if (!empty($casesOpen)) {
// Get the open thread
$query->casesInProgress($casesOpen);
}
if (!empty($casesClosed)) {
// Get the last thread
$query->casesDone($casesClosed);
}
}
}
return $query;
}
/**
* Get the data corresponding to advanced search
*
@@ -47,33 +145,11 @@ class Search extends AbstractCases
$query->joinTask();
// Join with users
$query->joinUser();
// Filter by case number
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());
}
// @todo: Filter by case title, pending from other PRD
// 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());
}
// Join with application
$query->joinApplication();
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause

View File

@@ -15,11 +15,12 @@ class Supervising extends AbstractCases
'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
'APPLICATION.APP_CREATE_DATE', // Start Date
'APPLICATION.APP_FINISH_DATE', // Finish Date
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -31,6 +32,59 @@ class Supervising extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Scope to search for an specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific status
if ($this->getCaseStatus()) {
$query->status($this->getCaseStatus());
}
// Specific start case date from
if (!empty($this->getStartCaseFrom())) {
$query->startDateFrom($this->getStartCaseFrom());
}
// Specific by start case date to
if (!empty($this->getStartCaseTo())) {
$query->startDateTo($this->getStartCaseTo());
}
// Specific finish case date from
if (!empty($this->getFinishCaseFrom())) {
$query->finishCaseFrom($this->getFinishCaseFrom());
}
// Filter by finish case date to
if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Gets the data for the Cases list Review
*
@@ -40,51 +94,53 @@ class Supervising extends AbstractCases
{
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// 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());
// 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);
// We will prepare the queries if the user is supervisor
if (!empty($processes)) {
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Join with application
$query->joinApplication();
// Only cases in progress
$query->caseInProgress();
// Scope that return the results for an specific user
$query->userId($this->getUserId());
// Scope the specific array of processes supervising
$query->processInList($processes);
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
//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['APP_CREATE_DATE_LABEL'] = !empty($item['APP_CREATE_DATE']) ? applyMaskDateEnvironment($item['APP_CREATE_DATE']): null;
$item['APP_FINISH_DATE_LABEL'] = !empty($item['APP_FINISH_DATE']) ? applyMaskDateEnvironment($item['APP_FINISH_DATE']): null;
// Calculate duration
$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);
return $item;
});
return $item;
});
return $results->values()->toArray();
return $results->values()->toArray();
} else {
return [];
}
}
/**

View File

@@ -22,7 +22,8 @@ class Unassigned extends AbstractCases
'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
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -34,6 +35,39 @@ class Unassigned extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if ($this->getCaseTitle()) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/**
* Get data self-services cases by user
*
@@ -47,28 +81,15 @@ class Unassigned extends AbstractCases
// Join with users
$query->joinUser();
// Join with application for add the initial scope for unassigned cases
$query->selfService($this->getUserUid());
if (!empty($this->getUserUid())) {
$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);
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Date range filter, this is used from mobile GET /light/unassigned
if ($this->getNewestThan()) {
$query->delegateDateFrom($this->getNewestThan());
}
if ($this->getOldestThan()) {
$query->delegateDateTo($this->getOldestThan());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
$query->joinApplication();
$query->status(Application::STATUS_TODO);
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());