/**
  * Helper function to record participant with paid contribution.
  *
  * @param int $feeTotal
  * @param int $actualPaidAmt
  *
  * @return array
  * @throws Exception
  */
 protected function addParticipantWithPayment($feeTotal, $actualPaidAmt)
 {
     $priceSetId = $this->eventPriceSetCreate($feeTotal);
     CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId);
     // create participant record
     $eventId = $this->_eventId;
     $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 14, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
     $participant = $this->callAPISuccess('participant', 'create', $participantParams);
     $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
     // create participant contribution with partial payment
     $contributionParams = array('total_amount' => $actualPaidAmt, 'source' => 'Fall Fundraiser Dinner: Offline registration', 'currency' => 'USD', 'non_deductible_amount' => 'null', 'receipt_date' => date('Y-m-d') . " 00:00:00", 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Y-m-d') . " 00:00:00", 'skipLineItem' => 1, 'partial_payment_total' => $feeTotal, 'partial_amount_pay' => $actualPaidAmt);
     $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
     $contributionId = $contribution->id;
     $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
     // add participant payment entry
     $this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contributionId));
     // -- processing priceSet using the BAO
     $lineItem = array();
     $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE);
     $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $feeBlock = CRM_Utils_Array::value('fields', $priceSet);
     $params['price_2'] = $feeTotal;
     CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItem);
     $lineItemVal[$priceSetId] = $lineItem;
     CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
     return array($participant, $contribution);
 }
Ejemplo n.º 2
0
/**
 * Create or update a PriceSet.
 *
 * @param array $params
 *   name/value pairs to insert in new 'PriceSet'
 *
 * @return array
 *   api result array
 */
function civicrm_api3_price_set_create($params)
{
    $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
    // Handle price_set_entity
    if (!empty($result['id']) && !empty($params['entity_table']) && !empty($params['entity_id'])) {
        $entityId = $params['entity_id'];
        if (!is_array($params['entity_id'])) {
            $entityId = explode(',', $entityId);
        }
        foreach ($entityId as $eid) {
            $eid = (int) trim($eid);
            if ($eid) {
                CRM_Price_BAO_PriceSet::addTo($params['entity_table'], $eid, $result['id']);
            }
        }
    }
    return $result;
}
 /**
  * helper function to record participant with paid contribution.
  * @param $feeTotal
  * @param $actualPaidAmt
  *
  * @return array
  * @throws Exception
  */
 public function _addParticipantWithPayment($feeTotal, $actualPaidAmt)
 {
     // creating price set, price field
     $paramsSet['title'] = 'Price Set';
     $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
     $paramsSet['is_active'] = FALSE;
     $paramsSet['extends'] = 1;
     $priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
     CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceset->id);
     $priceSetId = $priceset->id;
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => $feeTotal, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => $feeTotal), 'option_name' => array('1' => $feeTotal), 'option_weight' => array('1' => 1), 'option_amount' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1);
     $ids = array();
     $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield');
     // create participant record
     $eventId = $this->_eventId;
     $participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 14, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
     $participant = $this->callAPISuccess('participant', 'create', $participantParams);
     $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
     // create participant contribution with partial payment
     $contributionParams = array('total_amount' => $actualPaidAmt, 'source' => 'Fall Fundraiser Dinner: Offline registration', 'currency' => 'USD', 'non_deductible_amount' => 'null', 'receipt_date' => date('Y-m-d') . " 00:00:00", 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Y-m-d') . " 00:00:00", 'skipLineItem' => 1, 'partial_payment_total' => $feeTotal, 'partial_amount_pay' => $actualPaidAmt);
     $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
     $contributionId = $contribution->id;
     $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
     // add participant payment entry
     $this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contributionId));
     // -- processing priceSet using the BAO
     $lineItem = array();
     $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE);
     $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $feeBlock = CRM_Utils_Array::value('fields', $priceSet);
     $params['price_2'] = $feeTotal;
     CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItem);
     $lineItemVal[$priceSetId] = $lineItem;
     CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
     return array($participant, $contribution);
 }
Ejemplo n.º 4
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (!empty($_POST['_qf_Fee_submit'])) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (!empty($params['payment_processor'])) {
         $params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     $params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         //@todo note that this removes the reference from existing participants -
         // even where there is not change - redress?
         // note that a more tentative form of this is invoked by passing price_set_id as an array
         // to event.create see CRM-14069
         // @todo get all of this logic out of form layer (currently partially in BAO/api layer)
         if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (!empty($params['price_set_id'])) {
             //@todo this is now being done in the event BAO if passed price_set_id as an array
             // per notes on that fn - looking at the api converting to an array
             // so calling via the api may cause this to be done in the api
             CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (!empty($params['price_field_id'])) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (empty($params['price_set_id'])) {
                         if (empty($params['price_field_id'])) {
                             $setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             $eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode('.', microtime(TRUE));
                                 $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['financial_type_id'] = $params['financial_type_id'];
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet = new CRM_Price_BAO_PriceSet();
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                             if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                 CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
                             }
                         }
                         $fieldParams['label'] = $params['fee_label'];
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = $params['financial_type_id'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = !empty($this->_defaultValues['discount_price_set']) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = !empty($this->_defaultValues['discount_option_id']) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             $setParams = array();
                             if (empty($discountPriceSets[$keyCheck])) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode('.', microtime(TRUE));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['financial_type_id'] = $params['financial_type_id'];
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 $setParams = array('title' => $params['discount_name'][$j], 'id' => $priceSetID);
                                 if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                     $setParams['financial_type_id'] = $params['financial_type_id'];
                                 }
                                 CRM_Price_BAO_PriceSet::create($setParams);
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             $fieldParams['financial_type_id'] = $params['financial_type_id'];
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (!empty($value['is_default'])) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
                                     unset($discountFieldIDs[$j][$value['weight']]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                             if (!empty($discountFieldIDs[$j])) {
                                 foreach ($discountFieldIDs[$j] as $fID) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'price_set_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]), 'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (!empty($params['price_field_id'])) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
         }
         $params['financial_type_id'] = '';
         $params['is_pay_later'] = 0;
         $params['is_billing_required'] = 0;
     }
     //update 'is_billing_required'
     if (empty($params['is_pay_later'])) {
         $params['is_billing_required'] = FALSE;
     }
     //update events table
     $params['id'] = $this->_id;
     // skip update of financial type in price set
     $params['skipFinancialType'] = TRUE;
     CRM_Event_BAO_Event::add($params);
     // Update tab "disabled" css class
     $this->ajaxResponse['tabValid'] = !empty($params['is_monetary']);
     parent::endPostProcess();
 }
Ejemplo n.º 5
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         if ($this->_id && !empty($params['member_price_set_id'])) {
             CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
             if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(TRUE));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (empty($editedResults['id'])) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 if (empty($params['mem_price_field_id'])) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
             $fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (!empty($fieldParams['id'])) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
             }
             foreach ($options as $priceFieldID => $memType) {
                 CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
             }
             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
         } elseif (!$priceSetID) {
             $deletePriceSet = 1;
         }
         $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
         if ($priceSetID) {
             $params['membership_types'] = 'null';
             $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
             $params['membership_types'] = serialize($membershipTypes);
             $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
             $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
         }
         $params['entity_table'] = 'civicrm_contribution_page';
         $params['entity_id'] = $this->_id;
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->copyValues($params);
         $dao->save();
         if ($priceSetID && $params['is_active']) {
             CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
         }
         if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
             if ($this->_memPriceSetId) {
                 $pFIDs = array();
                 $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
                 CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
                 if (empty($pFIDs['id'])) {
                     CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
                 } else {
                     CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
                 }
             }
         }
     }
     parent::endPostProcess();
 }
Ejemplo n.º 6
0
 /**
  * Create price set with contribution test for test setup.
  *
  * This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
  * on parent class at some point (fn is not in 4.4).
  *
  * @param $entity
  * @param array $params
  */
 public function createPriceSetWithPage($entity, $params = array())
 {
     $membershipTypeID = $this->membershipTypeCreate();
     $contributionPageResult = $this->callAPISuccess('contribution_page', 'create', array('title' => "Test Contribution Page", 'financial_type_id' => 1, 'currency' => 'NZD', 'goal_amount' => 50, 'is_pay_later' => 1, 'is_monetary' => TRUE, 'is_email_receipt' => FALSE));
     $priceSet = $this->callAPISuccess('price_set', 'create', array('is_quick_config' => 0, 'extends' => 'CiviMember', 'financial_type_id' => 1, 'title' => 'my Page'));
     $priceSetID = $priceSet['id'];
     CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
     $priceField = $this->callAPISuccess('price_field', 'create', array('price_set_id' => $priceSetID, 'label' => 'Goat Breed', 'html_type' => 'Radio'));
     $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array('price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', 'amount' => 20, 'financial_type_id' => 'Donation', 'membership_type_id' => $membershipTypeID, 'membership_num_terms' => 1));
     $this->_ids['price_field_value'] = array($priceFieldValue['id']);
     $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array('price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', 'amount' => 10, 'financial_type_id' => 'Donation', 'membership_type_id' => $membershipTypeID, 'membership_num_terms' => 2));
     $this->_ids['price_field_value'][] = $priceFieldValue['id'];
     $this->_ids['price_set'] = $priceSetID;
     $this->_ids['contribution_page'] = $contributionPageResult['id'];
     $this->_ids['price_field'] = array($priceField['id']);
     $this->_ids['membership_type'] = $membershipTypeID;
 }
