From: monishdeb Date: Wed, 2 Dec 2015 14:49:57 +0000 (+0530) Subject: CRM-16901 fix - Offline Recurring Payments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5aae2a908bb332875dc9941e5d521f31baaf7189;p=civicrm-core.git CRM-16901 fix - Offline Recurring Payments https://issues.civicrm.org/jira/browse/CRM-16901 --- diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 3edeff6beb..ac4d40faf4 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -720,13 +720,12 @@ INNER JOIN civicrm_contribution con ON ( con.id = mp.contribution_id ) } } - $form->add('hidden', 'hidden_recurringcontribution', 1); // Add field to check if payment is made for recurring contribution $recurringPaymentOptions = array( - 0 => ts(' All recurring contributions'), - 1 => ts(' Recurring contributions with at least one payment'), + 1 => ts(' All recurring contributions'), + 2 => ts(' Recurring contributions with at least one payment'), ); - $form->addRadio('contribution_recur_payment_made', ts(''), $recurringPaymentOptions, array('allowClear' => TRUE)); + $form->addRadio('contribution_recur_payment_made', NULL, $recurringPaymentOptions, array('allowClear' => TRUE)); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_start_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_end_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_modified_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 7dd498ffc0..c9597e8fca 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -519,7 +519,7 @@ class CRM_Contribute_BAO_Query { case 'contribution_recur_payment_made': $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_recur.id", 'IS NOT EMPTY'); - if ($value) { + if ($value == 2) { $query->_qill[$grouping][] = ts("Recurring contributions with at least one payment"); self::$_contribRecurPayment = TRUE; } @@ -645,7 +645,7 @@ class CRM_Contribute_BAO_Query { // 'Made payment for the recurring contributions?' is ticked yes $from = " $side JOIN civicrm_contribution_recur ON contact_a.id = civicrm_contribution_recur.contact_id "; if (self::$_contribRecurPayment == TRUE) { - $from .= " AND civicrm_contribution.contribution_recur_id = civicrm_contribution_recur.id "; + $from .= " INNER JOIN civicrm_contribution cr ON cr.contribution_recur_id = civicrm_contribution_recur.id "; } } else { diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index b55a970b67..afe13b7cee 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -3078,7 +3078,8 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND foreach ($this->_columns as $tableName => $table) { if (array_key_exists('filters', $table)) { foreach ($table['filters'] as $fieldName => $field) { - if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE && + if ((CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE || + CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_TIME) && CRM_Utils_Array::value('operatorType', $field) != CRM_Report_Form::OP_MONTH ) { diff --git a/CRM/Report/Form/Contribute/RecurSummary.php b/CRM/Report/Form/Contribute/RecurSummary.php index c066da48fc..0133db518a 100644 --- a/CRM/Report/Form/Contribute/RecurSummary.php +++ b/CRM/Report/Form/Contribute/RecurSummary.php @@ -74,8 +74,8 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { 'filters' => array( 'start_date' => array( 'title' => ts('Start Date'), - 'operatorType' => CRM_Report_Form::OP_DATE, - 'type' => CRM_Utils_Type::T_DATE, + 'operatorType' => CRM_Report_Form::OP_DATETIME, + 'type' => CRM_Utils_Type::T_TIME, ), ), ), @@ -241,15 +241,15 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { $entryFound = FALSE; - $startDateFrom = $startDateTo = ''; + $startDateFrom = CRM_Utils_Array::value("start_date_to", $this->_params); + $startDateTo = CRM_Utils_Array::value("start_date_from", $this->_params); + $startDateRelative = CRM_Utils_Array::value("start_date_relative", $this->_params); - if (isset($_POST['start_date_from']) && !empty($_POST['start_date_from'])) { - $startDateFrom = CRM_Utils_Date::processDate($_POST['start_date_from']); - } + $startedDateSql = $this->dateClause('start_date', $startDateRelative, $startDateFrom, $startDateTo); + $startedDateSql = $startedDateSql ? $startedDateSql : " ( 1 ) "; - if (isset($_POST['start_date_to']) && !empty($_POST['start_date_to'])) { - $startDateTo = CRM_Utils_Date::processDate($_POST['start_date_to']); - } + $cancelledDateSql = $this->dateClause('cancel_date', $startDateRelative, $startDateFrom, $startDateTo); + $cancelledDateSql = $cancelledDateSql ? $cancelledDateSql : " ( cancel_date IS NOT NULL ) "; $started = $cancelled = $active = $total = 0; @@ -261,13 +261,7 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { $rows[$rowNum]['civicrm_contribution_recur_cancel_date'] = 0; $rows[$rowNum]['civicrm_contribution_recur_contribution_status_id'] = 0; - $startedSql = "SELECT count(*) as count FROM civicrm_contribution_recur WHERE payment_instrument_id = $paymentInstrumentId"; - if (!empty($startDateFrom)) { - $startedSql .= " AND start_date >= '{$startDateFrom}'"; - } - if (!empty($startDateTo)) { - $startedSql .= " AND start_date <= '{$startDateTo}'"; - } + $startedSql = "SELECT count(*) as count FROM civicrm_contribution_recur WHERE payment_instrument_id = $paymentInstrumentId AND $startedDateSql "; $startedDao = CRM_Core_DAO::executeQuery($startedSql); $startedDao->fetch(); @@ -275,13 +269,7 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { $rows[$rowNum]['civicrm_contribution_recur_start_date'] = $startedDao->count; $started = $started + $startedDao->count; - $cancelledSql = "SELECT count(*) as count FROM civicrm_contribution_recur WHERE payment_instrument_id = $paymentInstrumentId"; - if (!empty($startDateFrom)) { - $cancelledSql .= " AND cancel_date >= '{$startDateFrom}'"; - } - if (!empty($startDateTo)) { - $cancelledSql .= " AND cancel_date <= '{$startDateTo}'"; - } + $cancelledSql = "SELECT count(*) as count FROM civicrm_contribution_recur WHERE payment_instrument_id = $paymentInstrumentId AND $cancelledDateSql "; $cancelledDao = CRM_Core_DAO::executeQuery($cancelledSql); $cancelledDao->fetch(); @@ -291,13 +279,17 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { $cancelled = $cancelled + $cancelledDao->count; $activeSql = "SELECT count(*) as count FROM civicrm_contribution_recur WHERE payment_instrument_id = $paymentInstrumentId"; - if (!empty($startDateFrom)) { - //$activeSql .= " AND start_date >= '{$startDateFrom}'"; - //$activeSql .= " AND end_date >= '{$startDateFrom}'"; + list($from, $to) = $this->getFromTo($startDateRelative, $startDateFrom, $startDateTo); + // To find active recurring contribution start date must be >= to start of selected date-range AND + // end date or cancel date must be >= to end of selected date-range if NOT null OR end date is null + if (!empty($from)) { + $activeSql .= " AND start_date >= '{$from}'"; } - if (!empty($startDateTo)) { - $activeSql .= " AND start_date <= '{$startDateTo}'"; - $activeSql .= " AND (end_date <= '{$startDateTo}' OR end_date IS NULL)"; + if (!empty($to)) { + $activeSql .= " AND ( + ( end_date >= '{$to}' AND end_date IS NOT NULL ) OR + ( cancel_date >= '{$to}' AND cancel_date IS NOT NULL ) OR + end_date IS NULL )"; } $activeDao = CRM_Core_DAO::executeQuery($activeSql); @@ -311,14 +303,8 @@ class CRM_Report_Form_Contribute_RecurSummary extends CRM_Report_Form { $amountSql = " SELECT SUM(cc.total_amount) as amount FROM `civicrm_contribution` cc INNER JOIN civicrm_contribution_recur cr ON (cr.id = cc.contribution_recur_id AND cr.payment_instrument_id = {$paymentInstrumentId}) - WHERE cc.contribution_status_id = 1 AND cc.is_test = 0"; - if (!empty($startDateFrom)) { - $amountSql .= " AND cc.`receive_date` >= '{$startDateFrom}'"; - } - if (!empty($startDateTo)) { - $amountSql .= " AND cc.`receive_date` <= '{$startDateTo}'"; - } - + WHERE cc.contribution_status_id = 1 AND cc.is_test = 0 AND "; + $amountSql .= str_replace("start_date", "cc.`receive_date`", $startedDateSql); $amountDao = CRM_Core_DAO::executeQuery($amountSql); $amountDao->fetch(); if ($amountDao->amount) { diff --git a/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl b/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl index 23f49337c8..a01cad2e31 100644 --- a/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl +++ b/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl @@ -83,4 +83,3 @@ -