本文整理汇总了PHP中CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId方法的具体用法?PHP CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId怎么用?PHP CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_FinancialTrxn
的用法示例。
在下文中一共展示了CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeFeeSelections
/**
* @param array $params
* @param int $participantId
* @param int $contributionId
* @param $feeBlock
* @param array $lineItems
* @param $paidAmount
* @param int $priceSetId
*/
public static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
$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');
}
if (!empty($submittedLineItems)) {
$insertLines = $submittedLineItems;
$submittedFieldValueIds = array_keys($submittedLineItems);
$updateLines = array();
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)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] || $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] == 0 && $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'] == 1 || $previousLineItem['qty'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['qty']) {
$updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
$updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
}
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
}
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nSET li.qty = 0,\n li.line_total = 0.00,\n li.tax_amount = NULL\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id NOT IN ({$submittedFieldValues}))\n";
CRM_Core_DAO::executeQuery($updateLineItem);
// gathering necessary info to record negative (deselected) financial_item
$updateFinancialItem = "\n SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id, financial_type_id, tax_amount\n FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})\nGROUP BY li.entity_table, li.entity_id, price_field_value_id, fi.id\n";
$updateFinancialItemInfoDAO = CRM_Core_DAO::executeQuery($updateFinancialItem);
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId, 'DESC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$updateFinancialItemInfoValues = array();
$financialItemsArray = array();
while ($updateFinancialItemInfoDAO->fetch()) {
$updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
$updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
// the below params are not needed
unset($updateFinancialItemInfoValues['id']);
unset($updateFinancialItemInfoValues['created_date']);
// if not submitted and difference is not 0 make it negative
if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
// INSERT negative financial_items
$updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
if ($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']) {
$updateFinancialItemInfoValues['tax']['amount'] = -$previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount'];
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateFinancialItemInfoValues['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateFinancialItemInfoValues['financial_type_id']);
}
}
// INSERT negative financial_items for tax amount
$financialItemsArray[] = $updateFinancialItemInfoValues;
} elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
$updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
// INSERT financial_items for tax amount
if ($updateFinancialItemInfoValues['entity_id'] == $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['id'] && isset($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'])) {
$updateFinancialItemInfoValues['tax']['amount'] = $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'];
$updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
if ($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']) {
$updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']);
}
}
$financialItemsArray[] = $updateFinancialItemInfoValues;
}
}
} elseif (empty($submittedFields) && empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\n INNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\n SET li.qty = 0,\n li.line_total = 0.00,\n li.tax_amount = NULL\n WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
CRM_Core_DAO::executeQuery($updateLineItem);
}
$amountLevel = array();
$totalParticipant = $participantCount = 0;
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
$taxAmount = "NULL";
if (isset($vals['tax_amount'])) {
$taxAmount = $vals['tax_amount'];
}
$amountLevel[] = $vals['label'] . ' - ' . (double) $vals['qty'];
if (isset($vals['participant_count'])) {
$participantCount = $vals['participant_count'];
//.........这里部分代码省略.........
示例2: recordFees
/**
* create financial trxn and items when fee is charged
*
* @params params to create trxn entries
*
* @access public
* @static
*/
static function recordFees($params)
{
$expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
$domainId = CRM_Core_Config::domainID();
$amount = 0;
if (!empty($params['prevContribution'])) {
$amount = $params['prevContribution']->fee_amount;
}
$amount = $params['fee_amount'] - $amount;
if (!$amount) {
return FALSE;
}
$financialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $expenseTypeId);
$params['trxnParams']['from_financial_account_id'] = $params['to_financial_account_id'];
$params['trxnParams']['to_financial_account_id'] = $financialAccount;
$params['trxnParams']['total_amount'] = $amount;
$params['trxnParams']['fee_amount'] = $params['trxnParams']['net_amount'] = 0;
$params['trxnParams']['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
$params['trxnParams']['contribution_id'] = isset($params['contribution']->id) ? $params['contribution']->id : $params['contribution_id'];
$trxn = self::create($params['trxnParams']);
if (empty($params['entity_id'])) {
$financialTrxnID = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['trxnParams']['contribution_id'], 'DESC');
$params['entity_id'] = $financialTrxnID['financialTrxnId'];
}
$fItemParams = array('financial_account_id' => $financialAccount, 'contact_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $domainId, 'contact_id'), 'created_date' => date('YmdHis'), 'transaction_date' => date('YmdHis'), 'amount' => $amount, 'description' => 'Fee', 'status_id' => CRM_Core_OptionGroup::getValue('financial_item_status', 'Paid', 'name'), 'entity_table' => 'civicrm_financial_trxn', 'entity_id' => $params['entity_id'], 'currency' => $params['trxnParams']['currency']);
$trxnIDS['id'] = $trxn->id;
$financialItem = CRM_Financial_BAO_FinancialItem::create($fItemParams, NULL, $trxnIDS);
}
示例3: add
/**
* Add the financial items and financial trxn.
*
* @param object $lineItem
* Line item object.
* @param object $contribution
* Contribution object.
* @param bool $taxTrxnID
*
* @return void
*/
public static function add($lineItem, $contribution, $taxTrxnID = FALSE, $trxnId = NULL)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$itemStatus = NULL;
if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses) || $contribution->contribution_status_id == array_search('Pending refund', $contributionStatuses)) {
$itemStatus = array_search('Paid', $financialItemStatus);
} elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses) || $contribution->contribution_status_id == array_search('In Progress', $contributionStatuses)) {
$itemStatus = array_search('Unpaid', $financialItemStatus);
} elseif ($contribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
$itemStatus = array_search('Partially paid', $financialItemStatus);
}
$params = array('transaction_date' => CRM_Utils_Date::isoToMysql($contribution->receive_date), 'contact_id' => $contribution->contact_id, 'amount' => $lineItem->line_total, 'currency' => $contribution->currency, 'entity_table' => 'civicrm_line_item', 'entity_id' => $lineItem->id, 'description' => ($lineItem->qty != 1 ? $lineItem->qty . ' of ' : '') . ' ' . $lineItem->label, 'status_id' => $itemStatus);
if ($taxTrxnID) {
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$params['amount'] = $lineItem->tax_amount;
$params['description'] = $taxTerm;
$accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' "));
} else {
$accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
}
if ($lineItem->financial_type_id) {
$searchParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $lineItem->financial_type_id, 'account_relationship' => $accountRel);
$result = array();
CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
$params['financial_account_id'] = CRM_Utils_Array::value('financial_account_id', $result);
}
if (empty($trxnId)) {
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'ASC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
}
return self::create($params, NULL, $trxnId);
}
示例4: getPaymentInfo
/**
* Get list of payments displayed by Contribute_Page_PaymentInfo.
*
* @param int $id
* @param $component
* @param bool $getTrxnInfo
* @param bool $usingLineTotal
*
* @return mixed
*/
public static function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $usingLineTotal = FALSE)
{
if ($component == 'event') {
$entity = 'participant';
$entityTable = 'civicrm_participant';
$contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id');
if (!$contributionId) {
if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $id, 'registered_by_id')) {
$contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id');
$id = $primaryParticipantId;
}
if (!$contributionId) {
return;
}
}
}
$total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
$baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL;
$isBalance = NULL;
if ($baseTrxnId) {
$isBalance = TRUE;
} else {
$baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
$baseTrxnId = $baseTrxnId['financialTrxnId'];
$isBalance = FALSE;
}
if (!CRM_Utils_Array::value('total_amount', $total) || $usingLineTotal) {
// for additional participants
if ($entityTable == 'civicrm_participant') {
$ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
$total = 0;
foreach ($ids as $val) {
$total += CRM_Price_BAO_LineItem::getLineTotal($val, $entityTable);
}
} else {
$total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable);
}
} else {
$baseTrxnId = $total['trxn_id'];
$total = $total['total_amount'];
}
$paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total);
$contributionIsPayLater = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'is_pay_later');
$feeRelationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'financial_type_id');
$feeFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $feeRelationTypeId);
if ($paymentBalance == 0 && $contributionIsPayLater) {
$paymentBalance = $total;
}
$info['total'] = $total;
$info['paid'] = $total - $paymentBalance;
$info['balance'] = $paymentBalance;
$info['id'] = $id;
$info['component'] = $component;
$info['payLater'] = $contributionIsPayLater;
$rows = array();
if ($getTrxnInfo && $baseTrxnId) {
// Need to exclude fee trxn rows so filter out rows where TO FINANCIAL ACCOUNT is expense account
$sql = "\nSELECT ft.total_amount, con.financial_type_id, ft.payment_instrument_id, ft.trxn_date, ft.trxn_id, ft.status_id, ft.check_number\nFROM civicrm_contribution con\n LEFT JOIN civicrm_entity_financial_trxn eft ON (eft.entity_id = con.id AND eft.entity_table = 'civicrm_contribution')\n INNER JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id AND ft.to_financial_account_id != {$feeFinancialAccount}\nWHERE con.id = {$contributionId}\n";
// conditioned WHERE clause
if ($isBalance) {
// if balance trxn exists don't include details of it in transaction info
$sql .= " AND ft.id != {$baseTrxnId} ";
}
$resultDAO = CRM_Core_DAO::executeQuery($sql);
$statuses = CRM_Contribute_PseudoConstant::contributionStatus();
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
while ($resultDAO->fetch()) {
$paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$val = array('total_amount' => $resultDAO->total_amount, 'financial_type' => $financialTypes[$resultDAO->financial_type_id], 'payment_instrument' => $paidByLabel, 'receive_date' => $resultDAO->trxn_date, 'trxn_id' => $resultDAO->trxn_id, 'status' => $statuses[$resultDAO->status_id]);
if ($paidByName == 'Check') {
$val['check_number'] = $resultDAO->check_number;
}
$rows[] = $val;
}
$info['transaction'] = $rows;
}
return $info;
}
示例5: _checkFinancialRecords
/**
* @param array $params
* @param $context
*/
public function _checkFinancialRecords($params, $context)
{
$entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
$contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
$this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
if ($context == 'pending') {
$trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
$this->assertNull($trxn, 'No Trxn to be created until IPN callback');
return;
}
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
$trxnParams = array('id' => $trxn['financial_trxn_id']);
if ($context != 'online' && $context != 'payLater') {
$compareParams = array('to_financial_account_id' => 6, 'total_amount' => 100, 'status_id' => 1);
}
if ($context == 'feeAmount') {
$compareParams['fee_amount'] = 50;
} elseif ($context == 'online') {
$compareParams = array('to_financial_account_id' => 12, 'total_amount' => 100, 'status_id' => 1);
} elseif ($context == 'payLater') {
$compareParams = array('to_financial_account_id' => 7, 'total_amount' => 100, 'status_id' => 2);
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
$entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
$entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
$fitemParams = array('id' => $entityTrxn['entity_id']);
$compareParams = array('amount' => 100, 'status_id' => 1, 'financial_account_id' => 1);
if ($context == 'payLater') {
$compareParams = array('amount' => 100, 'status_id' => 3, 'financial_account_id' => 1);
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
if ($context == 'feeAmount') {
$maxParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
$maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
$trxnParams = array('id' => $maxTrxn['financial_trxn_id']);
$compareParams = array('to_financial_account_id' => 5, 'from_financial_account_id' => 6, 'total_amount' => 50, 'status_id' => 1);
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
$fitemParams = array('entity_id' => $trxnId['financialTrxnId'], 'entity_table' => 'civicrm_financial_trxn');
$compareParams = array('amount' => 50, 'status_id' => 1, 'financial_account_id' => 5);
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
}
}
示例6: buildValuesAndAssignOnline_Note_Type
/**
* @param int $id
* @param $values
*/
public function buildValuesAndAssignOnline_Note_Type($id, &$values)
{
$ids = array();
$params = array('id' => $id);
CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
//Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL)
$this->_online = FALSE;
$fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id);
if (!empty($fids['financialTrxnId'])) {
$this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id');
}
// Also don't allow user to update some fields for recurring contributions.
if (!$this->_online) {
$this->_online = CRM_Utils_Array::value('contribution_recur_id', $values);
}
$this->assign('isOnline', $this->_online ? TRUE : FALSE);
//to get note id
$daoNote = new CRM_Core_BAO_Note();
$daoNote->entity_table = 'civicrm_contribution';
$daoNote->entity_id = $id;
if ($daoNote->find(TRUE)) {
$this->_noteID = $daoNote->id;
$values['note'] = $daoNote->note;
}
$this->_contributionType = $values['financial_type_id'];
}
示例7: preProcess
/**
* Set variables up before form is built.
*
* @return void
*/
public function preProcess()
{
$id = $this->get('id');
$values = $ids = array();
$params = array('id' => $id);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
$this->assign('context', $context);
CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
CRM_Contribute_BAO_Contribution::resolveDefaults($values);
$cancelledStatus = TRUE;
$status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) {
$cancelledStatus = FALSE;
}
$this->assign('cancelledStatus', $cancelledStatus);
if (!empty($values['contribution_page_id'])) {
$contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
$values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
}
// get recieved into i.e to_financial_account_id from last trxn
$financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
$values['to_financial_account'] = '';
if (!empty($financialTrxnId['financialTrxnId'])) {
$values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
if ($values['to_financial_account_id']) {
$values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']);
}
$values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
if ($values['payment_processor_id']) {
$values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
}
}
if (!empty($values['contribution_recur_id'])) {
$sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
$params = array(1 => array($values['contribution_recur_id'], 'Integer'));
$dao = CRM_Core_DAO::executeQuery($sql, $params);
if ($dao->fetch()) {
$values['recur_installments'] = $dao->installments;
$values['recur_frequency_unit'] = $dao->frequency_unit;
$values['recur_frequency_interval'] = $dao->frequency_interval;
}
}
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
$premiumId = NULL;
if ($id) {
$dao = new CRM_Contribute_DAO_ContributionProduct();
$dao->contribution_id = $id;
if ($dao->find(TRUE)) {
$premiumId = $dao->id;
$productID = $dao->product_id;
}
}
if ($premiumId) {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $productID;
$productDAO->find(TRUE);
$this->assign('premium', $productDAO->name);
$this->assign('option', $dao->product_option);
$this->assign('fulfilled', $dao->fulfilled_date);
}
// Get Note
$noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution');
$values['note'] = array_values($noteValue);
// show billing address location details, if exists
if (!empty($values['address_id'])) {
$addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
$addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
$addressDetails = array_values($addressDetails);
$values['billing_address'] = $addressDetails[0]['display'];
}
//assign soft credit record if exists.
$SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE);
if (!empty($SCRecords['soft_credit'])) {
$this->assign('softContributions', $SCRecords['soft_credit']);
unset($SCRecords['soft_credit']);
}
//assign pcp record if exists
foreach ($SCRecords as $name => $value) {
$this->assign($name, $value);
}
$lineItems = array();
if ($id) {
$lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE);
if (!empty($lineItem)) {
$lineItems[] = $lineItem;
}
}
$this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
$values['totalAmount'] = $values['total_amount'];
//do check for campaigns
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
$values['campaign'] = $campaigns[$campaignId];
}
//.........这里部分代码省略.........
示例8: civicrm_api3_payment_create
/**
* Add a payment for a Contribution.
*
* @param array $params
* Input parameters.
*
* @throws API_Exception
* @return array
* Api result array
*/
function civicrm_api3_payment_create(&$params)
{
// Check if it is an update
if (CRM_Utils_Array::value('id', $params)) {
$amount = $params['total_amount'];
civicrm_api3('Payment', 'cancel', $params);
$params['total_amount'] = $amount;
}
// Get contribution
$contribution = civicrm_api3('Contribution', 'getsingle', array('id' => $params['contribution_id']));
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($contribution['contribution_status_id'], 'name');
if ($contributionStatus != 'Partially paid' && !($contributionStatus == 'Pending' && $contribution['is_pay_later'] == TRUE)) {
throw new API_Exception('Please select a contribution which has a partial or pending payment');
} else {
// Check if pending contribution
$fullyPaidPayLater = FALSE;
if ($contributionStatus == 'Pending') {
$cmp = bccomp($contribution['total_amount'], $params['total_amount'], 5);
// Total payment amount is the whole amount paid against pending contribution
if ($cmp == 0 || $cmp == -1) {
civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$ftParams = array('id' => $trxnId['financialTrxnId']);
$trxn = CRM_Core_BAO_FinancialTrxn::retrieve($ftParams, CRM_Core_DAO::$_nullArray);
$fullyPaidPayLater = TRUE;
} else {
civicrm_api3('Contribution', 'create', array('id' => $contribution['id'], 'contribution_status_id' => 'Partially paid'));
}
}
if (!$fullyPaidPayLater) {
$trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params);
if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) {
foreach ($params['line_item'] as $values) {
foreach ($values as $id => $amount) {
$p = array('id' => $id);
$check = CRM_Price_BAO_LineItem::retrieve($p, $defaults);
if (empty($check)) {
throw new API_Exception('Please specify a valid Line Item.');
}
// get financial item
$sql = "SELECT fi.id\n FROM civicrm_financial_item fi\n INNER JOIN civicrm_line_item li ON li.id = fi.entity_id and fi.entity_table = 'civicrm_line_item'\n WHERE li.contribution_id = %1 AND li.id = %2";
$sqlParams = array(1 => array($params['contribution_id'], 'Integer'), 2 => array($id, 'Integer'));
$fid = CRM_Core_DAO::singleValueQuery($sql, $sqlParams);
// Record Entity Financial Trxn
$eftParams = array('entity_table' => 'civicrm_financial_item', 'financial_trxn_id' => $trxn->id, 'amount' => $amount, 'entity_id' => $fid);
civicrm_api3('EntityFinancialTrxn', 'create', $eftParams);
}
}
} elseif (!empty($trxn)) {
// Assign the lineitems proportionally
CRM_Contribute_BAO_Contribution::assignProportionalLineItems($params, $trxn, $contribution);
}
}
}
$values = array();
_civicrm_api3_object_to_array_unique_fields($trxn, $values[$trxn->id]);
return civicrm_api3_create_success($values, $params, 'Payment', 'create', $trxn);
}
示例9: add
/**
* function to add the financial items and financial trxn
*
* @param object $lineItem line item object
* @param object $contribution contribution object
*
* @access public
* @static
* @return void
*/
static function add($lineItem, $contribution)
{
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$itemStatus = NULL;
if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)) {
$itemStatus = array_search('Paid', $financialItemStatus);
} elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses) || $contribution->contribution_status_id == array_search('In Progress', $contributionStatuses)) {
$itemStatus = array_search('Unpaid', $financialItemStatus);
} elseif ($contribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) {
$itemStatus = array_search('Partially paid', $financialItemStatus);
}
$params = array('transaction_date' => CRM_Utils_Date::isoToMysql($contribution->receive_date), 'contact_id' => $contribution->contact_id, 'amount' => $lineItem->line_total, 'currency' => $contribution->currency, 'entity_table' => 'civicrm_line_item', 'entity_id' => $lineItem->id, 'description' => ($lineItem->qty != 1 ? $lineItem->qty . ' of ' : '') . ' ' . $lineItem->label, 'status_id' => $itemStatus);
if ($lineItem->financial_type_id) {
$searchParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $lineItem->financial_type_id, 'account_relationship' => 1);
$result = array();
CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
$params['financial_account_id'] = CRM_Utils_Array::value('financial_account_id', $result);
}
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution->id, 'ASC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
return self::create($params, NULL, $trxnId);
}
示例10: _checkFinancialRecords
/**
* @param array $params
* @param $context
*/
public function _checkFinancialRecords($params, $context)
{
$entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
$contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
$this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
if ($context == 'pending') {
$trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
$this->assertNull($trxn, 'No Trxn to be created until IPN callback');
return;
}
$trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
$trxnParams = array('id' => $trxn['financial_trxn_id']);
if ($context != 'online' && $context != 'payLater') {
$compareParams = array('to_financial_account_id' => 6, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1);
}
if ($context == 'feeAmount') {
$compareParams['fee_amount'] = 50;
} elseif ($context == 'online') {
$compareParams = array('to_financial_account_id' => 12, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1, 'payment_instrument_id' => 1);
} elseif ($context == 'payLater') {
$compareParams = array('to_financial_account_id' => 7, 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 2);
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
$entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
$entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
$fitemParams = array('id' => $entityTrxn['entity_id']);
$compareParams = array('amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1, 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1));
if ($context == 'payLater') {
$compareParams = array('amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 3, 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1));
}
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
if ($context == 'feeAmount') {
$maxParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
$maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
$trxnParams = array('id' => $maxTrxn['financial_trxn_id']);
$compareParams = array('to_financial_account_id' => 5, 'from_financial_account_id' => 6, 'total_amount' => 50, 'status_id' => 1);
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
$fitemParams = array('entity_id' => $trxnId['financialTrxnId'], 'entity_table' => 'civicrm_financial_trxn');
$compareParams = array('amount' => 50, 'status_id' => 1, 'financial_account_id' => 5);
$this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
}
// This checks that empty Sales tax rows are not being created. If for any reason it needs to be removed the
// line should be copied into all the functions that call this function & evaluated there
// Be really careful not to remove or bypass this without ensuring stray rows do not re-appear
// when calling completeTransaction or repeatTransaction.
$this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
}
示例11: updateFinancialAccounts
/**
* Function to update all financial accounts entry
*
* @param array $params contribution object, line item array and params for trxn
*
* @param string $context update scenarios
*
* @access public
* @static
*/
static function updateFinancialAccounts(&$params, $context = NULL, $skipTrxn = NULL)
{
$itemAmount = $trxnID = NULL;
//get all the statuses
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus) && $context == 'changePaymentInstrument') {
return;
}
if ($context == 'changedAmount' || $context == 'changeFinancialType') {
$itemAmount = $params['trxnParams']['total_amount'] = $params['total_amount'] - $params['prevContribution']->total_amount;
}
if ($context == 'changedStatus') {
//get all the statuses
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if ($params['prevContribution']->contribution_status_id == array_search('Completed', $contributionStatus) && ($params['contribution']->contribution_status_id == array_search('Refunded', $contributionStatus) || $params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus))) {
$params['trxnParams']['total_amount'] = -$params['total_amount'];
} elseif ($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) && $params['prevContribution']->is_pay_later || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) {
$financialTypeID = CRM_Utils_Array::value('financial_type_id', $params) ? $params['financial_type_id'] : $params['prevContribution']->financial_type_id;
if ($params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus)) {
$params['trxnParams']['to_financial_account_id'] = NULL;
$params['trxnParams']['total_amount'] = -$params['total_amount'];
}
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$params['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeID, $relationTypeId);
}
$itemAmount = $params['trxnParams']['total_amount'];
} elseif ($context == 'changePaymentInstrument') {
if ($params['trxnParams']['total_amount'] < 0) {
$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');
$params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
}
} else {
$params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
$params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
}
}
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$params['entity_id'] = $trxn->id;
if ($context == 'changedStatus') {
if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus)) && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus)) {
$query = "UPDATE civicrm_financial_item SET status_id = %1 WHERE entity_id = %2 and entity_table = 'civicrm_line_item'";
$sql = "SELECT id, amount FROM civicrm_financial_item WHERE entity_id = %1 and entity_table = 'civicrm_line_item'";
$entityParams = array('entity_table' => 'civicrm_financial_item', 'financial_trxn_id' => $trxn->id);
foreach ($params['line_item'] as $fieldId => $fields) {
foreach ($fields as $fieldValueId => $fieldValues) {
$fparams = array(1 => array(CRM_Core_OptionGroup::getValue('financial_item_status', 'Paid', 'name'), 'Integer'), 2 => array($fieldValues['id'], 'Integer'));
CRM_Core_DAO::executeQuery($query, $fparams);
$fparams = array(1 => array($fieldValues['id'], 'Integer'));
$financialItem = CRM_Core_DAO::executeQuery($sql, $fparams);
while ($financialItem->fetch()) {
$entityParams['entity_id'] = $financialItem->id;
$entityParams['amount'] = $financialItem->amount;
CRM_Financial_BAO_FinancialItem::createEntityTrxn($entityParams);
}
}
}
return;
}
}
if ($context != 'changePaymentInstrument') {
$itemParams['entity_table'] = 'civicrm_line_item';
$trxnIds['id'] = $params['entity_id'];
foreach ($params['line_item'] as $fieldId => $fields) {
foreach ($fields as $fieldValueId => $fieldValues) {
$prevParams['entity_id'] = $fieldValues['id'];
$prevfinancialItem = CRM_Financial_BAO_FinancialItem::retrieve($prevParams, CRM_Core_DAO::$_nullArray);
$receiveDate = CRM_Utils_Date::isoToMysql($params['prevContribution']->receive_date);
if ($params['contribution']->receive_date) {
$receiveDate = CRM_Utils_Date::isoToMysql($params['contribution']->receive_date);
}
$financialAccount = $prevfinancialItem->financial_account_id;
if (CRM_Utils_Array::value('financial_account_id', $params)) {
$financialAccount = $params['financial_account_id'];
}
$currency = $params['prevContribution']->currency;
if ($params['contribution']->currency) {
$currency = $params['contribution']->currency;
}
if (CRM_Utils_Array::value('is_quick_config', $params)) {
$amount = $itemAmount;
if (!$amount) {
$amount = $params['total_amount'];
}
} else {
$diff = 1;
if ($context == 'changeFinancialType' || $params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus)) {
$diff = -1;
}
//.........这里部分代码省略.........
示例12: changeFeeSelections
/**
* @param $params
* @param $participantId
* @param $contributionId
* @param $feeBlock
* @param $lineItems
* @param $paidAmount
* @param $priceSetId
*/
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);
$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);
$updateLines = array();
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)) {
// if submitted line items are existing don't fire INSERT query
unset($insertLines[$previousLineItem['price_field_value_id']]);
// for updating the line items i.e. use-case - once deselect-option selecting again
if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) {
$updateLines[$previousLineItem['price_field_value_id']]['qty'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'];
$updateLines[$previousLineItem['price_field_value_id']]['line_total'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'];
}
}
}
$submittedFields = implode(', ', $submittedFieldId);
$submittedFieldValues = implode(', ', $submittedFieldValueIds);
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nSET li.qty = 0,\n li.line_total = 0.00\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id NOT IN ({$submittedFieldValues}))\n";
CRM_Core_DAO::executeQuery($updateLineItem);
// gathering necessary info to record negative (deselected) financial_item
$updateFinancialItem = "\n SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id\n FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})\nGROUP BY li.entity_table, li.entity_id, price_field_value_id\n";
$updateFinancialItemInfoDAO = CRM_Core_DAO::executeQuery($updateFinancialItem);
$trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId, 'ASC', TRUE);
$trxnId['id'] = $trxn['financialTrxnId'];
$updateFinancialItemInfoValues = array();
while ($updateFinancialItemInfoDAO->fetch()) {
$updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
$updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
// the below params are not needed
unset($updateFinancialItemInfoValues['id']);
unset($updateFinancialItemInfoValues['created_date']);
// if not submitted and difference is not 0 make it negative
if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
// INSERT negative financial_items
$updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
} elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
$updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
}
}
}
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
$updateLineItem = "\nUPDATE civicrm_line_item li\nSET li.qty = {$vals['qty']},\n li.line_total = {$vals['line_total']}\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n (price_field_value_id = {$valueId})\n";
CRM_Core_DAO::executeQuery($updateLineItem);
}
}
// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
// 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);
}
// the recordAdjustedAmt code would execute over here
$ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
if (count($ids) > 1) {
$total = 0;
foreach ($ids as $val) {
$total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant');
}
$updatedAmount = $total;
} else {
$updatedAmount = $params['amount'];
}
self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId);
$fetchCon = array('id' => $contributionId);
$updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
// insert financial items
foreach ($insertLines as $valueId => $lineParams) {
$lineParams['entity_table'] = 'civicrm_participant';
$lineParams['entity_id'] = $participantId;
$lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
// insert financial items
// ensure entity_financial_trxn table has a linking of it.
//.........这里部分代码省略.........
示例13: 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');
}