示例#1
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     require_once 'CRM/Utils/Money.php';
     $this->_first = true;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], true);
     $this->add('select', 'contribution_type_id', ts('Contribution Type'), CRM_Contribute_PseudoConstant::contributionType(), true);
     $this->addWysiwyg('intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->addWysiwyg('footer_text', ts('Footer Message'), $attributes['footer_text']);
     // is on behalf of an organization ?
     $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), null, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
     $options = array();
     $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Optional'), 1);
     $options[] = HTML_QuickForm::createElement('radio', null, null, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', ts(''));
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']);
     // collect goal amount
     $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
     $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // is this page active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
     // should the honor be enabled
     $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), null, array('onclick' => "showHonor()"));
     $this->add('text', 'honor_block_title', ts('Honoree Section Title'), $attributes['honor_block_title']);
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), $attributes['honor_block_text']);
     // add optional start and end dates
     $this->addDateTime('start_date', ts('Start Date'));
     $this->addDateTime('end_date', ts('End Date'));
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'));
     parent::buildQuickForm();
 }
 function setDefaultValues()
 {
     $dafaults = array();
     $dao = new CRM_PCP_DAO_PCP();
     if ($this->_pageId) {
         $dao->id = $this->_pageId;
         if ($dao->find(TRUE)) {
             CRM_Core_DAO::storeValues($dao, $defaults);
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['goal_amount'])) {
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
         }
         $defaults['pcp_title'] = CRM_Utils_Array::value('title', $defaults);
         $defaults['pcp_intro_text'] = CRM_Utils_Array::value('intro_text', $defaults);
     }
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
         $defaults['is_honor_roll'] = 1;
         $defaults['is_thermometer'] = 1;
     }
     $this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
     $this->_contriPageId = CRM_Utils_Array::value('page_id', $defaults);
     //MV: to set customData default values;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $customDataDefaults = CRM_Custom_Form_CustomData::setDefaultValues($this);
         $defaults += $customDataDefaults;
     }
     //END
     return $defaults;
 }
示例#3
0
文件: AJAX.php 项目: hguru/224Civi
 /**
  * Function to setDefaults according to membership type
  */
 function getMemberTypeDefaults($config)
 {
     if (!$_POST['mtype']) {
         $details['name'] = '';
         $details['auto_renew'] = '';
         $details['total_amount'] = '';
         echo json_encode($details);
         CRM_Utils_System::civiExit();
     }
     $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
     $query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew\nFROM    civicrm_membership_type\nWHERE   id = %1";
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($memType, 'Positive')));
     $properties = array('financial_type_id', 'total_amount', 'name', 'auto_renew');
     while ($dao->fetch()) {
         foreach ($properties as $property) {
             $details[$property] = $dao->{$property};
         }
     }
     $details['total_amount_numeric'] = $details['total_amount'];
     // fix the display of the monetary value, CRM-4038
     $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
     $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required '));
     $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
     echo json_encode($details);
     CRM_Utils_System::civiExit();
 }
 public function run()
 {
     CRM_Utils_System::setTitle(ts('PersonalCampaigns'));
     $contactID = $id = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
     $query = "\n\t\t\t\tSELECT id,title, is_active,page_type,goal_amount,pcp_block_id\n\t\t\t\tFROM civicrm_pcp pcp\n\t\t\t\tWHERE pcp.contact_id = %1\n\t\t\t\tORDER BY page_type, page_id";
     $params = array(1 => array($contactID, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $params);
     $results = array();
     while ($dao->fetch()) {
         $results[$dao->id]['title'] = $dao->title;
         $results[$dao->id]['is_active'] = $dao->is_active ? 'Active' : 'Inactive';
         $results[$dao->id]['page_type'] = $this->getContributionPageTitle($dao->id, $dao->page_type);
         $results[$dao->id]['goal_amount'] = CRM_Utils_Money::format($dao->goal_amount, $dao->currency);
         $contributionDetails = $this->getContributionDetails($dao->id);
         $results[$dao->id]['amout_raised'] = CRM_Utils_Money::format(0, $dao->currency);
         $results[$dao->id]['no_of_contributions'] = 0;
         if ($contributionDetails) {
             $results[$dao->id]['amout_raised'] = CRM_Utils_Money::format($contributionDetails[0], $dao->currency);
             $results[$dao->id]['no_of_contributions'] = $contributionDetails[1];
         }
         $results[$dao->id]['view_page_link'] = CRM_Utils_System::url('civicrm/pcp/info', 'reset=1&id=' . $dao->id . '&component=' . $dao->page_type);
         $results[$dao->id]['edit_page_link'] = CRM_Utils_System::url('civicrm/pcp/info', "action=update&reset=1&id={$dao->id}&context=dashboard");
     }
     $this->assign('campignResults', $results);
     parent::run();
 }
 public function setDefaultValues()
 {
     $defaults = array();
     $dao = new CRM_PCP_DAO_PCP();
     if ($this->_pageId) {
         $dao->id = $this->_pageId;
         if ($dao->find(TRUE)) {
             CRM_Core_DAO::storeValues($dao, $defaults);
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['goal_amount'])) {
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
         }
         $defaults['pcp_title'] = CRM_Utils_Array::value('title', $defaults);
         $defaults['pcp_intro_text'] = CRM_Utils_Array::value('intro_text', $defaults);
     }
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
         $defaults['is_honor_roll'] = 1;
         $defaults['is_thermometer'] = 1;
         $defaults['is_notify'] = 1;
     }
     $this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
     $this->_contriPageId = CRM_Utils_Array::value('page_id', $defaults);
     return $defaults;
 }
