X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FEvent%2FBAO%2FParticipant.php;h=6e54464185dab6db9d9fb375e5f7ed098afa58e0;hb=ad37ac8ed3992e075cddfef34d562f4dc8c22247;hp=6a9e78e98d3d3cce5f3a9b720beb91792292664c;hpb=c7956780e95aec6abcb7b73b6cf5d7b30b2d49ff;p=civicrm-core.git diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 6a9e78e98d..6e54464185 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1,7 +1,7 @@ name). - * - * @return void */ public static function resolveDefaults(&$defaults, $reverse = FALSE) { self::lookupValue($defaults, 'event', CRM_Event_PseudoConstant::event(), $reverse); @@ -827,12 +821,18 @@ WHERE civicrm_participant.id = {$participantId} } /** - * convert associative array names to values - * and vice-versa. + * Convert associative array names to values and vice-versa. * * This function is used by both the web form layer and the api. Note that * the api needs the name => value conversion, also the view layer typically * requires value => name conversion + * + * @param array $defaults + * @param string $property + * @param string $lookup + * @param bool $reverse + * + * @return bool */ public static function lookupValue(&$defaults, $property, $lookup, $reverse) { $id = $property . '_id'; @@ -856,12 +856,12 @@ WHERE civicrm_participant.id = {$participantId} } /** - * Delete the record that are associated with this participation. + * Delete the records that are associated with this participation. * * @param int $id * Id of the participation to delete. * - * @return void + * @return \CRM_Event_DAO_Participant */ public static function deleteParticipant($id) { CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray); @@ -967,10 +967,7 @@ WHERE civicrm_participant.id = {$participantId} * separated string before using fee_level in view mode. * * @param string $eventLevel - * Event_leval string from db. - * - * - * @return void + * Event_level string from db. */ public static function fixEventLevel(&$eventLevel) { if ((substr($eventLevel, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR) && @@ -1185,9 +1182,6 @@ INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_ * @param int $statusId * Status id for participant. * @param bool $updateRegisterDate - * - * @return void - * */ public static function updateStatus($participantIds, $statusId, $updateRegisterDate = FALSE) { if (!is_array($participantIds) || empty($participantIds) || !$statusId) { @@ -1961,13 +1955,18 @@ GROUP BY li.entity_table, li.entity_id, price_field_value_id WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})"; CRM_Core_DAO::executeQuery($updateLineItem); } + $amountLevel = array(); + $totalParticipant = $participantCount = 0; if (!empty($updateLines)) { foreach ($updateLines as $valueId => $vals) { + $taxAmount = "NULL"; if (isset($vals['tax_amount'])) { $taxAmount = $vals['tax_amount']; } - else { - $taxAmount = "NULL"; + $amountLevel[] = $vals['label'] . ' - ' . (float) $vals['qty']; + if (isset($vals['participant_count'])) { + $participantCount = $vals['participant_count']; + $totalParticipant += $vals['participant_count']; } $updateLineItem = " UPDATE civicrm_line_item li @@ -1975,6 +1974,7 @@ SET li.qty = {$vals['qty']}, li.line_total = {$vals['line_total']}, li.tax_amount = {$taxAmount}, li.unit_price = {$vals['unit_price']}, + li.participant_count = {$participantCount}, li.label = %1 WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND (price_field_value_id = {$valueId}) @@ -2012,7 +2012,15 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI else { $taxAmount = "NULL"; } - $trxn = self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount); + $displayParticipantCount = ''; + if ($totalParticipant > 0) { + $displayParticipantCount = ' Participant Count -' . $totalParticipant; + } + $updateAmountLevel = NULL; + if (!empty($amountLevel)) { + $updateAmountLevel = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR; + } + $trxn = self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount, $updateAmountLevel); $trxnId = array(); if ($trxn) { $trxnId['id'] = $trxn->id; @@ -2064,13 +2072,25 @@ WHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND } /** - * @param $updatedAmount - * @param $paidAmount + * Record adjusted amount. + * + * @param int $updatedAmount + * @param int $paidAmount * @param int $contributionId + * + * @param int $taxAmount + * @param bool $updateAmountLevel + * + * @return bool|\CRM_Core_BAO_FinancialTrxn */ - public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL) { + public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL) { $pendingAmount = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); - $balanceAmt = $updatedAmount - $paidAmount - CRM_Utils_Array::value('total_amount', $pendingAmount, 0); + $pendingAmount = CRM_Utils_Array::value('total_amount', $pendingAmount, 0); + $balanceAmt = $updatedAmount - $paidAmount; + if ($paidAmount != $pendingAmount) { + $balanceAmt -= $pendingAmount; + } + $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses); $pendingRefundStatusId = array_search('Pending refund', $contributionStatuses); @@ -2100,6 +2120,9 @@ WHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND $updatedContributionDAO->total_amount = $updatedContributionDAO->net_amount = $updatedAmount; $updatedContributionDAO->fee_amount = 0; $updatedContributionDAO->tax_amount = $taxAmount; + if (!empty($updateAmountLevel)) { + $updatedContributionDAO->amount_level = $updateAmountLevel; + } $updatedContributionDAO->save(); // adjusted amount financial_trxn creation $updatedContribution = CRM_Contribute_BAO_Contribution::getValues( @@ -2113,7 +2136,7 @@ WHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND 'from_financial_account_id' => NULL, 'to_financial_account_id' => $toFinancialAccount, 'total_amount' => $balanceAmt, - 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), + 'status_id' => $completedStatusId, 'payment_instrument_id' => $updatedContribution->payment_instrument_id, 'contribution_id' => $updatedContribution->id, 'trxn_date' => date('YmdHis'),