$financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$params['entity_id'] = $financialTxn->id;
}
- }
- // record line items and finacial items
+ // record line items and finacial items
- if (!CRM_Utils_Array::value('skipLineItem', $params)) {
- CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
+ if (!CRM_Utils_Array::value('skipLineItem', $params)) {
+ CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
+ }
}
// create batch entry if batch_id is passed
* @static
*/
static function checkStatusValidation($values, &$fields, &$errors) {
+ if (CRM_Utils_System::isNull($values) && CRM_Utils_Array::value('id', $fields)) {
+ $values['contribution_status_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $fields['id'], 'contribution_status_id');
+ if ($values['contribution_status_id'] == $fields['contribution_status_id']) {
+ return FALSE;
+ }
+ }
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$checkStatus = array(
'Cancelled' => array('Completed', 'Refunded'),
$ids = array();
if (CRM_Utils_Array::value('id', $params)) {
$ids['contribution'] = $params['id'];
+ // CRM-12498
+ if (CRM_Utils_Array::value('contribution_status_id', $params)) {
+ $error = array();
+ //throw error for invalid status change
+ CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
+ if (array_key_exists('contribution_status_id', $error)) {
+ return civicrm_api3_create_error($error['contribution_status_id']);
+ }
+ }
}
$contribution = CRM_Contribute_BAO_Contribution::create($values, $ids);
'total_amount' => 100.00,
'financial_type_id' => $this->_contributionTypeId,
'payment_instrument_id' => 1,
- 'contribution_status_id' => 2,
+ 'contribution_status_id' => 2,
+ 'is_pay_later' => 1,
'version' => $this->_apiversion,
);
$contribution = civicrm_api('contribution', 'create', $contribParams);
$newParams = array_merge($contribParams, array(
- 'id' => $contribution['id'],
- 'contribution_status_id' => 1,)
- );
+ 'id' => $contribution['id'],
+ 'contribution_status_id' => 1,)
+ );
$contribution = civicrm_api('contribution', 'update', $newParams);
$contribution = $contribution['values'][$contribution['id']];
$this->assertEquals($contribution['contribution_status_id'],'1');
$contribution = civicrm_api('contribution', 'update', $newParams);
$this->_checkFinancialTrxn($contribution, 'refund');
$this->_checkFinancialItem($contribution['id'], 'refund');
+ }
+
+ /*
+ * Function tests invalid contribution status change
+ */
+ function testCreateUpdateContributionInValidStatusChange() {
+ $contribParams = array(
+ 'contact_id' => 1,
+ 'receive_date' => '2012-01-01',
+ 'total_amount' => 100.00,
+ 'financial_type_id' => 1,
+ 'payment_instrument_id' => 1,
+ 'contribution_status_id' => 1,
+ 'version' => 3,
+ );
+ $contribution = civicrm_api('contribution', 'create', $contribParams);
+ $newParams = array_merge($contribParams, array(
+ 'id' => $contribution['id'],
+ 'contribution_status_id' => 2,
+ )
+ );
+ $contribution = civicrm_api('contribution', 'update', $newParams);
+ $this->assertTrue(!empty($contribution['is_error']), 'In line ' . __LINE__);
+ $this->assertEquals($contribution['error_message'], ts('Cannot change contribution status from Completed to Pending.'), 'In line ' . __LINE__);
+
}
/*
'financial_type_id' => $this->_contributionTypeId,
'payment_instrument_id' => 1,
'contribution_status_id' => 2,
+ 'is_pay_later' => 1,
'version' => $this->_apiversion,
);
$contribution = civicrm_api('contribution', 'create', $contribParams);