+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
if ($this->_mode) {
+ // @todo - remove this function as the parent does it too.
$config = CRM_Core_Config::singleton();
// Set default country from config if no country set.
if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
$this->assign('is_pay_later', TRUE);
}
$this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
-
+ if (!empty($defaults['contribution_status_id']) && in_array(
+ CRM_Contribute_PseudoConstant::contributionStatus($defaults['contribution_status_id'], 'name'),
+ // Historically not 'Cancelled' hence not using CRM_Contribute_BAO_Contribution::isContributionStatusNegative.
+ array('Refunded', 'Chargeback')
+ )) {
+ $defaults['refund_trxn_id'] = CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($this->_id);
+ }
+ else {
+ $defaults['refund_trxn_id'] = isset($defaults['trxn_id']) ? $defaults['trxn_id'] : NULL;
+ }
$dates = array(
'receive_date',
'receipt_date',
}
}
+ // define the status IDs that show the cancellation info, see CRM-17589
+ $cancelInfo_show_ids = array();
+ foreach (array_keys($statusName) as $status_id) {
+ if (CRM_Contribute_BAO_Contribution::isContributionStatusNegative($status_id)) {
+ $cancelInfo_show_ids[] = "'$status_id'";
+ }
+ }
+ $this->assign('cancelInfo_show_ids', implode(',', $cancelInfo_show_ids));
+
if ($this->_id) {
$contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
$name = CRM_Utils_Array::value($contributionStatus, $statusName);
switch ($name) {
case 'Completed':
+ // [CRM-17498] Removing unsupported status change options.
+ unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
+ unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
+ unset($status[CRM_Utils_Array::key('Partially paid', $statusName)]);
+ unset($status[CRM_Utils_Array::key('Pending refund', $statusName)]);
case 'Cancelled':
+ case 'Chargeback':
case 'Refunded':
unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
case 'Pending':
case 'In Progress':
unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
+ unset($status[CRM_Utils_Array::key('Chargeback', $statusName)]);
break;
case 'Failed':
foreach (array(
'Pending',
'Refunded',
+ 'Chargeback',
'Completed',
'In Progress',
'Cancelled',
}
else {
unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
+ unset($status[CRM_Utils_Array::key('Chargeback', $statusName)]);
}
$this->add('select', 'contribution_status_id',
FALSE
);
+ // CRM-16189, add Revenue Recognition Date
+ if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+ $this->add('date', 'revenue_recognition_date', ts('Revenue Recognition Date'), CRM_Core_SelectValues::date(NULL, 'M Y', NULL, 5));
+ }
+
// add various dates
$this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
$this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
$this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
-
+ $this->add('text', 'refund_trxn_id', ts('Transaction ID for the refund payment'));
$element = $this->add('select',
'payment_processor_id',
ts('Payment Processor'),
$errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
}
}
-
+ if (!empty($fields['revenue_recognition_date'])
+ && count(array_filter($fields['revenue_recognition_date'])) == 1
+ ) {
+ $errors['revenue_recognition_date'] = ts('Month and Year are required field for Revenue Recognition.');
+ }
+ // CRM-16189
+ $errorMessage = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self);
+ if ($errorMessage) {
+ $errors['financial_type_id'] = ' ';
+ $errors['_qf_default'] = $errorMessage;
+ }
$errors = array_merge($errors, $softErrors);
return $errors;
}
if ($priceSetId) {
$params['skipCleanMoney'] = 1;
}
-
+ $params['revenue_recognition_date'] = NULL;
+ if (!empty($formValues['revenue_recognition_date'])
+ && count(array_filter($formValues['revenue_recognition_date'])) == 2
+ ) {
+ $params['revenue_recognition_date'] = CRM_Utils_Date::processDate(
+ '01-' . implode('-', $formValues['revenue_recognition_date'])
+ );
+ }
$dates = array(
'receive_date',
'receipt_date',
);
foreach ($dates as $d) {
- $params[$d] = CRM_Utils_Date::processDate($formValues[$d], $formValues[$d . '_time'], TRUE);
+ if (isset($formValues[$d])) {
+ $params[$d] = CRM_Utils_Date::processDate($formValues[$d], CRM_Utils_Array::value($d . '_time', $formValues), TRUE);
+ }
}
if (!empty($formValues['is_email_receipt'])) {
$params['receipt_date'] = date("Y-m-d");
}
- if ($params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Cancelled', 'name')
- || $params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name')
+ if (CRM_Contribute_BAO_Contribution::isContributionStatusNegative($params['contribution_status_id'])
) {
if (CRM_Utils_System::isNull(CRM_Utils_Array::value('cancel_date', $params))) {
- $params['cancel_date'] = date('Y-m-d');
+ $params['cancel_date'] = date('YmdHis');
}
}
else {