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


PHP CRM_Contribute_BAO_Contribution_Utils类代码示例

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


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

示例1: processAmount

 /**
  * Get line item purchase information.
  *
  * This function takes the input parameters and interprets out of it what has been purchased.
  *
  * @param $fields
  *   This is the output of the function CRM_Price_BAO_PriceSet::getSetDetail($priceSetID, FALSE, FALSE);
  *   And, it would make sense to introduce caching into that function and call it from here rather than
  *   require the $fields array which is passed from pillar to post around the form in order to pass it in here.
  * @param array $params
  *   Params reflecting form input e.g with fields 'price_5' => 7, 'price_8' => array(7, 8)
  * @param $lineItem
  *   Line item array to be altered.
  * @param string $component
  *   This parameter appears to only be relevant to determining whether memberships should be auto-renewed.
  *   (and is effectively a boolean for 'is_membership' which could be calculated from the line items.)
  */
 public static function processAmount($fields, &$params, &$lineItem, $component = '')
 {
     // using price set
     $totalPrice = $totalTax = 0;
     $radioLevel = $checkboxLevel = $selectLevel = $textLevel = array();
     if ($component) {
         $autoRenew = array();
         $autoRenew[0] = $autoRenew[1] = $autoRenew[2] = 0;
     }
     foreach ($fields as $id => $field) {
         if (empty($params["price_{$id}"]) || empty($params["price_{$id}"]) && $params["price_{$id}"] == NULL) {
             // skip if nothing was submitted for this field
             continue;
         }
         switch ($field['html_type']) {
             case 'Text':
                 $firstOption = reset($field['options']);
                 $params["price_{$id}"] = array($firstOption['id'] => $params["price_{$id}"]);
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][key($field['options'])])) {
                     $lineItem = self::setLineItem($field, $lineItem, key($field['options']));
                     $totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
                 }
                 if (CRM_Utils_Array::value('name', $field['options'][key($field['options'])]) == 'contribution_amount') {
                     $taxRates = CRM_Core_PseudoConstant::getTaxRates();
                     if (array_key_exists($params['financial_type_id'], $taxRates)) {
                         $field['options'][key($field['options'])]['tax_rate'] = $taxRates[$params['financial_type_id']];
                         $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($field['options'][key($field['options'])]['amount'], $field['options'][key($field['options'])]['tax_rate']);
                         $field['options'][key($field['options'])]['tax_amount'] = round($taxAmount['tax_amount'], 2);
                         $lineItem = self::setLineItem($field, $lineItem, key($field['options']));
                         $totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
                     }
                 }
                 $totalPrice += $lineItem[$firstOption['id']]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[key($field['options'])]);
                 break;
             case 'Radio':
                 //special case if user select -none-
                 if ($params["price_{$id}"] <= 0) {
                     continue;
                 }
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
                 $params['amount_priceset_level_radio'] = array();
                 $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
                 if (isset($radioLevel)) {
                     $radioLevel = array_merge($radioLevel, array_keys($params['amount_priceset_level_radio']));
                 } else {
                     $radioLevel = array_keys($params['amount_priceset_level_radio']);
                 }
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
                     $lineItem = self::setLineItem($field, $lineItem, $optionValueId);
                     $totalTax += $field['options'][$optionValueId]['tax_amount'];
                     if (CRM_Utils_Array::value('field_title', $lineItem[$optionValueId]) == 'Membership Amount') {
                         $lineItem[$optionValueId]['line_total'] = $lineItem[$optionValueId]['unit_price'] = CRM_Utils_Rule::cleanMoney($lineItem[$optionValueId]['line_total'] - $lineItem[$optionValueId]['tax_amount']);
                     }
                 }
                 $totalPrice += $lineItem[$optionValueId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionValueId]);
                 if ($component && isset($lineItem[$optionValueId]['auto_renew']) && is_numeric($lineItem[$optionValueId]['auto_renew'])) {
                     $autoRenew[$lineItem[$optionValueId]['auto_renew']] += $lineItem[$optionValueId]['line_total'];
                 }
                 break;
             case 'Select':
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = $field['options'][$optionValueId]['label'];
                 $params['amount_priceset_level_select'] = array();
                 $params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel;
                 if (isset($selectLevel)) {
                     $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select']));
                 } else {
                     $selectLevel = array_keys($params['amount_priceset_level_select']);
                 }
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
                     $lineItem = self::setLineItem($field, $lineItem, $optionValueId);
                     $totalTax += $field['options'][$optionValueId]['tax_amount'];
                 }
                 $totalPrice += $lineItem[$optionValueId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionValueId]);
                 if ($component && isset($lineItem[$optionValueId]['auto_renew']) && is_numeric($lineItem[$optionValueId]['auto_renew'])) {
                     $autoRenew[$lineItem[$optionValueId]['auto_renew']] += $lineItem[$optionValueId]['line_total'];
                 }
//.........这里部分代码省略.........
开发者ID:rollox,项目名称:civicrm-core,代码行数:101,代码来源:PriceSet.php

