5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Form_Pledge_Pbnp
extends CRM_Report_Form
{
38 protected $_charts = array(
40 'barChart' => 'Bar Chart',
41 'pieChart' => 'Pie Chart',
43 public $_drilldownReport = array('pledge/summary' => 'Link to Detail Report');
45 protected $_customGroupExtends = array(
48 function __construct() {
49 $this->_columns
= array(
52 'dao' => 'CRM_Contact_DAO_Contact',
56 array('title' => ts('Constituent Name'),
66 'grouping' => 'contact-fields',
70 'dao' => 'CRM_Pledge_DAO_Pledge',
73 'pledge_create_date' =>
74 array('title' => ts('Pledge Made'),
77 'financial_type_id' =>
78 array('title' => ts('Financial Type'),
82 array('title' => ts('Amount'),
84 'type' => CRM_Utils_Type
::T_MONEY
,
92 array('title' => ts('Status'),
97 'pledge_create_date' =>
99 'title' => 'Pledge Made',
100 'operatorType' => CRM_Report_Form
::OP_DATE
,
103 array('title' => 'Currency',
104 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
105 'options' => CRM_Core_OptionGroup
::values('currencies_enabled'),
107 'type' => CRM_Utils_Type
::T_STRING
,
109 'financial_type_id' =>
110 array( 'title' => ts('Financial Type'),
111 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
112 'options' => CRM_Contribute_PseudoConstant
::financialType(),
115 'grouping' => 'pledge-fields',
117 'civicrm_pledge_payment' =>
119 'dao' => 'CRM_Pledge_DAO_PledgePayment',
123 array('title' => ts('Next Payment Due'),
124 'type' => CRM_Utils_Type
::T_DATE
,
128 'grouping' => 'pledge-fields',
132 'dao' => 'CRM_Core_DAO_Address',
135 'street_address' => NULL,
137 'postal_code' => NULL,
138 'state_province_id' =>
139 array('title' => ts('State/Province'),
142 array('title' => ts('Country'),
146 'grouping' => 'contact-fields',
150 'dao' => 'CRM_Core_DAO_Email',
152 array('email' => NULL),
153 'grouping' => 'contact-fields',
157 'dao' => 'CRM_Contact_DAO_Group',
163 'name' => 'group_id',
164 'title' => ts('Group'),
166 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
167 'options' => CRM_Core_PseudoConstant
::staticGroup(),
173 $this->_tagFilter
= TRUE;
174 $this->_currencyColumn
= 'civicrm_pledge_currency';
175 parent
::__construct();
178 function preProcess() {
179 $this->assign('reportTitle', ts('Pledge But Not Paid Report'));
180 parent
::preProcess();
185 $this->_columnHeaders
= array();
186 foreach ($this->_columns
as $tableName => $table) {
187 if (array_key_exists('fields', $table)) {
188 foreach ($table['fields'] as $fieldName => $field) {
189 if (CRM_Utils_Array
::value('required', $field) ||
190 CRM_Utils_Array
::value($fieldName, $this->_params
['fields'])
192 // to include optional columns address and email, only if checked
193 if ($tableName == 'civicrm_address') {
194 $this->_addressField
= TRUE;
195 $this->_emailField
= TRUE;
197 elseif ($tableName == 'civicrm_email') {
198 $this->_emailField
= TRUE;
200 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
201 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
202 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
207 $this->_select
= "SELECT " . implode(', ', $select) . " ";
213 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
214 $pendingStatus = array_search('Pending', $allStatus);
216 'Pending', 'In Progress', 'Overdue') as $statusKey) {
217 if ($key = CRM_Utils_Array
::key($statusKey, $allStatus)) {
218 $unpaidStatus[] = $key;
222 $statusIds = implode(', ', $unpaidStatus);
225 FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom}
226 INNER JOIN civicrm_pledge {$this->_aliases['civicrm_pledge']}
227 ON ({$this->_aliases['civicrm_pledge']}.contact_id =
228 {$this->_aliases['civicrm_contact']}.id) AND
229 {$this->_aliases['civicrm_pledge']}.status_id IN ( {$statusIds} )
230 LEFT JOIN civicrm_pledge_payment {$this->_aliases['civicrm_pledge_payment']}
231 ON ({$this->_aliases['civicrm_pledge']}.id =
232 {$this->_aliases['civicrm_pledge_payment']}.pledge_id AND {$this->_aliases['civicrm_pledge_payment']}.status_id = {$pendingStatus} ) ";
234 // include address field if address column is to be included
235 if ($this->_addressField
) {
237 LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
238 ON ({$this->_aliases['civicrm_contact']}.id =
239 {$this->_aliases['civicrm_address']}.contact_id) AND
240 {$this->_aliases['civicrm_address']}.is_primary = 1\n";
243 // include email field if email column is to be included
244 if ($this->_emailField
) {
246 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
247 ON ({$this->_aliases['civicrm_contact']}.id =
248 {$this->_aliases['civicrm_email']}.contact_id) AND
249 {$this->_aliases['civicrm_email']}.is_primary = 1\n";
255 GROUP BY {$this->_aliases['civicrm_pledge']}.contact_id,
256 {$this->_aliases['civicrm_pledge']}.id,
257 {$this->_aliases['civicrm_pledge']}.currency";
261 $this->_orderBy
= "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name, {$this->_aliases['civicrm_pledge']}.contact_id, {$this->_aliases['civicrm_pledge']}.id";
264 function postProcess() {
265 // get the acl clauses built before we assemble the query
266 $this->buildACLClause($this->_aliases
['civicrm_contact']);
267 parent
::PostProcess();
270 function alterDisplay(&$rows) {
271 // custom code to alter rows
273 $checkList = array();
274 $display_flag = $prev_cid = $cid = 0;
276 foreach ($rows as $rowNum => $row) {
277 if (!empty($this->_noRepeats
) && $this->_outputMode
!= 'csv') {
278 // don't repeat contact details if its same as the previous row
279 if (array_key_exists('civicrm_contact_id', $row)) {
280 if ($cid = $row['civicrm_contact_id']) {
285 if ($prev_cid == $cid) {
296 foreach ($row as $colName => $colVal) {
297 if (in_array($colName, $this->_noRepeats
)) {
298 unset($rows[$rowNum][$colName]);
307 //handle the Financial Type Ids
308 if (array_key_exists('civicrm_pledge_financial_type_id', $row)) {
309 if ($value = $row['civicrm_pledge_financial_type_id']) {
310 $rows[$rowNum]['civicrm_pledge_financial_type_id'] =
311 CRM_Contribute_PseudoConstant
::financialType($value, false);
316 //handle the Status Ids
317 if (array_key_exists('civicrm_pledge_status_id', $row)) {
318 if ($value = $row['civicrm_pledge_status_id']) {
319 $rows[$rowNum]['civicrm_pledge_status_id'] = CRM_Contribute_PseudoConstant
::contributionStatus($value);
324 // handle state province
325 if (array_key_exists('civicrm_address_state_province_id', $row)) {
326 if ($value = $row['civicrm_address_state_province_id']) {
327 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($value, FALSE);
333 if (array_key_exists('civicrm_address_country_id', $row)) {
334 if ($value = $row['civicrm_address_country_id']) {
335 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value, FALSE);
340 // convert display name to links
341 if (array_key_exists('civicrm_contact_sort_name', $row) &&
342 array_key_exists('civicrm_contact_id', $row)
344 $url = CRM_Report_Utils_Report
::getNextUrl('pledge/summary',
345 'reset=1&force=1&id_op=eq&id_value=' .
346 $row['civicrm_contact_id'],
347 $this->_absoluteUrl
, $this->_id
, $this->_drilldownReport
349 $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
350 $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Pledge Details for this contact");
354 // skip looking further in rows, if first row itself doesn't
355 // have the column we need