本文整理汇总了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类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 = C
|
请发表评论