Ejemplo n.º 1
0
 /**
  * Insert/update a new entry in the database.
  *
  * @param array $params
  *   (reference), array $ids.
  *
  * @param $ids
  *
  * @return CRM_Price_DAO_PriceFieldValue
  */
 public static function add(&$params, $ids = array())
 {
     $fieldValueBAO = new CRM_Price_BAO_PriceFieldValue();
     $fieldValueBAO->copyValues($params);
     if ($id = CRM_Utils_Array::value('id', $ids)) {
         $fieldValueBAO->id = $id;
     }
     if (!empty($params['is_default'])) {
         $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE  price_field_id = %1';
         $p = array(1 => array($params['price_field_id'], 'Integer'));
         CRM_Core_DAO::executeQuery($query, $p);
     }
     $fieldValueBAO->save();
     // Reset the cached values in this function.
     CRM_Price_BAO_PriceField::getOptions(CRM_Utils_Array::value('price_field_id', $params), FALSE, TRUE);
     return $fieldValueBAO;
 }
Ejemplo n.º 2
0
 function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             $field_name = "event_{$event->id}_price_{$field['id']}";
             CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
 /**
  * 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
 /**
  * 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.º 5
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     $params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
     $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
     if (isset($params['active_on'])) {
         $params['active_on'] = CRM_Utils_Date::processDate($params['active_on'], CRM_Utils_Array::value('active_on_time', $params), TRUE);
     }
     if (isset($params['expire_on'])) {
         $params['expire_on'] = CRM_Utils_Date::processDate($params['expire_on'], CRM_Utils_Array::value('expire_on_time', $params), TRUE);
     }
     $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
     $params['count'] = CRM_Utils_Array::value('count', $params, FALSE);
     // need the FKEY - price set id
     $params['price_set_id'] = $this->_sid;
     if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $oldWeight = NULL;
         if ($this->_fid) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', $oldWeight, $params['weight'], $fieldValues);
     }
     // make value <=> name consistency.
     if (isset($params['option_name'])) {
         $params['option_value'] = $params['option_name'];
     }
     $params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE);
     if ($params['html_type'] == 'Text') {
         // if html type is Text, force is_enter_qty on
         $params['is_enter_qty'] = 1;
         // modify params values as per the option group and option
         // value
         $params['option_amount'] = array(1 => $params['price']);
         $params['option_label'] = array(1 => $params['label']);
         $params['option_count'] = array(1 => $params['count']);
         $params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params));
         //$params['option_description']  = array( 1 => $params['description'] );
         $params['option_weight'] = array(1 => $params['weight']);
         $params['option_financial_type_id'] = array(1 => $params['financial_type_id']);
     }
     if ($this->_fid) {
         $params['id'] = $this->_fid;
     }
     $params['membership_num_terms'] = !empty($params['membership_type_id']) ? CRM_Utils_Array::value('membership_num_terms', $params, 1) : NULL;
     $priceField = CRM_Price_BAO_PriceField::create($params);
     if (!is_a($priceField, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)), ts('Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another price set field.'), '', 'info');
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
     }
 }
Ejemplo n.º 6
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.º 7
0
 /**
  * Create a price set for an event.
  *
  * @param int $feeTotal
  *
  * @return int
  *   Price Set ID.
  */
 protected function eventPriceSetCreate($feeTotal)
 {
     // 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);
     $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, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'));
     CRM_Price_BAO_PriceField::create($paramsField);
     return $priceSetId;
 }
Ejemplo n.º 8
0
 /**
  * build the radio/text form elements for the amount field
  *
  * @param object   $form form object
  * @param boolean  $required  true if you want to add formRule
  * @param int      $discountId discount id for the event
  *
  * @return void
  * @access public
  * @static
  */
 public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
 {
     //if payment done, no need to build the fee block.
     if (!empty($form->_paymentId)) {
         //fix to display line item in update mode.
         $form->assign('priceSet', isset($form->_priceSet) ? $form->_priceSet : NULL);
         return;
     }
     $feeFields = CRM_Utils_Array::value('fee', $form->_values);
     if (is_array($feeFields)) {
         $form->_feeBlock =& $form->_values['fee'];
     }
     //check for discount.
     $discountedFee = CRM_Utils_Array::value('discount', $form->_values);
     if (is_array($discountedFee) && !empty($discountedFee)) {
         if (!$discountId) {
             $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
         }
         if ($discountId) {
             $form->_feeBlock =& $form->_values['discount'][$discountId];
         }
     }
     if (!is_array($form->_feeBlock)) {
         $form->_feeBlock = array();
     }
     //its time to call the hook.
     CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
     //reset required if participant is skipped.
     $button = substr($form->controller->getButtonName(), -4);
     if ($required && $button == 'skip') {
         $required = FALSE;
     }
     $className = CRM_Utils_System::getClassName($form);
     //build the priceset fields.
     if (isset($form->_priceSetId) && $form->_priceSetId) {
         //format price set fields across option full.
         self::formatFieldsForOptionFull($form);
         if (CRM_Utils_Array::value('is_quick_config', $form->_priceSet)) {
             $form->_quickConfig = $form->_priceSet['is_quick_config'];
         }
         $form->add('hidden', 'priceSetId', $form->_priceSetId);
         foreach ($form->_feeBlock as $field) {
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || $className == 'CRM_Event_Form_Participant') {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 $isRequire = CRM_Utils_Array::value('is_required', $field);
                 if ($button == 'skip') {
                     $isRequire = FALSE;
                 }
                 //user might modified w/ hook.
                 $options = CRM_Utils_Array::value('options', $field);
                 if (!is_array($options)) {
                     continue;
                 }
                 $optionFullIds = CRM_Utils_Array::value('option_full_ids', $field, array());
                 //soft suppress required rule when option is full.
                 if (!empty($optionFullIds) && count($options) == count($optionFullIds)) {
                     $isRequire = FALSE;
                 }
                 //build the element.
                 CRM_Price_BAO_PriceField::addQuickFormElement($form, $elementName, $fieldId, FALSE, $isRequire, NULL, $options, $optionFullIds);
             }
         }
         $form->assign('priceSet', $form->_priceSet);
     } else {
         $eventFeeBlockValues = array();
         foreach ($form->_feeBlock as $fee) {
             if (is_array($fee)) {
                 //CRM-7632, CRM-6201
                 $totalAmountJs = NULL;
                 if ($className == 'CRM_Event_Form_Participant') {
                     $totalAmountJs = array('onClick' => "fillTotalAmount(" . $fee['value'] . ")");
                 }
                 $eventFeeBlockValues['amount_id_' . $fee['amount_id']] = $fee['value'];
                 $elements[] =& $form->createElement('radio', NULL, '', CRM_Utils_Money::format($fee['value']) . ' ' . $fee['label'], $fee['amount_id'], $totalAmountJs);
             }
         }
         $form->assign('eventFeeBlockValues', json_encode($eventFeeBlockValues));
         $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
         $element =& $form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
         if (isset($form->_online) && $form->_online) {
             $element->freeze();
         }
         if ($required) {
             $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * process membership records
  *
  * @param array $params associated array of submitted values
  *
  * @access public
  *
  * @return bool
  */
 private function processMembership(&$params)
 {
     $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
     // get the price set associated with offline memebership
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
     $this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             // if contact is not selected we should skip the row
             if (empty($params['primary_contact_id'][$key])) {
                 continue;
             }
             $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
             // update contact information
             $this->updateContactInfo($value);
             $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
             foreach ($dateTypes as $dateField => $dateVariable) {
                 ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
             }
             $calcDates = array();
             $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
             foreach ($calcDates as $memType => $calcDate) {
                 foreach ($dates as $d) {
                     //first give priority to form values then calDates.
                     $date = CRM_Utils_Array::value($d, $value);
                     if (!$date) {
                         $date = CRM_Utils_Array::value($d, $calcDate);
                     }
                     $value[$d] = CRM_Utils_Date::processDate($date);
                 }
             }
             if (!empty($value['send_receipt'])) {
                 $value['receipt_date'] = date('Y-m-d His');
             }
             if (!empty($value['membership_source'])) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             if (!empty($value['membership_status'])) {
                 $value['status_id'] = $value['membership_status'];
                 unset($value['membership_status']);
             }
             if (empty($customFields)) {
                 // membership type custom data
                 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
                 $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
             }
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId);
             if (!empty($value['financial_type'])) {
                 $value['financial_type_id'] = $value['financial_type'];
             }
             if (!empty($value['payment_instrument'])) {
                 $value['payment_instrument_id'] = $value['payment_instrument'];
             }
             // handle soft credit
             if (is_array(CRM_Utils_Array::value('soft_credit_contact_id', $params)) && !empty($params['soft_credit_contact_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) {
                 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
                 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
             }
             if (!empty($value['receive_date'])) {
                 $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
             }
             $params['actualBatchTotal'] += $value['total_amount'];
             unset($value['financial_type']);
             unset($value['payment_instrument']);
             $value['batch_id'] = $this->_batchId;
             $value['skipRecentView'] = TRUE;
             // make entry in line item for contribution
             $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (!empty($editedResults)) {
                 unset($this->_priceSet['fields']);
                 $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
                 unset($this->_priceSet['fields'][$editedResults['id']]['options']);
                 $fid = $editedResults['id'];
                 $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
                 $editedResults = array();
                 CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
                 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
                 if (!empty($value['total_amount'])) {
                     $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
                 }
                 $fieldID = key($this->_priceSet['fields']);
                 $value['price_' . $fieldID] = $editedResults['id'];
                 $lineItem = array();
                 CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
                 //CRM-11529 for backoffice transactions
                 //when financial_type_id is passed in form, update the
                 //lineitems with the financial type selected in form
                 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
                     foreach ($lineItem[$priceSetId] as &$values) {
                         $values['financial_type_id'] = $value['financial_type_id'];
                     }
                 }
                 $value['lineItems'] = $lineItem;
                 $value['processPriceSet'] = TRUE;
             }
             // end of contribution related section
             unset($value['membership_type']);
             unset($value['membership_start_date']);
             unset($value['membership_end_date']);
             $value['is_renew'] = false;
             if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
                 $this->_params = $params;
                 $value['is_renew'] = true;
                 $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']);
                 // make contribution entry
                 CRM_Member_BAO_Membership::recordMembershipContribution(array_merge($value, array('membership_id' => $membership->id)));
             } else {
                 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
             }
             //process premiums
             if (!empty($value['product_name'])) {
                 if ($value['product_name'][0] > 0) {
                     list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
                     $value['hidden_Premium'] = 1;
                     $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
                     $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1);
                     CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
                 }
             }
             // end of premium
             //send receipt mail.
             if ($membership->id && !empty($value['send_receipt'])) {
                 // add the domain email id
                 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
                 $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
                 $value['from_email_address'] = $domainEmail;
                 $value['membership_id'] = $membership->id;
                 CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
             }
         }
     }
     return TRUE;
 }
Ejemplo n.º 10
0
 /**
  * Process membership records.
  *
  * @param array $params
  *   Associated array of submitted values.
  *
  *
  * @return bool
  */
 private function processMembership(&$params)
 {
     $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
     // get the price set associated with offline membership
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
     $this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             // if contact is not selected we should skip the row
             if (empty($params['primary_contact_id'][$key])) {
                 continue;
             }
             $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
             // update contact information
             $this->updateContactInfo($value);
             $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
             foreach ($dateTypes as $dateField => $dateVariable) {
                 ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
                 $fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
             }
             $calcDates = array();
             $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
             foreach ($calcDates as $memType => $calcDate) {
                 foreach ($dates as $d) {
                     //first give priority to form values then calDates.
                     $date = CRM_Utils_Array::value($d, $value);
                     if (!$date) {
                         $date = CRM_Utils_Array::value($d, $calcDate);
                     }
                     $value[$d] = CRM_Utils_Date::processDate($date);
                 }
             }
             if (!empty($value['send_receipt'])) {
                 $value['receipt_date'] = date('Y-m-d His');
             }
             if (!empty($value['membership_source'])) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             if (!empty($value['membership_status'])) {
                 $value['status_id'] = $value['membership_status'];
                 unset($value['membership_status']);
             }
             if (empty($customFields)) {
                 // membership type custom data
                 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
                 $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
             }
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $key, 'Membership', $membershipTypeId);
             if (!empty($value['financial_type'])) {
                 $value['financial_type_id'] = $value['financial_type'];
             }
             if (!empty($value['payment_instrument'])) {
                 $value['payment_instrument_id'] = $value['payment_instrument'];
             }
             // handle soft credit
             if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
                 $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key];
                 $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]);
                 //CRM-15350: if soft-credit-type profile field is disabled or removed then
                 //we choose Gift as default value as per Gift Membership rule
                 if (!empty($params['soft_credit_type'][$key])) {
                     $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key];
                 } else {
                     $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
                 }
             }
             if (!empty($value['receive_date'])) {
                 $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
             }
             $params['actualBatchTotal'] += $value['total_amount'];
             unset($value['financial_type']);
             unset($value['payment_instrument']);
             $value['batch_id'] = $this->_batchId;
             $value['skipRecentView'] = TRUE;
             // make entry in line item for contribution
             $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
             $editedResults = array();
             CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
             if (!empty($editedResults)) {
                 unset($this->_priceSet['fields']);
                 $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
                 unset($this->_priceSet['fields'][$editedResults['id']]['options']);
                 $fid = $editedResults['id'];
                 $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
                 $editedResults = array();
                 CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
                 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
                 if (!empty($value['total_amount'])) {
                     $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
                 }
                 $fieldID = key($this->_priceSet['fields']);
                 $value['price_' . $fieldID] = $editedResults['id'];
                 $lineItem = array();
                 CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
                 //CRM-11529 for backoffice transactions
                 //when financial_type_id is passed in form, update the
                 //lineitems with the financial type selected in form
                 if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) {
                     foreach ($lineItem[$priceSetId] as &$values) {
                         $values['financial_type_id'] = $value['financial_type_id'];
                     }
                 }
                 $value['lineItems'] = $lineItem;
                 $value['processPriceSet'] = TRUE;
             }
             // end of contribution related section
             unset($value['membership_type']);
             unset($value['membership_start_date']);
             unset($value['membership_end_date']);
             $value['is_renew'] = FALSE;
             if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
                 // The following parameter setting may be obsolete.
                 $this->_params = $params;
                 $value['is_renew'] = TRUE;
                 $isPayLater = CRM_Utils_Array::value('is_pay_later', $params);
                 $campaignId = NULL;
                 if (isset($this->_values) && is_array($this->_values) && !empty($this->_values)) {
                     $campaignId = CRM_Utils_Array::value('campaign_id', $this->_params);
                     if (!array_key_exists('campaign_id', $this->_params)) {
                         $campaignId = CRM_Utils_Array::value('campaign_id', $this->_values);
                     }
                 }
                 foreach (array('join_date', 'start_date', 'end_date') as $dateType) {
                     //CRM-18000 - ignore $dateType if its not explicitly passed
                     if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) {
                         $formDates[$dateType] = CRM_Utils_Array::value($dateType, $value);
                     }
                 }
                 $membershipSource = CRM_Utils_Array::value('source', $value);
                 list($membership) = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, NULL, NULL, $value['custom'], 1, NULL, FALSE, NULL, $membershipSource, $isPayLater, $campaignId, $formDates);
                 // make contribution entry
                 $contrbutionParams = array_merge($value, array('membership_id' => $membership->id));
                 // @todo - calling this from here is pretty hacky since it is called from membership.create anyway
                 // This form should set the correct params & not call this fn directly.
                 CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
             } else {
                 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
             }
             //process premiums
             if (!empty($value['product_name'])) {
                 if ($value['product_name'][0] > 0) {
                     list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
                     $value['hidden_Premium'] = 1;
                     $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
                     $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'), 'product_option' => $value['product_option'], 'quantity' => 1);
                     CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
                 }
             }
             // end of premium
             //send receipt mail.
             if ($membership->id && !empty($value['send_receipt'])) {
                 // add the domain email id
                 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
                 $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
                 $value['from_email_address'] = $domainEmail;
                 $value['membership_id'] = $membership->id;
                 $value['contribution_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id');
                 CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
             }
         }
     }
     return TRUE;
 }