示例2: postProcess

 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     //get the submitted form values.
     $submittedValues = $this->controller->exportValues($this->_name);
     // get the chart type.
     $chartType = CRM_Utils_Array::value('chart_type', $submittedValues, 'bvg');
     //take contribution information monthly
     require_once 'CRM/Contribute/BAO/Contribution/Utils.php';
     $selectedYear = CRM_Utils_Array::value('select_year', $submittedValues, date('Y'));
     $chartInfoMonthly = CRM_Contribute_BAO_Contribution_Utils::contributionChartMonthly($selectedYear);
     $chartData = $abbrMonthNames = array();
     if (is_array($chartInfoMonthly)) {
         for ($i = 1; $i <= 12; $i++) {
             $abbrMonthNames[$i] = strftime('%b', mktime(0, 0, 0, $i, 10, 1970));
         }
         foreach ($abbrMonthNames as $monthKey => $monthName) {
             $val = CRM_Utils_Array::value($monthKey, $chartInfoMonthly['By Month'], 0);
             // don't include zero value month.
             if (!$val && $chartType != 'bvg') {
                 continue;
             }
             //build the params for chart.
             $chartData['by_month']['values'][$monthName] = $val;
         }
         $chartData['by_month']['legend'] = 'By Month' . ' - ' . $selectedYear;
         // handle onclick event.
         $chartData['by_month']['on_click_fun_name'] = 'byMonthOnClick';
         $chartData['by_month']['yname'] = ts('Contribution');
     }
     //take contribution information by yearly
     $chartInfoYearly = CRM_Contribute_BAO_Contribution_Utils::contributionChartYearly();
     //get the years.
     $this->_years = $chartInfoYearly['By Year'];
     $hasContributions = false;
     if (is_array($chartInfoYearly)) {
         $hasContributions = true;
         $chartData['by_year']['legend'] = 'By Year';
         $chartData['by_year']['values'] = $chartInfoYearly['By Year'];
         // handle onclick event.
         $chartData['by_year']['on_click_fun_name'] = 'byYearOnClick';
         $chartData['by_year']['yname'] = ts('Contribution');
     }
     $this->assign('hasContributions', $hasContributions);
     // process the data.
     require_once 'CRM/Utils/OpenFlashChart.php';
     $chartCnt = 1;
     $monthlyChart = $yearlyChart = false;
     foreach ($chartData as $chartKey => &$values) {
         $chartValues = CRM_Utils_Array::value('values', $values);
         if (!is_array($chartValues) || empty($chartValues)) {
             continue;
         }
         if ($chartKey == 'by_year') {
             $yearlyChart = true;
         }
         if ($chartKey == 'by_month') {
             $monthlyChart = true;
         }
         $values['divName'] = "open_flash_chart_{$chartKey}";
         $funName = $chartType == 'bvg' ? 'barChart' : 'pieChart';
         // build the chart objects.
         eval("\$values['object'] = CRM_Utils_OpenFlashChart::" . $funName . '( $values );');
         //build the urls.
         $urlCnt = 0;
         foreach ($chartValues as $index => $val) {
             $urlParams = null;
             if ($chartKey == 'by_month') {
                 $monthPosition = array_search($index, $abbrMonthNames);
                 $startDate = CRM_Utils_Date::format(array('Y' => $selectedYear, 'M' => $monthPosition));
                 $endDate = date('Ymd', mktime(0, 0, 0, $monthPosition + 1, 0, $selectedYear));
                 $urlParams = "reset=1&force=1&status=1&start={$startDate}&end={$endDate}&test=0";
             } else {
                 if ($chartKey == 'by_year') {
                     $startDate = CRM_Utils_Date::format(array('Y' => $index));
                     $endDate = date('Ymd', mktime(0, 0, 0, 13, 0, $index));
                     $urlParams = "reset=1&force=1&status=1&start={$startDate}&end={$endDate}&test=0";
                 }
             }
             if ($urlParams) {
                 $values['on_click_urls']["url_" . $urlCnt++] = CRM_Utils_System::url('civicrm/contribute/search', $urlParams, true, false, false);
             }
         }
         // calculate chart size.
         $xSize = 400;
         $ySize = 300;
         if ($chartType == 'bvg') {
             $ySize = 250;
             $xSize = 60 * count($chartValues);
             //hack to show tooltip.
             if ($xSize < 150) {
                 $xSize = 150;
             }
         }
         $values['size'] = array('xSize' => $xSize, 'ySize' => $ySize);
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:ContributionCharts.php

示例3: formatAPIParams

 /**
  * @param array $apiParams
  * @param $mapper
  * @param string $type
  * @param bool $category
  *
  * @return array
  */
 public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE)
 {
     $type = strtolower($type);
     if (!in_array($type, array('paypal', 'google', 'csv'))) {
         // return the params as is
         return $apiParams;
     }
     $params = $transaction = array();
     if ($type == 'paypal') {
         foreach ($apiParams as $detail => $val) {
             if (isset($mapper['contact'][$detail])) {
                 $params[$mapper['contact'][$detail]] = $val;
             } elseif (isset($mapper['location'][$detail])) {
                 $params['address'][1][$mapper['location'][$detail]] = $val;
             } elseif (isset($mapper['transaction'][$detail])) {
                 switch ($detail) {
                     case 'l_period2':
                         // Sadly, PayPal seems to send two distinct data elements in a single field,
                         // so we break them out here.  This is somewhat ugly and tragic.
                         $freqUnits = array('D' => 'day', 'W' => 'week', 'M' => 'month', 'Y' => 'year');
                         list($frequency_interval, $frequency_unit) = explode(' ', $val);
                         $transaction['frequency_interval'] = $frequency_interval;
                         $transaction['frequency_unit'] = $freqUnits[$frequency_unit];
                         break;
                     case 'subscriptiondate':
                     case 'timestamp':
                         // PayPal dates are in  ISO-8601 format.  We need a format that
                         // MySQL likes
                         $unix_timestamp = strtotime($val);
                         $transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
                         break;
                     case 'note':
                     case 'custom':
                     case 'l_number0':
                         if ($val) {
                             $val = "[PayPal_field:{$detail}] {$val}";
                             $transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ? $transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
                         }
                         break;
                     default:
                         $transaction[$mapper['transaction'][$detail]] = $val;
                 }
             }
         }
         if (!empty($transaction) && $category) {
             $params['transaction'] = $transaction;
         } else {
             $params += $transaction;
         }
         CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
         return $params;
     }
     if ($type == 'csv') {
         $header = $apiParams['header'];
         unset($apiParams['header']);
         foreach ($apiParams as $key => $val) {
             if (isset($mapper['contact'][$header[$key]])) {
                 $params[$mapper['contact'][$header[$key]]] = $val;
             } elseif (isset($mapper['location'][$header[$key]])) {
                 $params['address'][1][$mapper['location'][$header[$key]]] = $val;
             } elseif (isset($mapper['transaction'][$header[$key]])) {
                 $transaction[$mapper['transaction'][$header[$key]]] = $val;
             } else {
                 $params[$header[$key]] = $val;
             }
         }
         if (!empty($transaction) && $category) {
             $params['transaction'] = $transaction;
         } else {
             $params += $transaction;
         }
         CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
         return $params;
     }
     if ($type == 'google') {
         // return if response smell invalid
         if (!array_key_exists('risk-information-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
             return FALSE;
         }
         $riskInfo =& $apiParams[1][$apiParams[0]]['notifications']['risk-information-notification'];
         if (array_key_exists('new-order-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
             $newOrder =& $apiParams[1][$apiParams[0]]['notifications']['new-order-notification'];
         }
         if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
             foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
                 if (!empty($mapper['location'][$field])) {
                     $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
                 } elseif (!empty($mapper['contact'][$field])) {
                     if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
                         foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
                             $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
                         }
//.........这里部分代码省略.........
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:101,代码来源:ContributionProcessor.php

示例4: getOptions

 /**
  * Retrieve a list of options for the specified field.
  *
  * @param int $fieldId
  *   Price field ID.
  * @param bool $inactiveNeeded
  *   Include inactive options.
  * @param bool $reset
  *   Ignore stored values\.
  *
  * @return array
  *   array of options
  */
 public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE)
 {
     static $options = array();
     if ($reset || empty($options[$fieldId])) {
         $values = array();
         CRM_Price_BAO_PriceFieldValue::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
         $options[$fieldId] = $values;
         $taxRates = CRM_Core_PseudoConstant::getTaxRates();
         // ToDo - Code for Hook Invoke
         foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
             if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates)) {
                 $options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
                 $options[$fieldId][$priceFieldId]['tax_amount'] = round($taxAmount['tax_amount'], 2);
             }
         }
     }
     return $options[$fieldId];
 }
