]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/PopupCampaignRoi.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Campaigns / PopupCampaignRoi.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition 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 global $theme;
59
60
61
62
63 $GLOBALS['log']->info("Campaign detail view");
64
65 $xtpl=new XTemplate ('modules/Campaigns/PopupCampaignRoi.html');
66
67 //_pp($_REQUEST['id']);
68 $campaign_id=$_REQUEST['id'];
69 $campaign = new Campaign();
70 $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, 
71                             ROUND((SUM(opp.amount) - SUM(camp.actual_cost))/(SUM(camp.actual_cost)), 2)*100 as ROI";               
72             $opp_query1 .= " from opportunities opp";
73             $opp_query1 .= " right join campaigns camp on camp.id = opp.campaign_id";
74             $opp_query1 .= " where opp.sales_stage = 'Closed Won' and camp.id='$campaign_id'";
75             $opp_query1 .= " group by camp.name";
76             //$opp_query1 .= " and deleted=0";                                  
77             $opp_result1=$campaign->db->query($opp_query1);              
78             $opp_data1=$campaign->db->fetchByAssoc($opp_result1);
79  //get the click-throughs
80  $query_click = "SELECT count(*) hits ";
81                         $query_click.= " FROM campaign_log ";
82                         $query_click.= " WHERE campaign_id = '$campaign_id' AND activity_type='link' AND related_type='CampaignTrackers' AND archived=0 AND deleted=0";
83
84             //if $marketing id is specified, then lets filter the chart by the value
85             if (!empty($marketing_id)){
86                 $query_click.= " AND marketing_id ='$marketing_id'"; 
87             }            
88
89                         $query_click.= " GROUP BY  activity_type, target_type";
90                         $query_click.= " ORDER BY  activity_type, target_type";
91                         $result = $campaign->db->query($query_click);
92             
93             
94   $xtpl->assign("OPP_COUNT", $opp_data1['opp_count']);    
95   $xtpl->assign("ACTUAL_COST",$opp_data1['actual_cost']);
96   $xtpl->assign("PLANNED_BUDGET",$opp_data1['budget']);
97   $xtpl->assign("EXPECTED_REVENUE",$opp_data1['expected_revenue']);
98          
99            
100
101
102         $currency  = new Currency();
103 if(isset($focus->currency_id) && !empty($focus->currency_id))
104 {
105         $currency->retrieve($focus->currency_id);
106         if( $currency->deleted != 1){
107                 $xtpl->assign("CURRENCY", $currency->iso4217 .' '.$currency->symbol );
108         }else $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
109 }else{
110
111         $xtpl->assign("CURRENCY", $currency->getDefaultISO4217() .' '.$currency->getDefaultCurrencySymbol() );
112
113 }
114
115 global $current_user;
116 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
117
118         $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>");
119 }
120
121 //$detailView->processListNavigation($xtpl, "CAMPAIGN", $offset, $focus->is_AuditEnabled());
122 // adding custom fields:
123 //require_once('modules/DynamicFields/templates/Files/DetailView.php');
124
125 /* we need to build the dropdown of related marketing values
126     $latest_marketing_id = '';
127     $selected_marketing_id = '';
128     if(isset($_REQUEST['mkt_id'])) $selected_marketing_id = $_REQUEST['mkt_id'];
129     $options_str = '<option value="all">--None--</option>';
130     //query for all email marketing records related to this campaign
131     $latest_marketing_query = "select id, name, date_modified from email_marketing where campaign_id = '$focus->id' order by date_modified desc";
132     
133     //build string with value(s) retrieved
134     $result =$campaign->db->query($latest_marketing_query);
135     if ($row = $campaign->db->fetchByAssoc($result)){
136         //first, populated the latest marketing id variable, as this
137         // variable will be used to build chart and subpanels
138         $latest_marketing_id = $row['id'];
139         //fill in first option value
140         $options_str .= '<option value="'. $row['id'] .'"';
141         // if the marketing id is same as selected marketing id, set this option to render as "selected"
142         if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
143             $options_str .=' selected>'. $row['name'] .'</option>';
144         // if the marketing id is empty then set this first option to render as "selected"
145         }elseif(empty($selected_marketing_id)){
146             $options_str .=' selected>'. $row['name'] .'</option>';
147         // if the marketing is not empty, but not same as selected marketing id, then..
148         //.. do not set this option to render as "selected"            
149         }else{
150             $options_str .='>'. $row['name'] .'</option>';
151         }
152     }
153     //process rest of records, if they exist
154     while ($row = $campaign->db->fetchByAssoc($result)){
155         //add to list of option values
156         $options_str .= '<option value="'. $row['id'] .'"';
157         //if the marketing id is same as selected marketing id, then set this option to render as "selected"
158         if (!empty($selected_marketing_id) && $selected_marketing_id == $row['id']) {
159             $options_str .=' selected>'. $row['name'] .'</option>';
160         }else{
161             $options_str .=' >'. $row['name'] .'</option>';
162         }    
163      }
164     //populate the dropdown    
165     $xtpl->assign("MKT_DROP_DOWN",$options_str);
166     
167   */  
168
169 //add chart
170 $seps                           = array("-", "/");
171 $dates                          = array(date($GLOBALS['timedate']->dbDayFormat), $GLOBALS['timedate']->dbDayFormat);
172 $dateFileNameSafe       = str_replace($seps, "_", $dates);
173 $cache_file_name_roi    = $current_user->getUserPrivGuid()."_campaign_response_by_roi_".$dateFileNameSafe[0]."_".$dateFileNameSafe[1].".xml";
174 $chart= new campaign_charts();
175
176 //ob_start();
177
178     //if marketing id has been selected, then set "latest_marketing_id" to the selected value
179     //latest marketing id will be passed in to filter the charts and subpanels 
180     //_pp($sugar_config['tmp_dir'].$cache_file_name_roi);
181     
182     if(!empty($selected_marketing_id)){$latest_marketing_id = $selected_marketing_id;}
183     if(empty($latest_marketing_id) ||  $latest_marketing_id === 'all'){        
184         $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));
185     }else{
186         
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     }
189     
190 //$output_html .= ob_get_contents();
191 //ob_end_clean();
192
193
194 //_ppd($xtpl);
195 //end chart
196
197 $xtpl->parse("main");
198 $xtpl->out("main");
199
200 ?>