本文整理汇总了PHP中CRM_Contribute_BAO_Contribution::recordFinancialAccounts方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contribute_BAO_Contribution::recordFinancialAccounts方法的具体用法?PHP CRM_Contribute_BAO_Contribution::recordFinancialAccounts怎么用?PHP CRM_Contribute_BAO_Contribution::recordFinancialAccounts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contribute_BAO_Contribution
的用法示例。
在下文中一共展示了CRM_Contribute_BAO_Contribution::recordFinancialAccounts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: completeOrder
//.........这里部分代码省略.........
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
// @todo - we should pass membership_type_id instead of null here but not
// adding as not sure of testing
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'], $changeDate, NULL, $membershipParams['num_terms']);
$dates['join_date'] = $currentMembership['join_date'];
}
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membershipParams['membership_type_id'], $membershipParams);
$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
//we might be renewing membership,
//so make status override false.
$membershipParams['is_override'] = FALSE;
civicrm_api3('Membership', 'create', $membershipParams);
//update related Memberships.
CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $membershipParams);
}
}
}
} else {
if (empty($input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'])) {
$eventDetail = civicrm_api3('Event', 'getsingle', array('id' => $objects['event']->id));
$contributionParams['source'] = ts('Online Event Registration') . ': ' . $eventDetail['title'];
if ($eventDetail['is_email_confirm']) {
// @todo this should be set by the function that sends the mail after sending.
$contributionParams['receipt_date'] = $changeDate;
}
$participantParams['id'] = $participant->id;
$participantParams['status_id'] = 'Registered';
civicrm_api3('Participant', 'create', $participantParams);
}
}
$contributionParams['id'] = $contribution->id;
civicrm_api3('Contribution', 'create', $contributionParams);
// Add new soft credit against current $contribution.
if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id) {
CRM_Contribute_BAO_ContributionRecur::addrecurSoftCredit($objects['contributionRecur']->id, $contribution->id);
}
$paymentProcessorId = '';
if (isset($objects['paymentProcessor'])) {
if (is_array($objects['paymentProcessor'])) {
$paymentProcessorId = $objects['paymentProcessor']['id'];
} else {
$paymentProcessorId = $objects['paymentProcessor']->id;
}
}
$contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1));
if (empty($input['prevContribution']) && $paymentProcessorId || !$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == $contributionStatuses['Pending']) {
$input['payment_processor'] = $paymentProcessorId;
}
$input['contribution_status_id'] = $contributionStatuses['Completed'];
$input['total_amount'] = $input['amount'];
$input['contribution'] = $contribution;
$input['financial_type_id'] = $contribution->financial_type_id;
if (!empty($contribution->_relatedObjects['participant'])) {
$input['contribution_mode'] = 'participant';
$input['participant_id'] = $contribution->_relatedObjects['participant']->id;
$input['skipLineItem'] = 1;
} elseif (!empty($contribution->_relatedObjects['membership'])) {
$input['skipLineItem'] = TRUE;
$input['contribution_mode'] = 'membership';
}
//@todo writing a unit test I was unable to create a scenario where this line did not fatal on second
// and subsequent payments. In this case the line items are created at
// CRM_Contribute_BAO_ContributionRecur::addRecurLineItems
// and since the contribution is saved prior to this line there is always a contribution-id,
// however there is never a prevContribution (which appears to mean original contribution not previous
// contribution - or preUpdateContributionObject most accurately)
// so, this is always called & only appears to succeed when prevContribution exists - which appears
// to mean "are we updating an exisitng pending contribution"
//I was able to make the unit test complete as fataling here doesn't prevent
// the contribution being created - but activities would not be created or emails sent
CRM_Contribute_BAO_Contribution::recordFinancialAccounts($input, NULL);
CRM_Core_Error::debug_log_message("Contribution record updated successfully");
$transaction->commit();
CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contribution);
// create an activity record
if ($input['component'] == 'contribute') {
//CRM-4027
$targetContactID = NULL;
if (!empty($ids['related_contact'])) {
$targetContactID = $contribution->contact_id;
$contribution->contact_id = $ids['related_contact'];
}
CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
// event
} else {
CRM_Activity_BAO_Activity::addActivity($participant);
}
// CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending
// when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set
if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) {
self::sendMail($input, $ids, $objects['contribution'], $values, $recur, FALSE);
CRM_Core_Error::debug_log_message("Receipt sent");
}
CRM_Core_Error::debug_log_message("Success: Database updated");
if ($isRecurring) {
CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur, $isFirstOrLastRecurringPayment);
}
}
示例2: completeTransaction
//.........这里部分代码省略.........
}
if (CRM_Utils_Array::value('payment_instrument_id', $input)) {
$contribution->payment_instrument_id = $input['payment_instrument_id'];
}
if (!empty($contribution->id)) {
$contributionId['id'] = $contribution->id;
$input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues($contributionId, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
}
$contribution->save();
//add line items for recurring payments
if (!empty($contribution->contribution_recur_id)) {
if ($isNewContribution) {
$input['line_item'] = $this->addRecurLineItems($contribution->contribution_recur_id, $contribution);
} else {
// this is just to prevent e-notices when we call recordFinancialAccounts - per comments on that line - intention is somewhat unclear
$input['line_item'] = array();
}
if (!empty($memberships) && $primaryContributionID != $contribution->id) {
foreach ($memberships as $membership) {
try {
$membershipPayment = array('membership_id' => $membership->id, 'contribution_id' => $contribution->id);
if (!civicrm_api3('membership_payment', 'getcount', $membershipPayment)) {
civicrm_api3('membership_payment', 'create', $membershipPayment);
}
} catch (CiviCRM_API3_Exception $e) {
echo $e->getMessage();
// we are catching & ignoring errors as an extra precaution since lost IPNs may be more serious that lost membership_payment data
// this fn is unit-tested so risk of changes elsewhere breaking it are otherwise mitigated
}
}
}
}
//copy initial contribution custom fields for recurring contributions
if ($recurContrib && $recurContrib->id) {
$this->copyCustomValues($recurContrib->id, $contribution->id);
}
// next create the transaction record
$paymentProcessor = $paymentProcessorId = '';
if (isset($objects['paymentProcessor'])) {
if (is_array($objects['paymentProcessor'])) {
$paymentProcessor = $objects['paymentProcessor']['payment_processor_type'];
$paymentProcessorId = $objects['paymentProcessor']['id'];
} else {
$paymentProcessor = $objects['paymentProcessor']->payment_processor_type;
$paymentProcessorId = $objects['paymentProcessor']->id;
}
}
//it's hard to see how it could reach this point without a contributon id as it is saved in line 511 above
// which raised the question as to whether this check preceded line 511 & if so whether something could be broken
// From a lot of code reading /debugging I'm still not sure the intent WRT first & subsequent payments in this code
// it would be good if someone added some comments or refactored this
if ($contribution->id) {
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (empty($input['prevContribution']) && $paymentProcessorId || !$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses)) {
$input['payment_processor'] = $paymentProcessorId;
}
$input['contribution_status_id'] = array_search('Completed', $contributionStatuses);
$input['total_amount'] = $input['amount'];
$input['contribution'] = $contribution;
$input['financial_type_id'] = $contribution->financial_type_id;
if (CRM_Utils_Array::value('participant', $contribution->_relatedObjects)) {
$input['contribution_mode'] = 'participant';
$input['participant_id'] = $contribution->_relatedObjects['participant']->id;
$input['skipLineItem'] = 1;
}
//@todo writing a unit test I was unable to create a scenario where this line did not fatal on second
// and subsequent payments. In this case the line items are created at $this->addRecurLineItems
// and since the contribution is saved prior to this line there is always a contribution-id,
// however there is never a prevContribution (which appears to mean original contribution not previous
// contribution - or preUpdateContributionObject most accurately)
// so, this is always called & only appears to succeed when prevContribution exists - which appears
// to mean "are we updating an exisitng pending contribution"
//I was able to make the unit test complete as fataling here doesn't prevent
// the contribution being created - but activities would not be created or emails sent
CRM_Contribute_BAO_Contribution::recordFinancialAccounts($input, NULL);
}
self::updateRecurLinkedPledge($contribution);
// create an activity record
if ($input['component'] == 'contribute') {
//CRM-4027
$targetContactID = NULL;
if (CRM_Utils_Array::value('related_contact', $ids)) {
$targetContactID = $contribution->contact_id;
$contribution->contact_id = $ids['related_contact'];
}
CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
// event
} else {
CRM_Activity_BAO_Activity::addActivity($participant);
}
CRM_Core_Error::debug_log_message("Contribution record updated successfully");
$transaction->commit();
// CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending
// when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set
if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) {
self::sendMail($input, $ids, $objects, $values, $recur, FALSE);
CRM_Core_Error::debug_log_message("Receipt sent");
}
CRM_Core_Error::debug_log_message("Success: Database updated");
}
示例3: recordAdditionalPayment
/**
* Function to record additional payment for partial and refund contributions.
*
* @param int $contributionId
* is the invoice contribution id (got created after processing participant payment).
* @param array $trxnsData
* to take user provided input of transaction details.
* @param string $paymentType
* 'owed' for purpose of recording partial payments, 'refund' for purpose of recording refund payments.
* @param int $participantId
*
* @return null|object
*/
public static function recordAdditionalPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL)
{
$statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
$getInfoOf['id'] = $contributionId;
$defaults = array();
$contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray);
if ($paymentType == 'owed') {
// build params for recording financial trxn entry
$params['contribution'] = $contributionDAO;
$params = array_merge($defaults, $params);
$params['skipLineItem'] = TRUE;
$params['partial_payment_total'] = $contributionDAO->total_amount;
$params['partial_amount_pay'] = $trxnsData['total_amount'];
$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
$trxnsData['net_amount'] = !empty($trxnsData['net_amount']) ? $trxnsData['net_amount'] : $trxnsData['total_amount'];
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
$trxnId = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId, $contributionDAO->financial_type_id);
if (!empty($trxnId)) {
$trxnId = $trxnId['trxn_id'];
} elseif (!empty($contributionDAO->payment_instrument_id)) {
$trxnId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contributionDAO->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'));
$trxnId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams);
}
// update statuses
// criteria for updates contribution total_amount == financial_trxns of partial_payments
$sql = "SELECT SUM(ft.total_amount) as sum_of_payments, SUM(ft.net_amount) as net_amount_total\nFROM civicrm_financial_trxn ft\nLEFT JOIN civicrm_entity_financial_trxn eft\n ON (ft.id = eft.financial_trxn_id)\nWHERE eft.entity_table = 'civicrm_contribution'\n AND eft.entity_id = {$contributionId}\n AND ft.to_financial_account_id != {$toFinancialAccount}\n AND ft.status_id = {$statusId}\n";
$query = CRM_Core_DAO::executeQuery($sql);
$query->fetch();
$sumOfPayments = $query->sum_of_payments;
// update statuses
if ($contributionDAO->total_amount == $sumOfPayments) {
// update contribution status and
// clean cancel info (if any) if prev. contribution was updated in case of 'Refunded' => 'Completed'
$contributionDAO->contribution_status_id = $statusId;
$contributionDAO->cancel_date = 'null';
$contributionDAO->cancel_reason = NULL;
$netAmount = !empty($trxnsData['net_amount']) ? NULL : $trxnsData['total_amount'];
$contributionDAO->net_amount = $query->net_amount_total + $netAmount;
$contributionDAO->fee_amount = $contributionDAO->total_amount - $contributionDAO->net_amount;
$contributionDAO->save();
//Change status of financial record too
$financialTrxn->status_id = $statusId;
$financialTrxn->save();
// note : not using the self::add method,
// the reason because it performs 'status change' related code execution for financial records
// which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
if ($participantId) {
// update participant status
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
$ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
foreach ($ids as $val) {
$participantUpdate['id'] = $val;
$participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
CRM_Event_BAO_Participant::add($participantUpdate);
}
}
// update financial item statuses
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$paidStatus = array_search('Paid', $financialItemStatus);
$baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$sqlFinancialItemUpdate = "\nUPDATE civicrm_financial_item fi\n LEFT JOIN civicrm_entity_financial_trxn eft\n ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET status_id = {$paidStatus}\nWHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})\n";
CRM_Core_DAO::executeQuery($sqlFinancialItemUpdate);
}
} elseif ($paymentType == 'refund') {
// build params for recording financial trxn entry
$params['contribution'] = $contributionDAO;
$params = array_merge($defaults, $params);
$params['skipLineItem'] = TRUE;
$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$trxnsData['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
$trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
// note : not using the self::add method,
// the reason because it performs 'status change' related code execution for financial records
// which in 'Pending Refund' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
$contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
//.........这里部分代码省略.........