From f537dc051377ba1ac10f37d868a571d6b8fe2309 Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Fri, 5 Mar 2021 12:13:43 +0530 Subject: [PATCH] show inactive role on closed case, and give option to active role on case Fix php notice for case not having manager Fix pagination count issue Revert pagination code revert additional pagination changes --- CRM/Activity/Page/AJAX.php | 47 +++++++++++++++++++++------- CRM/Case/BAO/Case.php | 43 ++++++++++++++++++++----- CRM/Case/Form/CaseView.php | 10 ++++-- templates/CRM/Case/Form/CaseView.tpl | 42 +++++++++++++++++++++++-- 4 files changed, 117 insertions(+), 25 deletions(-) diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index f61df22bb4..1998fbc5d1 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -88,7 +88,7 @@ class CRM_Activity_Page_AJAX { 0, 0, 0, NULL, NULL, FALSE ); - $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); + $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID, NULL, FALSE); // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles // so they don't show up twice. @@ -136,7 +136,7 @@ class CRM_Activity_Page_AJAX { $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); - $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); + $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID, NULL, FALSE); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); @@ -162,9 +162,11 @@ class CRM_Activity_Page_AJAX { $rel = []; $rel['relation'] = $value; $rel['relation_type'] = $id; - $rel['name'] = '(not assigned)'; + $rel['sort_name'] = '(not assigned)'; $rel['phone'] = ''; $rel['email'] = ''; + $rel['is_active'] = ''; + $rel['end_date'] = ''; $rel['source'] = 'caseRoles'; $caseRelationships[] = $rel; } @@ -172,7 +174,7 @@ class CRM_Activity_Page_AJAX { foreach ($value as $clientRole) { $relClient = []; $relClient['relation'] = ts('Client'); - $relClient['name'] = $clientRole['sort_name']; + $relClient['sort_name'] = $clientRole['sort_name']; $relClient['phone'] = $clientRole['phone']; $relClient['email'] = $clientRole['email']; $relClient['cid'] = $clientRole['contact_id']; @@ -196,6 +198,12 @@ class CRM_Activity_Page_AJAX { // set user name, email and edit columns links foreach ($caseRelationships as $key => &$row) { + // add disabled class if role is inactive + if (isset($row['is_active'])) { + if ($row['is_active'] == '0') { + $row['DT_RowClass'] = 'disabled'; + } + } $typeLabel = $row['relation']; // Add "
(Case Manager)" to label if (!empty($row['relation_type']) && !empty($row['relationship_direction']) && $row['relation_type'] . '_' . $row['relationship_direction'] == $managerRoleId) { @@ -203,13 +211,26 @@ class CRM_Activity_Page_AJAX { } // view user links if (!empty($row['cid'])) { - $row['name'] = '' . $row['name'] . ''; + $row['sort_name'] = '' . $row['sort_name'] . ''; } // email column links/icon if ($row['email']) { $row['email'] = ''; } + + // view end date if set + if (!empty($row['end_date'])) { + $row['end_date'] = CRM_Utils_Date::customFormat($row['end_date']); + // add disabled class if end date is less than equal to current date. + if (CRM_Utils_Date::overdue($row['end_date'])) { + $row['DT_RowClass'] = 'disabled'; + } + } + else { + $row['end_date'] = ''; + } + // edit links $row['actions'] = ''; if ($hasAccessToAllCases) { @@ -217,12 +238,14 @@ class CRM_Activity_Page_AJAX { $contactType = $contactType == 'Contact' ? '' : $contactType; switch ($row['source']) { case 'caseRel': - $row['actions'] = '' . - '' . - '' . - '' . - '' . - ''; + if (empty($row['end_date'])) { + $row['actions'] = '' . + '' . + '' . + '' . + '' . + ''; + } break; case 'caseRoles': diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index f4671b98b9..168fb924be 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -776,6 +776,8 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas civicrm_email.email as email, civicrm_phone.phone as phone, con.id as civicrm_contact_id, + rel.is_active as is_active, + rel.end_date as end_date, IF(rel.contact_id_a = %1, civicrm_relationship_type.label_a_b, civicrm_relationship_type.label_b_a) as relation, civicrm_relationship_type.id as relation_type, IF(rel.contact_id_a = %1, "a_b", "b_a") as relationship_direction @@ -800,6 +802,7 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas $query .= ' AND rel.id = %3 '; $params[3] = [$relationshipID, 'Integer']; } + $dao = CRM_Core_DAO::executeQuery($query, $params); $values = []; @@ -807,9 +810,11 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas $rid = $dao->civicrm_relationship_id; $values[$rid]['cid'] = $dao->civicrm_contact_id; $values[$rid]['relation'] = $dao->relation; - $values[$rid]['name'] = $dao->sort_name; + $values[$rid]['sort_name'] = $dao->sort_name; $values[$rid]['email'] = $dao->email; $values[$rid]['phone'] = $dao->phone; + $values[$rid]['is_active'] = $dao->is_active; + $values[$rid]['end_date'] = $dao->end_date; $values[$rid]['relation_type'] = $dao->relation_type; $values[$rid]['rel_id'] = $dao->civicrm_relationship_id; $values[$rid]['client_id'] = $contactID; @@ -1723,20 +1728,24 @@ HERESQL; if (substr($managerRoleId, -4) == '_a_b') { $managerRoleQuery = " SELECT civicrm_contact.id as casemanager_id, - civicrm_contact.sort_name as casemanager + civicrm_contact.sort_name as casemanager, + civicrm_relationship.is_active, + civicrm_relationship.end_date FROM civicrm_contact LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_b = civicrm_contact.id AND civicrm_relationship.relationship_type_id = %1) AND civicrm_relationship.is_active LEFT JOIN civicrm_case ON civicrm_case.id = civicrm_relationship.case_id - WHERE civicrm_case.id = %2 AND is_active = 1"; + WHERE civicrm_case.id = %2"; } if (substr($managerRoleId, -4) == '_b_a') { $managerRoleQuery = " SELECT civicrm_contact.id as casemanager_id, - civicrm_contact.sort_name as casemanager + civicrm_contact.sort_name as casemanager, + civicrm_relationship.is_active, + civicrm_relationship.end_date FROM civicrm_contact LEFT JOIN civicrm_relationship ON (civicrm_relationship.contact_id_a = civicrm_contact.id AND civicrm_relationship.relationship_type_id = %1) AND civicrm_relationship.is_active LEFT JOIN civicrm_case ON civicrm_case.id = civicrm_relationship.case_id - WHERE civicrm_case.id = %2 AND is_active = 1"; + WHERE civicrm_case.id = %2"; } $managerRoleParams = [ @@ -1745,10 +1754,28 @@ HERESQL; ]; $dao = CRM_Core_DAO::executeQuery($managerRoleQuery, $managerRoleParams); - if ($dao->fetch()) { + // Pull an array of ALL case managers related to the case. + $caseManagerNameArray = []; + while ($dao->fetch()) { + $caseManagerNameArray[$dao->casemanager_id]['casemanager_id'] = $dao->casemanager_id; + $caseManagerNameArray[$dao->casemanager_id]['is_active'] = $dao->is_active; + $caseManagerNameArray[$dao->casemanager_id]['end_date'] = $dao->end_date; + $caseManagerNameArray[$dao->casemanager_id]['casemanager'] = $dao->casemanager; + } + + // Look for an active case manager, when no active case manager (like a closed case) show the most recently expired case manager. + // Get the index of the manager if set to active + $activekey = array_search(1, array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'is_active'))); + if (!empty($activekey)) { + $caseManagerName = sprintf('%s', + CRM_Utils_System::url('civicrm/contact/view', ['cid' => $activekey]), $caseManagerNameArray[$activekey]['casemanager'] + ); + } + elseif (!empty($caseManagerNameArray)) { + // if there is no active case manager, get the index of the most recent end_date + $max = array_search(max(array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'end_date'))), array_combine(array_keys($caseManagerNameArray), array_column($caseManagerNameArray, 'end_date'))); $caseManagerName = sprintf('%s', - CRM_Utils_System::url('civicrm/contact/view', ['cid' => $dao->casemanager_id]), - $dao->casemanager + CRM_Utils_System::url('civicrm/contact/view', ['cid' => $max]), $caseManagerNameArray[$max]['casemanager'] ); } } diff --git a/CRM/Case/Form/CaseView.php b/CRM/Case/Form/CaseView.php index 9e71a0cd1a..45a659fcd0 100644 --- a/CRM/Case/Form/CaseView.php +++ b/CRM/Case/Form/CaseView.php @@ -78,12 +78,18 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); + $statusClass = civicrm_api3('OptionValue', 'getsingle', [ + 'option_group_id' => "case_status", + 'value' => $values['case_status_id'], + 'return' => 'grouping', + ]); $this->_caseDetails = [ 'case_type' => $caseType, 'case_status' => $statuses[$values['case_status_id']] ?? NULL, 'case_subject' => $values['subject'] ?? NULL, 'case_start_date' => $values['case_start_date'], + 'status_class' => $statusClass['grouping'], ]; $this->_caseType = $caseTypeName; $this->assign('caseDetails', $this->_caseDetails); @@ -286,7 +292,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { self::activityForm($this, $aTypes); //get case related relationships (Case Role) - $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); + $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID, NULL, FALSE); //save special label because we unset it in the loop $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; @@ -467,7 +473,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form { //build reporter select $reporters = ["" => ts(' - any reporter - ')]; foreach ($caseRelationships as $key => & $value) { - $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; + $reporters[$value['cid']] = $value['sort_name'] . " ( {$value['relation']} )"; } $form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, ['id' => 'reporter_id_' . $form->_caseID]); diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 1301ac5b36..ca42afc3f8 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -150,14 +150,40 @@
- +
+ {* add checkbox to show only active role on case, default value is unchecked (it show all roles) *} + {if $caseDetails.status_class eq 'Opened'}{assign var=statusclass value='0'}{else}{assign var=statusclass value='1'}{/if} + +
+ {literal} + + {/literal} - + + {if $relId neq 'client' and $hasAccessToAllCases} {/if} @@ -170,7 +196,17 @@ var caseId = {/literal}{$caseID}{literal}; CRM.$('table#caseRoles-selector-' + caseId).data({ "ajax": { - "url": {/literal}'{crmURL p="civicrm/ajax/caseroles" h=0 q="snippet=4&caseID=$caseId&cid=$contactID&userID=$userID"}'{literal} + "url": {/literal}'{crmURL p="civicrm/ajax/caseroles" h=0 q="snippet=4&caseID=$caseId&cid=$contactID&userID=$userID"}'{literal}, + "complete" : function(){ + if (CRM.$('input[type=checkbox][id=role_inactive]').prop('checked')) { + CRM.$('[id^=caseRoles-selector] tbody tr').not('.disabled').hide(); + CRM.$('[id^=caseRoles-selector] tbody tr.disabled').show(); + } + else { + CRM.$('[id^=caseRoles-selector] tbody tr').not('.disabled').show(); + CRM.$('[id^=caseRoles-selector] tbody tr.disabled').hide(); + } + } } }); })(CRM.$); -- 2.25.1
{ts}Case Role{/ts}{ts}Name{/ts}{ts}Name{/ts} {ts}Phone{/ts} {ts}Email{/ts}{ts}End Date{/ts}{ts}Actions{/ts}