diff --git a/application/Espo/Core/defaults/config.php b/application/Espo/Core/defaults/config.php index 6d29049788..cf302e1177 100644 --- a/application/Espo/Core/defaults/config.php +++ b/application/Espo/Core/defaults/config.php @@ -87,7 +87,7 @@ return array ( 'Lead', 'Opportunity', ), - "tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email", "Document"), + "tabList" => array("Account", "Contact", "Lead", "Opportunity", "Calendar", "Meeting", "Call", "Task", "Case", "Email", "Document", "Campaign"), "quickCreateList" => array("Account", "Contact", "Lead", "Opportunity", "Meeting", "Call", "Task", "Case"), 'calendarDefaultEntity' => 'Meeting', 'disableExport' => false, diff --git a/application/Espo/Modules/Crm/Controllers/Campaign.php b/application/Espo/Modules/Crm/Controllers/Campaign.php new file mode 100644 index 0000000000..0e363c4d95 --- /dev/null +++ b/application/Espo/Modules/Crm/Controllers/Campaign.php @@ -0,0 +1,28 @@ +getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Clicked' + ))->count(); + $entity->set('sentCount', $sentCount); + + $openedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Opened' + ))->count(); + $entity->set('openedCount', $openedCount); + + $clickedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Clicked' + ))->count(); + $entity->set('clickedCount', $clickedCount); + + $optedOutCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Opted Out' + ))->count(); + $entity->set('optedOutCount', $optedOutCount); + + $bouncedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Bounced' + ))->count(); + $entity->set('bouncedCount', $bouncedCount); + + $leadCreatedCount = $this->getEntityManager()->getRepository('CampaignLogRecord')->where(array( + 'campaignId' => $entity->id, + 'action' => 'Lead Created' + ))->count(); + $entity->set('leadCreatedCount', $leadCreatedCount); + + $entity->set('revenueCurrency', $this->getConfig()->get('defaultCurrency')); + + $params = array( + 'select' => array('SUM:amountConverted'), + 'whereClause' => array( + 'status' => 'Closed Won', + 'campaignId' => $entity->id + ), + 'groupBy' => array('opportunity.campaignId') + ); + + $this->getEntityManager()->getRepository('Opportunity')->handleSelectParams($params); + + + $sql = $this->getEntityManager()->getQuery()->createSelectQuery('Opportunity', $params); + + + $pdo = $this->getEntityManager()->getPDO(); + $sth = $pdo->prepare($sql); + $sth->execute(); + + if ($row = $sth->fetch(\PDO::FETCH_ASSOC)) { + $revenue = floatval($row['SUM:amountConverted']); + if ($revenue > 0) { + $entity->set('revenue', $revenue); + } + } + } + +} + diff --git a/application/Espo/Modules/Crm/Services/TargetList.php b/application/Espo/Modules/Crm/Services/TargetList.php new file mode 100644 index 0000000000..c0cfc86eed --- /dev/null +++ b/application/Espo/Modules/Crm/Services/TargetList.php @@ -0,0 +1,51 @@ +loadEntryCountField($entity); + } + + public function loadAdditionalFieldsForList(Entity $entity) + { + parent::loadAdditionalFields($entity); + $this->loadEntryCountField($entity); + } + + protected function loadEntryCountField(Entity $entity) + { + $count = 0; + $count += $this->getEntityManager()->getRepository('TargetList')->countRelated($entity, 'contacts'); + $count += $this->getEntityManager()->getRepository('TargetList')->countRelated($entity, 'leads'); + $count += $this->getEntityManager()->getRepository('TargetList')->countRelated($entity, 'users'); + $count += $this->getEntityManager()->getRepository('TargetList')->countRelated($entity, 'accounts'); + $entity->set('entryCount', $count); + } +} + diff --git a/frontend/client/modules/crm/res/templates/campaign-log-record/fields/data/detail.tpl b/frontend/client/modules/crm/res/templates/campaign-log-record/fields/data/detail.tpl new file mode 100644 index 0000000000..d7c3887ed3 --- /dev/null +++ b/frontend/client/modules/crm/res/templates/campaign-log-record/fields/data/detail.tpl @@ -0,0 +1 @@ +{{{value}}} \ No newline at end of file diff --git a/frontend/client/modules/crm/res/templates/campaign/record/panels/campaign-log-records.tpl b/frontend/client/modules/crm/res/templates/campaign/record/panels/campaign-log-records.tpl new file mode 100644 index 0000000000..88149a4c8a --- /dev/null +++ b/frontend/client/modules/crm/res/templates/campaign/record/panels/campaign-log-records.tpl @@ -0,0 +1,8 @@ +
+
+ +
+
+
{{{list}}}
diff --git a/frontend/client/modules/crm/res/templates/campaign/record/panels/statistics.tpl b/frontend/client/modules/crm/res/templates/campaign/record/panels/statistics.tpl new file mode 100644 index 0000000000..30d74d2584 --- /dev/null +++ b/frontend/client/modules/crm/res/templates/campaign/record/panels/statistics.tpl @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/frontend/client/modules/crm/src/views/campaign-log-record/fields/data.js b/frontend/client/modules/crm/src/views/campaign-log-record/fields/data.js new file mode 100644 index 0000000000..84dc82b665 --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign-log-record/fields/data.js @@ -0,0 +1,54 @@ +/************************************************************************ + * 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.CampaignLogRecord.Fields.Data', 'Views.Fields.Base', function (Dep) { + + return Dep.extend({ + + listTemplate: 'crm:campaign-log-record.fields.data.detail', + + getValueForDisplay: function () { + var action = this.model.get('action'); + + switch (action) { + case 'Sent': + return this.model.get('stringData'); + case 'Clicked': + return '' + this.model.get('stringData') + ''; + case 'Opted Out': + return '' + this.model.get('stringData') + ''; + case 'Bounced': + var emailAddress = this.model.get('stringData'); + var type = this.model.get('stringAdditionalData'); + if (type == 'Hard') { + return '' + emailAddress + ''; + } else { + return '' + emailAddress + ''; + } + } + return ''; + } + + }); +}); + + diff --git a/frontend/client/modules/crm/src/views/campaign/record/detail-bottom.js b/frontend/client/modules/crm/src/views/campaign/record/detail-bottom.js new file mode 100644 index 0000000000..8700adcd79 --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign/record/detail-bottom.js @@ -0,0 +1,31 @@ +/************************************************************************ + * 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.Record.DetailBottom', 'Views.Record.DetailBottom', function (Dep) { + + return Dep.extend({ + + + }); +}); + + diff --git a/frontend/client/modules/crm/src/views/campaign/record/detail.js b/frontend/client/modules/crm/src/views/campaign/record/detail.js new file mode 100644 index 0000000000..bf7dff6fcd --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign/record/detail.js @@ -0,0 +1,49 @@ +/************************************************************************ + * 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.Record.Detail', 'Views.Record.Detail', function (Dep) { + + return Dep.extend({ + + bottomView: 'Crm:Campaign.Record.DetailBottom', + + handleStatisticsPanelAppearance: function() { + if (this.model.get('status') == 'Planning') { + this.hidePanel('statistics'); + } else { + this.showPanel('statistics'); + } + }, + + afterRender: function () { + Dep.prototype.afterRender.call(this); + + this.handleStatisticsPanelAppearance(); + this.listenTo(this.model, 'change:status', function () { + this.handleStatisticsPanelAppearance(); + }, this); + }, + + }); +}); + + diff --git a/frontend/client/modules/crm/src/views/campaign/record/panels/campaign-log-records.js b/frontend/client/modules/crm/src/views/campaign/record/panels/campaign-log-records.js new file mode 100644 index 0000000000..d07818acf5 --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign/record/panels/campaign-log-records.js @@ -0,0 +1,74 @@ +/************************************************************************ + * 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.Record.Panels.CampaignLogRecords', 'Views.Record.Panels.Relationship', function (Dep) { + + return Dep.extend({ + + template: 'crm:campaign.record.panels.campaign-log-records', + + filterList: ["All", "Sent", "Opened", "Opted Out", "Bounced", "Clicked", "Lead Created"], + + data: function () { + return _.extend({ + filterList: this.filterList, + filterValue: this.filterValue, + filterTranslatedOptions: this.getFilterTranslatedOptions() + }, Dep.prototype.data.call(this)); + }, + + getFilterTranslatedOptions: function () { + var o = Espo.Utils.clone(this.getLanguage().get('CampaignLogRecord', 'options', 'action')); + o['All'] = this.translate('All', 'labels', 'CampaignLogRecord'); + + return o; + }, + + setup: function () { + Dep.prototype.setup.call(this); + this.events = Espo.Utils.clone(this.events || {}); + + this.events['change select[name="filter"]'] = function (e) { + var value = $(e.currentTarget).val(); + this.setFilter(value); + }; + }, + + setFilter: function (value) { + this.filterValue = value; + if (value && value != 'All') { + this.collection.where = [{ + field: 'action', + type: 'equals', + value: value + }]; + } else { + this.collection.where = []; + } + this.collection.fetch(); + + } + + }); +}); + + diff --git a/frontend/client/modules/crm/src/views/campaign/record/panels/statistics.js b/frontend/client/modules/crm/src/views/campaign/record/panels/statistics.js new file mode 100644 index 0000000000..b990677f19 --- /dev/null +++ b/frontend/client/modules/crm/src/views/campaign/record/panels/statistics.js @@ -0,0 +1,69 @@ +/************************************************************************ + * 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.Record.Panels.Statistics', 'Views.Record.Panels.Side', function (Dep) { + + return Dep.extend({ + + + setupFieldList: function () { + var type = this.model.get('type'); + switch (type) { + case 'Email': + case 'Newsletter': + this.fieldList = ['sentCount', 'openedCount', 'clickedCount', 'optedOutCount', 'bouncedCount', 'revenue']; + break; + case 'Web': + case 'Television': + case 'Radio': + this.fieldList = ['leadCreatedCount', 'revenue']; + break; + case 'Mail': + this.fieldList = ['sentCount', 'leadCreatedCount', 'revenue']; + break; + default: + this.fieldList = ['leadCreatedCount', 'revenue']; + } + }, + + setup: function () { + this.fieldList = ['sentCount', 'openedCount', 'clickedCount', 'optedOutCount', 'bouncedCount', 'leadCreatedCount', 'revenue']; + Dep.prototype.setup.call(this); + this.setupFieldList(); + + this.listenTo(this.model, 'change:type', function () { + this.setupFieldList(); + if (this.isRendered()) { + this.render(); + } + }, this); + }, + + actionRefresh: function () { + this.model.fetch(); + }, + + + }); +}); + +