开发者ID:vakeesan26,项目名称:civicrm-core,代码行数:32,代码来源:PriceField.php

示例5: checkTaxAmount

 /**
  * Check tax amount.
  *
  * @param array $params
  * @param bool $isLineItem
  *
  * @return mixed
  */
 public static function checkTaxAmount($params, $isLineItem = FALSE)
 {
     $taxRates = CRM_Core_PseudoConstant::getTaxRates();
     // Update contribution.
     if (!empty($params['id'])) {
         $id = $params['id'];
         $values = $ids = array();
         $contrbutionParams = array('id' => $id);
         $prevContributionValue = CRM_Contribute_BAO_Contribution::getValues($contrbutionParams, $values, $ids);
         // To assign pervious finantial type on update of contribution
         if (!isset($params['financial_type_id'])) {
             $params['financial_type_id'] = $prevContributionValue->financial_type_id;
         } elseif (isset($params['financial_type_id']) && !array_key_exists($params['financial_type_id'], $taxRates)) {
             // Assisn tax Amount on update of contrbution
             if (!empty($prevContributionValue->tax_amount)) {
                 $params['tax_amount'] = 'null';
                 CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
                 foreach ($params['line_item'] as $setID => $priceField) {
                     foreach ($priceField as $priceFieldID => $priceFieldValue) {
                         $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
                     }
                 }
             }
         }
     }
     // New Contrbution and update of contribution with tax rate financial type
     if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && empty($params['skipLineItem']) && !$isLineItem) {
         $taxRateParams = $taxRates[$params['financial_type_id']];
         $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['total_amount'], $taxRateParams);
         $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
         // Get Line Item on update of contribution
         if (isset($params['id'])) {
             CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
         } else {
             CRM_Price_BAO_LineItem::getLineItemArray($params);
         }
         foreach ($params['line_item'] as $setID => $priceField) {
             foreach ($priceField as $priceFieldID => $priceFieldValue) {
                 $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
             }
         }
         $params['total_amount'] = $params['total_amount'] + $params['tax_amount'];
     } elseif (isset($params['api.line_item.create'])) {
         // Update total amount of contribution using lineItem
         $taxAmountArray = array();
         foreach ($params['api.line_item.create'] as $key => $value) {
             if (isset($value['financial_type_id']) && array_key_exists($value['financial_type_id'], $taxRates)) {
                 $taxRate = $taxRates[$value['financial_type_id']];
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($value['line_total'], $taxRate);
                 $taxAmountArray[] = round($taxAmount['tax_amount'], 2);
             }
         }
         $params['tax_amount'] = array_sum($taxAmountArray);
         $params['total_amount'] = $params['total_amount'] + $params['tax_amount'];
     } else {
         // update line item of contrbution
         if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && $isLineItem) {
             $taxRate = $taxRates[$params['financial_type_id']];
             $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate);
             $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
         }
     }
     return $params;
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:72,代码来源:Contribution.php

