* @param int $contributionId
*/
public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL) {
- $balanceAmt = $updatedAmount - $paidAmount;
+ $pendingAmount = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
+ $balanceAmt = $updatedAmount - $paidAmount - CRM_Utils_Array::value('total_amount', $pendingAmount, 0);
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
$updatedContributionDAO->total_amount = $updatedAmount;
$updatedContributionDAO->tax_amount = $taxAmount;
$updatedContributionDAO->save();
-
- $ftDetail = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
+
// adjusted amount financial_trxn creation
- if (empty($ftDetail['trxn_id'])) {
- $updatedContribution = CRM_Contribute_BAO_Contribution::getValues(
- array('id' => $contributionId),
- CRM_Core_DAO::$_nullArray,
- CRM_Core_DAO::$_nullArray
- );
- $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
- $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId);
-
- $adjustedTrxnValues = array(
- 'from_financial_account_id' => NULL,
- 'to_financial_account_id' => $toFinancialAccount,
- 'total_amount' => $balanceAmt,
- 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'),
- 'payment_instrument_id' => $updatedContribution->payment_instrument_id,
- 'contribution_id' => $updatedContribution->id,
- 'trxn_date' => date('YmdHis'),
- 'currency' => $updatedContribution->currency,
- );
- $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
- }
- else {
- // update the financial trxn amount as well, as the fee selections has been updated
- if ($balanceAmt != $ftDetail['total_amount']) {
- CRM_Core_DAO::setFieldValue('CRM_Core_BAO_FinancialTrxn', $ftDetail['trxn_id'], 'total_amount', $balanceAmt);
- }
- }
+ $updatedContribution = CRM_Contribute_BAO_Contribution::getValues(
+ array('id' => $contributionId),
+ CRM_Core_DAO::$_nullArray,
+ CRM_Core_DAO::$_nullArray
+ );
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
+ $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId);
+ $adjustedTrxnValues = array(
+ 'from_financial_account_id' => NULL,
+ 'to_financial_account_id' => $toFinancialAccount,
+ 'total_amount' => $balanceAmt,
+ 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'),
+ 'payment_instrument_id' => $updatedContribution->payment_instrument_id,
+ 'contribution_id' => $updatedContribution->id,
+ 'trxn_date' => date('YmdHis'),
+ 'currency' => $updatedContribution->currency,
+ );
+ $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
}
}