3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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(
46 function __construct() {
48 // Check if CiviCampaign is a) enabled and b) has active campaigns
49 $config = CRM_Core_Config
::singleton();
50 $campaignEnabled = in_array("CiviCampaign", $config->enableComponents
);
51 if ($campaignEnabled) {
52 $getCampaigns = CRM_Campaign_BAO_Campaign
::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
53 $this->activeCampaigns
= $getCampaigns['campaigns'];
54 asort($this->activeCampaigns
);
57 $this->_columns
= array(
60 'dao' => 'CRM_Contact_DAO_Contact',
64 array('title' => ts('Constituent Name'),
74 'grouping' => 'contact-fields',
78 'dao' => 'CRM_Pledge_DAO_Pledge',
81 'pledge_create_date' =>
82 array('title' => ts('Pledge Made'),
85 'financial_type_id' =>
86 array('title' => ts('Financial Type'),
90 array('title' => ts('Amount'),
92 'type' => CRM_Utils_Type
::T_MONEY
,
100 array('title' => ts('Status'),
105 'pledge_create_date' =>
107 'title' => ts('Pledge Made'),
108 'operatorType' => CRM_Report_Form
::OP_DATE
,
111 array('title' => 'Currency',
112 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
113 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
115 'type' => CRM_Utils_Type
::T_STRING
,
117 'financial_type_id' =>
118 array( 'title' => ts('Financial Type'),
119 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
120 'options' => CRM_Contribute_PseudoConstant
::financialType(),
123 'grouping' => 'pledge-fields',
125 'civicrm_pledge_payment' =>
127 'dao' => 'CRM_Pledge_DAO_PledgePayment',
131 array('title' => ts('Next Payment Due'),
132 'type' => CRM_Utils_Type
::T_DATE
,
140 'title' => ts('Next Payment Due'),
141 'operatorType' => CRM_Report_Form
::OP_DATE
,
144 'grouping' => 'pledge-fields',
148 'dao' => 'CRM_Core_DAO_Address',
151 'street_address' => NULL,
153 'postal_code' => NULL,
154 'state_province_id' =>
155 array('title' => ts('State/Province'),
158 array('title' => ts('Country'),
162 'grouping' => 'contact-fields',
166 'dao' => 'CRM_Core_DAO_Email',
168 array('email' => NULL),
169 'grouping' => 'contact-fields',
173 'dao' => 'CRM_Contact_DAO_Group',
179 'name' => 'group_id',
180 'title' => ts('Group'),
182 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
183 'options' => CRM_Core_PseudoConstant
::staticGroup(),
189 // If we have a campaign, build out the relevant elements
190 if ($campaignEnabled && !empty($this->activeCampaigns
)) {
191 $this->_columns
['civicrm_pledge']['fields']['campaign_id'] = array(
192 'title' => 'Campaign',
193 'default' => 'false',
195 $this->_columns
['civicrm_pledge']['filters']['campaign_id'] = array('title' => ts('Campaign'),
196 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
197 'options' => $this->activeCampaigns
,
201 $this->_tagFilter
= TRUE;
202 $this->_currencyColumn
= 'civicrm_pledge_currency';
203 parent
::__construct();
206 function preProcess() {
207 $this->assign('reportTitle', ts('Pledge But Not Paid Report'));
208 parent
::preProcess();
213 $this->_columnHeaders
= array();
214 foreach ($this->_columns
as $tableName => $table) {
215 if (array_key_exists('fields', $table)) {
216 foreach ($table['fields'] as $fieldName => $field) {
217 if (CRM_Utils_Array
::value('required', $field) ||
218 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
220 // to include optional columns address and email, only if checked
221 if ($tableName == 'civicrm_address') {
222 $this->_addressField
= TRUE;
223 $this->_emailField
= TRUE;
225 elseif ($tableName == 'civicrm_email') {
226 $this->_emailField
= TRUE;
228 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
229 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
230 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
235 $this->_select
= "SELECT " . implode(', ', $select) . " ";
241 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
242 $pendingStatus = array_search('Pending', $allStatus);
244 'Pending', 'In Progress', 'Overdue') as $statusKey) {
245 if ($key = CRM_Utils_Array
::key($statusKey, $allStatus)) {
246 $unpaidStatus[] = $key;
250 $statusIds = implode(', ', $unpaidStatus);
253 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
254 INNER JOIN civicrm_pledge {$this->_aliases['civicrm_pledge']}
255 ON ({$this->_aliases['civicrm_pledge']}.contact_id =
256 {$this->_aliases['civicrm_contact']}.id) AND
257 {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
258 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
259 ON ({$this->_aliases['civicrm_pledge']}.id =
260 {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";
262 // include address field if address column is to be included
263 if ($this->_addressField
) {
265 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
266 ON ({$this->_aliases['civicrm_contact']}.id =
267 {$this->_aliases['civicrm_address']}.contact_id) AND
268 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
271 // include email field if email column is to be included
272 if ($this->_emailField
) {
274 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
275 ON ({$this->_aliases['civicrm_contact']}.id =
276 {$this->_aliases['civicrm_email']}.contact_id) AND
277 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
283 GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
284 {$this->_aliases['civicrm_pledge']}.id,
285 {$this->_aliases['civicrm_pledge']}.currency";
289 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_pledge']}.contact_id, {$this->_aliases['civicrm_pledge']}.id";
292 function postProcess() {
293 // get the acl clauses built before we assemble the query
294 $this->buildACLClause($this->_aliases
['civicrm_contact']);
295 parent
::PostProcess();
298 function alterDisplay(&$rows) {
299 // custom code to alter rows
301 $checkList = array();
302 $display_flag = $prev_cid = $cid = 0;
304 foreach ($rows as $rowNum => $row) {
305 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
306 // don't repeat contact details if its same as the previous row
307 if (array_key_exists('civicrm_contact_id', $row)) {
308 if ($cid = $row['civicrm_contact_id']) {
313 if ($prev_cid == $cid) {
324 foreach ($row as $colName => $colVal) {
325 if (in_array($colName, $this->_noRepeats
)) {
326 unset($rows[$rowNum][$colName]);
335 //handle the Financial Type Ids
336 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
337 if ($value = $row['civicrm_pledge_financial_type_id']) {
338 $rows[$rowNum]['civicrm_pledge_financial_type_id'] =
339 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