From ae53df5f7a6953d4ccb84dd7ea39c64ec4cf1f85 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Sun, 20 Apr 2014 11:38:55 +0530 Subject: [PATCH] CRM-13973-comment : fee amount block fix for change selection and edit/view particpant --- CRM/Contribute/BAO/Contribution.php | 19 +++++++- CRM/Event/Form/ParticipantFeeSelection.php | 18 ++++++++ CRM/Price/BAO/LineItem.php | 6 +-- .../Event/Form/ParticipantFeeSelection.tpl | 43 +++++++++++-------- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 5e9bca255d..84a18d6a68 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3163,6 +3163,13 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) $entity = 'participant'; $entityTable = 'civicrm_participant'; $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); + + if (!$contributionId) { + if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $id, 'registered_by_id')) { + $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id'); + $id = $primaryParticipantId; + } + } } $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); $baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL; @@ -3176,7 +3183,17 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) $isBalance = FALSE; } if (empty($total) || $usingLineTotal) { - $total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable); + // for additional participants + if ($entityTable == 'civicrm_participant') { + $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); + $total = 0; + foreach ($ids as $val) { + $total += CRM_Price_BAO_LineItem::getLineTotal($val, $entityTable); + } + } + else { + $total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable); + } } else { $baseTrxnId = $total['trxn_id']; diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index 72253cb29e..abc6018588 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -77,6 +77,12 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId); $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id'); + if (!$this->_contributionId) { + if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'registered_by_id')) { + $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id'); + } + } + if ($this->_contributionId) { $this->_isPaidEvent = TRUE; } @@ -98,6 +104,18 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { $this->assign('paymentInfo', $paymentInfo); $this->assign('feePaid', $this->_paidAmount); + $ids = CRM_Event_BAO_Participant::getParticipantIds($this->_contributionId); + if (count($ids) > 1) { + $total = 0; + foreach ($ids as $val) { + $total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant'); + } + $this->assign('totalLineTotal', $total); + + $lineItemTotal = CRM_Price_BAO_LineItem::getLineTotal($this->_participantId, 'civicrm_participant'); + $this->assign('lineItemTotal', $lineItemTotal); + } + $title = "Change selections for {$this->_contributorDisplayName}"; if ($title) { CRM_Utils_System::setTitle(ts('%1', array(1 => $title))); diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 1a279543ff..a487536b58 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -95,9 +95,9 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { static function getLineTotal($entityId, $entityTable) { $sqlLineItemTotal = "SELECT SUM(li.line_total) FROM civicrm_line_item li -INNER JOIN civicrm_participant_payment pp ON ( li.entity_id = pp.participant_id -AND li.entity_table = '{$entityTable}' -AND li.entity_id = {$entityId})"; +WHERE li.entity_table = '{$entityTable}' +AND li.entity_id = {$entityId} +"; $lineItemTotal = CRM_Core_DAO::singleValueQuery($sqlLineItemTotal); return $lineItemTotal; } diff --git a/templates/CRM/Event/Form/ParticipantFeeSelection.tpl b/templates/CRM/Event/Form/ParticipantFeeSelection.tpl index 8b862babc8..3a8b50787d 100644 --- a/templates/CRM/Event/Form/ParticipantFeeSelection.tpl +++ b/templates/CRM/Event/Form/ParticipantFeeSelection.tpl @@ -40,18 +40,34 @@ function display(totalfee) { // populate the balance amount div // change the status selections according to updated selections - populatebalanceFee(totalfee); + populatebalanceFee(totalfee, false); } -function populatebalanceFee(updatedAmt) { +function populatebalanceFee(updatedAmt, onlyStatusUpdate) { + // updatedAmt is: selected line total + // assign statuses var partiallyPaid = {/literal}{$partiallyPaid}{literal}; var pendingRefund = {/literal}{$pendingRefund}{literal}; var participantStatus = {/literal}{$participantStatus}{literal}; + + // fee actually paid var feePaid = {/literal}{$feePaid}{literal}; + var updatedTotalLineTotal = updatedAmt; + + {/literal}{if $totalLineTotal}{literal} + // line total of current participant stored in DB + var linetotal = {/literal}{$lineItemTotal}{literal}; + + // line total of all the participants + var totalLineTotal = {/literal}{$totalLineTotal}{literal}; + updatedTotalLineTotal = totalLineTotal + (updatedAmt - linetotal); + {/literal}{/if}{literal} + // calculate the balance amount using total paid and updated amount - var balanceAmt = updatedAmt - feePaid; + var balanceAmt = updatedTotalLineTotal - feePaid; + // change the status selections according to updated selections if (balanceAmt > 0) { cj('#status_id').val(partiallyPaid); @@ -63,28 +79,17 @@ function populatebalanceFee(updatedAmt) { cj('#status_id').val(participantStatus); } - balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker); - cj('#balance-fee').text(symbol+" "+balanceAmt); + if (!onlyStatusUpdate) { + balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker); + cj('#balance-fee').text(symbol+" "+balanceAmt); + } } CRM.$(function($) { - // assign statuses - var partiallyPaid = {/literal}{$partiallyPaid}{literal}; - var pendingRefund = {/literal}{$pendingRefund}{literal}; - var participantStatus = {/literal}{$participantStatus}{literal}; - var feePaid = {/literal}{$feePaid}{literal}; - var updatedFeeUnFormatted = cj('#pricevalue').text(); var updatedAmt = parseFloat(updatedFeeUnFormatted.replace(/[^0-9-.]/g, '')); - var balanceAmt = updatedAmt - feePaid; - // change the status selections according to updated selections - if (balanceAmt > 0) { - cj('#status_id').val(partiallyPaid); - } - else if(balanceAmt < 0) { - cj('#status_id').val(pendingRefund); - } + populatebalanceFee(updatedAmt, true); }); {/literal} -- 2.25.1