$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
//if contribution is created with cancelled or refunded status, add credit note id
- if (!empty($params['contribution_status_id'])) {
- // @todo - should we include Chargeback? If so use self::isContributionStatusNegative($params['contribution_status_id'])
- if (($params['contribution_status_id'] == array_search('Refunded', $contributionStatus)
- || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus))
- ) {
- if (empty($params['creditnote_id'])) {
- $params['creditnote_id'] = self::createCreditNoteId();
- }
+ // do the same for chargeback - this entered the code 'accidentally' but moving it to here
+ // as part of cleanup maintains consistency.
+ if (self::isContributionStatusNegative(CRM_Utils_Array::value('contribution_status_id', $params))) {
+ if (empty($params['creditnote_id'])) {
+ $params['creditnote_id'] = self::createCreditNoteId();
}
}
- else {
+ if (empty($params['contribution_status_id'])) {
// Since the fee amount is expecting this (later on) ensure it is always set.
// It would only not be set for an update where it is unchanged.
$params['contribution_status_id'] = civicrm_api3('Contribution', 'getvalue', [
// @todo we should stop passing $params by reference - splitting this out would be a step towards that.
$params['trxnParams']['total_amount'] = -$params['total_amount'];
if (empty($params['contribution']->creditnote_id)) {
+ // This is always set in the Contribution::create function.
+ CRM_Core_Error::deprecatedFunctionWarning('Logic says this line is never reached & can be removed');
$creditNoteId = self::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
}
$params['trxnParams']['to_financial_account_id'] = $arAccountId;
$params['trxnParams']['total_amount'] = -$params['total_amount'];
if (empty($params['contribution']->creditnote_id)) {
+ // This is always set in the Contribution::create function.
+ CRM_Core_Error::deprecatedFunctionWarning('Logic says this line is never reached & can be removed');
$creditNoteId = self::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution']->id, 'creditnote_id', $creditNoteId);
}
if ($contribution->contribution_status_id == $refundedStatusId || $contribution->contribution_status_id == $cancelledStatusId) {
if (is_null($contribution->creditnote_id)) {
+ CRM_Core_Error::deprecatedFunctionWarning('This it the wrong place to add a credit note id since the id is added when the status is changed in the Contribution::Create function- hopefully it is never hit');
$creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId();
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'creditnote_id', $creditNoteId);
}
* CRM-17951 the contra account is a financial account with a relationship to a
* financial type. It is not always configured but should be reflected
* in the financial_trxn & financial_item table if it is.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testCreateUpdateChargebackContributionDefaultAccount() {
$contribution = $this->callAPISuccess('Contribution', 'create', $this->_params);
* Function tests that financial records are added when Pending Contribution is Canceled.
*/
public function testCreateUpdateContributionCancelPending() {
+ // Enable & disable invoicing just to standardise the credit note id setting.
+ // Longer term we want to separate that setting from 'taxAndInvoicing'.
+ // and / or remove from core.
+ $this->enableTaxAndInvoicing();
$contribParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
$contribution = $this->callAPISuccess('contribution', 'create', $newParams);
$this->_checkFinancialTrxn($contribution, 'cancelPending', NULL, $checkTrxnDate);
$this->_checkFinancialItem($contribution['id'], 'cancelPending');
+ $this->assertEquals('CN_1', $contribution['values'][$contribution['id']]['creditnote_id']);
+ $this->disableTaxAndInvoicing();
}
/**