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


PHP CRM_Price_BAO_LineItem::getLineItemArray方法代码示例

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


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

示例1: 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

示例2: import


//.........这里部分代码省略.........
         }
         $formatValues = array();
         foreach ($params as $key => $field) {
             if ($field == NULL || $field === '') {
                 continue;
             }
             $formatValues[$key] = $field;
         }
         //format params to meet api v2 requirements.
         //@todo find a way to test removing this formatting
         $formatError = $this->membership_format_params($formatValues, $formatted, TRUE);
         if ($onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE) {
             $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Membership');
         } else {
             //fix for CRM-2219 Update Membership
             // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE
             if (!empty($formatted['is_override']) && empty($formatted['status_id'])) {
                 array_unshift($values, 'Required parameter missing: Status');
                 return CRM_Import_Parser::ERROR;
             }
             if (!empty($formatValues['membership_id'])) {
                 $dao = new CRM_Member_BAO_Membership();
                 $dao->id = $formatValues['membership_id'];
                 $dates = array('join_date', 'start_date', 'end_date');
                 foreach ($dates as $v) {
                     if (empty($formatted[$v])) {
                         $formatted[$v] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $formatValues['membership_id'], $v);
                     }
                 }
                 $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, $formatValues['membership_id'], 'Membership');
                 if ($dao->find(TRUE)) {
                     $ids = array('membership' => $formatValues['membership_id'], 'userId' => $session->get('userID'));
                     if (empty($params['line_item']) && !empty($formatted['membership_type_id'])) {
                         CRM_Price_BAO_LineItem::getLineItemArray($formatted, NULL, 'membership', $formatted['membership_type_id']);
                     }
                     $newMembership = CRM_Member_BAO_Membership::create($formatted, $ids, TRUE);
                     if (civicrm_error($newMembership)) {
                         array_unshift($values, $newMembership['is_error'] . ' for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
                         return CRM_Import_Parser::ERROR;
                     } else {
                         $this->_newMemberships[] = $newMembership->id;
                         return CRM_Import_Parser::VALID;
                     }
                 } else {
                     array_unshift($values, 'Matching Membership record not found for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
                     return CRM_Import_Parser::ERROR;
                 }
             }
         }
         //Format dates
         $startDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $formatted), '%Y-%m-%d');
         $endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $formatted), '%Y-%m-%d');
         $joinDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $formatted), '%Y-%m-%d');
         if ($this->_contactIdIndex < 0) {
             //retrieve contact id using contact dedupe rule
             $formatValues['contact_type'] = $this->_contactType;
             $formatValues['version'] = 3;
             require_once 'CRM/Utils/DeprecatedUtils.php';
             $error = _civicrm_api3_deprecated_check_contact_dedupe($formatValues);
             if (CRM_Core_Error::isAPIError($error, CRM_Core_ERROR::DUPLICATE_CONTACT)) {
                 $matchedIDs = explode(',', $error['error_message']['params'][0]);
                 if (count($matchedIDs) > 1) {
                     array_unshift($values, 'Multiple matching contact records detected for this row. The membership was not imported');
                     return CRM_Import_Parser::ERROR;
                 } else {
                     $cid = $matchedIDs[0];
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:67,代码来源:Membership.php

示例3: recordFinancialAccounts

 /**
  * Function to create all financial accounts entry
  *
  * @param array $params contribution object, line item array and params for trxn
  *
  *
  * @access public
  * @static
  */
 static function recordFinancialAccounts(&$params)
 {
     $skipRecords = $update = FALSE;
     $additionalParticipantId = array();
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if (CRM_Utils_Array::value('contribution_mode', $params) == 'participant') {
         $entityId = $params['participant_id'];
         $entityTable = 'civicrm_participant';
         $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId);
     } else {
         $entityId = $params['contribution']->id;
         $entityTable = 'civicrm_contribution';
     }
     $entityID[] = $entityId;
     if (!empty($additionalParticipantId)) {
         $entityID += $additionalParticipantId;
     }
     // prevContribution appears to mean - original contribution object- ie copy of contribution from before the update started that is being updated
     if (!CRM_Utils_Array::value('prevContribution', $params)) {
         $entityID = NULL;
     } else {
         $update = TRUE;
     }
     // build line item array if its not set in $params
     if (!CRM_Utils_Array::value('line_item', $params) || $additionalParticipantId) {
         CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable));
     }
     if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Failed', $contributionStatuses) && !(CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses) && !$params['contribution']->is_pay_later)) {
         $skipRecords = TRUE;
         $pendingStatus = array(array_search('Pending', $contributionStatuses), array_search('In Progress', $contributionStatuses));
         if (in_array(CRM_Utils_Array::value('contribution_status_id', $params), $pendingStatus)) {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
             $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId);
         } elseif (CRM_Utils_Array::value('payment_processor', $params)) {
             $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
         } elseif (CRM_Utils_Array::value('payment_instrument_id', $params)) {
             $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['payment_instrument_id']);
         } else {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' "));
             $queryParams = array(1 => array($relationTypeId, 'Integer'));
             $params['to_financial_account_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams);
         }
         $totalAmount = CRM_Utils_Array::value('total_amount', $params);
         if (!isset($totalAmount) && CRM_Utils_Array::value('prevContribution', $params)) {
             $totalAmount = $params['total_amount'] = $params['prevContribution']->total_amount;
         }
         //build financial transaction params
         $trxnParams = array('contribution_id' => $params['contribution']->id, 'to_financial_account_id' => $params['to_financial_account_id'], 'trxn_date' => date('YmdHis'), 'total_amount' => $totalAmount, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'net_amount' => CRM_Utils_Array::value('net_amount', $params), 'currency' => $params['contribution']->currency, 'trxn_id' => $params['contribution']->trxn_id, 'status_id' => $params['contribution']->contribution_status_id, 'payment_instrument_id' => $params['contribution']->payment_instrument_id, 'check_number' => CRM_Utils_Array::value('check_number', $params));
         if (CRM_Utils_Array::value('payment_processor', $params)) {
             $trxnParams['payment_processor_id'] = $params['payment_processor'];
         }
         $params['trxnParams'] = $trxnParams;
         if (CRM_Utils_Array::value('prevContribution', $params)) {
             $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount;
             $params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount;
             $params['trxnParams']['net_amount'] = $params['prevContribution']->net_amount;
             $params['trxnParams']['trxn_id'] = $params['prevContribution']->trxn_id;
             $params['trxnParams']['status_id'] = $params['prevContribution']->contribution_status_id;
             $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
             $params['trxnParams']['check_number'] = $params['prevContribution']->check_number;
             //if financial type is changed
             if (CRM_Utils_Array::value('financial_type_id', $params) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) {
                 $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
                 $oldFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $incomeTypeId);
                 $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId);
                 if ($oldFinancialAccount != $newFinancialAccount) {
                     $params['total_amount'] = 0;
                     if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) {
                         $params['trxnParams']['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId);
                     } else {
                         $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC');
                         if (CRM_Utils_Array::value('financialTrxnId', $lastFinancialTrxnId)) {
                             $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
                         }
                     }
                     self::updateFinancialAccounts($params, 'changeFinancialType');
                     /* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */
                     $params['financial_account_id'] = $newFinancialAccount;
                     $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount'];
                     self::updateFinancialAccounts($params);
                     $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
                 }
             }
             //Update contribution status
             $params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id;
             if (CRM_Utils_Array::value('contribution_status_id', $params) && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) {
                 //Update Financial Records
                 self::updateFinancialAccounts($params, 'changedStatus');
             }
             // change Payment Instrument for a Completed contribution
             // first handle special case when contribution is changed from Pending to Completed status when initial payment
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:Contribution.php

示例4: civicrm_api3_membership_create

/**
 * Create a Contact Membership.
 *
 * This API is used for creating a Membership for a contact.
 * Required parameters : membership_type_id and status_id.
 *
 * @param array $params
 *   Array of name/value property values of civicrm_membership.
 *
 * @return array
 *   API result array.
 */
function civicrm_api3_membership_create($params)
{
    // check params for membership id during update
    if (!empty($params['id']) && !isset($params['skipStatusCal'])) {
        // Don't calculate status on existing membership - expect API use to pass them in
        // or leave unchanged.
        $params['skipStatusCal'] = 1;
    } else {
        // also check for status id if override is set (during add/update)
        if (!empty($params['is_override']) && empty($params['status_id'])) {
            return civicrm_api3_create_error('Status ID required');
        }
    }
    $values = array();
    _civicrm_api3_custom_format_params($params, $values, 'Membership');
    $params = array_merge($params, $values);
    // Fixme: This code belongs in the BAO
    if (empty($params['id']) || !empty($params['num_terms'])) {
        if (empty($params['id'])) {
            $calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'], CRM_Utils_Array::value('join_date', $params), CRM_Utils_Array::value('start_date', $params), CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('num_terms', $params, 1));
        } else {
            $calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($params['id'], NULL, CRM_Utils_Array::value('membership_type_id', $params), $params['num_terms']);
        }
        foreach (array('join_date', 'start_date', 'end_date') as $date) {
            if (empty($params[$date]) && isset($calcDates[$date])) {
                $params[$date] = $calcDates[$date];
            }
        }
    }
    // Fixme: This code belongs in the BAO
    $action = CRM_Core_Action::ADD;
    // we need user id during add mode
    $ids = array();
    if (!empty($params['contact_id'])) {
        $ids['userId'] = $params['contact_id'];
    }
    //for edit membership id should be present
    if (!empty($params['id'])) {
        $ids['membership'] = $params['id'];
        $action = CRM_Core_Action::UPDATE;
    }
    //need to pass action to handle related memberships.
    $params['action'] = $action;
    if (empty($params['line_item']) && !empty($params['membership_type_id'])) {
        CRM_Price_BAO_LineItem::getLineItemArray($params, NULL, 'membership', $params['membership_type_id']);
    }
    $membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
    if (array_key_exists('is_error', $membershipBAO)) {
        // In case of no valid status for given dates, $membershipBAO
        // is going to contain 'is_error' => "Error Message"
        return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
    }
    $membership = array();
    _civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
    return civicrm_api3_create_success($membership, $params, 'Membership', 'create', $membershipBAO);
}
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:68,代码来源:Membership.php

示例5: 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

示例6: changeFeeSelections

 static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
 {
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
     $pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
     $fetchCon = array('id' => $contributionId);
     $contributionObj = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
     $previousLineItems = CRM_Price_BAO_LineItem::getLineItems($participantId, 'participant');
     CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItems);
     // get the submitted
     foreach ($feeBlock as $id => $values) {
         CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
         $submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
     }
     $insertLines = $submittedLineItems;
     $submittedFieldValueIds = array_keys($submittedLineItems);
     foreach ($previousLineItems as $id => $previousLineItem) {
         // check through the submitted items if the previousItem exists,
         // if found in submitted items, do not use it for new item creations
         if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
             unset($insertLines[$previousLineItem['price_field_value_id']]);
         }
     }
     $submittedFields = implode(', ', $submittedFieldId);
     $submittedFieldValues = implode(', ', $submittedFieldValueIds);
     if (!empty($submittedFields) && !empty($submittedFieldValues)) {
         // if previous line item is not submitted in selection, update the line total and QTY to '0'
         $updateLineItem = "\nUPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n   ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nINNER JOIN civicrm_entity_financial_trxn eft\n   ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET li.qty = 0,\n    li.line_total = 0.00,\n    fi.amount = 0.00,\n    eft.amount = 0.00\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n      (price_field_value_id NOT IN ({$submittedFieldValues}) OR price_field_id NOT IN ({$submittedFields}))\n";
         CRM_Core_DAO::executeQuery($updateLineItem);
     }
     // insert new line items
     foreach ($insertLines as $valueId => $lineParams) {
         $lineParams['entity_table'] = 'civicrm_participant';
         $lineParams['entity_id'] = $participantId;
         $lineObj = CRM_Price_BAO_LineItem::create($lineParams);
         // insert financial items
         // ensure entity_financial_trxn table has a linking of it.
         $prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $contributionObj);
     }
     // insert new 'adjusted amount' transaction entry and update contribution entry.
     // ensure entity_financial_trxn table has a linking of it.
     $updatedAmount = $params['amount'];
     $balanceAmt = $updatedAmount - $paidAmount;
     if ($balanceAmt) {
         if ($balanceAmt > 0) {
             $contributionStatusVal = $partiallyPaidStatusId;
         } elseif ($balanceAmt < 0) {
             $contributionStatusVal = $pendngRefundStatusId;
         }
         // update contribution status and total amount without trigger financial code
         // as this is handled in current BAO function used for change selection
         $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
         $updatedContributionDAO->id = $contributionId;
         $updatedContributionDAO->contribution_status_id = $contributionStatusVal;
         $updatedContributionDAO->total_amount = $updatedAmount;
         $updatedContributionDAO->save();
         /*
          * adjusted amount financial_trxn creation,
          * adjusted amount line_item creation,
          * adjusted amount financial_item creations,
          * adjusted amount enitity_financial_trxn creation
          */
         $updatedContribution = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contributionId), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
         $prevTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
         $fetchPrevTrxn['id'] = $prevTrxnId['financialTrxnId'];
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId);
         $adjustedTrxnValues = array('from_financial_account_id' => NULL, 'to_financial_account_id' => $toFinancialAccount, 'trxn_date' => date('YmdHis'), 'total_amount' => $balanceAmt, 'currency' => $updatedContribution->currency, 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), 'payment_instrument_id' => $updatedContribution->payment_instrument_id, 'contribution_id' => $updatedContribution->id);
         $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
         // record line item
         $adjustPaymentLineParams = array('total_amount' => $updatedAmount, 'financial_type_id' => $updatedContribution->financial_type_id);
         $setId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
         CRM_Price_BAO_LineItem::getLineItemArray($adjustPaymentLineParams);
         $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
         $defaultPriceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($setId));
         $fieldID = key($defaultPriceSet['fields']);
         $adjustPaymentLineParams['line_item'][$setId][$fieldID]['entity_id'] = $updatedContribution->id;
         $adjustPaymentLineParams['line_item'][$setId][$fieldID]['entity_table'] = 'civicrm_contribution';
         $adjustPaymentLine = CRM_Price_BAO_LineItem::create($adjustPaymentLineParams['line_item'][$setId][$fieldID]);
         // record financial item
         $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
         $itemStatus = NULL;
         if ($updatedContribution->contribution_status_id == array_search('Pending refund', $contributionStatuses)) {
             $itemStatus = array_search('Paid', $financialItemStatus);
         } elseif ($updatedContribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
             $itemStatus = array_search('Partially paid', $financialItemStatus);
         }
         $params = array('transaction_date' => CRM_Utils_Date::isoToMysql($updatedContribution->receive_date), 'contact_id' => $updatedContribution->contact_id, 'amount' => $balanceAmt, 'currency' => $updatedContribution->currency, 'entity_table' => 'civicrm_line_item', 'entity_id' => $adjustPaymentLine->id, 'description' => ($adjustPaymentLine->qty != 1 ? $lineItem->qty . ' of ' : '') . ' ' . $adjustPaymentLine->label, 'status_id' => $itemStatus, 'financial_account_id' => $prevItem->financial_account_id);
         CRM_Financial_BAO_FinancialItem::create($params, NULL, array('id' => $adjustedTrxn->id));
     }
     //activity creation$contributionStatuses
     self::addActivityForSelection($participantId, 'Change Registration');
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:93,代码来源:Participant.php


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