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');
+ }
+
}
}
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) {
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');
}
}
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;
}
);
if ($params['installments'] == 1) {
- $params['is_recur'] == FALSE;
+ $params['is_recur'] = FALSE;
}
if ($params['is_recur'] == TRUE) {
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();
*/
class CRM_Event_Page_ParticipantListing_Name extends CRM_Event_Page_ParticipantListing_Simple {
public function preProcess() {
- $this->_participantListingType == 'Name';
+ $this->_participantListingType = 'Name';
parent::preProcess();
}
}
}
+ /**
+ * 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.');
+ }
+ }
+
}
$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;
}