throw new CRM_Core_Exception($message);
}
- // first clean up all the money fields
- $moneyFields = [
- 'total_amount',
- 'net_amount',
- 'fee_amount',
- 'non_deductible_amount',
- ];
-
- //if priceset is used, no need to cleanup money
- if (!empty($params['skipCleanMoney'])) {
- $moneyFields = [];
- }
- else {
- // @todo put a deprecated here - this should be done in the form layer.
- $params['skipCleanMoney'] = FALSE;
- Civi::log()->warning('Deprecated code path. Money should always be clean before it hits the BAO.', array('civi.tag' => 'deprecated'));
- }
-
- foreach ($moneyFields as $field) {
- if (isset($params[$field])) {
- $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
- }
- }
-
//set defaults in create mode
if (!$contributionID) {
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
CRM_Core_BAO_Note::add($noteParams);
}
- // make entry in batch entity batch table
- if (!empty($params['batch_id'])) {
- // in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
- $titleFields = [
- 'contact_id',
- 'total_amount',
- 'currency',
- 'financial_type_id',
- ];
- $retrieveRequired = 0;
- foreach ($titleFields as $titleField) {
- if (!isset($contribution->$titleField)) {
- $retrieveRequired = 1;
- break;
- }
- }
- if ($retrieveRequired == 1) {
- $contribution->find(TRUE);
- }
- }
-
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
*/
public static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL) {
$skipRecords = $update = $return = $isRelatedId = FALSE;
+ $isUpdate = !empty($params['prevContribution']);
$additionalParticipantId = [];
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (empty($params['prevContribution'])) {
$entityID = NULL;
}
- else {
- $update = TRUE;
- }
$statusId = $params['contribution']->contribution_status_id;
// CRM-13964 partial payment
$params['trxnParams'] = $trxnParams;
- if (!empty($params['prevContribution'])) {
+ if ($isUpdate) {
$updated = FALSE;
$params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount;
$params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount;
}
}
- if (!$update) {
+ else {
// records finanical trxn and entity financial trxn
// also make it available as return value
self::recordAlwaysAccountsReceivable($trxnParams, $params);
}
// record line items and financial items
if (empty($params['skipLineItem'])) {
- CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
+ CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $isUpdate);
}
// create batch entry if batch_id is passed and
* @param array $ids
* @param array $objects
* @param CRM_Core_Transaction $transaction
- * @param CRM_Contribute_BAO_Contribution $contribution
+ * It is not recommended to pass this in. The calling function handle it's own roll back if it wants it.
* @param bool $isPostPaymentCreate
* Is this being called from the payment.create api. If so the api has taken care of financial entities.
* Note that our goal is that this would only ever be called from payment.create and never handle financials (only
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public static function completeOrder($input, &$ids, $objects, $transaction, $contribution, $isPostPaymentCreate = FALSE) {
+ public static function completeOrder($input, &$ids, $objects, $transaction = NULL, $isPostPaymentCreate = FALSE) {
+ if (!$transaction) {
+ $transaction = new CRM_Core_Transaction();
+ }
+ $contribution = $objects['contribution'];
$primaryContributionID = $contribution->id ?? $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {