当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Rule::cleanMoney方法代码示例

本文整理汇总了PHP中CRM_Utils_Rule::cleanMoney方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Rule::cleanMoney方法的具体用法?PHP CRM_Utils_Rule::cleanMoney怎么用?PHP CRM_Utils_Rule::cleanMoney使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Rule的用法示例。


在下文中一共展示了CRM_Utils_Rule::cleanMoney方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: key

 /**
  * Takes an associative array and creates a participant object.
  *
  * the function extract all the params it needs to initialize the create a
  * participant object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Event_BAO_Participant
  */
 public static function &add(&$params)
 {
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Participant', NULL, $params);
     }
     // converting dates to mysql format
     if (!empty($params['register_date'])) {
         $params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
     }
     if (!empty($params['participant_fee_amount'])) {
         $params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
     }
     if (!empty($params['fee_amount'])) {
         $params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']);
     }
     // ensure that role ids are encoded as a string
     if (isset($params['role_id']) && is_array($params['role_id'])) {
         if (in_array(key($params['role_id']), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
             $op = key($params['role_id']);
             $params['role_id'] = $params['role_id'][$op];
         } else {
             $params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
         }
     }
     $participantBAO = new CRM_Event_BAO_Participant();
     if (!empty($params['id'])) {
         $participantBAO->id = CRM_Utils_Array::value('id', $params);
         $participantBAO->find(TRUE);
         $participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
     }
     $participantBAO->copyValues($params);
     //CRM-6910
     //1. If currency present, it should be valid one.
     //2. We should have currency when amount is not null.
     $currency = $participantBAO->fee_currency;
     if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) {
         if (!CRM_Utils_Rule::currencyCode($currency)) {
             $config = CRM_Core_Config::singleton();
             $currency = $config->defaultCurrency;
         }
     }
     $participantBAO->fee_currency = $currency;
     $participantBAO->save();
     $session = CRM_Core_Session::singleton();
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
     } else {
         CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
     }
     return $participantBAO;
 }
开发者ID:nyimbi,项目名称:civicrm-core,代码行数:67,代码来源:Participant.php

示例2: civicrm_api3_pcpteams_create

/**
 * File for the CiviCRM APIv3 group functions
 *
 * @package CiviCRM_APIv3
 * @subpackage API_pcpteams
 * @copyright CiviCRM LLC (c) 2004-2014
 */
function civicrm_api3_pcpteams_create($params)
{
    // since we are allowing html input from the user
    // we also need to purify it, so lets clean it up
    // $params['pcp_title']      = $pcp['title'];
    // $params['pcp_contact_id'] = $pcp['contact_id'];
    $htmlFields = array('intro_text', 'page_text', 'title');
    foreach ($htmlFields as $field) {
        if (!empty($params[$field])) {
            $params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
        }
    }
    $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
    $pcpBlock = new CRM_PCP_DAO_PCPBlock();
    $pcpBlock->entity_table = $entity_table;
    $pcpBlock->entity_id = $params['page_id'];
    $pcpBlock->find(TRUE);
    $params['pcp_block_id'] = $pcpBlock->id;
    $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
    // 1 -> waiting review
    // 2 -> active / approved (default for now)
    $params['status_id'] = CRM_Utils_Array::value('status_id', $params, 2);
    // active by default for now
    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
    $pcp = CRM_Pcpteams_BAO_PCP::create($params, FALSE);
    //Custom Set
    $customFields = CRM_Core_BAO_CustomField::getFields('PCP', FALSE, FALSE, NULL, NULL, TRUE);
    $isCustomValueSet = FALSE;
    foreach ($customFields as $fieldID => $fieldValue) {
        list($tableName, $columnName, $cgId) = CRM_Core_BAO_CustomField::getTableColumnGroup($fieldID);
        if (!empty($params[$columnName]) || !empty($params["custom_{$fieldID}"])) {
            $isCustomValueSet = TRUE;
            //FIXME: to find out the custom value exists, set -1 as default now
            $params["custom_{$fieldID}_-1"] = !empty($params[$columnName]) ? $params[$columnName] : $params["custom_{$fieldID}"];
        }
    }
    if ($isCustomValueSet) {
        $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $pcp->id, 'PCP');
        CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_pcp', $pcp->id);
    }
    //end custom set
    $values = array();
    @_civicrm_api3_object_to_array_unique_fields($pcp, $values[$pcp->id]);
    return civicrm_api3_create_success($values, $params, 'Pcpteams', 'create');
}
开发者ID:eruraindil,项目名称:uk.co.vedaconsulting.pcpteams,代码行数:52,代码来源:Pcpteams.php

示例3:

 /**
  * takes an associative array and creates a participant object
  *
  * the function extract all the params it needs to initialize the create a
  * participant object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Event_BAO_Participant object
  * @access public
  * @static
  */
 static function &add(&$params)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Participant', null, $params);
     }
     // converting dates to mysql format
     if (CRM_Utils_Array::value('register_date', $params)) {
         $params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
     }
     if (CRM_Utils_Array::value('participant_fee_amount', $params)) {
         $params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
     }
     $participantBAO = new CRM_Event_BAO_Participant();
     if (CRM_Utils_Array::value('id', $params)) {
         $participantBAO->id = CRM_Utils_Array::value('id', $params);
         $participantBAO->find(true);
         $participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
     }
     $participantBAO->copyValues($params);
     //make sure we have currency when amount is not null CRM-4453
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_System::isNull($participantBAO->fee_amount) && !CRM_Utils_Rule::currencyCode($participantBAO->fee_currency)) {
         require_once 'CRM/Core/Config.php';
         $config =& CRM_Core_Config::singleton();
         $participantBAO->fee_currency = $config->defaultCurrency;
     }
     $participantBAO->save();
     $session =& CRM_Core_Session::singleton();
     // reset the group contact cache for this group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
     } else {
         CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
     }
     return $participantBAO;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:55,代码来源:Participant.php

示例4: postProcess

 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
     foreach ($checkBoxes as $key) {
         if (!isset($params[$key])) {
             $params[$key] = 0;
         }
     }
     $session = CRM_Core_Session::singleton();
     $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
     if (!$contactID) {
         $contactID = $this->get('contactID');
     }
     $params['title'] = $params['pcp_title'];
     $params['intro_text'] = $params['pcp_intro_text'];
     $params['contact_id'] = $contactID;
     $params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId;
     $params['page_type'] = $this->_component;
     // since we are allowing html input from the user
     // we also need to purify it, so lets clean it up
     $htmlFields = array('intro_text', 'page_text', 'title');
     foreach ($htmlFields as $field) {
         if (!empty($params[$field])) {
             $params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
         }
     }
     $entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
     $pcpBlock = new CRM_PCP_DAO_PCPBlock();
     $pcpBlock->entity_table = $entity_table;
     $pcpBlock->entity_id = $params['page_id'];
     $pcpBlock->find(TRUE);
     $params['pcp_block_id'] = $pcpBlock->id;
     $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
     $approval_needed = $pcpBlock->is_approval_needed;
     $approvalMessage = NULL;
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $params['status_id'] = $approval_needed ? 1 : 2;
         $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
     }
     $params['id'] = $this->_pageId;
     $pcp = CRM_PCP_BAO_PCP::add($params, FALSE);
     //create page in wordpress
     create_wp_campaign($pcp->title, $pcp->contact_id, $pcp->id);
     CRM_Core_Error::debug_log_message("Calling create_wp_campaign.... Params title: {$pcp->title}, contact_id: {$pcp->contact_id}, pcp_id: {$pcp->id} ");
     // add attachments as needed
     CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id);
     $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
     $statusId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id, 'status_id');
     //send notification of PCP create/update.
     $pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id);
     $notifyParams = array();
     $notifyStatus = "";
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
     if ($emails = $pcpBlock->notify_email) {
         $this->assign('pcpTitle', $pcp->title);
         if ($this->_pageId) {
             $this->assign('mode', 'Update');
         } else {
             $this->assign('mode', 'Add');
         }
         $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId);
         $this->assign('pcpStatus', $pcpStatus);
         $this->assign('pcpId', $pcp->id);
         $supporterUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$pcp->contact_id}", TRUE, NULL, FALSE, FALSE);
         $this->assign('supporterUrl', $supporterUrl);
         $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
         $this->assign('supporterName', $supporterName);
         if ($this->_component == 'contribute') {
             $pageUrl = CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title');
         } elseif ($this->_component == 'event') {
             $pageUrl = CRM_Utils_System::url('civicrm/event', "reset=1&id={$pcpBlock->entity_id}", TRUE, NULL, FALSE, TRUE);
             $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title');
         }
         $this->assign('contribPageUrl', $pageUrl);
         $this->assign('contribPageTitle', $contribPageTitle);
         $managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp', "reset=1", TRUE, NULL, FALSE, FALSE);
         $this->assign('managePCPUrl', $managePCPUrl);
         //get the default domain email address.
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
             $fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
         }
         //if more than one email present for PCP notification ,
         //first email take it as To and other as CC and First email
         //address should be sent in users email receipt for
         //support purpose.
         $emailArray = explode(',', $emails);
         $to = $emailArray[0];
         unset($emailArray[0]);
         $cc = implode(',', $emailArray);
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc));
//.........这里部分代码省略.........
开发者ID:aydun,项目名称:uk.co.vedaconsulting.quickdonate,代码行数:101,代码来源:Campaign.php

