Merge pull request #9606 from yashodha/CRM-19783
authorYashodha Chaku <yashodha.chaku@webaccessglobal.com>
Mon, 2 Jan 2017 10:00:14 +0000 (15:30 +0530)
committerGitHub <noreply@github.com>
Mon, 2 Jan 2017 10:00:14 +0000 (15:30 +0530)
CRM-19783 - Accessibility Error - CiviCRM Subscription Page

CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/Contribution.php
CRM/Core/BAO/CMSUser.php
CRM/Core/Payment/PayflowPro.php
CRM/Event/Form/ManageEvent/Location.php
CRM/Event/Page/ParticipantListing/Name.php
tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
tests/phpunit/api/v3/MembershipTest.php

index 7e20ab4e5559a07d1dd24887062fff4cfb4bfbf4..301e98a39feaed557c4449e3a06c66c959d38fba 100644 (file)
@@ -5360,4 +5360,20 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     return $amount;
   }
 
+  /**
+   * Calculate net amount.
+   *
+   * @param array $netAmount
+   *
+   * @param float $taxAmount
+   *
+   * @return array
+   */
+  public static function calculateNetAmount($netAmount, $taxAmount) {
+    if ($taxAmount) {
+      $netAmount -= $taxAmount;
+    }
+    return CRM_Utils_Money::format($netAmount, NULL, '%a');
+  }
+
 }
index 757073e6fec9d216644df7cc709859ab30ebf819..76a626e493a20dcbce7c1b001a12ddb177f6943b 100644 (file)
@@ -378,7 +378,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     if (isset($defaults['net_amount'])) {
-      $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
+      $defaults['net_amount'] = CRM_Contribute_BAO_Contribution::calculateNetAmount($defaults['net_amount'], CRM_Utils_Array::value('tax_amount', $defaults));
     }
 
     if ($this->_contributionType) {
@@ -970,16 +970,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
 
     if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
       $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
-      // For taxable contribution we need to deduct taxable amount from
-      // (net amount + fee amount) before comparing it with total amount
-      if (!empty($self->_values['tax_amount'])) {
-        $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($self->_id);
-        if (!(CRM_Utils_Array::value('membership', $componentDetails) ||
-            CRM_Utils_Array::value('participant', $componentDetails))
-        ) {
-          $sum = CRM_Utils_Money::format($sum - $self->_values['tax_amount'], NULL, '%a');
-        }
-      }
       if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
         $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
       }
index 88e9b40c8a8c0931d31fdd5dd87dab7ba9a13575..d8cd5921cc7028d5509d4ea53257a281c879592b 100644 (file)
@@ -196,7 +196,7 @@ class CRM_Core_BAO_CMSUser {
       }
 
       if ($emailName == NULL) {
-        $errors['_qf_default'] == ts('Could not find an email address.');
+        $errors['_qf_default'] = ts('Could not find an email address.');
         return $errors;
       }
 
index f94448c53328db2c52bf0c0b4f0199e48623b12e..a250deb845d0be2aa3d3f46ee7d2a3ac70e89bbd 100644 (file)
@@ -124,7 +124,7 @@ class CRM_Core_Payment_PayflowPro extends CRM_Core_Payment {
     );
 
     if ($params['installments'] == 1) {
-      $params['is_recur'] == FALSE;
+      $params['is_recur'] = FALSE;
     }
 
     if ($params['is_recur'] == TRUE) {
index 103ec8f2e9d945795c3dfaf39bc9ef2cdc87cb94..53150ebe1d89632042de0e834e132961150fd72a 100644 (file)
@@ -197,7 +197,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
       if (!isset($locationEvents[$this->_oldLocBlockId]) || (!$this->_oldLocBlockId)) {
         $locationEvents = array('' => ts('- select -')) + $locationEvents;
       }
-      $this->add('select', 'loc_event_id', ts('Use Location'), $locationEvents);
+      $this->add('select', 'loc_event_id', ts('Use Location'), $locationEvents, FALSE, array('class' => 'crm-select2'));
     }
     $this->addElement('advcheckbox', 'is_show_location', ts('Show Location?'));
     parent::buildQuickForm();
index c8e8c3f2741ec69dbb253c7e84ec350396900d16..4638fdde8ce272e2dc8fc2e028974f456dca90ad 100644 (file)
@@ -34,7 +34,7 @@
  */
 class CRM_Event_Page_ParticipantListing_Name extends CRM_Event_Page_ParticipantListing_Simple {
   public function preProcess() {
-    $this->_participantListingType == 'Name';
+    $this->_participantListingType = 'Name';
 
     parent::preProcess();
   }
index 0e9395417e329b42bb5062fbc47362513376afbd..54dc980092d89a80b76097e7487bda46a6cc76e4 100644 (file)
@@ -1005,4 +1005,37 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
     }
   }
 
+  /**
+   * Test calculateNetAmount.
+   */
+  public function testcalculateNetAmount() {
+    $testParams = array(
+      array(
+        'net_amount' => 100,
+        'tax_amount' => 10,
+        'expectedNetAmount' => 90,
+      ),
+      array(
+        'net_amount' => 200,
+        'tax_amount' => 0,
+        'expectedNetAmount' => 200,
+      ),
+      array(
+        'net_amount' => 300,
+        'tax_amount' => NULL,
+        'expectedNetAmount' => 300,
+      ),
+      array(
+        'net_amount' => -100,
+        'tax_amount' => 20,
+        'expectedNetAmount' => -120,
+      ),
+    );
+
+    foreach ($testParams as $params) {
+      $netAmount = CRM_Contribute_BAO_Contribution::calculateNetAmount($params['net_amount'], $params['tax_amount']);
+      $this->assertEquals($netAmount, $params['expectedNetAmount'], 'Invalid Net amount.');
+    }
+  }
+
 }
index 47be4355b9a4f488fa8ddcecdef91a3508d39c07..336e158f3257b45f6f3209f750f46d86dbefcf67 100644 (file)
@@ -1154,10 +1154,15 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $joinDate = date('Y-m-d');
     $year = date('Y');
     $startDate = date('Y-m-d', strtotime(date('Y-03-01')));
+    $rollOver = TRUE;
+    if (strtotime($startDate) > time()) {
+      $rollOver = FALSE;
+      $startDate = date('Y-m-d', strtotime(date('Y-03-01') . '- 1 year'));
+    }
     $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($this->_membershipTypeID2);
     $fixedPeriodRollover = CRM_Member_BAO_MembershipType::isDuringFixedAnnualRolloverPeriod($joinDate, $membershipTypeDetails, $year, $startDate);
     $y = 1;
-    if ($fixedPeriodRollover) {
+    if ($fixedPeriodRollover && $rollOver) {
       $y += 1;
     }