$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
$trxnId = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId, $contributionDAO->financial_type_id);
- $trxnId = $trxnId['trxn_id'];
+ if (!empty($trxnId)) {
+ $trxnId = $trxnId['trxn_id'];
+ }
+ elseif (!empty($contributionDAO->payment_instrument_id)) {
+ $trxnId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contributionDAO->payment_instrument_id);
+ }
+ else {
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' "));
+ $queryParams = array(1 => array($relationTypeId, 'Integer'));
+ $trxnId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams);
+ }
// update statuses
// criteria for updates contribution total_amount == financial_trxns of partial_payments
// update statuses
if ($contributionDAO->total_amount == $sumOfPayments) {
- // update contribution status
- $contributionUpdate['id'] = $contributionId;
- $contributionUpdate['contribution_status_id'] = $statusId;
- $contributionUpdate['skipLineItem'] = TRUE;
+ // update contribution status and
+ // clean cancel info (if any) if prev. contribution was updated in case of 'Refunded' => 'Completed'
+ $contributionDAO->contribution_status_id = $statusId;
+ $contributionDAO->cancel_date = 'null';
+ $contributionDAO->cancel_reason = NULL;
+ $contributionDAO->save();
+
+ //Change status of financial record too
+ $financialTrxn->status_id = $statusId;
+ $financialTrxn->save();
+
// note : not using the self::add method,
// the reason because it performs 'status change' related code execution for financial records
// which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
- $contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
if ($participantId) {
// update participant status
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
+ $completedStatusId = array_search('Completed', $contributionStatuses);
+
+ $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
if ($balanceAmt) {
if ($balanceAmt > 0 && $paidAmount != 0) {
elseif ($balanceAmt < 0 && $paidAmount != 0) {
$contributionStatusVal = $pendngRefundStatusId;
}
+ elseif ($paidAmount == 0) {
+ $contributionStatusVal = $completedStatusId;
+ $updatedContributionDAO->cancel_date = 'null';
+ $updatedContributionDAO->cancel_reason = NULL;
+ }
// update contribution status and total amount without trigger financial code
// as this is handled in current BAO function used for change selection
- $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
$updatedContributionDAO->id = $contributionId;
$updatedContributionDAO->contribution_status_id = $contributionStatusVal;
$updatedContributionDAO->total_amount = $updatedAmount;
showHideCancelInfo(cj('#contribution_status_id'));
cj('#contribution_status_id').change(function() {
- showHideCancelInfo(this);
+ showHideCancelInfo(cj('#contribution_status_id'));
}
);
});
function showHideCancelInfo(obj) {
- contributionStatus = cj(obj).val();
- if (contributionStatus == 3 || contributionStatus == 7) {
+ if (obj.find(":selected").text() == 'Refunded' || obj.find(":selected").text() == 'Cancelled') {
cj('#cancelInfo').show( );
+ cj('#total_amount').attr('readonly', true);
}
else {
- status();
+ status();
cj('#cancelInfo').hide( );
+ cj("#total_amount").removeAttr('readonly');
}
}