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


PHP CRM_Core_BAO_FinancialTrxn::create方法代码示例

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


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

示例1: testCreate

 /**
  * Check method create()
  */
 public function testCreate()
 {
     $contactId = $this->individualCreate();
     $financialTypeId = 1;
     $this->contributionCreate(array('contact_id' => $contactId), $financialTypeId);
     $params = array('contribution_id' => $financialTypeId, 'to_financial_account_id' => 1, 'trxn_date' => 20091021184930.0, 'trxn_type' => 'Debit', 'total_amount' => 10, 'net_amount' => 90.0, 'currency' => 'USD', 'payment_processor' => 'Dummy', 'trxn_id' => 'test_01014000');
     $FinancialTrxn = CRM_Core_BAO_FinancialTrxn::create($params);
     $result = $this->assertDBNotNull('CRM_Core_BAO_FinancialTrxn', $FinancialTrxn->id, 'total_amount', 'id', 'Database check on updated financial trxn record.');
     $this->assertEquals($result, 10, 'Verify financial trxn total_amount.');
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:13,代码来源:FinancialTrxnTest.php

示例2: recordPartialPayment

 /**
  * This function is used to record partial payments for contribution
  *
  * @param array $contribution
  *
  * @param array $params
  *
  * @return object
  */
 public static function recordPartialPayment($contribution, $params)
 {
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $pendingStatus = array(array_search('Pending', $contributionStatuses), array_search('In Progress', $contributionStatuses));
     $statusId = array_search('Completed', $contributionStatuses);
     if (in_array(CRM_Utils_Array::value('contribution_status_id', $contribution), $pendingStatus)) {
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId);
     } elseif (!empty($params['payment_processor'])) {
         $balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($contribution['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
     } elseif (!empty($params['payment_instrument_id'])) {
         $balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contribution['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'));
         $balanceTrxnParams['to_financial_account_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams);
     }
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
     $fromFinancialAccountId = CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId);
     $balanceTrxnParams['from_financial_account_id'] = $fromFinancialAccountId;
     $balanceTrxnParams['total_amount'] = $params['total_amount'];
     $balanceTrxnParams['contribution_id'] = $params['contribution_id'];
     $balanceTrxnParams['trxn_date'] = !empty($params['contribution_receive_date']) ? $params['contribution_receive_date'] : date('YmdHis');
     $balanceTrxnParams['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params);
     $balanceTrxnParams['net_amount'] = CRM_Utils_Array::value('total_amount', $params);
     $balanceTrxnParams['currency'] = $contribution['currency'];
     $balanceTrxnParams['trxn_id'] = CRM_Utils_Array::value('contribution_trxn_id', $params, NULL);
     $balanceTrxnParams['status_id'] = $statusId;
     $balanceTrxnParams['payment_instrument_id'] = CRM_Utils_Array::value('payment_instrument_id', $params, $contribution['payment_instrument_id']);
     $balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params);
     if ($fromFinancialAccountId != NULL && ($statusId == array_search('Completed', $contributionStatuses) || $statusId == array_search('Partially paid', $contributionStatuses))) {
         $balanceTrxnParams['is_payment'] = 1;
     }
     if (!empty($params['payment_processor'])) {
         $balanceTrxnParams['payment_processor_id'] = $params['payment_processor'];
     }
     return CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams);
 }
开发者ID:joshgowans,项目名称:civicrm-core,代码行数:47,代码来源:Contribution.php

