• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP CRM_Financial_BAO_FinancialItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deleteContact

 /**
  * Delete a contact and all its associated records.
  *
  * @param int $id
  *   Id of the contact to delete.
  * @param bool $restore
  *   Whether to actually restore, not delete.
  * @param bool $skipUndelete
  *   Whether to force contact delete or not.
  *
  * @return bool
  *   Was contact deleted?
  */
 public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
 {
     if (!$id) {
         return FALSE;
     }
     // If trash is disabled in system settings then we always skip
     if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL, 1)) {
         $skipUndelete = TRUE;
     }
     // make sure we have edit permission for this contact
     // before we delete
     if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
         return FALSE;
     }
     // CRM-12929
     // Restrict contact to be delete if contact has financial trxns
     $error = NULL;
     if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) {
         return FALSE;
     }
     // make sure this contact_id does not have any membership types
     $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
     if ($membershipTypeID) {
         return FALSE;
     }
     $contact = new CRM_Contact_DAO_Contact();
     $contact->id = $id;
     if (!$contact->find(TRUE)) {
         return FALSE;
     }
     $contactType = $contact->contact_type;
     // currently we only clear employer cache.
     // we are now deleting inherited membership if any.
     if ($contact->contact_type == 'Organization') {
         $action = $restore ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
         $relationshipDtls = CRM_Contact_BAO_Relationship::getRelationship($id);
         if (!empty($relationshipDtls)) {
             foreach ($relationshipDtls as $rId => $details) {
                 CRM_Contact_BAO_Relationship::disableEnableRelationship($rId, $action);
             }
         }
         CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
     }
     if ($restore) {
         return self::contactTrashRestore($contact, TRUE);
     }
     // start a new transaction
     $transaction = new CRM_Core_Transaction();
     if ($skipUndelete) {
         CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray);
         //delete billing address if exists.
         CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
         // delete the log entries since we dont have triggers enabled as yet
         $logDAO = new CRM_Core_DAO_Log();
         $logDAO->entity_table = 'civicrm_contact';
         $logDAO->entity_id = $id;
         $logDAO->delete();
         // delete contact participants CRM-12155
         CRM_Event_BAO_Participant::deleteContactParticipant($id);
         // delete contact contributions CRM-12155
         CRM_Contribute_BAO_Contribution::deleteContactContribution($id);
         // do activity cleanup, CRM-5604
         CRM_Activity_BAO_Activity::cleanupActivity($id);
         // delete all notes related to contact
         CRM_Core_BAO_Note::cleanContactNotes($id);
         // delete cases related to contact
         $contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id);
         if (!empty($contactCases)) {
             foreach ($contactCases as $caseId) {
                 //check if case is associate with other contact or not.
                 $caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId);
                 if (count($caseContactId) <= 1) {
                     CRM_Case_BAO_Case::deleteCase($caseId);
                 }
             }
         }
         $contact->delete();
     } else {
         self::contactTrashRestore($contact);
     }
     //delete the contact id from recently view
     CRM_Utils_Recent::delContact($id);
     // Update the group contact cache
     if ($restore) {
         CRM_Contact_BAO_GroupContactCache::remove();
     } else {
         CRM_Contact_BAO_GroupContactCache::removeContact($id);
//.........这里部分代码省略.........
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contact.php


示例2: processPriceSet

 /**
  * Function to process price set and line items.
  * @param int $contributionId contribution id
  * @param array $lineItem line item array
  * @param object $contributionDetails
  * @param decimal $initAmount amount
  * @param string $entityTable entity table
  *
  * @access public
  * @return void
  * @static
  */
 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;
             $line['entity_id'] = $entityId;
             // if financial type is not set and if price field value is NOT NULL
             // get financial type id of price field value
             if (CRM_Utils_Array::value('price_field_value_id', $line) && !CRM_Utils_Array::value('financial_type_id', $line)) {
                 $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) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
             }
         }
     }
 }
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:36,代码来源:LineItem.php


示例3: 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;
                 }
             }
             // 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) {
                 CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails);
                 if (isset($line['tax_amount'])) {
                     CRM_Financial_BAO_FinancialItem::add($lineItems, $contributionDetails, TRUE);
                 }
             }
         }
     }
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:52,代码来源:LineItem.php


