本文整理汇总了PHP中CRM_Member_BAO_Membership::createLineItems方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Member_BAO_Membership::createLineItems方法的具体用法?PHP CRM_Member_BAO_Membership::createLineItems怎么用?PHP CRM_Member_BAO_Membership::createLineItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Member_BAO_Membership
的用法示例。
在下文中一共展示了CRM_Member_BAO_Membership::createLineItems方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Member_BAO_Membership::del($this->_id);
return;
}
$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
$isTest = $this->_mode == 'test' ? 1 : 0;
$lineItems = NULL;
if (!empty($this->_lineItem)) {
$lineItems = $this->_lineItem;
}
$config = CRM_Core_Config::singleton();
// get the submitted form values.
$this->_params = $formValues = $this->controller->exportValues($this->_name);
$this->convertDateFieldsToMySQL($formValues);
$params = $softParams = $ids = array();
$membershipTypeValues = array();
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['membership_type_id'] = $memType;
}
//take the required membership recur values.
if ($this->_mode && !empty($this->_params['auto_renew'])) {
$params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
$mapping = array('frequency_interval' => 'duration_interval', 'frequency_unit' => 'duration_unit');
$count = 0;
foreach ($this->_memTypeSelected as $memType) {
$recurMembershipTypeValues = CRM_Utils_Array::value($memType, $this->_recurMembershipTypes, array());
foreach ($mapping as $mapVal => $mapParam) {
$membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
if (!$count) {
$this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
}
}
$count++;
}
}
// process price set and get total amount and line items.
$lineItem = array();
$priceSetId = NULL;
if (!($priceSetId = CRM_Utils_Array::value('price_set_id', $formValues))) {
CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
}
$isQuickConfig = 0;
if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
$isQuickConfig = 1;
}
$termsByType = array();
if ($priceSetId) {
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
$params['tax_amount'] = $this->_params['tax_amount'];
}
$params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
if (!empty($lineItem[$priceSetId])) {
foreach ($lineItem[$priceSetId] as &$li) {
if (!empty($li['membership_type_id'])) {
if (!empty($li['membership_num_terms'])) {
$termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
}
}
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
}
}
$this->storeContactFields($formValues);
$params['contact_id'] = $this->_contactID;
$fields = array('status_id', 'source', 'is_override', 'campaign_id');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
// fix for CRM-3724
// when is_override false ignore is_admin statuses during membership
// status calculation. similarly we did fix for import in CRM-3570.
if (empty($params['is_override'])) {
$params['exclude_is_admin'] = TRUE;
}
// process date params to mysql date format.
$dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
}
$memTypeNumTerms = empty($termsByType) ? CRM_Utils_Array::value('num_terms', $formValues) : NULL;
$calcDates = array();
foreach ($this->_memTypeSelected as $memType) {
if (empty($memTypeNumTerms)) {
$memTypeNumTerms = CRM_Utils_Array::value($memType, $termsByType, 1);
//.........这里部分代码省略.........
示例2: postProcess
//.........这里部分代码省略.........
$renewalDate = NULL;
if ($formValues['renewal_date']) {
$this->set('renewalDate', CRM_Utils_Date::processDate($formValues['renewal_date']));
}
$this->_membershipId = $this->_id;
// membership type custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $formValues['membership_type_id'][1]);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
$customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
// check for test membership.
$isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
// chk for renewal for multiple terms CRM-8750
$numRenewTerms = 1;
if (is_numeric(CRM_Utils_Array::value('num_terms', $formValues))) {
$numRenewTerms = $formValues['num_terms'];
}
//if contribution status is pending then set pay later
if ($formValues['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
$this->_params['is_pay_later'] = 1;
}
$renewMembership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($this->_contactID, $formValues['membership_type_id'][1], $isTestMembership, $this, NULL, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId);
$endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
$memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
if (!empty($formValues['record_contribution']) || $this->_mode) {
// set the source
$formValues['contribution_source'] = "{$memType} Membership: Offline membership renewal (by {$userName})";
//create line items
$lineItem = array();
$priceSetId = NULL;
CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
//CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//line items with the financial type selected in form
if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues)) {
foreach ($lineItem[$priceSetId] as &$li) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
$formValues['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
if (!empty($lineItem)) {
$formValues['lineItems'] = $lineItem;
$formValues['processPriceSet'] = TRUE;
}
//assign contribution contact id to the field expected by recordMembershipContribution
if ($this->_contributorContactID != $this->_contactID) {
$formValues['contribution_contact_id'] = $this->_contributorContactID;
if (!empty($this->_params['soft_credit_type_id'])) {
$formValues['soft_credit'] = array('soft_credit_type_id' => $this->_params['soft_credit_type_id'], 'contact_id' => $this->_contactID);
}
}
$formValues['contact_id'] = $this->_contactID;
//recordMembershipContribution receives params as a reference & adds one variable. This is
// not a great pattern & ideally it would not receive as a reference. We assign our params as a
// temporary variable to avoid e-notice & to make it clear to future refactorer that
// this function is NOT reliant on that var being set
$temporaryParams = array_merge($formValues, array('membership_id' => $renewMembership->id));
CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
}
$receiptSend = FALSE;
if (!empty($formValues['send_receipt'])) {
$receiptSend = TRUE;
示例3: submit
/**
* Process form submission.
*
* This function is also accessed by a unit test.
*/
protected function submit()
{
$this->storeContactFields($this->_params);
$now = CRM_Utils_Date::getToday(NULL, 'YmdHis');
$this->convertDateFieldsToMySQL($this->_params);
$this->assign('receive_date', $this->_params['receive_date']);
$this->processBillingAddress($now);
list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID'));
$this->_params['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'));
$this->_membershipId = $this->_id;
$customFieldsFormatted = CRM_Core_BAO_CustomField::postProcess($this->_params, $this->_id, 'Membership');
if (empty($this->_params['financial_type_id'])) {
$this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
}
$this->assign('membershipID', $this->_id);
$this->assign('contactID', $this->_contactID);
$this->assign('module', 'Membership');
$this->assign('receiptType', 'membership renewal');
$this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
$this->_params['invoice_id'] = $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
if (!empty($this->_params['send_receipt'])) {
$this->_params['receipt_date'] = $now;
$this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($this->_params['receipt_date']));
} else {
$this->_params['receipt_date'] = NULL;
}
if ($this->_mode) {
$this->_params['register_date'] = $now;
$this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id']);
$this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
$this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
$this->assign('credit_card_exp_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format($this->_params['credit_card_exp_date'])));
$this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($this->_params['credit_card_number']));
$this->assign('credit_card_type', $this->_params['credit_card_type']);
$this->_params['description'] = ts("Contribution submitted by a staff person using member's credit card for renewal");
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $this->_params['total_amount'];
// 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 passed params
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
if (!empty($this->_params['send_receipt'])) {
$paymentParams['email'] = $this->_contributorEmail;
}
$paymentParams['contactID'] = $this->_contributorContactID;
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
$payment = $this->_paymentProcessor['object'];
if (!empty($this->_params['auto_renew'])) {
$contributionRecurParams = $this->processRecurringContribution($paymentParams);
$paymentParams = array_merge($paymentParams, $contributionRecurParams);
}
$result = $payment->doPayment($paymentParams);
$this->_params = array_merge($this->_params, $result);
$this->_params['contribution_status_id'] = $result['payment_status_id'];
$this->_params['trxn_id'] = $result['trxn_id'];
$this->_params['payment_instrument_id'] = 1;
$this->_params['is_test'] = $this->_mode == 'live' ? 0 : 1;
$this->set('params', $this->_params);
$this->assign('trxn_id', $result['trxn_id']);
}
$renewalDate = !empty($this->_params['renewal_date']) ? $renewalDate = CRM_Utils_Date::processDate($this->_params['renewal_date']) : NULL;
// check for test membership.
$isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
// chk for renewal for multiple terms CRM-8750
$numRenewTerms = 1;
if (is_numeric(CRM_Utils_Array::value('num_terms', $this->_params))) {
$numRenewTerms = $this->_params['num_terms'];
}
//if contribution status is pending then set pay later
$this->_params['is_pay_later'] = FALSE;
if ($this->_params['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
$this->_params['is_pay_later'] = 1;
}
// These variable sets prior to renewMembership may not be required for this form. They were in
// a function this form shared with other forms.
$contributionRecurID = isset($this->_params['contributionRecurID']) ? $this->_params['contributionRecurID'] : NULL;
$membershipSource = NULL;
if (!empty($this->_params['membership_source'])) {
$membershipSource = $this->_params['membership_source'];
}
$isPending = $this->_params['contribution_status_id'] == 2 ? TRUE : FALSE;
list($renewMembership) = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_params['membership_type_id'][1], $isTestMembership, $renewalDate, NULL, $customFieldsFormatted, $numRenewTerms, $this->_membershipId, $isPending, $contributionRecurID, $membershipSource, $this->_params['is_pay_later'], CRM_Utils_Array::value('campaign_id', $this->_params));
$this->endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
$this->membershipTypeName = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
if (!empty($this->_params['record_contribution']) || $this->_mode) {
// set the source
$this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})";
//create line items
$lineItem = array();
$priceSetId = CRM_Member_BAO_Membership::createLineItems($this, $this->_params['membership_type_id']);
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
//CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//line items with the financial type selected in form
if ($submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $this->_params)) {
//.........这里部分代码省略.........
示例4: submit
/**
* Submit function.
*
* This is also accessed by unit tests.
*
* @param array $formValues
*
* @return array
*/
public function submit($formValues)
{
$isTest = $this->_mode == 'test' ? 1 : 0;
$joinDate = $startDate = $endDate = NULL;
$membershipTypes = $membership = $calcDate = array();
$membershipType = NULL;
$mailSend = FALSE;
$priceSetID = CRM_Utils_Array::value('price_set_id', $formValues);
$params = $softParams = $ids = array();
$allMemberStatus = CRM_Member_PseudoConstant::membershipStatus();
$allContributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
if ($this->_id) {
$ids['membership'] = $params['id'] = $this->_id;
}
$ids['userId'] = CRM_Core_Session::singleton()->get('userID');
// Set variables that we normally get from context.
// In form mode these are set in preProcess.
//TODO: set memberships, fixme
$this->setContextVariables($formValues);
$this->_memTypeSelected = self::getSelectedMemberships($priceSetID, $formValues);
$config = CRM_Core_Config::singleton();
$this->convertDateFieldsToMySQL($formValues);
$membershipTypeValues = array();
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['membership_type_id'] = $memType;
}
//take the required membership recur values.
if ($this->_mode && !empty($formValues['auto_renew'])) {
$params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
$mapping = array('frequency_interval' => 'duration_interval', 'frequency_unit' => 'duration_unit');
$count = 0;
foreach ($this->_memTypeSelected as $memType) {
$recurMembershipTypeValues = CRM_Utils_Array::value($memType, $this->_recurMembershipTypes, array());
foreach ($mapping as $mapVal => $mapParam) {
$membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
if (!$count) {
$this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
}
}
$count++;
}
}
// process price set and get total amount and line items.
if (!$priceSetID) {
$priceSetID = CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], NULL);
}
$isQuickConfig = FALSE;
if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'is_quick_config')) {
$isQuickConfig = 1;
}
$termsByType = array();
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetID]);
if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
$params['tax_amount'] = $this->_params['tax_amount'];
}
$params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
$submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues);
if (!empty($lineItem[$priceSetID])) {
foreach ($lineItem[$priceSetID] as &$li) {
if (!empty($li['membership_type_id'])) {
if (!empty($li['membership_num_terms'])) {
$termsByType[$li['membership_type_id']] = $li['membership_num_terms'];
}
}
///CRM-11529 for quick config backoffice transactions
//when financial_type_id is passed in form, update the
//lineitems with the financial type selected in form
if ($isQuickConfig && $submittedFinancialType) {
$li['financial_type_id'] = $submittedFinancialType;
}
}
}
$this->storeContactFields($formValues);
$params['contact_id'] = $this->_contactID;
$fields = array('status_id', 'source', 'is_override', 'campaign_id');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
// fix for CRM-3724
// when is_override false ignore is_admin statuses during membership
// status calculation. similarly we did fix for import in CRM-3570.
if (empty($params['is_override'])) {
$params['exclude_is_admin'] = TRUE;
}
// process date params to mysql date format.
$dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
foreach ($dateTypes as $dateField => $dateVariable) {
${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
}
$memTypeNumTerms = empty($termsByType) ? CRM_Utils_Array::value('num_terms', $formValues) : NULL;
//.........这里部分代码省略.........