From 92fb5cb9fe481d8deeb872f91f19b278db35aaad Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Wed, 13 Jan 2021 19:04:46 +0530 Subject: [PATCH] correction to display deceased age only when birth date present --- CRM/Contact/BAO/Contact.php | 6 +++++- templates/CRM/Contact/Page/Inline/Demographics.tpl | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 9df85abcbb..e90708118d 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2599,7 +2599,11 @@ LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id ) if ($contact->birth_date) { $birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d'); if ($birthDate < date('Ymd')) { - $age = CRM_Utils_Date::calculateAge($birthDate, $contact->deceased_date ?? NULL); + $deceasedDate = NULL; + if (!empty($contact->is_deceased) && !empty($contact->deceased_date)) { + $deceasedDate = $contact->deceased_date; + } + $age = CRM_Utils_Date::calculateAge($birthDate, $deceasedDate); $values['age']['y'] = $age['years'] ?? NULL; $values['age']['m'] = $age['months'] ?? NULL; } diff --git a/templates/CRM/Contact/Page/Inline/Demographics.tpl b/templates/CRM/Contact/Page/Inline/Demographics.tpl index 4f7d4f1f45..f2995abbc6 100644 --- a/templates/CRM/Contact/Page/Inline/Demographics.tpl +++ b/templates/CRM/Contact/Page/Inline/Demographics.tpl @@ -34,7 +34,7 @@
{assign var="date_format" value = $fields.birth_date.smarty_view_format} {$deceased_date|crmDate:$date_format} - ({ts}Age{/ts} {if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if}) + {if $birth_date}({ts}Age{/ts} {if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if}){/if}
{else} -- 2.25.1