Example #1
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'order_bys' => array('sort_name' => array('title' => ts("Last name, First name"))), 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('id' => array('no_display' => TRUE, 'required' => TRUE), 'total_amount' => array('title' => ts('Amount Contributed to Date'), 'statistics' => array('sum' => ts("Total Amount Contributed"))))), 'civicrm_contribution_recur' => array('dao' => 'CRM_Contribute_DAO_ContributionRecur', 'fields' => array('id' => array('no_display' => TRUE, 'required' => TRUE), 'currency' => array('title' => ts("Currency"), 'required' => TRUE, 'no_display' => TRUE), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'frequency_interval' => array('title' => ts('Frequency interval'), 'default' => TRUE), 'frequency_unit' => array('title' => ts('Frequency unit'), 'default' => TRUE), 'amount' => array('title' => ts('Installment Amount'), 'default' => TRUE), 'installments' => array('title' => ts('Installments'), 'default' => TRUE), 'start_date' => array('title' => ts('Start Date')), 'create_date' => array('title' => ts('Create Date')), 'modified_date' => array('title' => ts('Modified Date')), 'cancel_date' => array('title' => ts('Cancel Date')), 'end_date' => array('title' => ts('End Date')), 'next_sched_contribution_date' => array('title' => ts('Next Scheduled Contribution Date')), 'failure_count' => array('title' => ts('Failure Count')), 'failure_retry_date' => array('title' => ts('Failure Retry Date'))), 'filters' => array('contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(5), 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(), 'type' => CRM_Utils_Type::T_INT), 'frequency_unit' => array('title' => ts('Frequency Unit'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('recur_frequency_units'), 'type' => CRM_Utils_Type::T_INT), 'frequency_interval' => array('title' => ts('Frequency Interval'), 'type' => CRM_Utils_Type::T_INT), 'amount' => array('title' => ts('Installment Amount'), 'type' => CRM_Utils_Type::T_MONEY), 'installments' => array('title' => ts('Installments'), 'type' => CRM_Utils_Type::T_INT), 'start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME), 'next_sched_contribution_date' => array('title' => ts('Next Scheduled Contribution Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME), 'modified_date' => array('title' => ts('Last Contribution Processed'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME), 'calculated_end_date' => array('title' => ts('Calculated end date (either end date or date all installments will be made)'), 'description' => "does this work?", 'operatorType' => CRM_Report_Form::OP_DATE, 'pseudofield' => TRUE))));
     $this->_currencyColumn = 'civicrm_contribution_recur_currency';
     $this->_groupFilter = TRUE;
     parent::__construct();
 }
Example #2
0
 /**
  */
 public function __construct()
 {
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'grouping' => 'contact-fields', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'display_name' => array('title' => ts('Display Name'), 'no_repeat' => TRUE), 'addressee_display' => array('title' => ts('Addressee Name'), 'no_repeat' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'contact_type' => array('title' => ts('Contact Type'), 'no_repeat' => TRUE), 'contact_sub_type' => array('title' => ts('Contact Subtype'), 'no_repeat' => TRUE)), 'filters' => array('percentage_change' => array('title' => ts('Percentage Change'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'percentage_change', 'dbAlias' => '( ( contribution_civireport2.total_amount_sum - contribution_civireport1.total_amount_sum ) * 100 / contribution_civireport1.total_amount_sum )')), 'group_bys' => array('id' => array('title' => ts('Contact'), 'default' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'grouping' => 'contact-fields', 'fields' => array('street_address' => array('title' => ts('Street Address')), 'supplemental_address_1' => array('title' => ts('Supplemental Address 1')), 'city' => array('title' => ts('City')), 'country_id' => array('title' => ts('Country')), 'state_province_id' => array('title' => ts('State/Province')), 'postal_code' => array('title' => ts('Postal Code'))), 'group_bys' => array('country_id' => array('title' => ts('Country')), 'state_province_id' => array('title' => ts('State/Province')))), 'civicrm_financial_type' => array('dao' => 'CRM_Financial_DAO_FinancialType', 'fields' => array('financial_type' => array('title' => ts('Financial Type'))), 'grouping' => 'contri-fields', 'group_bys' => array('financial_type' => array('name' => 'id', 'title' => ts('Financial Type')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => NULL, 'total_amount1' => array('name' => 'total_amount', 'alias' => 'contribution1', 'title' => ts('Range One Stat'), 'type' => CRM_Utils_Type::T_MONEY, 'default' => TRUE, 'required' => TRUE, 'clause' => 'contribution_civireport1.total_amount_count as contribution1_total_amount_count, contribution_civireport1.total_amount_sum as contribution1_total_amount_sum'), 'total_amount2' => array('name' => 'total_amount', 'alias' => 'contribution2', 'title' => ts('Range Two Stat'), 'type' => CRM_Utils_Type::T_MONEY, 'default' => TRUE, 'required' => TRUE, 'clause' => 'contribution_civireport2.total_amount_count as contribution2_total_amount_count, contribution_civireport2.total_amount_sum as contribution2_total_amount_sum')), 'grouping' => 'contri-fields', 'filters' => array('receive_date1' => array('title' => ts('Initial Date Range'), 'default' => 'previous.year', 'operatorType' => CRM_Report_Form::OP_DATE, 'name' => 'receive_date'), 'receive_date2' => array('title' => ts('Second Date Range'), 'default' => 'this.year', 'operatorType' => CRM_Report_Form::OP_DATE, 'name' => 'receive_date'), 'total_amount1' => array('title' => ts('Range One Amount'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'total_amount'), 'total_amount2' => array('title' => ts('Range Two Amount'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_INT, 'name' => 'total_amount'), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array('1'))), 'group_bys' => array('contribution_source' => NULL)));
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     parent::__construct();
 }
Example #3
0
 /**
  */
 public function __construct()
 {
     $this->_rollup = 'WITH ROLLUP';
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
     $yearsInPast = 10;
     $yearsInFuture = 1;
     $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture);
     $count = $date['maxYear'];
     while ($date['minYear'] <= $count) {
         $optionYear[$date['minYear']] = $date['minYear'];
         $date['minYear']++;
     }
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'grouping' => 'contact-field', 'fields' => array('sort_name' => array('title' => ts('Donor Name'), 'required' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('name' => 'first_name', 'title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'age_at_event' => array('name' => 'age_at_event', 'title' => ts('Age at Event')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'grouping' => 'contact-field', 'fields' => array('email' => array('title' => ts('Email'), 'default' => TRUE))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'grouping' => 'contact-field', 'fields' => array('phone' => array('title' => ts('Phone'), 'default' => TRUE))));
     $this->_columns += $this->addAddressFields();
     $this->_columns += array('civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contact_id' => array('title' => ts('contactId'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'total_amount' => array('title' => ts('Total Amount'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'receive_date' => array('title' => ts('Year'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE)), 'filters' => array('yid' => array('name' => 'receive_date', 'title' => ts('This Year'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $optionYear, 'default' => date('Y'), 'type' => CRM_Utils_Type::T_INT), 'financial_type_id' => array('title' => ts('Financial Type'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array('1')))));
     // If we have a campaign, build out the relevant elements
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns, 'type' => CRM_Utils_Type::T_INT);
     }
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     parent::__construct();
 }
Example #4
0
 /**
  */
 public function __construct()
 {
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Donor Name'), 'required' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE, 'type' => CRM_Utils_Type::T_INT), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('name' => 'first_name', 'title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Donor Email'), 'default' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Donor Phone'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'no_display' => TRUE, 'required' => TRUE), 'list_contri_id' => array('name' => 'id', 'title' => ts('Contribution ID')), 'financial_type_id' => array('title' => ts('Financial Type'), 'default' => TRUE), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'contribution_page_id' => array('title' => ts('Contribution Page')), 'source' => array('title' => ts('Source')), 'payment_instrument_id' => array('title' => ts('Payment Type')), 'check_number' => array('title' => ts('Check Number')), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'trxn_id' => NULL, 'receive_date' => array('default' => TRUE), 'receipt_date' => NULL, 'total_amount' => array('title' => ts('Amount'), 'required' => TRUE, 'statistics' => array('sum' => ts('Amount'))), 'fee_amount' => NULL, 'net_amount' => NULL, 'contribution_or_soft' => array('title' => ts('Contribution OR Soft Credit?'), 'dbAlias' => "'Contribution'"), 'soft_credits' => array('title' => ts('Soft Credits'), 'dbAlias' => "NULL"), 'soft_credit_for' => array('title' => ts('Soft Credit For'), 'dbAlias' => "NULL")), 'filters' => array('contribution_or_soft' => array('title' => ts('Contribution OR Soft Credit?'), 'clause' => "(1)", 'operatorType' => CRM_Report_Form::OP_SELECT, 'type' => CRM_Utils_Type::T_STRING, 'options' => array('both' => ts('Both'), 'contributions_only' => ts('Contributions Only'), 'soft_credits_only' => ts('Soft Credits Only'))), 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(), 'type' => CRM_Utils_Type::T_INT), 'contribution_page_id' => array('title' => ts('Contribution Page'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionPage(), 'type' => CRM_Utils_Type::T_INT), 'payment_instrument_id' => array('title' => ts('Payment Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'type' => CRM_Utils_Type::T_INT), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Contribution Amount'))), 'order_bys' => array('financial_type_id' => array('title' => ts('Financial Type')), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'payment_instrument_id' => array('title' => ts('Payment Method')), 'receive_date' => array('title' => ts('Date Received'))), 'grouping' => 'contri-fields'), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('soft_credit_type_id' => array('title' => ts('Soft Credit Type'))), 'filters' => array('soft_credit_type_id' => array('title' => 'Soft Credit Type', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('soft_credit_type'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING))), 'civicrm_contribution_ordinality' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'alias' => 'cordinality', 'filters' => array('ordinality' => array('title' => ts('Contribution Ordinality'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => array(0 => 'First by Contributor', 1 => 'Second or Later by Contributor'), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_note' => array('dao' => 'CRM_Core_DAO_Note', 'fields' => array('contribution_note' => array('name' => 'note', 'title' => ts('Contribution Note'))), 'filters' => array('note' => array('name' => 'note', 'title' => ts('Contribution Note'), 'operator' => 'like', 'type' => CRM_Utils_Type::T_STRING)))) + $this->addAddressFields(FALSE);
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     // Don't show Batch display column and filter unless batches are being used
     $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
     if (!empty($this->_allBatches)) {
         $this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
         $this->_columns['civicrm_batch']['fields']['batch_id'] = array('name' => 'id', 'title' => ts('Batch Name'));
         $this->_columns['civicrm_batch']['filters']['bid'] = array('name' => 'id', 'title' => ts('Batch Name'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->_allBatches);
         $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
         $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array('name' => 'batch_id', 'default' => TRUE, 'no_display' => TRUE);
     }
     // If we have active campaigns add those elements to both the fields and filters
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns, 'type' => CRM_Utils_Type::T_INT);
         $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
 }
Example #5
0
 /**
  */
 public function __construct()
 {
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Contact Name'), 'required' => TRUE, 'no_repeat' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('name' => 'first_name', 'title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('sort_name' => array('title' => ts('Contact Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_membership' => array('dao' => 'CRM_Member_DAO_Membership', 'fields' => array('id' => array('title' => ts('Membership #'), 'no_display' => TRUE, 'required' => TRUE))), 'civicrm_financial_account' => array('dao' => 'CRM_Financial_DAO_FinancialAccount', 'fields' => array('debit_accounting_code' => array('title' => ts('Financial Account Code - Debit'), 'name' => 'accounting_code', 'alias' => 'financial_account_civireport_debit', 'default' => TRUE), 'credit_accounting_code' => array('title' => ts('Financial Account Code - Credit'), 'name' => 'accounting_code', 'alias' => 'financial_account_civireport_credit', 'default' => TRUE), 'debit_name' => array('title' => ts('Financial Account Name - Debit'), 'name' => 'name', 'alias' => 'financial_account_civireport_debit', 'default' => TRUE), 'credit_name' => array('title' => ts('Financial Account Name - Credit'), 'name' => 'name', 'alias' => 'financial_account_civireport_credit', 'default' => TRUE)), 'filters' => array('debit_accounting_code' => array('title' => ts('Financial Account Code - Debit'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialAccount(NULL, NULL, 'accounting_code', 'accounting_code'), 'name' => 'accounting_code', 'alias' => 'financial_account_civireport_debit'), 'credit_accounting_code' => array('title' => ts('Financial Account Code - Credit'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialAccount(NULL, NULL, 'accounting_code', 'accounting_code')), 'debit_name' => array('title' => ts('Financial Account Name - Debit'), 'type' => CRM_Utils_Type::T_STRING, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialAccount(), 'name' => 'id', 'alias' => 'financial_account_civireport_debit'), 'credit_name' => array('title' => ts('Financial Account Name - Credit'), 'type' => CRM_Utils_Type::T_STRING, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialAccount()))), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem', 'fields' => array('financial_type_id' => array('title' => ts('Financial Type'), 'default' => TRUE)), 'filters' => array('financial_type_id' => array('title' => ts('Financial Type'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes())), 'order_bys' => array('financial_type_id' => array('title' => ts('Financial Type')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('receive_date' => array('default' => TRUE), 'invoice_id' => array('title' => ts('Invoice ID'), 'default' => TRUE), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'default' => TRUE), 'id' => array('title' => ts('Contribution #'), 'default' => TRUE)), 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1))), 'order_bys' => array('contribution_id' => array('title' => ts('Contribution #')), 'contribution_status_id' => array('title' => ts('Contribution Status'))), 'grouping' => 'contri-fields'), 'civicrm_financial_trxn' => array('dao' => 'CRM_Financial_DAO_FinancialTrxn', 'fields' => array('check_number' => array('title' => ts('Cheque #'), 'default' => TRUE), 'payment_instrument_id' => array('title' => ts('Payment Method'), 'default' => TRUE), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'trxn_date' => array('title' => ts('Transaction Date'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_DATE), 'trxn_id' => array('title' => ts('Trans #'), 'default' => TRUE)), 'filters' => array('payment_instrument_id' => array('title' => ts('Payment Method'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument()), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'trxn_date' => array('title' => ts('Transaction Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE)), 'order_bys' => array('payment_instrument_id' => array('title' => ts('Payment Method')))), 'civicrm_entity_financial_trxn' => array('dao' => 'CRM_Financial_DAO_EntityFinancialTrxn', 'fields' => array('amount' => array('title' => ts('Amount'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING)), 'filters' => array('amount' => array('title' => ts('Amount')))));
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     parent::__construct();
 }
Example #6
0
 /**
  */
 public function __construct()
 {
     $this->_autoIncludeIndexedFieldsAsOrderBys = 1;
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Contact Name'), 'required' => TRUE, 'no_repeat' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')))), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem'));
     $this->_columns += $this->getAddressColumns();
     $this->_columns += array('civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('total_amount' => array('title' => ts('Amount Statistics'), 'required' => TRUE, 'statistics' => array('sum' => ts('Aggregate Amount'), 'count' => ts('Donations'), 'avg' => ts('Average'))), 'currency' => array('required' => TRUE, 'no_display' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Participant Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')), 'receive_date' => array('default' => 'this.year', 'operatorType' => CRM_Report_Form::OP_DATE), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'total_range' => array('title' => ts('Show no. of Top Donors'), 'type' => CRM_Utils_Type::T_INT, 'default_op' => 'eq'), 'financial_type_id' => array('name' => 'financial_type_id', 'title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1)))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'email-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'phone-fields'));
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
 }
Example #7
0
/**
 * Add or update a Contribution.
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws API_Exception
 * @return array
 *   Api result array
 */
function civicrm_api3_contribution_create(&$params)
{
    $values = array();
    _civicrm_api3_custom_format_params($params, $values, 'Contribution');
    $params = array_merge($params, $values);
    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
        if (empty($params['id'])) {
            $op = CRM_Core_Action::ADD;
        } else {
            if (empty($params['financial_type_id'])) {
                $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['id'], 'financial_type_id');
            }
            $op = CRM_Core_Action::UPDATE;
        }
        CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
        if (!in_array($params['financial_type_id'], array_keys($types))) {
            return civicrm_api3_create_error('You do not have permission to create this contribution');
        }
    }
    if (!empty($params['id']) && !empty($params['contribution_status_id'])) {
        $error = array();
        //throw error for invalid status change such as setting completed back to pending
        //@todo this sort of validation belongs in the BAO not the API - if it is not an OK
        // action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
        CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
        if (array_key_exists('contribution_status_id', $error)) {
            throw new API_Exception($error['contribution_status_id']);
        }
    }
    if (!empty($params['id']) && !empty($params['financial_type_id'])) {
        $error = array();
        CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
        if (array_key_exists('financial_type_id', $error)) {
            throw new API_Exception($error['financial_type_id']);
        }
    }
    _civicrm_api3_contribution_create_legacy_support_45($params);
    // Make sure tax calculation is handled via api.
    // @todo this belongs in the BAO NOT the api.
    $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
    return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
}
Example #8
0
 /**
  */
 public function __construct()
 {
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name_creditor' => array('title' => ts('Soft Credit Name'), 'name' => 'sort_name', 'alias' => 'contact_civireport', 'required' => TRUE, 'no_repeat' => TRUE), 'id_creditor' => array('title' => ts('Soft Credit Id'), 'name' => 'id', 'alias' => 'contact_civireport', 'no_display' => TRUE, 'required' => TRUE), 'display_name_constituent' => array('title' => ts('Contributor Name'), 'name' => 'sort_name', 'alias' => 'constituentname', 'required' => TRUE), 'id_constituent' => array('title' => ts('Const Id'), 'name' => 'id', 'alias' => 'constituentname', 'no_display' => TRUE, 'required' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('name' => 'first_name', 'title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'age_at_event' => array('name' => 'age_at_event', 'title' => ts('Age at Event')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('sort_name' => array('name' => 'sort_name', 'title' => ts('Soft Credit Name')), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email_creditor' => array('title' => ts('Soft Credit Email'), 'name' => 'email', 'alias' => 'emailcredit', 'default' => TRUE, 'no_repeat' => TRUE), 'email_constituent' => array('title' => ts('Contributor\'s Email'), 'name' => 'email', 'alias' => 'emailconst')), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone_creditor' => array('title' => ts('Soft Credit Phone'), 'name' => 'phone', 'alias' => 'pcredit', 'default' => TRUE), 'phone_constituent' => array('title' => ts('Contributor\'s Phone'), 'name' => 'phone', 'alias' => 'pconst', 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_financial_type' => array('dao' => 'CRM_Financial_DAO_FinancialType', 'fields' => array('financial_type' => NULL), 'filters' => array('id' => array('name' => 'id', 'title' => ts('Financial Type'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes())), 'grouping' => 'softcredit-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_source' => NULL, 'currency' => array('required' => TRUE, 'no_display' => TRUE)), 'grouping' => 'softcredit-fields', 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1)))), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('contribution_id' => array('title' => ts('Contribution ID'), 'no_display' => TRUE, 'default' => TRUE), 'amount' => array('title' => ts('Amount Statistics'), 'default' => TRUE, 'statistics' => array('sum' => ts('Aggregate Amount'), 'count' => ts('Contributions'), 'avg' => ts('Average'))), 'id' => array('default' => TRUE, 'no_display' => TRUE), 'soft_credit_type_id' => array('title' => ts('Soft Credit Type'))), 'filters' => array('soft_credit_type_id' => array('title' => 'Soft Credit Type', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('soft_credit_type'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'amount' => array('title' => ts('Soft Credit Amount'))), 'grouping' => 'softcredit-fields'));
     // If we have a campaign, build out the relevant elements
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
     }
     $this->_groupFilter = TRUE;
     $this->_tagFilter = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
 }
Example #9
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     // Check if CiviCampaign is a) enabled and b) has active campaigns
     $config = CRM_Core_Config::singleton();
     $campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
     if ($campaignEnabled) {
         $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
         $this->activeCampaigns = $getCampaigns['campaigns'];
         asort($this->activeCampaigns);
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array_merge($this->getBasicContactFields(), array('sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE))), 'grouping' => 'contact-fields', 'group_bys' => array('id' => array('title' => ts('Contact ID')), 'sort_name' => array('title' => ts('Contact Name')))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_financial_type' => array('dao' => 'CRM_Financial_DAO_FinancialType', 'fields' => array('financial_type' => NULL), 'grouping' => 'contri-fields', 'group_bys' => array('financial_type' => array('title' => ts('Financial Type')))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_status_id' => array('title' => ts('Contribution Status')), 'contribution_source' => array('title' => ts('Source')), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'total_amount' => array('title' => ts('Contribution Amount Stats'), 'default' => TRUE, 'statistics' => array('count' => ts('Contributions'), 'sum' => ts('Contribution Aggregate'), 'avg' => ts('Contribution Avg')))), 'grouping' => 'contri-fields', 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => ts('Currency'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes(), 'type' => CRM_Utils_Type::T_INT), 'contribution_page_id' => array('title' => ts('Contribution Page'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionPage(), 'type' => CRM_Utils_Type::T_INT), 'total_amount' => array('title' => ts('Contribution Amount')), 'total_sum' => array('title' => ts('Contribution Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_sum', 'having' => TRUE), 'total_count' => array('title' => ts('Contribution Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_count', 'having' => TRUE), 'total_avg' => array('title' => ts('Contribution Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_total_amount_avg', 'having' => TRUE)), 'group_bys' => array('receive_date' => array('frequency' => TRUE, 'default' => TRUE, 'chart' => TRUE), 'contribution_source' => NULL, 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_batch' => array('dao' => 'CRM_Batch_DAO_EntityBatch', 'grouping' => 'contri-fields', 'filters' => array('batch_id' => array('title' => ts('Batch Title'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Batch_BAO_Batch::getBatches(), 'type' => CRM_Utils_Type::T_INT))), 'civicrm_contribution_soft' => array('dao' => 'CRM_Contribute_DAO_ContributionSoft', 'fields' => array('soft_amount' => array('title' => ts('Soft Credit Amount Stats'), 'name' => 'amount', 'statistics' => array('count' => ts('Soft Credits'), 'sum' => ts('Soft Credit Aggregate'), 'avg' => ts('Soft Credit Avg')))), 'grouping' => 'contri-fields', 'filters' => array('amount' => array('title' => ts('Soft Credit Amount')), 'soft_credit_type_id' => array('title' => ts('Soft Credit Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('soft_credit_type'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'soft_sum' => array('title' => ts('Soft Credit Aggregate'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_sum', 'having' => TRUE), 'soft_count' => array('title' => ts('Soft Credits Count'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_count', 'having' => TRUE), 'soft_avg' => array('title' => ts('Soft Credit Avg'), 'type' => CRM_Report_Form::OP_INT, 'dbAlias' => 'civicrm_contribution_soft_soft_amount_avg', 'having' => TRUE)))) + $this->addAddressFields();
     // If we have a campaign, build out the relevant elements
     if ($campaignEnabled && !empty($this->activeCampaigns)) {
         $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
         $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns);
         $this->_columns['civicrm_contribution']['group_bys']['campaign_id'] = array('title' => ts('Campaign'));
     }
     $this->_tagFilter = TRUE;
     $this->_groupFilter = TRUE;
     $this->_currencyColumn = 'civicrm_contribution_currency';
     parent::__construct();
 }
Example #10
0
 /**
  * Generate temporary table to hold all contributions with permissioned FTs.
  *
  * @param object $query
  * @param string $alias
  * @param bool $return
  */
 public function getPermissionedFTQuery(&$query, $alias = NULL, $return = FALSE)
 {
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         return FALSE;
     }
     $financialTypes = NULL;
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     if (empty($financialTypes)) {
         $contFTs = "0";
         $liFTs = implode(',', array_keys(CRM_Contribute_Pseudoconstant::financialType()));
     } else {
         $contFTs = $liFTs = implode(',', array_keys($financialTypes));
     }
     if ($alias) {
         $temp = CRM_Utils_Array::value('civicrm_line_item', $query->_aliases);
         $query->_aliases['civicrm_line_item'] = $alias;
     }
     if (empty($query->_where)) {
         $query->_where = "WHERE {$query->_aliases['civicrm_contribution']}.id IS NOT NULL ";
     }
     CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS civicrm_contribution_temp");
     $sql = "CREATE TEMPORARY TABLE civicrm_contribution_temp AS SELECT {$query->_aliases['civicrm_contribution']}.id {$query->_from}\n              LEFT JOIN civicrm_line_item   {$query->_aliases['civicrm_line_item']}\n                      ON {$query->_aliases['civicrm_contribution']}.id = {$query->_aliases['civicrm_line_item']}.contribution_id AND\n                         {$query->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution'\n                      AND {$query->_aliases['civicrm_line_item']}.financial_type_id NOT IN (" . $liFTs . ")\n              {$query->_where}\n                      AND {$query->_aliases['civicrm_contribution']}.financial_type_id IN (" . $contFTs . ")\n                      AND {$query->_aliases['civicrm_line_item']}.id IS NULL\n              GROUP BY {$query->_aliases['civicrm_contribution']}.id";
     CRM_Core_DAO::executeQuery($sql);
     if (isset($temp)) {
         $query->_aliases['civicrm_line_item'] = $temp;
     }
     $from = " INNER JOIN civicrm_contribution_temp temp ON {$query->_aliases['civicrm_contribution']}.id = temp.id ";
     if ($return) {
         return $from;
     }
     $query->_from .= $from;
 }
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE);
     $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id));
     $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description'));
     $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee'));
     $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money');
     $this->addSelect('duration_unit', array(), TRUE);
     //period type
     $this->addSelect('period_type', array(), TRUE);
     $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval'));
     $props = array('api' => array('params' => array('contact_type' => 'Organization')));
     $this->addEntityRef('member_of_contact_id', ts('Membership Organization'), $props, TRUE);
     //start day
     $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE);
     //Auto-renew Option
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
     $isAuthorize = FALSE;
     $options = array();
     if (is_array($paymentProcessor) && !empty($paymentProcessor)) {
         $isAuthorize = TRUE;
         $options = CRM_Core_SelectValues::memberAutoRenew();
     }
     $this->addRadio('auto_renew', ts('Auto-renew Option'), $options);
     $this->assign('authorize', $isAuthorize);
     //rollover day
     $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE);
     $this->add('date', 'month_fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'd'), FALSE);
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action), TRUE, array('class' => 'crm-select2'));
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
     if (is_array($relTypeInd)) {
         asort($relTypeInd);
     }
     $memberRel = $this->add('select', 'relationship_type_id', ts('Relationship Type'), $relTypeInd, FALSE, array('class' => 'crm-select2 huge', 'multiple' => 1));
     $this->addSelect('visibility', array('placeholder' => NULL, 'option_url' => NULL));
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $membershipRecords = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $membershipType = new CRM_Member_BAO_Membership();
         $membershipType->membership_type_id = $this->_id;
         if ($membershipType->find(TRUE)) {
             $membershipRecords = TRUE;
             $memberRel->freeze();
         }
     }
     $this->assign('membershipRecordsExists', $membershipRecords);
     $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'max_related'));
     $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule'));
     $this->assign('membershipTypeId', $this->_id);
 }
Example #12
0
 /**
  * Build Premium Block im Contribution Pages.
  *
  * @param CRM_Core_Form $form
  * @param int $pageID
  * @param bool $formItems
  * @param int $selectedProductID
  * @param string $selectedOption
  */
 public static function buildPremiumBlock(&$form, $pageID, $formItems = FALSE, $selectedProductID = NULL, $selectedOption = NULL)
 {
     $form->add('hidden', "selectProduct", $selectedProductID, array('id' => 'selectProduct'));
     $dao = new CRM_Contribute_DAO_Premium();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $pageID;
     $dao->premiums_active = 1;
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
     $addWhere = "financial_type_id IN (0)";
     if (!empty($financialTypes)) {
         $addWhere = "financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
     }
     if ($dao->find(TRUE)) {
         $premiumID = $dao->id;
         $premiumBlock = array();
         CRM_Core_DAO::storeValues($dao, $premiumBlock);
         $dao = new CRM_Contribute_DAO_PremiumsProduct();
         $dao->premiums_id = $premiumID;
         $dao->whereAdd($addWhere);
         $dao->orderBy('weight');
         $dao->find();
         $products = array();
         $radio = array();
         while ($dao->fetch()) {
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $dao->product_id;
             $productDAO->is_active = 1;
             if ($productDAO->find(TRUE)) {
                 if ($selectedProductID != NULL) {
                     if ($selectedProductID == $productDAO->id) {
                         if ($selectedOption) {
                             $productDAO->options = ts('Selected Option') . ': ' . $selectedOption;
                         } else {
                             $productDAO->options = NULL;
                         }
                         CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
                     }
                 } else {
                     CRM_Core_DAO::storeValues($productDAO, $products[$productDAO->id]);
                 }
             }
             $options = $temp = array();
             $temp = explode(',', $productDAO->options);
             foreach ($temp as $value) {
                 $options[trim($value)] = trim($value);
             }
             if ($temp[0] != '') {
                 $form->addElement('select', 'options_' . $productDAO->id, NULL, $options);
             }
         }
         if (count($products)) {
             $form->assign('showPremium', $formItems);
             $form->assign('showSelectOptions', $formItems);
             $form->assign('products', $products);
             $form->assign('premiumBlock', $premiumBlock);
         }
     }
 }
Example #13
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currency', CRM_Core_Config::singleton()->defaultCurrencySymbol);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if (isset($invoicing)) {
         $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
     }
     // build price set form.
     $buildPriceSet = FALSE;
     if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
         if (!empty($_POST['price_set_id'])) {
             $buildPriceSet = TRUE;
         }
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         $optionsMembershipTypes = array();
         foreach ($this->_priceSet['fields'] as $pField) {
             if (empty($pField['options'])) {
                 continue;
             }
             foreach ($pField['options'] as $opId => $opValues) {
                 $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
             }
         }
         $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
         $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
         $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     if ($this->_action & CRM_Core_Action::ADD) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
         if (!empty($priceSets)) {
             $buildPriceSet = TRUE;
         }
         if ($buildPriceSet) {
             $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
         }
         $this->assign('hasPriceSets', $buildPriceSet);
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Membership');
     $this->assign('customDataSubType', $this->_memType);
     $this->assign('entityID', $this->_id);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
     // Throw status bounce when no Membership type or priceset is present
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && empty($this->allMembershipTypeDetails) && empty($priceSets)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     // retrieve all memberships
     $allMembershipInfo = array();
     foreach ($this->allMembershipTypeDetails as $key => $values) {
         if ($this->_mode && empty($values['minimum_fee'])) {
             continue;
         } else {
             $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
             if (empty($selMemTypeOrg[$memberOfContactId])) {
                 $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                 $selOrgMemType[$memberOfContactId][0] = ts('- select -');
             }
             if (empty($selOrgMemType[$memberOfContactId][$key])) {
                 $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
             }
         }
         $totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
         //CRM-18827 - override the default value if total_amount is submitted
         if (!empty($this->_submitValues['total_amount'])) {
             $totalAmount = $this->_submitValues['total_amount'];
         }
         // build membership info array, which is used when membership type is selected to:
         // - set the payment information block
         // - set the max related block
         $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
     }
     $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
     // show organization by default, if only one organization in
     // the list
     if (count($selMemTypeOrg) == 2) {
         unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
     }
     //sort membership organization and type, CRM-6099
     natcasesort($selMemTypeOrg);
     foreach ($selOrgMemType as $index => $orgMembershipType) {
         natcasesort($orgMembershipType);
         $selOrgMemType[$index] = $orgMembershipType;
     }
     $memTypeJs = array('onChange' => "buildMaxRelated(this.value,true); CRM.buildCustomData('Membership', this.value);");
     if (!empty($this->_recurPaymentProcessors)) {
         $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . "buildAutoRenew(this.value, null, '{$this->_mode}');";
     }
     $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
     $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
     $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
     $elements = array();
     if ($sel) {
         $elements[] = $sel;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
     }
     $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
     $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
     $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
     if ($endDate) {
         $elements[] = $endDate;
     }
     $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     if (!$this->_mode) {
         $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
         $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
         if ($statusOverride) {
             $elements[] = $statusOverride;
         }
         $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
         $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
         $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         $this->add('text', 'trxn_id', ts('Transaction ID'));
         $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
         $allowStatuses = array();
         $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
         if ($this->_onlinePendingContributionId) {
             $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach ($statusNames as $val => $name) {
                 if (in_array($name, array('In Progress', 'Overdue'))) {
                     continue;
                 }
                 $allowStatuses[$val] = $statuses[$val];
             }
         } else {
             $allowStatuses = $statuses;
         }
         $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
         $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
     } else {
         //add field for amount to allow an amount to be entered that differs from minimum
         $this->add('text', 'total_amount', ts('Amount'));
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action));
     $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
     $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
     $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showEmailOptions()"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $this->add('textarea', 'receipt_text', ts('Receipt Message'));
     // Retrieve the name and email of the contact - this will be the TO for receipt email
     if ($this->_contactID) {
         list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('emailExists', $this->_memberEmail);
         $this->assign('displayName', $this->_memberDisplayName);
     }
     $isRecur = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
         if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
             $isRecur = TRUE;
             if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                 $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
             }
             foreach ($elements as $elem) {
                 $elem->freeze();
             }
         }
     }
     $this->assign('isRecur', $isRecur);
     $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('isEmailEnabledForSite', $mailingInfo['outBound_option'] != 2);
     parent::buildQuickForm();
 }
