From 6e1eaf31b83d5110396ec4ca6b4fe56c8190f4bd Mon Sep 17 00:00:00 2001 From: Fernando Ontiveros Date: Wed, 7 May 2025 19:27:28 -0400 Subject: [PATCH] fix issue when app_delegation does not have due date --- .../BusinessModel/Cases/AbstractCases.php | 23 +++++++------ .../engine/src/ProcessMaker/Util/helpers.php | 32 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index 91c28dbcc..ed874d8b3 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -112,7 +112,7 @@ class AbstractCases implements CasesInterface // Filter by specific cases, know as "$appUidCheck" in the old lists classes private $casesUids = []; - + // Filter by Send By private $sendBy = ''; @@ -333,7 +333,7 @@ class AbstractCases implements CasesInterface /** * Set send by - * + * * @param type $sendBy */ public function setSendBy(string $sendBy) @@ -343,7 +343,7 @@ class AbstractCases implements CasesInterface /** * Get send by. - * + * * @return string */ public function getSendBy() @@ -1170,8 +1170,11 @@ class AbstractCases implements CasesInterface * * @return int */ - public function getTaskColor(string $dueDate, string $statusThread = '', $dateToCompare = 'now') + public function getTaskColor(?string $dueDate, string $statusThread = '', $dateToCompare = 'now') { + if (empty($dueDate)) { + return self::COLOR_DRAFT; + } $currentDate = new DateTime($dateToCompare); $dueDate = new DateTime($dueDate); if ($currentDate > $dueDate) { @@ -1305,7 +1308,7 @@ class AbstractCases implements CasesInterface $threadTask['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare); $threadTask['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : ''; $threadTask['tas_color_label'] = (!empty($threadTask['tas_color'])) ? self::TASK_COLORS[$threadTask['tas_color']] : ''; - $threadTask['tas_status'] = self::TASK_STATUS[$threadTask['tas_color']]; + $threadTask['tas_status'] = (!empty($threadTask['tas_color'])) ? self::TASK_STATUS[$threadTask['tas_color']] : ''; $threadTask['unassigned'] = ($status === 'UNASSIGNED' ? true : false); $userInfo = User::getInformation($thread['USR_ID']); $threadTask['user_tooltip'] = $userInfo; @@ -1558,7 +1561,7 @@ class AbstractCases implements CasesInterface * @param int $category * @param bool $topTen * @param array $processes - * + * * @return array */ public function getCountersByProcesses($category = null, $topTen = false, $processes = []) @@ -1596,12 +1599,12 @@ class AbstractCases implements CasesInterface /** * Count how many cases has each process by range of dates - * + * * @param int $processId * @param string $dateFrom * @param string $dateTo * @param string $groupBy - * + * * @return array */ public function getCountersByRange($processId = null, $dateFrom = null, $dateTo = null, $groupBy = 'day') @@ -1648,13 +1651,13 @@ class AbstractCases implements CasesInterface /** * Get cases risk by process - * + * * @param int $processId * @param string $dateFrom * @param string $dateTo * @param string $riskStatus * @param int $topCases - * + * * @return array */ public function getCasesRisk($processId = '', $dateFrom = null, $dateTo = null, $riskStatus = 'ON_TIME', $topCases = null) diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index dfc1e9de2..a5140d5d4 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -590,7 +590,7 @@ function toSqlWithBindings(Illuminate\Database\Eloquent\Builder $queryObject) { /** * Get the version of the mysql - * + * * @return string */ function getMysqlVersion() @@ -642,18 +642,24 @@ function applyMaskDateEnvironment($date, $mask = '', $caseListSetting = true) * * @return string */ -function getDiffBetweenDates(string $startDate, string $endDate) +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); + try { + // Check if startDate and endDate are not empty + 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); + } + } catch (Exception $e) { + // Handle exception if the date format is invalid + $result = $e->getMessage(); } return $result; @@ -661,13 +667,13 @@ function getDiffBetweenDates(string $startDate, string $endDate) /** * Move the uploaded file to the documents folder - * + * * @param array $file * @param string $appUid * @param string $appDocUid * @param int $version * @param bool $upload - * + * * @return string */ function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = true)