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


PHP CRM_Core_BAO_FinancialTrxn::createDeferredTrxn方法代码示例

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


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

示例1: processPriceSet

 /**
  * Process price set and line items.
  *
  * @param int $entityId
  * @param array $lineItem
  *   Line item array.
  * @param object $contributionDetails
  * @param string $entityTable
  *   Entity table.
  *
  * @param bool $update
  *
  * @return void
  */
 public static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE)
 {
     if (!$entityId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) {
         return;
     }
     foreach ($lineItem as $priceSetId => &$values) {
         if (!$priceSetId) {
             continue;
         }
         foreach ($values as &$line) {
             $line['entity_table'] = $entityTable;
             if (empty($line['entity_id'])) {
                 $line['entity_id'] = $entityId;
             }
             if (!empty($line['membership_type_id'])) {
                 $line['entity_table'] = 'civicrm_membership';
             }
             if (!empty($contributionDetails->id)) {
                 $line['contribution_id'] = $contributionDetails->id;
                 if ($line['entity_table'] == 'civicrm_contribution') {
                     $line['entity_id'] = $contributionDetails->id;
                 } elseif ($line['entity_table'] == 'civicrm_membership' && !empty($line['entity_id']) && $line['entity_id'] == $contributionDetails->id) {
                     $membershipId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', 'contribution_id', $line['entity_id'], 'membership_id');
                     $line['entity_id'] = $membershipId ? $membershipId : $line['entity_id'];
                 }
             }
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (!empty($line['price_field_value_id']) && empty($line['financial_type_id'])) {
                 $line['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $line['price_field_value_id'], 'financial_type_id');
             }
             $lineItems = CRM_Price_BAO_LineItem::create($line);
             if (!$update && $contributionDetails) {
                 $financialItem = CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
                 $line['financial_item_id'] = $financialItem->id;
                 if (!empty($line['tax_amount'])) {
                     CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE);
                 }
             }
         }
     }
     if (!$update && $contributionDetails) {
         CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItem, $contributionDetails);
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:59,代码来源:LineItem.php

示例2: 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);
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Contribution.php

示例3: testCreateDeferredTrxn

 /**
  * Test for createDeferredTrxn().
  */
 public function testCreateDeferredTrxn()
 {
     Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
     $cid = $this->individualCreate();
     $params = array('contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 622, 'financial_type_id' => 4, 'line_items' => array(array('line_item' => array(array('entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, 'label' => 'test 1', 'qty' => 1, 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 4)), 'params' => array())));
     $contribution = CRM_Contribute_BAO_Contribution::create($params);
     $lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution->id);
     $lineItemId = key($lineItems[1]);
     $lineItems[1][$lineItemId]['financial_item_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_item WHERE entity_table = 'civicrm_line_item' AND entity_id = {$lineItemId}");
     // Get financial trxns for contribution
     $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622));
     $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime('2016-01-20')));
     $contribution->revenue_recognition_date = date('Ymd', strtotime("+1 month"));
     CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contribution);
     $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622, 'id' => array("NOT IN" => array($trxn['id']))));
     $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month")));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:20,代码来源:FinancialTrxnTest.php


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