示例3: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Member_BAO_Membership::deleteRelatedMemberships($this->_id);
         CRM_Member_BAO_Membership::deleteMembership($this->_id);
         return;
     }
     $config = CRM_Core_Config::singleton();
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $params = $ids = array();
     $membershipTypeValues = array();
     foreach ($this->_memTypeSelected as $memType) {
         $membershipTypeValues[$memType]['membership_type_id'] = $memType;
     }
     //take the required membership recur values.
     if ($this->_mode && CRM_Utils_Array::value('auto_renew', $this->_params)) {
         $params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE;
         $mapping = array('frequency_interval' => 'duration_interval', 'frequency_unit' => 'duration_unit');
         $count = 0;
         foreach ($this->_memTypeSelected as $memType) {
             $recurMembershipTypeValues = CRM_Utils_Array::value($memType, $this->_recurMembershipTypes, array());
             foreach ($mapping as $mapVal => $mapParam) {
                 $membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
                 if (!$count) {
                     $this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues);
                 }
             }
             $count++;
         }
         // unset send-receipt option, since receipt will be sent when ipn is received.
         unset($this->_params['send_receipt'], $formValues['send_receipt']);
     }
     // process price set and get total amount and line items.
     $lineItem = array();
     $priceSetId = NULL;
     if (!($priceSetId = CRM_Utils_Array::value('price_set_id', $formValues))) {
         CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId);
     }
     if ($priceSetId) {
         CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]);
         $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params);
     }
     $this->storeContactFields($formValues);
     $params['contact_id'] = $this->_contactID;
     $fields = array('status_id', 'source', 'is_override', 'campaign_id');
     foreach ($fields as $f) {
         $params[$f] = CRM_Utils_Array::value($f, $formValues);
     }
     // fix for CRM-3724
     // when is_override false ignore is_admin statuses during membership
     // status calculation. similarly we did fix for import in CRM-3570.
     if (!CRM_Utils_Array::value('is_override', $params)) {
         $params['exclude_is_admin'] = TRUE;
     }
     // process date params to mysql date format.
     $dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate');
     foreach ($dateTypes as $dateField => $dateVariable) {
         ${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]);
     }
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
     $calcDates = array();
     foreach ($this->_memTypeSelected as $memType) {
         $calcDates[$memType] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
     }
     foreach ($calcDates as $memType => $calcDate) {
         foreach ($dates as $d) {
             //first give priority to form values then calDates.
             $date = CRM_Utils_Array::value($d, $formValues);
             if (!$date) {
                 $date = CRM_Utils_Array::value($d, $calcDate);
             }
             $membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
             //$params[$d] = CRM_Utils_Date::processDate( $date );
         }
     }
     if ($this->_id) {
         $ids['membership'] = $params['id'] = $this->_id;
     }
     $session = CRM_Core_Session::singleton();
     $ids['userId'] = $session->get('userID');
     // membership type custom data
     foreach ($this->_memTypeSelected as $memType) {
         $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $memType);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
         $membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership');
     }
     foreach ($this->_memTypeSelected as $memType) {
         $membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType);
     }
     $membershipType = implode(', ', $membershipTypes);
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Membership.php

示例4: 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;
                     }
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:Contribution.php

示例5: recordAdjustedAmt

 /**
  * @param $updatedAmount
  * @param $paidAmount
  * @param $contributionId
  */
 static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId)
 {
     $balanceAmt = $updatedAmount - $paidAmount;
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
     $pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
     $completedStatusId = array_search('Completed', $contributionStatuses);
     $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
     if ($balanceAmt) {
         if ($balanceAmt > 0 && $paidAmount != 0) {
             $contributionStatusVal = $partiallyPaidStatusId;
         } elseif ($balanceAmt < 0 && $paidAmount != 0) {
             $contributionStatusVal = $pendngRefundStatusId;
         } elseif ($paidAmount == 0) {
             $contributionStatusVal = $completedStatusId;
             $updatedContributionDAO->cancel_date = 'null';
             $updatedContributionDAO->cancel_reason = NULL;
         }
         // update contribution status and total amount without trigger financial code
         // as this is handled in current BAO function used for change selection
         $updatedContributionDAO->id = $contributionId;
         $updatedContributionDAO->contribution_status_id = $contributionStatusVal;
         $updatedContributionDAO->total_amount = $updatedAmount;
         $updatedContributionDAO->save();
         $ftDetail = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
         // adjusted amount financial_trxn creation
         if (empty($ftDetail['trxn_id'])) {
             $updatedContribution = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contributionId), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
             $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, 'total_amount' => $balanceAmt, 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), 'payment_instrument_id' => $updatedContribution->payment_instrument_id, 'contribution_id' => $updatedContribution->id, 'trxn_date' => date('YmdHis'), 'currency' => $updatedContribution->currency);
             $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
         } else {
             // update the financial trxn amount as well, as the fee selections has been updated
             if ($balanceAmt != $ftDetail['total_amount']) {
                 CRM_Core_DAO::setFieldValue('CRM_Core_BAO_FinancialTrxn', $ftDetail['trxn_id'], 'total_amount', $balanceAmt);
             }
         }
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:45,代码来源:Participant.php

