/** */ public function __construct() { $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, 'no_repeat' => TRUE), 'first_name' => array('title' => ts('First Name'), 'no_repeat' => TRUE), 'last_name' => array('title' => ts('Last Name'), 'no_repeat' => TRUE), 'contact_type' => array('title' => ts('Contact Type'), 'no_repeat' => TRUE), 'contact_sub_type' => array('title' => ts('Contact Subtype'), 'no_repeat' => TRUE), 'do_not_email' => array('title' => ts('Do Not Email'), 'no_repeat' => TRUE), 'is_opt_out' => array('title' => ts('No Bulk Email(Is Opt Out)'), 'no_repeat' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE, 'csv_display' => TRUE, 'title' => ts('Contact ID'))), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Donor Email'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Donor Phone'), 'default' => TRUE, 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'first_donation' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('first_donation_date' => array('title' => ts('First Contribution Date'), 'base_field' => 'receive_date', 'no_repeat' => TRUE), 'first_donation_amount' => array('title' => ts('First Contribution Amount'), 'base_field' => 'total_amount', 'no_repeat' => TRUE))), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contribution_id' => array('name' => 'id', 'no_display' => TRUE, 'required' => TRUE, 'csv_display' => TRUE, 'title' => ts('Contribution ID')), 'financial_type_id' => array('title' => ts('Financial Type'), 'default' => TRUE), 'contribution_recur_id' => array('title' => ts('Recurring Contribution Id'), 'name' => 'contribution_recur_id', 'required' => TRUE, 'no_display' => TRUE, 'csv_display' => TRUE), 'contribution_status_id' => array('title' => ts('Contribution Status')), 'payment_instrument_id' => array('title' => ts('Payment Type')), 'contribution_source' => array('name' => 'source', 'title' => ts('Contribution Source')), 'currency' => array('required' => TRUE, 'no_display' => TRUE), 'trxn_id' => NULL, 'receive_date' => array('default' => TRUE), 'receipt_date' => NULL, 'fee_amount' => NULL, 'net_amount' => NULL, 'total_amount' => array('title' => ts('Amount'), 'required' => TRUE)), 'filters' => array('receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::financialType()), '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), 'payment_instrument_id' => array('title' => ts('Payment Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::paymentInstrument()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array(1)), 'total_amount' => array('title' => ts('Contribution Amount'))), 'grouping' => 'contri-fields'), 'civicrm_product' => array('dao' => 'CRM_Contribute_DAO_Product', 'fields' => array('product_name' => array('name' => 'name', 'title' => ts('Premium')))), 'civicrm_contribution_product' => array('dao' => 'CRM_Contribute_DAO_ContributionProduct', 'fields' => array('product_id' => array('no_display' => TRUE), 'product_option' => array('title' => ts('Premium Option')), 'fulfilled_date' => array('title' => ts('Premium Fulfilled Date')), 'contribution_id' => array('no_display' => TRUE))), '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')))), 'civicrm_membership' => array('dao' => 'CRM_Member_DAO_Membership', 'fields' => array('membership_type_id' => array('title' => ts('Membership Type'), 'required' => TRUE, 'no_repeat' => TRUE), 'membership_start_date' => array('title' => ts('Start Date'), 'default' => TRUE), 'membership_end_date' => array('title' => ts('End Date'), 'default' => TRUE), 'join_date' => array('title' => ts('Join Date'), 'default' => TRUE), 'source' => array('title' => ts('Membership Source'))), 'filters' => array('join_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'membership_start_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'membership_end_date' => array('operatorType' => CRM_Report_Form::OP_DATE), 'owner_membership_id' => array('title' => ts('Membership Owner ID'), 'operatorType' => CRM_Report_Form::OP_INT), 'tid' => array('name' => 'membership_type_id', 'title' => ts('Membership Types'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Member_PseudoConstant::membershipType())), 'grouping' => 'member-fields'), 'civicrm_membership_status' => array('dao' => 'CRM_Member_DAO_MembershipStatus', 'alias' => 'mem_status', 'fields' => array('membership_status_name' => array('name' => 'name', 'title' => ts('Membership Status'), 'default' => TRUE)), 'filters' => array('sid' => array('name' => 'id', 'title' => ts('Membership Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'))), 'grouping' => 'member-fields'), '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 ($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->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign')); } $this->_currencyColumn = 'civicrm_contribution_currency'; parent::__construct(); }
/** */ 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_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_Contribute_PseudoConstant::financialType(), '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 Instrument')), 'receive_date' => array('title' => ts('Receive Date'))), '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); $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign')); } $this->_currencyColumn = 'civicrm_contribution_currency'; parent::__construct(); }
/** * Retrieve records. */ public static function getBatchList() { $sortMapper = array(0 => 'batch.title', 1 => 'batch.type_id', 2 => '', 3 => 'batch.total', 4 => 'batch.status_id', 5 => ''); $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL; $params = $_REQUEST; if ($sort && $sortOrder) { $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = $offset / $rowCount + 1; $params['rp'] = $rowCount; if ($context != 'financialBatch') { // data entry status batches $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name'); } $params['context'] = $context; // get batch list $batches = CRM_Batch_BAO_Batch::getBatchListSelector($params); $iFilteredTotal = $iTotal = $params['total']; if ($context == 'financialBatch') { $selectorElements = array('check', 'batch_name', 'payment_instrument', 'item_count', 'total', 'status', 'created_by', 'links'); } else { $selectorElements = array('batch_name', 'type', 'item_count', 'total', 'status', 'created_by', 'links'); } CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }
function postProcess() { $batchIds = array(); foreach ($_POST as $key => $value) { if (substr($key, 0, 6) == "check_") { $batch = explode("_", $key); $batchIds[] = $batch[1]; } } if (!empty($_POST['batch_update'])) { CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']); } }
/** * 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(); }
/** * Process the form after the input has been submitted and validated. * * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $params['actualBatchTotal'] = 0; // get the profile information $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate'); if (in_array($this->_batchInfo['type_id'], array($batchTypes['Pledge Payment'], $batchTypes['Contribution']))) { $this->processContribution($params); } elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) { $this->processMembership($params); } // update batch to close status $paramValues = array('id' => $this->_batchId, 'status_id' => CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name'), 'total' => $params['actualBatchTotal']); CRM_Batch_BAO_Batch::create($paramValues); // set success status CRM_Core_Session::setStatus("", ts("Batch Processed."), "success"); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1')); }
/** * @param $rows */ public function alterDisplay(&$rows) { // custom code to alter rows $checkList = array(); $entryFound = FALSE; $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); $batches = CRM_Batch_BAO_Batch::getBatches(); //altering the csv display adding additional fields if ($this->_outputMode == 'csv') { foreach ($this->_columns as $tableName => $table) { if (array_key_exists('fields', $table)) { foreach ($table['fields'] as $fieldName => $field) { if (!empty($field['csv_display']) && !empty($field['no_display'])) { $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field); $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field); } } } } } // allow repeat for first donation amount and date in csv $fAmt = ''; $fDate = ''; foreach ($rows as $rowNum => $row) { if ($this->_outputMode == 'csv') { if (array_key_exists('civicrm_contact_id', $row)) { if ($contactId = $row['civicrm_contact_id']) { if ($rowNum == 0) { $pcid = $contactId; $fAmt = $row['first_donation_first_donation_amount']; $fDate = $row['first_donation_first_donation_date']; } else { if ($pcid == $contactId) { $rows[$rowNum]['first_donation_first_donation_amount'] = $fAmt; $rows[$rowNum]['first_donation_first_donation_date'] = $fDate; $pcid = $contactId; } else { $fAmt = $row['first_donation_first_donation_amount']; $fDate = $row['first_donation_first_donation_date']; $pcid = $contactId; } } } } } if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { $repeatFound = FALSE; $display_flag = NULL; if (array_key_exists('civicrm_contact_id', $row)) { if ($cid = $row['civicrm_contact_id']) { if ($rowNum == 0) { $prev_cid = $cid; } else { if ($prev_cid == $cid) { $display_flag = 1; $prev_cid = $cid; } else { $display_flag = 0; $prev_cid = $cid; } } if ($display_flag) { foreach ($row as $colName => $colVal) { if (in_array($colName, $this->_noRepeats)) { unset($rows[$rowNum][$colName]); } } } $entryFound = TRUE; } } } if (array_key_exists('civicrm_membership_membership_type_id', $row)) { if ($value = $row['civicrm_membership_membership_type_id']) { $rows[$rowNum]['civicrm_membership_membership_type_id'] = CRM_Member_PseudoConstant::membershipType($value, FALSE); } $entryFound = TRUE; } if (!empty($row['civicrm_batch_batch_id'])) { $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Utils_Array::value($row['civicrm_batch_batch_id'], $batches); $entryFound = TRUE; } if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); } $entryFound = TRUE; } if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); } $entryFound = TRUE; } // convert donor sort name to link if (array_key_exists('civicrm_contact_sort_name', $row) && !empty($rows[$rowNum]['civicrm_contact_sort_name']) && array_key_exists('civicrm_contact_id', $row)) { $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts('View Contact Summary for this Contact.'); } if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) { $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) { $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; $entryFound = TRUE; } if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && CRM_Core_Permission::check('access CiviContribute')) { $url = CRM_Utils_System::url('civicrm/contact/view/contribution', 'reset=1&id=' . $row['civicrm_contribution_contribution_id'] . '&cid=' . $row['civicrm_contact_id'] . '&action=view&context=contribution&selectedChild=contribute', $this->_absoluteUrl); $rows[$rowNum]['civicrm_contribution_total_amount_sum_link'] = $url; $rows[$rowNum]['civicrm_contribution_total_amount_sum_hover'] = ts('View Details of this Contribution.'); $entryFound = TRUE; } // convert campaign_id to campaign title if (array_key_exists('civicrm_contribution_campaign_id', $row)) { if ($value = $row['civicrm_contribution_campaign_id']) { $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; $entryFound = TRUE; } } $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'member/contributionDetail', 'List all contribution(s) for this ') ? TRUE : $entryFound; // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } $lastKey = $rowNum; } }
/** * @param $batchIds * @param string $fileName * * @throws CRM_Core_Exception */ public static function createActivityExport($batchIds, $fileName) { $session = CRM_Core_Session::singleton(); $values = array(); $params = array('id' => $batchIds); CRM_Batch_BAO_Batch::retrieve($params, $values); $createdBy = CRM_Contact_BAO_Contact::displayName($values['created_id']); $modifiedBy = CRM_Contact_BAO_Contact::displayName($values['modified_id']); $values['payment_instrument_id'] = ''; if (isset($values['payment_instrument_id'])) { $paymentInstrument = array_flip(CRM_Contribute_PseudoConstant::paymentInstrument('label')); $values['payment_instrument_id'] = array_search($values['payment_instrument_id'], $paymentInstrument); } $details = '<p>' . ts('Record:') . ' ' . $values['title'] . '</p><p>' . ts('Description:') . '</p><p>' . ts('Created By:') . " {$createdBy}" . '</p><p>' . ts('Created Date:') . ' ' . $values['created_date'] . '</p><p>' . ts('Last Modified By:') . ' ' . $modifiedBy . '</p><p>' . ts('Payment Instrument:') . ' ' . $values['payment_instrument_id'] . '</p>'; $subject = ''; if (!empty($values['total'])) { $subject .= ts('Total') . '[' . CRM_Utils_Money::format($values['total']) . '],'; } if (!empty($values['item_count'])) { $subject .= ' ' . ts('Count') . '[' . $values['item_count'] . '],'; } //create activity. $subject .= ' ' . ts('Batch') . '[' . $values['title'] . ']'; $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); $activityParams = array('activity_type_id' => array_search('Export Accounting Batch', $activityTypes), 'subject' => $subject, 'status_id' => 2, 'activity_date_time' => date('YmdHis'), 'source_contact_id' => $session->get('userID'), 'source_record_id' => $values['id'], 'target_contact_id' => $session->get('userID'), 'details' => $details, 'attachFile_1' => array('uri' => $fileName, 'type' => 'text/csv', 'location' => $fileName, 'upload_date' => date('YmdHis'))); CRM_Activity_BAO_Activity::create($activityParams); }
public static function getBatchSummary() { $batchID = CRM_Utils_Type::escape($_REQUEST['batchID'], 'String'); $params = array('id' => $batchID); $batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value); $batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID)); $batchSummary = array('created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id), 'status' => CRM_Core_OptionGroup::getLabel('batch_status', $batchInfo->status_id), 'description' => $batchInfo->description, 'payment_instrument' => CRM_Core_OptionGroup::getLabel('payment_instrument', $batchInfo->payment_instrument_id), 'item_count' => $batchInfo->item_count, 'assigned_item_count' => $batchTotals[$batchID]['item_count'], 'total' => CRM_Utils_Money::format($batchInfo->total), 'assigned_total' => CRM_Utils_Money::format($batchTotals[$batchID]['total']), 'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date)); CRM_Utils_JSON::output($batchSummary); }
/** * Process the form submission. * * @return void */ public function postProcess() { $session = CRM_Core_Session::singleton(); $ids = array(); $params = $this->exportValues(); $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id'); if ($this->_id) { $ids['batchID'] = $this->_id; $params['id'] = $this->_id; } // store the submitted values in an array $params['modified_date'] = date('YmdHis'); $params['modified_id'] = $session->get('userID'); if (!empty($params['created_date'])) { $params['created_date'] = CRM_Utils_Date::processDate($params['created_date']); } if ($this->_action & CRM_Core_Action::ADD) { $batchMode = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'mode_id', array('labelColumn' => 'name')); $params['mode_id'] = CRM_Utils_Array::key('Manual Batch', $batchMode); $params['status_id'] = CRM_Utils_Array::key('Open', $batchStatus); $params['created_date'] = date('YmdHis'); $params['created_id'] = $session->get('userID'); $details = "{$params['title']} batch has been created by this contact."; $activityTypeName = 'Create Batch'; } elseif ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { $details = "{$params['title']} batch has been edited by this contact."; if (CRM_Utils_Array::value($params['status_id'], $batchStatus) == 'Closed') { $details = "{$params['title']} batch has been closed by this contact."; } $activityTypeName = 'Edit Batch'; } $batch = CRM_Batch_BAO_Batch::create($params, $ids, 'financialBatch'); $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'); //create activity. $activityParams = array('activity_type_id' => array_search($activityTypeName, $activityTypes), 'subject' => $batch->title . "- Batch", 'status_id' => 2, 'priority_id' => 2, 'activity_date_time' => date('YmdHis'), 'source_contact_id' => $session->get('userID'), 'source_contact_qid' => $session->get('userID'), 'details' => $details); CRM_Activity_BAO_Activity::create($activityParams); $buttonName = $this->controller->getButtonName(); $context = $this->get("context"); if ($batch->title) { CRM_Core_Session::setStatus(ts("'%1' batch has been saved.", array(1 => $batch->title)), ts('Saved'), 'success'); } if ($buttonName == $this->getButtonName('next', 'new') & $this->_action == CRM_Core_Action::UPDATE) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/batch', "reset=1&action=add&context=1")); } elseif ($buttonName == $this->getButtonName('next', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/batch', "reset=1&action=add")); } elseif (CRM_Utils_Array::value($batch->status_id, $batchStatus) == 'Closed') { $session->replaceUserContext(CRM_Utils_System::url('civicrm', 'reset=1')); } elseif ($buttonName == $this->getButtonName('next') & $this->_action == CRM_Core_Action::UPDATE || $buttonName == $this->getButtonName('next') & $this->_action == CRM_Core_Action::ADD & $context == 1) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/financial/financialbatches', "reset=1&batchStatus=1")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/batchtransaction', "reset=1&bid={$batch->id}")); } }
/** * Makes an array of the batch's summary and returns array to parent getBatchSummary() function. * * @param $batchID * @param $params * * @return array */ public static function makeBatchSummary($batchID, $params) { $batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value); $batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID)); $batchSummary = array('created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id), 'status' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'status_id', $batchInfo->status_id), 'description' => $batchInfo->description, 'payment_instrument' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $batchInfo->payment_instrument_id), 'item_count' => $batchInfo->item_count, 'assigned_item_count' => $batchTotals[$batchID]['item_count'], 'total' => CRM_Utils_Money::format($batchInfo->total), 'assigned_total' => CRM_Utils_Money::format($batchTotals[$batchID]['total']), 'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date)); return $batchSummary; }
/** * Process the form after the input has been submitted and validated. */ public function postProcess() { if (!$this->_exportFormat) { $params = $this->exportValues(); $this->_exportFormat = $params['export_format']; } if ($this->_id) { $batchIds = array($this->_id); } elseif (!empty($this->_batchIds)) { $batchIds = explode(',', $this->_batchIds); } // Recalculate totals $totals = CRM_Batch_BAO_Batch::batchTotals($batchIds); // build batch params $session = CRM_Core_Session::singleton(); $batchParams['modified_date'] = date('YmdHis'); $batchParams['modified_id'] = $session->get('userID'); $batchParams['status_id'] = $this->_exportStatusId; $ids = array(); foreach ($batchIds as $batchId) { $batchParams['id'] = $ids['batchID'] = $batchId; // Update totals $batchParams = array_merge($batchParams, $totals[$batchId]); CRM_Batch_BAO_Batch::create($batchParams, $ids, 'financialBatch'); } CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat); }
/** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { $checkList = array(); $entryFound = FALSE; $display_flag = $prev_cid = $cid = 0; $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); $contributionPages = CRM_Contribute_PseudoConstant::contributionPage(); $batches = CRM_Batch_BAO_Batch::getBatches(); foreach ($rows as $rowNum => $row) { if (!empty($this->_noRepeats) && $this->_outputMode != 'csv') { // don't repeat contact details if its same as the previous row if (array_key_exists('civicrm_contact_id', $row)) { if ($cid = $row['civicrm_contact_id']) { if ($rowNum == 0) { $prev_cid = $cid; } else { if ($prev_cid == $cid) { $display_flag = 1; $prev_cid = $cid; } else { $display_flag = 0; $prev_cid = $cid; } } if ($display_flag) { foreach ($row as $colName => $colVal) { // Hide repeats in no-repeat columns, but not if the field's a section header if (in_array($colName, $this->_noRepeats) && !array_key_exists($colName, $this->_sections)) { unset($rows[$rowNum][$colName]); } } } $entryFound = TRUE; } } } if (CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) == 'Contribution') { unset($rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id']); } $entryFound = $this->alterDisplayContactFields($row, $rows, $rowNum, 'contribution/detail', ts('View Contribution Details')) ? TRUE : $entryFound; // convert donor sort name to link if (array_key_exists('civicrm_contact_sort_name', $row) && !empty($rows[$rowNum]['civicrm_contact_sort_name']) && array_key_exists('civicrm_contact_id', $row)) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact Summary for this Contact."); } if ($value = CRM_Utils_Array::value('civicrm_contribution_financial_type_id', $row)) { $rows[$rowNum]['civicrm_contribution_financial_type_id'] = $contributionTypes[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_status_id', $row)) { $rows[$rowNum]['civicrm_contribution_contribution_status_id'] = $contributionStatus[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_page_id', $row)) { $rows[$rowNum]['civicrm_contribution_contribution_page_id'] = $contributionPages[$value]; $entryFound = TRUE; } if ($value = CRM_Utils_Array::value('civicrm_contribution_payment_instrument_id', $row)) { $rows[$rowNum]['civicrm_contribution_payment_instrument_id'] = $paymentInstruments[$value]; $entryFound = TRUE; } if (!empty($row['civicrm_batch_batch_id'])) { $rows[$rowNum]['civicrm_batch_batch_id'] = CRM_Utils_Array::value($row['civicrm_batch_batch_id'], $batches); $entryFound = TRUE; } // Contribution amount links to viewing contribution if (($value = CRM_Utils_Array::value('civicrm_contribution_total_amount_sum', $row)) && CRM_Core_Permission::check('access CiviContribute')) { $url = CRM_Utils_System::url("civicrm/contact/view/contribution", "reset=1&id=" . $row['civicrm_contribution_contribution_id'] . "&cid=" . $row['civicrm_contact_id'] . "&action=view&context=contribution&selectedChild=contribute", $this->_absoluteUrl); $rows[$rowNum]['civicrm_contribution_total_amount_sum_link'] = $url; $rows[$rowNum]['civicrm_contribution_total_amount_sum_hover'] = ts("View Details of this Contribution."); $entryFound = TRUE; } // convert campaign_id to campaign title if (array_key_exists('civicrm_contribution_campaign_id', $row)) { if ($value = $row['civicrm_contribution_campaign_id']) { $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; $entryFound = TRUE; } } // soft credits if (array_key_exists('civicrm_contribution_soft_credits', $row) && 'Contribution' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) { $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency\nFROM civireport_contribution_detail_temp2\nWHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}"; $dao = CRM_Core_DAO::executeQuery($query); $string = ''; $separator = $this->_outputMode !== 'csv' ? "<br/>" : ' '; while ($dao->fetch()) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id); $string = $string . ($string ? $separator : '') . "<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a> " . CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency); } $rows[$rowNum]['civicrm_contribution_soft_credits'] = $string; } if (array_key_exists('civicrm_contribution_soft_credit_for', $row) && 'Soft Credit' == CRM_Utils_Array::value('civicrm_contribution_contribution_or_soft', $rows[$rowNum]) && array_key_exists('civicrm_contribution_contribution_id', $row)) { $query = "\nSELECT civicrm_contact_id, civicrm_contact_sort_name\nFROM civireport_contribution_detail_temp1\nWHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}"; $dao = CRM_Core_DAO::executeQuery($query); $string = ''; while ($dao->fetch()) { $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $dao->civicrm_contact_id); $string = $string . "\n<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a>"; } $rows[$rowNum]['civicrm_contribution_soft_credit_for'] = $string; } // CRM-18312 - hide 'contribution_or_soft' column if unchecked. if (!empty($this->noDisplayContributionOrSoftColumn)) { unset($rows[$rowNum]['civicrm_contribution_contribution_or_soft']); unset($this->_columnHeaders['civicrm_contribution_contribution_or_soft']); } //convert soft_credit_type_id into label if (array_key_exists('civicrm_contribution_soft_soft_credit_type_id', $rows[$rowNum])) { $rows[$rowNum]['civicrm_contribution_soft_soft_credit_type_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionSoft', 'soft_credit_type_id', $row['civicrm_contribution_soft_soft_credit_type_id']); } $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'contribute/detail', 'List all contribution(s) for this ') ? TRUE : $entryFound; // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } $lastKey = $rowNum; } }
/** * Process the form submission. */ public function postProcess() { $params = $this->controller->exportValues($this->_name); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_Session::setStatus("", ts("Batch Deleted"), "success"); CRM_Batch_BAO_Batch::deleteBatch($this->_id); return; } if ($this->_id) { $params['id'] = $this->_id; } else { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = CRM_Utils_Date::processDate(date("Y-m-d"), date("H:i:s")); } // always create with data entry status $params['status_id'] = CRM_Core_OptionGroup::getValue('batch_status', 'Data Entry', 'name'); $batch = CRM_Batch_BAO_Batch::create($params); // redirect to batch entry page. $session = CRM_Core_Session::singleton(); if ($this->_action & CRM_Core_Action::ADD) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1&action=add")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/batch/entry', "id={$batch->id}&reset=1")); } }
/** * Create all financial accounts entry. * * @param array $params * Contribution object, line item array and params for trxn. * * * @param array $financialTrxnValues * * @return null|object */ public static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL) { $skipRecords = $update = $return = $isRelatedId = FALSE; $additionalParticipantId = array(); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); if (CRM_Utils_Array::value('contribution_mode', $params) == 'participant') { $entityId = $params['participant_id']; $entityTable = 'civicrm_participant'; $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId); } elseif (!empty($params['membership_id'])) { //so far $params['membership_id'] should only be set coming in from membershipBAO::create so the situation where multiple memberships // are created off one contribution should be handled elsewhere $entityId = $params['membership_id']; $entityTable = 'civicrm_membership'; } else { $entityId = $params['contribution']->id; $entityTable = 'civicrm_contribution'; } if (CRM_Utils_Array::value('contribution_mode', $params) == 'membership') { $isRelatedId = TRUE; } $entityID[] = $entityId; if (!empty($additionalParticipantId)) { $entityID += $additionalParticipantId; } // prevContribution appears to mean - original contribution object- ie copy of contribution from before the update started that is being updated if (empty($params['prevContribution'])) { $entityID = NULL; } else { $update = TRUE; } $statusId = $params['contribution']->contribution_status_id; // CRM-13964 partial payment if (CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Partially paid', $contributionStatuses) && !empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) { $partialAmtPay = $params['partial_amount_pay']; $partialAmtTotal = $params['partial_payment_total']; $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $fromFinancialAccountId = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); $params['total_amount'] = $partialAmtPay; $balanceTrxnInfo = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($params['contribution']->id, $params['financial_type_id']); if (empty($balanceTrxnInfo['trxn_id'])) { // create new balance transaction record $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); $balanceTrxnParams['total_amount'] = $partialAmtTotal; $balanceTrxnParams['to_financial_account_id'] = $toFinancialAccount; $balanceTrxnParams['contribution_id'] = $params['contribution']->id; $balanceTrxnParams['trxn_date'] = !empty($params['contribution']->receive_date) ? $params['contribution']->receive_date : date('YmdHis'); $balanceTrxnParams['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params); $balanceTrxnParams['net_amount'] = CRM_Utils_Array::value('net_amount', $params); $balanceTrxnParams['currency'] = $params['contribution']->currency; $balanceTrxnParams['trxn_id'] = $params['contribution']->trxn_id; $balanceTrxnParams['status_id'] = $statusId; $balanceTrxnParams['payment_instrument_id'] = $params['contribution']->payment_instrument_id; $balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params); if (!empty($params['payment_processor'])) { $balanceTrxnParams['payment_processor_id'] = $params['payment_processor']; } $financialTxn = CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams); } } // build line item array if its not set in $params if (empty($params['line_item']) || $additionalParticipantId) { CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable), $isRelatedId); } if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Failed', $contributionStatuses) && !(CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses) && !$params['contribution']->is_pay_later)) { $skipRecords = TRUE; $pendingStatus = array(array_search('Pending', $contributionStatuses), array_search('In Progress', $contributionStatuses)); if (in_array(CRM_Utils_Array::value('contribution_status_id', $params), $pendingStatus)) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); } elseif (!empty($params['payment_processor'])) { $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id'); } elseif (!empty($params['payment_instrument_id'])) { $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['payment_instrument_id']); } else { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); $queryParams = array(1 => array($relationTypeId, 'Integer')); $params['to_financial_account_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams); } $totalAmount = CRM_Utils_Array::value('total_amount', $params); if (!isset($totalAmount) && !empty($params['prevContribution'])) { $totalAmount = $params['total_amount'] = $params['prevContribution']->total_amount; } //build financial transaction params $trxnParams = array('contribution_id' => $params['contribution']->id, 'to_financial_account_id' => $params['to_financial_account_id'], 'trxn_date' => !empty($params['contribution']->receive_date) ? $params['contribution']->receive_date : date('YmdHis'), 'total_amount' => $totalAmount, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'net_amount' => CRM_Utils_Array::value('net_amount', $params, $totalAmount), 'currency' => $params['contribution']->currency, 'trxn_id' => $params['contribution']->trxn_id, 'status_id' => $statusId, 'payment_instrument_id' => $params['contribution']->payment_instrument_id, 'check_number' => CRM_Utils_Array::value('check_number', $params)); if (!empty($params['payment_processor'])) { $trxnParams['payment_processor_id'] = $params['payment_processor']; } if (isset($fromFinancialAccountId)) { $trxnParams['from_financial_account_id'] = $fromFinancialAccountId; } // consider external values passed for recording transaction entry if (!empty($financialTrxnValues)) { $trxnParams = array_merge($trxnParams, $financialTrxnValues); } $params['trxnParams'] = $trxnParams; if (!empty($params['prevContribution'])) { $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount; $params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount; $params['trxnParams']['net_amount'] = $params['prevContribution']->net_amount; $params['trxnParams']['trxn_id'] = $params['prevContribution']->trxn_id; $params['trxnParams']['status_id'] = $params['prevContribution']->contribution_status_id; if (!(($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatuses)) && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses))) { $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id; $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; } //if financial type is changed if (!empty($params['financial_type_id']) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) { $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); $oldFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $incomeTypeId); $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId); if ($oldFinancialAccount != $newFinancialAccount) { $params['total_amount'] = 0; if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) { $params['trxnParams']['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId); } else { $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC'); if (!empty($lastFinancialTrxnId['financialTrxnId'])) { $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id'); } } self::updateFinancialAccounts($params, 'changeFinancialType'); /* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */ $params['financial_account_id'] = $newFinancialAccount; $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params); $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; } } //Update contribution status $params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id; $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id; if (!empty($params['contribution_status_id']) && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) { //Update Financial Records self::updateFinancialAccounts($params, 'changedStatus'); } // change Payment Instrument for a Completed contribution // first handle special case when contribution is changed from Pending to Completed status when initial payment // instrument is null and now new payment instrument is added along with the payment $params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id; $params['trxnParams']['check_number'] = CRM_Utils_Array::value('check_number', $params); if (array_key_exists('payment_instrument_id', $params)) { $params['trxnParams']['total_amount'] = -$trxnParams['total_amount']; if (CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id) && !CRM_Utils_System::isNull($params['contribution']->payment_instrument_id)) { //check if status is changed from Pending to Completed // do not update payment instrument changes for Pending to Completed if (!($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses) && in_array($params['prevContribution']->contribution_status_id, $pendingStatus))) { // for all other statuses create new financial records self::updateFinancialAccounts($params, 'changePaymentInstrument'); $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); } } elseif ((!CRM_Utils_System::isNull($params['contribution']->payment_instrument_id) || !CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id)) && $params['contribution']->payment_instrument_id != $params['prevContribution']->payment_instrument_id) { // for any other payment instrument changes create new financial records self::updateFinancialAccounts($params, 'changePaymentInstrument'); $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); } elseif (!CRM_Utils_System::isNull($params['contribution']->check_number) && $params['contribution']->check_number != $params['prevContribution']->check_number) { // another special case when check number is changed, create new financial records // create financial trxn with negative amount $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; self::updateFinancialAccounts($params, 'changePaymentInstrument'); // create financial trxn with positive amount $params['trxnParams']['check_number'] = $params['contribution']->check_number; $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); } } //if Change contribution amount $params['trxnParams']['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params); $params['trxnParams']['net_amount'] = CRM_Utils_Array::value('net_amount', $params); $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $totalAmount; $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id; if (isset($totalAmount) && $totalAmount != $params['prevContribution']->total_amount) { //Update Financial Records $params['trxnParams']['from_financial_account_id'] = NULL; self::updateFinancialAccounts($params, 'changedAmount'); } } if (!$update) { // records finanical trxn and entity financial trxn // also make it available as return value $return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams); $params['entity_id'] = $financialTxn->id; } } // record line items and financial items if (empty($params['skipLineItem'])) { CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update); } // create batch entry if batch_id is passed and // ensure no batch entry is been made on 'Pending' or 'Failed' contribution, CRM-16611 if (!empty($params['batch_id']) && !empty($financialTxn)) { $entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_financial_trxn', 'entity_id' => $financialTxn->id); CRM_Batch_BAO_Batch::addBatchEntity($entityParams); } // when a fee is charged if (!empty($params['fee_amount']) && (empty($params['prevContribution']) || $params['contribution']->fee_amount != $params['prevContribution']->fee_amount) && $skipRecords) { CRM_Core_BAO_FinancialTrxn::recordFees($params); } if (!empty($params['prevContribution']) && $entityTable == 'civicrm_participant' && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) { $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $entityId, 'event_id'); $feeLevel[] = str_replace('', '', $params['prevContribution']->amount_level); CRM_Event_BAO_Participant::createDiscountTrxn($eventID, $params, $feeLevel); } unset($params['line_item']); return $return; }
/** * Create all financial accounts entry. * * @param array $params * Contribution object, line item array and params for trxn. * * * @param array $financialTrxnValues * * @return null|object */ public static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL) { $skipRecords = $update = $return = $isRelatedId = FALSE; $additionalParticipantId = array(); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $contributionStatus = empty($params['contribution_status_id']) ? NULL : $contributionStatuses[$params['contribution_status_id']]; if (CRM_Utils_Array::value('contribution_mode', $params) == 'participant') { $entityId = $params['participant_id']; $entityTable = 'civicrm_participant'; $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId); } elseif (!empty($params['membership_id'])) { //so far $params['membership_id'] should only be set coming in from membershipBAO::create so the situation where multiple memberships // are created off one contribution should be handled elsewhere $entityId = $params['membership_id']; $entityTable = 'civicrm_membership'; } else { $entityId = $params['contribution']->id; $entityTable = 'civicrm_contribution'; } if (CRM_Utils_Array::value('contribution_mode', $params) == 'membership') { $isRelatedId = TRUE; } $entityID[] = $entityId; if (!empty($additionalParticipantId)) { $entityID += $additionalParticipantId; } // prevContribution appears to mean - original contribution object- ie copy of contribution from before the update started that is being updated if (empty($params['prevContribution'])) { $entityID = NULL; } else { $update = TRUE; } $statusId = $params['contribution']->contribution_status_id; // CRM-13964 partial payment if ($contributionStatus == 'Partially paid' && !empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) { $partialAmtPay = $params['partial_amount_pay']; $partialAmtTotal = $params['partial_payment_total']; $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $fromFinancialAccountId = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); $params['total_amount'] = $partialAmtPay; $balanceTrxnInfo = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($params['contribution']->id, $params['financial_type_id']); if (empty($balanceTrxnInfo['trxn_id'])) { // create new balance transaction record $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); $balanceTrxnParams['total_amount'] = $partialAmtTotal; $balanceTrxnParams['to_financial_account_id'] = $toFinancialAccount; $balanceTrxnParams['contribution_id'] = $params['contribution']->id; $balanceTrxnParams['trxn_date'] = !empty($params['contribution']->receive_date) ? $params['contribution']->receive_date : date('YmdHis'); $balanceTrxnParams['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params); $balanceTrxnParams['net_amount'] = CRM_Utils_Array::value('net_amount', $params); $balanceTrxnParams['currency'] = $params['contribution']->currency; $balanceTrxnParams['trxn_id'] = $params['contribution']->trxn_id; $balanceTrxnParams['status_id'] = $statusId; $balanceTrxnParams['payment_instrument_id'] = $params['contribution']->payment_instrument_id; $balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params); if (!empty($balanceTrxnParams['from_financial_account_id']) && ($statusId == array_search('Completed', $contributionStatuses) || $statusId == array_search('Partially paid', $contributionStatuses))) { $balanceTrxnParams['is_payment'] = 1; } if (!empty($params['payment_processor'])) { $balanceTrxnParams['payment_processor_id'] = $params['payment_processor']; } $financialTxn = CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams); } } // build line item array if its not set in $params if (empty($params['line_item']) || $additionalParticipantId) { CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable), $isRelatedId); } if ($contributionStatus != 'Failed' && !($contributionStatus == 'Pending' && !$params['contribution']->is_pay_later)) { $skipRecords = TRUE; $pendingStatus = array('Pending', 'In Progress'); if (in_array($contributionStatus, $pendingStatus)) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); } elseif (!empty($params['payment_processor'])) { $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id'); } elseif (!empty($params['payment_instrument_id'])) { $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['payment_instrument_id']); } else { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' ")); $queryParams = array(1 => array($relationTypeId, 'Integer')); $params['to_financial_account_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams); } $totalAmount = CRM_Utils_Array::value('total_amount', $params); if (!isset($totalAmount) && !empty($params['prevContribution'])) { $totalAmount = $params['total_amount'] = $params['prevContribution']->total_amount; } //build financial transaction params $trxnParams = array('contribution_id' => $params['contribution']->id, 'to_financial_account_id' => $params['to_financial_account_id'], 'trxn_date' => !empty($params['contribution']->receive_date) ? $params['contribution']->receive_date : date('YmdHis'), 'total_amount' => $totalAmount, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'net_amount' => CRM_Utils_Array::value('net_amount', $params, $totalAmount), 'currency' => $params['contribution']->currency, 'trxn_id' => $params['contribution']->trxn_id, 'status_id' => $statusId, 'payment_instrument_id' => $params['contribution']->payment_instrument_id, 'check_number' => CRM_Utils_Array::value('check_number', $params)); if ($contributionStatus == 'Refunded') { $trxnParams['trxn_date'] = !empty($params['contribution']->cancel_date) ? $params['contribution']->cancel_date : date('YmdHis'); if (isset($params['refund_trxn_id'])) { // CRM-17751 allow a separate trxn_id for the refund to be passed in via api & form. $trxnParams['trxn_id'] = $params['refund_trxn_id']; } } //CRM-16259, set is_payment flag for non pending status if (!in_array($contributionStatus, $pendingStatus)) { $trxnParams['is_payment'] = 1; } if (!empty($params['payment_processor'])) { $trxnParams['payment_processor_id'] = $params['payment_processor']; } if (isset($fromFinancialAccountId)) { $trxnParams['from_financial_account_id'] = $fromFinancialAccountId; } // consider external values passed for recording transaction entry if (!empty($financialTrxnValues)) { $trxnParams = array_merge($trxnParams, $financialTrxnValues); } $params['trxnParams'] = $trxnParams; if (!empty($params['prevContribution'])) { $updated = FALSE; $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount; $params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount; $params['trxnParams']['net_amount'] = $params['prevContribution']->net_amount; if (!isset($params['trxnParams']['trxn_id'])) { // Actually I have no idea why we are overwriting any values from the previous contribution. // (filling makes sense to me). However, only protecting this value as I really really know we // don't want this one overwritten. // CRM-17751. $params['trxnParams']['trxn_id'] = $params['prevContribution']->trxn_id; } $params['trxnParams']['status_id'] = $params['prevContribution']->contribution_status_id; if (!(($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatuses)) && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses))) { $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id; $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; } //if financial type is changed if (!empty($params['financial_type_id']) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) { $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); $oldFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $incomeTypeId); $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId); if ($oldFinancialAccount != $newFinancialAccount) { $params['total_amount'] = 0; if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) { $params['trxnParams']['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId); } else { $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC'); if (!empty($lastFinancialTrxnId['financialTrxnId'])) { $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id'); } } self::updateFinancialAccounts($params, 'changeFinancialType'); /* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */ $params['financial_account_id'] = $newFinancialAccount; $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params); $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; $updated = TRUE; } } //Update contribution status $params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id; if (!isset($params['refund_trxn_id'])) { // CRM-17751 This has previously been deliberately set. No explanation as to why one variant // gets preference over another so I am only 'protecting' a very specific tested flow // and letting natural justice take care of the rest. $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id; } if (!empty($params['contribution_status_id']) && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) { //Update Financial Records self::updateFinancialAccounts($params, 'changedStatus'); $updated = TRUE; } // change Payment Instrument for a Completed contribution // first handle special case when contribution is changed from Pending to Completed status when initial payment // instrument is null and now new payment instrument is added along with the payment $params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id; $params['trxnParams']['check_number'] = CRM_Utils_Array::value('check_number', $params); if (array_key_exists('payment_instrument_id', $params)) { $params['trxnParams']['total_amount'] = -$trxnParams['total_amount']; if (CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id) && !CRM_Utils_System::isNull($params['contribution']->payment_instrument_id)) { //check if status is changed from Pending to Completed // do not update payment instrument changes for Pending to Completed if (!($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses) && in_array($params['prevContribution']->contribution_status_id, $pendingStatus))) { // for all other statuses create new financial records self::updateFinancialAccounts($params, 'changePaymentInstrument'); $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); $updated = TRUE; } } elseif ((!CRM_Utils_System::isNull($params['contribution']->payment_instrument_id) || !CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id)) && $params['contribution']->payment_instrument_id != $params['prevContribution']->payment_instrument_id) { // for any other payment instrument changes create new financial records self::updateFinancialAccounts($params, 'changePaymentInstrument'); $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); $updated = TRUE; } elseif (!CRM_Utils_System::isNull($params['contribution']->check_number) && $params['contribution']->check_number != $params['prevContribution']->check_number) { // another special case when check number is changed, create new financial records // create financial trxn with negative amount $params['trxnParams']['check_number'] = $params['prevContribution']->check_number; self::updateFinancialAccounts($params, 'changePaymentInstrument'); // create financial trxn with positive amount $params['trxnParams']['check_number'] = $params['contribution']->check_number; $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount']; self::updateFinancialAccounts($params, 'changePaymentInstrument'); $updated = TRUE; } } //if Change contribution amount $params['trxnParams']['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params); $params['trxnParams']['net_amount'] = CRM_Utils_Array::value('net_amount', $params); $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $totalAmount; $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id; if (isset($totalAmount) && $totalAmount != $params['prevContribution']->total_amount) { //Update Financial Records $params['trxnParams']['from_financial_account_id'] = NULL; self::updateFinancialAccounts($params, 'changedAmount'); $updated = TRUE; } if (!$updated) { // Looks like we might have a data correction update. // This would be a case where a transaction id has been entered but it is incorrect & // the person goes back in & fixes it, as opposed to a new transaction. // Currently the UI doesn't support multiple refunds against a single transaction & we are only supporting // the data fix scenario. // CRM-17751. if (isset($params['refund_trxn_id'])) { $refundIDs = CRM_Core_BAO_FinancialTrxn::getRefundTransactionIDs($params['id']); if ($refundIDs['trxn_id'] != $params['refund_trxn_id']) { civicrm_api3('FinancialTrxn', 'create', array('id' => $refundIDs['financialTrxnId'], 'trxn_id' => $params['refund_trxn_id'])); } } } } if (!$update) { // records finanical trxn and entity financial trxn // also make it available as return value $return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams); $params['entity_id'] = $financialTxn->id; } } // record line items and financial items if (empty($params['skipLineItem'])) { CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update); } // create batch entry if batch_id is passed and // ensure no batch entry is been made on 'Pending' or 'Failed' contribution, CRM-16611 if (!empty($params['batch_id']) && !empty($financialTxn)) { $entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_financial_trxn', 'entity_id' => $financialTxn->id); CRM_Batch_BAO_Batch::addBatchEntity($entityParams); } // when a fee is charged if (!empty($params['fee_amount']) && (empty($params['prevContribution']) || $params['contribution']->fee_amount != $params['prevContribution']->fee_amount) && $skipRecords) { CRM_Core_BAO_FinancialTrxn::recordFees($params); } if (!empty($params['prevContribution']) && $entityTable == 'civicrm_participant' && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) { $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $entityId, 'event_id'); $feeLevel[] = str_replace('', '', $params['prevContribution']->amount_level); CRM_Event_BAO_Participant::createDiscountTrxn($eventID, $params, $feeLevel); } unset($params['line_item']); return $return; }
/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $params['actualBatchTotal'] = 0; // get the profile information if ($this->_batchInfo['type_id'] == 1) { $this->processContribution($params); } else { $this->processMembership($params); } // update batch to close status $paramValues = array('id' => $this->_batchId, 'status_id' => CRM_Core_OptionGroup::getValue('batch_status', 'Closed', 'name'), 'total' => $params['actualBatchTotal']); CRM_Batch_BAO_Batch::create($paramValues); // set success status CRM_Core_Session::setStatus("", ts("Batch Processed."), "success"); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1')); }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues(); $batchParams = array(); $batchParams['title'] = $params['title']; $batchParams['name'] = CRM_Utils_String::titleToVar($params['title'], 63); $batchParams['description'] = $params['description']; $batchParams['batch_type'] = "Gift Aid"; $session =& CRM_Core_Session::singleton(); $batchParams['created_id'] = $session->get('userID'); $batchParams['created_date'] = date("YmdHis"); $batchParams['status_id'] = 0; $batchMode = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'mode_id', array('labelColumn' => 'name')); $batchParams['mode_id'] = CRM_Utils_Array::key('Manual Batch', $batchMode); $batchParams['modified_date'] = date('YmdHis'); $batchParams['modified_id'] = $session->get('userID'); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //require_once 'CRM/Core/BAO/Batch.php'; //version 4.2 require_once 'CRM/Batch/BAO/Batch.php'; $createdBatch = CRM_Batch_BAO_Batch::create($batchParams); $batchID = $createdBatch->id; $batchLabel = $batchParams['title']; // Save current settings for the batch CRM_Civigiftaid_BAO_BatchSettings::create(array('batch_id' => $batchID)); require_once 'CRM/Civigiftaid/Utils/Contribution.php'; list($total, $added, $notAdded) = CRM_Civigiftaid_Utils_Contribution::addContributionToBatch($this->_contributionIds, $batchID); if ($added <= 0) { // rollback since there were no contributions added, and we might not want to keep an empty batch $transaction->rollback(); $status = ts('Could not create batch "%1", as there were no valid contribution(s) to be added.', array(1 => $batchLabel)); } else { $status = array(ts('Added Contribution(s) to %1', array(1 => $batchLabel)), ts('Total Selected Contribution(s): %1', array(1 => $total))); if ($added) { $status[] = ts('Total Contribution(s) added to batch: %1', array(1 => $added)); } if ($notAdded) { $status[] = ts('Total Contribution(s) already in batch or not valid: %1', array(1 => $notAdded)); } $status = implode('<br/>', $status); } $transaction->commit(); CRM_Core_Session::setStatus($status); }
/** * Function for exporting financial accounts, currently we support CSV and IIF format * @see http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation * * @param array $batchIds * Associated array of batch ids. * @param string $exportFormat * Export format. */ public static function exportFinancialBatch($batchIds, $exportFormat) { if (empty($batchIds)) { CRM_Core_Error::fatal(ts('No batches were selected.')); return; } if (empty($exportFormat)) { CRM_Core_Error::fatal(ts('No export format selected.')); return; } self::$_exportFormat = $exportFormat; // Instantiate appropriate exporter based on user-selected format. $exporterClass = "CRM_Financial_BAO_ExportFormat_" . self::$_exportFormat; if (class_exists($exporterClass)) { $exporter = new $exporterClass(); } else { CRM_Core_Error::fatal("Could not locate exporter: {$exporterClass}"); } foreach ($batchIds as $batchId) { $export[$batchId] = $exporter->generateExportQuery($batchId); } $exporter->makeExport($export); }
static function createBatch(array $batchDetails) { //check mandatory $params foreach (array('banking_date', 'banking_account', 'batch_status', 'exclude_from_posting', 'payment_instrument_id') as $param) { if (!isset($batchDetails[$param])) { throw new InvalidArgumentException("No param[{$param}]"); } } // PS Commented out this way of creating the batch // Replaced with using the batch description and tidying //$batch_sql = "SELECT max(id) as max_id FROM civicrm_batch"; //$batch_dao = CRM_Core_DAO::executeQuery($batch_sql); //$batch_dao->fetch(); //$nextId = $batch_dao->max_id + 1; $session =& CRM_Core_Session::singleton(); //$nextId = CRM_Utils_String::titleToVar($batchDetails['description']); if (!isset($batchDetails['batch_title'])) { $batchDetails['batch_title'] = 'Contrib Batch ' . CRM_Utils_Date::currentDBDate(); } $batchParams = array('title' => $batchDetails['batch_title'], 'description' => $batchDetails['description'], 'created_id' => $session->get('userID'), 'created_date' => CRM_Utils_Date::currentDBDate(), 'type_id' => 1, 'status_id' => 2); // Create the batch require_once 'CRM/Batch/BAO/Batch.php'; $createdBatch =& CRM_Batch_BAO_Batch::create($batchParams); $batchDetails['batch_id'] = $createdBatch->id; require_once 'CRM/Utils/Date.php'; $batchDetails['banking_date'] = CRM_Utils_Date::processDate($batchDetails['banking_date']); // require_once 'CRM/Finance/BAO/BatchType.php'; $expectedPostingDate = CRM_Finance_BAO_BatchType::getBatchTypeExpectedPostingDate(); //matusz: copied from CRM_Batch_Page_AJAX::getContributionTypeForCampaign() //$batchDetails['contribution_type_id'] $campaignId = null; if (!empty($batchDetails['campaign_id'])) { $campaignId = $batchDetails['campaign_id']; } /* $contributionTypeId = null; if($campaignId !== null) { $select_dao = CRM_Core_DAO::executeQuery("SELECT * FROM ".CIVICRM_MTL_CAMPAIGN_FUND_CODE." WHERE campaign_id = %0", array( array($campaignId, 'Int') )); if (!$select_dao->fetch()){ throw new Exception("No contribution_type_id found by using campaign id '$campaignId'"); } $batchDetails['contribution_type_id'] = $select_dao->contribution_type_id; } */ if (empty($batchDetails['contribution_type_id'])) { $batchDetails['contribution_type_id'] = 0; } $batchDetails['exclude_from_posting'] = empty($batchDetails['exclude_from_posting']) ? 0 : 1; $sqlParams = array(array($batchDetails['payment_instrument_id'], 'Int'), array($expectedPostingDate, 'Timestamp'), array($batchDetails['exclude_from_posting'], 'Boolean'), array($batchDetails['banking_date'], 'Timestamp'), array($batchDetails['banking_account'], 'Int'), array($batchDetails['contribution_type_id'], 'Int'), array((string) $batchDetails['batch_title'], 'String')); $batchDetailsSql = " UPDATE civicrm_batch SET "; $batchDetailsSql .= " payment_instrument_id = %0 "; $batchDetailsSql .= " , expected_posting_date = %1 "; $batchDetailsSql .= " , exclude_from_posting = %2 "; $batchDetailsSql .= " , banking_date = %3 "; $batchDetailsSql .= " , banking_account = %4 "; $batchDetailsSql .= " , contribution_type_id = %5 "; $batchDetailsSql .= " , title = %6 "; $parameterIndex = 6; if ($campaignId !== null) { $parameterIndex = $parameterIndex + 1; $batchDetailsSql .= ", campaign_id = %{$parameterIndex} "; $sqlParams[] = array($campaignId, 'Int'); } /* if(isset($batchDetails['expected_entries'])) { $parameterIndex = $parameterIndex + 1; $batchDetailsSql .= ", expected_entries = %$parameterIndex "; $sqlParams[] = array($batchDetails['expected_entries'], 'Int'); } if(isset($batchDetails['expected_value'])) { $parameterIndex = $parameterIndex + 1; $batchDetailsSql .= ", expected_value = %$parameterIndex "; $sqlParams[] = array($batchDetails['expected_value'], 'Money'); } */ if (isset($batchDetails['entity_type'])) { $parameterIndex = $parameterIndex + 1; $batchDetailsSql .= ", entity_type = %{$parameterIndex} "; $sqlParams[] = array($batchDetails['entity_type'], 'String'); } $parameterIndex = $parameterIndex + 1; $batchDetailsSql .= " WHERE id = %{$parameterIndex} "; $sqlParams[] = array($batchDetails['batch_id'], 'Int'); CRM_Core_DAO::executeQuery($batchDetailsSql, $sqlParams); return $batchDetails; }