示例5: postProcess

 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if (array_key_exists('payment_processor', $params)) {
         if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type'), 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).'));
         }
     }
     // 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_recur_interval' => 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 (!CRM_Utils_Array::value('is_recur', $params)) {
         $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);
     }
     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 (CRM_Utils_Array::value('amount_block_is_active', $params)) {
             // handle price set.
             if ($priceSetID) {
                 // add/update price set.
                 $deletePriceSet = FALSE;
                 if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) {
                     $deleteAmountBlk = TRUE;
                 }
                 CRM_Price_BAO_Set::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);
                     }
                 }
                 /* || CRM_Utils_Array::value( 'price_field_value', $params )|| CRM_Utils_Array::value( 'price_field_other', $params )*/
                 if (!empty($options) || CRM_Utils_Array::value('is_allow_other_amount', $params)) {
                     $fieldParams['is_quick_config'] = 1;
                     $noContriAmount = NULL;
                     $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3);
                     if (!(CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) && !$usedPriceSetId) {
                         $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                         $setParams['title'] = $this->_values['title'];
                         if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) {
                             $setParams['name'] = $pageTitle;
                         } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $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('CiviContribute');
                         $priceSet = CRM_Price_BAO_Set::create($setParams);
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Amount.php

示例6: updateCustomValues

 static function updateCustomValues($params)
 {
     $optionDAO = new CRM_Core_DAO_OptionValue();
     $optionDAO->id = $params['optionId'];
     $optionDAO->find(TRUE);
     $oldValue = $optionDAO->value;
     // get the table, column, html_type and data type for this field
     $query = "\nSELECT g.table_name  as tableName ,\n       f.column_name as columnName,\n       f.data_type   as dataType,\n       f.html_type   as htmlType\nFROM   civicrm_custom_group g,\n       civicrm_custom_field f\nWHERE  f.custom_group_id = g.id\n  AND  f.id = %1";
     $queryParams = array(1 => array($params['fieldId'], 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
     if ($dao->fetch()) {
         if ($dao->dataType == 'Money') {
             $params['value'] = CRM_Utils_Rule::cleanMoney($params['value']);
         }
         switch ($dao->htmlType) {
             case 'Autocomplete-Select':
             case 'Select':
             case 'Radio':
                 $query = "\nUPDATE {$dao->tableName}\nSET    {$dao->columnName} = %1\nWHERE  id = %2";
                 if ($dao->dataType == 'Auto-complete') {
                     $dataType = "String";
                 } else {
                     $dataType = $dao->dataType;
                 }
                 $queryParams = array(1 => array($params['value'], $dataType), 2 => array($params['optionId'], 'Integer'));
                 break;
             case 'AdvMulti-Select':
             case 'Multi-Select':
             case 'CheckBox':
                 $oldString = CRM_Core_DAO::VALUE_SEPARATOR . $oldValue . CRM_Core_DAO::VALUE_SEPARATOR;
                 $newString = CRM_Core_DAO::VALUE_SEPARATOR . $params['value'] . CRM_Core_DAO::VALUE_SEPARATOR;
                 $query = "\nUPDATE {$dao->tableName}\nSET    {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )";
                 $queryParams = array(1 => array($oldString, 'String'), 2 => array($newString, 'String'));
                 break;
             default:
                 CRM_Core_Error::fatal();
         }
         $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
     }
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:40,代码来源:CustomOption.php

示例7: postProcess

 /**
  * 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);
//.........这里部分代码省略.........
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:Fee.php

示例8: postProcess

 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Price_DAO_PriceFieldValue', $this->_oid, $fieldValues);
         $label = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'label', 'id');
         if (CRM_Price_BAO_PriceFieldValue::del($this->_oid)) {
             CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label)), ts('Record Deleted'), 'success');
         }
         return NULL;
     } else {
         $params = $ids = array();
         $params = $this->controller->exportValues('Option');
         $fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'label');
         $params['amount'] = CRM_Utils_Rule::cleanMoney(trim($params['amount']));
         $params['price_field_id'] = $this->_fid;
         $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
         $ids = array();
         if ($this->_oid) {
             $ids['id'] = $this->_oid;
         }
         $optionValue = CRM_Price_BAO_PriceFieldValue::create($params, $ids);
         CRM_Core_Session::setStatus(ts("The option '%1' has been saved.", array(1 => $params['label'])), ts('Value Saved'), 'success');
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:31,代码来源:Option.php

示例9: add

 /**
  * takes an associative array and creates a contribution object
  *
  * the function extract all the params it needs to initialize the create a
  * contribution object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Contribute_BAO_Contribution object
  * @access public
  * @static
  */
 static function add(&$params, &$ids)
 {
     if (empty($params)) {
         return;
     }
     $duplicates = array();
     if (self::checkDuplicate($params, $duplicates, CRM_Utils_Array::value('contribution', $ids))) {
         $error =& CRM_Core_Error::singleton();
         $d = implode(', ', $duplicates);
         $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}");
         return $error;
     }
     // first clean up all the money fields
     $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount');
     //if priceset is used, no need to cleanup money
     if (CRM_UTils_Array::value('skipCleanMoney', $params)) {
         unset($moneyFields[0]);
     }
     foreach ($moneyFields as $field) {
         if (isset($params[$field])) {
             $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
         }
     }
     if (CRM_Utils_Array::value('payment_instrument_id', $params)) {
         require_once 'CRM/Contribute/PseudoConstant.php';
         $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name');
         if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) {
             $params['check_number'] = 'null';
         }
     }
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('contribution', $ids)) {
         CRM_Utils_Hook::pre('edit', 'Contribution', $ids['contribution'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Contribution', null, $params);
     }
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->copyValues($params);
     $contribution->id = CRM_Utils_Array::value('contribution', $ids);
     // also add financial_trxn details as part of fix for CRM-4724
     $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params);
     $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params);
     require_once 'CRM/Utils/Rule.php';
     if (!CRM_Utils_Rule::currencyCode($contribution->currency)) {
         require_once 'CRM/Core/Config.php';
         $config = CRM_Core_Config::singleton();
         $contribution->currency = $config->defaultCurrency;
     }
     $result = $contribution->save();
     // reset the group contact cache for this group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     if (CRM_Utils_Array::value('contribution', $ids)) {
         CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution);
     } else {
         CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution);
     }
     return $result;
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:73,代码来源:Contribution.php