Example #14
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // FIXME: This probably needs to be done in preprocess
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE && CRM_Utils_Array::value('financial_type_id', $this->_values)) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
         if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     $allPanes = array();
     $recurJs = NULL;
     //tax rate from financialType
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled')));
     // build price set form.
     $buildPriceSet = FALSE;
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     // display tax amount on edit contribution page
     if ($invoicing && $this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) {
         $this->assign('totalTaxAmount', $this->_values['tax_amount']);
     }
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     if ($this->_mode) {
         if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) {
             if (!empty($this->_recurPaymentProcessors)) {
                 $buildRecurBlock = TRUE;
                 if ($this->_ppID) {
                     // ppID denotes a pledge payment.
                     foreach ($this->_paymentProcessors as $processor) {
                         if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
                             $buildRecurBlock = TRUE;
                             break;
                         }
                         $buildRecurBlock = FALSE;
                     }
                 }
                 if ($buildRecurBlock) {
                     CRM_Contribute_Form_Contribution_Main::buildRecur($this);
                     $this->setDefaults(array('is_recur' => 0));
                     $this->assign('buildRecurBlock', TRUE);
                     $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
                 }
             }
         }
     }
     foreach ($paneNames as $name => $type) {
         $allPanes[$name] = $this->generatePane($type, $defaults);
     }
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     // Check permissions for financial type first
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action);
     if (empty($financialTypes)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes, TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             // CRM-16451: set financial type of 'Price Set' in back office contribution
             // instead of selecting manually
             $financialTypeIds = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute', 'financial_type_id');
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value, " . json_encode($financialTypeIds) . ");"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     // if contribution is related to membership or participant freeze Financial Type, Amount
     if ($this->_id && isset($this->_values['tax_amount'])) {
         $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
             if ($totalAmount) {
                 $totalAmount->freeze();
             }
             $financialType->freeze();
             $this->assign('freezeFinancialType', TRUE);
         }
     }
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Example #15
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->addYesNo('is_monetary', ts('Paid Event'), NULL, NULL, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);"));
     //add currency element.
     $this->addCurrency('currency', ts('Currency'), FALSE);
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor();
     $this->assign('paymentProcessor', $paymentProcessor);
     $this->addEntityRef('payment_processor', ts('Payment Processor'), array('entity' => 'PaymentProcessor', 'multiple' => TRUE, 'select' => array('minimumInputLength' => 0)));
     // financial type
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() || CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         $this->addSelect('financial_type_id');
     } else {
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
         $this->addSelect('financial_type_id', array('context' => 'search', 'options' => $financialTypes));
     }
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);"));
     $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), FALSE);
     $this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'));
     $this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
     $this->add('text', 'fee_label', ts('Fee Label'));
     $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent');
     if (CRM_Utils_System::isNull($price)) {
         $this->assign('price', FALSE);
     } else {
         $this->assign('price', TRUE);
     }
     $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);"));
     $default = array($this->createElement('radio', NULL, NULL, NULL, 0));
     $this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id'));
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]"));
         // value
         $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
         $this->addRule("value[{$i}]", 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, 'default');
     $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);"));
     $discountSection = $this->get('discountSection');
     $this->assign('discountSection', $discountSection);
     // form fields of Discount sets
     $defaultOption = array();
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
         //the show hide blocks
         $showBlocks = 'discount_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
         } else {
             $_showHide->addShow($showBlocks);
         }
         //Increment by 1 of start date of previous end date.
         if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) {
             $end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
             if (!empty($this->_submitValues['discount_end_date'][$i + 1]) && empty($this->_submitValues['discount_start_date'][$i + 1])) {
                 list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days {$end_date}")));
             }
         }
         //Decrement by 1 of end date from next start date.
         if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i])) {
             $start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
             if (!empty($this->_submitValues['discount_start_date'][$i]) && empty($this->_submitValues['discount_end_date'][$i - 1])) {
                 list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days {$start_date}")));
             }
         }
         //discount name
         $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'));
         $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]"));
         //discount start date
         $this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));
         //discount end date
         $this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
     }
     $_showHide->addToTemplate();
     $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'crm-form-submit cancel'));
     $this->buildAmountLabel();
     parent::buildQuickForm();
 }
 /**
  * Check method testGetAvailableFinancialTypes()
  */
 public function testGetAvailableFinancialTypes()
 {
     $this->setACL();
     $this->setPermissions(array('view contributions of type Donation', 'view contributions of type Member Dues'));
     $types = array();
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
     $expectedResult = array(1 => "Donation", 2 => "Member Dues");
     $this->assertEquals($expectedResult, $types, 'Verify that only certain financial types can be retrieved');
     $this->setPermissions(array('view contributions of type Donation'));
     unset($expectedResult[2]);
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
     $this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available financial types');
 }
