Exemplo n.º 1
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_FieldValue::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         $defaults['value'] = CRM_Utils_Money::format(CRM_Utils_Array::value('value', $defaults), NULL, '%a');
     }
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_FieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
Exemplo n.º 2
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     require_once 'CRM/Price/BAO/FieldValue.php';
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_FieldValue::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         require_once 'CRM/Utils/Money.php';
         $defaults['value'] = CRM_Utils_Money::format($defaults['value'], null, '%a');
     }
     require_once 'CRM/Core/DAO.php';
     require_once 'CRM/Utils/Weight.php';
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_FieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
Exemplo n.º 3
0
 /**
  * process membership records
  *
  * @param array $params associated array of submitted values
  *
  * @access public
  *
  * @return None
  */
 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_Set', 'default_membership_type_amount', 'id', 'name');
     $this->_priceSet = $priceSets = current(CRM_Price_BAO_Set::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 (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) {
                 continue;
             }
             $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_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 (CRM_Utils_Array::value('send_receipt', $value)) {
                 $value['receipt_date'] = date('Y-m-d His');
             }
             if (CRM_Utils_Array::value('membership_source', $value)) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             if (CRM_Utils_Array::value('membership_status', $value)) {
                 $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 (CRM_Utils_Array::value('contribution_type', $value)) {
                 $value['contribution_type_id'] = $value['contribution_type'];
             }
             if (CRM_Utils_Array::value('payment_instrument', $value)) {
                 $value['payment_instrument_id'] = $value['payment_instrument'];
             }
             // handle soft credit
             if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) {
                 $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key];
             }
             if (CRM_Utils_Array::value('receive_date', $value)) {
                 $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
             }
             $params['actualBatchTotal'] += $value['total_amount'];
             unset($value['contribution_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_Field::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_FieldValue::retrieve($editedFieldParams, $editedResults);
                 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
                 if (CRM_Utils_Array::value('total_amount', $value)) {
                     $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_Set::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
                 $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 (CRM_Utils_Array::value('member_option', $params) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
                 $this->_params = $params;
                 $value['is_renew'] = true;
                 $membership = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']);
                 // make contribution entry
                 CRM_Member_BAO_Membership::recordMembershipContribution($value, CRM_Core_DAO::$_nullArray, $membership->id);
             } else {
                 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
             }
             //process premiums
             if (CRM_Utils_Array::value('product_name', $value)) {
                 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 && CRM_Utils_Array::value('send_receipt', $value)) {
                 // 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);
             }
         }
     }
 }
 function checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, &$optionsIds)
 {
     if ($previousID) {
         $editedFieldParams = array('price_set_id ' => $priceSetId, 'name' => $previousID);
         $editedResults = array();
         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
         if (!empty($editedResults)) {
             $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipTypeId);
             $editedResults = array();
             CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
             $optionsIds['option_id'][1] = CRM_Utils_Array::value('id', $editedResults);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     // is it an edit operation ?
     if (isset($this->_fid)) {
         $params = array('id' => $this->_fid);
         $this->assign('fid', $this->_fid);
         CRM_Price_BAO_Field::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $valueParams = array('price_field_id' => $this->_fid);
             CRM_Price_BAO_FieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], NULL, '%a');
         }
         if (CRM_Utils_Array::value('active_on', $defaults)) {
             list($defaults['active_on'], $defaults['active_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
         }
         if (CRM_Utils_Array::value('expire_on', $defaults)) {
             list($defaults['expire_on'], $defaults['expire_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
         }
     } else {
         $defaults['is_active'] = 1;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_status[' . $i . ']'] = 1;
             $defaults['option_weight[' . $i . ']'] = $i;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('price_set_id' => $this->_sid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_Field', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     return $defaults;
 }
Exemplo n.º 6
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array    array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     // is it an edit operation ?
     if (isset($this->_fid)) {
         $params = array('id' => $this->_fid);
         $this->assign('id', $this->_fid);
         CRM_Price_BAO_Field::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $valueParams = array('price_field_id' => $this->_fid);
             require_once 'CRM/Price/BAO/FieldValue.php';
             CRM_Price_BAO_FieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             require_once 'CRM/Utils/Money.php';
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], null, '%a');
         }
     } else {
         $defaults['is_active'] = 1;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_status[' . $i . ']'] = 1;
             $defaults['option_weight[' . $i . ']'] = $i;
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         require_once 'CRM/Utils/Weight.php';
         $fieldValues = array('price_set_id' => $this->_sid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_Field', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     return $defaults;
 }
 function createMembershipPriceField($params, $ids, $previousID, $membershipTypeId)
 {
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     if (CRM_Utils_Array::value('memberOfContact', $ids)) {
         $fieldName = $ids['memberOfContact'];
     } else {
         $fieldName = $previousID;
     }
     $fieldLabel = 'Membership Amount';
     $optionsIds = NULL;
     $fieldParams = array('price_set_id ' => $priceSetId, 'name' => $fieldName);
     $results = array();
     CRM_Price_BAO_Field::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['membership_type_id'][1] = $membershipTypeId;
         $fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee'];
         if ($previousID) {
             CRM_Member_Form_MembershipType::checkPreviousPriceField($previousID, $priceSetId, $membershipTypeId, $optionsIds);
             $fieldParams['option_id'] = CRM_Utils_Array::value('option_id', $optionsIds);
         }
         $priceField = CRM_Price_BAO_Field::create($fieldParams);
     } else {
         $fieldID = $results['id'];
         $fieldValueParams = array('price_field_id' => $fieldID, 'membership_type_id' => $membershipTypeId);
         $results = array();
         CRM_Price_BAO_FieldValue::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 (CRM_Utils_Array::value('option_id', $optionsIds)) {
                 $optionsIds['id'] = current(CRM_Utils_Array::value('option_id', $optionsIds));
             }
         }
         CRM_Price_BAO_FieldValue::add($results, $optionsIds);
     }
 }