示例10: postProcess

 /**
  * The post processing of the form gets done here.
  *
  * Key things done during post processing are
  *      - check for reset or next request. if present, skip post processing.
  *      - now check if user requested running a saved search, if so, then
  *        the form values associated with the saved search are used for searching.
  *      - if user has done a submit with new values the regular post submission is
  *        done.
  * The processing consists of using a Selector / Controller framework for getting the
  * search results.
  */
 public function postProcess()
 {
     if ($this->_done) {
         return;
     }
     $this->_done = TRUE;
     if (!empty($_POST)) {
         $this->_formValues = $this->controller->exportValues($this->_name);
     }
     $this->fixFormValues();
     // We don't show test records in summaries or dashboards
     if (empty($this->_formValues['contribution_test']) && $this->_force && !empty($this->_context) && $this->_context == 'dashboard') {
         $this->_formValues["contribution_test"] = 0;
     }
     foreach (array('contribution_amount_low', 'contribution_amount_high') as $f) {
         if (isset($this->_formValues[$f])) {
             $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
         }
     }
     $config = CRM_Core_Config::singleton();
     if (!empty($_POST)) {
         $specialParams = array('financial_type_id', 'contribution_soft_credit_type_id', 'contribution_status_id', 'contribution_source', 'contribution_trxn_id', 'contribution_page_id', 'contribution_product_id');
         foreach ($specialParams as $element) {
             $value = CRM_Utils_Array::value($element, $this->_formValues);
             if ($value) {
                 if (is_array($value)) {
                     $this->_formValues[$element] = array('IN' => $value);
                 } else {
                     $this->_formValues[$element] = array('LIKE' => "%{$value}%");
                 }
             }
         }
         $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues);
         if ($tags && !is_array($tags)) {
             unset($this->_formValues['contact_tags']);
             $this->_formValues['contact_tags'][$tags] = 1;
         }
         if ($tags && is_array($tags)) {
             unset($this->_formValues['contact_tags']);
             foreach ($tags as $notImportant => $tagID) {
                 $this->_formValues['contact_tags'][$tagID] = 1;
             }
         }
         if (!$config->groupTree) {
             $group = CRM_Utils_Array::value('group', $this->_formValues);
             if ($group && !is_array($group)) {
                 unset($this->_formValues['group']);
                 $this->_formValues['group'][$group] = 1;
             }
             if ($group && is_array($group)) {
                 unset($this->_formValues['group']);
                 foreach ($group as $notImportant => $groupID) {
                     $this->_formValues['group'][$groupID] = 1;
                 }
             }
         }
     }
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $this->set('formValues', $this->_formValues);
     $this->set('queryParams', $this->_queryParams);
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_actionButtonName) {
         // check actionName and if next, then do not repeat a search, since we are going to the next page
         // hack, make sure we reset the task values
         $stateMachine = $this->controller->getStateMachine();
         $formName = $stateMachine->getTaskFormName();
         $this->controller->resetPage($formName);
         return;
     }
     $sortID = NULL;
     if ($this->get(CRM_Utils_Sort::SORT_ID)) {
         $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
     }
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
     $selector = new CRM_Contribute_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context);
     $selector->setKey($this->controller->_key);
     $prefix = NULL;
     if ($this->_context == 'basic' || $this->_context == 'user') {
         $prefix = $this->_prefix;
     }
     $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix);
     $controller->setEmbedded(TRUE);
     $query =& $selector->getQuery();
     if ($this->_context == 'user') {
         $query->setSkipPermission(TRUE);
     }
     $summary =& $query->summaryContribution($this->_context);