Ejemplo n.º 7
0
 /**
  * Add participant with contribution
  *
  * @return array
  */
 protected function addParticipantWithContribution()
 {
     // creating price set, price field
     require_once 'CiviTest/Event.php';
     $this->_contactId = Contact::createIndividual();
     $this->_eventId = Event::create($this->_contactId);
     $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
     $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
     $paramsSet['is_active'] = TRUE;
     $paramsSet['financial_type_id'] = 4;
     $paramsSet['extends'] = 1;
     $priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
     $priceSetId = $priceset->id;
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'));
     $priceField = CRM_Price_BAO_PriceField::create($paramsField);
     $eventParams = array('id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1);
     CRM_Event_BAO_Event::create($eventParams);
     CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId);
     $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
     $participantParams = array('financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', 'contact_id' => $this->_contactId);
     $participant = CRM_Event_BAO_Participant::add($participantParams);
     $contributionParams = array('total_amount' => 150, 'currency' => 'USD', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'contribution_status_id' => 1, 'partial_payment_total' => 300.0, 'partial_amount_pay' => 150, 'contribution_mode' => 'participant', 'participant_id' => $participant->id);
     foreach ($priceFields['values'] as $key => $priceField) {
         $lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']);
     }
     $contributionParams['line_item'] = $lineItems;
     $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
     $paymentParticipant = array('participant_id' => $participant->id, 'contribution_id' => $contributions->id);
     $ids = array();
     CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
     return array($lineItems, $contributions);
 }
