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


PHP CRM_Core_BAO_FinancialTrxn::retrieve方法代码示例

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


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

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

示例2: testIsPaymentFlagForPending

 /**
  * Create() method (create and update modes).
  */
 public function testIsPaymentFlagForPending()
 {
     $contactId = Contact::createIndividual();
     $ids = array('contribution' => NULL);
     $params = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 2, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'is_pay_later' => 1, 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'non_deductible_amount' => 0.0, 'total_amount' => 200.0, 'fee_amount' => 5, 'net_amount' => 195, 'trxn_id' => '22ereerwww4444yy', 'invoice_id' => '86ed39c9e9yy6ef6541621ce0eafe7eb81', 'thankyou_date' => '20080522');
     $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
     $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
     $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id  creation.');
     $trxnArray = array('trxn_id' => $params['trxn_id'], 'is_payment' => 0);
     $defaults = array();
     $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
     $this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.');
     $trxnArray['is_payment'] = 1;
     $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
     $this->assertEquals(NULL, $financialTrxn, 'Mismatch count for is payment flag.');
     //update contribution amount
     $ids = array('contribution' => $contribution->id);
     $params['contribution_status_id'] = 1;
     $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
     $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id .');
     $this->assertEquals($params['contribution_status_id'], $contribution->contribution_status_id, 'Check for status updation.');
     $trxnArray = array('trxn_id' => $params['trxn_id'], 'is_payment' => 1);
     $defaults = array();
     $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
     $this->assertEquals(1, $financialTrxn->N, 'Mismatch count for is payment flag.');
     $trxnArray['is_payment'] = 0;
     $financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
     $this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.');
     //Delete Contribution
     $this->contributionDelete($contribution->id);
     //Delete Contact
     Contact::delete($contactId);
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:36,代码来源:ContributionTest.php


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