$isSkipRecordingPaymentHereForLegacyHandlingReasons = ($contributionStatus == 'Pending' && $isPaymentCompletesContribution);
if (!$isSkipRecordingPaymentHereForLegacyHandlingReasons && $params['total_amount'] > 0) {
- $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);
+ $balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_BAO_Contribution::getToFinancialAccount($contribution, $params);
+ $balanceTrxnParams['from_financial_account_id'] = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship($contribution['financial_type_id'], 'Accounts Receivable Account is');
+ $balanceTrxnParams['total_amount'] = $params['total_amount'];
+ $balanceTrxnParams['contribution_id'] = $params['contribution_id'];
+ $balanceTrxnParams['trxn_date'] = CRM_Utils_Array::value('trxn_date', $params, CRM_Utils_Array::value('contribution_receive_date', $params, date('YmdHis')));
+ $balanceTrxnParams['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params);
+ $balanceTrxnParams['net_amount'] = CRM_Utils_Array::value('total_amount', $params);
+ $balanceTrxnParams['currency'] = $contribution['currency'];
+ $balanceTrxnParams['trxn_id'] = CRM_Utils_Array::value('contribution_trxn_id', $params, NULL);
+ $balanceTrxnParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'status_id', 'Completed');
+ $balanceTrxnParams['payment_instrument_id'] = CRM_Utils_Array::value('payment_instrument_id', $params, $contribution['payment_instrument_id']);
+ $balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params);
+ $balanceTrxnParams['is_payment'] = 1;
+
+ if (!empty($params['payment_processor'])) {
+ // I can't find evidence this is passed in - I was gonna just remove it but decided to deprecate as I see getToFinancialAccount
+ // also anticipates it.
+ CRM_Core_Error::deprecatedFunctionWarning('passing payment_processor is deprecated - use payment_processor_id');
+ $balanceTrxnParams['payment_processor_id'] = $params['payment_processor'];
+ }
+ $trxn = CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams);
- if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) {
+ // @todo - this is just weird & historical & inconsistent - why 2 tracks?
+ if (!empty($params['line_item']) && !empty($trxn)) {
foreach ($params['line_item'] as $values) {
foreach ($values as $id => $amount) {
$p = ['id' => $id];
}
}
elseif (!empty($trxn)) {
- CRM_Contribute_BAO_Contribution::assignProportionalLineItems($params, $trxn->id, $contribution['total_amount']);
+ $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']);
+ if (!empty($lineItems)) {
+ // get financial item
+ list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution::getLastFinancialItemIds($params['contribution_id']);
+ $entityParams = [
+ 'contribution_total_amount' => $contribution['total_amount'],
+ 'trxn_total_amount' => $params['total_amount'],
+ 'trxn_id' => $trxn->id,
+ ];
+ $eftParams = [
+ 'entity_table' => 'civicrm_financial_item',
+ 'financial_trxn_id' => $entityParams['trxn_id'],
+ ];
+ foreach ($lineItems as $key => $value) {
+ if ($value['qty'] == 0) {
+ continue;
+ }
+ $eftParams['entity_id'] = $ftIds[$value['price_field_value_id']];
+ $entityParams['line_item_amount'] = $value['line_total'];
+ CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
+ if (array_key_exists($value['price_field_value_id'], $taxItems)) {
+ $entityParams['line_item_amount'] = $taxItems[$value['price_field_value_id']]['amount'];
+ $eftParams['entity_id'] = $taxItems[$value['price_field_value_id']]['financial_item_id'];
+ CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
+ }
+ }
+ }
}
}
elseif ($params['total_amount'] < 0) {
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$ftParams = ['id' => $trxnId['financialTrxnId']];
- $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray);
+ $trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams);
}
}
elseif ($contributionStatus === 'Pending') {
protected static function getContributionAndParamsInFormatForRecordFinancialTransaction($contributionId) {
$getInfoOf['id'] = $contributionId;
$defaults = [];
- $contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray);
+ $contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults);
// build params for recording financial trxn entry
$params['contribution'] = $contributionDAO;