3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 'total_amount' => 'Amount',
285 'financial_type' => 'Financial Type',
286 'payment_instrument' => 'Paid By',
289 //CRM-16480 if contact is selected, validate financial type and amount field.
290 foreach ($params['field'] as $key => $value) {
291 foreach ($fields as $field => $label) {
292 if (!empty($params['primary_contact_id'][$key]) && empty($value[$field])) {
293 $errors["field[$key][$field]"] = ts('%1 is a required field.', array(1 => $label));
298 if (!empty($params['_qf_Entry_upload_force'])) {
299 if (!empty($errors)) {
306 foreach ($params['field'] as $key => $value) {
307 $batchTotal +
= $value['total_amount'];
309 //validate for soft credit fields
310 if (!empty($params['soft_credit_contact_id'][$key]) && empty($params['soft_credit_amount'][$key])) {
311 $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
313 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'])) {
314 $errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount');
317 //membership type is required for membership batch entry
318 if ($self->_batchInfo
['type_id'] == $batchTypes['Membership']) {
319 if (empty($value['membership_type'][1])) {
320 $errors["field[$key][membership_type]"] = ts('Membership type is a required field.');
324 if ($self->_batchInfo
['type_id'] == $batchTypes['Pledge Payment']) {
325 foreach (array_unique($params["open_pledges"]) as $value) {
326 $duplicateRows = array_keys($params["open_pledges"], $value);
327 if (count($duplicateRows) > 1) {
328 foreach ($duplicateRows as $key) {
329 $errors["open_pledges[$key]"] = ts('You can not record two payments for the same pledge in a single batch.');
334 if ((string) $batchTotal != $self->_batchInfo
['total']) {
335 $self->assign('batchAmountMismatch', TRUE);
336 $errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.');
339 if (!empty($errors)) {
343 $self->assign('batchAmountMismatch', FALSE);
348 * Override default cancel action.
350 public function cancelAction() {
351 // redirect to batch listing
352 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/batch', 'reset=1'));
353 CRM_Utils_System
::civiExit();
357 * Set default values for the form.
362 public function setDefaultValues() {
363 if (empty($this->_fields
)) {
367 // for add mode set smart defaults
368 if ($this->_action
& CRM_Core_Action
::ADD
) {
369 list($currentDate, $currentTime) = CRM_Utils_Date
::setDateDefaults(NULL, 'activityDateTime');
372 $allStatus = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
373 $completeStatus = array_search('Completed', $allStatus);
374 $specialFields = array(
375 'join_date' => $currentDate,
376 'receive_date' => $currentDate,
377 'receive_date_time' => $currentTime,
378 'contribution_status_id' => $completeStatus,
381 for ($rowNumber = 1; $rowNumber <= $this->_batchInfo
['item_count']; $rowNumber++
) {
382 foreach ($specialFields as $key => $value) {
383 $defaults['field'][$rowNumber][$key] = $value;
388 // get the cached info from data column of civicrm_batch
389 $data = CRM_Core_DAO
::getFieldValue('CRM_Batch_BAO_Batch', $this->_batchId
, 'data');
390 $defaults = json_decode($data, TRUE);
391 $defaults = $defaults['values'];
398 * Process the form after the input has been submitted and validated.
403 public function postProcess() {
404 $params = $this->controller
->exportValues($this->_name
);
405 $params['actualBatchTotal'] = 0;
407 // get the profile information
408 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
409 if (in_array($this->_batchInfo
['type_id'], array($batchTypes['Pledge Payment'], $batchTypes['Contribution']))) {
410 $this->processContribution($params);
412 elseif ($this->_batchInfo
['type_id'] == $batchTypes['Membership']) {
413 $this->processMembership($params);
416 // update batch to close status
417 $paramValues = array(
418 'id' => $this->_batchId
,
420 'status_id' => CRM_Core_OptionGroup
::getValue('batch_status', 'Closed', 'name'),
421 'total' => $params['actualBatchTotal'],
424 CRM_Batch_BAO_Batch
::create($paramValues);
426 // set success status
427 CRM_Core_Session
::setStatus("", ts("Batch Processed."), "success");
429 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/batch', 'reset=1'));
433 * Process contribution records.
435 * @param array $params
436 * Associated array of submitted values.
441 private function processContribution(&$params) {
449 // get the price set associated with offline contribution record.
450 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
451 $this->_priceSet
= current(CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId));
452 $priceFieldID = CRM_Price_BAO_PriceSet
::getOnlyPriceFieldID($this->_priceSet
);
453 $priceFieldValueID = CRM_Price_BAO_PriceSet
::getOnlyPriceFieldValueID($this->_priceSet
);
455 if (isset($params['field'])) {
456 foreach ($params['field'] as $key => $value) {
457 // if contact is not selected we should skip the row
458 if (empty($params['primary_contact_id'][$key])) {
462 $value['contact_id'] = CRM_Utils_Array
::value($key, $params['primary_contact_id']);
464 // update contact information
465 $this->updateContactInfo($value);
467 //build soft credit params
468 if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
469 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
470 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule
::cleanMoney($params['soft_credit_amount'][$key]);
472 //CRM-15350: if soft-credit-type profile field is disabled or removed then
473 //we choose configured SCT default value
474 if (!empty($params['soft_credit_type'][$key])) {
475 $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
478 $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup
::getDefaultValue("soft_credit_type");
482 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($value,
483 CRM_Core_DAO
::$_nullObject,
488 foreach ($dates as $val) {
489 if (!empty($value[$val])) {
490 $value[$val] = CRM_Utils_Date
::processDate($value[$val], $value[$val . '_time'], TRUE);
494 if (!empty($value['send_receipt'])) {
495 $value['receipt_date'] = date('Y-m-d His');
497 // these translations & date handling are required because we are calling BAO directly rather than the api
498 $fieldTranslations = array(
499 'financial_type' => 'financial_type_id',
500 'payment_instrument' => 'payment_instrument_id',
501 'contribution_source' => 'source',
502 'contribution_note' => 'note',
505 foreach ($fieldTranslations as $formField => $baoField) {
506 if (isset($value[$formField])) {
507 $value[$baoField] = $value[$formField];
509 unset($value[$formField]);
512 $params['actualBatchTotal'] +
= $value['total_amount'];
513 $value['batch_id'] = $this->_batchId
;
514 $value['skipRecentView'] = TRUE;
516 // build line item params
517 $this->_priceSet
['fields'][$priceFieldID]['options'][$priceFieldValueID]['amount'] = $value['total_amount'];
518 $value['price_' . $priceFieldID] = 1;
521 CRM_Price_BAO_PriceSet
::processAmount($this->_priceSet
['fields'], $value, $lineItem[$priceSetId]);
523 //unset amount level since we always use quick config price set
524 unset($value['amount_level']);
526 //CRM-11529 for back office transactions
527 //when financial_type_id is passed in form, update the
528 //line items with the financial type selected in form
529 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
530 foreach ($lineItem[$priceSetId] as &$values) {
531 $values['financial_type_id'] = $value['financial_type_id'];
534 $value['line_item'] = $lineItem;
535 //finally call contribution create for all the magic
536 $contribution = CRM_Contribute_BAO_Contribution
::create($value, CRM_Core_DAO
::$_nullArray);
537 $batchTypes = CRM_Core_Pseudoconstant
::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
538 if (!empty($this->_batchInfo
['type_id']) && ($this->_batchInfo
['type_id'] == $batchTypes['Pledge Payment'])) {
539 $adjustTotalAmount = FALSE;
540 if (isset($params['option_type'][$key])) {
541 if ($params['option_type'][$key] == 2) {
542 $adjustTotalAmount = TRUE;
545 $pledgeId = $params['open_pledges'][$key];
546 if (is_numeric($pledgeId)) {
547 $result = CRM_Pledge_BAO_PledgePayment
::getPledgePayments($pledgeId);
548 $pledgePaymentId = 0;
549 foreach ($result as $key => $values) {
550 if ($values['status'] != 'Completed') {
551 $pledgePaymentId = $values['id'];
555 CRM_Core_DAO
::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentId, 'contribution_id', $contribution->id
);
556 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($pledgeId,
557 array($pledgePaymentId),
558 $contribution->contribution_status_id
,
560 $contribution->total_amount
,
567 if (!empty($value['product_name'])) {
568 if ($value['product_name'][0] > 0) {
569 list($products, $options) = CRM_Contribute_BAO_Premium
::getPremiumProductInfo();
571 $value['hidden_Premium'] = 1;
572 $value['product_option'] = CRM_Utils_Array
::value(
573 $value['product_name'][1],
574 $options[$value['product_name'][0]]
577 $premiumParams = array(
578 'product_id' => $value['product_name'][0],
579 'contribution_id' => $contribution->id
,
580 'product_option' => $value['product_option'],
583 CRM_Contribute_BAO_Contribution
::addPremium($premiumParams);
589 if ($contribution->id
&& !empty($value['send_receipt'])) {
590 // add the domain email id
591 $domainEmail = CRM_Core_BAO_Domain
::getNameAndEmail();
592 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
593 $value['from_email_address'] = $domainEmail;
594 $value['contribution_id'] = $contribution->id
;
595 CRM_Contribute_Form_AdditionalInfo
::emailReceipt($this, $value);
603 * Process membership records.
605 * @param array $params
606 * Associated array of submitted values.
611 private function processMembership(&$params) {
613 'join_date' => 'joinDate',
614 'membership_start_date' => 'startDate',
615 'membership_end_date' => 'endDate',
625 // get the price set associated with offline memebership
626 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
627 $this->_priceSet
= $priceSets = current(CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId));
629 if (isset($params['field'])) {
630 $customFields = array();
631 foreach ($params['field'] as $key => $value) {
632 // if contact is not selected we should skip the row
633 if (empty($params['primary_contact_id'][$key])) {
637 $value['contact_id'] = CRM_Utils_Array
::value($key, $params['primary_contact_id']);
639 // update contact information
640 $this->updateContactInfo($value);
642 $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
644 foreach ($dateTypes as $dateField => $dateVariable) {
645 $
$dateVariable = CRM_Utils_Date
::processDate($value[$dateField]);
648 $calcDates = array();
649 $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType
::getDatesForMembershipType($membershipTypeId,
650 $joinDate, $startDate, $endDate
653 foreach ($calcDates as $memType => $calcDate) {
654 foreach ($dates as $d) {
655 //first give priority to form values then calDates.
656 $date = CRM_Utils_Array
::value($d, $value);
658 $date = CRM_Utils_Array
::value($d, $calcDate);
661 $value[$d] = CRM_Utils_Date
::processDate($date);
665 if (!empty($value['send_receipt'])) {
666 $value['receipt_date'] = date('Y-m-d His');
669 if (!empty($value['membership_source'])) {
670 $value['source'] = $value['membership_source'];
673 unset($value['membership_source']);
675 //Get the membership status
676 if (!empty($value['membership_status'])) {
677 $value['status_id'] = $value['membership_status'];
678 unset($value['membership_status']);
681 if (empty($customFields)) {
682 // membership type custom data
683 $customFields = CRM_Core_BAO_CustomField
::getFields('Membership', FALSE, FALSE, $membershipTypeId);
685 $customFields = CRM_Utils_Array
::crmArrayMerge($customFields,
686 CRM_Core_BAO_CustomField
::getFields('Membership',
687 FALSE, FALSE, NULL, NULL, TRUE
692 //check for custom data
693 $value['custom'] = CRM_Core_BAO_CustomField
::postProcess($params['field'][$key],
700 if (!empty($value['financial_type'])) {
701 $value['financial_type_id'] = $value['financial_type'];
704 if (!empty($value['payment_instrument'])) {
705 $value['payment_instrument_id'] = $value['payment_instrument'];
708 // handle soft credit
709 if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
710 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
711 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule
::cleanMoney($params['soft_credit_amount'][$key]);
713 //CRM-15350: if soft-credit-type profile field is disabled or removed then
714 //we choose Gift as default value as per Gift Membership rule
715 if (!empty($params['soft_credit_type'][$key])) {
716 $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
719 $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup
::getValue('soft_credit_type', 'Gift', 'name');
723 if (!empty($value['receive_date'])) {
724 $value['receive_date'] = CRM_Utils_Date
::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
727 $params['actualBatchTotal'] +
= $value['total_amount'];
729 unset($value['financial_type']);
730 unset($value['payment_instrument']);
732 $value['batch_id'] = $this->_batchId
;
733 $value['skipRecentView'] = TRUE;
735 // make entry in line item for contribution
737 $editedFieldParams = array(
738 'price_set_id' => $priceSetId,
739 'name' => $value['membership_type'][0],
742 $editedResults = array();
743 CRM_Price_BAO_PriceField
::retrieve($editedFieldParams, $editedResults);
745 if (!empty($editedResults)) {
746 unset($this->_priceSet
['fields']);
747 $this->_priceSet
['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
748 unset($this->_priceSet
['fields'][$editedResults['id']]['options']);
749 $fid = $editedResults['id'];
750 $editedFieldParams = array(
751 'price_field_id' => $editedResults['id'],
752 'membership_type_id' => $value['membership_type_id'],
755 $editedResults = array();
756 CRM_Price_BAO_PriceFieldValue
::retrieve($editedFieldParams, $editedResults);
757 $this->_priceSet
['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
758 if (!empty($value['total_amount'])) {
759 $this->_priceSet
['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
762 $fieldID = key($this->_priceSet
['fields']);
763 $value['price_' . $fieldID] = $editedResults['id'];
766 CRM_Price_BAO_PriceSet
::processAmount($this->_priceSet
['fields'],
767 $value, $lineItem[$priceSetId]
770 //CRM-11529 for backoffice transactions
771 //when financial_type_id is passed in form, update the
772 //lineitems with the financial type selected in form
773 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
774 foreach ($lineItem[$priceSetId] as &$values) {
775 $values['financial_type_id'] = $value['financial_type_id'];
779 $value['lineItems'] = $lineItem;
780 $value['processPriceSet'] = TRUE;
782 // end of contribution related section
784 unset($value['membership_type']);
785 unset($value['membership_start_date']);
786 unset($value['membership_end_date']);
788 $value['is_renew'] = FALSE;
789 if (!empty($params['member_option']) && CRM_Utils_Array
::value($key, $params['member_option']) == 2) {
790 $this->_params
= $params;
791 $value['is_renew'] = TRUE;
792 $membership = CRM_Member_BAO_Membership
::renewMembershipFormWrapper(
793 $value['contact_id'],
794 $value['membership_type_id'],
795 FALSE, $this, NULL, NULL,
799 // make contribution entry
800 $contrbutionParams = array_merge($value, array('membership_id' => $membership->id
));
801 CRM_Member_BAO_Membership
::recordMembershipContribution($contrbutionParams);
804 $membership = CRM_Member_BAO_Membership
::create($value, CRM_Core_DAO
::$_nullArray);
808 if (!empty($value['product_name'])) {
809 if ($value['product_name'][0] > 0) {
810 list($products, $options) = CRM_Contribute_BAO_Premium
::getPremiumProductInfo();
812 $value['hidden_Premium'] = 1;
813 $value['product_option'] = CRM_Utils_Array
::value(
814 $value['product_name'][1],
815 $options[$value['product_name'][0]]
818 $premiumParams = array(
819 'product_id' => $value['product_name'][0],
820 'contribution_id' => CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id
, 'contribution_id', 'membership_id'),
821 'product_option' => $value['product_option'],
824 CRM_Contribute_BAO_Contribution
::addPremium($premiumParams);
830 if ($membership->id
&& !empty($value['send_receipt'])) {
832 // add the domain email id
833 $domainEmail = CRM_Core_BAO_Domain
::getNameAndEmail();
834 $domainEmail = "$domainEmail[0] <$domainEmail[1]>";
836 $value['from_email_address'] = $domainEmail;
837 $value['membership_id'] = $membership->id
;
838 $value['contribution_id'] = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id
, 'contribution_id', 'membership_id');
839 CRM_Member_Form_Membership
::emailReceipt($this, $value, $membership);
847 * Update contact information.
849 * @param array $value
850 * Associated array of submitted values.
855 private function updateContactInfo(&$value) {
856 $value['preserveDBName'] = $this->_preserveDefault
;
858 //parse street address, CRM-7768
859 CRM_Contact_Form_Task_Batch
::parseStreetAddress($value, $this);
861 CRM_Contact_BAO_Contact
::createProfileContact($value, $this->_fields
,
867 * Function exists purely for unit testing purposes. If you feel tempted to use this in live code
868 * then it probably means there is some functionality that needs to be moved
869 * out of the form layer
871 * @param array $params
875 public function testProcessMembership($params) {
876 return $this->processMembership($params);
880 * Function exists purely for unit testing purposes. If you feel tempted to use this in live code
881 * then it probably means there is some functionality that needs to be moved
882 * out of the form layer
884 * @param array $params
888 public function testProcessContribution($params) {
889 return $this->processContribution($params);