示例6: postProcessMembership

 /**
  * Process the Memberships.
  *
  * @param array $membershipParams
  *   Array of membership fields.
  * @param int $contactID
  *   Contact id.
  * @param CRM_Contribute_Form_Contribution_Confirm $form
  *   Confirmation form object.
  *
  * @param array $premiumParams
  * @param null $customFieldsFormatted
  * @param null $includeFieldTypes
  *
  * @param array $membershipDetails
  *
  * @param array $membershipTypeIDs
  *
  * @param bool $isPaidMembership
  * @param array $membershipID
  *
  * @param $isProcessSeparateMembershipTransaction
  *
  * @param int $defaultContributionTypeID
  * @param array $membershipLineItems
  *   Line items specific to membership payment that is separate to contribution.
  * @param $isPayLater
  *
  * @throws \CRM_Core_Exception
  */
 public static function postProcessMembership($membershipParams, $contactID, &$form, $premiumParams, $customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeIDs, $isPaidMembership, $membershipID, $isProcessSeparateMembershipTransaction, $defaultContributionTypeID, $membershipLineItems, $isPayLater)
 {
     $result = $membershipContribution = NULL;
     $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE);
     $errors = $createdMemberships = array();
     //@todo move this into the calling function & pass in the correct financialTypeID
     if (isset($paymentParams['financial_type'])) {
         $financialTypeID = $paymentParams['financial_type'];
     } else {
         $financialTypeID = $defaultContributionTypeID;
     }
     if (CRM_Utils_Array::value('membership_source', $form->_params)) {
         $membershipParams['contribution_source'] = $form->_params['membership_source'];
     }
     if ($isPaidMembership) {
         $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, $financialTypeID, 'membership', array(), $isTest, $isPayLater);
         if (is_a($result[1], 'CRM_Core_Error')) {
             $errors[1] = CRM_Core_Error::getMessages($result[1]);
         } elseif (!empty($result[1])) {
             // Save the contribution ID so that I can be used in email receipts
             // For example, if you need to generate a tax receipt for the donation only.
             $form->_values['contribution_other_id'] = $result[1]->id;
             //note that this will be over-written if we are using a separate membership transaction. Otherwise there is only one
             $membershipContribution = $result[1];
         }
     }
     if ($isProcessSeparateMembershipTransaction) {
         try {
             $lineItems = $form->_lineItem = $membershipLineItems;
             if (empty($form->_params['auto_renew']) && !empty($membershipParams['is_recur'])) {
                 unset($membershipParams['is_recur']);
             }
             $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipParams, $isTest, $membershipLineItems, CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0), CRM_Utils_Array::value('financial_type_id', $membershipDetails));
         } catch (CRM_Core_Exception $e) {
             $errors[2] = $e->getMessage();
             $membershipContribution = NULL;
         }
     }
     $membership = NULL;
     if (!empty($membershipContribution) && !is_a($membershipContribution, 'CRM_Core_Error')) {
         $membershipContributionID = $membershipContribution->id;
     }
     //@todo - why is this nested so deep? it seems like it could be just set on the calling function on the form layer
     if (isset($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])) {
         $form->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
     }
     //@todo it should no longer be possible for it to get to this point & membership to not be an array
     if (is_array($membershipTypeIDs) && !empty($membershipContributionID)) {
         $typesTerms = CRM_Utils_Array::value('types_terms', $membershipParams, array());
         foreach ($membershipTypeIDs as $memType) {
             $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1);
             $createdMemberships[$memType] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, $form);
         }
         if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) {
             foreach ($form->_lineItem[$form->_priceSetId] as &$priceFieldOp) {
                 if (!empty($priceFieldOp['membership_type_id']) && isset($createdMemberships[$priceFieldOp['membership_type_id']])) {
                     $membershipOb = $createdMemberships[$priceFieldOp['membership_type_id']];
                     $priceFieldOp['start_date'] = $membershipOb->start_date ? CRM_Utils_Date::customFormat($membershipOb->start_date, '%B %E%f, %Y') : '-';
                     $priceFieldOp['end_date'] = $membershipOb->end_date ? CRM_Utils_Date::customFormat($membershipOb->end_date, '%B %E%f, %Y') : '-';
                 } else {
                     $priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A';
                 }
             }
             $form->_values['lineItem'] = $form->_lineItem;
             $form->assign('lineItem', $form->_lineItem);
         }
     }
     if (!empty($errors)) {
         $message = self::compileErrorMessage($errors);
         throw new CRM_Core_Exception($message);
//.........这里部分代码省略.........
开发者ID:kidaa30,项目名称:yes,代码行数:101,代码来源:Membership.php

示例7: postProcessMembership

 /**
  * Process the Memberships
  *
  * @param array  $membershipParams array of membership fields
  * @param int    $contactID        contact id 
  * @param object $form             form object  
  *
  * @return void
  * @access public
  */
 public function postProcessMembership($membershipParams, $contactID, &$form, &$premiumParams)
 {
     $tempParams = $membershipParams;
     $paymentDone = false;
     $result = null;
     $isTest = CRM_Utils_Array::value('is_test', $membershipParams, false);
     $form->assign('membership_assign', true);
     $form->set('membershipTypeID', $membershipParams['selectMembership']);
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Member/BAO/Membership.php';
     $membershipTypeID = $membershipParams['selectMembership'];
     $membershipDetails = self::buildMembershipTypeValues($form, $membershipTypeID);
     $form->assign('membership_name', $membershipDetails['name']);
     $minimumFee = CRM_Utils_Array::value('minimum_fee', $membershipDetails);
     $contributionTypeId = null;
     if ($form->_values['amount_block_is_active']) {
         $contributionTypeId = $form->_values['contribution_type_id'];
     } else {
         $paymentDone = true;
         $params['amount'] = $minimumFee;
         $contributionTypeId = $membershipDetails['contribution_type_id'];
     }
     //amount must be greater than zero for
     //adding contribution record  to contribution table.
     //this condition is arises when separate membership payment is
     //enable and contribution amount is not selected. fix for CRM-3010
     require_once 'CRM/Contribute/BAO/Contribution/Utils.php';
     if ($form->_amount > 0.0) {
         $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, $contributionTypeId, 'membership');
     } else {
         // create the CMS contact here since we normally do this under processConfirm
         CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, $membershipParams['cms_contactID'], 'email-' . $form->_bltID);
     }
     $errors = array();
     if (is_a($result[1], 'CRM_Core_Error')) {
         $errors[1] = CRM_Core_Error::getMessages($result[1]);
     } else {
         $contribution[1] = $result[1];
     }
     $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
     if ($memBlockDetails['is_separate_payment'] && !$paymentDone) {
         require_once 'CRM/Contribute/DAO/ContributionType.php';
         $contributionType = new CRM_Contribute_DAO_ContributionType();
         $contributionType->id = $membershipDetails['contribution_type_id'];
         if (!$contributionType->find(true)) {
             CRM_Core_Error::fatal("Could not find a system table");
         }
         $tempParams['amount'] = $minimumFee;
         $invoiceID = md5(uniqid(rand(), true));
         $tempParams['invoiceID'] = $invoiceID;
         //we don't allow recurring membership.CRM-3781.
         if (CRM_Utils_Array::value('is_recur', $tempParams)) {
             $tempParams['is_recur'] = 0;
         }
         $result = null;
         if ($form->_values['is_monetary'] && !$form->_params['is_pay_later']) {
             require_once 'CRM/Core/Payment.php';
             $payment =& CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form);
             if ($form->_contributeMode == 'express') {
                 $result =& $payment->doExpressCheckout($tempParams);
             } else {
                 $result =& $payment->doDirectPayment($tempParams);
             }
         }
         if (is_a($result, 'CRM_Core_Error')) {
             $errors[2] = CRM_Core_Error::getMessages($result);
         } else {
             //assign receive date when separate membership payment
             //and contribution amount not selected.
             if ($form->_amount == 0) {
                 $now = date('YmdHis');
                 $form->_params['receive_date'] = $now;
                 $receiveDate = CRM_Utils_Date::mysqlToIso($now);
                 $form->set('params', $form->_params);
                 $form->assign('receive_date', $receiveDate);
             }
             $form->set('membership_trx_id', $result['trxn_id']);
             $form->set('membership_amount', $minimumFee);
             $form->assign('membership_trx_id', $result['trxn_id']);
             $form->assign('membership_amount', $minimumFee);
             // we dont need to create the user twice, so lets disable cms_create_account
             // irrespective of the value, CRM-2888
             $tempParams['cms_create_account'] = 0;
             $pending = $form->_params['is_pay_later'] ? true : false;
             //set this variable as we are not creating pledge for
             //separate membership payment contribution.
             //so for differentiating membership contributon from
             //main contribution.
             $form->_params['separate_membership_payment'] = 1;
             $contribution[2] = CRM_Contribute_Form_Contribution_Confirm::processContribution($form, $tempParams, $result, $contactID, $contributionType, false, $pending);
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Membership.php

示例8: csv

 static function csv()
 {
     $csvFile = '/home/deepak/Desktop/crm-4247.csv';
     $delimiter = ";";
     $row = 1;
     $handle = fopen($csvFile, "r");
     if (!$handle) {
         CRM_Core_Error::fatal("Can't locate csv file.");
     }
     require_once "CRM/Contribute/BAO/Contribution/Utils.php";
     while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
         if ($row !== 1) {
             $data['header'] = $header;
             $params = CRM_Contribute_BAO_Contribution_Utils::formatAPIParams($data, self::$_csvParamsMapper, 'csv');
             if (CRM_Contribute_BAO_Contribution_Utils::processAPIContribution($params)) {
                 CRM_Core_Error::debug_log_message("Processed - line {$row} of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", true);
             } else {
                 CRM_Core_Error::debug_log_message("Skipped - line {$row} of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", true);
             }
             // clean up memory from dao's
             CRM_Core_DAO::freeResult();
         } else {
             // we assuming - first row is always the header line
             $header = $data;
             CRM_Core_Error::debug_log_message("Considering first row ( line {$row} ) as HEADER ..<p>", true);
             if (empty($header)) {
                 CRM_Core_Error::fatal("Header is empty.");
             }
         }
         $row++;
     }
     fclose($handle);
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:33,代码来源:ContributionProcessor.php

示例9: postProcess

 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->getName());
     if (!$this->_contactID && isset($params['cms_create_account'])) {
         foreach ($params as $key => $value) {
             if (substr($key, 0, 5) == 'email' && !empty($value)) {
                 list($fieldName, $locTypeId) = CRM_Utils_System::explode('-', $key, 2);
                 $isPrimary = 0;
                 if ($locTypeId == 'Primary') {
                     require_once "CRM/Core/BAO/LocationType.php";
                     $locTypeId =& CRM_Core_BAO_LocationType::getDefault();
                     $isPrimary = 1;
                 }
                 $params['email'] = array();
                 $params['email'][1]['email'] = $value;
                 $params['email'][1]['location_type_id'] = $locTypeId;
                 $params['email'][1]['is_primary'] = $isPrimary;
             }
         }
     }
     require_once 'CRM/Dedupe/Finder.php';
     $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
     $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', 'Strict');
     if ($ids) {
         $this->_contactID = $ids['0'];
     }
     $contactID =& CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID);
     $this->set('contactID', $contactID);
     if (!empty($params['email'])) {
         $params['email'] = $params['email'][1]['email'];
     }
     require_once "CRM/Contribute/BAO/Contribution/Utils.php";
     CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email');
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:40,代码来源:PCPAccount.php

