| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | Copyright CiviCRM LLC. All rights reserved. | |
| 6 | | | |
| 7 | | This work is published under the GNU AGPLv3 license with some | |
| 8 | | permitted exceptions and without any warranty. For full license | |
| 9 | | and copyright information, see https://civicrm.org/licensing | |
| 10 | +--------------------------------------------------------------------+ |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * |
| 15 | * @package CRM |
| 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * This class generates form components to transfer an Event to another participant |
| 21 | * |
| 22 | */ |
| 23 | class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { |
| 24 | /** |
| 25 | * from participant id |
| 26 | * |
| 27 | * @var string |
| 28 | * |
| 29 | */ |
| 30 | protected $_from_participant_id; |
| 31 | /** |
| 32 | * from contact id |
| 33 | * |
| 34 | * @var string |
| 35 | * |
| 36 | */ |
| 37 | protected $_from_contact_id; |
| 38 | /** |
| 39 | * last name of the participant to transfer to |
| 40 | * |
| 41 | * @var string |
| 42 | * |
| 43 | */ |
| 44 | protected $_to_contact_last_name; |
| 45 | /** |
| 46 | * first name of the participant to transfer to |
| 47 | * |
| 48 | * @var string |
| 49 | * |
| 50 | */ |
| 51 | protected $_to_contact_first_name; |
| 52 | /** |
| 53 | * email of participant |
| 54 | * |
| 55 | * |
| 56 | * @var string |
| 57 | */ |
| 58 | protected $_to_contact_email; |
| 59 | /** |
| 60 | * _to_contact_id |
| 61 | * |
| 62 | * @var string |
| 63 | */ |
| 64 | protected $_to_contact_id; |
| 65 | /** |
| 66 | * event to be cancelled/transferred |
| 67 | * |
| 68 | * @var string |
| 69 | */ |
| 70 | protected $_event_id; |
| 71 | /** |
| 72 | * event title |
| 73 | * |
| 74 | * @var string |
| 75 | */ |
| 76 | protected $_event_title; |
| 77 | /** |
| 78 | * event title |
| 79 | * |
| 80 | * @var string |
| 81 | */ |
| 82 | protected $_event_start_date; |
| 83 | /** |
| 84 | * action |
| 85 | * |
| 86 | * @var string |
| 87 | */ |
| 88 | public $_action; |
| 89 | /** |
| 90 | * participant object |
| 91 | * |
| 92 | * @var string |
| 93 | */ |
| 94 | protected $_participant = []; |
| 95 | /** |
| 96 | * participant values |
| 97 | * |
| 98 | * @var string |
| 99 | */ |
| 100 | protected $_part_values; |
| 101 | /** |
| 102 | * details |
| 103 | * |
| 104 | * @var array |
| 105 | */ |
| 106 | protected $_details = []; |
| 107 | /** |
| 108 | * line items |
| 109 | * |
| 110 | * @var array |
| 111 | */ |
| 112 | protected $_line_items = []; |
| 113 | /** |
| 114 | * contact_id |
| 115 | * |
| 116 | * @var int |
| 117 | */ |
| 118 | protected $contact_id; |
| 119 | |
| 120 | /** |
| 121 | * Is backoffice form? |
| 122 | * |
| 123 | * @var bool |
| 124 | */ |
| 125 | protected $isBackoffice = FALSE; |
| 126 | |
| 127 | /** |
| 128 | * Get source values for transfer based on participant id in URL. Line items will |
| 129 | * be transferred to this participant - at this point no transaction changes processed |
| 130 | * |
| 131 | * return @void |
| 132 | * |
| 133 | * @throws \CRM_Core_Exception |
| 134 | */ |
| 135 | public function preProcess() { |
| 136 | $session = CRM_Core_Session::singleton(); |
| 137 | $this->_userContext = $session->readUserContext(); |
| 138 | $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); |
| 139 | $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); |
| 140 | $this->isBackoffice = CRM_Utils_Request::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST') ?? FALSE; |
| 141 | $params = ['id' => $this->_from_participant_id]; |
| 142 | $participant = $values = []; |
| 143 | $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); |
| 144 | $this->_part_values = $values[$this->_from_participant_id]; |
| 145 | $this->set('values', $this->_part_values); |
| 146 | $this->_event_id = $this->_part_values['event_id']; |
| 147 | $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); |
| 148 | $this->_from_contact_id = $this->_part_values['participant_contact_id']; |
| 149 | $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_from_contact_id, $this->_userChecksum); |
| 150 | if (!$validUser && !CRM_Core_Permission::check('edit all events')) { |
| 151 | CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url); |
| 152 | } |
| 153 | $this->assign('action', $this->_action); |
| 154 | if ($this->_from_participant_id) { |
| 155 | $this->assign('participantId', $this->_from_participant_id); |
| 156 | } |
| 157 | |
| 158 | $daoName = 'title'; |
| 159 | $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); |
| 160 | $daoName = 'start_date'; |
| 161 | $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); |
| 162 | [$displayName, $email] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); |
| 163 | $this->_contact_name = $displayName; |
| 164 | $this->_contact_email = $email; |
| 165 | |
| 166 | $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id); |
| 167 | $selfServiceDetails = CRM_Event_BAO_Participant::getSelfServiceEligibility($this->_from_participant_id, $url, $this->isBackoffice); |
| 168 | if (!$selfServiceDetails['eligible']) { |
| 169 | CRM_Core_Error::statusBounce($selfServiceDetails['ineligible_message'], $url, ts('Sorry')); |
| 170 | } |
| 171 | $details = array_merge($details, $selfServiceDetails); |
| 172 | $this->assign('details', $details); |
| 173 | //This participant row will be cancelled. Get line item(s) to cancel |
| 174 | $this->selfsvctransferUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', |
| 175 | "reset=1&id={$this->_from_participant_id}&id=0"); |
| 176 | $this->selfsvctransferText = ts('Update'); |
| 177 | $this->selfsvctransferButtonText = ts('Update'); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Build form for input of transferree email, name |
| 182 | * |
| 183 | * return @void |
| 184 | */ |
| 185 | public function buildQuickForm() { |
| 186 | // use entityRef select field for contact when this form is used by staff/admin user |
| 187 | if ($this->isBackoffice) { |
| 188 | $this->addEntityRef("contact_id", ts('Select Contact'), ['create' => TRUE], TRUE); |
| 189 | } |
| 190 | // for front-end user show and use the basic three fields used to create a contact |
| 191 | else { |
| 192 | $this->add('text', 'email', ts('To Email'), $this->_contact_email, TRUE); |
| 193 | $this->add('text', 'last_name', ts('To Last Name'), $this->_to_contact_last_name, TRUE); |
| 194 | $this->add('text', 'first_name', ts('To First Name'), $this->_to_contact_first_name, TRUE); |
| 195 | } |
| 196 | |
| 197 | $this->addButtons([ |
| 198 | [ |
| 199 | 'type' => 'submit', |
| 200 | 'name' => ts('Transfer Registration'), |
| 201 | ], |
| 202 | ]); |
| 203 | $this->addFormRule(['CRM_Event_Form_SelfSvcTransfer', 'formRule'], $this); |
| 204 | parent::buildQuickForm(); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Set defaults |
| 209 | * |
| 210 | * return @array _defaults |
| 211 | */ |
| 212 | public function setDefaultValues() { |
| 213 | $this->_defaults = []; |
| 214 | return $this->_defaults; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Validate email and name input |
| 219 | * |
| 220 | * return array $errors |
| 221 | */ |
| 222 | public static function formRule($fields, $files, $self) { |
| 223 | $errors = []; |
| 224 | if (!empty($fields['contact_id'])) { |
| 225 | $to_contact_id = $fields['contact_id']; |
| 226 | } |
| 227 | else { |
| 228 | //check that either an email or firstname+lastname is included in the form(CRM-9587) |
| 229 | $to_contact_id = self::checkProfileComplete($fields, $errors, $self); |
| 230 | } |
| 231 | //To check if the user is already registered for the event(CRM-2426) |
| 232 | if (!empty($to_contact_id)) { |
| 233 | self::checkRegistration($fields, $self, $to_contact_id, $errors); |
| 234 | } |
| 235 | //return parent::formrule($fields, $files, $self); |
| 236 | return empty($errors) ? TRUE : $errors; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Check whether profile (name, email) is complete |
| 241 | * |
| 242 | * return $contact_id |
| 243 | */ |
| 244 | public static function checkProfileComplete($fields, &$errors, $self) { |
| 245 | $email = ''; |
| 246 | foreach ($fields as $fieldname => $fieldvalue) { |
| 247 | if (substr($fieldname, 0, 5) == 'email' && $fieldvalue) { |
| 248 | $email = $fieldvalue; |
| 249 | } |
| 250 | } |
| 251 | if (empty($email) && (empty($fields['first_name']) || empty($fields['last_name']))) { |
| 252 | $message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form."); |
| 253 | $errors['_qf_default'] = $message; |
| 254 | } |
| 255 | $contact = CRM_Contact_BAO_Contact::matchContactOnEmail($email, ""); |
| 256 | $contact_id = empty($contact->contact_id) ? NULL : $contact->contact_id; |
| 257 | if (!CRM_Utils_Rule::email($fields['email'])) { |
| 258 | $errors['email'] = ts('Enter valid email address.'); |
| 259 | } |
| 260 | if (empty($errors) && empty($contact_id)) { |
| 261 | $params = [ |
| 262 | 'email-Primary' => $fields['email'] ?? NULL, |
| 263 | 'first_name' => $fields['first_name'] ?? NULL, |
| 264 | 'last_name' => $fields['last_name'] ?? NULL, |
| 265 | 'is_deleted' => $fields['is_deleted'] ?? FALSE, |
| 266 | ]; |
| 267 | //create new contact for this name/email pair |
| 268 | //if new contact, no need to check for contact already registered |
| 269 | $contact_id = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id); |
| 270 | } |
| 271 | return $contact_id; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Check contact details |
| 276 | * |
| 277 | * return @void |
| 278 | */ |
| 279 | public static function checkRegistration($fields, $self, $contact_id, &$errors) { |
| 280 | // verify whether this contact already registered for this event |
| 281 | $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); |
| 282 | $display_name = $contact_details[0]; |
| 283 | $query = 'select event_id from civicrm_participant where contact_id = ' . $contact_id; |
| 284 | $dao = CRM_Core_DAO::executeQuery($query); |
| 285 | while ($dao->fetch()) { |
| 286 | $to_event_id[] = $dao->event_id; |
| 287 | } |
| 288 | if (!empty($to_event_id)) { |
| 289 | foreach ($to_event_id as $id) { |
| 290 | if ($id == $self->_event_id) { |
| 291 | $errors['email'] = $display_name . ts(" is already registered for this event"); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Process transfer - first add the new participant to the event, then cancel |
| 299 | * source participant - send confirmation email to transferee |
| 300 | * |
| 301 | * @throws \CiviCRM_API3_Exception |
| 302 | */ |
| 303 | public function postProcess() { |
| 304 | //For transfer, process form to allow selection of transferree |
| 305 | $params = $this->controller->exportValues($this->_name); |
| 306 | if (!empty($params['contact_id'])) { |
| 307 | $contact_id = $params['contact_id']; |
| 308 | } |
| 309 | else { |
| 310 | //cancel 'from' participant row |
| 311 | $contact_id_result = civicrm_api3('Contact', 'get', [ |
| 312 | 'sequential' => 1, |
| 313 | 'return' => ['id'], |
| 314 | 'email' => $params['email'], |
| 315 | 'options' => ['limit' => 1], |
| 316 | ]); |
| 317 | $contact_id_result = $contact_id_result['values'][0]; |
| 318 | $contact_id = $contact_id_result['contact_id']; |
| 319 | $contact_is_deleted = $contact_id_result['contact_is_deleted']; |
| 320 | if ($contact_is_deleted || !is_numeric($contact_id)) { |
| 321 | CRM_Core_Error::statusBounce(ts('Contact does not exist.')); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | $this->transferParticipantRegistration($contact_id, $this->_from_participant_id); |
| 326 | |
| 327 | $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); |
| 328 | $display_name = current($contact_details); |
| 329 | $this->assign('to_participant', $display_name); |
| 330 | $this->sendCancellation(); |
| 331 | list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id); |
| 332 | $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $displayName]); |
| 333 | $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', [1 => $email]); |
| 334 | CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success'); |
| 335 | if ($this->isBackoffice) { |
| 336 | return; |
| 337 | } |
| 338 | $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); |
| 339 | CRM_Utils_System::redirect($url); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Based on input, create participant row for transferee and send email |
| 344 | * |
| 345 | * @param CRM_Event_BAO_Participant $participant |
| 346 | * |
| 347 | * @throws \API_Exception |
| 348 | * @throws \CRM_Core_Exception |
| 349 | * @throws \CiviCRM_API3_Exception |
| 350 | */ |
| 351 | public function participantTransfer($participant): void { |
| 352 | $contactDetails = civicrm_api3('Contact', 'getsingle', ['id' => $participant->contact_id, 'return' => ['display_name', 'email']]); |
| 353 | |
| 354 | $participantRoles = CRM_Event_PseudoConstant::participantRole(); |
| 355 | $participantDetails = []; |
| 356 | $query = 'SELECT * FROM civicrm_participant WHERE id = ' . $participant->id; |
| 357 | $dao = CRM_Core_DAO::executeQuery($query); |
| 358 | while ($dao->fetch()) { |
| 359 | $participantDetails[$dao->id] = [ |
| 360 | 'id' => $dao->id, |
| 361 | 'role' => $participantRoles[$dao->role_id], |
| 362 | 'is_test' => $dao->is_test, |
| 363 | 'event_id' => $dao->event_id, |
| 364 | 'status_id' => $dao->status_id, |
| 365 | 'fee_amount' => $dao->fee_amount, |
| 366 | 'contact_id' => $dao->contact_id, |
| 367 | 'register_date' => $dao->register_date, |
| 368 | 'registered_by_id' => $dao->registered_by_id, |
| 369 | ]; |
| 370 | } |
| 371 | |
| 372 | $eventDetails = []; |
| 373 | $eventParams = ['id' => $participant->event_id]; |
| 374 | CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails); |
| 375 | |
| 376 | CRM_Event_BAO_Event::setOutputTimeZone($eventDetails); |
| 377 | |
| 378 | //get default participant role. |
| 379 | $eventDetails['participant_role'] = $participantRoles[$eventDetails['default_role_id']] ?? NULL; |
| 380 | //get the location info |
| 381 | $locParams = [ |
| 382 | 'entity_id' => $participant->event_id, |
| 383 | 'entity_table' => 'civicrm_event', |
| 384 | ]; |
| 385 | $eventDetails['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); |
| 386 | $toEmail = $contactDetails['email'] ?? NULL; |
| 387 | if ($toEmail) { |
| 388 | //take a receipt from as event else domain. |
| 389 | $receiptFrom = CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE); |
| 390 | $receiptFrom = reset($receiptFrom); |
| 391 | if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) { |
| 392 | $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; |
| 393 | } |
| 394 | $participantName = $contactDetails['display_name']; |
| 395 | $tplParams = [ |
| 396 | 'event' => $eventDetails, |
| 397 | 'participant' => $participantDetails[$participant->id], |
| 398 | 'participantID' => $participant->id, |
| 399 | 'participant_status' => 'Registered', |
| 400 | ]; |
| 401 | |
| 402 | $sendTemplateParams = [ |
| 403 | 'groupName' => 'msg_tpl_workflow_event', |
| 404 | 'valueName' => 'event_online_receipt', |
| 405 | 'contactId' => $participantDetails[$participant->id]['contact_id'], |
| 406 | 'tplParams' => $tplParams, |
| 407 | 'from' => $receiptFrom, |
| 408 | 'toName' => $participantName, |
| 409 | 'toEmail' => $toEmail, |
| 410 | 'cc' => $eventDetails['cc_confirm'] ?? NULL, |
| 411 | 'bcc' => $eventDetails['bcc_confirm'] ?? NULL, |
| 412 | ]; |
| 413 | CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Send confirmation of cancellation to source participant |
| 419 | * |
| 420 | * return @ void |
| 421 | */ |
| 422 | public function sendCancellation() { |
| 423 | $participantRoles = CRM_Event_PseudoConstant::participantRole(); |
| 424 | $participantDetails = []; |
| 425 | $query = "SELECT * FROM civicrm_participant WHERE id = {$this->_from_participant_id}"; |
| 426 | $dao = CRM_Core_DAO::executeQuery($query); |
| 427 | while ($dao->fetch()) { |
| 428 | $participantDetails[$dao->id] = [ |
| 429 | 'id' => $dao->id, |
| 430 | 'role' => $participantRoles[$dao->role_id], |
| 431 | 'is_test' => $dao->is_test, |
| 432 | 'event_id' => $dao->event_id, |
| 433 | 'status_id' => $dao->status_id, |
| 434 | 'fee_amount' => $dao->fee_amount, |
| 435 | 'contact_id' => $dao->contact_id, |
| 436 | 'register_date' => $dao->register_date, |
| 437 | 'registered_by_id' => $dao->registered_by_id, |
| 438 | ]; |
| 439 | } |
| 440 | $eventDetails = []; |
| 441 | $eventParams = ['id' => $this->_event_id]; |
| 442 | CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]); |
| 443 | //get default participant role. |
| 444 | $eventDetails[$this->_event_id]['participant_role'] = $participantRoles[$eventDetails[$this->_event_id]['default_role_id']] ?? NULL; |
| 445 | //get the location info |
| 446 | $locParams = ['entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event']; |
| 447 | $eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE); |
| 448 | //send a 'cancelled' email to user, and cc the event's cc_confirm email |
| 449 | CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id, |
| 450 | $participantDetails[$this->_from_participant_id], |
| 451 | $eventDetails[$this->_event_id], |
| 452 | NULL, |
| 453 | 'Transferred' |
| 454 | ); |
| 455 | $statusMsg = ts('Event registration information for %1 has been updated.', [1 => $this->_contact_name]); |
| 456 | $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', [1 => $this->_contact_email]); |
| 457 | CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success'); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Move Participant registration to new contact. |
| 462 | * |
| 463 | * @param int $toContactID |
| 464 | * @param int $fromParticipantID |
| 465 | * |
| 466 | * @throws \CRM_Core_Exception |
| 467 | * @throws \CiviCRM_API3_Exception |
| 468 | */ |
| 469 | public function transferParticipantRegistration($toContactID, $fromParticipantID) { |
| 470 | $toParticipantValues = \Civi\Api4\Participant::get() |
| 471 | ->addWhere('id', '=', $fromParticipantID) |
| 472 | ->execute() |
| 473 | ->first(); |
| 474 | $participantPayments = civicrm_api3('ParticipantPayment', 'get', [ |
| 475 | 'return' => 'id', |
| 476 | 'participant_id' => $fromParticipantID, |
| 477 | ])['values']; |
| 478 | unset($toParticipantValues['id']); |
| 479 | $toParticipantValues['contact_id'] = $toContactID; |
| 480 | $toParticipantValues['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'status_id', 'Registered'); |
| 481 | $toParticipantValues['register_date'] = date("Y-m-d"); |
| 482 | //first create the new participant row -don't set registered_by yet or email won't be sent |
| 483 | $participant = CRM_Event_BAO_Participant::create($toParticipantValues); |
| 484 | foreach ($participantPayments as $payment) { |
| 485 | civicrm_api3('ParticipantPayment', 'create', ['id' => $payment['id'], 'participant_id' => $participant->id]); |
| 486 | } |
| 487 | //send a confirmation email to the new participant |
| 488 | $this->participantTransfer($participant); |
| 489 | //now update registered_by_id |
| 490 | $query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})"; |
| 491 | $params = [1 => [$fromParticipantID, 'Integer']]; |
| 492 | CRM_Core_DAO::executeQuery($query, $params); |
| 493 | //copy line items to new participant |
| 494 | $line_items = CRM_Price_BAO_LineItem::getLineItems($fromParticipantID); |
| 495 | foreach ($line_items as $id => $item) { |
| 496 | //Remove contribution id from older participant line item. |
| 497 | CRM_Core_DAO::singleValueQuery('UPDATE civicrm_line_item SET contribution_id = NULL WHERE id = %1', [1 => [$id, 'Integer']]); |
| 498 | |
| 499 | $item['entity_id'] = $participant->id; |
| 500 | $item['id'] = NULL; |
| 501 | $item['entity_table'] = "civicrm_participant"; |
| 502 | $tolineItem = CRM_Price_BAO_LineItem::create($item); |
| 503 | |
| 504 | //Update Financial Item for previous line item row. |
| 505 | $prevFinancialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($id); |
| 506 | $prevFinancialItem['contact_id'] = $toContactID; |
| 507 | $prevFinancialItem['entity_id'] = $tolineItem->id; |
| 508 | CRM_Financial_BAO_FinancialItem::create($prevFinancialItem); |
| 509 | } |
| 510 | //now cancel the from participant record, leaving the original line-item(s) |
| 511 | $value_from = []; |
| 512 | $value_from['id'] = $fromParticipantID; |
| 513 | $tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); |
| 514 | $value_from['status_id'] = $tansferId; |
| 515 | $value_from['transferred_to_contact_id'] = $toContactID; |
| 516 | CRM_Event_BAO_Participant::create($value_from); |
| 517 | } |
| 518 | |
| 519 | } |