Skip to content

Commit

Permalink
Merge pull request #20791 from eileenmcnaughton/batch_renew
Browse files Browse the repository at this point in the history
[REF] Simplify isRenew handling on batch for membership
  • Loading branch information
monishdeb authored Jul 16, 2021
2 parents b00ecc5 + d6dd2be commit b33ecf0
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
*/
protected $_preserveDefault = TRUE;

/**
* Renew option for current row.
*
* This is as set on the form.
*
* @var int
*/
protected $currentRowIsRenewOption;

/**
* Contact fields.
*
Expand All @@ -86,6 +95,13 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
*/
protected $currentRowContributionID;

/**
* Row being processed.
*
* @var array
*/
protected $currentRow = [];

/**
* Get the contribution id for the current row.
*
Expand Down Expand Up @@ -733,12 +749,9 @@ private function processMembership(array $params) {
continue;
}
$value['contact_id'] = $params['primary_contact_id'][$key];
foreach ($value as $fieldKey => $fieldValue) {
if (isset($this->_fields[$fieldKey]) && $this->_fields[$fieldKey]['data_type'] === 'Money') {
$value[$fieldKey] = CRM_Utils_Rule::cleanMoney($fieldValue);
}
}
$value = $this->standardiseRow($value);
$this->currentRow = $value;
$this->currentRowIsRenewOption = (int) ($params['member_option'][$key] ?? 1);

// update contact information
$this->updateContactInfo($value);
Expand Down Expand Up @@ -789,12 +802,10 @@ private function processMembership(array $params) {
'join_date' => $value['membership_join_date'] ?? NULL,
'campaign_id' => $value['member_campaign_id'] ?? NULL,
];
$value['is_renew'] = FALSE;
if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {

if ($this->currentRowIsRenew()) {
// The following parameter setting may be obsolete.
$this->_params = $params;
$value['is_renew'] = TRUE;

$formDates = [
'end_date' => $value['membership_end_date'] ?? NULL,
Expand Down Expand Up @@ -865,10 +876,6 @@ private function processMembership(array $params) {
* true if mail was sent successfully
* @throws \CRM_Core_Exception|\API_Exception
*
* @deprecated
* This function is shared with Batch_Entry which has limited overlap
* & needs rationalising.
*
*/
protected function emailReceipt($form, &$formValues, $membership): bool {
// @todo figure out how much of the stuff below is genuinely shared with the batch form & a logical shared place.
Expand All @@ -888,12 +895,7 @@ protected function emailReceipt($form, &$formValues, $membership): bool {
$form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
}

if (!empty($formValues['is_renew'])) {
$form->assign('receiptType', 'membership renewal');
}
else {
$form->assign('receiptType', 'membership signup');
}
$form->assign('receiptType', $this->currentRowIsRenew() ? 'membership renewal' : 'membership signup');
$form->assign('receive_date', CRM_Utils_Array::value('receive_date', $formValues));
$form->assign('formValues', $formValues);

Expand Down Expand Up @@ -1220,6 +1222,11 @@ private function getFromEmailAddress(): string {
* @return array
*/
private function standardiseRow(array $row): array {
foreach ($row as $fieldKey => $fieldValue) {
if (isset($this->_fields[$fieldKey]) && $this->_fields[$fieldKey]['data_type'] === 'Money') {
$row[$fieldKey] = CRM_Utils_Rule::cleanMoney($fieldValue);
}
}
$renameFieldMapping = [
'financial_type' => 'financial_type_id',
'payment_instrument' => 'payment_instrument_id',
Expand All @@ -1242,4 +1249,13 @@ private function standardiseRow(array $row): array {
return $row;
}

/**
* Is the current row a renewal.
*
* @return bool
*/
private function currentRowIsRenew(): bool {
return $this->currentRowIsRenewOption === 2;
}

}

0 comments on commit b33ecf0

Please sign in to comment.