示例10: processAmount

 /**
  * Get line item purchase information.
  *
  * This function takes the input parameters and interprets out of it what has been purchased.
  *
  * @param $fields
  *   This is the output of the function CRM_Price_BAO_PriceSet::getSetDetail($priceSetID, FALSE, FALSE);
  *   And, it would make sense to introduce caching into that function and call it from here rather than
  *   require the $fields array which is passed from pillar to post around the form in order to pass it in here.
  * @param array $params
  *   Params reflecting form input e.g with fields 'price_5' => 7, 'price_8' => array(7, 8)
  * @param $lineItem
  *   Line item array to be altered.
  * @param string $component
  *   This parameter appears to only be relevant to determining whether memberships should be auto-renewed.
  *   (and is effectively a boolean for 'is_membership' which could be calculated from the line items.)
  */
 public static function processAmount($fields, &$params, &$lineItem, $component = '')
 {
     // using price set
     $totalPrice = $totalTax = 0;
     $radioLevel = $checkboxLevel = $selectLevel = $textLevel = array();
     if ($component) {
         $autoRenew = array();
         $autoRenew[0] = $autoRenew[1] = $autoRenew[2] = 0;
     }
     foreach ($fields as $id => $field) {
         if (empty($params["price_{$id}"]) || empty($params["price_{$id}"]) && $params["price_{$id}"] == NULL) {
             // skip if nothing was submitted for this field
             continue;
         }
         switch ($field['html_type']) {
             case 'Text':
                 $firstOption = reset($field['options']);
                 $params["price_{$id}"] = array($firstOption['id'] => $params["price_{$id}"]);
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][key($field['options'])])) {
                     $lineItem = self::setLineItem($field, $lineItem, key($field['options']));
                     $totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
                 }
                 if (CRM_Utils_Array::value('name', $field['options'][key($field['options'])]) == 'contribution_amount') {
                     $taxRates = CRM_Core_PseudoConstant::getTaxRates();
                     if (array_key_exists($params['financial_type_id'], $taxRates)) {
                         $field['options'][key($field['options'])]['tax_rate'] = $taxRates[$params['financial_type_id']];
                         $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($field['options'][key($field['options'])]['amount'], $field['options'][key($field['options'])]['tax_rate']);
                         $field['options'][key($field['options'])]['tax_amount'] = round($taxAmount['tax_amount'], 2);
                         $lineItem = self::setLineItem($field, $lineItem, key($field['options']));
                         $totalTax += $field['options'][key($field['options'])]['tax_amount'] * $lineItem[key($field['options'])]['qty'];
                     }
                 }
                 $totalPrice += $lineItem[$firstOption['id']]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[key($field['options'])]);
                 break;
             case 'Radio':
                 //special case if user select -none-
                 if ($params["price_{$id}"] <= 0) {
                     continue;
                 }
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
                 $params['amount_priceset_level_radio'] = array();
                 $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
                 if (isset($radioLevel)) {
                     $radioLevel = array_merge($radioLevel, array_keys($params['amount_priceset_level_radio']));
                 } else {
                     $radioLevel = array_keys($params['amount_priceset_level_radio']);
                 }
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
                     $lineItem = self::setLineItem($field, $lineItem, $optionValueId);
                     $totalTax += $field['options'][$optionValueId]['tax_amount'];
                     if (CRM_Utils_Array::value('field_title', $lineItem[$optionValueId]) == 'Membership Amount') {
                         $lineItem[$optionValueId]['line_total'] = $lineItem[$optionValueId]['unit_price'] = CRM_Utils_Rule::cleanMoney($lineItem[$optionValueId]['line_total'] - $lineItem[$optionValueId]['tax_amount']);
                     }
                 }
                 $totalPrice += $lineItem[$optionValueId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionValueId]);
                 if ($component && isset($lineItem[$optionValueId]['auto_renew']) && is_numeric($lineItem[$optionValueId]['auto_renew'])) {
                     $autoRenew[$lineItem[$optionValueId]['auto_renew']] += $lineItem[$optionValueId]['line_total'];
                 }
                 break;
             case 'Select':
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = $field['options'][$optionValueId]['label'];
                 $params['amount_priceset_level_select'] = array();
                 $params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel;
                 if (isset($selectLevel)) {
                     $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select']));
                 } else {
                     $selectLevel = array_keys($params['amount_priceset_level_select']);
                 }
                 CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) {
                     $lineItem = self::setLineItem($field, $lineItem, $optionValueId);
                     $totalTax += $field['options'][$optionValueId]['tax_amount'];
                 }
                 $totalPrice += $lineItem[$optionValueId]['line_total'] + CRM_Utils_Array::value('tax_amount', $lineItem[$optionValueId]);
                 if ($component && isset($lineItem[$optionValueId]['auto_renew']) && is_numeric($lineItem[$optionValueId]['auto_renew'])) {
                     $autoRenew[$lineItem[$optionValueId]['auto_renew']] += $lineItem[$optionValueId]['line_total'];
                 }