Ejemplo n.º 11
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     // Check for Credit Card Contribution.
     if ($self->_mode) {
         if (empty($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
         } else {
             // validate payment instrument (e.g. credit card number)
             CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, NULL);
         }
     }
     // Do the amount validations.
     if (empty($fields['total_amount']) && empty($self->_lineItems)) {
         if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $fields, $errors);
         }
     }
     $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
     if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
         $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
         // For taxable contribution we need to deduct taxable amount from
         // (net amount + fee amount) before comparing it with total amount
         if (!empty($self->_values['tax_amount'])) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($self->_id);
             if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
                 $sum = CRM_Utils_Money::format($sum - $self->_values['tax_amount'], NULL, '%a');
             }
         }
         if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
             $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
         }
     }
     //CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
     CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors);
     // Form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
         CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
     }
     // CRM-16015, add form-rule to restrict change of financial type if using price field of different financial type
     if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['financial_type_id'] != $fields['financial_type_id']) {
         CRM_Contribute_BAO_Contribution::checkFinancialTypeChange(NULL, $self->_id, $errors);
     }
     //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if (!empty($fields['fee_amount']) && !empty($fields['financial_type_id']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id']))) {
         $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     // $trxn_id must be unique CRM-13919
     if (!empty($fields['trxn_id'])) {
         $queryParams = array(1 => array($fields['trxn_id'], 'String'));
         $query = 'select count(*) from civicrm_contribution where trxn_id = %1';
         if ($self->_id) {
             $queryParams[2] = array((int) $self->_id, 'Integer');
             $query .= ' and id !=%2';
         }
         $tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
         if ($tCnt) {
             $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
         }
     }
     $errors = array_merge($errors, $softErrors);
     return $errors;
 }
Ejemplo n.º 12
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));
 }
 /**
  * Build price options.
  *
  * @param CRM_Event_BAO_Event $event
  *
  * @return array
  */
 public function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $event->id);
     //CRM-14492 display admin fields only if user is admin
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) {
                 $field_name = "event_{$event->id}_price_{$field['id']}";
                 CRM_Price_BAO_PriceField::addQuickFormElement($this, $field_name, $field['id'], FALSE);
                 $price_fields_for_event[] = $field_name;
             }
         }
     }
     return $price_fields_for_event;
 }
Ejemplo n.º 14
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->assign('groupTree', $this->_groupTree);
     // add the form elements
     foreach ($this->_groupTree as $group) {
         if (is_array($group['fields']) && !empty($group['fields'])) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'price_' . $fieldId;
                 CRM_Price_BAO_PriceField::addQuickFormElement($this, $elementName, $fieldId, FALSE, $field['is_required']);
             }
         }
     }
     $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done with Preview'), 'isDefault' => TRUE)));
 }