示例6: processContribution

 /**
  * Process the contribution
  *
  * @return void
  * @access public
  */
 static function processContribution(&$form, $params, $result, $contactID, $contributionType, $deductibleMode = true, $pending = false, $online = true)
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $className = get_class($form);
     $honorCId = $recurringContributionID = null;
     if ($online && $form->get('honor_block_is_active')) {
         $honorCId = $form->createHonorContact();
     }
     $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $online);
     if (!$online && isset($params['honor_contact_id'])) {
         $honorCId = $params['honor_contact_id'];
     }
     $config = CRM_Core_Config::singleton();
     if (!$online && isset($params['non_deductible_amount'])) {
         $nonDeductibleAmount = $params['non_deductible_amount'];
     } else {
         $nonDeductibleAmount = $params['amount'];
     }
     if ($online && $contributionType->is_deductible && $deductibleMode) {
         $selectProduct = CRM_Utils_Array::value('selectProduct', $premiumParams);
         if ($selectProduct && $selectProduct != 'no_thanks') {
             require_once 'CRM/Contribute/DAO/Product.php';
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $selectProduct;
             $productDAO->find(true);
             if ($params['amount'] < $productDAO->price) {
                 $nonDeductibleAmount = $params['amount'];
             } else {
                 $nonDeductibleAmount = $productDAO->price;
             }
         } else {
             $nonDeductibleAmount = '0.00';
         }
     }
     $now = date('YmdHis');
     $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
     if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
         $receiptDate = $now;
     }
     //get the contrib page id.
     $contributionPageId = null;
     if ($online) {
         $contributionPageId = $form->_id;
     } else {
         //also for offline we do support - CRM-7290
         $contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
     }
     // first create the contribution record
     $contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => $now, 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || CRM_Utils_Array::value('source', $params) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : null, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : null);
     if (!$online && isset($params['thankyou_date'])) {
         $contribParams['thankyou_date'] = $params['thankyou_date'];
     }
     if (!$online || $form->_values['is_monetary']) {
         if (!CRM_Utils_Array::value('is_pay_later', $params)) {
             $contribParams['payment_instrument_id'] = 1;
         }
     }
     if (!$pending && $result) {
         $contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => $result['trxn_result_code'], 'payment_processor' => $result['payment_processor']);
     }
     if (isset($honorCId)) {
         $contribParams['honor_contact_id'] = $honorCId;
         $contribParams['honor_type_id'] = $params['honor_type_id'];
     }
     if ($recurringContributionID) {
         $contribParams['contribution_recur_id'] = $recurringContributionID;
     }
     $contribParams['contribution_status_id'] = $pending ? 2 : 1;
     $contribParams['is_test'] = 0;
     if ($form->_mode == 'test') {
         $contribParams['is_test'] = 1;
     }
     $ids = array();
     if (isset($contribParams['invoice_id'])) {
         $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
         if (isset($contribID)) {
             $ids['contribution'] = $contribID;
             $contribParams['id'] = $contribID;
         }
     }
     foreach (array('pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
         if (CRM_Utils_Array::value($val, $params)) {
             $contribSoftParams[$val] = $params[$val];
         }
     }
     require_once 'CRM/Contribute/BAO/Contribution.php';
     //create an contribution address
     if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params)) {
         $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
     }
     // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
     require_once 'CRM/Utils/Money.php';
     $contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Confirm.php

