Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ready-for-core-team-review]CRM-19288, fixed civicrm_contribution.tax_amount value for multiple p… #9545

Merged
merged 2 commits into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public function postProcess() {
$this->set('finalAmount', $this->_amount);
}
$participantCount = array();
$taxAmount = $totalTaxAmount = 0;

//unset the skip participant from params.
//build the $participantCount array.
Expand All @@ -442,7 +443,10 @@ public function postProcess() {
elseif ($participantNum) {
$participantCount[$participantNum] = 'participant';
}

$totalTaxAmount += CRM_Utils_Array::value('tax_amount', $record, 0);
if (CRM_Utils_Array::value('is_primary', $record)) {
$taxAmount = &$params[$participantNum]['tax_amount'];
}
//lets get additional participant id to cancel.
if ($this->_allowConfirmation && is_array($cancelledIds)) {
$additonalId = CRM_Utils_Array::value('participant_id', $record);
Expand All @@ -451,7 +455,7 @@ public function postProcess() {
}
}
}

$taxAmount = $totalTaxAmount;
$payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
$paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');

Expand Down Expand Up @@ -1290,9 +1294,11 @@ public static function testSubmit($params) {
$_REQUEST['id'] = $form->_eventId = $params['id'];
$form->controller = new CRM_Event_Controller_Registration();
$form->_params = $params['params'];
$form->_amount = $form->_totalAmount = CRM_Utils_Array::value('totalAmount', $params);
$form->set('params', $params['params']);
$form->_values['custom_pre_id'] = array();
$form->_values['custom_post_id'] = array();
$form->_values['event'] = CRM_Utils_Array::value('event', $params);
$form->_contributeMode = $params['contributeMode'];
$eventParams = array('id' => $params['id']);
CRM_Event_BAO_Event::retrieve($eventParams, $form->_values['event']);
Expand Down
86 changes: 86 additions & 0 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,90 @@ public function testSubmit() {
$this->callAPISuccessGetSingle('Participant', array());
}

/**
* Test for Tax amount for multiple participant.
*
* @throws \Exception
*/
public function testTaxMultipleParticipant() {
$params = array('is_monetary' => 1, 'financial_type_id' => 1);
$event = $this->eventCreate($params);
CRM_Event_Form_Registration_Confirm::testSubmit(array(
'id' => $event['id'],
'contributeMode' => 'direct',
'registerByID' => $this->createLoggedInUser(),
'totalAmount' => 440,
'event' => reset($event['values']),
'params' => array(
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant1',
'last_name' => 'LastName',
'email-Primary' => 'participant1@example.com',
'scriptFee' => '',
'scriptArray' => '',
'additional_participants' => 2,
'payment_processor_id' => 0,
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'is_primary' => 1,
'is_pay_later' => 1,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '100.00',
'tax_amount' => 10,
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'trxn_id' => '123456789',
'button' => '_qf_Register_upload',
),
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant2',
'last_name' => 'LastName',
'email-Primary' => 'participant2@example.com',
'scriptFee' => '',
'scriptArray' => '',
'campaign_id' => NULL,
'is_pay_later' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 9-18) - 1',
'amount' => '200.00',
'tax_amount' => 20,
),
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
'first_name' => 'Participant3',
'last_name' => 'LastName',
'email-Primary' => 'participant3@example.com',
'scriptFee' => '',
'scriptArray' => '',
'campaign_id' => NULL,
'is_pay_later' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '100.00',
'tax_amount' => 10,
),
),
));
$this->callAPISuccessGetCount('Participant', array(), 3);
$contribution = $this->callAPISuccessGetSingle(
'Contribution',
array(
'return' => array('tax_amount', 'total_amount'),
)
);
$this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
$this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
}

}