//.........这里部分代码省略.........
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:101,代码来源:PriceSet.php

示例11: checkTaxAmount

 /**
  * Get the tax amount (misnamed function).
  *
  * @param array $params
  * @param bool $isLineItem
  *
  * @return array
  */
 public static function checkTaxAmount($params, $isLineItem = FALSE)
 {
     $taxRates = CRM_Core_PseudoConstant::getTaxRates();
     // Update contribution.
     if (!empty($params['id'])) {
         // CRM-19126 and CRM-19152 If neither total or financial_type_id are set on an update
         // there are no tax implications - early return.
         if (!isset($params['total_amount']) && !isset($params['financial_type_id'])) {
             return $params;
         }
         if (empty($params['prevContribution'])) {
             $params['prevContribution'] = self::getOriginalContribution($params['id']);
         }
         foreach (array('total_amount', 'financial_type_id', 'fee_amount') as $field) {
             if (!isset($params[$field])) {
                 if ($field == 'total_amount' && $params['prevContribution']->tax_amount) {
                     // Tax amount gets added back on later....
                     $params['total_amount'] = $params['prevContribution']->total_amount - $params['prevContribution']->tax_amount;
                 } else {
                     $params[$field] = $params['prevContribution']->{$field};
                     if ($params[$field] != $params['prevContribution']->{$field}) {
                     }
                 }
             }
         }
         self::calculateMissingAmountParams($params, $params['id']);
         if (!array_key_exists($params['financial_type_id'], $taxRates)) {
             // Assign tax Amount on update of contribution
             if (!empty($params['prevContribution']->tax_amount)) {
                 $params['tax_amount'] = 'null';
                 CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
                 foreach ($params['line_item'] as $setID => $priceField) {
                     foreach ($priceField as $priceFieldID => $priceFieldValue) {
                         $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
                     }
                 }
             }
         }
     }
     // New Contribution and update of contribution with tax rate financial type
     if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && empty($params['skipLineItem']) && !$isLineItem) {
         $taxRateParams = $taxRates[$params['financial_type_id']];
         $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams);
         $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
         // Get Line Item on update of contribution
         if (isset($params['id'])) {
             CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
         } else {
             CRM_Price_BAO_LineItem::getLineItemArray($params);
         }
         foreach ($params['line_item'] as $setID => $priceField) {
             foreach ($priceField as $priceFieldID => $priceFieldValue) {
                 $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
             }
         }
         $params['total_amount'] = CRM_Utils_Array::value('total_amount', $params) + $params['tax_amount'];
     } elseif (isset($params['api.line_item.create'])) {
         // Update total amount of contribution using lineItem
         $taxAmountArray = array();
         foreach ($params['api.line_item.create'] as $key => $value) {
             if (isset($value['financial_type_id']) && array_key_exists($value['financial_type_id'], $taxRates)) {
                 $taxRate = $taxRates[$value['financial_type_id']];
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($value['line_total'], $taxRate);
                 $taxAmountArray[] = round($taxAmount['tax_amount'], 2);
             }
         }
         $params['tax_amount'] = array_sum($taxAmountArray);
         $params['total_amount'] = $params['total_amount'] + $params['tax_amount'];
     } else {
         // update line item of contrbution
         if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && $isLineItem) {
             $taxRate = $taxRates[$params['financial_type_id']];
             $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate);
             $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
         }
     }
     return $params;
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:86,代码来源:Contribution.php

示例12: processContribution


//.........这里部分代码省略.........
             }
         } elseif (!CRM_Utils_Array::value('is_quick_config', $form->_params)) {
             CRM_Contribute_Form_AdditionalInfo::processPriceSet($contribution->id, $form->_lineItem);
         }
         if (!$form->_separateMembershipPayment && CRM_Utils_Array::value('is_quick_config', $form->_params)) {
             $form->_lineItem = null;
         }
     }
     //handle pledge stuff.
     if (!CRM_Utils_Array::value('separate_membership_payment', $form->_params) && CRM_Utils_Array::value('pledge_block_id', $form->_values) && (CRM_Utils_Array::value('is_pledge', $form->_params) || CRM_Utils_Array::value('pledge_id', $form->_values))) {
         if (CRM_Utils_Array::value('pledge_id', $form->_values)) {
             //when user doing pledge payments.
             //update the schedule when payment(s) are made
             foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
                 $scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
                 $pledgePaymentParams = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $scheduledAmount);
                 CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
             }
             //update pledge status according to the new payment statuses
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
         } else {
             //when user creating pledge record.
             $pledgeParams = array();
             $pledgeParams['contact_id'] = $contribution->contact_id;
             $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
             $pledgeParams['contribution_id'] = $contribution->id;
             $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
             $pledgeParams['contribution_type_id'] = $contribution->contribution_type_id;
             $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
             $pledgeParams['installments'] = $params['pledge_installments'];
             $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
             if ($pledgeParams['frequency_unit'] == 'month') {
                 $pledgeParams['frequency_day'] = intval(date("d"));
             } else {
                 $pledgeParams['frequency_day'] = 1;
             }
             $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
             $pledgeParams['status_id'] = $contribution->contribution_status_id;
             $pledgeParams['max_reminders'] = $form->_values['max_reminders'];
             $pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
             $pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
             $pledgeParams['is_test'] = $contribution->is_test;
             $pledgeParams['acknowledge_date'] = date('Ymd');
             $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
             //inherit campaign from contirb page.
             $pledgeParams['campaign_id'] = $campaignId;
             $pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
             $form->_params['pledge_id'] = $pledge->id;
             //send acknowledgment email. only when pledge is created
             if ($pledge->id) {
                 //build params to send acknowledgment.
                 $pledgeParams['id'] = $pledge->id;
                 $pledgeParams['receipt_from_name'] = $form->_values['receipt_from_name'];
                 $pledgeParams['receipt_from_email'] = $form->_values['receipt_from_email'];
                 //scheduled amount will be same as installment_amount.
                 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
                 //get total pledge amount.
                 $pledgeParams['total_pledge_amount'] = $pledge->amount;
                 CRM_Pledge_BAO_Pledge::sendAcknowledgment($form, $pledgeParams);
             }
         }
     }
     if ($online && $contribution) {
         CRM_Core_BAO_CustomValueTable::postProcess($form->_params, CRM_Core_DAO::$_nullArray, 'civicrm_contribution', $contribution->id, 'Contribution');
     } elseif ($contribution) {
         //handle custom data.
         $params['contribution_id'] = $contribution->id;
         if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom']) && !is_a($contribution, 'CRM_Core_Error')) {
             CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
         }
     }
     if (isset($params['related_contact'])) {
         $contactID = $params['related_contact'];
     } elseif (isset($params['cms_contactID'])) {
         $contactID = $params['cms_contactID'];
     }
     CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email-' . $form->_bltID);
     // return if pending
     if ($pending) {
         return $contribution;
     }
     // next create the transaction record
     if ($contribution && (!$online || $form->_values['is_monetary']) && $result['trxn_id']) {
         $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $params['amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'currency' => $params['currencyID'], 'payment_processor' => $form->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id'], 'trxn_result_code' => isset($result['trxn_result_code']) ? $result['trxn_result_code'] : FALSE);
         $trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
     }
     //create contribution activity w/ individual and target
     //activity w/ organisation contact id when onbelf, CRM-4027
     $targetContactID = NULL;
     if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
         $targetContactID = $contribution->contact_id;
         $contribution->contact_id = $contactID;
     }
     // create an activity record
     if ($contribution) {
         CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
     }
     $transaction->commit();
     return $contribution;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Confirm.php