Ejemplo n.º 15
0
 /**
  * Build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
         $validFieldsOnly = FALSE;
     }
     $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $form->_quickConfig = $quickConfig;
     }
     $form->assign('priceSet', $form->_priceSet);
     $component = 'contribution';
     if ($className == 'CRM_Member_Form_Membership') {
         $component = 'membership';
     }
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
         if (!empty($form->_useForMember)) {
             $component = 'membership';
         }
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     foreach ($feeBlock as $id => $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $userid = $form->getVar('_membershipContactID');
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
                 continue;
             }
             CRM_Price_BAO_PriceField::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
Ejemplo n.º 17
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.º 18
0
 /**
  * Global validation rules for the form.
  *
  * @param array $values
  *   Posted values of the form.
  * @param $files
  * @param $self
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRule($values, $files, $self)
 {
     // If $values['_qf_Participant_next'] is Delete or
     // $values['event_id'] is empty, then return
     // instead of proceeding further.
     if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) {
         return TRUE;
     }
     $errorMsg = array();
     if (!empty($values['payment_processor_id'])) {
         // make sure that payment instrument values (e.g. credit card number and cvv) are valid
         CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
     }
     if (!empty($values['record_contribution'])) {
         if (empty($values['financial_type_id'])) {
             $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
         }
         if (empty($values['payment_instrument_id'])) {
             $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
     }
     // do the amount validations.
     //skip for update mode since amount is freeze, CRM-6052
     if (!$self->_id && empty($values['total_amount']) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) {
         if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
         }
     }
     // For single additions - show validation error if the contact has already been registered
     // for this event with the same role.
     if ($self->_single && $self->_action & CRM_Core_Action::ADD) {
         $contactId = $self->_contactId;
         $eventId = CRM_Utils_Array::value('event_id', $values);
         if (!empty($contactId) && !empty($eventId)) {
             $dupeCheck = new CRM_Event_BAO_Participant();
             $dupeCheck->contact_id = $contactId;
             $dupeCheck->event_id = $eventId;
             $dupeCheck->find(TRUE);
             if (!empty($dupeCheck->id)) {
                 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
             }
         }
     }
     return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
 }
Ejemplo n.º 19
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the group id
     $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     if ($this->_sid) {
         $usedBy = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid);
         $this->assign('usedBy', $usedBy);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
         CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
         $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page', 'EventTemplate' => 'civicrm_event_template');
         $priceSetContexts = array();
         foreach ($comps as $name => $table) {
             if (array_key_exists($table, $usedBy)) {
                 $priceSetContexts[] = $name;
             }
         }
         $this->assign('contexts', $priceSetContexts);
     }
     if ($action & CRM_Core_Action::DELETE && !$this->_isSetReserved) {
         if (empty($usedBy)) {
             // prompt to delete
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
             $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
             $controller->set('fid', $fid);
             $controller->setEmbedded(TRUE);
             $controller->process();
             $controller->run();
         } else {
             // add breadcrumb
             $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
             CRM_Utils_System::appendBreadCrumb(ts('Price'), $url);
             $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField::getTitle($fid));
         }
     }
     if ($this->_sid) {
         $groupTitle = CRM_Price_BAO_PriceSet::getTitle($this->_sid);
         $this->assign('sid', $this->_sid);
         $this->assign('groupTitle', $groupTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
     }
     // assign vars to templates
     $this->assign('action', $action);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } elseif ($action & CRM_Core_Action::PREVIEW) {
         $this->preview($fid);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }
Ejemplo n.º 20
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function run()
 {
     // get the field id
     $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0);
     //get the price set id
     if (!$this->_sid) {
         $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
     }
     if ($this->_sid) {
         CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
         $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
         $this->assign('isReserved', $this->_isSetReserved);
     }
     //as url contain $sid so append breadcrumb dynamically.
     $breadcrumb = array(array('title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid)));
     CRM_Utils_System::appendBreadCrumb($breadcrumb);
     if ($this->_fid) {
         $fieldTitle = CRM_Price_BAO_PriceField::getTitle($this->_fid);
         $this->assign('fid', $this->_fid);
         $this->assign('fieldTitle', $fieldTitle);
         CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
         $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
         $this->assign('addMoreFields', TRUE);
         //for text price field only single option present
         if ($htmlType == 'Text') {
             $this->assign('addMoreFields', FALSE);
         }
     }
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // assign vars to templates
     $this->assign('action', $action);
     $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0);
     // what action to take ?
     if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE) && !$this->_isSetReserved) {
         // no browse for edit/update/view
         $this->edit($action);
     } else {
         $this->browse();
     }
     // Call the parents run method
     return parent::run();
 }
Ejemplo n.º 21
0
 /**
  * @param array $params
  * @param int $previousID
  * @param int $membershipTypeId
  */
 public static function createMembershipPriceField($params, $previousID, $membershipTypeId)
 {
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
     if (!empty($params['member_of_contact_id'])) {
         $fieldName = $params['member_of_contact_id'];
     } else {
         $fieldName = $previousID;
     }
     $fieldLabel = 'Membership Amount';
     $optionsIds = NULL;
     $fieldParams = array('price_set_id ' => $priceSetId, 'name' => $fieldName);
     $results = array();
     CRM_Price_BAO_PriceField::retrieve($fieldParams, $results);
     if (empty($results)) {
         $fieldParams = array();
         $fieldParams['label'] = $fieldLabel;
         $fieldParams['name'] = $fieldName;
         $fieldParams['price_set_id'] = $priceSetId;
         $fieldParams['html_type'] = 'Radio';
         $fieldParams['is_display_amounts'] = $fieldParams['is_required'] = 0;
         $fieldParams['weight'] = $fieldParams['option_weight'][1] = 1;
         $fieldParams['option_label'][1] = $params['name'];
         $fieldParams['option_description'][1] = CRM_Utils_Array::value('description', $params);
         $fieldParams['membership_type_id'][1] = $membershipTypeId;
         $fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
         $fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
         if ($previousID) {
             CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
             $fieldParams['option_id'] = CRM_Utils_Array::value('option_id', $optionsIds);
         }
         CRM_Price_BAO_PriceField::create($fieldParams);
     } else {
         $fieldID = $results['id'];
         $fieldValueParams = array('price_field_id' => $fieldID, 'membership_type_id' => $membershipTypeId);
         $results = array();
         CRM_Price_BAO_PriceFieldValue::retrieve($fieldValueParams, $results);
         if (!empty($results)) {
             $results['label'] = $results['name'] = $params['name'];
             $results['amount'] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
             $optionsIds['id'] = $results['id'];
         } else {
             $results = array('price_field_id' => $fieldID, 'name' => $params['name'], 'label' => $params['name'], 'amount' => empty($params['minimum_fee']) ? 0 : $params['minimum_fee'], 'membership_type_id' => $membershipTypeId, 'is_active' => 1);
         }
         if ($previousID) {
             CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
             if (!empty($optionsIds['option_id'])) {
                 $optionsIds['id'] = current(CRM_Utils_Array::value('option_id', $optionsIds));
             }
         }
         $results['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
         $results['description'] = CRM_Utils_Array::value('description', $params);
         CRM_Price_BAO_PriceFieldValue::add($results, $optionsIds);
     }
 }
Ejemplo n.º 22
0
 /**
  * global form rule
  *
  * @param array $fields the input form values
  * @param array $files the uploaded files if any
  * @param $self
  *
  * @internal param array $options additional user data
  *
  * @return true if no errors, else array of errors
  * @access public
  * @static
  */
 static function formRule($fields, $files, $self)
 {
     $errors = array();
     //check for Credit Card Contribution.
     if ($self->_mode) {
         if (empty($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
         }
     }
     // do the amount validations.
     if (empty($fields['total_amount']) && empty($self->_lineItems)) {
         if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $fields, $errors);
         }
     }
     $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
     if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
         $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
         if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
             $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
         }
     }
     //form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if ($self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
         CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
     }
     //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if (!empty($fields['fee_amount']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id']))) {
         $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     // $trxn_id must be unique CRM-13919
     if (!empty($fields['trxn_id'])) {
         $queryParams = array(1 => array($fields['trxn_id'], 'String'));
         $query = 'select count(*) from civicrm_contribution where trxn_id = %1';
         if ($self->_id) {
             $queryParams[2] = array((int) $self->_id, 'Integer');
             $query .= ' and id !=%2';
         }
         $tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
         if ($tCnt) {
             $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
         }
     }
     $errors = array_merge($errors, $softErrors);
     return $errors;
 }