Example #17
0
 /**
  * Add all the elements shared between contribute search and advnaced search.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildSearchForm(&$form)
 {
     // Added contribution source
     $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'source'));
     CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE);
     $form->add('text', 'contribution_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
     $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
     // Adding select option for curreny type -- CRM-4711
     $form->add('select', 'contribution_currency_type', ts('Currency Type'), array('' => ts('- any -')) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', array('labelColumn' => 'name')), FALSE, array('class' => 'crm-select2'));
     // CRM-13848
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::VIEW);
     $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search', 'options' => $financialTypes));
     $form->add('select', 'contribution_page_id', ts('Contribution Page'), CRM_Contribute_PseudoConstant::contributionPage(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')));
     $form->addSelect('payment_instrument_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
     $form->add('select', 'contribution_pcp_made_through_id', ts('Personal Campaign Page'), CRM_Contribute_PseudoConstant::pcPage(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')));
     $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id');
     // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue).
     unset($statusValues['5'], $statusValues['6']);
     $form->add('select', 'contribution_status_id', ts('Contribution Status'), $statusValues, FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple'));
     // Add fields for thank you and receipt
     $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE);
     $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?'), TRUE);
     $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?'), TRUE);
     $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE);
     $form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE);
     // Add field for transaction ID search
     $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
     $form->addElement('text', 'invoice_id', ts("Invoice ID"));
     $form->addElement('text', 'contribution_check_number', ts('Check Number'));
     // Add field for pcp display in roll search
     $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'), TRUE);
     // Soft credit related fields
     $options = array('only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), 'both_related' => ts('Soft Credits with related Hard Credit'), 'both' => ts('Both'));
     $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2"));
     $form->addSelect('contribution_soft_credit_type_id', array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'context' => 'search'));
     // CRM-16713 - contribution search by premiums on 'Find Contribution' form.
     $form->add('select', 'contribution_product_id', ts('Premium'), CRM_Contribute_PseudoConstant::products(), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')));
     // Add all the custom searchable fields
     $contribution = array('Contribution');
     $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contribution);
     if ($groupDetails) {
         $form->assign('contributeGroupTree', $groupDetails);
         foreach ($groupDetails as $group) {
             foreach ($group['fields'] as $field) {
                 $fieldId = $field['id'];
                 $elementName = 'custom_' . $fieldId;
                 CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE);
             }
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'contribution_campaign_id');
     // Add batch select
     $batches = CRM_Contribute_PseudoConstant::batch();
     if (!empty($batches)) {
         $form->add('select', 'contribution_batch_id', ts('Batch Name'), array('' => ts('- any -')) + $batches, FALSE, array('class' => 'crm-select2'));
     }
     $form->assign('validCiviContribute', TRUE);
     $form->setDefaults(array('contribution_test' => 0));
     CRM_Contribute_BAO_ContributionRecur::recurringContribution($form);
 }
Example #18
0
 /**
  * Return an associative array of all price sets.
  *
  * @param bool $withInactive
  *   Whether or not to include inactive entries.
  * @param bool|string $extendComponentName name of the component like 'CiviEvent','CiviContribute'
  * @param string $column name of the column.
  *
  * @return array
  *   associative array of id => name
  */
 public static function getAssoc($withInactive = FALSE, $extendComponentName = FALSE, $column = 'title')
 {
     $query = "\n    SELECT\n       DISTINCT ( price_set_id ) as id, s.{$column}\n    FROM\n       civicrm_price_set s\n       INNER JOIN civicrm_price_field f ON f.price_set_id = s.id\n       INNER JOIN civicrm_price_field_value v ON v.price_field_id = f.id\n    WHERE\n       is_quick_config = 0 ";
     if (!$withInactive) {
         $query .= ' AND s.is_active = 1 ';
     }
     if (self::eventPriceSetDomainID()) {
         $query .= ' AND s.domain_id = ' . CRM_Core_Config::domainID();
     }
     $priceSets = array();
     if ($extendComponentName) {
         $componentId = CRM_Core_Component::getComponentID($extendComponentName);
         if (!$componentId) {
             return $priceSets;
         }
         $query .= " AND s.extends LIKE '%{$componentId}%' ";
     }
     // Check permissioned financial types
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialType, CRM_Core_Action::ADD);
     if ($financialType) {
         $types = implode(',', array_keys($financialType));
         $query .= ' AND s.financial_type_id IN (' . $types . ') AND v.financial_type_id IN (' . $types . ') ';
     } else {
         // Do not display any price sets
         $query .= " AND 0 ";
     }
     $query .= " GROUP BY s.id";
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $priceSets[$dao->id] = $dao->{$column};
     }
     return $priceSets;
 }