//.........这里部分代码省略.........
开发者ID:vakeesan26,项目名称:civicrm-core,代码行数:101,代码来源:Search.php

示例11: submit


//.........这里部分代码省略.........
             foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
                 if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
                     $fieldId = $fieldVal['id'];
                     $fieldOption = $params['price_' . $fieldId];
                     $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                     $memPresent = TRUE;
                 } else {
                     if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
                         $fieldId = $fieldVal['id'];
                         if ($fieldVal['name'] == 'other_amount') {
                             $proceFieldAmount += $this->_submitValues['price_' . $fieldId];
                         } elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
                             $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
                         }
                         unset($params['price_' . $fieldId]);
                         break;
                     }
                 }
             }
         }
     }
     if (!isset($params['amount_other'])) {
         $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
     }
     if (!empty($this->_ccid)) {
         $this->set('lineItem', $this->_lineItem);
     } elseif ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
         $lineItem = array();
         $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($is_quick_config) {
             foreach ($this->_values['fee'] as $key => &$val) {
                 if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && !empty($params['price_' . $key])) {
                     // Clean out any currency symbols.
                     $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]);
                     if ($params['price_' . $key] != 0) {
                         foreach ($val['options'] as $optionKey => &$options) {
                             $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
                             break;
                         }
                     }
                     $params['price_' . $key] = 1;
                     break;
                 }
             }
         }
         $component = '';
         if ($this->_membershipBlock) {
             $component = 'membership';
         }
         CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[$priceSetId], $component);
         if ($params['tax_amount']) {
             $this->set('tax_amount', $params['tax_amount']);
         }
         if ($proceFieldAmount) {
             $lineItem[$params['priceSetId']][$fieldOption]['unit_price'] = $proceFieldAmount;
             $lineItem[$params['priceSetId']][$fieldOption]['line_total'] = $proceFieldAmount;
             if (isset($lineItem[$params['priceSetId']][$fieldOption]['tax_amount'])) {
                 $proceFieldAmount += $lineItem[$params['priceSetId']][$fieldOption]['tax_amount'];
             }
             if (!$this->_membershipBlock['is_separate_payment']) {
                 //require when separate membership not used
                 $params['amount'] = $proceFieldAmount;
             }
         }
         $this->set('lineItem', $lineItem);
     }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:67,代码来源:Main.php

