}
}
- //set defaults in create mode
+ //set defaults in create mode
if (!$contributionID) {
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
self::calculateMissingAmountParams($params);
* @return int
*/
public function getNumTermsByContributionAndMembershipType($membershipTypeID, $contributionID) {
- $numTerms = CRM_Core_DAO::singleValueQuery("
+ $numTerms = CRM_Core_DAO::singleValueQuery("
SELECT membership_num_terms FROM civicrm_line_item li
LEFT JOIN civicrm_price_field_value v ON li.price_field_value_id = v.id
WHERE contribution_id = %1 AND membership_type_id = %2",
- array(1 => array($contributionID, 'Integer') , 2 => array($membershipTypeID, 'Integer'))
+ array(1 => array($contributionID, 'Integer'), 2 => array($membershipTypeID, 'Integer'))
);
// default of 1 is precautionary
return empty($numTerms) ? 1 : $numTerms;
);
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
- if(!isset($contribution->$titleField)){
+ if (!isset($contribution->$titleField)) {
$retrieveRequired = 1;
break;
}
$softParams = $params['soft_credit'];
if (!empty($softIDs)) {
- foreach ( $softIDs as $softID) {
+ foreach ($softIDs as $softID) {
if (!in_array($softID, $params['soft_credit_ids'])) {
$deleteParams = array('id' => $softID);
CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
);
$retrieveRequired = 0;
foreach ($titleFields as $titleField) {
- if(!isset($contribution->$titleField)){
+ if (!isset($contribution->$titleField)) {
$retrieveRequired = 1;
break;
}
}
- if($retrieveRequired == 1){
+ if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
// Using new Dedupe rule.
$ruleParams = array(
'contact_type' => $contactType,
- 'used' => 'Unsupervised',
+ 'used' => 'Unsupervised',
);
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
$tmpContactField = array();
self::$_exportableFields = array();
}
- $impFields = CRM_Contribute_DAO_Contribution::export();
- $expFieldProduct = CRM_Contribute_DAO_Product::export();
- $expFieldsContrib = CRM_Contribute_DAO_ContributionProduct::export();
- $typeField = CRM_Financial_DAO_FinancialType::export();
- $financialAccount = CRM_Financial_DAO_FinancialAccount::export();
- $optionField = CRM_Core_OptionValue::getFields($mode = 'contribute');
+ $impFields = CRM_Contribute_DAO_Contribution::export();
+ $expFieldProduct = CRM_Contribute_DAO_Product::export();
+ $expFieldsContrib = CRM_Contribute_DAO_ContributionProduct::export();
+ $typeField = CRM_Financial_DAO_FinancialType::export();
+ $financialAccount = CRM_Financial_DAO_FinancialAccount::export();
+ $optionField = CRM_Core_OptionValue::getFields($mode = 'contribute');
$contributionStatus = array(
'contribution_status' => array(
'title' => ts('Contribution Status'),
'name' => 'contribution_status',
'data_type' => CRM_Utils_Type::T_STRING
- ));
+ )
+ );
$contributionNote = array(
'contribution_note' =>
- array(
- 'title' => ts('Contribution Note'),
- 'name' => 'contribution_note',
- 'data_type' => CRM_Utils_Type::T_TEXT
- )
+ array(
+ 'title' => ts('Contribution Note'),
+ 'name' => 'contribution_note',
+ 'data_type' => CRM_Utils_Type::T_TEXT
+ )
);
$contributionRecurId = array(
'name' => 'contribution_recur_id',
'where' => 'civicrm_contribution.contribution_recur_id',
'data_type' => CRM_Utils_Type::T_INT
- ));
+ )
+ );
$extraFields = array(
'contribution_batch' => array(
GROUP BY currency
";
- $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+ $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
$amount = array();
- $count = 0;
+ $count = 0;
while ($dao->fetch()) {
$count += $dao->total_count;
$amount[] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
}
if ($count) {
- return array('amount' => implode(', ', $amount),
+ return array(
+ 'amount' => implode(', ', $amount),
'count' => $count,
);
}
$input[3] = array($id, 'Integer');
}
- $query = "SELECT id FROM civicrm_contribution WHERE $clause";
- $dao = CRM_Core_DAO::executeQuery($query, $input);
+ $query = "SELECT id FROM civicrm_contribution WHERE $clause";
+ $dao = CRM_Core_DAO::executeQuery($query, $input);
$result = FALSE;
while ($dao->fetch()) {
$duplicates[] = $dao->id;
$config = CRM_Core_Config::singleton();
$params = array(1 => array($pageID, 'Integer'));
- $dao = CRM_Core_DAO::executeQuery($query, $params);
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
return array($dao->goal, $dao->total);
AND b.receive_date < $endDate
GROUP BY currency
";
- $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
- $count = 0;
+ $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+ $count = 0;
$amount = $average = array();
while ($dao->fetch()) {
if ($dao->count > 0 && $dao->amount > 0) {
}
}
$clause = implode(' AND ', $clause);
- $query = "SELECT id FROM civicrm_contribution WHERE $clause";
- $dao = CRM_Core_DAO::executeQuery($query, $input);
+ $query = "SELECT id FROM civicrm_contribution WHERE $clause";
+ $dao = CRM_Core_DAO::executeQuery($query, $input);
while ($dao->fetch()) {
$result = $dao->id;
}
if ($componentName == 'Event') {
- $idName = 'participant_id';
+ $idName = 'participant_id';
$componentTable = 'civicrm_participant';
- $paymentTable = 'civicrm_participant_payment';
- $source = ts('Online Event Registration');
+ $paymentTable = 'civicrm_participant_payment';
+ $source = ts('Online Event Registration');
}
if ($componentName == 'Membership') {
- $idName = 'membership_id';
+ $idName = 'membership_id';
$componentTable = 'civicrm_membership';
- $paymentTable = 'civicrm_membership_payment';
- $source = ts('Online Contribution');
+ $paymentTable = 'civicrm_membership_payment';
+ $source = ts('Online Contribution');
}
$pendingStatusId = array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
// we process only ( Completed, Cancelled, or Failed ) contributions.
if (!$contributionId ||
- !in_array($contributionStatusId, array(array_search('Completed', $contributionStatuses),
- array_search('Cancelled', $contributionStatuses),
- array_search('Failed', $contributionStatuses),
- ))
+ !in_array($contributionStatusId, array(
+ array_search('Completed', $contributionStatuses),
+ array_search('Cancelled', $contributionStatuses),
+ array_search('Failed', $contributionStatuses),
+ ))
) {
return $updateResult;
}
CRM_Core_Error::fatal();
}
- $memberships = &$objects['membership'];
- $participant = &$objects['participant'];
+ $memberships = &$objects['membership'];
+ $participant = &$objects['participant'];
$pledgePayment = &$objects['pledge_payment'];
- $contribution = &$objects['contribution'];
+ $contribution = &$objects['contribution'];
if ($pledgePayment) {
$pledgePaymentIDs = array();
//updating the membership log
$membershipLog = array();
$membershipLog = $formattedParams;
- $logStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('log_start_date', $dates), $format);
- $logStartDate = ($logStartDate) ? CRM_Utils_Date::isoToMysql($logStartDate) : $formattedParams['start_date'];
+ $logStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('log_start_date', $dates), $format);
+ $logStartDate = ($logStartDate) ? CRM_Utils_Date::isoToMysql($logStartDate) : $formattedParams['start_date'];
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
if ($processContribution) {
$contributionParams = array();
$fields = array(
- 'contact_id', 'total_amount', 'receive_date', 'is_test', 'campaign_id',
- 'payment_instrument_id', 'trxn_id', 'invoice_id', 'financial_type_id',
- 'contribution_status_id', 'non_deductible_amount', 'receipt_date', 'check_number',
+ 'contact_id',
+ 'total_amount',
+ 'receive_date',
+ 'is_test',
+ 'campaign_id',
+ 'payment_instrument_id',
+ 'trxn_id',
+ 'invoice_id',
+ 'financial_type_id',
+ 'contribution_status_id',
+ 'non_deductible_amount',
+ 'receipt_date',
+ 'check_number',
);
foreach ($fields as $field) {
if (empty($params[$field])) {
* @static
*/
public static function getContributionDates() {
- $config = CRM_Core_Config::singleton();
+ $config = CRM_Core_Config::singleton();
$currentMonth = date('m');
- $currentDay = date('d');
+ $currentDay = date('d');
if ((int ) $config->fiscalYearStart['M'] > $currentMonth ||
((int ) $config->fiscalYearStart['M'] == $currentMonth &&
(int ) $config->fiscalYearStart['d'] > $currentDay
else {
$year = date('Y');
}
- $year = array('Y' => $year);
+ $year = array('Y' => $year);
$yearDate = $config->fiscalYearStart;
$yearDate = array_merge($year, $yearDate);
$yearDate = CRM_Utils_Date::format($yearDate);
* @return bool
* @throws Exception
*/
- public function loadRelatedObjects(&$input, &$ids, $required = FALSE, $loadAll = false) {
- if($loadAll){
- $ids = array_merge($this->getComponentDetails($this->id),$ids);
- if(empty($ids['contact']) && isset($this->contact_id)){
+ public function loadRelatedObjects(&$input, &$ids, $required = FALSE, $loadAll = FALSE) {
+ if ($loadAll) {
+ $ids = array_merge($this->getComponentDetails($this->id), $ids);
+ if (empty($ids['contact']) && isset($this->contact_id)) {
$ids['contact'] = $this->contact_id;
}
}
if (empty($this->_component)) {
- if (! empty($ids['event'])) {
+ if (!empty($ids['event'])) {
$this->_component = 'event';
}
else {
// CRM-6056
//in any case get the memberships associated with the contribution
//because we now support multiple memberships w/ price set
- // see if there are any other memberships to be considered for same contribution.
- $query = "
+ // see if there are any other memberships to be considered for same contribution.
+ $query = "
SELECT membership_id
FROM civicrm_membership_payment
WHERE contribution_id = %1 ";
$params = array(1 => array($this->id, 'Integer'));
- $dao = CRM_Core_DAO::executeQuery($query, $params );
- while ($dao->fetch()) {
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
+ while ($dao->fetch()) {
if ($dao->membership_id) {
if (!is_array($ids['membership'])) {
$ids['membership'] = array();
}
- $ids['membership'][] = $dao->membership_id;
- }
+ $ids['membership'][] = $dao->membership_id;
}
+ }
if (array_key_exists('membership', $ids) && is_array($ids['membership'])) {
- foreach ($ids['membership'] as $id) {
- if (!empty($id)) {
- $membership = new CRM_Member_BAO_Membership();
- $membership->id = $id;
- if (!$membership->find(TRUE)) {
- throw new Exception("Could not find membership record: $id");
- }
- $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date);
- $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date);
- $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date);
- $this->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
- $membership->free();
+ foreach ($ids['membership'] as $id) {
+ if (!empty($id)) {
+ $membership = new CRM_Member_BAO_Membership();
+ $membership->id = $id;
+ if (!$membership->find(TRUE)) {
+ throw new Exception("Could not find membership record: $id");
}
+ $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date);
+ $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date);
+ $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date);
+ $this->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
+ $membership->free();
}
}
+ }
if (!empty($ids['pledge_payment'])) {
public function _gatherMessageValues($input, &$values, $ids = array()) {
// set display address of contributor
if ($this->address_id) {
- $addressParams = array('id' => $this->address_id);
- $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
- $addressDetails = array_values($addressDetails);
+ $addressParams = array('id' => $this->address_id);
+ $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
+ $addressDetails = array_values($addressDetails);
$values['address'] = $addressDetails[0]['display'];
}
if ($this->_component == 'contribute') {
if ($this->id) {
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->id, 'contribution', 1);
if (!empty($lineItem)) {
- $itemId = key($lineItem);
+ $itemId = key($lineItem);
foreach ($lineItem as &$eachItem) {
- if (array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership']) ) {
+ if (array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) {
$eachItem['join_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->join_date);
$eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date);
$eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date);
}
}
$values['lineItem'][0] = $lineItem;
- $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id');
- }
+ $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id');
+ }
}
$relatedContact = CRM_Contribute_BAO_Contribution::getOnbehalfIds(
$ufJoinParams = array(
'entity_table' => 'civicrm_event',
- 'entity_id' => $ids['event'],
- 'module' => 'CiviEvent',
+ 'entity_id' => $ids['event'],
+ 'module' => 'CiviEvent',
);
list($custom_pre_id,
- $custom_post_ids
- ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+ $custom_post_ids
+ ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
$values['custom_pre_id'] = $custom_pre_id;
$values['custom_post_id'] = $custom_post_ids;
*
* @return mixed
*/
- public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = True) {
+ public function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = TRUE) {
$template->assign('first_name', $this->_relatedObjects['contact']->first_name);
$template->assign('last_name', $this->_relatedObjects['contact']->last_name);
$template->assign('displayName', $this->_relatedObjects['contact']->display_name);
if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) {
- $template->assign('useForMember', true);
+ $template->assign('useForMember', TRUE);
}
//assign honor information to receipt message
$softRecord = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->id);
);
$softCreditTypes = CRM_Core_OptionGroup::values('soft_credit_type');
- $template->assign('soft_credit_type', $softRecord['soft_credit'][1]['soft_credit_type_label']);
+ $template->assign('soft_credit_type', $softRecord['soft_credit'][1]['soft_credit_type_label']);
$template->assign('honor_block_is_active', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFJoin', $values['id'], 'is_active', 'entity_id'));
}
else {
$template->assign('price', $productDAO->price);
$template->assign('sku', $productDAO->sku);
}
- $template->assign('title', CRM_Utils_Array::value('title',$values));
- $amount = CRM_Utils_Array::value('total_amount', $input,(CRM_Utils_Array::value('amount', $input)),null);
- if(empty($amount) && isset($this->total_amount)){
+ $template->assign('title', CRM_Utils_Array::value('title', $values));
+ $amount = CRM_Utils_Array::value('total_amount', $input, (CRM_Utils_Array::value('amount', $input)), NULL);
+ if (empty($amount) && isset($this->total_amount)) {
$amount = $this->total_amount;
}
$template->assign('amount', $amount);
$values['params'] = array();
//to get email of primary participant.
$primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $this->_relatedObjects['participant']->contact_id, 'email', 'contact_id');
- $primaryAmount[] = array('label' => $this->_relatedObjects['participant']->fee_level . ' - ' . $primaryEmail, 'amount' => $this->_relatedObjects['participant']->fee_amount);
+ $primaryAmount[] = array(
+ 'label' => $this->_relatedObjects['participant']->fee_level . ' - ' . $primaryEmail,
+ 'amount' => $this->_relatedObjects['participant']->fee_amount
+ );
//build an array of cId/pId of participants
$additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, NULL, $this->_relatedObjects['contact']->id, $isTest, TRUE);
unset($additionalIDs[$this->_relatedObjects['participant']->id]);
$additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id);
}
$amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount);
- $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount);
+ $primaryAmount[] = array(
+ 'label' => $additional->fee_level . ' - ' . $additionalParticipantInfo,
+ 'amount' => $additional->fee_amount
+ );
$additional->save();
$additional->free();
$template->assign('amount', $amount);
FROM civicrm_contribution_recur cr
LEFT JOIN civicrm_contribution con ON ( cr.id = con.contribution_recur_id )
WHERE con.id = %1 LIMIT 1";
- $params = array(1 => array($contributionId, 'Integer'));
+ $params = array(1 => array($contributionId, 'Integer'));
$statusId = CRM_Core_DAO::singleValueQuery($sql, $params);
- $status = CRM_Contribute_PseudoConstant::contributionStatus($statusId);
+ $status = CRM_Contribute_PseudoConstant::contributionStatus($statusId);
if ($status == 'Cancelled') {
return 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'])) {
+ && !empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])
+ ) {
$partialAmtPay = $params['partial_amount_pay'];
$partialAmtTotal = $params['partial_payment_total'];
}
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)) {
+ !(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));
+ $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);
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['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) {
+ $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);
//Update contribution status
$params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id;
if (!empty($params['contribution_status_id']) &&
- $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) {
+ $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id
+ ) {
//Update Financial Records
self::updateFinancialAccounts($params, 'changedStatus');
}
$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'];
+ $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)) {
+ !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))) {
+ 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'];
}
}
else if ((!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) {
+ !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');
}
else if (!CRM_Utils_System::isNull($params['contribution']->check_number) &&
- $params['contribution']->check_number != $params['prevContribution']->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;
$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) {
+ $totalAmount != $params['prevContribution']->total_amount
+ ) {
//Update Financial Records
$params['trxnParams']['from_financial_account_id'] = NULL;
self::updateFinancialAccounts($params, 'changedAmount');
}
if (!empty($params['prevContribution']) && $entityTable == 'civicrm_participant'
- && $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id) {
+ && $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('\ 1', '', $params['prevContribution']->amount_level);
CRM_Event_BAO_Participant::createDiscountTrxn($eventID, $params, $feeLevel);
//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['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus))
&& $params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus)
- && $context == 'changePaymentInstrument') {
+ && $context == 'changePaymentInstrument'
+ ) {
return;
}
if ($context == 'changedAmount' || $context == 'changeFinancialType') {
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'];
+ || $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)) {
+ && $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'];
+ $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(
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))) {
+ || $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'";
}
else {
if ($context == 'changeFinancialType' || $params['contribution']->contribution_status_id == array_search('Cancelled', $contributionStatus)
- || $params['contribution']->contribution_status_id == array_search('Refunded', $contributionStatus)) {
- $diff = -1;
+ || $params['contribution']->contribution_status_id == array_search('Refunded', $contributionStatus)
+ ) {
+ $diff = -1;
}
$amount = $diff * $fieldValues['line_total'];
}
);
if (!in_array($contributionStatuses[$fields['contribution_status_id']], $checkStatus[$contributionStatuses[$values['contribution_status_id']]])) {
- $errors['contribution_status_id'] = ts("Cannot change contribution status from %1 to %2.", array(1 => $contributionStatuses[$values['contribution_status_id']], 2 => $contributionStatuses[$fields['contribution_status_id']]));
+ $errors['contribution_status_id'] = ts("Cannot change contribution status from %1 to %2.", array(
+ 1 => $contributionStatuses[$values['contribution_status_id']],
+ 2 => $contributionStatuses[$fields['contribution_status_id']]
+ ));
}
}
$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'];
+ $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);
'entity_id' => $lineItemId->id,
'entity_table' => 'civicrm_line_item'
);
- $trxnIds['id'] = $financialTrxn->id;
+ $trxnIds['id'] = $financialTrxn->id;
CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds);
}
if ($participantId) {
if (empty($total) || $usingLineTotal) {
// for additional participants
if ($entityTable == 'civicrm_participant') {
- $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
- $total = 0;
- foreach ($ids as $val) {
- $total += CRM_Price_BAO_LineItem::getLineTotal($val, $entityTable);
- }
+ $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId);
+ $total = 0;
+ foreach ($ids as $val) {
+ $total += CRM_Price_BAO_LineItem::getLineTotal($val, $entityTable);
+ }
}
else {
$total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable);
$statuses = CRM_Contribute_PseudoConstant::contributionStatus();
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
- while($resultDAO->fetch()) {
+ while ($resultDAO->fetch()) {
$paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$val = array(
'account_relationship' => $accountRel,
);
$result = array();
- CRM_Financial_BAO_FinancialTypeAccount::retrieve( $searchParams, $result );
+ CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
- return CRM_Utils_Array::value( 'financial_account_id', $result );
+ return CRM_Utils_Array::value('financial_account_id', $result);
}
public static function checkTaxAmount($params, $isLineItem = FALSE) {
$prevContributionValue = CRM_Contribute_BAO_Contribution::getValues($contrbutionParams, $values, $ids);
// To assign pervious finantial type on update of contribution
- if (!isset($params['financial_type_id'])) {
+ if (!isset($params['financial_type_id'])) {
$params['financial_type_id'] = $prevContributionValue->financial_type_id;
}
else if (isset($params['financial_type_id']) && !array_key_exists($params['financial_type_id'], $taxRates)) {
// New Contrbution and update of contribution with tax rate financial type
if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) &&
- empty($params['skipLineItem']) && !$isLineItem)
- {
- $taxRateParams = $taxRates[$params['financial_type_id']];
- $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['total_amount'], $taxRateParams);
- $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
+ empty($params['skipLineItem']) && !$isLineItem
+ ) {
+ $taxRateParams = $taxRates[$params['financial_type_id']];
+ $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['total_amount'], $taxRateParams);
+ $params['tax_amount'] = round($taxAmount['tax_amount'], 2);
- // Get Line Item on update of contribution
- if (isset($params['id'])) {
- CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
- }
- else {
- CRM_Price_BAO_LineItem::getLineItemArray($params);
- }
- foreach ($params['line_item'] as $setID => $priceField) {
- foreach ($priceField as $priceFieldID => $priceFieldValue) {
- $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
- }
+ // Get Line Item on update of contribution
+ if (isset($params['id'])) {
+ CRM_Price_BAO_LineItem::getLineItemArray($params, array($params['id']));
+ }
+ else {
+ CRM_Price_BAO_LineItem::getLineItemArray($params);
+ }
+ foreach ($params['line_item'] as $setID => $priceField) {
+ foreach ($priceField as $priceFieldID => $priceFieldValue) {
+ $params['line_item'][$setID][$priceFieldID]['tax_amount'] = $params['tax_amount'];
}
- $params['total_amount'] = $params['total_amount'] + $params['tax_amount'];
}
+ $params['total_amount'] = $params['total_amount'] + $params['tax_amount'];
+ }
else if (isset($params['api.line_item.create'])) {
// Update total amount of contribution using lineItem
$taxAmountArray = array();
foreach ($params['api.line_item.create'] as $key => $value) {
if (isset($value['financial_type_id']) && array_key_exists($value['financial_type_id'], $taxRates)) {
- $taxRate = $taxRates[$value['financial_type_id']];
+ $taxRate = $taxRates[$value['financial_type_id']];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($value['line_total'], $taxRate);
$taxAmountArray[] = round($taxAmount['tax_amount'], 2);
}