$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
$trxnsData['total_amount'] = - $trxnsData['total_amount'];
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
+ $trxnsData['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
$trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
CRM_Activity_BAO_Activity::create($activityParams);
}
- function getPaymentInfo($id, $component, $getTrxnInfo = FALSE) {
+ function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $usingLineTotal = FALSE) {
if ($component == 'event') {
$entity = 'participant';
$entityTable = 'civicrm_participant';
$contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id');
}
$total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
- $baseTrxnId = NULL;
- if (empty($total)) {
+ $baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL;
+ if (empty($total) || $usingLineTotal) {
$total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable);
}
else {
$baseTrxnId = $total['trxn_id'];
$total = $total['total_amount'];
}
+
$paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total);
$info['total'] = $total;
$info['paid'] = $total - $paymentBalance;
function browse() {
$getTrxnInfo = $this->_context == 'transaction' ? TRUE : FALSE;
- $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, $getTrxnInfo);
+ $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, $getTrxnInfo, TRUE);
if ($this->_context == 'payment_info') {
$this->assign('paymentInfo', $paymentInfo);
}
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionFinancialTypeId, $relationTypeId);
$q = "SELECT ft.id, ft.total_amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') WHERE eft.entity_id = %1 AND ft.to_financial_account_id = %2";
+
$p[1] = array($contributionId, 'Integer');
$p[2] = array($toFinancialAccount, 'Integer');
+
$balanceAmtDAO = CRM_Core_DAO::executeQuery($q, $p);
$ret = array();
while($balanceAmtDAO->fetch()) {
if ($contributionId && $financialTypeId) {
$statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
+ $refundStatusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
+
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $relationTypeId);
LEFT JOIN civicrm_contribution c ON (eft.entity_id = c.id)
LEFT JOIN civicrm_participant_payment pp ON (pp.contribution_id = c.id)
WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFinancialAccount}
- AND ft.status_id = {$statusId}
+ AND ft.status_id IN ({$statusId}, {$refundStatusId})
";
$ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt);
$value = 0;
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event');
$this->_paidAmount = $paymentInfo['paid'];
$this->assign('paymentInfo', $paymentInfo);
- CRM_Core_Resources::singleton()->addSetting(array('feePaid' => $this->_paidAmount));
+ $this->assign('feePaid', $this->_paidAmount);
$title = "Change selections for {$this->_contributorDisplayName}";
if ($title) {
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
$statuses = CRM_Event_PseudoConstant::participantStatus();
- CRM_Core_Resources::singleton()->addSetting(array(
- 'partiallyPaid' => array_search('Partially paid', $statuses),
- 'pendingRefund' => array_search('Pending refund', $statuses),
- 'participantStatus' => $this->_participantStatus
- ));
+ $this->assign('partiallyPaid', array_search('Partially paid', $statuses));
+ $this->assign('pendingRefund', array_search('Pending refund', $statuses));
+ $this->assign('participantStatus', $this->_participantStatus);
$config = CRM_Core_Config::singleton();
$this->assign('currencySymbol', $config->defaultCurrencySymbol);
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->getButtonName('upload', 'new')) {
$session = CRM_Core_Session::singleton();
- $session->replaceUserContext(CRM_Utils_System::url('civicrm/payment/add',
+ $session->pushUserContext(CRM_Utils_System::url('civicrm/payment/add',
"reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}"
));
}
<td {$valueStyle}>
{$totalAmount|crmMoney}
</td>
+ </tr>
+ <tr>
<td {$labelStyle}>
{ts}You Paid{/ts}
</td>
<td {$valueStyle}>
{$totalPaid|crmMoney}
</td>
+ </tr>
+ <tr>
<td {$labelStyle}>
{ts}Refund Amount{/ts}
</td>
// populate the balance amount div
// change the status selections according to updated selections
- populatebalanceFee(totalEventFee);
+ populatebalanceFee(totalfee);
}
function populatebalanceFee(updatedAmt) {
+ // assign statuses
+ var partiallyPaid = {/literal}{$partiallyPaid}{literal};
+ var pendingRefund = {/literal}{$pendingRefund}{literal};
+ var participantStatus = {/literal}{$participantStatus}{literal};
+ var feePaid = {/literal}{$feePaid}{literal};
+
// calculate the balance amount using total paid and updated amount
- var balanceAmt = updatedAmt - CRM.feePaid;
+ var balanceAmt = updatedAmt - feePaid;
// change the status selections according to updated selections
if (balanceAmt > 0) {
- cj('#status_id').val(CRM.partiallyPaid);
+ cj('#status_id').val(partiallyPaid);
}
else if(balanceAmt < 0) {
- cj('#status_id').val(CRM.pendingRefund);
+ cj('#status_id').val(pendingRefund);
}
else if(balanceAmt == 0) {
- cj('#status_id').val(CRM.participantStatus);
+ cj('#status_id').val(participantStatus);
}
balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker);
}
cj(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 - CRM.feePaid;
+ var balanceAmt = updatedAmt - feePaid;
// change the status selections according to updated selections
if (balanceAmt > 0) {
- cj('#status_id').val(CRM.partiallyPaid);
+ cj('#status_id').val(partiallyPaid);
}
else if(balanceAmt < 0) {
- cj('#status_id').val(CRM.pendingRefund);
+ cj('#status_id').val(pendingRefund);
}
});
<div class='crm-section'>
<div class='label'>{ts}Updated Fee(s){/ts}</div><div id="pricevalue" class='content updated-fee'></div>
<div class='label'>{ts}Total Paid{/ts}</div>
- <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment/view" q="action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
+ <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment" q="view=transaction&action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
</div>
<div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div class='content'><strong id='balance-fee'></strong></div>
</div>
var balanceFee = cj('#balance-fee').text();
balanceFee = parseFloat(balanceFee.replace(/[^0-9-.]/g, ''));
- if (balanceFee > 0 && statusId != CRM.partiallyPaid) {
+ if (balanceFee > 0 && statusId != partiallyPaid) {
var result = confirm('Balance is owing for the updated selections. Expected participant status is \'Partially paid\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries.');
if (result == false) {
e.preventDefault();
}
}
- else if (balanceFee < 0 && statusId != CRM.pendingRefund) {
+ else if (balanceFee < 0 && statusId != pendingRefund) {
var result = confirm('Balance is overpaid for the updated selections. Expected participant status is \'Pending refund\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries');
if (result == false) {
e.preventDefault();
<td {$valueStyle}>
{$totalAmount|crmMoney}
</td>
+ </tr>
+ <tr>
<td {$labelStyle}>
{ts}You Paid{/ts}
</td>
<td {$valueStyle}>
{$totalPaid|crmMoney}
</td>
+ </tr>
+ <tr>
<td {$labelStyle}>
{ts}Refund Amount{/ts}
</td>