示例7: recordAdjustedAmt

 /**
  * Record adjusted amount.
  *
  * @param int $updatedAmount
  * @param int $paidAmount
  * @param int $contributionId
  *
  * @param int $taxAmount
  * @param bool $updateAmountLevel
  *
  * @return bool|\CRM_Core_BAO_FinancialTrxn
  */
 public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL)
 {
     $pendingAmount = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId);
     $pendingAmount = CRM_Utils_Array::value('total_amount', $pendingAmount, 0);
     $balanceAmt = $updatedAmount - $paidAmount;
     if ($paidAmount != $pendingAmount) {
         $balanceAmt -= $pendingAmount;
     }
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
     $pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
     $completedStatusId = array_search('Completed', $contributionStatuses);
     $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
     $adjustedTrxn = $skip = FALSE;
     if ($balanceAmt) {
         if ($balanceAmt > 0 && $paidAmount != 0) {
             $contributionStatusVal = $partiallyPaidStatusId;
         } elseif ($balanceAmt < 0 && $paidAmount != 0) {
             $contributionStatusVal = $pendingRefundStatusId;
         } elseif ($paidAmount == 0) {
             //skip updating the contribution status if no payment is made
             $skip = TRUE;
             $updatedContributionDAO->cancel_date = 'null';
             $updatedContributionDAO->cancel_reason = NULL;
         }
         // update contribution status and total amount without trigger financial code
         // as this is handled in current BAO function used for change selection
         $updatedContributionDAO->id = $contributionId;
         if (!$skip) {
             $updatedContributionDAO->contribution_status_id = $contributionStatusVal;
         }
         $updatedContributionDAO->total_amount = $updatedContributionDAO->net_amount = $updatedAmount;
         $updatedContributionDAO->fee_amount = 0;
         $updatedContributionDAO->tax_amount = $taxAmount;
         if (!empty($updateAmountLevel)) {
             $updatedContributionDAO->amount_level = $updateAmountLevel;
         }
         $updatedContributionDAO->save();
         // adjusted amount financial_trxn creation
         $updatedContribution = CRM_Contribute_BAO_Contribution::getValues(array('id' => $contributionId), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
         $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, 'total_amount' => $balanceAmt, 'status_id' => $completedStatusId, 'payment_instrument_id' => $updatedContribution->payment_instrument_id, 'contribution_id' => $updatedContribution->id, 'trxn_date' => date('YmdHis'), 'currency' => $updatedContribution->currency);
         $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
     }
     return $adjustedTrxn;
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:59,代码来源:Participant.php

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

示例9: postProcess

 /**
  * Function to process the renewal form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Member/BAO/Membership.php';
     require_once 'CRM/Member/BAO/MembershipType.php';
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $params = array();
     $ids = array();
     $config = CRM_Core_Config::singleton();
     $params['contact_id'] = $this->_contactID;
     if ($this->_mode) {
         $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
         $formValues['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id');
         require_once 'CRM/Core/BAO/PaymentProcessor.php';
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
         require_once "CRM/Contact/BAO/Contact.php";
         $now = CRM_Utils_Date::getToday($now, 'YmdHis');
         $fields = array();
         // set email for primary location.
         $fields["email-Primary"] = 1;
         $formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail;
         $formValues['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
         $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $formValues)) {
                 $formValues[$name] = $formValues["billing_{$name}"];
                 $formValues['preserveDBName'] = true;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype);
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
         $this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $formValues['total_amount'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), true));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         require_once 'CRM/Core/Payment/Form.php';
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
         $payment =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $formValues['contribution_status_id'] = 1;
         $formValues['receive_date'] = $now;
         $formValues['invoice_id'] = $this->_params['invoiceID'];
         $formValues['trxn_id'] = $result['trxn_id'];
         $formValues['payment_instrument_id'] = 1;
         $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $formValues['receipt_date'] = $now;
         } else {
             $formValues['receipt_date'] = null;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($formValues['receive_date']));
     }
     $renewalDate = null;
     if ($formValues['renewal_date']) {
         $this->set('renewDate', CRM_Utils_Date::processDate($formValues['renewal_date']));
     }
     $this->_membershipId = $this->_id;
     // check for test membership.
     $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test');
     $renewMembership = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_memType, $isTestMembership, $this, null);
     $endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:MembershipRenewal.php

示例10: recordAlwaysAccountsReceivable

 /**
  * Create Accounts Receivable financial trxn entry for Completed Contribution.
  *
  * @param array $trxnParams
  *   Financial trxn params
  * @param string $contributionParams
  *   Contribution Params
  *
  * @return string
  */
 public static function recordAlwaysAccountsReceivable(&$trxnParams, $contributionParams)
 {
     if (!self::checkContributeSettings('always_post_to_accounts_receivable')) {
         return NULL;
     }
     $statusId = $contributionParams['contribution']->contribution_status_id;
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $contributionStatus = empty($statusId) ? NULL : $contributionStatuses[$statusId];
     $previousContributionStatus = empty($contributionParams['prevContribution']) ? NULL : $contributionStatuses[$contributionParams['prevContribution']->contribution_status_id];
     // Return if contribution status is not completed.
     if (!($contributionStatus == 'Completed' && (empty($previousContributionStatus) || !empty($previousContributionStatus) && $previousContributionStatus == 'Pending' && $contributionParams['prevContribution']->is_pay_later == 0))) {
         return NULL;
     }
     $params = $trxnParams;
     $financialTypeID = CRM_Utils_Array::value('financial_type_id', $contributionParams) ? $contributionParams['financial_type_id'] : $contributionParams['prevContribution']->financial_type_id;
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
     $arAccountId = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeID, $relationTypeId);
     $params['to_financial_account_id'] = $arAccountId;
     $params['status_id'] = array_search('Pending', $contributionStatuses);
     $params['is_payment'] = FALSE;
     $trxn = CRM_Core_BAO_FinancialTrxn::create($params);
     self::$_trxnIDs[] = $trxn->id;
     $trxnParams['from_financial_account_id'] = $params['to_financial_account_id'];
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:34,代码来源:Contribution.php