Example #19
0
 /**
  * Retrive the all values for given field id.
  *
  * @param int $fieldId
  *   Price_field_id.
  * @param array $values
  *   (reference ) to hold the values.
  * @param string $orderBy
  *   For order by, default weight.
  * @param bool|int $isActive is_active, default false
  *
  * @return array
  *
  */
 public static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE)
 {
     $sql = "SELECT cs.id FROM civicrm_price_set cs INNER JOIN civicrm_price_field cp ON cp.price_set_id = cs.id \n              WHERE cs.name IN ('default_contribution_amount', 'default_membership_type_amount') AND cp.id = {$fieldId} ";
     $setId = CRM_Core_DAO::singleValueQuery($sql);
     $fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
     $fieldValueDAO->price_field_id = $fieldId;
     if (!$setId) {
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
         $addWhere = "financial_type_id IN (0)";
         if (!empty($financialTypes)) {
             $addWhere = "financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
         }
         $fieldValueDAO->whereAdd($addWhere);
     }
     $fieldValueDAO->orderBy($orderBy, 'label');
     if ($isActive) {
         $fieldValueDAO->is_active = 1;
     }
     $fieldValueDAO->find();
     while ($fieldValueDAO->fetch()) {
         CRM_Core_DAO::storeValues($fieldValueDAO, $values[$fieldValueDAO->id]);
     }
     return $values;
 }