Ejemplo n.º 23
0
 /**
  * This function for building custom fields
  *
  * @param CRM_Core_Form $qf form object (reference)
  * @param string $elementName name of the custom field
  * @param $fieldId
  * @param boolean $inactiveNeeded
  * @param boolean $useRequired true if required else false
  * @param string $label label for custom field
  *
  * @param null $fieldOptions
  * @param array $feezeOptions
  *
  * @return null
  * @internal param bool $search true if used for search else false
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array())
 {
     $field = new CRM_Price_DAO_PriceField();
     $field->id = $fieldId;
     if (!$field->find(TRUE)) {
         /* FIXME: failure! */
         return NULL;
     }
     $is_pay_later = 0;
     if (isset($qf->_mode) && empty($qf->_mode)) {
         $is_pay_later = 1;
     } elseif (isset($qf->_values)) {
         $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
     }
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $qf->assign('currencySymbol', $currencySymbol);
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
     if (!isset($label)) {
         $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
     }
     if ($field->name == 'contribution_amount') {
         $qf->_contributionAmount = 1;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = FALSE;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
             $extra = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 foreach ($fieldOptions as &$fieldOption) {
                     if ($fieldOption['name'] == 'other_amount') {
                         $fieldOption['label'] = $fieldOption['label'] . '  ' . $currencySymbol;
                     }
                 }
                 $qf->assign('priceset', $elementName);
                 $extra = array('onclick' => 'useAmountOther();');
             }
             if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
                 $useRequired = 0;
             } elseif (!empty($fieldOptions[$optionKey]['label'])) {
                 //check for label.
                 $label = $fieldOptions[$optionKey]['label'];
             }
             $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
             if ($is_pay_later) {
                 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
             }
             // CRM-6902
             if (in_array($optionKey, $feezeOptions)) {
                 $element->freeze();
             }
             //CRM-10117
             if (!empty($qf->_quickConfig)) {
                 $message = ts('Please enter a valid amount.');
                 $type = 'money';
             } else {
                 $message = ts('%1 must be an integer (whole number).', array(1 => $label));
                 $type = 'positiveInteger';
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, $message, $type);
             break;
         case 'Radio':
             $choice = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 $qf->assign('contriPriceset', $elementName);
             }
             foreach ($customOption as $opId => $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] = !empty($opt['label']) ? $opt['label'] : '';
                     $opt['label'] = '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span> <span class="crm-price-amount-label">' . $opt['label'] . '</span>';
                 }
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 $extra = array('price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName);
                 if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
                     $extra += array('onclick' => 'clearAmountOther();');
                 } elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
                     $extra += array('onclick' => "return showHideAutoRenew({$opt['membership_type_id']});", 'membership-type' => $opt['membership_type_id']);
                     $qf->assign('membershipFieldID', $field->id);
                 }
                 $choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $choice[$opId]->freeze();
                 }
             }
             if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
                 $choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1', array('onclick' => 'clearAmountOther();'));
             }
             if (!$field->is_required) {
                 // add "none" option
                 if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
                     $none = ts('Other Amount');
                 } elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
                     $none = ts('No thank you');
                 } else {
                     $none = ts('- none -');
                 }
                 $choice[] = $qf->createElement('radio', NULL, '', $none, '0', array('price' => json_encode(array($elementName, '0'))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             // make contribution field required for quick config when membership block is enabled
             if (($field->name == 'membership_amount' || $field->name == 'contribution_amount') && !empty($qf->_membershipBlock) && !$field->is_required) {
                 $useRequired = $field->is_required = TRUE;
             }
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $selectOption = $allowedOptions = $priceVal = array();
             foreach ($customOption as $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
                 if (!in_array($opt['id'], $feezeOptions)) {
                     $allowedOptions[] = $opt['id'];
                 }
                 if ($is_pay_later) {
                     $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
                 }
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($priceVal)));
             // CRM-6902
             $button = substr($qf->controller->getButtonName(), -4);
             if (!empty($feezeOptions) && $button != 'skip') {
                 $qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
             }
             break;
         case 'CheckBox':
             $check = array();
             foreach ($customOption as $opId => $opt) {
                 $count = CRM_Utils_Array::value('count', $opt, '');
                 $max_value = CRM_Utils_Array::value('max_value', $opt, '');
                 $priceVal = implode($seperator, array($opt[$valueFieldName], $count, $max_value));
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[$opId] =& $qf->createElement('checkbox', $opt['id'], NULL, $opt['label'], array('price' => json_encode(array($opt['id'], $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName));
                 if ($is_pay_later) {
                     $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
                     $qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
                 }
                 // CRM-6902
                 if (in_array($opId, $feezeOptions)) {
                     $check[$opId]->freeze();
                 }
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
Ejemplo n.º 24
0
 /**
  * Record line items for default membership.
  * @deprecated
  *
  * Use getQuickConfigMembershipLineItems
  *
  * @param CRM_Core_Form $qf
  * @param array $membershipType
  *   Array with membership type and organization.
  *
  * @return int $priceSetId
  */
 public static function createLineItems(&$qf, $membershipType)
 {
     $qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
     $qf->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
     // The name of the price field corresponds to the membership_type organization contact.
     $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $membershipType[0]);
     $editedResults = array();
     CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
     if (!empty($editedResults)) {
         unset($qf->_priceSet['fields']);
         $qf->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
         unset($qf->_priceSet['fields'][$editedResults['id']]['options']);
         $fid = $editedResults['id'];
         $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipType[1]);
         $editedResults = array();
         CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
         $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
         if (!empty($qf->_params['total_amount'])) {
             $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $qf->_params['total_amount'];
         }
     }
     $fieldID = key($qf->_priceSet['fields']);
     $qf->_params['price_' . $fieldID] = CRM_Utils_Array::value('id', $editedResults);
     return $priceSetId;
 }
Ejemplo n.º 25
0
 /**
  * Validation.
  *
  * @param array $params
  *   (ref.) an assoc array of name/value pairs.
  *
  * @param $files
  * @param $self
  *
  * @throws CiviCRM_API3_Exception
  * @return bool|array
  *   mixed true or array of errors
  */
 public static function formRule($params, $files, $self)
 {
     $errors = array();
     $priceSetId = CRM_Utils_Array::value('price_set_id', $params);
     if ($priceSetId) {
         CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors);
         $priceFieldIDS = array();
         foreach ($self->_priceSet['fields'] as $priceIds => $field) {
             if (!empty($params['price_' . $priceIds])) {
                 if (is_array($params['price_' . $priceIds])) {
                     foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) {
                         if ($isSet) {
                             $priceFieldIDS[] = $priceFldVal;
                         }
                     }
                 } elseif (!$field['is_enter_qty']) {
                     $priceFieldIDS[] = $params['price_' . $priceIds];
                 }
             }
         }
         if (!empty($priceFieldIDS)) {
             $ids = implode(',', $priceFieldIDS);
             $count = CRM_Price_BAO_PriceSet::getMembershipCount($ids);
             foreach ($count as $id => $occurance) {
                 if ($occurance > 1) {
                     $errors['_qf_default'] = ts('Select at most one option associated with the same membership type.');
                 }
             }
             foreach ($priceFieldIDS as $priceFieldId) {
                 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
                     $self->_memTypeSelected[$id] = $id;
                 }
             }
         }
     } elseif (empty($params['membership_type_id'][1])) {
         $errors['membership_type_id'] = ts('Please select a membership type.');
     } else {
         $self->_memTypeSelected[] = $params['membership_type_id'][1];
     }
     if (!$priceSetId) {
         $numterms = CRM_Utils_Array::value('num_terms', $params);
         if ($numterms && intval($numterms) != $numterms) {
             $errors['num_terms'] = ts('Please enter an integer for the number of terms.');
         }
     }
     // Return error if empty $self->_memTypeSelected
     if ($priceSetId && empty($errors) && empty($self->_memTypeSelected)) {
         $errors['_qf_default'] = ts('Select at least one membership option.');
     }
     if (!empty($errors) && count($self->_memTypeSelected) > 1) {
         $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($self->_memTypeSelected);
         $duplicateMemberOfContacts = array_count_values($memberOfContacts);
         foreach ($duplicateMemberOfContacts as $countDuplicate) {
             if ($countDuplicate > 1) {
                 $errors['_qf_default'] = ts('Please do not select more than one membership associated with the same organization.');
             }
         }
     }
     if (!empty($errors)) {
         return $errors;
     }
     if ($priceSetId && !$self->_mode && empty($params['record_contribution'])) {
         $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.');
     }
     if (!$priceSetId && $self->_mode && empty($params['financial_type_id'])) {
         $errors['financial_type_id'] = ts('Please enter the financial Type.');
     }
     if (!empty($params['record_contribution']) && empty($params['payment_instrument_id'])) {
         $errors['payment_instrument_id'] = ts('Paid By is a required field.');
     }
     if (!empty($params['is_different_contribution_contact'])) {
         if (empty($params['soft_credit_type_id'])) {
             $errors['soft_credit_type_id'] = ts('Please Select a Soft Credit Type');
         }
         if (empty($params['soft_credit_contact_id'])) {
             $errors['soft_credit_contact_id'] = ts('Please select a contact');
         }
     }
     if (!empty($params['payment_processor_id'])) {
         // validate payment instrument (e.g. credit card number)
         CRM_Core_Payment_Form::validatePaymentInstrument($params['payment_processor_id'], $params, $errors, $self);
     }
     $joinDate = NULL;
     if (!empty($params['join_date'])) {
         $joinDate = CRM_Utils_Date::processDate($params['join_date']);
         foreach ($self->_memTypeSelected as $memType) {
             $startDate = NULL;
             if (!empty($params['start_date'])) {
                 $startDate = CRM_Utils_Date::processDate($params['start_date']);
             }
             // if end date is set, ensure that start date is also set
             // and that end date is later than start date
             $endDate = NULL;
             if (!empty($params['end_date'])) {
                 $endDate = CRM_Utils_Date::processDate($params['end_date']);
             }
             $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
             if ($startDate && CRM_Utils_Array::value('period_type', $membershipDetails) == 'rolling') {
                 if ($startDate < $joinDate) {
                     $errors['start_date'] = ts('Start date must be the same or later than Member since.');
                 }
             }
             if ($endDate) {
                 if ($membershipDetails['duration_unit'] == 'lifetime') {
                     // Check if status is NOT cancelled or similar. For lifetime memberships, there is no automated
                     // process to update status based on end-date. The user must change the status now.
                     $result = civicrm_api3('MembershipStatus', 'get', array('sequential' => 1, 'is_current_member' => 0));
                     $tmp_statuses = $result['values'];
                     $status_ids = array();
                     foreach ($tmp_statuses as $cur_stat) {
                         $status_ids[] = $cur_stat['id'];
                     }
                     if (empty($params['status_id']) || in_array($params['status_id'], $status_ids) == FALSE) {
                         $errors['status_id'] = ts('Please enter a status that does NOT represent a current membership status.');
                         $errors['is_override'] = ts('This must be checked because you set an End Date for a lifetime membership');
                     }
                 } else {
                     if (!$startDate) {
                         $errors['start_date'] = ts('Start date must be set if end date is set.');
                     }
                     if ($endDate < $startDate) {
                         $errors['end_date'] = ts('End date must be the same or later than start date.');
                     }
                 }
             }
             //  Default values for start and end dates if not supplied
             //  on the form
             $defaultDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
             if (!$startDate) {
                 $startDate = CRM_Utils_Array::value('start_date', $defaultDates);
             }
             if (!$endDate) {
                 $endDate = CRM_Utils_Array::value('end_date', $defaultDates);
             }
             //CRM-3724, check for availability of valid membership status.
             if (empty($params['is_override']) && !isset($errors['_qf_default'])) {
                 $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', TRUE, $memType, $params);
                 if (empty($calcStatus)) {
                     $url = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', 'reset=1&action=browse');
                     $errors['_qf_default'] = ts('There is no valid Membership Status available for selected membership dates.');
                     $status = ts('Oops, it looks like there is no valid membership status available for the given membership dates. You can <a href="%1">Configure Membership Status Rules</a>.', array(1 => $url));
                     if (!$self->_mode) {
                         $status .= ' ' . ts('OR You can sign up by setting Status Override? to true.');
                     }
                     CRM_Core_Session::setStatus($status, ts('Membership Status Error'), 'error');
                 }
             }
         }
     } else {
         $errors['join_date'] = ts('Please enter the Member Since.');
     }
     if (isset($params['is_override']) && $params['is_override'] && empty($params['status_id'])) {
         $errors['status_id'] = ts('Please enter the status.');
     }
     //total amount condition arise when membership type having no
     //minimum fee
     if (isset($params['record_contribution'])) {
         if (!$params['financial_type_id']) {
             $errors['financial_type_id'] = ts('Please enter the financial Type.');
         }
         if (CRM_Utils_System::isNull($params['total_amount'])) {
             $errors['total_amount'] = ts('Please enter the contribution.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && !empty($params['record_contribution']) && CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errors['contribution_status_id'] = ts('Please select a valid payment status before updating.');
     }
     return empty($errors) ? TRUE : $errors;
 }
Ejemplo n.º 26
0
 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  *
  * @return array list of errors to be posted back to the form
  * @static
  * @access public
  */
 static function formRule($values, $files, $self)
 {
     // If $values['_qf_Participant_next'] is Delete or
     // $values['event_id'] is empty, then return
     // instead of proceeding further.
     if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) {
         return TRUE;
     }
     $errorMsg = array();
     //check if contact is selected in standalone mode
     if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
         $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
     }
     if (CRM_Utils_Array::value('payment_processor_id', $values)) {
         // make sure that credit card number and cvv are valid
         CRM_Core_Payment_Form::validateCreditCard($values, $errorMsg);
     }
     if (CRM_Utils_Array::value('record_contribution', $values)) {
         if (!CRM_Utils_Array::value('financial_type_id', $values)) {
             $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
         }
         if (!CRM_Utils_Array::value('payment_instrument_id', $values)) {
             $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $values) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
     }
     // do the amount validations.
     //skip for update mode since amount is freeze, CRM-6052
     if (!$self->_id && !CRM_Utils_Array::value('total_amount', $values) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) {
         if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
         }
     }
     return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
 }
