From e1f0715c4d32bef8d3c8cf3b47ce9f7ffcba2f96 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 7 Oct 2015 10:35:07 +0300 Subject: [PATCH] email import: relate to converted entity if lead is converted --- application/Espo/Core/Mail/Importer.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/application/Espo/Core/Mail/Importer.php b/application/Espo/Core/Mail/Importer.php index 9c20c7fce7..1fb6fecabb 100644 --- a/application/Espo/Core/Mail/Importer.php +++ b/application/Espo/Core/Mail/Importer.php @@ -194,6 +194,28 @@ class Importer $n = sscanf($reference, '%s %s %d %d espo', $parentType, $parentId, $emailSent, $number); if ($n == 4 && $emailSent < time()) { if (!empty($parentType) && !empty($parentId)) { + if ($parentType == 'Lead') { + $parent = $this->getEntityManager()->getEntity('Lead', $parentId); + if ($parent && $parent->get('status') == 'Converted') { + if ($parent->get('createdAccountId')) { + $account = $this->getEntityManager()->getEntity('Account', $parent->get('createdAccountId')); + if ($account) { + $parentType = 'Account'; + $parentId = $account->id; + } + } else { + if ($this->getConfig()->get('b2cMode')) { + if ($parent->get('createdContactId')) { + $contact = $this->getEntityManager()->getEntity('Contact', $parent->get('createdContactId')); + if ($contact) { + $parentType = 'Contact'; + $parentId = $contact->id; + } + } + } + } + } + } $email->set('parentType', $parentType); $email->set('parentId', $parentId); $parentFound = true;