X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FReport%2FForm%2FContribute%2FSybunt.php;h=3dcfffb67f74c7666dcc55ff68e636e9e0d2535c;hb=5667521530926d61b370a4bb0806b7e5ad63ccbc;hp=fcb778f592f6fc8cb19187ab5469d85b13f84f91;hpb=9c41996008a0cb938cd30d8996cdec462c6a61a7;p=civicrm-core.git diff --git a/CRM/Report/Form/Contribute/Sybunt.php b/CRM/Report/Form/Contribute/Sybunt.php index fcb778f592..3dcfffb67f 100644 --- a/CRM/Report/Form/Contribute/Sybunt.php +++ b/CRM/Report/Form/Contribute/Sybunt.php @@ -1,7 +1,7 @@ 'Link to Detail Report'); - protected $_add2groupSupported = FALSE; - - /** - * - */ /** * */ - function __construct() { - $yearsInPast = 10; + public function __construct() { + $yearsInPast = 10; $yearsInFuture = 1; - $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture); - $count = $date['maxYear']; + $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture); + $count = $date['maxYear']; while ($date['minYear'] <= $count) { $optionYear[$date['minYear']] = $date['minYear']; $date['minYear']++; @@ -69,114 +64,101 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { } $this->_columns = array( - 'civicrm_contact' => - array( - 'dao' => 'CRM_Contact_DAO_Contact', - 'grouping' => 'contact-field', - 'fields' => - array( - 'sort_name' => - array('title' => ts('Donor Name'), - 'required' => TRUE, - ), - 'first_name' => array( - 'title' => ts('First Name'), - ), - 'last_name' => array( - 'title' => ts('Last Name'), + 'civicrm_contact' => array( + 'dao' => 'CRM_Contact_DAO_Contact', + 'grouping' => 'contact-field', + 'fields' => array( + 'sort_name' => array( + 'title' => ts('Donor Name'), + 'required' => TRUE, + ), + 'first_name' => array( + 'title' => ts('First Name'), + ), + 'last_name' => array( + 'title' => ts('Last Name'), + ), + 'contact_type' => array( + 'title' => ts('Contact Type'), + ), + 'contact_sub_type' => array( + 'title' => ts('Contact Subtype'), + ), ), - 'contact_type' => - array( - 'title' => ts('Contact Type'), - ), - 'contact_sub_type' => - array( - 'title' => ts('Contact SubType'), - ), - ), - 'filters' => - array( - 'sort_name' => - array('title' => ts('Donor Name'), - 'operator' => 'like', - ), - ), - ), - 'civicrm_email' => - array( - 'dao' => 'CRM_Core_DAO_Email', - 'grouping' => 'contact-field', - 'fields' => - array( - 'email' => - array('title' => ts('Email'), - 'default' => TRUE, + 'filters' => array( + 'sort_name' => array( + 'title' => ts('Donor Name'), + 'operator' => 'like', + ), ), ), - ), - 'civicrm_phone' => - array( - 'dao' => 'CRM_Core_DAO_Phone', - 'grouping' => 'contact-field', - 'fields' => - array( - 'phone' => - array('title' => ts('Phone'), - 'default' => TRUE, + 'civicrm_email' => array( + 'dao' => 'CRM_Core_DAO_Email', + 'grouping' => 'contact-field', + 'fields' => array( + 'email' => array( + 'title' => ts('Email'), + 'default' => TRUE, + ), ), ), - ), - ) - + $this->addAddressFields() - + array( - 'civicrm_contribution' => - array( - 'dao' => 'CRM_Contribute_DAO_Contribution', - 'fields' => - array( - 'contact_id' => - array('title' => ts('contactId'), - 'no_display' => TRUE, - 'required' => TRUE, - 'no_repeat' => TRUE, - ), - 'total_amount' => - array('title' => ts('Total Amount'), - 'no_display' => TRUE, - 'required' => TRUE, - 'no_repeat' => TRUE, - ), - 'receive_date' => - array('title' => ts('Year'), - 'no_display' => TRUE, - 'required' => TRUE, - 'no_repeat' => TRUE, + 'civicrm_phone' => array( + 'dao' => 'CRM_Core_DAO_Phone', + 'grouping' => 'contact-field', + 'fields' => array( + 'phone' => array( + 'title' => ts('Phone'), + 'default' => TRUE, + ), ), ), - 'filters' => - array( - 'yid' => - array( - 'name' => 'receive_date', - 'title' => ts('This Year'), - 'operatorType' => CRM_Report_Form::OP_SELECT, - 'options' => $optionYear, - 'default' => date('Y'), - ), - 'financial_type_id' => - array('title' => ts('Financial Type'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Contribute_PseudoConstant::financialType(), + ) + + $this->addAddressFields() + + array( + 'civicrm_contribution' => array( + 'dao' => 'CRM_Contribute_DAO_Contribution', + 'fields' => array( + 'contact_id' => array( + 'title' => ts('contactId'), + 'no_display' => TRUE, + 'required' => TRUE, + 'no_repeat' => TRUE, + ), + 'total_amount' => array( + 'title' => ts('Total Amount'), + 'no_display' => TRUE, + 'required' => TRUE, + 'no_repeat' => TRUE, + ), + 'receive_date' => array( + 'title' => ts('Year'), + 'no_display' => TRUE, + 'required' => TRUE, + 'no_repeat' => TRUE, + ), ), - 'contribution_status_id' => - array('title' => ts('Contribution Status'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), - 'default' => array('1'), + 'filters' => array( + 'yid' => array( + 'name' => 'receive_date', + 'title' => ts('This Year'), + 'operatorType' => CRM_Report_Form::OP_SELECT, + 'options' => $optionYear, + 'default' => date('Y'), + ), + 'financial_type_id' => array( + 'title' => ts('Financial Type'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => CRM_Contribute_PseudoConstant::financialType(), + ), + 'contribution_status_id' => array( + 'title' => ts('Contribution Status'), + 'operatorType' => CRM_Report_Form::OP_MULTISELECT, + 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), + 'default' => array('1'), + ), ), ), - ), - ); + ); // If we have a campaign, build out the relevant elements if ($campaignEnabled && !empty($this->activeCampaigns)) { @@ -184,7 +166,8 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { 'title' => ts('Campaign'), 'default' => 'false', ); - $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), + $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( + 'title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns, ); @@ -195,11 +178,11 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { parent::__construct(); } - function preProcess() { + public function preProcess() { parent::preProcess(); } - function select() { + public function select() { $select = array(); $this->_columnHeaders = array(); $current_year = $this->_params['yid_value']; @@ -212,7 +195,9 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $fieldName => $field) { - if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) { + if (!empty($field['required']) || + !empty($this->_params['fields'][$fieldName]) + ) { if ($fieldName == 'total_amount') { $select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}"; @@ -232,7 +217,8 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $this->_columnHeaders["civicrm_life_time_total"]['title'] = 'LifeTime';; } elseif ($fieldName == 'receive_date') { - $select[] = self::fiscalYearOffset($field['dbAlias']) . " as {$tableName}_{$fieldName}"; + $select[] = self::fiscalYearOffset($field['dbAlias']) . + " as {$tableName}_{$fieldName}"; } else { $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}"; @@ -250,7 +236,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $this->_select = "SELECT " . implode(', ', $select) . " "; } - function from() { + public function from() { $this->_from = " FROM civicrm_contribution {$this->_aliases['civicrm_contribution']} @@ -273,7 +259,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $this->addAddressFromClause(); } - function where() { + public function where() { $this->_statusClause = ""; $clauses = array($this->_aliases['civicrm_contribution'] . '.is_test = 0'); foreach ($this->_columns as $tableName => $table) { @@ -283,12 +269,16 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { if ($fieldName == 'yid') { $clause = "contribution_civireport.contact_id NOT IN (SELECT distinct cont.id FROM civicrm_contact cont, civicrm_contribution contri - WHERE cont.id = contri.contact_id AND " . self::fiscalYearOffset('contri.receive_date') . " = {$this->_params['yid_value']} AND contri.is_test = 0 )"; + WHERE cont.id = contri.contact_id AND " . + self::fiscalYearOffset('contri.receive_date') . + " = {$this->_params['yid_value']} AND contri.is_test = 0 )"; } - elseif (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) { + elseif (CRM_Utils_Array::value('type', $field) & + CRM_Utils_Type::T_DATE + ) { $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params); - $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); - $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); + $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params); + $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params); if ($relative || $from || $to) { $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']); @@ -303,7 +293,9 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params) ); - if (($fieldName == 'contribution_status_id' || $fieldName == 'financial_type_id') && !empty($clause)) { + if (($fieldName == 'contribution_status_id' || + $fieldName == 'financial_type_id') && !empty($clause) + ) { $this->_statusClause .= " AND " . $clause; } } @@ -323,9 +315,12 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { } } - function groupBy() { + public function groupBy() { $this->assign('chartSupported', TRUE); - $this->_groupBy = "Group BY {$this->_aliases['civicrm_contribution']}.contact_id, " . self::fiscalYearOffset($this->_aliases['civicrm_contribution'] . '.receive_date') . " WITH ROLLUP "; + $this->_groupBy = + "Group BY {$this->_aliases['civicrm_contribution']}.contact_id, " . + self::fiscalYearOffset($this->_aliases['civicrm_contribution'] . + '.receive_date') . " WITH ROLLUP "; } /** @@ -333,7 +328,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { * * @return array */ - function statistics(&$rows) { + public function statistics(&$rows) { $statistics = parent::statistics($rows); if (!empty($rows)) { @@ -354,7 +349,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { return $statistics; } - function postProcess() { + public function postProcess() { // get ready with post process params $this->beginPostProcess(); @@ -383,19 +378,22 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy}"; } else { - $sql = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . implode(',', $contactIds) . ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} "; + $sql = + "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . + implode(',', $contactIds) . + ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} "; } - $current_year = $this->_params['yid_value']; - $previous_year = $current_year - 1; - $previous_pyear = $current_year - 2; + $current_year = $this->_params['yid_value']; + $previous_year = $current_year - 1; + $previous_pyear = $current_year - 2; $previous_ppyear = $current_year - 3; - $upTo_year = $current_year - 4; + $upTo_year = $current_year - 4; - $rows = $row = array(); - $dao = CRM_Core_DAO::executeQuery($sql); + $rows = $row = array(); + $dao = CRM_Core_DAO::executeQuery($sql); $contributionSum = 0; - $yearcal = array(); + $yearcal = array(); while ($dao->fetch()) { if (!$dao->civicrm_contribution_contact_id) { continue; @@ -414,8 +412,10 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { } else { $rows[$dao->civicrm_contribution_contact_id]['civicrm_life_time_total'] = $dao->civicrm_contribution_total_amount; - if (($dao->civicrm_contribution_total_amount - $contributionSum) > 0) { - $rows[$dao->civicrm_contribution_contact_id]["civicrm_upto_{$upTo_year}"] = $dao->civicrm_contribution_total_amount - $contributionSum; + if (($dao->civicrm_contribution_total_amount - $contributionSum) > 0 + ) { + $rows[$dao->civicrm_contribution_contact_id]["civicrm_upto_{$upTo_year}"] = + $dao->civicrm_contribution_total_amount - $contributionSum; } $contributionSum = 0; } @@ -435,14 +435,14 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { /** * @param $rows */ - function buildChart(&$rows) { - $graphRows = array(); - $count = 0; - $current_year = $this->_params['yid_value']; - $previous_year = $current_year - 1; - $previous_two_year = $current_year - 2; + public function buildChart(&$rows) { + $graphRows = array(); + $count = 0; + $current_year = $this->_params['yid_value']; + $previous_year = $current_year - 1; + $previous_two_year = $current_year - 2; $previous_three_year = $current_year - 3; - $upto = $current_year - 4; + $upto = $current_year - 4; $interval[$previous_year] = $previous_year; $interval[$previous_two_year] = $previous_two_year; @@ -450,15 +450,23 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { $interval["upto_{$upto}"] = "Up To {$upto}"; foreach ($rows as $key => $row) { - $display["upto_{$upto}"] = CRM_Utils_Array::value("upto_{$upto}", $display) + CRM_Utils_Array::value("civicrm_upto_{$upto}", $row); - $display[$previous_year] = CRM_Utils_Array::value($previous_year, $display) + CRM_Utils_Array::value($previous_year, $row); - $display[$previous_two_year] = CRM_Utils_Array::value($previous_two_year, $display) + CRM_Utils_Array::value($previous_two_year, $row); - $display[$previous_three_year] = CRM_Utils_Array::value($previous_three_year, $display) + CRM_Utils_Array::value($previous_three_year, $row); + $display["upto_{$upto}"] = + CRM_Utils_Array::value("upto_{$upto}", $display) + + CRM_Utils_Array::value("civicrm_upto_{$upto}", $row); + $display[$previous_year] = + CRM_Utils_Array::value($previous_year, $display) + + CRM_Utils_Array::value($previous_year, $row); + $display[$previous_two_year] = + CRM_Utils_Array::value($previous_two_year, $display) + + CRM_Utils_Array::value($previous_two_year, $row); + $display[$previous_three_year] = + CRM_Utils_Array::value($previous_three_year, $display) + + CRM_Utils_Array::value($previous_three_year, $row); } $graphRows['value'] = $display; - $config = CRM_Core_Config::Singleton(); - $chartInfo = array( + $config = CRM_Core_Config::Singleton(); + $chartInfo = array( 'legend' => 'Sybunt Report', 'xname' => 'Year', 'yname' => "Amount ({$config->defaultCurrency})", @@ -473,7 +481,7 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { /** * @param $rows */ - function alterDisplay(&$rows) { + public function alterDisplay(&$rows) { // custom code to alter rows $entryFound = FALSE; @@ -483,7 +491,8 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { array_key_exists('civicrm_contribution_contact_id', $row) ) { $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', - 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contribution_contact_id'], + 'reset=1&force=1&id_op=eq&id_value=' . + $row['civicrm_contribution_contact_id'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport ); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; @@ -516,11 +525,13 @@ class CRM_Report_Form_Contribute_Sybunt extends CRM_Report_Form { * * @return array */ - function getOperationPair($type = "string", $fieldName = NULL) { + public function getOperationPair($type = "string", $fieldName = NULL) { if ($fieldName == 'yid') { - return array('calendar' => ts('Is Calendar Year'), 'fiscal' => ts('Fiscal Year Starting')); + return array( + 'calendar' => ts('Is Calendar Year'), + 'fiscal' => ts('Fiscal Year Starting') + ); } return parent::getOperationPair($type, $fieldName); } } -