示例#6
0
文件: Money.php 项目: bhirsch/voipdev
 /**
  * format a monetary string
  *
  * Format a monetary string basing on the amount provided,
  * ISO currency code provided and a format string consisting of:
  *
  * %a - the formatted amount
  * %C - the currency ISO code (e.g., 'USD') if provided
  * %c - the currency symbol (e.g., '$') if available
  *
  * @param float  $amount    the monetary amount to display (1234.56)
  * @param string $currency  the three-letter ISO currency code ('USD')
  * @param string $format    the desired currency format
  *
  * @return string  formatted monetary string
  *
  * @static
  */
 static function format($amount, $currency = null, $format = null)
 {
     if (CRM_Utils_System::isNull($amount)) {
         return '';
     }
     $config =& CRM_Core_Config::singleton();
     if (!self::$_currencySymbols) {
         require_once "CRM/Core/PseudoConstant.php";
         $currencySymbolName = CRM_Core_PseudoConstant::currencySymbols('name');
         $currencySymbol = CRM_Core_PseudoConstant::currencySymbols();
         self::$_currencySymbols = array_combine($currencySymbolName, $currencySymbol);
     }
     if (!$currency) {
         $currency = $config->defaultCurrency;
     }
     if (!$format) {
         $format = $config->moneyformat;
     }
     // money_format() exists only in certain PHP install (CRM-650)
     if (is_numeric($amount) and function_exists('money_format')) {
         $amount = money_format($config->moneyvalueformat, $amount);
     }
     $replacements = array('%a' => $amount, '%C' => $currency, '%c' => CRM_Utils_Array::value($currency, self::$_currencySymbols, $currency));
     return strtr($format, $replacements);
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 /**
  * Test retrieve Soft Contribution through AJAX
  */
 public function testGetSoftContributionSelector()
 {
     $softTypes = array(3, 2, 5);
     $amounts = array('100', '600', '150');
     // create sample soft contribution for contact
     foreach ($this->_primaryContacts as $seq => $contactId) {
         $this->callAPISuccess('Contribution', 'create', array('contact_id' => $contactId, 'receive_date' => date('Ymd'), 'total_amount' => $amounts[$seq], 'financial_type_id' => 1, 'non_deductible_amount' => '10', 'contribution_status_id' => 1, 'soft_credit' => array('1' => array('contact_id' => $this->_softContactId, 'amount' => $amounts[$seq], 'soft_credit_type_id' => $softTypes[$seq]))));
     }
     $_GET = array_merge($this->_params, array('cid' => $this->_softContactId, 'context' => 'contribution'));
     $softCreditList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
     foreach ($this->_fields as $columnName) {
         $_GET['columns'][] = array('data' => $columnName);
     }
     // get the results in descending order
     $_GET['order'] = array('0' => array('column' => 0, 'dir' => 'desc'));
     $amountSortedList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
     $this->assertEquals(3, $softCreditList['recordsTotal']);
     $this->assertEquals(3, $amountSortedList['recordsTotal']);
     rsort($amounts);
     foreach ($amounts as $key => $amount) {
         $amount = CRM_Utils_Money::format($amount, 'USD');
         $this->assertEquals($amount, $amountSortedList['data'][$key]['amount']);
     }
     // sort with soft credit types
     $_GET['order'][0]['column'] = 1;
     foreach ($softTypes as $id) {
         $softLabels[] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $id);
     }
     rsort($softLabels);
     $softTypeSortedList = CRM_Contribute_Page_AJAX::getSoftContributionRows();
     foreach ($softLabels as $key => $labels) {
         $this->assertEquals($labels, $softTypeSortedList['data'][$key]['sct_label']);
     }
 }
示例#9
0
 /**
  * Get a list of templates demonstrating how to format currencies.
  */
 static function getCurrencyFormats()
 {
     $currencies = CRM_Core_PseudoConstant::get('CRM_HRJob_DAO_HRJobPay', 'pay_currency');
     $formats = array();
     foreach ($currencies as $currency => $label) {
         $formats[$currency] = CRM_Utils_Money::format(1234.56, $currency);
     }
     return $formats;
 }