Ejemplo n.º 8
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //update 'is_billing_required'
     if (empty($params['is_pay_later'])) {
         $params['is_billing_required'] = 0;
     }
     if (array_key_exists('payment_processor', $params)) {
         if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type_id'), CRM_Utils_Array::value('payment_processor', $params))) {
             CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).'), '', 'alert');
         }
     }
     // check for price set.
     $priceSetID = CRM_Utils_Array::value('price_set_id', $params);
     // get required fields.
     $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_billing_required' => FALSE, 'is_recur_interval' => FALSE, 'is_recur_installments' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE);
     $resetFields = array();
     if ($priceSetID) {
         $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
     }
     if (empty($params['is_recur'])) {
         $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
     }
     foreach ($fields as $field => $defaultVal) {
         $val = CRM_Utils_Array::value($field, $params, $defaultVal);
         if (in_array($field, $resetFields)) {
             $val = $defaultVal;
         }
         if (in_array($field, array('min_amount', 'max_amount'))) {
             $val = CRM_Utils_Rule::cleanMoney($val);
         }
         $params[$field] = $val;
     }
     if ($params['is_recur']) {
         $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit']));
         $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE);
         $params['is_recur_installments'] = CRM_Utils_Array::value('is_recur_installments', $params, FALSE);
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
     $contributionPageID = $contributionPage->id;
     // prepare for data cleanup.
     $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
     if ($this->_priceSetID) {
         $deletePriceSet = TRUE;
     }
     if ($this->_pledgeBlockID) {
         $deletePledgeBlk = TRUE;
     }
     if (!empty($this->_amountBlock)) {
         $deleteAmountBlk = TRUE;
     }
     if ($contributionPageID) {
         if (!empty($params['amount_block_is_active'])) {
             // handle price set.
             if ($priceSetID) {
                 // add/update price set.
                 $deletePriceSet = FALSE;
                 if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
                     $deleteAmountBlk = TRUE;
                 }
                 CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
             } else {
                 $deletePriceSet = FALSE;
                 // process contribution amount block
                 $deleteAmountBlk = FALSE;
                 $labels = CRM_Utils_Array::value('label', $params);
                 $values = CRM_Utils_Array::value('value', $params);
                 $default = CRM_Utils_Array::value('default', $params);
                 $options = array();
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 /* || !empty($params['price_field_value']) || CRM_Utils_Array::value( 'price_field_other', $params )*/
                 if (!empty($options) || !empty($params['is_allow_other_amount'])) {
                     $fieldParams['is_quick_config'] = 1;
                     $noContriAmount = NULL;
                     $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
                     if (!(!empty($params['price_field_id']) || !empty($params['price_field_other'])) && !$usedPriceSetId) {
                         $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                         $setParams['title'] = $this->_values['title'];
                         if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
                             $setParams['name'] = $pageTitle;
                         } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                             $setParams['name'] = $pageTitle . '_' . $this->_id;
                         } else {
                             $timeSec = explode(".", microtime(TRUE));
                             $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                         }
                         $setParams['is_quick_config'] = 1;
                         $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                         $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
                         $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                         $priceSetId = $priceSet->id;
                     } elseif ($usedPriceSetId && empty($params['price_field_id'])) {
                         $priceSetId = $usedPriceSetId;
                     } else {
                         if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             if (implode('', $params['price_field_value'])) {
                                 $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                                 $fieldParams['option_id'] = $params['price_field_value'];
                             } else {
                                 $noContriAmount = 0;
                                 CRM_Price_BAO_PriceField::setIsActive($priceFieldId, '0');
                             }
                         } else {
                             $priceFieldId = CRM_Utils_Array::value('price_field_other', $params);
                         }
                         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceFieldId, 'price_set_id');
                     }
                     CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetId);
                     if (!empty($options)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount');
                         $editedResults = array();
                         $noContriAmount = 1;
                         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
                         if (empty($editedResults['id'])) {
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245));
                         } else {
                             $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
                         }
                         $fieldParams['price_set_id'] = $priceSetId;
                         $fieldParams['is_active'] = 1;
                         $fieldParams['weight'] = 2;
                         if (!empty($params['is_allow_other_amount'])) {
                             $fieldParams['is_required'] = 0;
                         } else {
                             $fieldParams['is_required'] = 1;
                         }
                         $fieldParams['label'] = $params['amount_label'];
                         $fieldParams['html_type'] = 'Radio';
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                     if (!empty($params['is_allow_other_amount']) && empty($params['price_field_other'])) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount');
                         $editedResults = array();
                         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
                         if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) {
                             $fieldParams = array('name' => 'other_amount', 'label' => ts('Other Amount'), 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $this->_values), 'is_display_amounts' => 0, 'weight' => 3);
                             $fieldParams['option_weight'][1] = 1;
                             $fieldParams['option_amount'][1] = 1;
                             if (!$noContriAmount) {
                                 $fieldParams['is_required'] = 1;
                                 $fieldParams['option_label'][1] = $fieldParams['label'] = $params['amount_label'];
                             } else {
                                 $fieldParams['is_required'] = 0;
                                 $fieldParams['option_label'][1] = $fieldParams['label'] = ts('Other Amount');
                             }
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                         } else {
                             if (empty($editedResults['is_active'])) {
                                 $fieldParams = $editedResults;
                                 if (!$noContriAmount) {
                                     $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
                                     CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
                                     $fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
                                 }
                                 $fieldParams['is_active'] = 1;
                                 $priceField = CRM_Price_BAO_PriceField::add($fieldParams);
                             }
                         }
                     } elseif (empty($params['is_allow_other_amount']) && !empty($params['price_field_other'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
                     } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
                         $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
                         if (!$noContriAmount) {
                             $fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
                             CRM_Price_BAO_PriceField::add($fieldParams);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
                         } else {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', ts('Other Amount'));
                         }
                     }
                 }
                 if (!empty($params['is_pledge_active'])) {
                     $deletePledgeBlk = FALSE;
                     $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page'));
                     if ($this->_pledgeBlockID) {
                         $pledgeBlockParams['id'] = $this->_pledgeBlockID;
                     }
                     $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
                     foreach ($pledgeBlock as $key) {
                         $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params);
                     }
                     $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE);
                     // create pledge block.
                     CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
                 }
             }
         } else {
             if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
                 $usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
                 if ($usedPriceSetId) {
                     if (!empty($params['price_field_id'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_id'], '0');
                     }
                     if (!empty($params['price_field_other'])) {
                         CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
                     }
                 } else {
                     $deleteAmountBlk = TRUE;
                     $deletePriceSet = TRUE;
                 }
             }
         }
         // delete pledge block.
         if ($deletePledgeBlk) {
             CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID);
         }
         // delete previous price set.
         if ($deletePriceSet) {
             CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $contributionPageID);
         }
         if ($deleteAmountBlk) {
             $priceField = !empty($params['price_field_id']) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
             if ($priceField) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceField, 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         }
     }
     parent::endPostProcess();
 }
 public function setUpContributionPage()
 {
     $contributionPageResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
     if (empty($this->_ids['price_set'])) {
         $priceSet = $this->callAPISuccess('price_set', 'create', $this->_priceSetParams);
         $this->_ids['price_set'][] = $priceSet['id'];
     }
     $priceSetID = $this->_price = reset($this->_ids['price_set']);
     CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageResult['id'], $priceSetID);
     if (empty($this->_ids['price_field'])) {
         $priceField = $this->callAPISuccess('price_field', 'create', array('price_set_id' => $priceSetID, 'label' => 'Goat Breed', 'html_type' => 'Radio'));
         $this->_ids['price_field'] = array($priceField['id']);
     }
     if (empty($this->_ids['price_field_value'])) {
         $this->callAPISuccess('price_field_value', 'create', array('price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Long Haired Goat', 'amount' => 100, 'financial_type_id' => $this->financialtypeID));
         $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', array('price_set_id' => $priceSetID, 'price_field_id' => $priceField['id'], 'label' => 'Shoe-eating Goat', 'amount' => 300, 'financial_type_id' => $this->halfFinancialTypeId));
         $this->_ids['price_field_value'] = array($priceFieldValue['id']);
     }
     $this->_ids['contribution_page'] = $contributionPageResult['id'];
 }
