Merge pull request #4093 from yashodha/CRM-15219
authorYashodha Chaku <yashodha.chaku@webaccess.co.in>
Wed, 10 Sep 2014 06:38:46 +0000 (12:08 +0530)
committerYashodha Chaku <yashodha.chaku@webaccess.co.in>
Wed, 10 Sep 2014 06:38:46 +0000 (12:08 +0530)
CRM-15219: fixed import of activity date

CRM/Member/BAO/Membership.php
CRM/Report/Form/ActivitySummary.php
CRM/Report/Form/Event/IncomeCountSummary.php
tests/phpunit/api/v3/ReportTemplateTest.php

index 3ce24572f08bbb6caebbde99b1bdf7a64974393b..3ba09975e33010a3b4c4cdcb4dd62d9ddfe8b388 100644 (file)
@@ -1315,7 +1315,7 @@ AND civicrm_membership.is_test = %2";
       $form->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
     }
     //@todo it should no longer be possible for it to get to this point & membership to not be an array
-    if (is_array($membershipTypeIDs)) {
+    if (is_array($membershipTypeIDs) && !empty($membershipContributionID)) {
       $typesTerms = CRM_Utils_Array::value('types_terms', $membershipParams, array());
       foreach ($membershipTypeIDs as $memType) {
         $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1);
index f77c37475852cb00342d4dd2a132d0e3c801e22d..038ae0ca1f7048ee298697ebb2bd6ff39d23bd3a 100644 (file)
@@ -46,137 +46,122 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
    */
   function __construct() {
     $this->_columns = array(
-      'civicrm_contact' =>
-      array(
+      'civicrm_contact' => array(
         'dao' => 'CRM_Contact_DAO_Contact',
-        'fields' =>
-        array(
-          'id' =>
-          array(
+        'fields' => array(
+          'id' => array(
             'required' => TRUE,
             'no_display' => TRUE,
           ),
-          'sort_name' =>
-          array('title' => ts('Contact Name'),
+          'sort_name' => array(
+            'title' => ts('Contact Name'),
             'default' => TRUE,
             'no_repeat' => TRUE,
           ),
         ),
-        'filters' =>
-        array(
-          'sort_name' =>
-          array('title' => ts('Contact Name'),
+        'filters' => array(
+          'sort_name' => array(
+            'title' => ts('Contact Name'),
           ),
         ),
-        'group_bys' =>
-        array(
-          'sort_name' =>
-          array(
+        'group_bys' => array(
+          'sort_name' => array(
             'name' => 'id',
             'title' => ts('Contact'),
             'default' => TRUE,
           ),
         ),
-        'order_bys' =>
-        array(
-          'sort_name' =>
-          array('title' => ts('Contact Name')),
+        'order_bys' => array(
+          'sort_name' => array(
+            'title' => ts('Contact Name')
+          ),
         ),
         'grouping' => 'contact-fields',
       ),
-      'civicrm_email' =>
-      array(
+      'civicrm_email' => array(
         'dao' => 'CRM_Core_DAO_Email',
-        'fields' =>
-        array(
-          'email' =>
-          array(
+        'fields' => array(
+          'email' => array(
             'title' => 'Email',
             'default' => TRUE,
           ),
         ),
-        'order_bys' =>
-        array(
-          'email' =>
-          array('title' => ts('Email')),
+        'order_bys' => array(
+          'email' => array(
+            'title' => ts('Email')
+          ),
         ),
         'grouping' => 'contact-fields',
       ),
-      'civicrm_phone' =>
-      array(
+      'civicrm_phone' => array(
         'dao' => 'CRM_Core_DAO_Email',
-        'fields' =>
-        array(
-          'phone' =>
-          array('title' => 'Phone'),
+        'fields' => array(
+          'phone' => array(
+            'title' => 'Phone'
+          ),
         ),
         'grouping' => 'contact-fields',
       ),
-      'civicrm_activity' =>
-      array(
+      'civicrm_activity' => array(
         'dao' => 'CRM_Activity_DAO_Activity',
-        'fields' =>
-        array(
-          'activity_type_id' =>
-          array('title' => ts('Activity Type'),
+        'fields' => array(
+          'activity_type_id' => array(
+            'title' => ts('Activity Type'),
             'default' => TRUE,
             'type' => CRM_Utils_Type::T_STRING,
           ),
-          'duration' =>
-          array(
+          'duration' => array(
             'title' => 'Duration',
-            'statistics' =>
-            array(
+            'statistics' => array(
               'sum' => ts('Total Duration'),
             ),
           ),
-          'id' =>
-          array(
+          'id' => array(
             'title' => 'Total Activities',
             'required' => TRUE,
-            'statistics' =>
-            array(
+            'statistics' => array(
               'count' => ts('Activity Count'),
             ),
           ),
         ),
-        'filters' =>
-        array(
-          'activity_date_time' =>
-          array('operatorType' => CRM_Report_Form::OP_DATE),
-          'activity_type_id' =>
-          array('title' => ts('Activity Type'),
+        'filters' => array(
+          'activity_date_time' => array(
+            'operatorType' => CRM_Report_Form::OP_DATE
+          ),
+          'activity_type_id' => array(
+            'title' => ts('Activity Type'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE),
           ),
-          'status_id' =>
-          array('title' => ts('Activity Status'),
+          'status_id' => array(
+            'title' => ts('Activity Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::activityStatus(),
           ),
-          'priority_id' =>
-          array('title' => ts('Priority'),
+          'priority_id' => array(
+            'title' => ts('Priority'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'),
           ),
         ),
-        'group_bys' =>
-        array(
+        'group_bys' => array(
           'activity_date_time' =>
-          array('title' => ts('Activity Date'),
-            'frequency' => TRUE,
-          ),
-          'activity_type_id' =>
-          array('title' => ts('Activity Type'),
+            array(
+              'title' => ts('Activity Date'),
+              'frequency' => TRUE,
+            ),
+          'activity_type_id' => array(
+            'title' => ts('Activity Type'),
             'default' => TRUE,
           ),
         ),
-        'order_bys' =>
-        array(
-          'activity_date_time' =>
-          array('title' => ts('Activity Date')),
-          'activity_type_id' =>
-          array('title' => ts('Activity Type')),
+        'order_bys' => array(
+          'activity_date_time' => array(
+            'title' => ts('Activity Date')
+          ),
+          'activity_type_id' => array(
+            'title' => ts('Activity Type')
+          ),
         ),
         'grouping' => 'activity-fields',
         'alias' => 'activity',
@@ -193,38 +178,37 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
       if (array_key_exists('group_bys', $table)) {
         foreach ($table['group_bys'] as $fieldName => $field) {
           if (!empty($this->_params['group_bys'][$fieldName])) {
-
-            switch (CRM_Utils_Array::value($fieldName, $this->_params['group_bys_freq'])) {
-              case 'YEARWEEK':
-                $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
-
-                $select[]       = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
-                $select[]       = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
-                $field['title'] = 'Week';
-                break;
-
-              case 'YEAR':
-                $select[]       = "MAKEDATE(YEAR({$field['dbAlias']}), 1)  AS {$tableName}_{$fieldName}_start";
-                $select[]       = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
-                $select[]       = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
-                $field['title'] = 'Year';
-                break;
-
-              case 'MONTH':
-                $select[]       = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
-                $select[]       = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
-                $select[]       = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
-                $field['title'] = 'Month';
-                break;
-
-              case 'QUARTER':
-                $select[]       = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
-                $select[]       = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
-                $select[]       = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
-                $field['title'] = 'Quarter';
-                break;
-            }
-            if (!empty($this->_params['group_bys_freq'][$fieldName])) {
+            if (isset($this->_params['group_bys_freq']) && !empty($this->_params['group_bys_freq'][$fieldName])) {
+              switch ($this->_params['group_bys_freq'][$fieldName]) {
+                case 'YEARWEEK':
+                  $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
+
+                  $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
+                  $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
+                  $field['title'] = 'Week';
+                  break;
+
+                case 'YEAR':
+                  $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1)  AS {$tableName}_{$fieldName}_start";
+                  $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
+                  $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
+                  $field['title'] = 'Year';
+                  break;
+
+                case 'MONTH':
+                  $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
+                  $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
+                  $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
+                  $field['title'] = 'Month';
+                  break;
+
+                case 'QUARTER':
+                  $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
+                  $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
+                  $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
+                  $field['title'] = 'Quarter';
+                  break;
+              }
               $this->_interval = $field['title'];
               $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
               $this->_columnHeaders["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
@@ -357,8 +341,8 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
           $clause = NULL;
           if (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);
 
             $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
           }
@@ -405,12 +389,14 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
               if (!empty($field['chart'])) {
                 $this->assign('chartSupported', TRUE);
               }
-              if (!empty($table['group_bys'][$fieldName]['frequency']) && !empty($this->_params['group_bys_freq'][$fieldName])) {
+              if (!empty($table['group_bys'][$fieldName]['frequency']) &&
+                !empty($this->_params['group_bys_freq'][$fieldName])
+              ) {
 
                 $append = "YEAR({$field['dbAlias']}),";
                 if (in_array(strtolower($this->_params['group_bys_freq'][$fieldName]),
-                    array('year')
-                  )) {
+                  array('year')
+                )) {
                   $append = '';
                 }
                 $this->_groupBy[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
@@ -481,9 +467,9 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
   function alterDisplay(&$rows) {
     // custom code to alter rows
 
-    $entryFound   = FALSE;
+    $entryFound = FALSE;
     $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
-    $flagContact  = 0;
+    $flagContact = 0;
 
     $onHover = ts('View Contact Summary for this Contact');
     foreach ($rows as $rowNum => $row) {
@@ -521,7 +507,8 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
               $this->_absoluteUrl
             );
 
-            $rows[$rowNum]['civicrm_contact_sort_name'] = "<a href='$url'>" . $row['civicrm_contact_sort_name'] . '</a>';
+            $rows[$rowNum]['civicrm_contact_sort_name'] = "<a href='$url'>" . $row['civicrm_contact_sort_name'] .
+              '</a>';
           }
           $entryFound = TRUE;
         }
index cd3ba9a4055b131ed0565daa84ea27f5aab98e13..4876c915ea4fba068dd9367b40adf6de599e30e0 100644 (file)
@@ -45,7 +45,8 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
   protected $_add2groupSupported = FALSE;
 
   protected $_customGroupExtends = array(
-    'Event');
+    'Event'
+  );
 
   public $_drilldownReport = array('event/participantlist' => 'Link to Detail Report');
 
@@ -58,31 +59,36 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
   function __construct() {
 
     $this->_columns = array(
-      'civicrm_event' =>
-      array(
+      'civicrm_event' => array(
         'dao' => 'CRM_Event_DAO_Event',
-        'fields' =>
-        array(
-          'title' => array('title' => ts('Event'),
+        'fields' => array(
+          'title' => array(
+            'title' => ts('Event'),
             'required' => TRUE,
           ),
           'id' => array(
+            'title' => 'Event ID',
             'no_display' => TRUE,
             'required' => TRUE,
           ),
-          'event_type_id' => array('title' => ts('Event Type'),
+          'event_type_id' => array(
+            'title' => ts('Event Type'),
+          ),
+          'fee_label' => array(
+            'title' => ts('Fee Label')
           ),
-          'fee_label' => array('title' => ts('Fee Label')),
-          'event_start_date' => array('title' => ts('Event Start Date'),
+          'event_start_date' => array(
+            'title' => ts('Event Start Date'),
           ),
-          'event_end_date' => array('title' => ts('Event End Date'),
+          'event_end_date' => array(
+            'title' => ts('Event End Date'),
           ),
-          'max_participants' => array('title' => ts('Capacity'),
+          'max_participants' => array(
+            'title' => ts('Capacity'),
             'type' => CRM_Utils_Type::T_INT,
           ),
         ),
-        'filters' =>
-        array(
+        'filters' => array(
           'id' => array(
             'title' => ts('Event'),
             'operatorType' => CRM_Report_Form::OP_ENTITYREF,
@@ -95,43 +101,44 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Core_OptionGroup::values('event_type'),
           ),
-          'event_start_date' => array('title' => ts('Event Start Date'),
+          'event_start_date' => array(
+            'title' => ts('Event Start Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
           ),
-          'event_end_date' => array('title' => ts('Event End Date'),
+          'event_end_date' => array(
+            'title' => ts('Event End Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
           ),
         ),
       ),
-      'civicrm_line_item' =>
-      array(
+      'civicrm_line_item' => array(
         'dao' => 'CRM_Price_DAO_LineItem',
-        'fields' =>
-        array(
+        'fields' => array(
           'participant_count' => array(
             'title' => ts('Participants'),
             'default' => TRUE,
             'statistics' =>
-            array('count' => ts('Participants'),
-            ),
+              array(
+                'count' => ts('Participants'),
+              ),
           ),
           'line_total' => array(
             'title' => ts('Income Statistics'),
             'type' => CRM_Utils_Type::T_MONEY,
             'default' => TRUE,
             'statistics' =>
-            array('sum' => ts('Income'),
-              'avg' => ts('Average'),
-            ),
+              array(
+                'sum' => ts('Income'),
+                'avg' => ts('Average'),
+              ),
           ),
         ),
       ),
-      'civicrm_participant' =>
-      array(
+      'civicrm_participant' => array(
         'dao' => 'CRM_Event_DAO_Participant',
-        'filters' =>
-        array(
-          'sid' => array('name' => 'status_id',
+        'filters' => array(
+          'sid' => array(
+            'name' => 'status_id',
             'title' => ts('Participant Status'),
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Event_PseudoConstant::participantStatus(),
@@ -142,7 +149,8 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
             'operatorType' => CRM_Report_Form::OP_MULTISELECT,
             'options' => CRM_Event_PseudoConstant::participantRole(),
           ),
-          'participant_register_date' => array('title' => ts('Registration Date'),
+          'participant_register_date' => array(
+            'title' => ts('Registration Date'),
             'operatorType' => CRM_Report_Form::OP_DATE,
           ),
         ),
@@ -220,8 +228,8 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
           $clause = NULL;
           if (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']);
@@ -268,6 +276,7 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
     $dao = CRM_Core_DAO::executeQuery($sql);
 
     if ($dao->fetch()) {
+      $avg = 0;
       if ($dao->count && $dao->amount) {
         $avg = $dao->amount / $dao->count;
       }
@@ -281,7 +290,7 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
         'title' => 'Total Income',
         'type' => CRM_Utils_Type::T_MONEY,
       );
-      $statistics['counts']['avg   '] = array(
+      $statistics['counts']['avg'] = array(
         'value' => $avg,
         'title' => 'Average',
         'type' => CRM_Utils_Type::T_MONEY,
@@ -356,7 +365,8 @@ class CRM_Report_Form_Event_IncomeCountSummary extends CRM_Report_Form_Event {
       foreach ($rows as $key => $value) {
         if ($value['civicrm_event_id']) {
           $graphRows['totalParticipants'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
-          $graphRows[$this->_interval][] = substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
+          $graphRows[$this->_interval][] =
+            substr($rows[$key]['civicrm_event_title'], 0, 12) . "..(" . $rows[$key]['civicrm_event_id'] . ") ";
           $graphRows['value'][] = ($rows[$key]['civicrm_line_item_participant_count_count']);
         }
       }
index 355080c602293317031dbb769ead1e5bd70d9507..5ed5c0ae8bc888fd028740b3b831b01824e1388c 100644 (file)
@@ -181,8 +181,6 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
         'contribute/lybunt' => 'same as sybunt - fatals on force url & test identifies why',
         'event/income' => 'I do no understant why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120',
         'contact/relationship' => '(see contribute/repeat), property declaration issue, Undefined property: CRM_Report_Form_Contact_Relationship::$relationType in /Contact/Relationship.php(486):',
-        'activitySummary' => 'Undefined index: group_bys_freq m/ActivitySummary.php(191)',
-        'event/incomesummary' => 'Undefined index: title, Report/Form/Event/IncomeCountSummary.php(187)',
         'logging/contact/summary' => '(likely to be test releated) probably logging off Undefined index: Form/Contact/LoggingSummary.php(231): PHP',
         'logging/contact/detail' => '(likely to be test releated) probably logging off  DB Error: no such table',
         'logging/contribute/summary' => '(likely to be test releated) probably logging off DB Error: no such table',