示例#10
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao = new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (!empty($values['contribution_page_id'])) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['financial_type'] = CRM_Utils_Array::value($values['financial_type_id'], CRM_Contribute_PseudoConstant::financialType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['financial_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther);
     // Check if this is default domain contact CRM-10482
     if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
         $displayName .= ' (' . ts('default organization') . ')';
     }
     // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
     CRM_Utils_System::setTitle(ts('View Pledge by') . ' ' . $displayName);
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
示例#11
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     $values = array();
     $params['id'] = $this->_id;
     require_once 'CRM/Grant/BAO/Grant.php';
     CRM_Grant_BAO_Grant::retrieve($params, $values);
     require_once 'CRM/Grant/PseudoConstant.php';
     $grantType = CRM_Grant_PseudoConstant::grantType();
     $grantStatus = CRM_Grant_PseudoConstant::grantStatus();
     $this->assign('grantType', $grantType[$values['grant_type_id']]);
     $this->assign('grantStatus', $grantStatus[$values['status_id']]);
     $grantTokens = array('amount_total', 'amount_requested', 'amount_granted', 'rationale', 'grant_report_received', 'application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($grantTokens as $token) {
         $this->assign($token, CRM_Utils_Array::value($token, $values));
     }
     if (isset($this->_id)) {
         require_once 'CRM/Core/BAO/Note.php';
         $noteDAO = new CRM_Core_BAO_Note();
         $noteDAO->entity_table = 'civicrm_grant';
         $noteDAO->entity_id = $this->_id;
         if ($noteDAO->find(true)) {
             $this->_noteId = $noteDAO->id;
         }
     }
     if (isset($this->_noteId)) {
         $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
     }
     // add Grant to Recent Items
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Utils/Money.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], null, $recentOther);
     require_once 'CRM/Core/BAO/File.php';
     $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
     $this->assign('attachment', $attachment);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign('id', $this->_id);
 }