示例13: alterDisplay

 /**
  * @param $rows
  */
 function alterDisplay(&$rows)
 {
     require_once 'CRM/Contribute/BAO/Contribution/Utils.php';
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Utils/Date.php';
     $config =& CRM_Core_Config::singleton();
     // custom code to alter rows
     $checkList = array();
     $entryFound = FALSE;
     $display_flag = $prev_cid = $cid = 0;
     $contributionTypes = CRM_Contribute_PseudoConstant::contributionType();
     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) {
                             if (in_array($colName, $this->_noRepeats)) {
                                 unset($rows[$rowNum][$colName]);
                             }
                         }
                     }
                     $entryFound = TRUE;
                 }
             }
         }
         if (array_key_exists('first_contribution', $row) || array_key_exists('last_contribution', $row)) {
             $details = CRM_Contribute_BAO_Contribution_Utils::getFirstLastDetails($row['civicrm_contact_id']);
             if ($details['first']) {
                 $rows[$rowNum]['first_contribution'] = CRM_Utils_Money::format($details['first']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['first']['receive_date'], $config->dateformatFull);
             }
             if ($details['last']) {
                 $rows[$rowNum]['last_contribution'] = CRM_Utils_Money::format($details['last']['total_amount']) . ' - ' . CRM_Utils_Date::customFormat($details['last']['receive_date'], $config->dateformatFull);
             }
         }
         // handle state province
         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);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "state_province_id_op=in&state_province_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("List all contribution(s) for this State.");
             }
             $entryFound = TRUE;
         }
         // handle country
         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);
                 $url = CRM_Report_Utils_Report::getNextUrl('contribute/detail', "reset=1&force=1&" . "country_id_op=in&country_id_value={$value}", $this->_absoluteUrl, $this->_id);
                 $rows[$rowNum]['civicrm_address_country_id_link'] = $url;
                 $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("List all contribution(s) for this Country.");
             }
             $entryFound = TRUE;
         }
         // convert display name to links
         if (array_key_exists('civicrm_contact_display_name', $row) && !empty($rows[$rowNum]['civicrm_contact_display_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_display_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_display_name_hover'] = ts("View Contact Summary for this Contact.");
         }
         // convert soft credit id to link
         if (array_key_exists('soft_credit_display_name', $row) && !empty($rows[$rowNum]['soft_credit_display_name']) && array_key_exists('id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['id'], $this->_absoluteUrl);
             $rows[$rowNum]['soft_credit_display_name_creditor_link'] = $url;
             $rows[$rowNum]['soft_credit_display_name_creditor_hover'] = ts("View Contact Summary for this Soft Credit.");
         }
         // convert hon/mem contact to link
         if (array_key_exists('civicrm_contact_hon_mem_display_name', $row) && !empty($rows[$rowNum]['civicrm_contribution_honor_contact_id']) && array_key_exists('civicrm_contribution_honor_contact_id', $row)) {
             $url = CRM_Utils_System::url("civicrm/contact/view", 'reset=1&cid=' . $row['civicrm_contribution_honor_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_hon_mem_display_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_hon_mem_display_name_hover'] = ts("View Contact Summary for this Honor/Memory Contribution.");
         }
         // honor of/memory of type
         if ($value = CRM_Utils_Array::value('civicrm_contribution_honor_type_id', $row) && !empty($rows[$rowNum]['civicrm_contribution_honor_type_id'])) {
             // rather than do a join, just change the output here, since there these values are pretty static
             if ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 1) {
                 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Honor Of";
             } elseif ($rows[$rowNum]['civicrm_contribution_honor_type_id'] == 2) {
                 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "In Memory Of";
             } else {
                 $rows[$rowNum]['civicrm_contribution_honor_type_id'] = "n/a";
             }
         }
         if ($value = CRM_Utils_Array::value('civicrm_contribution_contribution_type_id', $row)) {
//.........这里部分代码省略.........
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Baykeeper.php

示例14: processFormSubmission


//.........这里部分代码省略.........
             $this->set('membershipTypeID', $this->_params['selectMembership']);
         }
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $membershipParams['is_test'] = 1;
         }
         if ($this->_params['is_pay_later']) {
             $membershipParams['is_pay_later'] = 1;
         }
     }
     if ($processMembership) {
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE);
         // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
         if (isset($this->_params['related_contact'])) {
             $membershipParams['cms_contactID'] = $this->_params['related_contact'];
         } else {
             $membershipParams['cms_contactID'] = $contactID;
         }
         //inherit campaign from contribution page.
         if (!array_key_exists('campaign_id', $membershipParams)) {
             $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
         }
         if (!empty($membershipParams['onbehalf']) && is_array($membershipParams['onbehalf']) && !empty($membershipParams['onbehalf']['member_campaign_id'])) {
             $this->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
         }
         $customFieldsFormatted = $fieldTypes = array();
         if (!empty($membershipParams['onbehalf']) && is_array($membershipParams['onbehalf'])) {
             foreach ($membershipParams['onbehalf'] as $key => $value) {
                 if (strstr($key, 'custom_')) {
                     $customFieldId = explode('_', $key);
                     CRM_Core_BAO_CustomField::formatCustomField($customFieldId[1], $customFieldsFormatted, $value, 'Membership', NULL, $contactID);
                 }
             }
             $fieldTypes = array('Contact', 'Organization', 'Membership');
         }
         $priceFieldIds = $this->get('memberPriceFieldIDS');
         if (!empty($priceFieldIds)) {
             $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
             unset($priceFieldIds['id']);
             $membershipTypeIds = array();
             $membershipTypeTerms = array();
             foreach ($priceFieldIds as $priceFieldId) {
                 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
                     $membershipTypeIds[] = $id;
                     //@todo the value for $term is immediately overwritten. It is unclear from the code whether it was intentional to
                     // do this or a double = was intended (this ambiguity is the reason many IDEs complain about 'assignment in condition'
                     $term = 1;
                     if ($term = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
                         $membershipTypeTerms[$id] = $term > 1 ? $term : 1;
                     } else {
                         $membershipTypeTerms[$id] = 1;
                     }
                 }
             }
             $membershipParams['selectMembership'] = $membershipTypeIds;
             $membershipParams['financial_type_id'] = $contributionTypeID;
             $membershipParams['types_terms'] = $membershipTypeTerms;
         }
         if (!empty($membershipParams['selectMembership'])) {
             // CRM-12233
             $membershipLineItems = array();
             if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) {
                 foreach ($this->_values['fee'] as $key => $feeValues) {
                     if ($feeValues['name'] == 'membership_amount') {
                         $fieldId = $this->_params['price_' . $key];
                         $membershipLineItems[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
                         unset($this->_lineItem[$this->_priceSetId][$fieldId]);
                         break;
                     }
                 }
             }
             $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems, $isPayLater);
             if (!$this->_amount > 0.0 || !$membershipParams['amount']) {
                 // we need to explicitly create a CMS user in case of free memberships
                 // since it is done under processConfirm for paid memberships
                 CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, $membershipParams['cms_contactID'], 'email-' . $this->_bltID);
             }
         }
     } else {
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         $contributionTypeId = $this->_values['financial_type_id'];
         $fieldTypes = array();
         if (!empty($paymentParams['onbehalf']) && is_array($paymentParams['onbehalf'])) {
             foreach ($paymentParams['onbehalf'] as $key => $value) {
                 if (strstr($key, 'custom_')) {
                     $this->_params[$key] = $value;
                 }
             }
             $fieldTypes = array('Contact', 'Organization', 'Contribution');
         }
         $financialTypeID = $this->wrangleFinancialTypeID($contributionTypeId);
         $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $premiumParams, $contactID, $financialTypeID, 'contribution', $fieldTypes, $this->_mode == 'test' ? 1 : 0, $isPayLater);
         if (CRM_Utils_Array::value('contribution_status_id', $result) == 1) {
             civicrm_api3('contribution', 'completetransaction', array('id' => $result['contribution']->id, 'trxn_id' => CRM_Utils_Array::value('trxn_id', $result)));
         }
         return $result;
     }
 }
