From f6bae84fe290bb2a9374f04f16fcd1ad76690ae0 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Thu, 6 Mar 2014 10:10:47 +0530 Subject: [PATCH] CRM-13965-qa-fixes : some major improvements and #5 issue fix mentioned in comment by dgg after the initial QA round --- CRM/Event/BAO/Participant.php | 29 ++++++++++++++++-- CRM/Event/Form/Participant.php | 38 ++++++++++++++---------- CRM/Financial/BAO/FinancialItem.php | 2 +- templates/CRM/Event/Form/Participant.tpl | 4 +++ 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 00122d6b588f..4795ef0a01b0 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -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) { @@ -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, @@ -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) { diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 0d474fad715e..975e40159c20 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -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); @@ -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 @@ -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(); @@ -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']; } @@ -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 && @@ -1751,5 +1760,4 @@ public function postProcess() { )); } } -} - +} \ No newline at end of file diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 349fb2ebe43e..b15507d19c83 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -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); } diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index 55d022540e6d..1df9af497d5a 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -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();