示例#12
0
 /**
  * Function to setDefaults according to membership type
  */
 function getMemberTypeDefaults($config)
 {
     require_once 'CRM/Utils/Type.php';
     $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
     $contributionType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType, 'contribution_type_id');
     $totalAmount = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType, 'minimum_fee');
     // fix the display of the monetary value, CRM-4038
     require_once 'CRM/Utils/Money.php';
     $totalAmount = CRM_Utils_Money::format($totalAmount, null, '%a');
     $details = array('contribution_type_id' => $contributionType, 'total_amount' => $totalAmount);
     echo json_encode($details);
     CRM_Utils_System::civiExit();
 }
 private function renderPayments()
 {
     $from = $this->get('range_from');
     $to = $this->get('range_to');
     if (!empty($from) && !empty($to)) {
         $bao = $this->controller->getImportBAO();
         $paymentsApi = $bao->fetchAllPayments($from, $to);
         $pays = array();
         require_once 'CRM/Utils/Money.php';
         foreach ($paymentsApi as $item) {
             $pays[] = array('id' => $item->PaymentRef, 'date' => $item->PaymentDate, 'net' => CRM_Utils_Money::format($item->Net));
         }
         $this->assign('payments', $pays);
     }
 }
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @param null
  *
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_FieldValue::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         $defaults['value'] = CRM_Utils_Money::format(CRM_Utils_Array::value('value', $defaults), NULL, '%a');
     }
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_FieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
 /**
  * format a monetary string
  *
  * Format a monetary string basing on the amount provided,
  * ISO currency code provided and a format string consisting of:
  *
  * %a - the formatted amount
  * %C - the currency ISO code (e.g., 'USD') if provided
  * %c - the currency symbol (e.g., '$') if available
  *
  * @param float  $amount    the monetary amount to display (1234.56)
  * @param string $currency  the three-letter ISO currency code ('USD')
  * @param string $format    the desired currency format
  *
  * @return string  formatted monetary string
  *
  * @static
  */
 static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE)
 {
     if (CRM_Utils_System::isNull($amount)) {
         return '';
     }
     $config = CRM_Core_Config::singleton();
     if (!$format) {
         $format = $config->moneyformat;
     }
     if ($onlyNumber) {
         // money_format() exists only in certain PHP install (CRM-650)
         if (is_numeric($amount) and function_exists('money_format')) {
             $amount = money_format($config->moneyvalueformat, $amount);
         }
         return $amount;
     }
     if (!self::$_currencySymbols) {
         $currencySymbolName = CRM_Core_PseudoConstant::currencySymbols('name');
         $currencySymbol = CRM_Core_PseudoConstant::currencySymbols();
         self::$_currencySymbols = array_combine($currencySymbolName, $currencySymbol);
     }
     if (!$currency) {
         $currency = $config->defaultCurrency;
     }
     if (!$format) {
         $format = $config->moneyformat;
     }
     // money_format() exists only in certain PHP install (CRM-650)
     // setlocale() affects native gettext (CRM-11054, CRM-9976)
     if (is_numeric($amount) && function_exists('money_format')) {
         $lc = setlocale(LC_MONETARY, 0);
         setlocale(LC_MONETARY, 'en_US.utf8', 'en_US', 'en_US.utf8', 'en_US', 'C');
         $amount = money_format($config->moneyvalueformat, $amount);
         setlocale(LC_MONETARY, $lc);
     }
     $rep = array(',' => $config->monetaryThousandSeparator, '.' => $config->monetaryDecimalPoint);
     // If it contains tags, means that HTML was passed and the
     // amount is already converted properly,
     // so don't mess with it again.
     if (strip_tags($amount) === $amount) {
         $money = strtr($amount, $rep);
     } else {
         $money = $amount;
     }
     $replacements = array('%a' => $money, '%C' => $currency, '%c' => CRM_Utils_Array::value($currency, self::$_currencySymbols, $currency));
     return strtr($format, $replacements);
 }
 function run()
 {
     if (isset($_REQUEST['group_id'])) {
         // get some values
         $group_id = (int) $_REQUEST['group_id'];
         $financial_types = CRM_Contribute_PseudoConstant::financialType();
         // load the group
         $txgroup = civicrm_api('SepaTransactionGroup', 'getsingle', array('id' => $group_id, 'version' => 3));
         if (isset($txgroup['is_error']) && $txgroup['is_error']) {
             CRM_Core_Session::setStatus(sprintf(ts("Cannot read SEPA transaction group [%s]. Error was: '%s'"), $group_id, $txgroup['error_message']), ts("Error"), "error");
         }
         // load the group's contributions
         $sql = "\n      SELECT\n        civicrm_sdd_txgroup.reference           AS reference,\n        civicrm_contact.display_name            AS contact_display_name,\n        civicrm_contact.contact_type            AS contact_contact_type,\n        civicrm_contact.id                      AS contact_id,\n        civicrm_contribution.id                 AS contribution_id,\n        civicrm_contribution.total_amount       AS contribution_amount,\n        civicrm_contribution.financial_type_id  AS contribution_financial_type_id,\n        civicrm_campaign.title                  AS contribution_campaign\n      FROM   \n        civicrm_sdd_txgroup\n      LEFT JOIN \n        civicrm_sdd_contribution_txgroup   ON   civicrm_sdd_txgroup.id = civicrm_sdd_contribution_txgroup.txgroup_id\n      LEFT JOIN \n        civicrm_contribution               ON   civicrm_contribution.id = civicrm_sdd_contribution_txgroup.contribution_id\n      LEFT JOIN \n        civicrm_contact                    ON   civicrm_contact.id = civicrm_contribution.contact_id\n      LEFT JOIN \n        civicrm_campaign                   ON   civicrm_campaign.id = civicrm_contribution.campaign_id\n      WHERE       \n        civicrm_sdd_txgroup.id = {$group_id};";
         $total_amount = 0.0;
         $total_count = 0;
         $total_campaigns = array();
         $total_types = array();
         $total_contacts = array();
         $contact_base_link = CRM_Utils_System::url('civicrm/contact/view', '&reset=1&cid=');
         $contribution_base_link = CRM_Utils_System::url('civicrm/contact/view/contribution', '&reset=1&id=_cid_&cid=_id_&action=view');
         $contributions = array();
         $result = CRM_Core_DAO::executeQuery($sql);
         while ($result->fetch()) {
             $contributions[$total_count] = array('contact_display_name' => $result->contact_display_name, 'contact_type' => $result->contact_contact_type, 'contact_id' => $result->contact_id, 'contact_link' => $contact_base_link . $result->contact_id, 'contribution_link' => str_replace('_id_', $result->contact_id, str_replace('_cid_', $result->contribution_id, $contribution_base_link)), 'contribution_id' => $result->contribution_id, 'contribution_amount' => $result->contribution_amount, 'contribution_amount_str' => CRM_Utils_Money::format($result->contribution_amount, 'EUR'), 'financial_type' => $financial_types[$result->contribution_financial_type_id], 'campaign' => $result->contribution_campaign);
             $total_count += 1;
             $total_amount += $result->contribution_amount;
             $total_types[$result->contribution_financial_type_id] = 1;
             $total_contacts[$result->contact_id] = 1;
             $total_campaigns[$result->contribution_campaign] = 1;
             $reference = $result->reference;
         }
     }
     $this->assign("txgroup", $txgroup);
     $this->assign("reference", $reference);
     $this->assign("group_id", $group_id);
     $this->assign("total_count", $total_count);
     $this->assign("total_amount", $total_amount);
     $this->assign("total_amount_str", CRM_Utils_Money::format($total_amount, 'EUR'));
     $this->assign("contributions", $contributions);
     $this->assign("different_campaigns", count($total_campaigns));
     $this->assign("different_types", count($total_types));
     $this->assign("different_contacts", count($total_contacts));
     parent::run();
 }
示例#17
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     require_once 'CRM/Price/BAO/FieldValue.php';
     if (isset($this->_oid)) {
         $params = array('id' => $this->_oid);
         CRM_Price_BAO_FieldValue::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         require_once 'CRM/Utils/Money.php';
         $defaults['value'] = CRM_Utils_Money::format($defaults['value'], null, '%a');
     }
     require_once 'CRM/Core/DAO.php';
     require_once 'CRM/Utils/Weight.php';
     if (!isset($defaults['weight']) || !$defaults['weight']) {
         $fieldValues = array('price_field_id' => $this->_fid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_FieldValue', $fieldValues);
         $defaults['is_active'] = 1;
     }
     return $defaults;
 }