Example #20
0
 /**
  * Modifies $params array for filtering financial types.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  */
 public static function getAPILineItemParams(&$params)
 {
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
     if ($types && empty($params['financial_type_id'])) {
         $params['financial_type_id'] = array('IN' => array_keys($types));
     } elseif ($types) {
         if (is_array($params['financial_type_id'])) {
             $invalidFts = array_diff($params['financial_type_id'], array_keys($types));
         } elseif (!in_array($params['financial_type_id'], array_keys($types))) {
             $invalidFts = $params['financial_type_id'];
         }
         if ($invalidFts) {
             $params['financial_type_id'] = array('NOT IN' => $invalidFts);
         }
     } else {
         $params['financial_type_id'] = 0;
     }
 }
Example #21
0
 /**
  * Build the form object.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = TRUE;
         }
     }
     if ($form->_isPaidEvent) {
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         CRM_Event_Form_Registration::initEventFee($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
         $lineItem = array();
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
             foreach ($form->_values['line_items'] as $key => $value) {
                 $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
             }
         }
         if ($invoicing) {
             $form->assign('totalTaxAmount', $totalTaxAmount);
         }
         $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $value = current($value);
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, FALSE, array('class' => "crm-select2"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Utils_Array::value('fee', $form->_values) && CRM_Utils_Array::value('snippet', $_REQUEST) == CRM_Core_Smarty::PRINT_NOFORM) {
             $form->assign('isFTPermissionDenied', TRUE);
             return FALSE;
         }
         if ($form->_mode) {
             CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE);
         } elseif (!$form->_mode) {
             $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
             // Check permissions for financial type first
             if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
                 CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->_action);
             } else {
                 $financialTypes = CRM_Contribute_PseudoConstant::financialType();
             }
             $form->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes);
             $form->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
             $form->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
             // don't show transaction id in batch update mode
             $path = CRM_Utils_System::currentPath();
             $form->assign('showTransactionId', FALSE);
             if ($path != 'civicrm/contact/search/basic') {
                 $form->add('text', 'trxn_id', ts('Transaction ID'));
                 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                 $form->assign('showTransactionId', TRUE);
             }
             $status = CRM_Contribute_PseudoConstant::contributionStatus();
             // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('Cancelled', 'Failed', 'In Progress', 'Overdue', 'Refunded', 'Pending refund') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', 'contribution_status_id', ts('Payment Status'), $status);
             $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             $form->add('text', 'total_amount', ts('Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount'));
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign('paid', $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactId) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', TRUE);
         }
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
     $form->assign('hasPayment', $form->_paymentId);
 }
Example #22
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->_first = TRUE;
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
     // financial Type
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
     $financialOptions = array('options' => $financialTypes);
     if (!CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         $financialOptions['context'] = 'search';
     }
     $this->addSelect('financial_type_id', $financialOptions, TRUE);
     // name
     $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
     //CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     $this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']);
     $this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']);
     //Register schema which will be used for OnBehalOf and HonorOf profile Selector
     CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel', 'HouseholdModel'));
     // 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);"));
     //CRM-15787 - If applicable, register 'membership_1'
     $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
     $coreTypes = array('Contact', 'Organization');
     $entities[] = array('entity_name' => array('contact_1'), 'entity_type' => 'OrganizationModel');
     if ($member && $member['is_active']) {
         $coreTypes[] = 'Membership';
         $entities[] = array('entity_name' => array('membership_1'), 'entity_type' => 'MembershipModel');
     }
     $allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType::subTypes('Organization'));
     $allowSubTypes = array();
     $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
     $options = array();
     $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
     $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
     $this->addGroup($options, 'is_for_organization', '');
     $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50));
     // 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 confirmation page enabled?
     $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
     // is this page shareable through social media ?
     $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
     // 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'), array('maxlength' => 255, 'size' => 45));
     $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
     $this->addSelect('soft_credit_types', array('label' => ts('Honor Types'), 'entity' => 'ContributionSoft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'class' => 'huge'));
     $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'));
     $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
     $allowSubTypes = array();
     $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
     if (!empty($this->_submitValues['honor_block_is_active'])) {
         $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
         $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
     }
     // 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'), $this);
     parent::buildQuickForm();
 }
Example #23
0
 /**
  * @param int $contactId
  * @param bool $includeSoftCredit
  *
  * @return null|string
  */
 public static function contributionCount($contactId, $includeSoftCredit = TRUE)
 {
     if (!$contactId) {
         return 0;
     }
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     $additionalWhere = " AND contribution.financial_type_id IN (0)";
     $liWhere = " AND i.financial_type_id IN (0)";
     if (!empty($financialTypes)) {
         $additionalWhere = " AND contribution.financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
         $liWhere = " AND i.financial_type_id NOT IN (" . implode(',', array_keys($financialTypes)) . ")";
     }
     $contactContributionsSQL = "\n      SELECT contribution.id AS id\n      FROM civicrm_contribution contribution\n      LEFT JOIN civicrm_line_item i ON i.contribution_id = contribution.id AND i.entity_table = 'civicrm_contribution' {$liWhere}\n      WHERE contribution.is_test = 0 AND contribution.contact_id = {$contactId}\n      {$additionalWhere}\n      AND i.id IS NULL";
     $contactSoftCreditContributionsSQL = "\n      SELECT contribution.id\n      FROM civicrm_contribution contribution INNER JOIN civicrm_contribution_soft softContribution\n      ON ( contribution.id = softContribution.contribution_id )\n      WHERE contribution.is_test = 0 AND softContribution.contact_id = {$contactId} ";
     $query = "SELECT count( x.id ) count FROM ( ";
     $query .= $contactContributionsSQL;
     if ($includeSoftCredit) {
         $query .= " UNION ";
         $query .= $contactSoftCreditContributionsSQL;
     }
     $query .= ") x";
     return CRM_Core_DAO::singleValueQuery($query);
 }
