3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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 'type' => CRM_Utils_Type
::T_INT
,
117 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
118 'options' => CRM_Contribute_PseudoConstant
::financialType(),
121 'grouping' => 'pledge-fields',
123 'civicrm_pledge_payment' => array(
124 'dao' => 'CRM_Pledge_DAO_PledgePayment',
126 'scheduled_date' => array(
127 'title' => ts('Next Payment Due'),
128 'type' => CRM_Utils_Type
::T_DATE
,
133 'scheduled_date' => array(
134 'title' => ts('Next Payment Due'),
135 'operatorType' => CRM_Report_Form
::OP_DATE
,
136 'type' => CRM_Utils_Type
::T_DATE
,
139 'grouping' => 'pledge-fields',
141 'civicrm_address' => array(
142 'dao' => 'CRM_Core_DAO_Address',
144 'street_address' => NULL,
146 'postal_code' => NULL,
147 'state_province_id' => array(
148 'title' => ts('State/Province'),
150 'country_id' => array(
151 'title' => ts('Country'),
155 'grouping' => 'contact-fields',
157 'civicrm_email' => array(
158 'dao' => 'CRM_Core_DAO_Email',
159 'fields' => array('email' => NULL),
160 'grouping' => 'contact-fields',
162 'civicrm_group' => array(
163 'dao' => 'CRM_Contact_DAO_Group',
167 'name' => 'group_id',
168 'title' => ts('Group'),
169 'type' => CRM_Utils_Type
::T_INT
,
171 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
172 'options' => CRM_Core_PseudoConstant
::staticGroup(),
178 // If we have a campaign, build out the relevant elements
179 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
180 $this->_columns
['civicrm_pledge']['fields']['campaign_id'] = array(
181 'title' => 'Campaign',
182 'default' => 'false',
184 $this->_columns
['civicrm_pledge']['filters']['campaign_id'] = array(
185 'title' => ts('Campaign'),
186 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
187 'options' => $this->activeCampaigns
,
188 'type' => CRM_Utils_Type
::T_INT
,
192 $this->_tagFilter
= TRUE;
193 $this->_currencyColumn
= 'civicrm_pledge_currency';
194 parent
::__construct();
197 public function preProcess() {
198 $this->assign('reportTitle', ts('Pledged but not Paid Report'));
199 parent
::preProcess();
202 public function select() {
204 $this->_columnHeaders
= array();
205 foreach ($this->_columns
as $tableName => $table) {
206 if (array_key_exists('fields', $table)) {
207 foreach ($table['fields'] as $fieldName => $field) {
208 if (!empty($field['required']) ||
209 !empty($this->_params
['fields'][$fieldName])
211 // to include optional columns address and email, only if checked
212 if ($tableName == 'civicrm_address') {
213 $this->_addressField
= TRUE;
214 $this->_emailField
= TRUE;
216 elseif ($tableName == 'civicrm_email') {
217 $this->_emailField
= TRUE;
219 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
220 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
221 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
226 $this->_select
= "SELECT " . implode(', ', $select) . " ";
229 public function from() {
232 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
233 $pendingStatus = array_search('Pending', $allStatus);
239 if ($key = CRM_Utils_Array
::key($statusKey, $allStatus)) {
240 $unpaidStatus[] = $key;
244 $statusIds = implode(', ', $unpaidStatus);
247 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
248 INNER JOIN civicrm_pledge {$this->_aliases['civicrm_pledge']}
249 ON ({$this->_aliases['civicrm_pledge']}.contact_id =
250 {$this->_aliases['civicrm_contact']}.id) AND
251 {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
252 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
253 ON ({$this->_aliases['civicrm_pledge']}.id =
254 {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";
256 // include address field if address column is to be included
257 if ($this->_addressField
) {
259 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
260 ON ({$this->_aliases['civicrm_contact']}.id =
261 {$this->_aliases['civicrm_address']}.contact_id) AND
262 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
265 // include email field if email column is to be included
266 if ($this->_emailField
) {
268 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
269 ON ({$this->_aliases['civicrm_contact']}.id =
270 {$this->_aliases['civicrm_email']}.contact_id) AND
271 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
275 public function groupBy() {
277 GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
278 {$this->_aliases['civicrm_pledge']}.id,
279 {$this->_aliases['civicrm_pledge']}.currency";
282 public function orderBy() {
283 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_pledge']}.contact_id, {$this->_aliases['civicrm_pledge']}.id";
286 public function postProcess() {
287 // get the acl clauses built before we assemble the query
288 $this->buildACLClause($this->_aliases
['civicrm_contact']);
289 parent
::PostProcess();
293 * Alter display of rows.
295 * Iterate through the rows retrieved via SQL and make changes for display purposes,
296 * such as rendering contacts as links.
300 public function alterDisplay(&$rows) {
302 $checkList = array();
303 $display_flag = $prev_cid = $cid = 0;
305 foreach ($rows as $rowNum => $row) {
306 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
307 // don't repeat contact details if its same as the previous row
308 if (array_key_exists('civicrm_contact_id', $row)) {
309 if ($cid = $row['civicrm_contact_id']) {
314 if ($prev_cid == $cid) {
325 foreach ($row as $colName => $colVal) {
326 if (in_array($colName, $this->_noRepeats
)) {
327 unset($rows[$rowNum][$colName]);
336 //handle the Financial Type Ids
337 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
338 if ($value = $row['civicrm_pledge_financial_type_id']) {
339 $rows[$rowNum]['civicrm_pledge_financial_type_id'] = CRM_Contribute_PseudoConstant
::financialType($value, FALSE);
344 //handle the Status Ids
345 if (array_key_exists('civicrm_pledge_status_id', $row)) {
346 if ($value = $row['civicrm_pledge_status_id']) {
347 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant
::contributionStatus($value);
352 // handle state province
353 if (array_key_exists('civicrm_address_state_province_id', $row)) {
354 if ($value = $row['civicrm_address_state_province_id']) {
355 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value, FALSE);
361 if (array_key_exists('civicrm_address_country_id', $row)) {
362 if ($value = $row['civicrm_address_country_id']) {
363 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
368 // convert display name to links
369 if (array_key_exists('civicrm_contact_sort_name', $row) &&
370 array_key_exists('civicrm_contact_id', $row)
372 $url = CRM_Report_Utils_Report
::getNextUrl('pledge/summary',
373 'reset=1&force=1&id_op=eq&id_value=' .
374 $row['civicrm_contact_id'],
375 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
377 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
378 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Pledge Details for this contact");
382 // If using campaigns, convert campaign_id to campaign title
383 if (array_key_exists('civicrm_pledge_campaign_id', $row)) {
384 if ($value = $row['civicrm_pledge_campaign_id']) {
385 $rows[$rowNum]['civicrm_pledge_campaign_id'] = $this->activeCampaigns
[$value];
390 // skip looking further in rows, if first row itself doesn't
391 // have the column we need