/**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::COPY)) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $element = $this->add('text', 'code', ts('Discount Code'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'code'), TRUE);
     $this->addRule('code', ts('Code already exists in Database.'), 'objectExists', array('CRM_CiviDiscount_DAO_Item', $this->_id, 'code'));
     $this->addRule('code', ts('Code can only consist of alpha-numeric characters'), 'variable');
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $element->freeze();
     }
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'description'));
     $this->addMoney('amount', ts('Discount Amount'), TRUE, CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'amount'), FALSE);
     $this->add('select', 'amount_type', NULL, array(1 => ts('Percent'), 2 => ts('Fixed Amount')), TRUE);
     $this->add('text', 'count_max', ts('Usage Limit'), CRM_Core_DAO::getAttribute('CRM_CiviDiscount_DAO_Item', 'count_max') + array('min' => 1));
     $this->addRule('count_max', ts('Must be an integer'), 'integer');
     $this->addDate('active_on', ts('Activation Date'), FALSE);
     $this->addDate('expire_on', ts('Expiration Date'), FALSE);
     $this->addEntityRef('organization_id', ts('Organization'), array('api' => array('params' => array('contact_type' => 'Organization'))));
     // is this discount active ?
     $this->addElement('checkbox', 'is_active', ts('Is this discount active?'));
     $this->addElement('checkbox', 'discount_msg_enabled', ts('Display a message to users not eligible for this discount?'));
     $this->add('textarea', 'discount_msg', ts('Message to non-eligible users'), array('class' => 'big'));
     // add memberships, events, pricesets
     $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     if (!empty($membershipTypes)) {
         $this->add('select', 'memberships', ts('Memberships'), $membershipTypes, FALSE, $this->select2style);
     }
     $this->assignAutoDiscountFields();
     $this->addElement('text', 'advanced_autodiscount_filter_entity', ts('Specify entity for advanced autodiscount'));
     $this->addElement('text', 'advanced_autodiscount_filter_string', ts('Specify api string for advanced filter'), array('class' => 'huge'));
     $events = CRM_CiviDiscount_Utils::getEvents();
     if (!empty($events)) {
         $events = array(ts('--any event--')) + $events;
         $this->_multiValued['events'] = $events;
         $this->add('select', 'events', ts('Events'), $events, FALSE, $this->select2style);
         $eventTypes = $this->getOptions('event', 'event_type_id');
         $this->_multiValued['eventtypes'] = $eventTypes;
         $this->add('select', 'event_type_id', ts('Event Types'), $eventTypes, FALSE, $this->select2style);
     }
     $pricesets = CRM_CiviDiscount_Utils::getNestedPriceSets();
     if (!empty($pricesets)) {
         $this->_multiValued['pricesets'] = $pricesets;
         $this->add('select', 'pricesets', ts('Price Field Options'), $pricesets, FALSE, array('placeholder' => ts('- any -')) + $this->select2style);
     }
 }