示例11: processContribution

 /**
  * Process the contribution
  *
  * @return void
  * @access public
  */
 static function processContribution(&$form, $params, $result, $contactID, $contributionType, $deductibleMode = TRUE, $pending = FALSE, $online = TRUE)
 {
     $transaction = new CRM_Core_Transaction();
     $className = get_class($form);
     $honorCId = $recurringContributionID = NULL;
     if ($online && $form->get('honor_block_is_active')) {
         $honorCId = $form->createHonorContact();
     }
     // add these values for the recurringContrib function ,CRM-10188
     $params['contribution_type_id'] = $contributionType->id;
     $params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $form->_values);
     $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $contributionType, $online);
     if (!$online && isset($params['honor_contact_id'])) {
         $honorCId = $params['honor_contact_id'];
     }
     $config = CRM_Core_Config::singleton();
     if (!$online && isset($params['non_deductible_amount'])) {
         $nonDeductibleAmount = $params['non_deductible_amount'];
     } else {
         $nonDeductibleAmount = $params['amount'];
     }
     if ($online && $contributionType->is_deductible && $deductibleMode) {
         $selectProduct = CRM_Utils_Array::value('selectProduct', $params);
         if ($selectProduct && $selectProduct != 'no_thanks') {
             $productDAO = new CRM_Contribute_DAO_Product();
             $productDAO->id = $selectProduct;
             $productDAO->find(TRUE);
             if ($params['amount'] < $productDAO->price) {
                 $nonDeductibleAmount = $params['amount'];
             } else {
                 $nonDeductibleAmount = $productDAO->price;
             }
         } else {
             $nonDeductibleAmount = '0.00';
         }
     }
     $now = date('YmdHis');
     $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
     if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
         $receiptDate = $now;
     }
     //get the contrib page id.
     $campaignId = $contributionPageId = NULL;
     if ($online) {
         $contributionPageId = $form->_id;
         $campaignId = CRM_Utils_Array::value('campaign_id', $params);
         if (!array_key_exists('campaign_id', $params)) {
             $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
         }
     } else {
         //also for offline we do support - CRM-7290
         $contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
         $campaignId = CRM_Utils_Array::value('campaign_id', $params);
     }
     // first create the contribution record
     $contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || CRM_Utils_Array::value('source', $params) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'campaign_id' => $campaignId);
     if (!$online && isset($params['thankyou_date'])) {
         $contribParams['thankyou_date'] = $params['thankyou_date'];
     }
     if (!$online || $form->_values['is_monetary']) {
         if (!CRM_Utils_Array::value('is_pay_later', $params)) {
             $contribParams['payment_instrument_id'] = 1;
         }
     }
     if (!$pending && $result) {
         $contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result), 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result));
     }
     if (isset($honorCId)) {
         $contribParams['honor_contact_id'] = $honorCId;
         $contribParams['honor_type_id'] = $params['honor_type_id'];
     }
     if ($recurringContributionID) {
         $contribParams['contribution_recur_id'] = $recurringContributionID;
     }
     $contribParams['contribution_status_id'] = $pending ? 2 : 1;
     $contribParams['is_test'] = 0;
     if ($form->_mode == 'test') {
         $contribParams['is_test'] = 1;
     }
     $ids = array();
     if (isset($contribParams['invoice_id'])) {
         $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
         if (isset($contribID)) {
             $ids['contribution'] = $contribID;
             $contribParams['id'] = $contribID;
         }
     }
     //create an contribution address
     if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params) && CRM_Utils_Array::value('is_monetary', $form->_values)) {
         $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
     }
     // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
     $contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
     $contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Confirm.php

示例12: createDeferredTrxn

 /**
  * Create transaction for deferred revenue.
  *
  * @param array $lineItems
  *
  * @param array $contributionDetails
  *
  * @param bool $update
  *
  * @param string $context
  *
  */
 public static function createDeferredTrxn($lineItems, $contributionDetails, $update = FALSE, $context = NULL)
 {
     if (empty($lineItems)) {
         return FALSE;
     }
     $revenueRecognitionDate = $contributionDetails->revenue_recognition_date;
     if (!CRM_Utils_System::isNull($revenueRecognitionDate)) {
         $statuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         if (!$update && (CRM_Utils_Array::value($contributionDetails->contribution_status_id, $statuses) != 'Completed' || CRM_Utils_Array::value($contributionDetails->contribution_status_id, $statuses) != 'Pending' && $contributionDetails->is_pay_later)) {
             return;
         }
         $trxnParams = array('contribution_id' => $contributionDetails->id, 'fee_amount' => '0.00', 'currency' => $contributionDetails->currency, 'trxn_id' => $contributionDetails->trxn_id, 'status_id' => $contributionDetails->contribution_status_id, 'payment_instrument_id' => $contributionDetails->payment_instrument_id, 'check_number' => $contributionDetails->check_number, 'is_payment' => 1);
         $deferredRevenues = array();
         foreach ($lineItems as $priceSetID => $lineItem) {
             if (!$priceSetID) {
                 continue;
             }
             foreach ($lineItem as $key => $item) {
                 $lineTotal = !empty($item['deferred_line_total']) ? $item['deferred_line_total'] : $item['line_total'];
                 if ($lineTotal <= 0 && !$update) {
                     continue;
                 }
                 $deferredRevenues[$key] = $item;
                 if ($context == 'changeFinancialType') {
                     $deferredRevenues[$key]['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $item['id'], 'financial_type_id');
                 }
                 if (in_array($item['entity_table'], array('civicrm_participant', 'civicrm_contribution'))) {
                     $deferredRevenues[$key]['revenue'][] = array('amount' => $lineTotal, 'revenue_date' => $revenueRecognitionDate);
                 } else {
                     // for membership
                     $item['line_total'] = $lineTotal;
                     $deferredRevenues[$key]['revenue'] = self::getMembershipRevenueAmount($item);
                 }
             }
         }
         $accountRel = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
         CRM_Utils_Hook::alterDeferredRevenueItems($deferredRevenues, $contributionDetails, $update, $context);
         foreach ($deferredRevenues as $key => $deferredRevenue) {
             $results = civicrm_api3('EntityFinancialAccount', 'get', array('entity_table' => 'civicrm_financial_type', 'entity_id' => $deferredRevenue['financial_type_id'], 'account_relationship' => array('IN' => array('Income Account is', 'Deferred Revenue Account is'))));
             if ($results['count'] != 2) {
                 continue;
             }
             foreach ($results['values'] as $result) {
                 if ($result['account_relationship'] == $accountRel) {
                     $trxnParams['to_financial_account_id'] = $result['financial_account_id'];
                 } else {
                     $trxnParams['from_financial_account_id'] = $result['financial_account_id'];
                 }
             }
             foreach ($deferredRevenue['revenue'] as $revenue) {
                 $trxnParams['total_amount'] = $trxnParams['net_amount'] = $revenue['amount'];
                 $trxnParams['trxn_date'] = CRM_Utils_Date::isoToMysql($revenue['revenue_date']);
                 $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
                 $entityParams = array('entity_id' => $deferredRevenue['financial_item_id'], 'entity_table' => 'civicrm_financial_item', 'amount' => $revenue['amount'], 'financial_trxn_id' => $financialTxn->id);
                 civicrm_api3('EntityFinancialTrxn', 'create', $entityParams);
             }
         }
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:71,代码来源:FinancialTrxn.php

示例13: processContribution

 /**
  * Process the contribution
  *
  * @return void
  * @access public
  */
 static function processContribution(&$form, $params, $result, $contactID, $pending = false, $isAdditionalAmount = false)
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $config = CRM_Core_Config::singleton();
     $now = date('YmdHis');
     $receiptDate = null;
     if ($form->_values['event']['is_email_confirm']) {
         $receiptDate = $now;
     }
     //CRM-4196
     if ($isAdditionalAmount) {
         $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
     }
     $contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $form->_values['event']['contribution_type_id'] ? $form->_values['event']['contribution_type_id'] : $params['contribution_type_id'], 'receive_date' => $now, 'total_amount' => $params['amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => $params['description'], 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0));
     if (!CRM_Utils_Array::value('is_pay_later', $params)) {
         $contribParams['payment_instrument_id'] = 1;
     }
     if (!$pending && $result) {
         $contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate);
     }
     require_once 'CRM/Contribute/PseudoConstant.php';
     $allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
     $contribParams["contribution_status_id"] = array_search('Completed', $allStatuses);
     if ($pending) {
         $contribParams["contribution_status_id"] = array_search('Pending', $allStatuses);
     }
     $contribParams["is_test"] = 0;
     if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
         $contribParams["is_test"] = 1;
     }
     $contribID = null;
     if (CRM_Utils_Array::value('invoice_id', $contribParams)) {
         $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
     }
     $ids = array();
     if ($contribID) {
         $ids['contribution'] = $contribID;
         $contribParams['id'] = $contribID;
     }
     require_once 'CRM/Contribute/BAO/Contribution.php';
     //create an contribution address
     if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params)) {
         $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
     }
     // create contribution record
     $contribution =& CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
     // return if pending
     if ($pending || $contribution->total_amount == 0) {
         $transaction->commit();
         return $contribution;
     }
     // next create the transaction record
     $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $params['amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'currency' => $params['currencyID'], 'payment_processor' => $form->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
     require_once 'CRM/Core/BAO/FinancialTrxn.php';
     $trxn =& CRM_Core_BAO_FinancialTrxn::create($trxnParams);
     $transaction->commit();
     return $contribution;
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:65,代码来源:Confirm.php

示例14: postProcess

 /**
  * Function to process the renewal form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $ids = array();
     $config = CRM_Core_Config::singleton();
     // get the submitted form values.
     $this->_params = $formValues = $this->controller->exportValues($this->_name);
     $this->storeContactFields($formValues);
     // use values from screen
     if ($formValues['membership_type_id'][1] != 0) {
         $defaults['receipt_text_renewal'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1], 'receipt_text_renewal');
     }
     $now = CRM_Utils_Date::getToday(null, 'YmdHis');
     if (CRM_Utils_Array::value('receive_date', $this->_params)) {
         $formValues['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date']);
     } else {
         $formValues['receive_date'] = $now;
     }
     $this->assign('receive_date', $formValues['receive_date']);
     if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
         $formValues['receipt_date'] = $now;
         $this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($formValues['receipt_date']));
     } else {
         $formValues['receipt_date'] = NULL;
     }
     if ($this->_mode) {
         $formValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'));
         $formValues['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id');
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode);
         $fields = array();
         // set email for primary location.
         $fields['email-Primary'] = 1;
         $formValues['email-5'] = $formValues['email-Primary'] = $this->_contributorEmail;
         $formValues['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues);
         $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $formValues)) {
                 $formValues[$name] = $formValues["billing_{$name}"];
                 $formValues['preserveDBName'] = TRUE;
             }
         }
         //here we are setting up the billing contact - if different from the member they are already created
         // but they will get billing details assigned
         CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contributorContactID, NULL, NULL, $ctype);
         // add all the additional payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $formValues['total_amount'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the passed params
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         $paymentParams['contactID'] = $this->_contributorContactID;
         //CRM-10377 if payment is by an alternate contact then we need to set that person
         // as the contact in the payment params
         if ($this->_contributorContactID != $this->_contactID) {
             if (CRM_Utils_Array::value('honor_type_id', $this->_params)) {
                 $paymentParams['honor_contact_id'] = $this->_contactID;
                 $paymentParams['honor_type_id'] = $this->_params['honor_type_id'];
             }
         }
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
         $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $formValues['contribution_status_id'] = 1;
         $formValues['invoice_id'] = $this->_params['invoiceID'];
         $formValues['trxn_id'] = $result['trxn_id'];
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:MembershipRenewal.php

示例15: 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');
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:93,代码来源:Participant.php


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