From 83d9d1d924b60d2de3cfd1e2d56cdd573477ecb1 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 6 Oct 2015 13:19:30 +0300 Subject: [PATCH] campaign statystic percentage --- .../metadata/entityDefs/Campaign.json | 28 ++++++++++++++ .../Espo/Modules/Crm/Services/Campaign.php | 24 ++++++++++++ .../campaign/fields/int-with-percentage.js | 38 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 frontend/client/modules/crm/src/views/campaign/fields/int-with-percentage.js diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json index a7d2cf5ae5..78c85b6bb9 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json @@ -58,24 +58,28 @@ "disabled": true }, "openedCount": { + "view": "crm:views/campaign/fields/int-with-percentage", "type": "int", "notStorable": true, "readOnly": true, "disabled": true }, "clickedCount": { + "view": "crm:views/campaign/fields/int-with-percentage", "type": "int", "notStorable": true, "readOnly": true, "disabled": true }, "optedOutCount": { + "view": "crm:views/campaign/fields/int-with-percentage", "type": "int", "notStorable": true, "readOnly": true, "disabled": true }, "bouncedCount": { + "view": "crm:views/campaign/fields/int-with-percentage", "type": "int", "notStorable": true, "readOnly": true, @@ -99,6 +103,30 @@ "readOnly": true, "disabled": true }, + "openedPercentage": { + "type": "int", + "notStorable": true, + "readOnly": true, + "disabled": true + }, + "clickedPercentage": { + "type": "int", + "notStorable": true, + "readOnly": true, + "disabled": true + }, + "optedOutPercentage": { + "type": "int", + "notStorable": true, + "readOnly": true, + "disabled": true + }, + "bouncedPercentage": { + "type": "int", + "notStorable": true, + "readOnly": true, + "disabled": true + }, "revenue": { "type": "currency", "notStorable": true, diff --git a/application/Espo/Modules/Crm/Services/Campaign.php b/application/Espo/Modules/Crm/Services/Campaign.php index b2c1dc3bd4..8a2025f3bf 100644 --- a/application/Espo/Modules/Crm/Services/Campaign.php +++ b/application/Espo/Modules/Crm/Services/Campaign.php @@ -43,24 +43,48 @@ class Campaign extends \Espo\Services\Record ))->count(); $entity->set('openedCount', $openedCount); + $openedPercentage = null; + if ($sentCount > 0) { + $openedPercentage = round($openedCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); + } + $entity->set('openedPercentage', $openedPercentage); + $clickedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( 'campaignId' => $entity->id, 'action' => 'Clicked' ))->count(); $entity->set('clickedCount', $clickedCount); + $clickedPercentage = null; + if ($sentCount > 0) { + $clickedPercentage = round($clickedCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); + } + $entity->set('clickedPercentage', $clickedPercentage); + $optedOutCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( 'campaignId' => $entity->id, 'action' => 'Opted Out' ))->count(); $entity->set('optedOutCount', $optedOutCount); + $optedOutPercentage = null; + if ($sentCount > 0) { + $optedOutPercentage = round($optedOutCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); + } + $entity->set('optedOutPercentage', $optedOutPercentage); + $bouncedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( 'campaignId' => $entity->id, 'action' => 'Bounced' ))->count(); $entity->set('bouncedCount', $bouncedCount); + $bouncedPercentage = null; + if ($sentCount > 0) { + $bouncedPercentage = round($bouncedCount / $sentCount * 100, 2, \PHP_ROUND_HALF_EVEN); + } + $entity->set('bouncedPercentage', $bouncedPercentage); + $leadCreatedCount = $this->getEntityManager()->getRepository('Lead')->where(array( 'campaignId' => $entity->id ))->count(); diff --git a/frontend/client/modules/crm/src/views/campaign/fields/int-with-percentage.js b/frontend/client/modules/crm/src/views/campaign/fields/int-with-percentage.js new file mode 100644 index 0000000000..3368ca55ed --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign/fields/int-with-percentage.js @@ -0,0 +1,38 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko + * Website: http://www.espocrm.com + * + * EspoCRM is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EspoCRM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EspoCRM. If not, see http://www.gnu.org/licenses/. + ************************************************************************/ + +Espo.define('crm:views/campaign/fields/int-with-percentage', 'views/fields/int', function (Dep) { + + return Dep.extend({ + + getValueForDisplay: function () { + var percentageFieldName = this.name.substr(0, this.name.length - 5) + 'Percentage'; + var value = this.model.get(this.name) ; + + var percentageValue = this.model.get(percentageFieldName); + if (percentageValue !== null && typeof percentageValue !== 'undefined' && percentageValue) { + value += ' ' + '(' + this.model.get(percentageFieldName) + '%)'; + } + return value; + }, + }); + +});