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
*
public static function add(&$params) {
$contributionSoft = new CRM_Contribute_DAO_ContributionSoft();
$contributionSoft->copyValues($params);
+
+ // set currency for CRM-1496
+ if (!isset($contributionSoft->currency)) {
+ $config = CRM_Core_Config::singleton();
+ $contributionSoft->currency = $config->defaultCurrency;
+ }
return $contributionSoft->save();
}
$contributionSoft->contribution_id = $contributionID;
$contributionSoft->delete();
}
+
+
+ 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);
+ }
+
+ /**
+ * 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;
+ }
+
+
}
$this->_contributionType = $values['financial_type_id'];
$csParams = array('contribution_id' => $id);
- $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, TRUE);
+ $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
$softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
// add pcp id
$contribSoftParams['pcp_id'] = $params['pcp_made_through_id'];
- $softContribution = CRM_Contribute_BAO_Contribution::addSoftContribution($contribSoftParams);
+ $softContribution = CRM_Contribute_BAO_ContributionSoft::add($contribSoftParams);
}
}
//get soft credit record if exists.
$softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
- $softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams);
+ $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($softParams);
if (!empty($softContribution)) {
foreach($softContribution as &$individualSoftContribution) {
$individualSoftContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
'contact_id' => $formatted['soft_credit_to'],
'contribution_id' => $ids['contribution'],
);
- $existingSoftCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($dupeSoftCredit);
+ $existingSoftCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dupeSoftCredit);
if (CRM_Utils_Array::value('soft_credit_id', $existingSoftCredit)) {
$formatted['softID'] = $existingSoftCredit['soft_credit_id'];
}
}
$this->assign('isTest', $isTest);
- $softCreditList = CRM_Contribute_BAO_Contribution::getSoftContributionList($this->_contactId, $isTest);
+ $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $isTest);
if (!empty($softCreditList)) {
$softCreditTotals = array();
list($softCreditTotals['amount'],
$softCreditTotals['avg'],
$softCreditTotals['currency']
- ) = CRM_Contribute_BAO_Contribution::getSoftContributionTotals($this->_contactId, $isTest);
+ ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest);
$this->assign('softCredit', TRUE);
$this->assign('softCreditRows', $softCreditList);
//CRM-8662
$contribution_details = $query->store ( $dao );
$soft_params = array('contribution_id' => $dao->contribution_id);
- $soft_contribution = CRM_Contribute_BAO_Contribution::getSoftContribution ( $soft_params , true);
+ $soft_contribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution ( $soft_params , true);
$contribution [$dao->contribution_id] = array_merge($contribution_details, $soft_contribution);
}
return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao);