fixes for CRM-13476
[civicrm-core.git] / CRM / Batch / Form / Entry.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class provides the functionality for batch entry for contributions/memeberships
38 */
39 class CRM_Batch_Form_Entry extends CRM_Core_Form {
40
41 /**
42 * maximum profile fields that will be displayed
43 *
44 */
45 protected $_rowCount = 1;
46
47 /**
48 * Batch id
49 */
50 protected $_batchId;
51
52 /**
53 * Batch informtaion
54 */
55 protected $_batchInfo = array();
56
57 /**
58 * store the profile id associated with the batch type
59 */
60 protected $_profileId;
61
62 public $_action;
63
64 public $_mode;
65
66 public $_params;
67
68 public $_membershipId = null;
69 /**
70 * when not to reset sort_name
71 */
72 protected $_preserveDefault = TRUE;
73
74 /**
75 * Contact fields
76 */
77 protected $_contactFields = array();
78
79 /**
80 * build all the data structures needed to build the form
81 *
82 * @return void
83 * @access public
84 */
85 function preProcess() {
86 $this->_batchId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
87
88 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
89
90 if (empty($this->_batchInfo)) {
91 $params = array('id' => $this->_batchId);
92 CRM_Batch_BAO_Batch::retrieve($params, $this->_batchInfo);
93
94 $this->assign('batchTotal', $this->_batchInfo['total']);
95 $this->assign('batchType', $this->_batchInfo['type_id']);
96
97 // get the profile id associted with this batch type
98 $this->_profileId = CRM_Batch_BAO_Batch::getProfileId($this->_batchInfo['type_id']);
99 }
100 }
101
102 /**
103 * Build the form
104 *
105 * @access public
106 *
107 * @return void
108 */
109 function buildQuickForm() {
110 if (!$this->_profileId) {
111 CRM_Core_Error::fatal(ts('Profile for bulk data entry is missing.'));
112 }
113
114 $this->addElement('hidden', 'batch_id', $this->_batchId);
115
116 // get the profile information
117 if ($this->_batchInfo['type_id'] == 1) {
118 CRM_Utils_System::setTitle(ts('Batch Data Entry for Contributions'));
119 $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
120 }
121 else {
122 CRM_Utils_System::setTitle(ts('Batch Data Entry for Memberships'));
123 $customFields = CRM_Core_BAO_CustomField::getFields('Membership');
124 }
125
126 $this->_fields = array();
127 $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW);
128
129 // remove file type field and then limit fields
130 $suppressFields = FALSE;
131 $removehtmlTypes = array('File', 'Autocomplete-Select');
132 foreach ($this->_fields as $name => $field) {
133 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
134 in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
135 ) {
136 $suppressFields = TRUE;
137 unset($this->_fields[$name]);
138 }
139
140 //fix to reduce size as we are using this field in grid
141 if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
142 //shrink class to "form-text-medium"
143 $this->_fields[$name]['attributes']['size'] = 19;
144 }
145 }
146
147 $this->addFormRule(array('CRM_Batch_Form_Entry', 'formRule'), $this);
148
149 // add the force save button
150 $forceSave = $this->getButtonName('upload', 'force');
151
152 $this->addElement('submit',
153 $forceSave,
154 ts('Ignore Mismatch & Process the Batch?')
155 );
156
157 $this->addButtons(array(
158 array(
159 'type' => 'upload',
160 'name' => ts('Validate & Process the Batch'),
161 'isDefault' => TRUE
162 ),
163 array(
164 'type' => 'cancel',
165 'name' => ts('Save & Continue Later'),
166 )
167 )
168 );
169
170 $this->assign('rowCount', $this->_batchInfo['item_count'] + 1);
171
172 $fileFieldExists = FALSE;
173 $preserveDefaultsArray = array(
174 'first_name', 'last_name', 'middle_name',
175 'organization_name',
176 'household_name',
177 );
178
179 $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
180 for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
181 CRM_Contact_Form_NewContact::buildQuickForm($this, $rowNumber, NULL, TRUE, 'primary_', ts('Contact'));
182
183 // special field specific to membership batch udpate
184 if ($this->_batchInfo['type_id'] == 2) {
185 $options = array(
186 1 => ts('Add Membership'),
187 2 => ts('Renew Membership'),
188 );
189 $this->add('select', "member_option[$rowNumber]", '', $options);
190 }
191
192 foreach ($this->_fields as $name => $field) {
193 if (in_array($field['field_type'], $contactTypes)) {
194 $this->_contactFields[$field['name']] = 1;
195 }
196 CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
197
198 if (in_array($field['name'], $preserveDefaultsArray)) {
199 $this->_preserveDefault = FALSE;
200 }
201 }
202 }
203
204 $this->assign('fields', $this->_fields);
205 $this->assign('contactFields', $this->_contactFields);
206
207 // don't set the status message when form is submitted.
208 $buttonName = $this->controller->getButtonName('submit');
209
210 if ($suppressFields && $buttonName != '_qf_Entry_next') {
211 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 have been excluded."), "info");
212 }
213 }
214
215 /**
216 * form validations
217 *
218 * @param array $params posted values of the form
219 * @param array $files list of errors to be posted back to the form
220 * @param array $self form object
221 *
222 * @return array list of errors to be posted back to the form
223 * @static
224 * @access public
225 */
226 static function formRule($params, $files, $self) {
227 $errors = array();
228
229 if (CRM_Utils_Array::value('_qf_Entry_upload_force', $params)) {
230 return TRUE;
231 }
232
233 $batchTotal = 0;
234 foreach ($params['field'] as $key => $value) {
235 $batchTotal += $value['total_amount'];
236
237 //membership type is required for membership batch entry
238 if ( $self->_batchInfo['type_id'] == 2 ) {
239 if ( !CRM_Utils_Array::value( 1, $value['membership_type'] ) ) {
240 $errors["field[$key][membership_type]"] = ts('Membership type is a required field.');
241 }
242 }
243 }
244
245 // if contact name is set for a row using autocomplete widget then make sure contact id exists, CRM-13078
246 // I was not able to replicate this on my local but adding this check and hopefully it will fix the issue.
247 if (!empty($params['primary_contact'])) {
248 foreach($params['primary_contact'] as $rowIndex => $contactName) {
249 if (empty($params['primary_contact_select_id'][$rowIndex])) {
250 $errors['primary_contact['.$rowIndex.']'] = ts('Please select a valid contact.');
251 }
252 }
253 }
254
255 if ($batchTotal != $self->_batchInfo['total']) {
256 $self->assign('batchAmountMismatch', TRUE);
257 $errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.');
258 }
259
260 if (!empty($errors)) {
261 return $errors;
262 }
263
264 $self->assign('batchAmountMismatch', FALSE);
265 return TRUE;
266 }
267
268 /**
269 * Override default cancel action
270 */
271 function cancelAction() {
272 // redirect to batch listing
273 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1'));
274 CRM_Utils_System::civiExit();
275 }
276
277 /**
278 * This function sets the default values for the form.
279 *
280 * @access public
281 *
282 * @return None
283 */
284 function setDefaultValues() {
285 if (empty($this->_fields)) {
286 return;
287 }
288
289 // for add mode set smart defaults
290 if ( $this->_action & CRM_Core_Action::ADD ) {
291 list( $currentDate, $currentTime ) = CRM_Utils_Date::setDateDefaults( NULL, 'activityDateTime' );
292
293 //get all status
294 $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
295 $completeStatus = array_search( 'Completed', $allStatus );
296 $specialFields = array(
297 'join_date' => $currentDate,
298 'receive_date' => $currentDate,
299 'receive_date_time' => $currentTime,
300 'contribution_status_id' => $completeStatus
301 );
302
303 for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
304 foreach ($specialFields as $key => $value ) {
305 $defaults['field'][$rowNumber][$key] = $value;
306 }
307 }
308 }
309 else {
310 // get the existing batch values from cache table
311 $cacheKeyString = CRM_Batch_BAO_Batch::getCacheKeyForBatch($this->_batchId);
312 $defaults = CRM_Core_BAO_Cache::getItem('batch entry', $cacheKeyString);
313 }
314 return $defaults;
315 }
316
317 /**
318 * process the form after the input has been submitted and validated
319 *
320 * @access public
321 *
322 * @return None
323 */
324 public function postProcess() {
325 $params = $this->controller->exportValues($this->_name);
326
327 $params['actualBatchTotal'] = 0;
328
329 // get the profile information
330 if ($this->_batchInfo['type_id'] == 1) {
331 $this->processContribution($params);
332 }
333 else {
334 $this->processMembership($params);
335 }
336
337 // update batch to close status
338 $paramValues = array(
339 'id' => $this->_batchId,
340 // close status
341 'status_id' => 2,
342 'total' => $params['actualBatchTotal'],
343 );
344
345 CRM_Batch_BAO_Batch::create($paramValues);
346
347 // delete from cache table
348 $cacheKeyString = CRM_Batch_BAO_Batch::getCacheKeyForBatch($this->_batchId);
349 CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE);
350
351 // set success status
352 CRM_Core_Session::setStatus("", ts("Batch Processed."), "success");
353
354 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1'));
355 }
356
357 /**
358 * process contribution records
359 *
360 * @param array $params associated array of submitted values
361 *
362 * @access public
363 *
364 * @return None
365 */
366 private function processContribution(&$params) {
367 $dates = array(
368 'receive_date',
369 'receipt_date',
370 'thankyou_date',
371 'cancel_date',
372 );
373
374 // get the price set associated with offline contribution record.
375 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
376 $this->_priceSet = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
377 $fieldID = key($this->_priceSet['fields']);
378
379 if (isset($params['field'])) {
380 foreach ($params['field'] as $key => $value) {
381 // if contact is not selected we should skip the row
382 if (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) {
383 continue;
384 }
385
386 $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
387
388 // update contact information
389 $this->updateContactInfo($value);
390
391 // handle soft credit
392 if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) {
393 $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key];
394 }
395
396 $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value,
397 CRM_Core_DAO::$_nullObject,
398 NULL,
399 'Contribution'
400 );
401
402 foreach ($dates as $val) {
403 if ( CRM_Utils_Array::value( $val, $value ) ) {
404 $value[$val] = CRM_Utils_Date::processDate( $value[$val], $value[$val . '_time'], TRUE );
405 }
406 }
407
408 if (CRM_Utils_Array::value('send_receipt', $value)) {
409 $value['receipt_date'] = date('Y-m-d His');
410 }
411
412 if ($value['financial_type']) {
413 $value['financial_type_id'] = $value['financial_type'];
414 }
415
416 if (CRM_Utils_Array::value('payment_instrument', $value)) {
417 $value['payment_instrument_id'] = $value['payment_instrument'];
418 }
419
420 if (CRM_Utils_Array::value('contribution_source', $value)) {
421 $value['source'] = $value['contribution_source'];
422 }
423
424 if (CRM_Utils_Array::value('contribution_note', $value)) {
425 $value['note'] = $value['contribution_note'];
426 }
427
428 $params['actualBatchTotal'] += $value['total_amount'];
429
430 unset($value['contribution_note']);
431 unset($value['financial_type']);
432 unset($value['contribution_source']);
433
434 $value['batch_id'] = $this->_batchId;
435 $value['skipRecentView'] = TRUE;
436
437 // build line item params
438 $this->_priceSet['fields'][$fieldID]['options'][$fieldID]['amount'] = $value['total_amount'];
439 $value['price_'.$fieldID] = 1;
440
441 $lineItem = array();
442 CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
443
444 //unset amount level since we always use quick config price set
445 unset($value['amount_level']);
446
447 //CRM-11529 for backoffice transactions
448 //when financial_type_id is passed in form, update the
449 //lineitems with the financial type selected in form
450 if (CRM_Utils_Array::value('financial_type_id', $value) && CRM_Utils_Array::value($priceSetId, $lineItem)) {
451 foreach ($lineItem[$priceSetId] as &$values) {
452 $values['financial_type_id'] = $value['financial_type_id'];
453 }
454 }
455 $value['line_item'] = $lineItem;
456
457 //finally call contribution create for all the magic
458 $contribution = CRM_Contribute_BAO_Contribution::create($value, CRM_Core_DAO::$_nullArray);
459
460 //process premiums
461 if (CRM_Utils_Array::value('product_name', $value)) {
462 if ($value['product_name'][0] > 0) {
463 list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
464
465 $value['hidden_Premium'] = 1;
466 $value['product_option'] = CRM_Utils_Array::value(
467 $value['product_name'][1],
468 $options[$value['product_name'][0]]
469 );
470
471 $premiumParams = array(
472 'product_id' => $value['product_name'][0],
473 'contribution_id' => $contribution->id,
474 'product_option' => $value['product_option'],
475 'quantity' => 1,
476 );
477 CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
478 }
479 }
480 // end of premium
481
482 //send receipt mail.
483 if ( $contribution->id &&
484 CRM_Utils_Array::value( 'send_receipt', $value ) ) {
485 // add the domain email id
486 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
487 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
488
489 $value['from_email_address'] = $domainEmail;
490 $value['contribution_id'] = $contribution->id;
491 CRM_Contribute_Form_AdditionalInfo::emailReceipt( $this, $value );
492 }
493 }
494 }
495 }
496 //end of function
497
498 /**
499 * process membership records
500 *
501 * @param array $params associated array of submitted values
502 *
503 * @access public
504 *
505 * @return None
506 */
507 private function processMembership(&$params) {
508 $dateTypes = array(
509 'join_date' => 'joinDate',
510 'membership_start_date' => 'startDate',
511 'membership_end_date' => 'endDate'
512 );
513
514 $dates = array(
515 'join_date',
516 'start_date',
517 'end_date',
518 'reminder_date'
519 );
520
521 // get the price set associated with offline memebership
522 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
523 $this->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
524
525 if (isset($params['field'])) {
526 $customFields = array();
527 foreach ($params['field'] as $key => $value) {
528 // if contact is not selected we should skip the row
529 if (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) {
530 continue;
531 }
532
533 $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
534
535 // update contact information
536 $this->updateContactInfo($value);
537
538 $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
539
540 foreach ($dateTypes as $dateField => $dateVariable) {
541 $$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
542 }
543
544 $calcDates = array();
545 $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId,
546 $joinDate, $startDate, $endDate
547 );
548
549 foreach ($calcDates as $memType => $calcDate) {
550 foreach ($dates as $d) {
551 //first give priority to form values then calDates.
552 $date = CRM_Utils_Array::value($d, $value);
553 if (!$date) {
554 $date = CRM_Utils_Array::value($d, $calcDate);
555 }
556
557 $value[$d] = CRM_Utils_Date::processDate($date);
558 }
559 }
560
561 if (CRM_Utils_Array::value('send_receipt', $value)) {
562 $value['receipt_date'] = date('Y-m-d His');
563 }
564
565 if (CRM_Utils_Array::value('membership_source', $value)) {
566 $value['source'] = $value['membership_source'];
567 }
568
569 unset($value['membership_source']);
570
571 //Get the membership status
572 if ( CRM_Utils_Array::value('membership_status', $value) ) {
573 $value['status_id'] = $value['membership_status'];
574 unset($value['membership_status']);
575 }
576
577 if (empty($customFields)) {
578 // membership type custom data
579 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
580
581 $customFields = CRM_Utils_Array::crmArrayMerge($customFields,
582 CRM_Core_BAO_CustomField::getFields('Membership',
583 FALSE, FALSE, NULL, NULL, TRUE
584 )
585 );
586 }
587
588 //check for custom data
589 $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key],
590 $customFields,
591 $key,
592 'Membership',
593 $membershipTypeId
594 );
595
596 if (CRM_Utils_Array::value('financial_type', $value)) {
597 $value['financial_type_id'] = $value['financial_type'];
598 }
599
600 if (CRM_Utils_Array::value('payment_instrument', $value)) {
601 $value['payment_instrument_id'] = $value['payment_instrument'];
602 }
603
604 // handle soft credit
605 if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) {
606 $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key];
607 }
608
609 if ( CRM_Utils_Array::value('receive_date', $value) ) {
610 $value['receive_date'] = CRM_Utils_Date::processDate( $value['receive_date'], $value['receive_date_time'] , TRUE );
611 }
612
613 $params['actualBatchTotal'] += $value['total_amount'];
614
615 unset($value['financial_type']);
616 unset($value['payment_instrument']);
617
618 $value['batch_id'] = $this->_batchId;
619 $value['skipRecentView'] = TRUE;
620
621 // make entry in line item for contribution
622
623 $editedFieldParams = array(
624 'price_set_id' => $priceSetId,
625 'name' => $value['membership_type'][0]
626 );
627
628 $editedResults = array();
629 CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
630
631 if (!empty($editedResults)) {
632 unset($this->_priceSet['fields']);
633 $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
634 unset($this->_priceSet['fields'][$editedResults['id']]['options']);
635 $fid = $editedResults['id'];
636 $editedFieldParams = array(
637 'price_field_id' => $editedResults['id'],
638 'membership_type_id' => $value['membership_type_id']
639 );
640
641 $editedResults = array();
642 CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
643 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
644 if (CRM_Utils_Array::value('total_amount', $value)) {
645 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
646 }
647
648 $fieldID = key($this->_priceSet['fields']);
649 $value['price_' . $fieldID] = $editedResults['id'];
650
651 $lineItem = array();
652 CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'],
653 $value, $lineItem[$priceSetId]
654 );
655
656 //CRM-11529 for backoffice transactions
657 //when financial_type_id is passed in form, update the
658 //lineitems with the financial type selected in form
659 if (CRM_Utils_Array::value('financial_type_id', $value) && CRM_Utils_Array::value($priceSetId, $lineItem)) {
660 foreach ($lineItem[$priceSetId] as &$values) {
661 $values['financial_type_id'] = $value['financial_type_id'];
662 }
663 }
664
665 $value['lineItems'] = $lineItem;
666 $value['processPriceSet'] = TRUE;
667 }
668 // end of contribution related section
669
670 unset($value['membership_type']);
671 unset($value['membership_start_date']);
672 unset($value['membership_end_date']);
673
674 $value['is_renew'] = false;
675 if ( CRM_Utils_Array::value('member_option', $params) && CRM_Utils_Array::value( $key, $params['member_option'] ) == 2 ) {
676 $this->_params = $params;
677 $value['is_renew'] = true;
678 $membership = CRM_Member_BAO_Membership::renewMembership(
679 $value['contact_id'],
680 $value['membership_type_id'],
681 FALSE, $this, NULL, NULL,
682 $value['custom']
683 );
684
685 // make contribution entry
686 CRM_Member_BAO_Membership::recordMembershipContribution( $value, CRM_Core_DAO::$_nullArray, $membership->id );
687 }
688 else {
689 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
690 }
691
692 //process premiums
693 if (CRM_Utils_Array::value('product_name', $value)) {
694 if ($value['product_name'][0] > 0) {
695 list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
696
697 $value['hidden_Premium'] = 1;
698 $value['product_option'] = CRM_Utils_Array::value(
699 $value['product_name'][1],
700 $options[$value['product_name'][0]]
701 );
702
703 $premiumParams = array(
704 'product_id' => $value['product_name'][0],
705 'contribution_id' => $value['contribution_id'],
706 'product_option' => $value['product_option'],
707 'quantity' => 1,
708 );
709 CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
710 }
711 }
712 // end of premium
713
714 //send receipt mail.
715 if ( $membership->id &&
716 CRM_Utils_Array::value( 'send_receipt', $value ) ) {
717
718 // add the domain email id
719 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
720 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
721
722 $value['from_email_address'] = $domainEmail;
723 $value['membership_id'] = $membership->id;
724 CRM_Member_Form_Membership::emailReceipt( $this, $value, $membership );
725 }
726 }
727 }
728 }
729
730 /**
731 * update contact information
732 *
733 * @param array $value associated array of submitted values
734 *
735 * @access public
736 *
737 * @return None
738 */
739 private function updateContactInfo(&$value) {
740 $value['preserveDBName'] = $this->_preserveDefault;
741
742 //parse street address, CRM-7768
743 CRM_Contact_Form_Task_Batch::parseStreetAddress($value, $this);
744
745 CRM_Contact_BAO_Contact::createProfileContact($value, $this->_fields,
746 $value['contact_id']
747 );
748 }
749 }
750