/**
  * Check method getFinancialAccount()
  */
 public function testGetFinancialAccount()
 {
     list($financialAccount, $financialType, $financialAccountType) = $this->createFinancialAccount('Asset');
     $params = array('financial_account_id' => $financialAccount->id, 'payment_processor_type_id' => 1, 'domain_id' => 1, 'billing_mode' => 1, 'name' => 'paymentProcessor');
     $processor = CRM_Financial_BAO_PaymentProcessor::create($params);
     $account = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($processor->id, 'civicrm_payment_processor');
     $this->assertEquals($account, $financialAccount->name, 'Verify Financial Account Name');
 }
Exemplo n.º 2
0
 /**
  * Create all financial accounts entry.
  *
  * @param array $params
  *   Contribution object, line item array and params for trxn.
  *
  *
  * @param array $financialTrxnValues
  *
  * @return null|object
  */
 public static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL)
 {
     $skipRecords = $update = $return = $isRelatedId = FALSE;
     $additionalParticipantId = array();
     $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if (CRM_Utils_Array::value('contribution_mode', $params) == 'participant') {
         $entityId = $params['participant_id'];
         $entityTable = 'civicrm_participant';
         $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId);
     } elseif (!empty($params['membership_id'])) {
         //so far $params['membership_id'] should only be set coming in from membershipBAO::create so the situation where multiple memberships
         // are created off one contribution should be handled elsewhere
         $entityId = $params['membership_id'];
         $entityTable = 'civicrm_membership';
     } else {
         $entityId = $params['contribution']->id;
         $entityTable = 'civicrm_contribution';
     }
     if (CRM_Utils_Array::value('contribution_mode', $params) == 'membership') {
         $isRelatedId = TRUE;
     }
     $entityID[] = $entityId;
     if (!empty($additionalParticipantId)) {
         $entityID += $additionalParticipantId;
     }
     // prevContribution appears to mean - original contribution object- ie copy of contribution from before the update started that is being updated
     if (empty($params['prevContribution'])) {
         $entityID = NULL;
     } else {
         $update = TRUE;
     }
     $statusId = $params['contribution']->contribution_status_id;
     // CRM-13964 partial payment
     if (CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Partially paid', $contributionStatuses) && !empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) {
         $partialAmtPay = $params['partial_amount_pay'];
         $partialAmtTotal = $params['partial_payment_total'];
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
         $fromFinancialAccountId = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId);
         $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
         $params['total_amount'] = $partialAmtPay;
         $balanceTrxnInfo = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($params['contribution']->id, $params['financial_type_id']);
         if (empty($balanceTrxnInfo['trxn_id'])) {
             // create new balance transaction record
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
             $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId);
             $balanceTrxnParams['total_amount'] = $partialAmtTotal;
             $balanceTrxnParams['to_financial_account_id'] = $toFinancialAccount;
             $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('net_amount', $params);
             $balanceTrxnParams['currency'] = $params['contribution']->currency;
             $balanceTrxnParams['trxn_id'] = $params['contribution']->trxn_id;
             $balanceTrxnParams['status_id'] = $statusId;
             $balanceTrxnParams['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
             $balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params);
             if (!empty($params['payment_processor'])) {
                 $balanceTrxnParams['payment_processor_id'] = $params['payment_processor'];
             }
             $financialTxn = CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams);
         }
     }
     // build line item array if its not set in $params
     if (empty($params['line_item']) || $additionalParticipantId) {
         CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable), $isRelatedId);
     }
     if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Failed', $contributionStatuses) && !(CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses) && !$params['contribution']->is_pay_later)) {
         $skipRecords = TRUE;
         $pendingStatus = array(array_search('Pending', $contributionStatuses), array_search('In Progress', $contributionStatuses));
         if (in_array(CRM_Utils_Array::value('contribution_status_id', $params), $pendingStatus)) {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
             $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId);
         } elseif (!empty($params['payment_processor'])) {
             $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
         } elseif (!empty($params['payment_instrument_id'])) {
             $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['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'));
             $params['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);
         }
         $totalAmount = CRM_Utils_Array::value('total_amount', $params);
         if (!isset($totalAmount) && !empty($params['prevContribution'])) {
             $totalAmount = $params['total_amount'] = $params['prevContribution']->total_amount;
         }
         //build financial transaction params
         $trxnParams = array('contribution_id' => $params['contribution']->id, 'to_financial_account_id' => $params['to_financial_account_id'], 'trxn_date' => !empty($params['contribution']->receive_date) ? $params['contribution']->receive_date : date('YmdHis'), 'total_amount' => $totalAmount, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'net_amount' => CRM_Utils_Array::value('net_amount', $params, $totalAmount), 'currency' => $params['contribution']->currency, 'trxn_id' => $params['contribution']->trxn_id, 'status_id' => $statusId, 'payment_instrument_id' => $params['contribution']->payment_instrument_id, 'check_number' => CRM_Utils_Array::value('check_number', $params));
         if (!empty($params['payment_processor'])) {
             $trxnParams['payment_processor_id'] = $params['payment_processor'];
         }
         if (isset($fromFinancialAccountId)) {
             $trxnParams['from_financial_account_id'] = $fromFinancialAccountId;
         }
         // consider external values passed for recording transaction entry
         if (!empty($financialTrxnValues)) {
             $trxnParams = array_merge($trxnParams, $financialTrxnValues);
         }
         $params['trxnParams'] = $trxnParams;
         if (!empty($params['prevContribution'])) {
             $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount;
             $params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount;
             $params['trxnParams']['net_amount'] = $params['prevContribution']->net_amount;
             $params['trxnParams']['trxn_id'] = $params['prevContribution']->trxn_id;
             $params['trxnParams']['status_id'] = $params['prevContribution']->contribution_status_id;
             if (!(($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses) || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatuses)) && $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses))) {
                 $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
                 $params['trxnParams']['check_number'] = $params['prevContribution']->check_number;
             }
             //if financial type is changed
             if (!empty($params['financial_type_id']) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) {
                 $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
                 $oldFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $incomeTypeId);
                 $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId);
                 if ($oldFinancialAccount != $newFinancialAccount) {
                     $params['total_amount'] = 0;
                     if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) {
                         $params['trxnParams']['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId);
                     } else {
                         $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC');
                         if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
                             $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
                         }
                     }
                     self::updateFinancialAccounts($params, 'changeFinancialType');
                     /* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */
                     $params['financial_account_id'] = $newFinancialAccount;
                     $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount'];
                     self::updateFinancialAccounts($params);
                     $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
                 }
             }
             //Update contribution status
             $params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id;
             $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id;
             if (!empty($params['contribution_status_id']) && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) {
                 //Update Financial Records
                 self::updateFinancialAccounts($params, 'changedStatus');
             }
             // change Payment Instrument for a Completed contribution
             // first handle special case when contribution is changed from Pending to Completed status when initial payment
             // instrument is null and now new payment instrument is added along with the payment
             $params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
             $params['trxnParams']['check_number'] = CRM_Utils_Array::value('check_number', $params);
             if (array_key_exists('payment_instrument_id', $params)) {
                 $params['trxnParams']['total_amount'] = -$trxnParams['total_amount'];
                 if (CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id) && !CRM_Utils_System::isNull($params['contribution']->payment_instrument_id)) {
                     //check if status is changed from Pending to Completed
                     // do not update payment instrument changes for Pending to Completed
                     if (!($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatuses) && in_array($params['prevContribution']->contribution_status_id, $pendingStatus))) {
                         // for all other statuses create new financial records
                         self::updateFinancialAccounts($params, 'changePaymentInstrument');
                         $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount'];
                         self::updateFinancialAccounts($params, 'changePaymentInstrument');
                     }
                 } elseif ((!CRM_Utils_System::isNull($params['contribution']->payment_instrument_id) || !CRM_Utils_System::isNull($params['prevContribution']->payment_instrument_id)) && $params['contribution']->payment_instrument_id != $params['prevContribution']->payment_instrument_id) {
                     // for any other payment instrument changes create new financial records
                     self::updateFinancialAccounts($params, 'changePaymentInstrument');
                     $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount'];
                     self::updateFinancialAccounts($params, 'changePaymentInstrument');
                 } elseif (!CRM_Utils_System::isNull($params['contribution']->check_number) && $params['contribution']->check_number != $params['prevContribution']->check_number) {
                     // another special case when check number is changed, create new financial records
                     // create financial trxn with negative amount
                     $params['trxnParams']['check_number'] = $params['prevContribution']->check_number;
                     self::updateFinancialAccounts($params, 'changePaymentInstrument');
                     // create financial trxn with positive amount
                     $params['trxnParams']['check_number'] = $params['contribution']->check_number;
                     $params['total_amount'] = $params['trxnParams']['total_amount'] = $trxnParams['total_amount'];
                     self::updateFinancialAccounts($params, 'changePaymentInstrument');
                 }
             }
             //if Change contribution amount
             $params['trxnParams']['fee_amount'] = CRM_Utils_Array::value('fee_amount', $params);
             $params['trxnParams']['net_amount'] = CRM_Utils_Array::value('net_amount', $params);
             $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $totalAmount;
             $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id;
             if (isset($totalAmount) && $totalAmount != $params['prevContribution']->total_amount) {
                 //Update Financial Records
                 $params['trxnParams']['from_financial_account_id'] = NULL;
                 self::updateFinancialAccounts($params, 'changedAmount');
             }
         }
         if (!$update) {
             // records finanical trxn and entity financial trxn
             // also make it available as return value
             $return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
             $params['entity_id'] = $financialTxn->id;
         }
     }
     // record line items and financial items
     if (empty($params['skipLineItem'])) {
         CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
     }
     // create batch entry if batch_id is passed and
     // ensure no batch entry is been made on 'Pending' or 'Failed' contribution, CRM-16611
     if (!empty($params['batch_id']) && !empty($financialTxn)) {
         $entityParams = array('batch_id' => $params['batch_id'], 'entity_table' => 'civicrm_financial_trxn', 'entity_id' => $financialTxn->id);
         CRM_Batch_BAO_Batch::addBatchEntity($entityParams);
     }
     // when a fee is charged
     if (!empty($params['fee_amount']) && (empty($params['prevContribution']) || $params['contribution']->fee_amount != $params['prevContribution']->fee_amount) && $skipRecords) {
         CRM_Core_BAO_FinancialTrxn::recordFees($params);
     }
     if (!empty($params['prevContribution']) && $entityTable == 'civicrm_participant' && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) {
         $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $entityId, 'event_id');
         $feeLevel[] = str_replace('', '', $params['prevContribution']->amount_level);
         CRM_Event_BAO_Participant::createDiscountTrxn($eventID, $params, $feeLevel);
     }
     unset($params['line_item']);
     return $return;
 }
