本文整理汇总了PHP中CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem方法的具体用法?PHP CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem怎么用?PHP CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Financial_BAO_FinancialItem
的用法示例。
在下文中一共展示了CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateFinancialAccounts
//.........这里部分代码省略.........
if ($context == 'changedStatus') {
if (($previousContributionStatus == 'Pending' || $previousContributionStatus == 'In Progress') && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus)) {
if (empty($params['line_item'])) {
//CRM-15296
//@todo - check with Joe regarding this situation - payment processors create pending transactions with no line items
// when creating recurring membership payment - there are 2 lines to comment out in contributonPageTest if fixed
// & this can be removed
return;
}
self::recordAlwaysAccountsReceivable($params['trxnParams'], $params);
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$params['entity_id'] = self::$_trxnIDs[] = $trxn->id;
$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');
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;
foreach (self::$_trxnIDs as $tID) {
$entityParams['financial_trxn_id'] = $tID;
CRM_Financial_BAO_FinancialItem::createEntityTrxn($entityParams);
}
}
}
}
return;
}
}
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$params['entity_id'] = $trxn->id;
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) {
$prevFinancialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($fieldValues['id']);
$receiveDate = CRM_Utils_Date::isoToMysql($params['prevContribution']->receive_date);
if ($params['contribution']->receive_date) {
$receiveDate = CRM_Utils_Date::isoToMysql($params['contribution']->receive_date);
}
$financialAccount = self::getFinancialAccountForStatusChangeTrxn($params, $prevFinancialItem);
$currency = $params['prevContribution']->currency;
if ($params['contribution']->currency) {
$currency = $params['contribution']->currency;
}
$diff = 1;
if ($context == 'changeFinancialType' || self::isContributionStatusNegative($params['contribution']->contribution_status_id)) {
$diff = -1;
}
if (!empty($params['is_quick_config'])) {
$amount = $itemAmount;
if (!$amount) {
$amount = $params['total_amount'];
}
} else {
$amount = $diff * $fieldValues['line_total'];
}
$itemParams = array('transaction_date' => $receiveDate, 'contact_id' => $params['prevContribution']->contact_id, 'currency' => $currency, 'amount' => $amount, 'description' => $prevFinancialItem->description, 'status_id' => $prevFinancialItem->status_id, 'financial_account_id' => $financialAccount, 'entity_table' => 'civicrm_line_item', 'entity_id' => $fieldValues['id']);
$financialItem = CRM_Financial_BAO_FinancialItem::create($itemParams, NULL, $trxnIds);
$params['line_item'][$fieldId][$fieldValueId]['deferred_line_total'] = $amount;
$params['line_item'][$fieldId][$fieldValueId]['financial_item_id'] = $financialItem->id;
if ($fieldValues['tax_amount']) {
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$itemParams['amount'] = $diff * $fieldValues['tax_amount'];
$itemParams['description'] = $taxTerm;
if ($fieldValues['financial_type_id']) {
$itemParams['financial_account_id'] = self::getFinancialAccountId($fieldValues['financial_type_id']);
}
CRM_Financial_BAO_FinancialItem::create($itemParams, NULL, $trxnIds);
}
}
}
}
if ($context == 'changeFinancialType') {
$params['skipLineItem'] = FALSE;
foreach ($params['line_item'] as &$lineItems) {
foreach ($lineItems as &$line) {
$line['financial_type_id'] = $params['financial_type_id'];
}
}
}
if ($context == 'changePaymentInstrument') {
foreach ($params['line_item'] as $lineitems) {
foreach ($lineitems as $fieldValueId => $fieldValues) {
$prevFinancialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($fieldValues['id']);
// save to entity_financial_trxn table
$entityFinancialTrxnParams = array('entity_table' => "civicrm_financial_item", 'entity_id' => $prevFinancialItem->id, 'financial_trxn_id' => $trxn->id, 'amount' => $trxn->total_amount);
civicrm_api3('entityFinancialTrxn', 'create', $entityFinancialTrxnParams);
}
}
}
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, $context);
}
示例2: testGetPreviousFinancialItem
/**
* Check method getPreviousFinancialItem().
*/
public function testGetPreviousFinancialItem()
{
$contactId = $this->individualCreate();
$params = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 1, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20160522000000', 'receipt_date' => '20160522000000', 'non_deductible_amount' => 0.0, 'total_amount' => 100.0, 'trxn_id' => '22ereerwww444444', 'invoice_id' => '86ed39c9e9ee6ef6031621ce0eafe7eb81');
$contribution = CRM_Contribute_BAO_Contribution::create($params);
$params = array('id' => $contribution->id, 'total_amount' => 300.0);
$contribution = CRM_Contribute_BAO_Contribution::create($params);
$financialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution->id);
$params = array('id' => $financialItem->id);
$financialItem = $this->callAPISuccess('FinancialItem', 'get', $params);
$this->assertEquals($financialItem['values'][$financialItem['id']]['amount'], 200.0, "The amounts do not match.");
}