This has only been added for those with sites with no ACLs as the financial acl code is quite new & raised questions when I looked.
Further the option is only editable if there is a single line item. Multiple line item recurrings cannot be overridden from here
Contribution Recur Edit should not require installments
Leaving installments empty is valid - ie. it could be null for unlimited
(there is an implication that it should be '0' rather than null but null 'works' & is set in some cases
and we permit the DB field to be null - which we should not do if null is not OK)
if (!empty($input['amount'])) {
$contribution->total_amount = $contributionParams['total_amount'] = $input['amount'];
}
- $templateContribution = civicrm_api3('Contribution', 'getsingle', array(
- 'contribution_recur_id' => $contributionParams['contribution_recur_id'],
- 'options' => array('limit' => 1),
- ));
+ $templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($contributionParams['contribution_recur_id']);
if (!empty($contributionParams['contribution_recur_id'])) {
$recurringContribution = civicrm_api3('ContributionRecur', 'getsingle', array(
'id' => $contributionParams['contribution_recur_id'],
* @throws \CiviCRM_API3_Exception
*/
public static function isSingleLineItem($id) {
- $lineItemCount = civicrm_api3('LineItem', 'getcount', array('id' => $id));
+ $lineItemCount = civicrm_api3('LineItem', 'getcount', array('contribution_id' => $id));
return ($lineItemCount == 1);
}
}
/**
- * Get the description (source field) for the recurring contribution.
- *
- * @param CRM_Contribute_BAO_Contribution $contribution
- * @param CRM_Event_DAO_Event|null $event
- *
- * @return array
- * @throws \CiviCRM_API3_Exception
- */
+ * Get the description (source field) for the recurring contribution.
+ *
+ * @param CRM_Contribute_BAO_Contribution $contribution
+ * @param CRM_Event_DAO_Event|null $event
+ *
+ * @return array
+ * @throws \CiviCRM_API3_Exception
+ */
protected static function getRecurringContributionDescription($contribution, $event) {
if (!empty($contribution->contribution_page_id)) {
$contributionPageTitle = civicrm_api3('ContributionPage', 'getvalue', array(
));
return ts('Online Contribution') . ': ' . $contributionPageTitle;
}
- .elseif ($event) {
+ elseif ($event) {
return ts('Online Event Registration') . ': ' . $event->title;
}
return 'recurring contribution';
rec.auto_renew,
rec.currency,
rec.campaign_id,
- con.id as contribution_id,
+ rec.financial_type_id,
+ con.id as contribution_id,
con.contribution_page_id,
rec.contact_id,
mp.membership_id";
return $dao;
}
else {
- return CRM_Core_DAO::$_nullObject;
+ return NULL;
}
}
+ /**
+ * Does the recurring contribution support financial type change.
+ *
+ * This is conditional on there being only one line item or if there are no contributions as yet.
+ *
+ * (This second is a bit of an unusual condition but might occur in the context of a
+ *
+ * @param int $id
+ *
+ * @return bool
+ */
+ public static function supportsFinancialTypeChange($id) {
+ // At this stage only sites with no Financial ACLs will have the opportunity to edit the financial type.
+ // this is to limit the scope of the change and because financial ACLs are still fairly new & settling down.
+ if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
+ return FALSE;
+ }
+ $contribution = self::getTemplateContribution($id);
+ return CRM_Contribute_BAO_Contribution::isSingleLineItem($contribution['id']);
+ }
+
+ /**
+ * Get the contribution to be used as the template for later contributions.
+ *
+ * Later we might merge in data stored against the contribution recur record rather than just return the contribution.
+ *
+ * @param int $id
+ *
+ * @return array
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function getTemplateContribution($id) {
+ $templateContribution = civicrm_api3('Contribution', 'get', array(
+ 'contribution_recur_id' => $id,
+ 'options' => array('limit' => 1, 'sort' => array('id DESC')),
+ 'sequential' => 1,
+ ));
+ if ($templateContribution['count']) {
+ return $templateContribution['values'][0];
+ }
+ return array();
+ }
+
public static function setSubscriptionContext() {
// handle context redirection for subscription url
$session = CRM_Core_Session::singleton();
$this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'info');
$this->_paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($this->_coid, 'contribute', 'obj');
$this->_subscriptionDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($this->_coid, 'contribution');
+ $this->_crid = $this->_subscriptionDetails->recur_id;
}
elseif ($this->_crid) {
$this->_coid = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_crid, 'id', 'contribution_recur_id');
}
- if ((!$this->_crid && !$this->_coid) ||
+ if ((!$this->_crid) ||
($this->_subscriptionDetails == CRM_Core_DAO::$_nullObject)
) {
CRM_Core_Error::fatal('Required information missing.');
$this->_defaults['amount'] = $this->_subscriptionDetails->amount;
$this->_defaults['installments'] = $this->_subscriptionDetails->installments;
$this->_defaults['campaign_id'] = $this->_subscriptionDetails->campaign_id;
+ $this->_defaults['financial_type_id'] = $this->_subscriptionDetails->financial_type_id;
$this->_defaults['is_notify'] = 1;
return $this->_defaults;
TRUE, 'currency', $this->_subscriptionDetails->currency, TRUE
);
- $this->add('text', 'installments', ts('Number of Installments'), array('size' => 20), TRUE);
+ $this->add('text', 'installments', ts('Number of Installments'), array('size' => 20), FALSE);
if ($this->_donorEmail) {
$this->add('checkbox', 'is_notify', ts('Notify Contributor?'));
}
if (CRM_Core_Permission::check('edit contributions')) {
- CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
+ CRM_Campaign_BAO_Campaign::addCampaign($this);
+ }
+
+ if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($this->_crid)) {
+ $this->addEntityRef('financial_type_id', ts('Financial Type'), array('entity' => 'FinancialType'), TRUE);
}
$type = 'next';
'name'
);
}
- // get contribution status label
- if (!empty($values['contribution_status_id'])) {
- $values['contribution_status'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $values['contribution_status_id']);
+ $idFields = array('contribution_status_id', 'campaign_id');
+ if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($values['id'])) {
+ $idFields[] = 'financial_type_id';
+ }
+ foreach ($idFields as $idField) {
+ if (!empty($values[$idField])) {
+ $values[substr($idField, 0, -3)] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', $idField, $values[$idField]);
+ }
}
$this->assign('recur', $values);
{if !$self_service}
<tr><td class="label">{$form.is_notify.label}</td><td>{$form.is_notify.html}</td></tr>
<tr><td class="label">{$form.campaign_id.label}</td><td>{$form.campaign_id.html}</td></tr>
+ <tr><td class="label">{$form.financial_type_id.label}</td><td>{$form.financial_type_id.html}</td></tr>
{/if}
{* Currently changes to interval, unit and cycle day are not supported. *}
{if $recur.invoice_id}<tr><td class="label">{ts}Failure Retry Date{/ts}</td><td>{$recur.next_sched_contribution_date|crmDate}</td></tr>{/if}
<tr><td class="label">{ts}Auto Renew?{/ts}</td><td>{if $recur.auto_renew}{ts}Yes{/ts}{else}{ts}No{/ts}{/if}</td></tr>
{if $recur.payment_processor}<tr><td class="label">{ts}Payment Processor{/ts}</td><td>{$recur.payment_processor}</td></tr>{/if}
+ {if $recur.financial_type}<tr><td class="label">{ts}Financial Type{/ts}</td><td>{$recur.financial_type}</td></tr>{/if}
+ {if $recur.campaign}<tr><td class="label">{ts}Campaign{/ts}</td><td>{$recur.campaign}</td></tr>{/if}
</table>
<div class="crm-submit-buttons"><a class="button cancel crm-form-submit" href="{crmURL p='civicrm/contact/view' q='action=browse&selectedChild=contribute'}">{ts}Done{/ts}</a></div>
</div>