Ejemplo n.º 27
0
 /**
  * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
  */
 public function testfixEventLevel()
 {
     $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);
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, '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' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'option_name' => array('1' => 10), 'option_weight' => 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');
     $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' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
     $participant = CRM_Event_BAO_Participant::add($participantParams);
     //Checking for participant added in the table.
     $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant');
     $values = array();
     $ids = array();
     $params = array('id' => $participant->id);
     CRM_Event_BAO_Participant::getValues($params, $values, $ids);
     $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
     CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]);
     if ($values[$participant->id]['fee_level']) {
         CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']);
     }
     $deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id);
     $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.');
     $deletePriceset = CRM_Price_BAO_PriceSet::deleteSet($priceset->id);
     $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.');
     Participant::delete($participant->id);
     Contact::delete($this->_contactId);
     Event::delete($eventId);
 }
Ejemplo n.º 28
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();
 }
Ejemplo n.º 29
0
 /**
  * Get line items representing the default price set.
  *
  * @param int $membershipOrg
  * @param int $membershipTypeID
  * @param float $total_amount
  * @param int $priceSetId
  *
  * @return array
  */
 public static function setQuickConfigMembershipParameters($membershipOrg, $membershipTypeID, $total_amount, $priceSetId)
 {
     $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
     // The name of the price field corresponds to the membership_type organization contact.
     $params = array('price_set_id' => $priceSetId, 'name' => $membershipOrg);
     $results = array();
     CRM_Price_BAO_PriceField::retrieve($params, $results);
     if (!empty($results)) {
         $fields[$results['id']] = $priceSets['fields'][$results['id']];
         $fid = $results['id'];
         $editedFieldParams = array('price_field_id' => $results['id'], 'membership_type_id' => $membershipTypeID);
         $results = array();
         CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $results);
         $fields[$fid]['options'][$results['id']] = $priceSets['fields'][$fid]['options'][$results['id']];
         if (!empty($total_amount)) {
             $fields[$fid]['options'][$results['id']]['amount'] = $total_amount;
         }
     }
     $fieldID = key($fields);
     $returnParams = array('price_set_id' => $priceSetId, 'price_sets' => $priceSets, 'fields' => $fields, 'price_fields' => array('price_' . $fieldID => CRM_Utils_Array::value('id', $results)));
     return $returnParams;
 }
Ejemplo n.º 30
0
 /**
  * @param int $previousID
  * @param int $priceSetId
  * @param int $membershipTypeId
  * @param $optionsIds
  */
 public static function checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, &$optionsIds)
 {
     if ($previousID) {
         $editedFieldParams = array('price_set_id ' => $priceSetId, 'name' => $previousID);
         $editedResults = array();
         CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
         if (!empty($editedResults)) {
             $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipTypeId);
             $editedResults = array();
             CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults);
             $optionsIds['option_id'][1] = CRM_Utils_Array::value('id', $editedResults);
         }
     }
 }