示例12: calculateTaxAmount

 /**
  * Calculate the tax amount based on given tax rate.
  *
  * @param float $amount
  *   Amount of field.
  * @param float $taxRate
  *   Tax rate of selected financial account for field.
  *
  * @return array
  *   array of tax amount
  *
  */
 public static function calculateTaxAmount($amount, $taxRate)
 {
     $taxAmount = array();
     $taxAmount['tax_amount'] = $taxRate / 100 * CRM_Utils_Rule::cleanMoney($amount);
     return $taxAmount;
 }
开发者ID:utkarshsharma,项目名称:civicrm-core,代码行数:18,代码来源:Utils.php

示例13: postProcess

 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         try {
             CRM_Member_BAO_MembershipType::del($this->_id);
         } catch (CRM_Core_Exception $e) {
             CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Membership Type Not Deleted'));
         }
         CRM_Core_Session::setStatus(ts('Selected membership type has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $buttonName = $this->controller->getButtonName();
         $submitted = $this->controller->exportValues($this->_name);
         $fields = array('name', 'weight', 'is_active', 'member_of_contact_id', 'visibility', 'period_type', 'minimum_fee', 'description', 'auto_renew', 'duration_unit', 'duration_interval', 'financial_type_id', 'fixed_period_start_day', 'fixed_period_rollover_day', 'month_fixed_period_rollover_day', 'max_related');
         $params = $ids = array();
         foreach ($fields as $fld) {
             $params[$fld] = CRM_Utils_Array::value($fld, $submitted, 'NULL');
         }
         //clean money.
         if ($params['minimum_fee']) {
             $params['minimum_fee'] = CRM_Utils_Rule::cleanMoney($params['minimum_fee']);
         }
         $hasRelTypeVal = FALSE;
         if (!CRM_Utils_System::isNull($submitted['relationship_type_id'])) {
             // To insert relation ids and directions with value separator
             $relTypeDirs = $submitted['relationship_type_id'];
             $relIds = $relDirection = array();
             foreach ($relTypeDirs as $key => $value) {
                 $relationId = explode('_', $value);
                 if (count($relationId) == 3 && is_numeric($relationId[0])) {
                     $relIds[] = $relationId[0];
                     $relDirection[] = $relationId[1] . '_' . $relationId[2];
                 }
             }
             if (!empty($relIds)) {
                 $hasRelTypeVal = TRUE;
                 $params['relationship_type_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relIds);
                 $params['relationship_direction'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $relDirection);
             }
         }
         if (!$hasRelTypeVal) {
             $params['relationship_type_id'] = $params['relationship_direction'] = $params['max_related'] = 'NULL';
         }
         if ($params['duration_unit'] == 'lifetime' && empty($params['duration_interval'])) {
             $params['duration_interval'] = 1;
         }
         $periods = array('fixed_period_start_day', 'fixed_period_rollover_day');
         foreach ($periods as $per) {
             if (!empty($params[$per]['M']) && !empty($params[$per]['d'])) {
                 $mon = $params[$per]['M'];
                 $dat = $params[$per]['d'];
                 $mon = $mon < 10 ? '0' . $mon : $mon;
                 $dat = $dat < 10 ? '0' . $dat : $dat;
                 $params[$per] = $mon . $dat;
             } elseif ($per == 'fixed_period_rollover_day' && !empty($params['month_fixed_period_rollover_day'])) {
                 $params['fixed_period_rollover_day'] = $params['month_fixed_period_rollover_day']['d'];
                 unset($params['month_fixed_period_rollover_day']);
             } else {
                 $params[$per] = 'NULL';
             }
         }
         $oldWeight = NULL;
         if ($this->_id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_id, 'weight', 'id');
         }
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipType', $oldWeight, $params['weight']);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['membershipType'] = $this->_id;
         }
         $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The membership type \'%1\' has been saved.', array(1 => $membershipType->name)), ts('Saved'), 'success');
         $session = CRM_Core_Session::singleton();
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/member/membershipType/add', 'action=add&reset=1'));
         }
     }
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:82,代码来源:MembershipType.php