Example #24
0
 /**
  * Browse all price set fields.
  *
  * @return void
  */
 public function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
     }
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
     // fkey is sid
     $priceFieldBAO->price_set_id = $this->_sid;
     $priceFieldBAO->orderBy('weight, label');
     $priceFieldBAO->find();
     // display taxTerm for priceFields
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $getTaxDetails = FALSE;
     $taxRate = CRM_Core_PseudoConstant::getTaxRates();
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     while ($priceFieldBAO->fetch()) {
         $priceField[$priceFieldBAO->id] = array();
         CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
         // get price if it's a text field
         if ($priceFieldBAO->html_type == 'Text') {
             $optionValues = array();
             $params = array('price_field_id' => $priceFieldBAO->id);
             CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues);
             $financialTypeId = $optionValues['financial_type_id'];
             if (!array_key_exists($financialTypeId, $financialTypes)) {
                 unset($priceField[$priceFieldBAO->id]);
                 continue;
             }
             $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
             if ($invoicing && isset($taxRate[$financialTypeId])) {
                 $priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId];
                 $getTaxDetails = TRUE;
             }
             if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate']);
                 $priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
             }
         }
         $action = array_sum(array_keys(self::actionLinks()));
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
         } else {
             if ($priceFieldBAO->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['active_on'] = '';
         }
         if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['expire_on'] = '';
         }
         // need to translate html types from the db
         $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
         $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
         $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('getTaxDetails', $getTaxDetails);
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
     $filter = "price_set_id = {$this->_sid}";
     CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }
Example #25
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $urlParams = 'civicrm/admin/contribute/premium';
     if ($this->_action & CRM_Core_Action::DELETE) {
         $session = CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
         $session->pushUserContext($url);
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject, '', '', 'GET')) {
             $dao = new CRM_Contribute_DAO_PremiumsProduct();
             $dao->id = $this->_pid;
             $dao->delete();
             CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success');
             CRM_Utils_System::redirect($url);
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, NULL, $this->_pid);
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Done with Preview'), 'isDefault' => TRUE)));
         return;
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
     $session->pushUserContext($url);
     $this->add('select', 'product_id', ts('Select the Product') . ' ', $this->_products, TRUE);
     $this->addElement('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PremiumsProduct', 'weight'));
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $premiumFinancialType = array();
     CRM_Core_PseudoConstant::populate($premiumFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 8');
     $costFinancialType = array();
     CRM_Core_PseudoConstant::populate($costFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, 'account_relationship = 7');
     $productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
     foreach ($financialType as $key => $financialTypeName) {
         if (!in_array($key, $productFinancialType)) {
             unset($financialType[$key]);
         }
     }
     // Check permissioned financial types
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialType, CRM_Core_Action::ADD);
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
     $this->addRule('weight', ts('Please enter integer value for weight'), 'integer');
     $session->pushUserContext(CRM_Utils_System::url($urlParams, 'action=update&reset=1&id=' . $this->_id));
     if ($this->_single) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     } else {
         parent::buildQuickForm();
     }
 }
Example #26
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'financial_type_id');
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::UPDATE);
         if (!array_key_exists($finTypeId, $financialTypes)) {
             CRM_Core_Error::fatal(ts("You do not have permission to access this page"));
         }
     }
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete')), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return NULL;
     } else {
         $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
         // lets trim all the whitespace
         $this->applyFilter('__ALL__', 'trim');
         // hidden Option Id for validation use
         $this->add('hidden', 'optionId', $this->_oid);
         // Needed for i18n dialog
         $this->assign('optionId', $this->_oid);
         //hidden field ID for validation use
         $this->add('hidden', 'fieldId', $this->_fid);
         // label
         $this->add('text', 'label', ts('Option Label'), NULL, TRUE);
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
         } elseif ($this->_action == CRM_Core_Action::ADD || $this->_action == CRM_Core_Action::VIEW) {
             $this->_sid = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'price_set_id', 'id');
         }
         $this->isEvent = FALSE;
         $extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
         $this->assign('showMember', FALSE);
         if ($memberComponentId == $extendComponentId) {
             $this->assign('showMember', TRUE);
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $this->add('select', 'membership_type_id', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, array('onClick' => "calculateRowValues( );"));
             $this->add('text', 'membership_num_terms', ts('Number of Terms'), $attributes['membership_num_terms']);
         } else {
             $allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
             $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
             if (in_array($eventComponentId, $allComponents)) {
                 $this->isEvent = TRUE;
                 // count
                 $this->add('text', 'count', ts('Participant Count'));
                 $this->addRule('count', ts('Please enter a valid Max Participants.'), 'positiveInteger');
                 $this->add('text', 'max_value', ts('Max Participants'));
                 $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             }
         }
         //Financial Type
         $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
         if (count($financialType)) {
             $this->assign('financialType', $financialType);
         }
         $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialType, TRUE);
         //CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id' );
         // FIX ME: duplicate rule?
         /*
               $this->addRule( 'label',
               ts('Duplicate option label.'),
               'optionExists',
               array( 'CRM_Core_DAO_OptionValue', $this->_oid, $this->_ogId, 'label' ) );
         */
         // value
         $this->add('text', 'amount', ts('Option Amount'), NULL, TRUE);
         // the above value is used directly by QF, so the value has to be have a rule
         // please check with Lobo before u comment this
         $this->registerRule('amount', 'callback', 'money', 'CRM_Utils_Rule');
         $this->addRule('amount', ts('Please enter a monetary value for this field.'), 'money');
         $this->add('textarea', 'description', ts('Description'));
         $this->add('textarea', 'help_pre', ts('Pre Option Help'));
         $this->add('textarea', 'help_post', ts('Post Option Help'));
         // weight
         $this->add('text', 'weight', ts('Order'), NULL, TRUE);
         $this->addRule('weight', ts('is a numeric field'), 'numeric');
         // is active ?
         $this->add('checkbox', 'is_active', ts('Active?'));
         //is default
         $this->add('checkbox', 'is_default', ts('Default'));
         if ($this->_fid) {
             //hide the default checkbox option for text field
             $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
             $this->assign('hideDefaultOption', FALSE);
             if ($htmlType == 'Text') {
                 $this->assign('hideDefaultOption', TRUE);
             }
         }
         // add buttons
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Save')), array('type' => 'cancel', 'name' => ts('Cancel'))));
         // if view mode pls freeze it with the done button.
         if ($this->_action & CRM_Core_Action::VIEW) {
             $this->freeze();
             $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'isDefault' => TRUE)));
         }
     }
     $this->addFormRule(array('CRM_Price_Form_Option', 'formRule'), $this);
 }