示例4: _checkFinancialTrxn

 /**
  * Check financial transaction.
  *
  * @todo break this down into sensible functions - most calls to it only use a few lines out of the big if.
  *
  * @param array $contribution
  * @param string $context
  * @param int $instrumentId
  * @param array $extraParams
  */
 public function _checkFinancialTrxn($contribution, $context, $instrumentId = NULL, $extraParams = array())
 {
     $trxnParams = array('entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution');
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, TRUE));
     $params = array('id' => $trxn['financial_trxn_id']);
     if ($context == 'payLater') {
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $compareParams = array('status_id' => 1, 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId));
     } elseif ($context == 'refund') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => -100, 'status_id' => 7, 'trxn_date' => '2015-01-01 09:00:00', 'trxn_id' => 'the refund');
     } elseif ($context == 'cancelPending') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => -100, 'status_id' => 3);
     } elseif ($context == 'changeFinancial' || $context == 'paymentInstrument') {
         $entityParams = array('entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'amount' => -100);
         $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
         $trxnParams1 = array('id' => $trxn['financial_trxn_id']);
         if (empty($extraParams)) {
             $compareParams = array('total_amount' => -100, 'status_id' => 1);
         } else {
             $compareParams = array('total_amount' => 100, 'status_id' => 1);
         }
         if ($context == 'paymentInstrument') {
             $compareParams += array('to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4), 'payment_instrument_id' => 4);
         } else {
             $compareParams['to_financial_account_id'] = 12;
         }
         $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams1, array_merge($compareParams, $extraParams));
         $compareParams['total_amount'] = 100;
         if ($context == 'paymentInstrument') {
             $compareParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($instrumentId);
             $compareParams['payment_instrument_id'] = $instrumentId;
         } else {
             $compareParams['to_financial_account_id'] = 12;
         }
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $params, array_merge($compareParams, $extraParams));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:47,代码来源:ContributionTest.php


示例5: _checkFinancialRecords

 /**
  * @param array $params
  * @param $context
  */
 public function _checkFinancialRecords($params, $context)
 {
     $entityParams = array('entity_id' => $params['id'], 'entity_table' => 'civicrm_contribution');
     if ($context == 'pending') {
         $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
         $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
         return;
     }
     $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $trxnParams = array('id' => $trxn['financial_trxn_id']);
     if ($context != 'online' && $context != 'payLater') {
         $compareParams = array('to_financial_account_id' => 6, 'total_amount' => 120, 'status_id' => 1);
     }
     if ($context == 'online') {
         $compareParams = array('to_financial_account_id' => 12, 'total_amount' => 120, 'status_id' => 1);
     } elseif ($context == 'payLater') {
         $compareParams = array('to_financial_account_id' => 7, 'total_amount' => 120, 'status_id' => 2);
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
     $entityParams = array('financial_trxn_id' => $trxn['financial_trxn_id'], 'entity_table' => 'civicrm_financial_item');
     $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
     $fitemParams = array('id' => $entityTrxn['entity_id']);
     $compareParams = array('amount' => 100, 'status_id' => 1, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID));
     if ($context == 'payLater') {
         $compareParams = array('amount' => 100, 'status_id' => 3, 'financial_account_id' => $this->_getFinancialAccountId($this->financialtypeID));
     }
     $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:32,代码来源:TaxContributionPageTest.php


示例6: recordAdditionalPayment


//.........这里部分代码省略.........
             $trxnId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contributionDAO->payment_instrument_id);
         } else {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Asset' "));
             $queryParams = array(1 => array($relationTypeId, 'Integer'));
             $trxnId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = %1", $queryParams);
         }
         // update statuses
         // criteria for updates contribution total_amount == financial_trxns of partial_payments
         $sql = "SELECT SUM(ft.total_amount) as sum_of_payments, SUM(ft.net_amount) as net_amount_total\nFROM civicrm_financial_trxn ft\nLEFT JOIN civicrm_entity_financial_trxn eft\n  ON (ft.id = eft.financial_trxn_id)\nWHERE eft.entity_table = 'civicrm_contribution'\n  AND eft.entity_id = {$contributionId}\n  AND ft.to_financial_account_id != {$toFinancialAccount}\n  AND ft.status_id = {$statusId}\n";
         $query = CRM_Core_DAO::executeQuery($sql);
         $query->fetch();
         $sumOfPayments = $query->sum_of_payments;
         // update statuses
         if ($contributionDAO->total_amount == $sumOfPayments) {
             // update contribution status and
             // clean cancel info (if any) if prev. contribution was updated in case of 'Refunded' => 'Completed'
             $contributionDAO->contribution_status_id = $statusId;
             $contributionDAO->cancel_date = 'null';
             $contributionDAO->cancel_reason = NULL;
             $netAmount = !empty($trxnsData['net_amount']) ? NULL : $trxnsData['total_amount'];
             $contributionDAO->net_amount = $query->net_amount_total + $netAmount;
             $contributionDAO->fee_amount = $contributionDAO->total_amount - $contributionDAO->net_amount;
             $contributionDAO->save();
             //Change status of financial record too
             $financialTrxn->status_id = $statusId;
             $financialTrxn->save();
             // note : not using the self::add method,
             // the reason because it performs 'status change' related code execution for financial records
             // which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates
             // are coded below i.e. just updating financial_item status to 'Paid'
             if ($participantId) {
                 // update participant status
                 $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
                 $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
                 foreach ($ids as $val) {
                     $participantUpdate['id'] = $val;
                     $participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
                     CRM_Event_BAO_Participant::add($participantUpdate);
                 }
             }
             // update financial item statuses
             $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
             $paidStatus = array_search('Paid', $financialItemStatus);
             $baseTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId);
             $sqlFinancialItemUpdate = "\nUPDATE civicrm_financial_item fi\n  LEFT JOIN civicrm_entity_financial_trxn eft\n    ON (eft.entity_id = fi.id AND eft.entity_table = 'civicrm_financial_item')\nSET status_id = {$paidStatus}\nWHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})\n";
             CRM_Core_DAO::executeQuery($sqlFinancialItemUpdate);
         }
     } elseif ($paymentType == 'refund') {
         // build params for recording financial trxn entry
         $params['contribution'] = $contributionDAO;
         $params = array_merge($defaults, $params);
         $params['skipLineItem'] = TRUE;
         $trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
         $trxnsData['total_amount'] = -$trxnsData['total_amount'];
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $trxnsData['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId);
         $trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
         // record the entry
         $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
         // note : not using the self::add method,
         // the reason because it performs 'status change' related code execution for financial records
         // which in 'Pending Refund' => 'Completed' is not useful, instead specific financial record updates
         // are coded below i.e. just updating financial_item status to 'Paid'
         $contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
         // add financial item entry
         $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id');
         $getLine['entity_id'] = $contributionDAO->id;
         $getLine['entity_table'] = 'civicrm_contribution';
         $lineItemId = CRM_Price_BAO_LineItem::retrieve($getLine, CRM_Core_DAO::$_nullArray);
         if (!empty($lineItemId->id)) {
             $addFinancialEntry = array('transaction_date' => $financialTrxn->trxn_date, 'contact_id' => $contributionDAO->contact_id, 'amount' => $financialTrxn->total_amount, 'status_id' => array_search('Paid', $financialItemStatus), 'entity_id' => $lineItemId->id, 'entity_table' => 'civicrm_line_item');
             $trxnIds['id'] = $financialTrxn->id;
             CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds);
         }
         if ($participantId) {
             // update participant status
             $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
             $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
             foreach ($ids as $val) {
                 $participantUpdate['id'] = $val;
                 $participantUpdate['status_id'] = array_search('Registered', $participantStatuses);
                 CRM_Event_BAO_Participant::add($participantUpdate);
             }
         }
     }
     // activity creation
     if (!empty($financialTrxn)) {
         if ($participantId) {
             $inputParams['id'] = $participantId;
             $values = array();
             $ids = array();
             $component = 'event';
             $entityObj = CRM_Event_BAO_Participant::getValues($inputParams, $values, $ids);
             $entityObj = $entityObj[$participantId];
         }
         $activityType = $paymentType == 'refund' ? 'Refund' : 'Payment';
         self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId);
     }
     return $financialTrxn;
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:101,代码来源:Contribution.php