开发者ID:vakeesan26,项目名称:civicrm-core,代码行数:101,代码来源:Confirm.php

示例15: formatAPIParams

 /**
  * @param array $apiParams
  * @param $mapper
  * @param string $type
  * @param bool $category
  *
  * @return array
  */
 public static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE)
 {
     $type = strtolower($type);
     if (!in_array($type, array('paypal', 'csv'))) {
         // return the params as is
         return $apiParams;
     }
     $params = $transaction = array();
     if ($type == 'paypal') {
         foreach ($apiParams as $detail => $val) {
             if (isset($mapper['contact'][$detail])) {
                 $params[$mapper['contact'][$detail]] = $val;
             } elseif (isset($mapper['location'][$detail])) {
                 $params['address'][1][$mapper['location'][$detail]] = $val;
             } elseif (isset($mapper['transaction'][$detail])) {
                 switch ($detail) {
                     case 'l_period2':
                         // Sadly, PayPal seems to send two distinct data elements in a single field,
                         // so we break them out here.  This is somewhat ugly and tragic.
                         $freqUnits = array('D' => 'day', 'W' => 'week', 'M' => 'month', 'Y' => 'year');
                         list($frequency_interval, $frequency_unit) = explode(' ', $val);
                         $transaction['frequency_interval'] = $frequency_interval;
                         $transaction['frequency_unit'] = $freqUnits[$frequency_unit];
                         break;
                     case 'subscriptiondate':
                     case 'timestamp':
                         // PayPal dates are in  ISO-8601 format.  We need a format that
                         // MySQL likes
                         $unix_timestamp = strtotime($val);
                         $transaction[$mapper['transaction'][$detail]] = date('YmdHis', $unix_timestamp);
                         break;
                     case 'note':
                     case 'custom':
                     case 'l_number0':
                         if ($val) {
                             $val = "[PayPal_field:{$detail}] {$val}";
                             $transaction[$mapper['transaction'][$detail]] = !empty($transaction[$mapper['transaction'][$detail]]) ? $transaction[$mapper['transaction'][$detail]] . " <br/> " . $val : $val;
                         }
                         break;
                     default:
                         $transaction[$mapper['transaction'][$detail]] = $val;
                 }
             }
         }
         if (!empty($transaction) && $category) {
             $params['transaction'] = $transaction;
         } else {
             $params += $transaction;
         }
         CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
         return $params;
     }
     if ($type == 'csv') {
         $header = $apiParams['header'];
         unset($apiParams['header']);
         foreach ($apiParams as $key => $val) {
             if (isset($mapper['contact'][$header[$key]])) {
                 $params[$mapper['contact'][$header[$key]]] = $val;
             } elseif (isset($mapper['location'][$header[$key]])) {
                 $params['address'][1][$mapper['location'][$header[$key]]] = $val;
             } elseif (isset($mapper['transaction'][$header[$key]])) {
                 $transaction[$mapper['transaction'][$header[$key]]] = $val;
             } else {
                 $params[$header[$key]] = $val;
             }
         }
         if (!empty($transaction) && $category) {
             $params['transaction'] = $transaction;
         } else {
             $params += $transaction;
         }
         CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
         return $params;
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:83,代码来源:ContributionProcessor.php


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