campaign statystic percentage

This commit is contained in:
yuri
2015-10-06 13:19:30 +03:00
parent 5935bb012d
commit 83d9d1d924
3 changed files with 90 additions and 0 deletions
@@ -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,
@@ -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();
@@ -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;
},
});
});