示例14: postProcess

 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     $sendReceipt = $pId = $contribution = $isRelatedId = FALSE;
     $softParams = $softIDs = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contribute_BAO_Contribution::deleteContribution($this->_id);
         CRM_Core_Session::singleton()->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=contribute"));
         return;
     }
     // Get the submitted form values.
     $submittedValues = $this->controller->exportValues($this->_name);
     if (!empty($submittedValues['price_set_id']) && $this->_action & CRM_Core_Action::UPDATE) {
         $line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution');
         $lineID = key($line);
         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $line[$lineID]), 'price_set_id');
         $quickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($quickConfig) {
             CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_contribution');
         }
     }
     // Process price set and get total amount and line items.
     $lineItem = array();
     $priceSetId = CRM_Utils_Array::value('price_set_id', $submittedValues);
     if (empty($priceSetId) && !$this->_id) {
         $this->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
         $this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
         $fieldID = key($this->_priceSet['fields']);
         $fieldValueId = key($this->_priceSet['fields'][$fieldID]['options']);
         $this->_priceSet['fields'][$fieldID]['options'][$fieldValueId]['amount'] = $submittedValues['total_amount'];
         $submittedValues['price_' . $fieldID] = 1;
     }
     if ($priceSetId) {
         CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $submittedValues, $lineItem[$priceSetId]);
         // Unset tax amount for offline 'is_quick_config' contribution.
         if ($this->_priceSet['is_quick_config'] && !array_key_exists($submittedValues['financial_type_id'], CRM_Core_PseudoConstant::getTaxRates())) {
             unset($submittedValues['tax_amount']);
         }
         $submittedValues['total_amount'] = CRM_Utils_Array::value('amount', $submittedValues);
     }
     if ($this->_id) {
         if ($this->_compId) {
             if ($this->_context == 'participant') {
                 $pId = $this->_compId;
             } elseif ($this->_context == 'membership') {
                 $isRelatedId = TRUE;
             } else {
                 $pId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'participant_id', 'contribution_id');
             }
         } else {
             $contributionDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (array_key_exists('membership', $contributionDetails)) {
                 $isRelatedId = TRUE;
             } elseif (array_key_exists('participant', $contributionDetails)) {
                 $pId = $contributionDetails['participant'];
             }
         }
     }
     if (!$priceSetId && !empty($submittedValues['total_amount']) && $this->_id) {
         // CRM-10117 update the line items for participants.
         if ($pId) {
             $entityTable = 'participant';
             $entityID = $pId;
             $isRelatedId = FALSE;
             $participantParams = array('fee_amount' => $submittedValues['total_amount'], 'id' => $entityID);
             CRM_Event_BAO_Participant::add($participantParams);
             if (empty($this->_lineItems)) {
                 $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($entityID, 'participant', 1);
             }
         } else {
             $entityTable = 'contribution';
             $entityID = $this->_id;
         }
         $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, $entityTable, NULL, TRUE, $isRelatedId);
         foreach (array_keys($lineItems) as $id) {
             $lineItems[$id]['id'] = $id;
         }
         $itemId = key($lineItems);
         if ($itemId && !empty($lineItems[$itemId]['price_field_id'])) {
             $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id');
         }
         if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
             $lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('total_amount', $submittedValues));
             // Update line total and total amount with tax on edit.
             $financialItemsId = CRM_Core_PseudoConstant::getTaxRates();
             if (array_key_exists($submittedValues['financial_type_id'], $financialItemsId)) {
                 $lineItems[$itemId]['tax_rate'] = $financialItemsId[$submittedValues['financial_type_id']];
             } else {
                 $lineItems[$itemId]['tax_rate'] = $lineItems[$itemId]['tax_amount'] = "";
                 $submittedValues['tax_amount'] = 'null';
             }
             if ($lineItems[$itemId]['tax_rate']) {
                 $lineItems[$itemId]['tax_amount'] = $lineItems[$itemId]['tax_rate'] / 100 * $lineItems[$itemId]['line_total'];
                 $submittedValues['total_amount'] = $lineItems[$itemId]['line_total'] + $lineItems[$itemId]['tax_amount'];
                 $submittedValues['tax_amount'] = $lineItems[$itemId]['tax_amount'];
             }
         }
         // CRM-10117 update the line items for participants.