Exemplo n.º 3
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if ($this->_ppType) {
         $defaults['payment_processor_type_id'] = $this->_ppType;
     }
     if (!$this->_id) {
         $defaults['is_active'] = $defaults['is_default'] = 1;
         $defaults['url_site'] = $this->_ppDAO->url_site_default;
         $defaults['url_api'] = $this->_ppDAO->url_api_default;
         $defaults['url_recur'] = $this->_ppDAO->url_recur_default;
         $defaults['url_button'] = $this->_ppDAO->url_button_default;
         $defaults['test_url_site'] = $this->_ppDAO->url_site_test_default;
         $defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
         $defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
         $defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
         return $defaults;
     }
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     if (!$dao->find(TRUE)) {
         return $defaults;
     }
     CRM_Core_DAO::storeValues($dao, $defaults);
     // now get testID
     $testDAO = new CRM_Financial_DAO_PaymentProcessor();
     $testDAO->name = $dao->name;
     $testDAO->is_test = 1;
     $testDAO->domain_id = $domainID;
     if ($testDAO->find(TRUE)) {
         $this->_testID = $testDAO->id;
         foreach ($this->_fields as $field) {
             $testName = "test_{$field['name']}";
             $defaults[$testName] = $testDAO->{$field['name']};
         }
     }
     $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor', 'financial_account_id');
     return $defaults;
 }
