3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Report_Form_Pledge_Pbnp
extends CRM_Report_Form
{
36 protected $_charts = array(
38 'barChart' => 'Bar Chart',
39 'pieChart' => 'Pie Chart',
41 public $_drilldownReport = array('pledge/summary' => 'Link to Detail Report');
43 protected $_customGroupExtends = array(
51 public function __construct() {
53 // Check if CiviCampaign is a) enabled and b) has active campaigns
54 $config = CRM_Core_Config
::singleton();
55 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
56 if ($campaignEnabled) {
57 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
58 $this->activeCampaigns
= $getCampaigns['campaigns'];
59 asort($this->activeCampaigns
);
62 $this->_columns
= array(
63 'civicrm_contact' => array(
64 'dao' => 'CRM_Contact_DAO_Contact',
67 'title' => ts('Constituent Name'),
76 'grouping' => 'contact-fields',
78 'civicrm_pledge' => array(
79 'dao' => 'CRM_Pledge_DAO_Pledge',
81 'pledge_create_date' => array(
82 'title' => ts('Pledge Made'),
85 'financial_type_id' => array(
86 'title' => ts('Financial Type'),
90 'title' => ts('Amount'),
92 'type' => CRM_Utils_Type
::T_MONEY
,
99 'title' => ts('Status'),
103 'pledge_create_date' => array(
104 'title' => ts('Pledge Made'),
105 'operatorType' => CRM_Report_Form
::OP_DATE
,
108 'title' => 'Currency',
109 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
110 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
112 'type' => CRM_Utils_Type
::T_STRING
,
114 'financial_type_id' => array(
115 'title' => ts('Financial Type'),
116 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
117 'options' => CRM_Contribute_PseudoConstant
::financialType(),
120 'grouping' => 'pledge-fields',
122 'civicrm_pledge_payment' => array(
123 'dao' => 'CRM_Pledge_DAO_PledgePayment',
125 'scheduled_date' => array(
126 'title' => ts('Next Payment Due'),
127 'type' => CRM_Utils_Type
::T_DATE
,
132 'scheduled_date' => array(
133 'title' => ts('Next Payment Due'),
134 'operatorType' => CRM_Report_Form
::OP_DATE
,
135 'type' => CRM_Utils_Type
::T_DATE
,
138 'grouping' => 'pledge-fields',
140 'civicrm_address' => array(
141 'dao' => 'CRM_Core_DAO_Address',
143 'street_address' => NULL,
145 'postal_code' => NULL,
146 'state_province_id' => array(
147 'title' => ts('State/Province'),
149 'country_id' => array(
150 'title' => ts('Country'),
154 'grouping' => 'contact-fields',
156 'civicrm_email' => array(
157 'dao' => 'CRM_Core_DAO_Email',
158 'fields' => array('email' => NULL),
159 'grouping' => 'contact-fields',
161 'civicrm_group' => array(
162 'dao' => 'CRM_Contact_DAO_Group',
166 'name' => 'group_id',
167 'title' => ts('Group'),
169 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
170 'options' => CRM_Core_PseudoConstant
::staticGroup(),
176 // If we have a campaign, build out the relevant elements
177 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
178 $this->_columns
['civicrm_pledge']['fields']['campaign_id'] = array(
179 'title' => 'Campaign',
180 'default' => 'false',
182 $this->_columns
['civicrm_pledge']['filters']['campaign_id'] = array(
183 'title' => ts('Campaign'),
184 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
185 'options' => $this->activeCampaigns
,
189 $this->_tagFilter
= TRUE;
190 $this->_currencyColumn
= 'civicrm_pledge_currency';
191 parent
::__construct();
194 public function preProcess() {
195 $this->assign('reportTitle', ts('Pledged but not Paid Report'));
196 parent
::preProcess();
199 public function select() {
201 $this->_columnHeaders
= array();
202 foreach ($this->_columns
as $tableName => $table) {
203 if (array_key_exists('fields', $table)) {
204 foreach ($table['fields'] as $fieldName => $field) {
205 if (!empty($field['required']) ||
206 !empty($this->_params
['fields'][$fieldName])
208 // to include optional columns address and email, only if checked
209 if ($tableName == 'civicrm_address') {
210 $this->_addressField
= TRUE;
211 $this->_emailField
= TRUE;
213 elseif ($tableName == 'civicrm_email') {
214 $this->_emailField
= TRUE;
216 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
217 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
218 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
223 $this->_select
= "SELECT " . implode(', ', $select) . " ";
226 public function from() {
229 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
230 $pendingStatus = array_search('Pending', $allStatus);
236 if ($key = CRM_Utils_Array
::key($statusKey, $allStatus)) {
237 $unpaidStatus[] = $key;
241 $statusIds = implode(', ', $unpaidStatus);
244 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
245 INNER JOIN civicrm_pledge {$this->_aliases['civicrm_pledge']}
246 ON ({$this->_aliases['civicrm_pledge']}.contact_id =
247 {$this->_aliases['civicrm_contact']}.id) AND
248 {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
249 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
250 ON ({$this->_aliases['civicrm_pledge']}.id =
251 {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";
253 // include address field if address column is to be included
254 if ($this->_addressField
) {
256 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
257 ON ({$this->_aliases['civicrm_contact']}.id =
258 {$this->_aliases['civicrm_address']}.contact_id) AND
259 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
262 // include email field if email column is to be included
263 if ($this->_emailField
) {
265 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
266 ON ({$this->_aliases['civicrm_contact']}.id =
267 {$this->_aliases['civicrm_email']}.contact_id) AND
268 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
272 public function groupBy() {
274 GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
275 {$this->_aliases['civicrm_pledge']}.id,
276 {$this->_aliases['civicrm_pledge']}.currency";
279 public function orderBy() {
280 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_pledge']}.contact_id, {$this->_aliases['civicrm_pledge']}.id";
283 public function postProcess() {
284 // get the acl clauses built before we assemble the query
285 $this->buildACLClause($this->_aliases
['civicrm_contact']);
286 parent
::PostProcess();
290 * Alter display of rows.
292 * Iterate through the rows retrieved via SQL and make changes for display purposes,
293 * such as rendering contacts as links.
297 public function alterDisplay(&$rows) {
299 $checkList = array();
300 $display_flag = $prev_cid = $cid = 0;
302 foreach ($rows as $rowNum => $row) {
303 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
304 // don't repeat contact details if its same as the previous row
305 if (array_key_exists('civicrm_contact_id', $row)) {
306 if ($cid = $row['civicrm_contact_id']) {
311 if ($prev_cid == $cid) {
322 foreach ($row as $colName => $colVal) {
323 if (in_array($colName, $this->_noRepeats
)) {
324 unset($rows[$rowNum][$colName]);
333 //handle the Financial Type Ids
334 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
335 if ($value = $row['civicrm_pledge_financial_type_id']) {
336 $rows[$rowNum]['civicrm_pledge_financial_type_id'] = CRM_Contribute_PseudoConstant
::financialType($value, FALSE);
341 //handle the Status Ids
342 if (array_key_exists('civicrm_pledge_status_id', $row)) {
343 if ($value = $row['civicrm_pledge_status_id']) {
344 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant
::contributionStatus($value);
349 // handle state province
350 if (array_key_exists('civicrm_address_state_province_id', $row)) {
351 if ($value = $row['civicrm_address_state_province_id']) {
352 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value, FALSE);
358 if (array_key_exists('civicrm_address_country_id', $row)) {
359 if ($value = $row['civicrm_address_country_id']) {
360 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
365 // convert display name to links
366 if (array_key_exists('civicrm_contact_sort_name', $row) &&
367 array_key_exists('civicrm_contact_id', $row)
369 $url = CRM_Report_Utils_Report
::getNextUrl('pledge/summary',
370 'reset=1&force=1&id_op=eq&id_value=' .
371 $row['civicrm_contact_id'],
372 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
374 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
375 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Pledge Details for this contact");
379 // If using campaigns, convert campaign_id to campaign title
380 if (array_key_exists('civicrm_pledge_campaign_id', $row)) {
381 if ($value = $row['civicrm_pledge_campaign_id']) {
382 $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns
[$value];
387 // skip looking further in rows, if first row itself doesn't
388 // have the column we need