//.........这里部分代码省略.........
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contribution.php

示例15: _cividiscount_calc_discount

/**
 * Calculate either a monetary or percentage discount.
 */
function _cividiscount_calc_discount($amount, $label, $discount, $autodiscount, $currency = 'USD')
{
    $title = $autodiscount ? 'Member Discount' : "Discount {$discount['code']}";
    if ($discount['amount_type'] == '2') {
        $newamount = CRM_Utils_Rule::cleanMoney($amount) - CRM_Utils_Rule::cleanMoney($discount['amount']);
        $fmt_discount = CRM_Utils_Money::format($discount['amount'], $currency);
        $newlabel = $label . " ({$title}: {$fmt_discount} {$discount['description']})";
    } else {
        $newamount = $amount - $amount * ($discount['amount'] / 100);
        $newlabel = $label . " ({$title}: {$discount['amount']}% {$discount['description']})";
    }
    $newamount = round($newamount, 2);
    // Return a formatted string for zero amount.
    // @see http://issues.civicrm.org/jira/browse/CRM-12278
    if ($newamount <= 0) {
        $newamount = '0.00';
    }
    return array($newamount, $newlabel);
}
开发者ID:krishgopi,项目名称:org.civicrm.module.cividiscount,代码行数:22,代码来源:cividiscount.php


注:本文中的CRM_Utils_Rule::cleanMoney方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。