示例7: changeFeeSelections


//.........这里部分代码省略.........
         $updateLineItem = "UPDATE civicrm_line_item li\n        INNER JOIN civicrm_financial_item fi\n        ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\n        SET li.qty = 0,\n        li.line_total = 0.00,\n        li.tax_amount = NULL\n        WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
         CRM_Core_DAO::executeQuery($updateLineItem);
     }
     $amountLevel = array();
     $totalParticipant = $participantCount = 0;
     if (!empty($updateLines)) {
         foreach ($updateLines as $valueId => $vals) {
             $taxAmount = "NULL";
             if (isset($vals['tax_amount'])) {
                 $taxAmount = $vals['tax_amount'];
             }
             $amountLevel[] = $vals['label'] . ' - ' . (double) $vals['qty'];
             if (isset($vals['participant_count'])) {
                 $participantCount = $vals['participant_count'];
                 $totalParticipant += $vals['participant_count'];
             }
             $updateLineItem = "\nUPDATE civicrm_line_item li\nSET li.qty = {$vals['qty']},\n    li.line_total = {$vals['line_total']},\n    li.tax_amount = {$taxAmount},\n    li.unit_price = {$vals['unit_price']},\n    li.participant_count = {$participantCount},\n    li.label = %1\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n      (price_field_value_id = {$valueId})\n";
             CRM_Core_DAO::executeQuery($updateLineItem, array(1 => array($vals['label'], 'String')));
         }
     }
     // insert new 'adjusted amount' transaction entry and update contribution entry.
     // ensure entity_financial_trxn table has a linking of it.
     // insert new line items
     if (!empty($insertLines)) {
         foreach ($insertLines as $valueId => $lineParams) {
             $lineParams['entity_table'] = 'civicrm_participant';
             $lineParams['entity_id'] = $participantId;
             $lineParams['contribution_id'] = $contributionId;
             $lineObj = CRM_Price_BAO_LineItem::create($lineParams);
         }
     }
     // the recordAdjustedAmt code would execute over here
     $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
     if (count($ids) > 1) {
         $total = 0;
         foreach ($ids as $val) {
             $total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant');
         }
         $updatedAmount = $total;
     } else {
         $updatedAmount = $params['amount'];
     }
     if (strlen($params['tax_amount']) != 0) {
         $taxAmount = $params['tax_amount'];
     } else {
         $taxAmount = "NULL";
     }
     $displayParticipantCount = '';
     if ($totalParticipant > 0) {
         $displayParticipantCount = ' Participant Count -' . $totalParticipant;
     }
     $updateAmountLevel = NULL;
     if (!empty($amountLevel)) {
         $updateAmountLevel = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR;
     }
     $trxn = self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount, $updateAmountLevel);
     $trxnId = array();
     if ($trxn) {
         $trxnId['id'] = $trxn->id;
         foreach ($financialItemsArray as $updateFinancialItemInfoValues) {
             CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
             if (!empty($updateFinancialItemInfoValues['tax'])) {
                 $updateFinancialItemInfoValues['tax']['amount'] = $updateFinancialItemInfoValues['amount'];
                 $updateFinancialItemInfoValues['tax']['description'] = $updateFinancialItemInfoValues['description'];
                 if (!empty($updateFinancialItemInfoValues['financial_account_id'])) {
                     $updateFinancialItemInfoValues['financial_account_id'] = $updateFinancialItemInfoValues['tax']['financial_account_id'];
                 }
                 CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
             }
         }
     }
     $fetchCon = array('id' => $contributionId);
     $updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
     // insert financial items
     if (!empty($insertLines)) {
         foreach ($insertLines as $valueId => $lineParams) {
             $lineParams['entity_table'] = 'civicrm_participant';
             $lineParams['entity_id'] = $participantId;
             $lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
             // insert financial items
             // ensure entity_financial_trxn table has a linking of it.
             $prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, NULL, $trxnId);
             if (isset($lineObj->tax_amount)) {
                 CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, TRUE, $trxnId);
             }
         }
     }
     // update participant fee_amount column
     $partUpdateFeeAmt['id'] = $participantId;
     $getUpdatedLineItems = "SELECT *\nFROM civicrm_line_item\nWHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND qty > 0)";
     $getUpdatedLineItemsDAO = CRM_Core_DAO::executeQuery($getUpdatedLineItems);
     while ($getUpdatedLineItemsDAO->fetch()) {
         $line[$getUpdatedLineItemsDAO->price_field_value_id] = $getUpdatedLineItemsDAO->label . ' - ' . (double) $getUpdatedLineItemsDAO->qty;
     }
     $partUpdateFeeAmt['fee_level'] = implode(', ', $line);
     $partUpdateFeeAmt['fee_amount'] = $params['amount'];
     self::add($partUpdateFeeAmt);
     //activity creation
     self::addActivityForSelection($participantId, 'Change Registration');
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:101,代码来源:Participant.php


