if ($this->_contributionType) {
$defaults['financial_type_id'] = $this->_contributionType;
}
+
+ if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
+ $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
+ }
if (CRM_Utils_Array::value('is_test', $defaults)) {
$this->assign('is_test', TRUE);
$paymentInstrument = $this->add('select', 'payment_instrument_id',
ts('Paid By'),
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
- FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
+ TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
);
}
}
}
- $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields);
+ $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
if (CRM_Utils_Array::value('total_amount', $fields) && (CRM_Utils_Array::value('net_amount', $fields) || CRM_Utils_Array::value('fee_amount', $fields))) {
$sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
}
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
- if (CRM_Utils_Array::value('fee_amount', $fields)) {
- $financialAccount = array();
- CRM_Core_PseudoConstant::populate($financialAccount,
- 'CRM_Financial_DAO_EntityFinancialAccount',
- $all = TRUE,
- $retrieve = 'financial_account_id',
- $filter = NULL,
- " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} ");
- if (!current($financialAccount)) {
- $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type");
- }
+ if (CRM_Utils_Array::value('fee_amount', $fields)
+ && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) {
+ $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
+ }
+
+ // $trxn_id must be unique CRM-13919
+ if (!empty($fields['trxn_id'])) {
+ $queryParams = array(1 => array($fields['trxn_id'], 'String'));
+ $query = 'select count(*) from civicrm_contribution where trxn_id = %1';
+ if ($self->_id) {
+ $queryParams[2] = array((int)$self->_id, 'Integer');
+ $query .= ' and id !=%2';
+ }
+ $tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
+ if ($tCnt) {
+ $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
+ }
}
$errors = array_merge($errors, $softErrors);