Ejemplo n.º 10
0
 /**
  * Create price set
  *
  * @param string $component
  * @param int $componentId
  *
  * @return array
  */
 protected function createPriceSet($component = 'contribution_page', $componentId = NULL)
 {
     $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 7);
     $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
     $paramsSet['is_active'] = TRUE;
     $paramsSet['financial_type_id'] = 4;
     $paramsSet['extends'] = 1;
     $priceSet = $this->callAPISuccess('price_set', 'create', $paramsSet);
     $priceSetId = $priceSet['id'];
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceSet['id'], 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'));
     $priceField = CRM_Price_BAO_PriceField::create($paramsField);
     if ($componentId) {
         CRM_Price_BAO_PriceSet::addTo('civicrm_' . $component, $componentId, $priceSetId);
     }
     return $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
 }
Ejemplo n.º 11
0
 /**
  * Copy priceSet when event/contibution page is copied
  *
  * @param string $baoName
  *   BAO name.
  * @param int $id
  *   Old event/contribution page id.
  * @param int $newId
  *   Newly created event/contribution page id.
  */
 public static function copyPriceSet($baoName, $id, $newId)
 {
     $priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id);
     if ($priceSetId) {
         $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($isQuickConfig) {
             $copyPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetId);
             CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id);
         } else {
             $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSetEntity', array('entity_id' => $id, 'entity_table' => $baoName), array('entity_id' => $newId));
         }
         // copy event discount
         if ($baoName == 'civicrm_event') {
             $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
             foreach ($discount as $discountId => $setId) {
                 $copyPriceSet =& CRM_Price_BAO_PriceSet::copy($setId);
                 CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('id' => $discountId), array('entity_id' => $newId, 'price_set_id' => $copyPriceSet->id));
             }
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (CRM_Utils_Array::value('price_set_id', $params)) {
             CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (CRM_Utils_Array::value('price_field_id', $params)) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (!CRM_Utils_Array::value('price_set_id', $params)) {
                         if (!CRM_Utils_Array::value('price_field_id', $params)) {
                             $setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             $eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode('.', microtime(true));
                                 $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['financial_type_id'] = $params['financial_type_id'];
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet = new CRM_Price_BAO_PriceSet();
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                             if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                 CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
                             }
                         }
                         $fieldParams['label'] = $params['fee_label'];
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = $params['financial_type_id'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             $setParams = array();
                             if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode('.', microtime(true));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['financial_type_id'] = $params['financial_type_id'];
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 $setParams = array('title' => $params['discount_name'][$j], 'id' => $priceSetID);
                                 if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                     $setParams['financial_type_id'] = $params['financial_type_id'];
                                 }
                                 CRM_Price_BAO_PriceSet::create($setParams);
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             $fieldParams['financial_type_id'] = $params['financial_type_id'];
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (CRM_Utils_Array::value('is_default', $value)) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'], $discountFieldIDs[$j])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
                                     unset($discountFieldIDs[$j][$value['weight']]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                             if (!empty($discountFieldIDs[$j])) {
                                 foreach ($discountFieldIDs[$j] as $fID) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'price_set_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]), 'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (CRM_Utils_Array::value('price_field_id', $params)) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
         }
         $params['financial_type_id'] = '';
         $params['is_pay_later'] = 0;
     }
     //update events table
     $params['id'] = $this->_id;
     // skip update of financial type in price set
     $params['skipFinancialType'] = TRUE;
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }