+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Batch_Form_Entry extends CRM_Core_Form {
/**
- * Maximum profile fields that will be displayed
+ * Maximum profile fields that will be displayed.
*/
protected $_rowCount = 1;
/**
- * Batch id
+ * Batch id.
*/
protected $_batchId;
/**
- * Batch information
+ * Batch information.
*/
protected $_batchInfo = array();
/**
- * Store the profile id associated with the batch type
+ * Store the profile id associated with the batch type.
*/
protected $_profileId;
public $_params;
- public $_membershipId = NULL;
/**
- * When not to reset sort_name
+ * When not to reset sort_name.
*/
protected $_preserveDefault = TRUE;
/**
- * Contact fields
+ * Contact fields.
*/
protected $_contactFields = array();
/**
- * Fields array of fields in the batch profile
+ * Fields array of fields in the batch profile.
* (based on the uf_field table data)
* (this can't be protected as it is passed into the CRM_Contact_Form_Task_Batch::parseStreetAddress function
* (although a future refactoring might hopefully change that so it uses the api & the function is not
public $_fields = array();
/**
- * Build all the data structures needed to build the form
+ * Build all the data structures needed to build the form.
*
* @return void
*/
}
/**
- * Build the form object
+ * Build the form object.
*
*
* @return void
for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
$this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array(
'create' => TRUE,
- 'placeholder' => ts('- select -')
+ 'placeholder' => ts('- select -'),
));
// special field specific to membership batch udpate
'contact' => array(
'return' => implode(',', $contactReturnProperties),
'fieldmap' => array_flip($contactReturnProperties),
- )
+ ),
));
// don't set the status message when form is submitted.
}
/**
- * Form validations
+ * Form validations.
*
* @param array $params
* Posted values of the form.
*
* @return array
* list of errors to be posted back to the form
- * @static
*/
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;
}
}
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.');
}
}
/**
- * Override default cancel action
+ * Override default cancel action.
*/
public function cancelAction() {
// redirect to batch listing
}
/**
- * Process the form after the input has been submitted and validated
+ * Process the form after the input has been submitted and validated.
*
*
* @return void
}
/**
- * Process contribution records
+ * Process contribution records.
*
* @param array $params
* Associated array of submitted values.
}
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value,
- CRM_Core_DAO::$_nullObject,
NULL,
'Contribution'
);
}
/**
- * Process membership records
+ * Process membership records.
*
* @param array $params
* Associated array of submitted values.
'reminder_date',
);
- // get the price set associated with offline memebership
+ // get the price set associated with offline membership
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
$this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
//check for custom data
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key],
- $customFields,
$key,
'Membership',
$membershipTypeId
$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
- CRM_Member_BAO_Membership::recordMembershipContribution(array_merge($value, array('membership_id' => $membership->id)));
+ $contrbutionParams = array_merge($value, array('membership_id' => $membership->id));
+ CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
}
else {
$membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
}
/**
- * Update contact information
+ * Update contact information.
*
* @param array $value
* Associated array of submitted values.
public function testProcessContribution($params) {
return $this->processContribution($params);
}
+
}