return $additionalParticipantIds;
}
+ /**
+ * Get the amount for the undiscounted version of the field.
+ *
+ * Note this function is part of the refactoring process rather than the best approach.
+ *
+ * @param int $eventID
+ * @param int $discountedPriceFieldOptionID
+ * @param string $feeLevel (deprecated)
+ *
+ * @return null|string
+ */
+ public static function getUnDiscountedAmountForEventPriceSetFieldValue($eventID, $discountedPriceFieldOptionID, $feeLevel) {
+ $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
+ $params = array(
+ 1 => array($priceSetId, 'Integer'),
+ );
+ if ($discountedPriceFieldOptionID) {
+ $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
+LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
+WHERE cpf.price_set_id = %1 AND cpfv.label = (SELECT label from civicrm_price_field_value WHERE id = %2)";
+ $params[2] = array($discountedPriceFieldOptionID, 'Integer');
+ }
+ else {
+ $feeLevel = current($feeLevel);
+ $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
+LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
+WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
+ $params[2] = array($feeLevel, 'String');
+ }
+ return CRM_Core_DAO::singleValueQuery($query, $params);
+ }
+
/**
* Get the event fee info for given participant ids
* either from line item table / participant table.
* @param array $contributionParams
* Contribution params.
*
- * @param $feeLevel
- *
+ * @param string $feeLevel (deprecated)
+ * @param int $discountedPriceFieldOptionID
+ * ID of the civicrm_price_field_value field for the discount id.
*/
- public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel) {
- // CRM-11124
+ public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel, $discountedPriceFieldOptionID) {
+ $financialTypeID = $contributionParams['contribution']->financial_type_id;
+ $total_amount = $contributionParams['total_amount'];
+
$checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
if (!empty($checkDiscount)) {
- $feeLevel = current($feeLevel);
- $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
- $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
-LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
-WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
- $params = array(
- 1 => array($priceSetId, 'Integer'),
- 2 => array($feeLevel, 'String'),
- );
- $mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
+ $mainAmount = self::getUnDiscountedAmountForEventPriceSetFieldValue($eventID, $discountedPriceFieldOptionID, $feeLevel);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
- $contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType(
- $contributionParams['contribution']->financial_type_id, $relationTypeId);
- if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
- $contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
- $contributionParams['trxnParams']['payment_processor_id'] = NULL;
- $contributionParams['trxnParams']['payment_instrument_id'] = NULL;
- $contributionParams['trxnParams']['check_number'] = NULL;
- $contributionParams['trxnParams']['trxn_id'] = NULL;
- $contributionParams['trxnParams']['net_amount'] = NULL;
- $contributionParams['trxnParams']['fee_amount'] = NULL;
-
- CRM_Core_BAO_FinancialTrxn::create($contributionParams['trxnParams']);
+ $transactionParams['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType(
+ $financialTypeID, $relationTypeId);
+ if (!empty($transactionParams['trxnParams']['from_financial_account_id'])) {
+ $transactionParams['trxnParams']['total_amount'] = $mainAmount - $total_amount;
+ $transactionParams['trxnParams']['payment_processor_id'] = NULL;
+ $transactionParams['trxnParams']['payment_instrument_id'] = NULL;
+ $transactionParams['trxnParams']['check_number'] = NULL;
+ $transactionParams['trxnParams']['trxn_id'] = NULL;
+ $transactionParams['trxnParams']['net_amount'] = NULL;
+ $transactionParams['trxnParams']['fee_amount'] = NULL;
+ CRM_Core_BAO_FinancialTrxn::create($transactionParams);
}
}
}
$params['discountAmount'] = $this->_params[0]['discountAmount'];
$params['discountMessage'] = $this->_params[0]['discountMessage'];
}
- if (!empty($this->_params[0]['amount_priceset_level_radio'])) {
- $params['amount_priceset_level_radio'] = $this->_params[0]['amount_priceset_level_radio'];
- }
+
$params['amount_level'] = $this->_params[0]['amount_level'];
$params['currencyID'] = $this->_params[0]['currencyID'];
// create contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
// CRM-11124
- CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, CRM_Utils_Array::value('amount_priceset_level_radio', $params, NULL));
+ CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, NULL, CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($params));
// process soft credit / pcp pages
if (!empty($params['pcp_made_through_id'])) {
}
$params["price_{$id}"] = array($params["price_{$id}"] => 1);
$optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
- $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
- $params['amount_priceset_level_radio'] = array();
- $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
case 'Select':
$params["price_{$id}"] = array($params["price_{$id}"] => 1);
$optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
- $optionLabel = $field['options'][$optionValueId]['label'];
- $params['amount_priceset_level_select'] = array();
- $params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel;
CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
return $lineItem;
}
+ /**
+ * Get the first price set value IDs from a parameters array.
+ *
+ * In practice this is really used when we only expect one to exist.
+ *
+ * @param array $params
+ *
+ * @return array
+ * Array of the ids of the price set values.
+ */
+ public static function parseFirstPriceSetValueIDFromParams($params) {
+ $priceSetValueIDs = self::parsePriceSetValueIDsFromParams($params);
+ return reset($priceSetValueIDs);
+ }
+
+ /**
+ * Get the price set value IDs from a set of parameters
+ *
+ * @param array $params
+ *
+ * @return array
+ * Array of the ids of the price set values.
+ */
+ public static function parsePriceSetValueIDsFromParams($params) {
+ $priceSetParams = self::parsePriceSetArrayFromParams($params);
+ $priceSetValueIDs = array();
+ foreach ($priceSetParams as $priceSetParam) {
+ foreach (array_keys($priceSetParam) as $priceValueID) {
+ $priceSetValueIDs[] = $priceValueID;
+ }
+ }
+ return $priceSetValueIDs;
+ }
+
+ /**
+ * Get the price set value IDs from a set of parameters
+ *
+ * @param array $params
+ *
+ * @return array
+ * Array of price fields filtered from the params.
+ */
+ public static function parsePriceSetArrayFromParams($params) {
+ $priceSetParams = array();
+ foreach ($params as $field => $value) {
+ $parts = explode('_', $field);
+ if (count($parts) == 2 && $parts[0] == 'price' && is_numeric($parts[1])) {
+ $priceSetParams[$field] = $value;
+ }
+ }
+ return $priceSetParams;
+ }
+
}