示例#18
0
 /**
  * Set the parameters to be passed to contribution create function.
  *
  * @param array $params
  * @param int $financialTypeID
  * @param float $nonDeductibleAmount
  * @param bool $pending
  * @param array $paymentProcessorOutcome
  * @param string $receiptDate
  * @param int $recurringContributionID
  *
  * @return array
  */
 public static function getContributionParams($params, $financialTypeID, $nonDeductibleAmount, $pending, $paymentProcessorOutcome, $receiptDate, $recurringContributionID)
 {
     $contributionParams = array('financial_type_id' => $financialTypeID, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'tax_amount' => CRM_Utils_Array::value('tax_amount', $params), 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'skipLineItem' => CRM_Utils_Array::value('skipLineItem', $params, 0));
     if ($paymentProcessorOutcome) {
         $contributionParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $paymentProcessorOutcome);
     }
     if (!$pending && $paymentProcessorOutcome) {
         $contributionParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $paymentProcessorOutcome), 'net_amount' => CRM_Utils_Array::value('net_amount', $paymentProcessorOutcome, $params['amount']), 'trxn_id' => $paymentProcessorOutcome['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $paymentProcessorOutcome));
     }
     // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
     $contributionParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contributionParams['non_deductible_amount'], ' '));
     $contributionParams['total_amount'] = trim(CRM_Utils_Money::format($contributionParams['total_amount'], ' '));
     if ($recurringContributionID) {
         $contributionParams['contribution_recur_id'] = $recurringContributionID;
     }
     $contributionParams['contribution_status_id'] = $pending ? 2 : 1;
     if (isset($contributionParams['invoice_id'])) {
         $contributionParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionParams['invoice_id'], 'id', 'invoice_id');
     }
     return $contributionParams;
 }
示例#19
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     require_once 'CRM/Pledge/BAO/Pledge.php';
     $values = $ids = array();
     $params = array('id' => $this->get('id'));
     CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids);
     $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit']));
     $values['eachPaymentAmount'] = floor($values['amount'] / $values['installments']);
     if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"];
         $dao =& new CRM_Core_DAO();
         $dao->query($sql);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     //handle custom data.
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     if (CRM_Utils_Array::value('contribution_page_id', $values)) {
         $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title');
     }
     $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType());
     if ($values['status_id']) {
         $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus());
     }
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     require_once 'CRM/Utils/Money.php';
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')';
     // add Pledge to Recent Items
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null);
     $this->assign($values);
 }
/**
 * CampaignDetails.CampaignDetailsActivity API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_campaign_details_activity_get()
{
    $query = "\n            SELECT id,title, is_active,page_type,goal_amount,pcp_block_id\n            FROM civicrm_pcp ";
    $dao = CRM_Core_DAO::executeQuery($query);
    $result = array();
    while ($dao->fetch()) {
        $results[$dao->id]['title'] = $dao->title;
        $results[$dao->id]['is_active'] = $dao->is_active ? 'Active' : 'Inactive';
        $results[$dao->id]['page_type'] = getContributionPageTitle($dao->id, $dao->page_type);
        $results[$dao->id]['goal_amount'] = CRM_Utils_Money::format($dao->goal_amount, $dao->currency);
        $contributionDetails = getContributionDetails($dao->id);
        $results[$dao->id]['amout_raised'] = CRM_Utils_Money::format(0, $dao->currency);
        $results[$dao->id]['no_of_contributions'] = 0;
        if ($contributionDetails) {
            $results[$dao->id]['amout_raised'] = CRM_Utils_Money::format($contributionDetails[0], $dao->currency);
            $results[$dao->id]['no_of_contributions'] = $contributionDetails[1];
        }
        $results[$dao->id]['view_page_link'] = CRM_Utils_System::url('civicrm/pcp/info', 'reset=1&id=' . $dao->id . '&component=' . $dao->page_type);
        $results[$dao->id]['edit_page_link'] = CRM_Utils_System::url('civicrm/pcp/info', "action=update&reset=1&id={$dao->id}&context=dashboard");
    }
    return civicrm_api3_create_success($results);
}
示例#21
0
 /**
  * Set default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return array
  *   defaults
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         $baoName = $this->_BAOName;
         $baoName::retrieve($params, $defaults);
     }
     if (isset($defaults['minimum_fee'])) {
         $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
     }
     if (isset($defaults['status'])) {
         $this->assign('membershipStatus', $defaults['status']);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
     }
     if (isset($defaults['member_of_contact_id']) && $defaults['member_of_contact_id']) {
         $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['member_of_contact_id'], 'display_name');
     }
     return $defaults;
 }
示例#22
0
 /**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     $params = array();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         require_once str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php";
         eval($this->_BAOName . '::retrieve( $params, $defaults );');
     }
     if (isset($defaults['minimum_fee'])) {
         $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
     }
     if (isset($defaults['status'])) {
         $this->assign('membershipStatus', $defaults['status']);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
     }
     if (isset($defaults['member_of_contact_id']) && $defaults['member_of_contact_id']) {
         $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['member_of_contact_id'], 'display_name');
     }
     return $defaults;
 }
示例#23
0
 function setDefaultValues()
 {
     require_once 'CRM/Contribute/DAO/PCP.php';
     $dafaults = array();
     $dao =& new CRM_Contribute_DAO_PCP();
     if ($this->_pageId) {
         $dao->id = $this->_pageId;
         if ($dao->find(true)) {
             CRM_Core_DAO::storeValues($dao, $defaults);
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['goal_amount'])) {
             require_once 'CRM/Utils/Money.php';
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], null, '%a');
         }
     }
     if ($this->get('action') & CRM_Core_Action::ADD) {
         $defaults['is_active'] = 1;
     }
     $this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
     $this->_contriPageId = CRM_Utils_Array::value('contribution_page_id', $defaults);
     return $defaults;
 }
示例#24
0
文件: AJAX.php 项目: kidaa30/yes
 /**
  * SetDefaults according to membership type.
  */
 public static function getMemberTypeDefaults()
 {
     if (!$_POST['mtype']) {
         $details['name'] = '';
         $details['auto_renew'] = '';
         $details['total_amount'] = '';
         CRM_Utils_JSON::output($details);
     }
     $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
     $query = "SELECT name, minimum_fee AS total_amount, financial_type_id, auto_renew\nFROM    civicrm_membership_type\nWHERE   id = %1";
     $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($memType, 'Positive')));
     $properties = array('financial_type_id', 'total_amount', 'name', 'auto_renew');
     while ($dao->fetch()) {
         foreach ($properties as $property) {
             $details[$property] = $dao->{$property};
         }
     }
     $details['total_amount_numeric'] = $details['total_amount'];
     // fix the display of the monetary value, CRM-4038
     $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
     $options = CRM_Core_SelectValues::memberAutoRenew();
     $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
     CRM_Utils_JSON::output($details);
 }
