3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class provides the functionality for batch entry for contributions/memberships
39 class CRM_Batch_Form_Entry
extends CRM_Core_Form
{
42 * Maximum profile fields that will be displayed.
44 protected $_rowCount = 1;
54 protected $_batchInfo = array();
57 * Store the profile id associated with the batch type.
59 protected $_profileId;
67 public $_membershipId = NULL;
69 * When not to reset sort_name.
71 protected $_preserveDefault = TRUE;
76 protected $_contactFields = array();
79 * Fields array of fields in the batch profile.
80 * (based on the uf_field table data)
81 * (this can't be protected as it is passed into the CRM_Contact_Form_Task_Batch::parseStreetAddress function
82 * (although a future refactoring might hopefully change that so it uses the api & the function is not
86 public $_fields = array();
89 * Build all the data structures needed to build the form.
93 public function preProcess() {
94 $this->_batchId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
96 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
98 if (empty($this->_batchInfo
)) {
99 $params = array('id' => $this->_batchId
);
100 CRM_Batch_BAO_Batch
::retrieve($params, $this->_batchInfo
);
102 $this->assign('batchTotal', !empty($this->_batchInfo
['total']) ?
$this->_batchInfo
['total'] : NULL);
103 $this->assign('batchType', $this->_batchInfo
['type_id']);
105 // get the profile id associted with this batch type
106 $this->_profileId
= CRM_Batch_BAO_Batch
::getProfileId($this->_batchInfo
['type_id']);
108 CRM_Core_Resources
::singleton()
109 ->addScriptFile('civicrm', 'templates/CRM/Batch/Form/Entry.js', 1, 'html-header')
110 ->addSetting(array('batch' => array('type_id' => $this->_batchInfo
['type_id'])))
111 ->addSetting(array('setting' => array('monetaryThousandSeparator' => CRM_Core_Config
::singleton()->monetaryThousandSeparator
)))
112 ->addSetting(array('setting' => array('monetaryDecimalPoint' => CRM_Core_Config
::singleton()->monetaryDecimalPoint
)));
117 * Build the form object.
122 public function buildQuickForm() {
123 if (!$this->_profileId
) {
124 CRM_Core_Error
::fatal(ts('Profile for bulk data entry is missing.'));
127 $this->addElement('hidden', 'batch_id', $this->_batchId
);
129 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
130 // get the profile information
131 if ($this->_batchInfo
['type_id'] == $batchTypes['Contribution']) {
132 CRM_Utils_System
::setTitle(ts('Batch Data Entry for Contributions'));
133 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution');
135 elseif ($this->_batchInfo
['type_id'] == $batchTypes['Membership']) {
136 CRM_Utils_System
::setTitle(ts('Batch Data Entry for Memberships'));
137 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership');
139 elseif ($this->_batchInfo
['type_id'] == $batchTypes['Pledge Payment']) {
140 CRM_Utils_System
::setTitle(ts('Batch Data Entry for Pledge Payments'));
141 $customFields = CRM_Core_BAO_CustomField
::getFields('Contribution');
143 $this->_fields
= array();
144 $this->_fields
= CRM_Core_BAO_UFGroup
::getFields($this->_profileId
, FALSE, CRM_Core_Action
::VIEW
);
146 // remove file type field and then limit fields
147 $suppressFields = FALSE;
148 $removehtmlTypes = array('File', 'Autocomplete-Select');
149 foreach ($this->_fields
as $name => $field) {
150 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name) &&
151 in_array($this->_fields
[$name]['html_type'], $removehtmlTypes)
153 $suppressFields = TRUE;
154 unset($this->_fields
[$name]);
157 //fix to reduce size as we are using this field in grid
158 if (is_array($field['attributes']) && $this->_fields
[$name]['attributes']['size'] > 19) {
159 //shrink class to "form-text-medium"
160 $this->_fields
[$name]['attributes']['size'] = 19;
164 $this->addFormRule(array('CRM_Batch_Form_Entry', 'formRule'), $this);
166 // add the force save button
167 $forceSave = $this->getButtonName('upload', 'force');
169 $this->addElement('submit',
171 ts('Ignore Mismatch & Process the Batch?')
174 $this->addButtons(array(
177 'name' => ts('Validate & Process the Batch'),
182 'name' => ts('Save & Continue Later'),
187 $this->assign('rowCount', $this->_batchInfo
['item_count'] +
1);
189 $fileFieldExists = FALSE;
190 $preserveDefaultsArray = array(
198 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
199 $contactReturnProperties = array();
200 $config = CRM_Core_Config
::singleton();
202 for ($rowNumber = 1; $rowNumber <= $this->_batchInfo
['item_count']; $rowNumber++
) {
203 $this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array(
205 'placeholder' => ts('- select -'),
208 // special field specific to membership batch udpate
209 if ($this->_batchInfo
['type_id'] == 2) {
211 1 => ts('Add Membership'),
212 2 => ts('Renew Membership'),
214 $this->add('select', "member_option[$rowNumber]", '', $options);
216 if ($this->_batchInfo
['type_id'] == $batchTypes['Pledge Payment']) {
217 $options = array('' => '-select-');
218 $optionTypes = array(
219 '1' => ts('Adjust Pledge Payment Schedule?'),
220 '2' => ts('Adjust Total Pledge Amount?'),
222 $this->add('select', "option_type[$rowNumber]", NULL, $optionTypes);
223 if (!empty($this->_batchId
) && !empty($this->_batchInfo
['data']) && !empty($rowNumber)) {
224 $dataValues = json_decode($this->_batchInfo
['data'], TRUE);
225 if (!empty($dataValues['values']['primary_contact_id'][$rowNumber])) {
226 $pledgeIDs = CRM_Pledge_BAO_Pledge
::getContactPledges($dataValues['values']['primary_contact_id'][$rowNumber]);
227 foreach ($pledgeIDs as $pledgeID) {
228 $pledgePayment = CRM_Pledge_BAO_PledgePayment
::getOldestPledgePayment($pledgeID);
229 $options +
= array($pledgeID => CRM_Utils_Date
::customFormat($pledgePayment['schedule_date'], '%m/%d/%Y') . ', ' . $pledgePayment['amount'] . ' ' . $pledgePayment['currency']);
234 $this->add('select', "open_pledges[$rowNumber]", '', $options);
237 foreach ($this->_fields
as $name => $field) {
238 if (in_array($field['field_type'], $contactTypes)) {
239 $fld = explode('-', $field['name']);
240 $contactReturnProperties[$field['name']] = $fld[0];
242 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
244 if (in_array($field['name'], $preserveDefaultsArray)) {
245 $this->_preserveDefault
= FALSE;
250 $this->assign('fields', $this->_fields
);
251 CRM_Core_Resources
::singleton()
254 'return' => implode(',', $contactReturnProperties),
255 'fieldmap' => array_flip($contactReturnProperties),
259 // don't set the status message when form is submitted.
260 $buttonName = $this->controller
->getButtonName('submit');
262 if ($suppressFields && $buttonName != '_qf_Entry_next') {
263 CRM_Core_Session
::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Batch Update."), ts('Some Fields Excluded'), 'info');
270 * @param array $params
271 * Posted values of the form.
272 * @param array $files
273 * List of errors to be posted back to the form.
278 * list of errors to be posted back to the form
280 public static function formRule($params, $files, $self) {
282 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
284 if (!empty($params['_qf_Entry_upload_force'])) {
289 foreach ($params['field'] as $key => $value) {
290 $batchTotal +
= $value['total_amount'];
292 //validate for soft credit fields
293 if (!empty($params['soft_credit_contact_id'][$key]) && empty($params['soft_credit_amount'][$key])) {
294 $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
296 if (!empty($params['soft_credit_amount']) && !empty($params['soft_credit_amount'][$key]) && CRM_Utils_Rule
::cleanMoney(CRM_Utils_Array
::value($key, $params['soft_credit_amount'])) > CRM_Utils_Rule
::cleanMoney($value['total_amount'])) {
297 $errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount');
300 //membership type is required for membership batch entry
301 if ($self->_batchInfo
['type_id'] == $batchTypes['Membership']) {
302 if (empty($value['membership_type'][1])) {
303 $errors["field[$key][membership_type]"] = ts('Membership type is a required field.');
307 if ($self->_batchInfo
['type_id'] == $batchTypes['Pledge Payment']) {
308 foreach (array_unique($params["open_pledges"]) as $value) {
309 $duplicateRows = array_keys($params["open_pledges"], $value);
310 if (count($duplicateRows) > 1) {
311 foreach ($duplicateRows as $key) {
312 $errors["open_pledges[$key]"] = ts('You can not record two payments for the same pledge in a single batch.');
317 if ($batchTotal != $self->_batchInfo
['total']) {
318 $self->assign('batchAmountMismatch', TRUE);
319 $errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.');
322 if (!empty($errors)) {
326 $self->assign('batchAmountMismatch', FALSE);
331 * Override default cancel action.
333 public function cancelAction() {
334 // redirect to batch listing
335 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/batch', 'reset=1'));
336 CRM_Utils_System
::civiExit();
340 * Set default values for the form.
345 public function setDefaultValues() {
346 if (empty($this->_fields
)) {
350 // for add mode set smart defaults
351 if ($this->_action
& CRM_Core_Action
::ADD
) {
352 list($currentDate, $currentTime) = CRM_Utils_Date
::setDateDefaults(NULL, 'activityDateTime');
355 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
356 $completeStatus = array_search('Completed', $allStatus);
357 $specialFields = array(
358 'join_date' => $currentDate,
359 'receive_date' => $currentDate,
360 'receive_date_time' => $currentTime,
361 'contribution_status_id' => $completeStatus,
364 for ($rowNumber = 1; $rowNumber <= $this->_batchInfo
['item_count']; $rowNumber++
) {
365 foreach ($specialFields as $key => $value) {
366 $defaults['field'][$rowNumber][$key] = $value;
371 // get the cached info from data column of civicrm_batch
372 $data = CRM_Core_DAO
::getFieldValue('CRM_Batch_BAO_Batch', $this->_batchId
, 'data');
373 $defaults = json_decode($data, TRUE);
374 $defaults = $defaults['values'];
381 * Process the form after the input has been submitted and validated.
386 public function postProcess() {
387 $params = $this->controller
->exportValues($this->_name
);
388 $params['actualBatchTotal'] = 0;
390 // get the profile information
391 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
392 if (in_array($this->_batchInfo
['type_id'], array($batchTypes['Pledge Payment'], $batchTypes['Contribution']))) {
393 $this->processContribution($params);
395 elseif ($this->_batchInfo
['type_id'] == $batchTypes['Membership']) {
396 $this->processMembership($params);
399 // update batch to close status
400 $paramValues = array(
401 'id' => $this->_batchId
,
403 'status_id' => CRM_Core_OptionGroup
::getValue('batch_status', 'Closed', 'name'),
404 'total' => $params['actualBatchTotal'],
407 CRM_Batch_BAO_Batch
::create($paramValues);
409 // set success status
410 CRM_Core_Session
::setStatus("", ts("Batch Processed."), "success");
412 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/batch', 'reset=1'));
416 * Process contribution records.
418 * @param array $params
419 * Associated array of submitted values.
424 private function processContribution(&$params) {
432 // get the price set associated with offline contribution record.
433 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
434 $this->_priceSet
= current(CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId));
435 $priceFieldID = CRM_Price_BAO_PriceSet
::getOnlyPriceFieldID($this->_priceSet
);
436 $priceFieldValueID = CRM_Price_BAO_PriceSet
::getOnlyPriceFieldValueID($this->_priceSet
);
438 if (isset($params['field'])) {
439 foreach ($params['field'] as $key => $value) {
440 // if contact is not selected we should skip the row
441 if (empty($params['primary_contact_id'][$key])) {
445 $value['contact_id'] = CRM_Utils_Array
::value($key, $params['primary_contact_id']);
447 // update contact information
448 $this->updateContactInfo($value);
450 //build soft credit params
451 if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
452 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
453 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule
::cleanMoney($params['soft_credit_amount'][$key]);
455 //CRM-15350: if soft-credit-type profile field is disabled or removed then
456 //we choose configured SCT default value
457 if (!empty($params['soft_credit_type'][$key])) {
458 $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
461 $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type");
465 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($value,
466 CRM_Core_DAO
::$_nullObject,
471 foreach ($dates as $val) {
472 if (!empty($value[$val])) {
473 $value[$val] = CRM_Utils_Date
::processDate($value[$val], $value[$val . '_time'], TRUE);
477 if (!empty($value['send_receipt'])) {
478 $value['receipt_date'] = date('Y-m-d His');
480 // these translations & date handling are required because we are calling BAO directly rather than the api
481 $fieldTranslations = array(
482 'financial_type' => 'financial_type_id',
483 'payment_instrument' => 'payment_instrument_id',
484 'contribution_source' => 'source',
485 'contribution_note' => 'note',
488 foreach ($fieldTranslations as $formField => $baoField) {
489 if (isset($value[$formField])) {
490 $value[$baoField] = $value[$formField];
492 unset($value[$formField]);
495 $params['actualBatchTotal'] +
= $value['total_amount'];
496 $value['batch_id'] = $this->_batchId
;
497 $value['skipRecentView'] = TRUE;
499 // build line item params
500 $this->_priceSet
['fields'][$priceFieldID]['options'][$priceFieldValueID]['amount'] = $value['total_amount'];
501 $value['price_' . $priceFieldID] = 1;
504 CRM_Price_BAO_PriceSet
::processAmount($this->_priceSet
['fields'], $value, $lineItem[$priceSetId]);
506 //unset amount level since we always use quick config price set
507 unset($value['amount_level']);
509 //CRM-11529 for back office transactions
510 //when financial_type_id is passed in form, update the
511 //line items with the financial type selected in form
512 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
513 foreach ($lineItem[$priceSetId] as &$values) {
514 $values['financial_type_id'] = $value['financial_type_id'];
517 $value['line_item'] = $lineItem;
518 //finally call contribution create for all the magic
519 $contribution = CRM_Contribute_BAO_Contribution
::create($value, CRM_Core_DAO
::$_nullArray);
520 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
521 if (!empty($this->_batchInfo
['type_id']) && ($this->_batchInfo
['type_id'] == $batchTypes['Pledge Payment'])) {
522 $adjustTotalAmount = FALSE;
523 if (isset($params['option_type'][$key])) {
524 if ($params['option_type'][$key] == 2) {
525 $adjustTotalAmount = TRUE;
528 $pledgeId = $params['open_pledges'][$key];
529 if (is_numeric($pledgeId)) {
530 $result = CRM_Pledge_BAO_PledgePayment
::getPledgePayments($pledgeId);
531 $pledgePaymentId = 0;
532 foreach ($result as $key => $values) {
533 if ($values['status'] != 'Completed') {
534 $pledgePaymentId = $values['id'];
538 CRM_Core_DAO
::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentId, 'contribution_id', $contribution->id
);
539 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($pledgeId,
540 array($pledgePaymentId),
541 $contribution->contribution_status_id
,
543 $contribution->total_amount
,
550 if (!empty($value['product_name'])) {
551 if ($value['product_name'][0] > 0) {
552 list($products, $options) = CRM_Contribute_BAO_Premium
::getPremiumProductInfo();
554 $value['hidden_Premium'] = 1;
555 $value['product_option'] = CRM_Utils_Array
::value(
556 $value['product_name'][1],
557 $options[$value['product_name'][0]]
560 $premiumParams = array(
561 'product_id' => $value['product_name'][0],
562 'contribution_id' => $contribution->id
,
563 'product_option' => $value['product_option'],
566 CRM_Contribute_BAO_Contribution
::addPremium($premiumParams);
572 if ($contribution->id
&& !empty($value['send_receipt'])) {
573 // add the domain email id
574 $domainEmail = CRM_Core_BAO_Domain
::getNameAndEmail();
575 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
576 $value['from_email_address'] = $domainEmail;
577 $value['contribution_id'] = $contribution->id
;
578 CRM_Contribute_Form_AdditionalInfo
::emailReceipt($this, $value);
586 * Process membership records.
588 * @param array $params
589 * Associated array of submitted values.
594 private function processMembership(&$params) {
596 'join_date' => 'joinDate',
597 'membership_start_date' => 'startDate',
598 'membership_end_date' => 'endDate',
608 // get the price set associated with offline memebership
609 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
610 $this->_priceSet
= $priceSets = current(CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId));
612 if (isset($params['field'])) {
613 $customFields = array();
614 foreach ($params['field'] as $key => $value) {
615 // if contact is not selected we should skip the row
616 if (empty($params['primary_contact_id'][$key])) {
620 $value['contact_id'] = CRM_Utils_Array
::value($key, $params['primary_contact_id']);
622 // update contact information
623 $this->updateContactInfo($value);
625 $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
627 foreach ($dateTypes as $dateField => $dateVariable) {
628 $
$dateVariable = CRM_Utils_Date
::processDate($value[$dateField]);
631 $calcDates = array();
632 $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType
::getDatesForMembershipType($membershipTypeId,
633 $joinDate, $startDate, $endDate
636 foreach ($calcDates as $memType => $calcDate) {
637 foreach ($dates as $d) {
638 //first give priority to form values then calDates.
639 $date = CRM_Utils_Array
::value($d, $value);
641 $date = CRM_Utils_Array
::value($d, $calcDate);
644 $value[$d] = CRM_Utils_Date
::processDate($date);
648 if (!empty($value['send_receipt'])) {
649 $value['receipt_date'] = date('Y-m-d His');
652 if (!empty($value['membership_source'])) {
653 $value['source'] = $value['membership_source'];
656 unset($value['membership_source']);
658 //Get the membership status
659 if (!empty($value['membership_status'])) {
660 $value['status_id'] = $value['membership_status'];
661 unset($value['membership_status']);
664 if (empty($customFields)) {
665 // membership type custom data
666 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership', FALSE, FALSE, $membershipTypeId);
668 $customFields = CRM_Utils_Array
::crmArrayMerge($customFields,
669 CRM_Core_BAO_CustomField
::getFields('Membership',
670 FALSE, FALSE, NULL, NULL, TRUE
675 //check for custom data
676 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($params['field'][$key],
683 if (!empty($value['financial_type'])) {
684 $value['financial_type_id'] = $value['financial_type'];
687 if (!empty($value['payment_instrument'])) {
688 $value['payment_instrument_id'] = $value['payment_instrument'];
691 // handle soft credit
692 if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
693 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
694 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule
::cleanMoney($params['soft_credit_amount'][$key]);
696 //CRM-15350: if soft-credit-type profile field is disabled or removed then
697 //we choose Gift as default value as per Gift Membership rule
698 if (!empty($params['soft_credit_type'][$key])) {
699 $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
702 $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'Gift', 'name');
706 if (!empty($value['receive_date'])) {
707 $value['receive_date'] = CRM_Utils_Date
::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
710 $params['actualBatchTotal'] +
= $value['total_amount'];
712 unset($value['financial_type']);
713 unset($value['payment_instrument']);
715 $value['batch_id'] = $this->_batchId
;
716 $value['skipRecentView'] = TRUE;
718 // make entry in line item for contribution
720 $editedFieldParams = array(
721 'price_set_id' => $priceSetId,
722 'name' => $value['membership_type'][0],
725 $editedResults = array();
726 CRM_Price_BAO_PriceField
::retrieve($editedFieldParams, $editedResults);
728 if (!empty($editedResults)) {
729 unset($this->_priceSet
['fields']);
730 $this->_priceSet
['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
731 unset($this->_priceSet
['fields'][$editedResults['id']]['options']);
732 $fid = $editedResults['id'];
733 $editedFieldParams = array(
734 'price_field_id' => $editedResults['id'],
735 'membership_type_id' => $value['membership_type_id'],
738 $editedResults = array();
739 CRM_Price_BAO_PriceFieldValue
::retrieve($editedFieldParams, $editedResults);
740 $this->_priceSet
['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
741 if (!empty($value['total_amount'])) {
742 $this->_priceSet
['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
745 $fieldID = key($this->_priceSet
['fields']);
746 $value['price_' . $fieldID] = $editedResults['id'];
749 CRM_Price_BAO_PriceSet
::processAmount($this->_priceSet
['fields'],
750 $value, $lineItem[$priceSetId]
753 //CRM-11529 for backoffice transactions
754 //when financial_type_id is passed in form, update the
755 //lineitems with the financial type selected in form
756 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
757 foreach ($lineItem[$priceSetId] as &$values) {
758 $values['financial_type_id'] = $value['financial_type_id'];
762 $value['lineItems'] = $lineItem;
763 $value['processPriceSet'] = TRUE;
765 // end of contribution related section
767 unset($value['membership_type']);
768 unset($value['membership_start_date']);
769 unset($value['membership_end_date']);
771 $value['is_renew'] = FALSE;
772 if (!empty($params['member_option']) && CRM_Utils_Array
::value($key, $params['member_option']) == 2) {
773 $this->_params
= $params;
774 $value['is_renew'] = TRUE;
775 $membership = CRM_Member_BAO_Membership
::renewMembershipFormWrapper(
776 $value['contact_id'],
777 $value['membership_type_id'],
778 FALSE, $this, NULL, NULL,
782 // make contribution entry
783 CRM_Member_BAO_Membership
::recordMembershipContribution(array_merge($value, array('membership_id' => $membership->id
)));
786 $membership = CRM_Member_BAO_Membership
::create($value, CRM_Core_DAO
::$_nullArray);
790 if (!empty($value['product_name'])) {
791 if ($value['product_name'][0] > 0) {
792 list($products, $options) = CRM_Contribute_BAO_Premium
::getPremiumProductInfo();
794 $value['hidden_Premium'] = 1;
795 $value['product_option'] = CRM_Utils_Array
::value(
796 $value['product_name'][1],
797 $options[$value['product_name'][0]]
800 $premiumParams = array(
801 'product_id' => $value['product_name'][0],
802 'contribution_id' => CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id
, 'contribution_id', 'membership_id'),
803 'product_option' => $value['product_option'],
806 CRM_Contribute_BAO_Contribution
::addPremium($premiumParams);
812 if ($membership->id
&& !empty($value['send_receipt'])) {
814 // add the domain email id
815 $domainEmail = CRM_Core_BAO_Domain
::getNameAndEmail();
816 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
818 $value['from_email_address'] = $domainEmail;
819 $value['membership_id'] = $membership->id
;
820 $value['contribution_id'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id
, 'contribution_id', 'membership_id');
821 CRM_Member_Form_Membership
::emailReceipt($this, $value, $membership);
829 * Update contact information.
831 * @param array $value
832 * Associated array of submitted values.
837 private function updateContactInfo(&$value) {
838 $value['preserveDBName'] = $this->_preserveDefault
;
840 //parse street address, CRM-7768
841 CRM_Contact_Form_Task_Batch
::parseStreetAddress($value, $this);
843 CRM_Contact_BAO_Contact
::createProfileContact($value, $this->_fields
,
849 * Function exists purely for unit testing purposes. If you feel tempted to use this in live code
850 * then it probably means there is some functionality that needs to be moved
851 * out of the form layer
853 * @param array $params
857 public function testProcessMembership($params) {
858 return $this->processMembership($params);
862 * Function exists purely for unit testing purposes. If you feel tempted to use this in live code
863 * then it probably means there is some functionality that needs to be moved
864 * out of the form layer
866 * @param array $params
870 public function testProcessContribution($params) {
871 return $this->processContribution($params);