*/
/**
- * This class provides the functionality for batch entry for contributions/memeberships
+ * This class provides the functionality for batch entry for contributions/memberships
*/
class CRM_Batch_Form_Entry extends CRM_Core_Form {
protected $_batchId;
/**
- * Batch informtaion
+ * Batch information
*/
protected $_batchInfo = array();
$paramValues = array(
'id' => $this->_batchId,
// close status
- 'status_id' => 2,
+ 'status_id' => CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name'),
'total' => $params['actualBatchTotal'],
);
// get the price set associated with offline contribution record.
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
$this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
- $fieldID = key($this->_priceSet['fields']);
+ $priceFieldID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldID($this->_priceSet);
+ $priceFieldValueID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldValueID($this->_priceSet);
if (isset($params['field'])) {
foreach ($params['field'] as $key => $value) {
if (!empty($value['send_receipt'])) {
$value['receipt_date'] = date('Y-m-d His');
}
+ // these translations & date handling are required because we are calling BAO directly rather than the api
+ $fieldTranslations = array(
+ 'financial_type' => 'financial_type_id',
+ 'payment_instrument' => 'payment_instrument_id',
+ 'contribution_source' => 'source',
+ 'contribution_note' => 'note',
- if ($value['financial_type']) {
- $value['financial_type_id'] = $value['financial_type'];
- }
-
- if (!empty($value['payment_instrument'])) {
- $value['payment_instrument_id'] = $value['payment_instrument'];
- }
-
- if (!empty($value['contribution_source'])) {
- $value['source'] = $value['contribution_source'];
- }
-
- if (!empty($value['contribution_note'])) {
- $value['note'] = $value['contribution_note'];
+ );
+ foreach ($fieldTranslations as $formField => $baoField) {
+ if(isset($value[$formField])) {
+ $value[$baoField] = $value[$formField];
+ }
+ unset($value[$formField]);
}
$params['actualBatchTotal'] += $value['total_amount'];
-
- unset($value['contribution_note']);
- unset($value['financial_type']);
- unset($value['contribution_source']);
-
$value['batch_id'] = $this->_batchId;
$value['skipRecentView'] = TRUE;
// build line item params
- $this->_priceSet['fields'][$fieldID]['options'][$fieldID]['amount'] = $value['total_amount'];
- $value['price_'.$fieldID] = 1;
+ $this->_priceSet['fields'][$priceFieldID]['options'][$priceFieldValueID ]['amount'] = $value['total_amount'];
+ $value['price_'. $priceFieldID] = 1;
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
//unset amount level since we always use quick config price set
unset($value['amount_level']);
- //CRM-11529 for backoffice transactions
+ //CRM-11529 for back office transactions
//when financial_type_id is passed in form, update the
- //lineitems with the financial type selected in form
+ //line items with the financial type selected in form
if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
foreach ($lineItem[$priceSetId] as &$values) {
$values['financial_type_id'] = $value['financial_type_id'];
}
}
}
+ return TRUE;
}
//end of function
*
* @access public
*
- * @return void
+ * @return bool
*/
private function processMembership(&$params) {
$dateTypes = array(
if (!empty($params['member_option']) && CRM_Utils_Array::value( $key, $params['member_option'] ) == 2 ) {
$this->_params = $params;
$value['is_renew'] = true;
- $membership = CRM_Member_BAO_Membership::renewMembership(
+ $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper(
$value['contact_id'],
$value['membership_type_id'],
FALSE, $this, NULL, NULL,
$value['contact_id']
);
}
+
/**
* Function exists purely for unit testing purposes. If you feel tempted to use this in live code
* then it probably means there is some functionality that needs to be moved
* out of the form layer
+ *
* @param unknown_type $params
+ *
+ * @return bool
*/
function testProcessMembership($params) {
return $this->processMembership($params);
}
+
+ /**
+ * Function exists purely for unit testing purposes. If you feel tempted to use this in live code
+ * then it probably means there is some functionality that needs to be moved
+ * out of the form layer
+ *
+ * @param array $params
+ *
+ * @return bool
+ */
+ function testProcessContribution($params) {
+ return $this->processContribution($params);
+ }
}