Skip to content

Commit

Permalink
CRM-13965-qa-fixes : some major improvements and civicrm#5 issue fix …
Browse files Browse the repository at this point in the history
…mentioned in comment by dgg after the initial QA round
  • Loading branch information
Pratik Joshi committed Mar 6, 2014
1 parent 6652666 commit f6bae84
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
29 changes: 26 additions & 3 deletions CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1829,10 +1829,21 @@ static function changeFeeSelections($params, $participantId, $contributionId, $f
// ensure entity_financial_trxn table has a linking of it.
$prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $contributionObj);
}

// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
$updatedAmount = $params['amount'];
self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId);

//activity creation
self::addActivityForSelection($participantId, 'Change Registration');
}

static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId) {
$balanceAmt = $updatedAmount - $paidAmount;
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);

if ($balanceAmt) {
if ($balanceAmt > 0) {
Expand Down Expand Up @@ -1899,6 +1910,20 @@ static function changeFeeSelections($params, $participantId, $contributionId, $f
elseif ($updatedContribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
$itemStatus = array_search('Partially paid', $financialItemStatus);
}

$financialAccountId = NULL;
if ($adjustPaymentLine->financial_type_id) {
$searchParams = array(
'entity_table' => 'civicrm_financial_type',
'entity_id' => $adjustPaymentLine->financial_type_id,
'account_relationship' => 1
);

$result = array();
CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
$financialAccountId = CRM_Utils_Array::value('financial_account_id', $result);
}

$params = array(
'transaction_date' => CRM_Utils_Date::isoToMysql($updatedContribution->receive_date),
'contact_id' => $updatedContribution->contact_id,
Expand All @@ -1908,12 +1933,10 @@ static function changeFeeSelections($params, $participantId, $contributionId, $f
'entity_id' => $adjustPaymentLine->id,
'description' => ( $adjustPaymentLine->qty != 1 ? $lineItem->qty . ' of ' : ''). ' ' . $adjustPaymentLine->label,
'status_id' => $itemStatus,
'financial_account_id' => $prevItem->financial_account_id
'financial_account_id' => $financialAccountId
);
CRM_Financial_BAO_FinancialItem::create($params, NULL, array('id' => $adjustedTrxn->id));
}
//activity creation
self::addActivityForSelection($participantId, 'Change Registration');
}

static function addActivityForSelection($participantId, $activityType) {
Expand Down
38 changes: 23 additions & 15 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,20 +841,14 @@ public function buildQuickForm() {
$this->assign('notificationStatusIds', $notificationStatusIds);

$this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
$participantStatuses = $this->addSelect('status_id', $checkCancelledJs, TRUE);
$this->addSelect('status_id', $checkCancelledJs, TRUE);

$enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
'enable_cart'
);
$pendingInCartStatusId = CRM_Utils_Array::key( "Pending in cart" , $this->_participantStatuses );
if (!$enableCart) {
$statusOptions = & $participantStatuses->_options;
foreach($statusOptions as $key =>$option){
$status_id = $option['attr']['value'];
if ($status_id == $pendingInCartStatusId) {
unset($statusOptions[$key]);
}
}
}
$pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
$this->assign('pendingInCartStatusId', $pendingInCartStatusId);
$this->assign('enableCart', $enableCart);

$this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);

Expand Down Expand Up @@ -1062,7 +1056,9 @@ public function postProcess() {

$params['fee_level'] = $params['amount_level'];
$contributionParams['total_amount'] = $params['amount'];
if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
if ($this->_quickConfig && !empty($params['total_amount']) &&
($params['status_id'] != array_search('Partially paid', $participantStatus) &&
$params['status_id'] != array_search('Pending refund', $participantStatus))) {
$params['fee_amount'] = $params['total_amount'];
} else {
//fix for CRM-3086
Expand Down Expand Up @@ -1415,6 +1411,10 @@ public function postProcess() {
$contributionParams['partial_amount_pay'] = $params['total_amount'];
}
}
elseif ($params['status_id'] == array_search('Pending refund', $participantStatus)) {
$totalPaid = $params['total_amount'];
$updatedAmt = $amountOwed;
}
if ($this->_single) {
if (empty($ids)) {
$ids = array();
Expand Down Expand Up @@ -1464,7 +1464,9 @@ public function postProcess() {
if (is_array($value) && $value != 'skip') {
foreach ($value as $lineKey => $line) {
//10117 update the line items for participants if contribution amount is recorded
if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)
if ($this->_quickConfig && !empty($params['total_amount']) &&
($params['status_id'] != array_search('Partially paid', $participantStatus) &&
$params['status_id'] != array_search('Pending refund', $participantStatus))
) {
$line['unit_price'] = $line['line_total'] = $params['total_amount'];
}
Expand All @@ -1476,6 +1478,13 @@ public function postProcess() {
}
}

// record adjusted trxn entry for refund case
if ($this->_isPaidEvent && $params['status_id'] == array_search('Pending refund', $participantStatus) &&
!empty($totalPaid) && !empty($updatedAmt)) {
$contributionDetail = $contributions[0];
$contributionId = $contributionDetail->id;
CRM_Event_BAO_Participant::recordAdjustedAmt($updatedAmt, $totalPaid, $contributionId);
}
$updateStatusMsg = NULL;
//send mail when participant status changed, CRM-4326
if ($this->_id && $this->_statusId &&
Expand Down Expand Up @@ -1751,5 +1760,4 @@ public function postProcess() {
));
}
}
}

}
2 changes: 1 addition & 1 deletion CRM/Financial/BAO/FinancialItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static function add($lineItem, $contribution) {
if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)) {
$itemStatus = array_search('Paid', $financialItemStatus);
}
elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)
elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)
|| $contribution->contribution_status_id == array_search('In Progress', $contributionStatuses)) {
$itemStatus = array_search('Unpaid', $financialItemStatus);
}
Expand Down
4 changes: 4 additions & 0 deletions templates/CRM/Event/Form/Participant.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@
var $form = $('form#{/literal}{$form.formName}{literal}');
// don't show cart related statuses if it's disabled
var pendingInCartStatusId = {/literal}{$pendingInCartStatusId}{literal};
$("#status_id option[value='" + pendingInCartStatusId + "']").remove();
// Handle event selection
$('#event_id', $form).change(function() {
var eventId = $(this).val();
Expand Down

0 comments on commit f6bae84

Please sign in to comment.