示例#25
0
 /**
  * wrapper for ajax batch selector.
  *
  * @param array $params
  *   Associated array for params record id.
  *
  * @return array
  *   associated array of batch list
  */
 public function getBatchListSelector(&$params)
 {
     // format the params
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     // get batches
     $batches = self::getBatchList($params);
     // get batch totals for open batches
     $fetchTotals = array();
     $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
     $batchStatus = array(array_search('Open', $batchStatus), array_search('Reopened', $batchStatus));
     if ($params['context'] == 'financialBatch') {
         foreach ($batches as $id => $batch) {
             if (in_array($batch['status_id'], $batchStatus)) {
                 $fetchTotals[] = $id;
             }
         }
     }
     $totals = self::batchTotals($fetchTotals);
     // add count
     $params['total'] = self::getBatchCount($params);
     // format params and add links
     $batchList = array();
     foreach ($batches as $id => $value) {
         $batch = array();
         if ($params['context'] == 'financialBatch') {
             $batch['check'] = $value['check'];
         }
         $batch['batch_name'] = $value['title'];
         $batch['total'] = '';
         $batch['payment_instrument'] = $value['payment_instrument'];
         $batch['item_count'] = CRM_Utils_Array::value('item_count', $value);
         $batch['type'] = $value['batch_type'];
         if (!empty($value['total'])) {
             $batch['total'] = CRM_Utils_Money::format($value['total']);
         }
         // Compare totals with actuals
         if (isset($totals[$id])) {
             $batch['item_count'] = self::displayTotals($totals[$id]['item_count'], $batch['item_count']);
             $batch['total'] = self::displayTotals(CRM_Utils_Money::format($totals[$id]['total']), $batch['total']);
         }
         $batch['status'] = $value['batch_status'];
         $batch['created_by'] = $value['created_by'];
         $batch['links'] = $value['action'];
         $batchList[$id] = $batch;
     }
     return $batchList;
 }
示例#26
0
 public function buildAmountLabel()
 {
     $default = array();
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "discounted_label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         // value
         for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
             $this->add('text', "discounted_value[{$i}][{$j}]", ts('Value'), array('size' => 10));
             $this->addRule("discounted_value[{$i}][{$j}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
         }
         // default
         $default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
     }
     $this->addGroup($default, 'discounted_default');
 }
示例#27
0
文件: PCP.php 项目: kidaa30/yes
 /**
  * Show the amount, nickname on honor roll
  *
  * @param array $pcpId
  *   Contains the pcp ID.
  *
  *
  * @return array
  */
 public static function honorRoll($pcpId)
 {
     $query = "\n            SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note,\n                   cc.total_amount, cc.currency\n            FROM civicrm_contribution cc\n                 LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id\n            WHERE cs.pcp_id = {$pcpId}\n                  AND cs.pcp_display_in_roll = 1\n                  AND contribution_status_id = 1\n                  AND is_test = 0";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     $honor = array();
     while ($dao->fetch()) {
         $honor[$dao->id]['nickname'] = ucwords($dao->pcp_roll_nickname);
         $honor[$dao->id]['total_amount'] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
         $honor[$dao->id]['personal_note'] = $dao->pcp_personal_note;
     }
     return $honor;
 }