示例8: testRetrieveEntityFinancialTrxn

 /**
  * check method retrieveEntityFinancialTrxn()
  */
 function testRetrieveEntityFinancialTrxn()
 {
     $entityTrxn = self::testCreateEntityTrxn();
     $params = array('entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $entityTrxn->financial_trxn_id, 'amount' => $entityTrxn->amount);
     CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($params);
     $entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $entityTrxn->financial_trxn_id, 'amount', 'financial_trxn_id', 'Database check on added entity financial trxn record.');
     $this->assertEquals($entityResult, $entityTrxn->amount, 'Verify Amount for Financial Item');
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:11,代码来源:FinancialItemTest.php


示例9: 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


示例10: testChangeFinancialType

 public function testChangeFinancialType()
 {
     $this->webtestLogin();
     $amount = 100.0;
     $this->_testOfflineContribution($amount);
     $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']");
     $this->clickLink("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", '_qf_Contribution_cancel-bottom', FALSE);
     //Contribution status
     $this->select("financial_type_id", "value=3");
     $contId = explode('&id=', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
     $contId = explode('&', $contId[1]);
     $contId = $contId[0];
     $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='Edit']", FALSE);
     $this->waitForText('crm-notification-container', "The contribution record has been saved.");
     //Assertions
     $search = array('id' => $contId);
     $compare = array('financial_type_id' => 3);
     $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $search, $compare);
     $lineItem = key(CRM_Price_BAO_LineItem::getLineItems($contId, 'contribution'));
     $itemParams = array('amount' => '-100.00', 'entity_id' => $lineItem);
     $item1 = $item2 = array();
     CRM_Financial_BAO_FinancialItem::retrieve($itemParams, $item1);
     $this->assertEquals($item1['amount'], "-100.00", "Verify Amount for New Financial Item");
     $itemParams['amount'] = '100.00';
     CRM_Financial_BAO_FinancialItem::retrieve($itemParams, $item2);
     $this->assertEquals($item2['amount'], "100.00", "Verify Amount for New Financial Item");
     $cValue1 = $this->_getPremiumActualCost($contId, NULL, NULL, "-100.00", "'civicrm_contribution'");
     $fValue1 = $this->_getPremiumActualCost($item1['id'], NULL, NULL, "-100.00", "'civicrm_financial_item'");
     $this->assertEquals($cValue1, "-100.00", "Verify Amount");
     $this->assertEquals($fValue1, "-100.00", "Verify Amount");
     $cValue2 = $this->_getPremiumActualCost($contId, NULL, NULL, "100.00", "'civicrm_contribution'");
     $fValue2 = $this->_getPremiumActualCost($item2['id'], NULL, NULL, "100.00", "'civicrm_financial_item'");
     $this->assertEquals($cValue2, "100.00", "Verify Amount");
     $this->assertEquals($fValue2, "100.00", "Verify Amount");
 }
