X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FBatch%2FForm%2FEntry.php;h=9baf89a4fd65cfbf1fbbb738fb050d2782c01507;hb=61767a1d73296c1b3d986070bee26982169fca66;hp=02daea9a3b9fd8f0bc80dfea2c6b763cd963df3a;hpb=a14e123a77a33879f3dd63c74b0c72031e0c8b5f;p=civicrm-core.git diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 02daea9a3b..9baf89a4fd 100755 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -64,7 +64,6 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { public $_params; - public $_membershipId = NULL; /** * When not to reset sort_name. */ @@ -280,8 +279,25 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { public static function formRule($params, $files, $self) { $errors = array(); $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate'); + $fields = array( + 'total_amount' => 'Amount', + 'financial_type' => 'Financial Type', + 'payment_instrument' => 'Paid By', + ); + + //CRM-16480 if contact is selected, validate financial type and amount field. + foreach ($params['field'] as $key => $value) { + foreach ($fields as $field => $label) { + if (!empty($params['primary_contact_id'][$key]) && empty($value[$field])) { + $errors["field[$key][$field]"] = ts('%1 is a required field.', array(1 => $label)); + } + } + } if (!empty($params['_qf_Entry_upload_force'])) { + if (!empty($errors)) { + return $errors; + } return TRUE; } @@ -306,15 +322,17 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } if ($self->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) { foreach (array_unique($params["open_pledges"]) as $value) { - $duplicateRows = array_keys($params["open_pledges"], $value); - if (count($duplicateRows) > 1) { + if (!empty($value)) { + $duplicateRows = array_keys($params["open_pledges"], $value); + } + if (!empty($duplicateRows) && count($duplicateRows) > 1) { foreach ($duplicateRows as $key) { $errors["open_pledges[$key]"] = ts('You can not record two payments for the same pledge in a single batch.'); } } } } - if ($batchTotal != $self->_batchInfo['total']) { + if ((string) $batchTotal != $self->_batchInfo['total']) { $self->assign('batchAmountMismatch', TRUE); $errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.'); } @@ -768,13 +786,23 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $value['is_renew'] = FALSE; if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) { + + // The following parameter setting may be obsolete. $this->_params = $params; $value['is_renew'] = TRUE; - $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper( - $value['contact_id'], - $value['membership_type_id'], - FALSE, $this, NULL, NULL, - $value['custom'] + $isPayLater = CRM_Utils_Array::value('is_pay_later', $params); + $campaignId = NULL; + if (isset($this->_values) && is_array($this->_values) && !empty($this->_values)) { + $campaignId = CRM_Utils_Array::value('campaign_id', $this->_params); + if (!array_key_exists('campaign_id', $this->_params)) { + $campaignId = CRM_Utils_Array::value('campaign_id', $this->_values); + } + } + + list($membership) = CRM_Member_BAO_Membership::renewMembership( + $value['contact_id'], $value['membership_type_id'], FALSE, + NULL, NULL, $value['custom'], NULL, NULL, FALSE, + NULL, NULL, $isPayLater, $campaignId ); // make contribution entry