コード例 #1
0
ファイル: Option.php プロジェクト: kcristiano/civicrm-core
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @return array|void  array of default values
  */
 public function setDefaultValues()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         return NULL;
     }
     $defaults = array();
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_PriceFieldValue::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');
     }
     $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
     if (!isset($defaults['membership_num_terms']) && $memberComponentId == $extendComponentId) {
         $defaults['membership_num_terms'] = 1;
     }
     // set financial type used for price set to set default for new option
     if (!$this->_oid) {
         $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id', 'id');
     }
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceFieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
コード例 #2
0
ファイル: Membership.php プロジェクト: konadave/civicrm-core
 /**
  * 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;
 }
コード例 #3
0
ファイル: Entry.php プロジェクト: prashantgajare/civicrm-core
 /**
  * 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;
 }
コード例 #4
0
ファイル: Field.php プロジェクト: ruchirapingale/civicrm-core
 /**
  * Browse all price set fields.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999);
     }
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
     // 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_PriceFieldValue::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_PriceField::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type_display'] = $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), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id);
     }
     $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_PriceField', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }
コード例 #5
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);
     }
 }
コード例 #6
0
ファイル: Field.php プロジェクト: hyebahi/civicrm-core
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @return array
  *   array of default values
  */
 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_PriceField::retrieve($params, $defaults);
         $this->_sid = $defaults['price_set_id'];
         // if text, retrieve price
         if ($defaults['html_type'] == 'Text') {
             $isActive = $defaults['is_active'];
             $valueParams = array('price_field_id' => $this->_fid);
             CRM_Price_BAO_PriceFieldValue::retrieve($valueParams, $defaults);
             // fix the display of the monetary value, CRM-4038
             $defaults['price'] = CRM_Utils_Money::format($defaults['amount'], NULL, '%a');
             $defaults['is_active'] = $isActive;
         }
         if (!empty($defaults['active_on'])) {
             list($defaults['active_on'], $defaults['active_on_time']) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
         }
         if (!empty($defaults['expire_on'])) {
             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_PriceField', $fieldValues);
         $defaults['options_per_line'] = 1;
         $defaults['is_display_amounts'] = 1;
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (isset($this->_sid) && $this->_action == CRM_Core_Action::ADD) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id');
         $defaults['financial_type_id'] = $financialTypeId;
         for ($i = 1; $i <= self::NUM_OPTION; $i++) {
             $defaults['option_financial_type_id[' . $i . ']'] = $financialTypeId;
         }
     }
     return $defaults;
 }
コード例 #7
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);
         }
     }
 }
コード例 #8
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;
 }
コード例 #9
0
ファイル: Entry.php プロジェクト: kcristiano/civicrm-core
 /**
  * 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;
 }
コード例 #10
0
ファイル: Field.php プロジェクト: scardinius/civicrm-core
 /**
  * Browse all price set fields.
  *
  * @return void
  */
 public function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
     }
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
     // fkey is sid
     $priceFieldBAO->price_set_id = $this->_sid;
     $priceFieldBAO->orderBy('weight, label');
     $priceFieldBAO->find();
     // display taxTerm for priceFields
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $getTaxDetails = FALSE;
     $taxRate = CRM_Core_PseudoConstant::getTaxRates();
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     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_PriceFieldValue::retrieve($params, $optionValues);
             $financialTypeId = $optionValues['financial_type_id'];
             if (!array_key_exists($financialTypeId, $financialTypes)) {
                 unset($priceField[$priceFieldBAO->id]);
                 continue;
             }
             $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
             if ($invoicing && isset($taxRate[$financialTypeId])) {
                 $priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId];
                 $getTaxDetails = TRUE;
             }
             if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate']);
                 $priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
             }
         }
         $action = array_sum(array_keys(self::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_PriceField::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type_display'] = $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), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('getTaxDetails', $getTaxDetails);
     }
     $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_PriceField', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }