本文整理汇总了PHP中CRM_Financial_BAO_FinancialItem::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Financial_BAO_FinancialItem::create方法的具体用法?PHP CRM_Financial_BAO_FinancialItem::create怎么用?PHP CRM_Financial_BAO_FinancialItem::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Financial_BAO_FinancialItem
的用法示例。
在下文中一共展示了CRM_Financial_BAO_FinancialItem::create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: addFinancialItem
/**
* @param $result
* @param null $financialAccountId
*/
private function addFinancialItem($result, $financialAccountId = NULL)
{
$defaultFinancialAccount = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1");
while ($result->fetch()) {
$trxnParams = array('trxn_date' => CRM_Utils_Date::processDate($result->receive_date), 'total_amount' => $result->total_amount, 'currency' => $result->currency, 'status_id' => 1, 'trxn_id' => $result->trxn_id, 'contribution_id' => $result->contribution_id, 'to_financial_account_id' => empty($financialAccountId[$result->payment_instrument_id]) ? $defaultFinancialAccount : $financialAccountId[$result->payment_instrument_id], 'payment_instrument_id' => $result->payment_instrument_id, 'check_number' => $result->check_number);
$trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$financialItem = array('transaction_date' => CRM_Utils_Date::processDate($result->receive_date), 'amount' => $result->total_amount, 'currency' => $result->currency, 'status_id' => 1, 'entity_id' => $result->line_item_id, 'contact_id' => $result->contact_id, 'entity_table' => 'civicrm_line_item', 'description' => $result->label, 'financial_account_id' => $result->financial_account_id);
$trxnId['id'] = $trxn->id;
CRM_Financial_BAO_FinancialItem::create($financialItem, NULL, $trxnId);
}
}
示例3: 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'];
//.........这里部分代码省略.........
示例4: recordAdditionalPayment
//.........这里部分代码省略.........
$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);
// add financial item entry
$financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
$getLine['entity_id'] = $contributionDAO->id;
$getLine['entity_table'] = 'civicrm_contribution';
$lineItemId = CRM_Price_BAO_LineItem::retrieve($getLine, CRM_Core_DAO::$_nullArray);
if (!empty($lineItemId->id)) {
$addFinancialEntry = array('transaction_date' => $financialTrxn->trxn_date, 'contact_id' => $contributionDAO->contact_id, 'amount' => $financialTrxn->total_amount, 'status_id' => array_search('Paid', $financialItemStatus), 'entity_id' => $lineItemId->id, 'entity_table' => 'civicrm_line_item');
$trxnIds['id'] = $financialTrxn->id;
CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds);
}
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);
}
}
}
// activity creation
if (!empty($financialTrxn)) {
if ($participantId) {
$inputParams['id'] = $participantId;
$values = array();
$ids = array();
$component = 'event';
$entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids);
$entityObj = $entityObj[$participantId];
}
$activityType = $paymentType == 'refund' ? 'Refund' : 'Payment';
self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId);
}
return $financialTrxn;
}
示例5: 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;
}
//.........这里部分代码省略.........
示例6: testCreate
/**
* check method create()
*/
function testCreate()
{
$firstName = 'Shane';
$lastName = 'Whatson';
$params = array('first_name' => $firstName, 'last_name' => $lastName, 'contact_type' => 'Individual');
$contact = CRM_Contact_BAO_Contact::add($params);
$price = 100.0;
$cParams = array('contact_id' => $contact->id, 'total_amount' => $price, 'financial_type_id' => 1, 'is_active' => 1, 'skipLineItem' => 1);
$defaults = array();
$contribution = CRM_Contribute_BAO_Contribution::add($cParams, $defaults);
$lParams = array('entity_id' => $contribution->id, 'entity_table' => 'civicrm_contribution', 'price_field_id' => 1, 'qty' => 1, 'label' => 'Contribution Amount', 'unit_price' => $price, 'line_total' => $price, 'price_field_value_id' => 1, 'financial_type_id' => 1);
$lineItem = CRM_Price_BAO_LineItem::create($lParams);
$fParams = array('contact_id' => $contact->id, 'description' => 'Contribution Amount', 'amount' => $price, 'financial_account_id' => 1, 'status_id' => 1, 'transaction_date' => date('YmdHis'), 'entity_id' => $lineItem->id, 'entity_table' => 'civicrm_line_item');
CRM_Financial_BAO_FinancialItem::create($fParams);
$entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
$entityTrxn->entity_table = 'civicrm_contribution';
$entityTrxn->entity_id = $contribution->id;
$entityTrxn->amount = $price;
if ($entityTrxn->find(TRUE)) {
$entityId = $entityTrxn->entity_id;
}
$result = $this->assertDBNotNull('CRM_Financial_DAO_FinancialItem', $lineItem->id, 'amount', 'entity_id', 'Database check on added financial item record.');
$this->assertEquals($result, $price, 'Verify Amount for Financial Item');
$entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $entityId, 'amount', 'entity_id', 'Database check on added entity financial trxn record.');
$this->assertEquals($entityResult, $price, 'Verify Amount for Financial Item');
}
示例7: 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.
//.........这里部分代码省略.........
示例8: 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');
}