<?php
-// $Id$
-
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
'currency',
'financial_type_id',
);
- $retrieverequired = 0;
+ $retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if(!isset($contribution->$titleField)){
- $retrieverequired = 1;
+ $retrieveRequired = 1;
break;
}
}
- if ($retrieverequired == 1) {
- $contribution->find(true);
+ if ($retrieveRequired == 1) {
+ $contribution->find(TRUE);
}
}
if (!$activity->find()) {
CRM_Activity_BAO_Activity::addActivity($contribution, 'Offline');
}
+
// Handle soft credit and / or link to personal campaign page
- if (CRM_Utils_Array::value('deleteSoftCredit', $params, TRUE)) {
- // first delete soft credits if any
- CRM_Contribute_BAO_ContributionSoft::del($contribution->id);
-
- if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
- $softParams = array();
- $softParams['contribution_id'] = $contribution->id;
- $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
- $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
- $pcp['pcp_made_through_id'], 'contact_id'
- );
- $softParams['currency'] = $contribution->currency;
- $softParams['amount'] = $contribution->total_amount;
- $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
- $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
- $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
- CRM_Contribute_BAO_ContributionSoft::add($softParams);
- }
- elseif (CRM_Utils_Array::value('soft_credit', $params)) {
- $softParams = $params['soft_credit'];
- foreach ($softParams as $softParam) {
- $softParam['contribution_id'] = $contribution->id;
- $softParam['currency'] = $contribution->currency;
- CRM_Contribute_BAO_ContributionSoft::add($softParam);
+ list($type, $softIDs) = CRM_Contribute_BAO_ContributionSoft::getSoftCreditType($contribution->id);
+ if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
+ if (!empty($type) && $type == 'soft') {
+ $deleteParams = array('contribution_id' => $contribution->id);
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
+ $softParams = array();
+ $softParams['contribution_id'] = $contribution->id;
+ $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
+ $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
+ $pcp['pcp_made_through_id'], 'contact_id'
+ );
+ $softParams['currency'] = $contribution->currency;
+ $softParams['amount'] = $contribution->total_amount;
+ $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
+ $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
+ $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
+ CRM_Contribute_BAO_ContributionSoft::add($softParams);
+ }
+ elseif (CRM_Utils_Array::value('soft_credit', $params)) {
+ $softParams = $params['soft_credit'];
+
+ if (!empty($softIDs)) {
+ foreach ( $softIDs as $softID) {
+ if (!in_array($softID, $params['soft_credit_ids'])) {
+ $deleteParams = array('id' => $softID);
+ CRM_Contribute_BAO_ContributionSoft::del($deleteParams);
+ }
}
}
+
+ foreach ($softParams as $softParam) {
+ $softParam['contribution_id'] = $contribution->id;
+ $softParam['currency'] = $contribution->currency;
+ $softParam['pcp_id'] = 'null';
+ $softParam['pcp_display_in_roll'] = 'null';
+ $softParam['pcp_roll_nickname'] = 'null';
+ $softParam['pcp_personal_note'] = 'NULL';
+ CRM_Contribute_BAO_ContributionSoft::add($softParam);
+ }
}
+
$transaction->commit();
// do not add to recent items for import, CRM-4399
'currency',
'financial_type_id',
);
- $retrieverequired = 0;
+ $retrieveRequired = 0;
foreach ($titleFields as $titleField) {
if(!isset($contribution->$titleField)){
- $retrieverequired = 1;
+ $retrieveRequired = 1;
break;
}
}
- if($retrieverequired == 1){
- $contribution->find(true);
+ if($retrieveRequired == 1){
+ $contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->financial_type_id] . ')';
* @access public
* @static
*/
- static function &importableFields($contacType = 'Individual', $status = TRUE) {
+ static function &importableFields($contactType = 'Individual', $status = TRUE) {
if (!self::$_importableFields) {
if (!self::$_importableFields) {
self::$_importableFields = array();
$tmpFields = CRM_Contribute_DAO_Contribution::import();
unset($tmpFields['option_value']);
$optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute');
- $contactFields = CRM_Contact_BAO_Contact::importableFields($contacType, NULL);
+ $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
// Using new Dedupe rule.
$ruleParams = array(
- 'contact_type' => $contacType,
+ 'contact_type' => $contactType,
'used' => 'Unsupervised',
);
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
- $tmpConatctField = array();
+ $tmpContactField = array();
if (is_array($fieldsArray)) {
foreach ($fieldsArray as $value) {
//skip if there is no dupe rule
'column_name'
);
$value = $customFieldId ? 'custom_' . $customFieldId : $value;
- $tmpConatctField[trim($value)] = $contactFields[trim($value)];
+ $tmpContactField[trim($value)] = $contactFields[trim($value)];
if (!$status) {
- $title = $tmpConatctField[trim($value)]['title'] . ' ' . ts('(match to contact)');
+ $title = $tmpContactField[trim($value)]['title'] . ' ' . ts('(match to contact)');
}
else {
- $title = $tmpConatctField[trim($value)]['title'];
+ $title = $tmpContactField[trim($value)]['title'];
}
- $tmpConatctField[trim($value)]['title'] = $title;
+ $tmpContactField[trim($value)]['title'] = $title;
}
}
- $tmpConatctField['external_identifier'] = $contactFields['external_identifier'];
- $tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)');
+ $tmpContactField['external_identifier'] = $contactFields['external_identifier'];
+ $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)');
$tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . ' ' . ts('(match to contact)');
- $fields = array_merge($fields, $tmpConatctField);
+ $fields = array_merge($fields, $tmpContactField);
$fields = array_merge($fields, $tmpFields);
$fields = array_merge($fields, $note);
$fields = array_merge($fields, $optionFields);
CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id);
// remove entry from civicrm_price_set_entity, CRM-5095
- if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
- CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id);
+ if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) {
+ CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id);
}
// cleanup line items.
$participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
return $address->id;
}
- /**
- * Function to create soft contributon with contribution record.
- * @param array $params an associated array
- *
- * @return soft contribution id
- * @static
- */
- static function addSoftContribution($params) {
- $softContribution = new CRM_Contribute_DAO_ContributionSoft();
- $softContribution->copyValues($params);
-
- // set currency for CRM-1496
- if (!isset($softContribution->currency)) {
- $config = CRM_Core_Config::singleton();
- $softContribution->currency = $config->defaultCurrency;
- }
-
- return $softContribution->save();
- }
-
- /**
- * Function to retrieve soft contributions for contribution record.
- * @param array $params an associated array
- * @param boolean $all include PCP data
- *
- * @return array of soft contribution ids, amounts, and associated contact ids
- * @static
- */
- static function getSoftContribution($params, $all = FALSE) {
- $cs = new CRM_Contribute_DAO_ContributionSoft();
- $cs->copyValues($params);
- $softContribution = array();
- $cs->find();
- if ($cs->N > 0) {
- while ($cs->fetch()) {
-
- if ($all) {
- foreach (array(
- 'pcp_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note') as $key => $val) {
- $softContribution[$val] = $cs->$val;
- }
- }
- $softContribution[$cs->id]['soft_credit_to'] = $cs->contact_id;
- $softContribution[$cs->id]['soft_credit_id'] = $cs->id;
- $softContribution[$cs->id]['soft_credit_amount'] = $cs->amount;
- }
- }
- return $softContribution;
- }
-
- /**
- * Function to retrieve the list of soft contributons for given contact.
- * @param int $contact_id contact id
- *
- * @return array
- * @static
- */
- static function getSoftContributionList($contact_id, $isTest = 0) {
- $query = "
- SELECT ccs.id, ccs.amount as amount,
- ccs.contribution_id,
- ccs.pcp_id,
- ccs.pcp_display_in_roll,
- ccs.pcp_roll_nickname,
- ccs.pcp_personal_note,
- cc.receive_date,
- cc.contact_id as contributor_id,
- cc.contribution_status_id as contribution_status_id,
- cp.title as pcp_title,
- cc.currency,
- contact.display_name,
- cct.name as contributionType
- FROM civicrm_contribution_soft ccs
- LEFT JOIN civicrm_contribution cc
- ON ccs.contribution_id = cc.id
- LEFT JOIN civicrm_pcp cp
- ON ccs.pcp_id = cp.id
- LEFT JOIN civicrm_contact contact
- ON ccs.contribution_id = cc.id AND
- cc.contact_id = contact.id
- LEFT JOIN civicrm_financial_type cct
- ON cc.financial_type_id = cct.id
- WHERE cc.is_test = %2 AND ccs.contact_id = %1
- ORDER BY cc.receive_date DESC";
-
- $params = array(1 => array($contact_id, 'Integer'),
- 2 => array($isTest, 'Integer'));
- $cs = CRM_Core_DAO::executeQuery($query, $params);
- $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
- $result = array();
- while ($cs->fetch()) {
- $result[$cs->id]['amount'] = $cs->amount;
- $result[$cs->id]['currency'] = $cs->currency;
- $result[$cs->id]['contributor_id'] = $cs->contributor_id;
- $result[$cs->id]['contribution_id'] = $cs->contribution_id;
- $result[$cs->id]['contributor_name'] = $cs->display_name;
- $result[$cs->id]['financial_type'] = $cs->contributionType;
- $result[$cs->id]['receive_date'] = $cs->receive_date;
- $result[$cs->id]['pcp_id'] = $cs->pcp_id;
- $result[$cs->id]['pcp_title'] = $cs->pcp_title;
- $result[$cs->id]['pcp_display_in_roll'] = $cs->pcp_display_in_roll;
- $result[$cs->id]['pcp_roll_nickname'] = $cs->pcp_roll_nickname;
- $result[$cs->id]['pcp_personal_note'] = $cs->pcp_personal_note;
- $result[$cs->id]['contribution_status'] = CRM_Utils_Array::value($cs->contribution_status_id, $contributionStatus);
-
- if ($isTest) {
- $result[$cs->id]['contribution_status'] = $result[$cs->id]['contribution_status'] . '<br /> (test)';
- }
- }
- return $result;
- }
-
- static function getSoftContributionTotals($contact_id, $isTest = 0) {
- $query = "
- SELECT SUM(amount) as amount,
- AVG(total_amount) as average,
- cc.currency
- FROM civicrm_contribution_soft ccs
- LEFT JOIN civicrm_contribution cc
- ON ccs.contribution_id = cc.id
- WHERE cc.is_test = %2 AND
- ccs.contact_id = %1
- GROUP BY currency ";
-
- $params = array(1 => array($contact_id, 'Integer'),
- 2 => array($isTest, 'Integer'));
-
- $cs = CRM_Core_DAO::executeQuery($query, $params);
-
- $count = 0;
- $amount = $average = array();
-
- while ($cs->fetch()) {
- if ($cs->amount > 0) {
- $count++;
- $amount[] = $cs->amount;
- $average[] = $cs->average;
- $currency[] = $cs->currency;
- }
- }
-
- if ($count > 0) {
- return array(implode(', ', $amount),
- implode(', ', $average),
- implode(', ', $currency),
- );
- }
- return array(0, 0);
- }
-
/**
* Delete billing address record related contribution
*
$pledgeID = $pledgePayment[0]->pledge_id;
}
-
$membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
if ($participant) {
$dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
}
else {
- $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, null, null, null, $numterms);
+ $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $numterms);
}
//get the status for membership.
TRUE
);
- $formatedParams = array(
+ $formattedParams = array(
'status_id' => CRM_Utils_Array::value('id', $calcStatus,
array_search('Current', $membershipStatuses)
),
'end_date' => CRM_Utils_Date::customFormat($dates['end_date'], $format),
);
- CRM_Utils_Hook::pre('edit', 'Membership', $membership->id, $formatedParams);
+ CRM_Utils_Hook::pre('edit', 'Membership', $membership->id, $formattedParams);
- $membership->copyValues($formatedParams);
+ $membership->copyValues($formattedParams);
$membership->save();
//updating the membership log
$membershipLog = array();
- $membershipLog = $formatedParams;
+ $membershipLog = $formattedParams;
$logStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('log_start_date', $dates), $format);
- $logStartDate = ($logStartDate) ? CRM_Utils_Date::isoToMysql($logStartDate) : $formatedParams['start_date'];
+ $logStartDate = ($logStartDate) ? CRM_Utils_Date::isoToMysql($logStartDate) : $formattedParams['start_date'];
$membershipLog['start_date'] = $logStartDate;
$membershipLog['membership_id'] = $membership->id;
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
- CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
+ CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formattedParams);
$updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'],
'%B %E%f, %Y'
* Function to get individual id for onbehalf contribution
*
* @param int $contributionId contribution id
- * @param int $contributorId contributer id
+ * @param int $contributorId contributor id
*
* @return array $ids containing organization id and individual id
* @access public
AND civicrm_activity_contact.record_type_id = %3
";
- $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+ $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
$params = array(
}
}
$values['lineItem'][0] = $lineItem;
- $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $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');
}
}
$honorIds['contribution'] = $this->id;
$idParams = array('id' => $honorID, 'contact_id' => $honorID);
CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds);
- $honorType = CRM_Core_PseudoConstant::honor();
+ $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
$template->assign('honor_block_is_active', 1);
if (CRM_Utils_Array::value('prefix_id', $honorDefault)) {
- $prefix = CRM_Core_PseudoConstant::individualPrefix();
+ $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
$template->assign('honor_prefix', $prefix[$honorDefault['prefix_id']]);
}
$template->assign('honor_first_name', CRM_Utils_Array::value('first_name', $honorDefault));
*/
static function recordFinancialAccounts(&$params, $ids) {
$skipRecords = $update = FALSE;
- $additionalPaticipantId = array();
+ $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';
- $additionalPaticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId);
+ $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId);
}
else {
$entityId = $params['contribution']->id;
$entityTable = 'civicrm_contribution';
}
$entityID[] = $entityId;
- if (!empty($additionalPaticipantId)) {
- $entityID += $additionalPaticipantId;
+ if (!empty($additionalParticipantId)) {
+ $entityID += $additionalParticipantId;
}
if (!CRM_Utils_Array::value('prevContribution', $params)) {
$entityID = NULL;
}
+ else {
+ $update = TRUE;
+ }
// build line item array if its not set in $params
- if (!CRM_Utils_Array::value('line_item', $params) || $additionalPaticipantId) {
+ if (!CRM_Utils_Array::value('line_item', $params) || $additionalParticipantId) {
CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable));
}
$params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['payment_instrument_id']);
}
else {
- $params['to_financial_account_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1");
+ $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);
'currency' => $params['contribution']->currency,
'trxn_id' => $params['contribution']->trxn_id,
'status_id' => $params['contribution']->contribution_status_id,
- 'payment_instrument_id' => CRM_Utils_Array::value('payment_instrument_id', $params),
+ 'payment_instrument_id' => $params['contribution']->payment_instrument_id,
'check_number' => CRM_Utils_Array::value('check_number', $params),
);
self::updateFinancialAccounts($params);
}
}
- $update = TRUE;
}
if (!$update) {
}
}
// record line items and finacial items
-
if (!CRM_Utils_Array::value('skipLineItem', $params)) {
CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
}
'batch_id' => $params['batch_id'],
'entity_table' => 'civicrm_financial_trxn',
'entity_id' => $financialTxn->id,
- );
+ );
CRM_Batch_BAO_Batch::addBatchEntity($entityParams);
}
$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' "));
+ $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);
}
* @static
*/
static function checkStatusValidation($values, &$fields, &$errors) {
+ if (CRM_Utils_System::isNull($values) && CRM_Utils_Array::value('id', $fields)) {
+ $values['contribution_status_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $fields['id'], 'contribution_status_id');
+ if ($values['contribution_status_id'] == $fields['contribution_status_id']) {
+ return FALSE;
+ }
+ }
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$checkStatus = array(
'Cancelled' => array('Completed', 'Refunded'),