Exemplo n.º 8
0
 /**
  * Browse all price set fields.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_Field();
     // fkey is sid
     $priceFieldBAO->price_set_id = $this->_sid;
     $priceFieldBAO->orderBy('weight, label');
     $priceFieldBAO->find();
     while ($priceFieldBAO->fetch()) {
         $priceField[$priceFieldBAO->id] = array();
         CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
         // get price if it's a text field
         if ($priceFieldBAO->html_type == 'Text') {
             $optionValues = array();
             $params = array('price_field_id' => $priceFieldBAO->id);
             CRM_Price_BAO_FieldValue::retrieve($params, $optionValues);
             $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
         }
         $action = array_sum(array_keys($this->actionLinks()));
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
         } else {
             if ($priceFieldBAO->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['active_on'] = '';
         }
         if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['expire_on'] = '';
         }
         // need to translate html types from the db
         $htmlTypes = CRM_Price_BAO_Field::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
         $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
         $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid));
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
     $filter = "price_set_id = {$this->_sid}";
     CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_Field', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }
 /**
  * Function to record line items for default membership
  *
  * @param $qf object
  *
  * @param $membershipType array with membership type and organization
  *
  * @param$ priceSetId priceset id
  * @access public
  * @static
  */
 static function createLineItems(&$qf, $membershipType, &$priceSetId)
 {
     $qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     if ($priceSetId) {
         $qf->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
     }
     $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $membershipType[0]);
     $editedResults = array();
     CRM_Price_BAO_Field::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_FieldValue::retrieve($editedFieldParams, $editedResults);
         $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
         if (CRM_Utils_Array::value('total_amount', $qf->_params)) {
             $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $qf->_params['total_amount'];
         }
     }
     $fieldID = key($qf->_priceSet['fields']);
     $qf->_params['price_' . $fieldID] = $editedResults['id'];
 }