]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/PopupCampaignRoi.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Campaigns / PopupCampaignRoi.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48
49 require_once('include/DetailView/DetailView.php');
50 require_once('modules/Campaigns/Charts.php');
51
52
53 global $mod_strings;
54 global $app_strings;
55 global $app_list_strings;
56 global $sugar_version, $sugar_config;
57
58 /*
59 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_NEWSLETTER'].": ".$focus->name, true);
60 */
61 global $theme;
62
63
64
65
66 $GLOBALS['log']->info("Campaign detail view");
67
68 $xtpl=new XTemplate ('modules/Campaigns/PopupCampaignRoi.html');
69
70 //_pp($_REQUEST['id']);
71 $campaign_id=$_REQUEST['id'];
72 $campaign = new Campaign();
73 $opp_query1  = "select camp.name, camp.actual_cost,camp.budget,camp.expected_revenue,count(*) opp_count,SUM(opp.amount) as Revenue, SUM(camp.actual_cost) as Investment, 
74                             ROUND((SUM(opp.amount) - SUM(camp.actual_cost))/(SUM(camp.actual_cost)), 2)*100 as ROI";               
75             $opp_query1 .= " from opportunities opp";
76             $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
77             $opp_query1 .= " where opp.sales_stage = 'Closed Won' and camp.id='$campaign_id'";
78             $opp_query1 .= " group by camp.name";
79             //$opp_query1 .= " and deleted=0";                                  
80             $opp_result1=$campaign->db->query($opp_query1);              
81             $opp_data1=$campaign->db->fetchByAssoc($opp_result1);
82  //get the click-throughs
83  $query_click = "SELECT count(*) hits ";
84                         $query_click.= " FROM campaign_log ";
85                         $query_click.= " WHERE campaign_id = '$campaign_id' AND activity_type='link' AND related_type='CampaignTrackers' AND archived=0 AND deleted=0";
86
87             //if $marketing id is specified, then lets filter the chart by the value
88             if (!empty($marketing_id)){
89                 $query_click.= " AND marketing_id ='$marketing_id'"; 
90             }            
91
92                         $query_click.= " GROUP BY  activity_type, target_type";
93                         $query_click.= " ORDER BY  activity_type, target_type";
94                         $result = $campaign->db->query($query_click);
95             
96             
97   $xtpl->assign("OPP_COUNT", $opp_data1['opp_count']);    
98   $xtpl->assign("ACTUAL_COST",$opp_data1['actual_cost']);
99   $xtpl->assign("PLANNED_BUDGET",$opp_data1['budget']);
100   $xtpl->assign("EXPECTED_REVENUE",$opp_data1['expected_revenue']);
101          
102            
103
104
105         $currency  = new Currency();
106 if(isset($focus->currency_id) && !empty($focus->currency_id))
107 {
108         $currency->retrieve($focus->currency_id);
109         if( $currency->deleted != 1){
110                 $xtpl->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
111         }else $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
112 }else{
113
114         $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
115
116 }
117
118 global $current_user;
119 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
120
121         $xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$_REQUEST['record']. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
122 }
123
124 //$detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
125 // adding custom fields:
126 //require_once('modules/DynamicFields/templates/Files/DetailView.php');
127
128 /* we need to build the dropdown of related marketing values
129     $latest_marketing_id = '';
130     $selected_marketing_id = '';
131     if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
132     $options_str = '<option value="all">--None--</option>';
133     //query for all email marketing records related to this campaign
134     $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
135     
136     //build string with value(s) retrieved
137     $result =$campaign->db->query($latest_marketing_query);
138     if ($row = $campaign->db->fetchByAssoc($result)){
139         //first, populated the latest marketing id variable, as this
140         // variable will be used to build chart and subpanels
141         $latest_marketing_id = $row['id'];
142         //fill in first option value
143         $options_str .= '<option value="'. $row['id'] .'"';
144         // if the marketing id is same as selected marketing id, set this option to render as "selected"
145         if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
146             $options_str .=' selected>'. $row['name'] .'</option>';
147         // if the marketing id is empty then set this first option to render as "selected"
148         }elseif(empty($selected_marketing_id)){
149             $options_str .=' selected>'. $row['name'] .'</option>';
150         // if the marketing is not empty, but not same as selected marketing id, then..
151         //.. do not set this option to render as "selected"            
152         }else{
153             $options_str .='>'. $row['name'] .'</option>';
154         }
155     }
156     //process rest of records, if they exist
157     while ($row = $campaign->db->fetchByAssoc($result)){
158         //add to list of option values
159         $options_str .= '<option value="'. $row['id'] .'"';
160         //if the marketing id is same as selected marketing id, then set this option to render as "selected"
161         if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
162             $options_str .=' selected>'. $row['name'] .'</option>';
163         }else{
164             $options_str .=' >'. $row['name'] .'</option>';
165         }    
166      }
167     //populate the dropdown    
168     $xtpl->assign("MKT_DROP_DOWN",$options_str);
169     
170   */  
171
172 //add chart
173 $seps                           = array("-", "/");
174 $dates                          = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
175 $dateFileNameSafe       = str_replace($seps, "_", $dates);
176 $cache_file_name_roi    = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
177 $chart= new campaign_charts();
178
179 //ob_start();
180
181     //if marketing id has been selected, then set "latest_marketing_id" to the selected value
182     //latest marketing id will be passed in to filter the charts and subpanels 
183     //_pp($sugar_config['tmp_dir'].$cache_file_name_roi);
184     
185     if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
186     if(empty($latest_marketing_id) ||  $latest_marketing_id === 'all'){        
187         $xtpl->assign("MY_CHART_ROI", $chart->campaign_response_roi_popup($app_list_strings['roi_type_dom'],$app_list_strings['roi_type_dom'],$campaign_id,$sugar_config['tmp_dir'].$cache_file_name_roi,true));
188     }else{
189         
190     $xtpl->assign("MY_CHART_ROI", $chart->campaign_response_roi_popup($app_list_strings['roi_type_dom'],$app_list_strings['roi_type_dom'],$campaign_id,$sugar_config['tmp_dir'].$cache_file_name_roi,true));                
191     }
192     
193 //$output_html .= ob_get_contents();
194 //ob_end_clean();
195
196
197 //_ppd($xtpl);
198 //end chart
199
200 $xtpl->parse("main");
201 $xtpl->out("main");
202
203 ?>