3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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(
52 function __construct() {
54 // Check if CiviCampaign is a) enabled and b) has active campaigns
55 $config = CRM_Core_Config
::singleton();
56 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
57 if ($campaignEnabled) {
58 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
59 $this->activeCampaigns
= $getCampaigns['campaigns'];
60 asort($this->activeCampaigns
);
63 $this->_columns
= array(
66 'dao' => 'CRM_Contact_DAO_Contact',
70 array('title' => ts('Constituent Name'),
80 'grouping' => 'contact-fields',
84 'dao' => 'CRM_Pledge_DAO_Pledge',
87 'pledge_create_date' =>
88 array('title' => ts('Pledge Made'),
91 'financial_type_id' =>
92 array('title' => ts('Financial Type'),
96 array('title' => ts('Amount'),
98 'type' => CRM_Utils_Type
::T_MONEY
,
103 'no_display' => TRUE,
106 array('title' => ts('Status'),
111 'pledge_create_date' =>
113 'title' => ts('Pledge Made'),
114 'operatorType' => CRM_Report_Form
::OP_DATE
,
117 array('title' => 'Currency',
118 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
119 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
121 'type' => CRM_Utils_Type
::T_STRING
,
123 'financial_type_id' =>
124 array( 'title' => ts('Financial Type'),
125 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
126 'options' => CRM_Contribute_PseudoConstant
::financialType(),
129 'grouping' => 'pledge-fields',
131 'civicrm_pledge_payment' =>
133 'dao' => 'CRM_Pledge_DAO_PledgePayment',
136 'scheduled_date' => array(
137 'title' => ts('Next Payment Due'),
138 'type' => CRM_Utils_Type
::T_DATE
,
146 'title' => ts('Next Payment Due'),
147 'operatorType' => CRM_Report_Form
::OP_DATE
,
148 'type' => CRM_Utils_Type
::T_DATE
,
151 'grouping' => 'pledge-fields',
155 'dao' => 'CRM_Core_DAO_Address',
158 'street_address' => NULL,
160 'postal_code' => NULL,
161 'state_province_id' =>
162 array('title' => ts('State/Province'),
165 array('title' => ts('Country'),
169 'grouping' => 'contact-fields',
173 'dao' => 'CRM_Core_DAO_Email',
175 array('email' => NULL),
176 'grouping' => 'contact-fields',
180 'dao' => 'CRM_Contact_DAO_Group',
186 'name' => 'group_id',
187 'title' => ts('Group'),
189 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
190 'options' => CRM_Core_PseudoConstant
::staticGroup(),
196 // If we have a campaign, build out the relevant elements
197 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
198 $this->_columns
['civicrm_pledge']['fields']['campaign_id'] = array(
199 'title' => 'Campaign',
200 'default' => 'false',
202 $this->_columns
['civicrm_pledge']['filters']['campaign_id'] = array('title' => ts('Campaign'),
203 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
204 'options' => $this->activeCampaigns
,
208 $this->_tagFilter
= TRUE;
209 $this->_currencyColumn
= 'civicrm_pledge_currency';
210 parent
::__construct();
213 function preProcess() {
214 $this->assign('reportTitle', ts('Pledged but not Paid Report'));
215 parent
::preProcess();
220 $this->_columnHeaders
= array();
221 foreach ($this->_columns
as $tableName => $table) {
222 if (array_key_exists('fields', $table)) {
223 foreach ($table['fields'] as $fieldName => $field) {
224 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
225 // to include optional columns address and email, only if checked
226 if ($tableName == 'civicrm_address') {
227 $this->_addressField
= TRUE;
228 $this->_emailField
= TRUE;
230 elseif ($tableName == 'civicrm_email') {
231 $this->_emailField
= TRUE;
233 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
234 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
235 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
240 $this->_select
= "SELECT " . implode(', ', $select) . " ";
246 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
247 $pendingStatus = array_search('Pending', $allStatus);
249 'Pending', 'In Progress', 'Overdue') as $statusKey) {
250 if ($key = CRM_Utils_Array
::key($statusKey, $allStatus)) {
251 $unpaidStatus[] = $key;
255 $statusIds = implode(', ', $unpaidStatus);
258 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
259 INNER JOIN civicrm_pledge {$this->_aliases['civicrm_pledge']}
260 ON ({$this->_aliases['civicrm_pledge']}.contact_id =
261 {$this->_aliases['civicrm_contact']}.id) AND
262 {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
263 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
264 ON ({$this->_aliases['civicrm_pledge']}.id =
265 {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";
267 // include address field if address column is to be included
268 if ($this->_addressField
) {
270 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
271 ON ({$this->_aliases['civicrm_contact']}.id =
272 {$this->_aliases['civicrm_address']}.contact_id) AND
273 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
276 // include email field if email column is to be included
277 if ($this->_emailField
) {
279 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
280 ON ({$this->_aliases['civicrm_contact']}.id =
281 {$this->_aliases['civicrm_email']}.contact_id) AND
282 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
288 GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
289 {$this->_aliases['civicrm_pledge']}.id,
290 {$this->_aliases['civicrm_pledge']}.currency";
294 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_pledge']}.contact_id, {$this->_aliases['civicrm_pledge']}.id";
297 function postProcess() {
298 // get the acl clauses built before we assemble the query
299 $this->buildACLClause($this->_aliases
['civicrm_contact']);
300 parent
::PostProcess();
306 function alterDisplay(&$rows) {
307 // custom code to alter rows
309 $checkList = array();
310 $display_flag = $prev_cid = $cid = 0;
312 foreach ($rows as $rowNum => $row) {
313 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
314 // don't repeat contact details if its same as the previous row
315 if (array_key_exists('civicrm_contact_id', $row)) {
316 if ($cid = $row['civicrm_contact_id']) {
321 if ($prev_cid == $cid) {
332 foreach ($row as $colName => $colVal) {
333 if (in_array($colName, $this->_noRepeats
)) {
334 unset($rows[$rowNum][$colName]);
343 //handle the Financial Type Ids
344 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
345 if ($value = $row['civicrm_pledge_financial_type_id']) {
346 $rows[$rowNum]['civicrm_pledge_financial_type_id'] =
347 CRM_Contribute_PseudoConstant
::financialType($value, false);
352 //handle the Status Ids
353 if (array_key_exists('civicrm_pledge_status_id', $row)) {
354 if ($value = $row['civicrm_pledge_status_id']) {
355 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant
::contributionStatus($value);
360 // handle state province
361 if (array_key_exists('civicrm_address_state_province_id', $row)) {
362 if ($value = $row['civicrm_address_state_province_id']) {
363 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value, FALSE);
369 if (array_key_exists('civicrm_address_country_id', $row)) {
370 if ($value = $row['civicrm_address_country_id']) {
371 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
376 // convert display name to links
377 if (array_key_exists('civicrm_contact_sort_name', $row) &&
378 array_key_exists('civicrm_contact_id', $row)
380 $url = CRM_Report_Utils_Report
::getNextUrl('pledge/summary',
381 'reset=1&force=1&id_op=eq&id_value=' .
382 $row['civicrm_contact_id'],
383 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
385 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
386 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Pledge Details for this contact");
390 // If using campaigns, convert campaign_id to campaign title
391 if (array_key_exists('civicrm_pledge_campaign_id', $row)) {
392 if ($value = $row['civicrm_pledge_campaign_id']) {
393 $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns
[$value];
398 // skip looking further in rows, if first row itself doesn't
399 // have the column we need