示例#28
0
 /**
  * Browse all membership types.
  *  
  * 
  * @return void
  * @access public
  * @static
  */
 function browse()
 {
     // get all membership types sorted by weight
     $membershipType = array();
     require_once 'CRM/Member/DAO/MembershipType.php';
     $dao =& new CRM_Member_DAO_MembershipType();
     $dao->orderBy('weight');
     $dao->find();
     require_once 'CRM/Utils/Money.php';
     while ($dao->fetch()) {
         $membershipType[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]);
         // fix the display of the monetary value, CRM-4038
         if (CRM_Utils_Array::value('minimum_fee', $membershipType[$dao->id])) {
             $membershipType[$dao->id]['minimum_fee'] = CRM_Utils_Money::format($membershipType[$dao->id]['minimum_fee'], null, '%a');
         }
         //adding column for relationship type label. CRM-4178.
         if ($dao->relationship_type_id) {
             $relationshipName = 'label_' . $dao->relationship_direction;
             $membershipType[$dao->id]['relationshipTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $dao->relationship_type_id, $relationshipName);
         }
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links depending on if it is is_reserved or is_active
         if (!isset($dao->is_reserved)) {
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
             $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight'];
             $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
         }
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
     require_once 'CRM/Utils/Weight.php';
     CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL);
     CRM_Member_BAO_MembershipType::convertDayFormat($membershipType);
     $this->assign('rows', $membershipType);
 }
示例#29
0
 /** 
  * This function sets the default values for the form. Note that in edit/view mode 
  * the default values are retrieved from the database 
  * 
  * @access public 
  * @return void 
  */
 function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
     CRM_Utils_System::setTitle(ts('Contribution Amounts (%1)', array(1 => $title)));
     if (!CRM_Utils_Array::value('pay_later_text', $defaults)) {
         $defaults['pay_later_text'] = ts('I will send payment by check');
     }
     if (CRM_Utils_Array::value('amount_block_is_active', $defaults)) {
         // don't allow other amount option when price set present.
         $this->assign('priceSetID', $this->_priceSetID);
         if ($this->_priceSetID) {
             return $defaults;
         }
         require_once 'CRM/Core/OptionGroup.php';
         CRM_Core_OptionGroup::getAssoc("civicrm_contribution_page.amount.{$this->_id}", $this->_amountBlock);
         $hasAmountBlock = false;
         if (!empty($this->_amountBlock)) {
             $hasAmountBlock = true;
             $defaults = array_merge($defaults, $this->_amountBlock);
         }
         if (CRM_Utils_Array::value('value', $defaults) && is_array($defaults['value'])) {
             if (CRM_Utils_Array::value('default_amount_id', $defaults) && CRM_Utils_Array::value('amount_id', $defaults) && is_array($defaults['amount_id'])) {
                 foreach ($defaults['value'] as $i => $v) {
                     if ($defaults['amount_id'][$i] == $defaults['default_amount_id']) {
                         $defaults['default'] = $i;
                         break;
                     }
                 }
             }
             // CRM-4038: fix value display
             foreach ($defaults['value'] as &$amount) {
                 $amount = trim(CRM_Utils_Money::format($amount, ' '));
             }
         }
     }
     // fix the display of the monetary value, CRM-4038
     require_once 'CRM/Utils/Money.php';
     if (isset($defaults['min_amount'])) {
         $defaults['min_amount'] = CRM_Utils_Money::format($defaults['min_amount'], null, '%a');
     }
     if (isset($defaults['max_amount'])) {
         $defaults['max_amount'] = CRM_Utils_Money::format($defaults['max_amount'], null, '%a');
     }
     return $defaults;
 }