Example #27
0
 /**
  * @param null $context
  *
  * @return array
  */
 public function &summaryContribution($context = NULL)
 {
     list($innerselect, $from, $where, $having) = $this->query(TRUE);
     // hack $select
     $select = "\nSELECT COUNT( conts.total_amount ) as total_count,\n       SUM(   conts.total_amount ) as total_amount,\n       AVG(   conts.total_amount ) as total_avg,\n       conts.total_amount          as amount,\n       conts.currency              as currency";
     if ($this->_permissionWhereClause) {
         $where .= " AND " . $this->_permissionWhereClause;
     }
     if ($context == 'search') {
         $where .= " AND contact_a.is_deleted = 0 ";
     }
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     if (!empty($financialTypes)) {
         $where .= " AND civicrm_contribution.financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ") AND li.id IS NULL";
         $from .= " LEFT JOIN civicrm_line_item li\n                      ON civicrm_contribution.id = li.contribution_id AND\n                         li.entity_table = 'civicrm_contribution' AND li.financial_type_id NOT IN (" . implode(',', array_keys($financialTypes)) . ") ";
     } else {
         $where .= " AND civicrm_contribution.financial_type_id IN (0)";
     }
     // make sure contribution is completed - CRM-4989
     $completedWhere = $where . " AND civicrm_contribution.contribution_status_id = 1 ";
     $summary = array();
     $summary['total'] = array();
     $summary['total']['count'] = $summary['total']['amount'] = $summary['total']['avg'] = "n/a";
     $innerQuery = "SELECT civicrm_contribution.total_amount, COUNT(civicrm_contribution.total_amount) as civicrm_contribution_total_amount_count,\n      civicrm_contribution.currency {$from} {$completedWhere}";
     $query = "{$select} FROM (\n      {$innerQuery} GROUP BY civicrm_contribution.id\n    ) as conts\n    GROUP BY currency";
     $dao = CRM_Core_DAO::executeQuery($query);
     $summary['total']['count'] = 0;
     $summary['total']['amount'] = $summary['total']['avg'] = array();
     while ($dao->fetch()) {
         $summary['total']['count'] += $dao->total_count;
         $summary['total']['amount'][] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
         $summary['total']['avg'][] = CRM_Utils_Money::format($dao->total_avg, $dao->currency);
     }
     $orderBy = 'ORDER BY civicrm_contribution_total_amount_count DESC';
     $groupBy = 'GROUP BY currency, civicrm_contribution.total_amount';
     $modeSQL = "{$select}, conts.civicrm_contribution_total_amount_count as civicrm_contribution_total_amount_count FROM ({$innerQuery}\n    {$groupBy} {$orderBy}) as conts\n    GROUP BY currency";
     $summary['total']['mode'] = CRM_Contribute_BAO_Contribution::computeStats('mode', $modeSQL);
     $medianSQL = "{$from} {$completedWhere}";
     $summary['total']['median'] = CRM_Contribute_BAO_Contribution::computeStats('median', $medianSQL, 'civicrm_contribution');
     $summary['total']['currencyCount'] = count($summary['total']['median']);
     if (!empty($summary['total']['amount'])) {
         $summary['total']['amount'] = implode(',&nbsp;', $summary['total']['amount']);
         $summary['total']['avg'] = implode(',&nbsp;', $summary['total']['avg']);
         $summary['total']['mode'] = implode(',&nbsp;', $summary['total']['mode']);
         $summary['total']['median'] = implode(',&nbsp;', $summary['total']['median']);
     } else {
         $summary['total']['amount'] = $summary['total']['avg'] = $summary['total']['median'] = 0;
     }
     // soft credit summary
     if (CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) {
         $softCreditWhere = "{$completedWhere} AND civicrm_contribution_soft.id IS NOT NULL";
         $query = "\n        {$select} FROM (\n          SELECT civicrm_contribution_soft.amount as total_amount, civicrm_contribution_soft.currency {$from} {$softCreditWhere}\n          GROUP BY civicrm_contribution_soft.id\n        ) as conts\n        GROUP BY currency";
         $dao = CRM_Core_DAO::executeQuery($query);
         $summary['soft_credit']['count'] = 0;
         $summary['soft_credit']['amount'] = $summary['soft_credit']['avg'] = array();
         while ($dao->fetch()) {
             $summary['soft_credit']['count'] += $dao->total_count;
             $summary['soft_credit']['amount'][] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
             $summary['soft_credit']['avg'][] = CRM_Utils_Money::format($dao->total_avg, $dao->currency);
         }
         if (!empty($summary['soft_credit']['amount'])) {
             $summary['soft_credit']['amount'] = implode(',&nbsp;', $summary['soft_credit']['amount']);
             $summary['soft_credit']['avg'] = implode(',&nbsp;', $summary['soft_credit']['avg']);
         } else {
             $summary['soft_credit']['amount'] = $summary['soft_credit']['avg'] = 0;
         }
     }
     // hack $select
     //@todo  - this could be one query using the IF in mysql - eg
     //  SELECT sum(total_completed), sum(count_completed), sum(count_cancelled), sum(total_cancelled) FROM (
     //   SELECT civicrm_contribution.total_amount, civicrm_contribution.currency  ,
     //  IF(civicrm_contribution.contribution_status_id = 1, 1, 0 ) as count_completed,
     //  IF(civicrm_contribution.contribution_status_id = 1, total_amount, 0 ) as total_completed,
     //  IF(civicrm_contribution.cancel_date IS NOT NULL = 1, 1, 0 ) as count_cancelled,
     //  IF(civicrm_contribution.cancel_date IS NOT NULL = 1, total_amount, 0 ) as total_cancelled
     // FROM civicrm_contact contact_a
     //  LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id
     // WHERE  ( ... where clause....
     // AND (civicrm_contribution.cancel_date IS NOT NULL OR civicrm_contribution.contribution_status_id = 1)
     //  ) as conts
     $select = "\nSELECT COUNT( conts.total_amount ) as cancel_count,\n       SUM(   conts.total_amount ) as cancel_amount,\n       AVG(   conts.total_amount ) as cancel_avg,\n       conts.currency              as currency";
     $where .= " AND civicrm_contribution.cancel_date IS NOT NULL ";
     if ($context == 'search') {
         $where .= " AND contact_a.is_deleted = 0 ";
     }
     $query = "{$select} FROM (\n      SELECT civicrm_contribution.total_amount, civicrm_contribution.currency {$from} {$where}\n      GROUP BY civicrm_contribution.id\n    ) as conts\n    GROUP BY currency";
     $dao = CRM_Core_DAO::executeQuery($query);
     if ($dao->N <= 1) {
         if ($dao->fetch()) {
             $summary['cancel']['count'] = $dao->cancel_count;
             $summary['cancel']['amount'] = $dao->cancel_amount;
             $summary['cancel']['avg'] = $dao->cancel_avg;
         }
     } else {
         $summary['cancel']['count'] = 0;
         $summary['cancel']['amount'] = $summary['cancel']['avg'] = array();
         while ($dao->fetch()) {
             $summary['cancel']['count'] += $dao->cancel_count;
             $summary['cancel']['amount'][] = CRM_Utils_Money::format($dao->cancel_amount, $dao->currency);
             $summary['cancel']['avg'][] = CRM_Utils_Money::format($dao->cancel_avg, $dao->currency);
         }
         $summary['cancel']['amount'] = implode(',&nbsp;', $summary['cancel']['amount']);
         $summary['cancel']['avg'] = implode(',&nbsp;', $summary['cancel']['avg']);
     }
     return $summary;
 }
Example #28
0
 /**
  * Build an array of available membership types.
  *
  * @param CRM_Core_Form $form
  * @param array $membershipTypeID
  * @param bool $activeOnly
  *   Do we only want active ones?
  *   (probably this should default to TRUE but as a newly added parameter we are leaving default b
  *   behaviour unchanged).
  *
  * @return array
  */
 public static function buildMembershipTypeValues(&$form, $membershipTypeID = array(), $activeOnly = FALSE)
 {
     $whereClause = " WHERE domain_id = " . CRM_Core_Config::domainID();
     $membershipTypeIDS = (array) $membershipTypeID;
     if ($activeOnly) {
         $whereClause .= " AND is_active = 1 ";
     }
     if (!empty($membershipTypeIDS)) {
         $allIDs = implode(',', $membershipTypeIDS);
         $whereClause .= " AND id IN ( {$allIDs} )";
     }
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
     if ($financialTypes) {
         $whereClause .= " AND financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
     } else {
         $whereClause .= " AND financial_type_id IN (0)";
     }
     $query = "\nSELECT *\nFROM   civicrm_membership_type\n       {$whereClause};\n";
     $dao = CRM_Core_DAO::executeQuery($query);
     $membershipTypeValues = array();
     $membershipTypeFields = array('id', 'minimum_fee', 'name', 'is_active', 'description', 'financial_type_id', 'auto_renew', 'member_of_contact_id', 'relationship_type_id', 'relationship_direction', 'max_related', 'duration_unit', 'duration_interval');
     while ($dao->fetch()) {
         $membershipTypeValues[$dao->id] = array();
         foreach ($membershipTypeFields as $mtField) {
             $membershipTypeValues[$dao->id][$mtField] = $dao->{$mtField};
         }
     }
     $dao->free();
     CRM_Utils_Hook::membershipTypeValues($form, $membershipTypeValues);
     if (is_numeric($membershipTypeID) && $membershipTypeID > 0) {
         return $membershipTypeValues[$membershipTypeID];
     } else {
         return $membershipTypeValues;
     }
 }
Example #29
0
/**
 * Delete an existing LineItem.
 *
 * This method is used to delete any existing LineItem given its id.
 *
 * @param array $params
 *   Array containing id of the group to be deleted.
 *
 * @return array
 *   API result array
 */
function civicrm_api3_line_item_delete($params)
{
    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) {
        CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, CRM_Core_Action::DELETE);
        if (empty($params['financial_type_id'])) {
            $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], 'financial_type_id');
        }
        if (!in_array($params['financial_type_id'], array_keys($types))) {
            throw new API_Exception('You do not have permission to delete this line item');
        }
    }
    return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}