Exemplo n.º 4
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = array();
     if (!$this->_id) {
         $defaults['is_active'] = $defaults['is_default'] = 1;
         $defaults['url_site'] = $this->_ppDAO->url_site_default;
         $defaults['url_api'] = $this->_ppDAO->url_api_default;
         $defaults['url_recur'] = $this->_ppDAO->url_recur_default;
         $defaults['url_button'] = $this->_ppDAO->url_button_default;
         $defaults['test_url_site'] = $this->_ppDAO->url_site_test_default;
         $defaults['test_url_api'] = $this->_ppDAO->url_api_test_default;
         $defaults['test_url_recur'] = $this->_ppDAO->url_recur_test_default;
         $defaults['test_url_button'] = $this->_ppDAO->url_button_test_default;
         $defaults['payment_instrument_id'] = $this->_ppDAO->payment_instrument_id;
         // When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
         if ($this->_ppType) {
             $defaults['payment_processor_type_id'] = $this->_ppType;
         }
         return $defaults;
     }
     $domainID = CRM_Core_Config::domainID();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->id = $this->_id;
     $dao->domain_id = $domainID;
     if (!$dao->find(TRUE)) {
         return $defaults;
     }
     CRM_Core_DAO::storeValues($dao, $defaults);
     // When user changes payment processor type, it is passed in via $this->_ppType so update defaults array.
     if ($this->_ppType) {
         $defaults['payment_processor_type_id'] = $this->_ppType;
     }
     $cards = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $this->_id, 'accepted_credit_cards'), TRUE);
     $acceptedCards = array();
     if (!empty($cards)) {
         foreach ($cards as $card => $val) {
             $acceptedCards[$card] = 1;
         }
     }
     $defaults['accept_credit_cards'] = $acceptedCards;
     unset($defaults['accepted_credit_cards']);
     // now get testID
     $testDAO = new CRM_Financial_DAO_PaymentProcessor();
     $testDAO->name = $dao->name;
     $testDAO->is_test = 1;
     $testDAO->domain_id = $domainID;
     if ($testDAO->find(TRUE)) {
         $this->_testID = $testDAO->id;
         foreach ($this->_fields as $field) {
             $testName = "test_{$field['name']}";
             $defaults[$testName] = $testDAO->{$field['name']};
         }
     }
     $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor', 'financial_account_id');
     return $defaults;
 }
 /**
  * check method getFinancialAccount()
  */
 function testGetFinancialAccount()
 {
     $params = array('name' => 'TestFinancialAccount', 'accounting_code' => 4800, 'is_deductible' => 0, 'is_active' => 1, 'is_reserved' => 0);
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
     $params = array('financial_account_id' => $financialAccount->id, 'payment_processor_type_id' => 1, 'domain_id' => 1, 'billing_mode' => 1, 'name' => 'paymentProcessor');
     $processor = CRM_Financial_BAO_PaymentProcessor::create($params);
     $account = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($processor->id, 'civicrm_payment_processor');
     $this->assertEquals($account, 'TestFinancialAccount', 'Verify Financial Account Name');
 }
Exemplo n.º 6
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     // Default weight & value
     $fieldValues = array('option_group_id' => $this->_gid);
     foreach (array('weight', 'value') as $field) {
         if (empty($defaults[$field])) {
             $defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field);
         }
     }
     //setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee'))) {
         $defaults['contactOptions'] = CRM_Utils_Array::value('filter', $defaults) ? $defaults['filter'] : NULL;
     }
     // CRM-11516
     if ($this->_gName == 'payment_instrument' && $this->_id) {
         $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($this->_id, 'civicrm_option_value', 'financial_account_id');
     }
     return $defaults;
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
 /**
  * Browse all payment processors.
  *
  * @param null $action
  *
  * @return void
  * @access public
  * @static
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $paymentProcessor = array();
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->is_test = 0;
     $dao->domain_id = CRM_Core_Config::domainID();
     $dao->orderBy('name');
     $dao->find();
     while ($dao->fetch()) {
         $paymentProcessor[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
         $paymentProcessor[$dao->id]['payment_processor_type'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType', $paymentProcessor[$dao->id]['payment_processor_type_id']);
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $paymentProcessor[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'paymentProcessor.manage.action', 'PaymentProcessor', $dao->id);
         $paymentProcessor[$dao->id]['financialAccount'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($dao->id, 'civicrm_payment_processor');
     }
     $this->assign('rows', $paymentProcessor);
 }
Exemplo n.º 9
0
 /**
  * Browse all options
  *
  *
  * @return void
  * @access public
  * @static
  */
 function browse()
 {
     if (!self::$_gName) {
         return parent::browse();
     }
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
     $groupParams = array('name' => self::$_gName);
     $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
     $gName = self::$_gName;
     $returnURL = CRM_Utils_System::url("civicrm/admin/options/{$gName}", "reset=1&group={$gName}");
     $filter = "option_group_id = " . self::$_gId;
     CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter);
     // retrieve financial account name for the payment instrument page
     if ($gName = "payment_instrument") {
         foreach ($optionValue as $key => $option) {
             $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value');
         }
     }
     $this->assign('includeWysiwygEditor', TRUE);
     $this->assign('rows', $optionValue);
 }
Exemplo n.º 10
0
 /**
  * Browse all options.
  *
  *
  * @return void
  */
 public function browse()
 {
     if (!self::$_gName) {
         return parent::browse();
     }
     $groupParams = array('name' => self::$_gName);
     $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
     $gName = self::$_gName;
     $returnURL = CRM_Utils_System::url("civicrm/admin/options/{$gName}", "reset=1&group={$gName}");
     $filter = "option_group_id = " . self::$_gId;
     CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue', 'id', $returnURL, $filter);
     // retrieve financial account name for the payment method page
     if ($gName = "payment_instrument") {
         foreach ($optionValue as $key => $option) {
             $optionValue[$key]['financial_account'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($key, 'civicrm_option_value');
         }
     }
     $this->assign('rows', $optionValue);
 }
Exemplo n.º 11
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     $defaults = parent::setDefaultValues();
     if (!CRM_Utils_Array::value('weight', $defaults)) {
         $query = "SELECT max( `weight` ) as weight FROM `civicrm_option_value` where option_group_id=" . $this->_gid;
         $dao = new CRM_Core_DAO();
         $dao->query($query);
         $dao->fetch();
         $defaults['weight'] = $dao->weight + 1;
     }
     // CRM-11516
     if ($this->_gName == 'payment_instrument' && $this->_id) {
         $defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($this->_id, 'civicrm_option_value', 'financial_account_id');
     }
     //setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575
     if (in_array($this->_gName, array('email_greeting', 'postal_greeting', 'addressee'))) {
         $defaults['contactOptions'] = CRM_Utils_Array::value('filter', $defaults);
     }
     return $defaults;
 }