示例#30
0
 /**
  * @param $rows
  *
  * @return array
  */
 public function statistics(&$rows)
 {
     $statistics = parent::statistics($rows);
     //fetch contributions for both date ranges from pre-existing temp tables
     $sql = "\nCREATE TEMPORARY TABLE civicrm_temp_civireport_repeat3\nSELECT contact_id FROM civicrm_temp_civireport_repeat1 UNION SELECT contact_id FROM civicrm_temp_civireport_repeat2;";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $sql = "\nSELECT civicrm_temp_civireport_repeat3.contact_id,\n       civicrm_temp_civireport_repeat1.total_amount_sum as contribution1_total_amount_sum,\n       civicrm_temp_civireport_repeat2.total_amount_sum as contribution2_total_amount_sum\nFROM civicrm_temp_civireport_repeat3\nLEFT JOIN civicrm_temp_civireport_repeat1\n       ON civicrm_temp_civireport_repeat3.contact_id = civicrm_temp_civireport_repeat1.contact_id\nLEFT JOIN civicrm_temp_civireport_repeat2\n       ON civicrm_temp_civireport_repeat3.contact_id = civicrm_temp_civireport_repeat2.contact_id";
     $dao = CRM_Core_DAO::executeQuery($sql);
     //store contributions in array 'contact_sums' for comparison
     $contact_sums = array();
     while ($dao->fetch()) {
         $contact_sums[$dao->contact_id] = array('contribution1_total_amount_sum' => $dao->contribution1_total_amount_sum, 'contribution2_total_amount_sum' => $dao->contribution2_total_amount_sum);
     }
     $total_distinct_contacts = count($contact_sums);
     $maintained = 0;
     $upgraded = 0;
     $downgraded = 0;
     $new = 0;
     $lapsed = 0;
     foreach ($contact_sums as $uid => $row) {
         if ($row['contribution1_total_amount_sum'] && $row['contribution2_total_amount_sum']) {
             $change = $row['contribution1_total_amount_sum'] - $row['contribution2_total_amount_sum'];
             if ($change == 0) {
                 $maintained += 1;
             } elseif ($change > 0) {
                 $upgraded += 1;
             } elseif ($change < 0) {
                 $downgraded += 1;
             }
         } elseif ($row['contribution1_total_amount_sum']) {
             $new += 1;
         } elseif ($row['contribution2_total_amount_sum']) {
             $lapsed += 1;
         }
     }
     //calculate percentages from numbers
     if (!empty($total_distinct_contacts)) {
         $maintained = $maintained / $total_distinct_contacts * 100;
         $upgraded = $upgraded / $total_distinct_contacts * 100;
         $downgraded = $downgraded / $total_distinct_contacts * 100;
         $new = $new / $total_distinct_contacts * 100;
         $lapsed = $lapsed / $total_distinct_contacts * 100;
     }
     //display percentages for new, lapsed, upgraded, downgraded, and maintained contributors
     $statistics['counts']['count_new'] = array('value' => $new, 'title' => '% New Donors');
     $statistics['counts']['count_lapsed'] = array('value' => $lapsed, 'title' => '% Lapsed Donors');
     $statistics['counts']['count_upgraded'] = array('value' => $upgraded, 'title' => '% Upgraded Donors');
     $statistics['counts']['count_downgraded'] = array('value' => $downgraded, 'title' => '% Downgraded Donors');
     $statistics['counts']['count_maintained'] = array('value' => $maintained, 'title' => '% Maintained Donors');
     $select = "\nSELECT COUNT({$this->_aliases['civicrm_contribution']}1.total_amount_count )       as count,\n       SUM({$this->_aliases['civicrm_contribution']}1.total_amount_sum )           as amount,\n       ROUND(AVG({$this->_aliases['civicrm_contribution']}1.total_amount_sum), 2)  as avg,\n       COUNT({$this->_aliases['civicrm_contribution']}2.total_amount_count )       as count2,\n       SUM({$this->_aliases['civicrm_contribution']}2.total_amount_sum )           as amount2,\n       ROUND(AVG({$this->_aliases['civicrm_contribution']}2.total_amount_sum), 2)  as avg2,\n       currency";
     $sql = "{$select} {$this->_from} {$this->_where}\nGROUP BY    currency\n";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $amount = $average = $amount2 = $average2 = array();
     $count = $count2 = 0;
     while ($dao->fetch()) {
         if ($dao->amount) {
             $amount[] = CRM_Utils_Money::format($dao->amount, $dao->currency) . "(" . $dao->count . ")";
             $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
         }
         $count += $dao->count;
         if ($dao->amount2) {
             $amount2[] = CRM_Utils_Money::format($dao->amount2, $dao->currency) . "(" . $dao->count . ")";
             $average2[] = CRM_Utils_Money::format($dao->avg2, $dao->currency);
         }
         $count2 += $dao->count2;
     }
     $statistics['counts']['range_one_title'] = array('title' => 'Initial Date Range:');
     $statistics['counts']['amount'] = array('value' => implode(',  ', $amount), 'title' => 'Total Amount', 'type' => CRM_Utils_Type::T_STRING);
     $statistics['counts']['count'] = array('value' => $count, 'title' => 'Total Donations');
     $statistics['counts']['avg'] = array('value' => implode(',  ', $average), 'title' => 'Average', 'type' => CRM_Utils_Type::T_STRING);
     $statistics['counts']['range_two_title'] = array('title' => 'Second Date Range:');
     $statistics['counts']['amount2'] = array('value' => implode(',  ', $amount2), 'title' => 'Total Amount', 'type' => CRM_Utils_Type::T_STRING);
     $statistics['counts']['count2'] = array('value' => $count2, 'title' => 'Total Donations');
     $statistics['counts']['avg2'] = array('value' => implode(',  ', $average2), 'title' => 'Average', 'type' => CRM_Utils_Type::T_STRING);
     return $statistics;
 }