开发者ID:scardinius,项目名称:civicrm-core,代码行数:35,代码来源:UpdateContributionTest.php


示例11: changeFeeSelections

 /**
  * @param $params
  * @param $participantId
  * @param $contributionId
  * @param $feeBlock
  * @param $lineItems
  * @param $paidAmount
  * @param $priceSetId
  */
 static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId)
 {
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
     $pendngRefundStatusId = array_search('Pending refund', $contributionStatuses);
     $previousLineItems = CRM_Price_BAO_LineItem::getLineItems($participantId, 'participant');
     CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItems);
     // get the submitted
     foreach ($feeBlock as $id => $values) {
         CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
         $submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
     }
     $insertLines = $submittedLineItems;
     $submittedFieldValueIds = array_keys($submittedLineItems);
     $updateLines = array();
     foreach ($previousLineItems as $id => $previousLineItem) {
         // check through the submitted items if the previousItem exists,
         // if found in submitted items, do not use it for new item creations
         if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
             // if submitted line items are existing don't fire INSERT query
             unset($insertLines[$previousLineItem['price_field_value_id']]);
             // for updating the line items i.e. use-case - once deselect-option selecting again
             if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) {
                 $updateLines[$previousLineItem['price_field_value_id']]['qty'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'];
                 $updateLines[$previousLineItem['price_field_value_id']]['line_total'] = $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'];
             }
         }
     }
     $submittedFields = implode(', ', $submittedFieldId);
     $submittedFieldValues = implode(', ', $submittedFieldValueIds);
     if (!empty($submittedFields) && !empty($submittedFieldValues)) {
         $updateLineItem = "UPDATE civicrm_line_item li\nINNER JOIN civicrm_financial_item fi\n   ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nSET li.qty = 0,\n    li.line_total = 0.00\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n       (price_field_value_id NOT IN ({$submittedFieldValues}))\n";
         CRM_Core_DAO::executeQuery($updateLineItem);
         // gathering necessary info to record negative (deselected) financial_item
         $updateFinancialItem = "\n  SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id\n    FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})\nGROUP BY li.entity_table, li.entity_id, price_field_value_id\n";
         $updateFinancialItemInfoDAO = CRM_Core_DAO::executeQuery($updateFinancialItem);
         $trxn = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contributionId, 'ASC', TRUE);
         $trxnId['id'] = $trxn['financialTrxnId'];
         $updateFinancialItemInfoValues = array();
         while ($updateFinancialItemInfoDAO->fetch()) {
             $updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
             $updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
             // the below params are not needed
             unset($updateFinancialItemInfoValues['id']);
             unset($updateFinancialItemInfoValues['created_date']);
             // if not submitted and difference is not 0 make it negative
             if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
                 // INSERT negative financial_items
                 $updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
                 CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
             } elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
                 $updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
                 CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
             }
         }
     }
     if (!empty($updateLines)) {
         foreach ($updateLines as $valueId => $vals) {
             $updateLineItem = "\nUPDATE civicrm_line_item li\nSET li.qty = {$vals['qty']},\n    li.line_total = {$vals['line_total']}\nWHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND\n      (price_field_value_id = {$valueId})\n";
             CRM_Core_DAO::executeQuery($updateLineItem);
         }
     }
     // insert new 'adjusted amount' transaction entry and update contribution entry.
     // ensure entity_financial_trxn table has a linking of it.
     // insert new line items
     foreach ($insertLines as $valueId => $lineParams) {
         $lineParams['entity_table'] = 'civicrm_participant';
         $lineParams['entity_id'] = $participantId;
         $lineObj = CRM_Price_BAO_LineItem::create($lineParams);
     }
     // the recordAdjustedAmt code would execute over here
     $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
     if (count($ids) > 1) {
         $total = 0;
         foreach ($ids as $val) {
             $total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant');
         }
         $updatedAmount = $total;
     } else {
         $updatedAmount = $params['amount'];
     }
     self::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId);
     $fetchCon = array('id' => $contributionId);
     $updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
     // insert financial items
     foreach ($insertLines as $valueId => $lineParams) {
         $lineParams['entity_table'] = 'civicrm_participant';
         $lineParams['entity_id'] = $participantId;
         $lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
         // insert financial items
         // ensure entity_financial_trxn table has a linking of it.
//.........这里部分代码省略.........
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Participant.php


示例12: civicrm_api3_contact_delete

/**
 * Delete a contact with given contact id
 *
 * @param  array       $params (reference ) input parameters, contact_id element required
 *
 * @return array API Result Array
 * @access public
 *
 * @example ContactDelete.php
 * {@getfields contact_delete}
 */
function civicrm_api3_contact_delete($params)
{
    $contactID = CRM_Utils_Array::value('id', $params);
    $session = CRM_Core_Session::singleton();
    if ($contactID == $session->get('userID')) {
        return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
    }
    $restore = CRM_Utils_Array::value('restore', $params) ? $params['restore'] : FALSE;
    $skipUndelete = CRM_Utils_Array::value('skip_undelete', $params) ? $params['skip_undelete'] : FALSE;
    // CRM-12929
    // restrict permanent delete if a contact has financial trxn associated with it
    $error = NULL;
    if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($contactID), $error)) {
        return civicrm_api3_create_error($error['_qf_default']);
    }
    if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete)) {
        return civicrm_api3_create_success();
    } else {
        return civicrm_api3_create_error('Could not delete contact');
    }
}
开发者ID:hguru,项目名称:224Civi,代码行数:32,代码来源:Contact.php


示例13: testChangeFinancialType

 function testChangeFinancialType()
 {
     $this->webtestLogin();
     $firstName = substr(sha1(rand()), 0, 7);
     $lastName = 'Cont 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CRM_Financial_BAO_FinancialType类代码示例发布时间:2022-05-20
下一篇:
PHP CRM_Financial_BAO_FinancialAccount类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap