From b6545333e8a376e5aac378c26b55f34e6394f1b4 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Sat, 29 Mar 2014 18:12:23 +0530 Subject: [PATCH] CRM-14377 fix - http://issues.civicrm.org/jira/browse/CRM-14377 --- CRM/Contribute/BAO/Contribution.php | 8 +-- CRM/Contribute/BAO/ContributionSoft.php | 68 +++++++------------ CRM/Contribute/Form/Contribution.php | 33 +++++---- CRM/Contribute/Form/ContributionView.php | 11 ++- CRM/Contribute/Form/SoftCredit.php | 7 +- .../CRM/Contribute/Form/Contribution.tpl | 47 +++++++------ .../CRM/Contribute/Form/ContributionView.tpl | 10 +-- templates/CRM/Contribute/Form/SoftCredit.tpl | 1 + templates/CRM/Contribute/Page/Tab.hlp | 12 ++++ 9 files changed, 98 insertions(+), 99 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d19728a1a9..68514a7e1e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -318,10 +318,10 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } // Handle soft credit and / or link to personal campaign page - list($type, $softIDs) = CRM_Contribute_BAO_ContributionSoft::getSoftCreditType($contribution->id); + $softIDs = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id); if ($pcp = CRM_Utils_Array::value('pcp', $params)) { - if (!empty($type) && $type == 'soft') { - $deleteParams = array('contribution_id' => $contribution->id); + if ($pcpId = CRM_Contribute_BAO_ContributionSoft::getSoftCreditIds($contribution->id, TRUE)) { + $deleteParams = array('id' => $pcpId); CRM_Contribute_BAO_ContributionSoft::del($deleteParams); } $softParams = array(); @@ -338,7 +338,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $softParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name'); CRM_Contribute_BAO_ContributionSoft::add($softParams); } - elseif (isset($params['soft_credit'])) { + if (isset($params['soft_credit'])) { $softParams = $params['soft_credit']; if (!empty($softIDs)) { diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index af23c793c0..39436c6409 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -147,14 +147,16 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio static function getSoftContribution($contributionID, $all = FALSE) { $pcpFields = array( 'pcp_id', + 'pcp_title', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', ); $query = ' - SELECT ccs.id, pcp_id, pcp_display_in_roll, pcp_roll_nickname, pcp_personal_note, currency, amount, contact_id, c.display_name, ccs.soft_credit_type_id + SELECT ccs.id, pcp_id, cpcp.title as pcp_title, pcp_display_in_roll, pcp_roll_nickname, pcp_personal_note, ccs.currency as currency, amount, ccs.contact_id as contact_id, c.display_name, ccs.soft_credit_type_id FROM civicrm_contribution_soft ccs INNER JOIN civicrm_contact c on c.id = ccs.contact_id + LEFT JOIN civicrm_pcp cpcp ON ccs.pcp_id = cpcp.id WHERE contribution_id = %1; '; @@ -165,74 +167,54 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio $softContribution = array(); $count = 1; while ($dao->fetch()) { - if ($all) { - foreach ($pcpFields as $val) { - $softContribution[$val] = $dao->$val; - } - } - - $softContribution['soft_credit'][$count] = array( - 'contact_id' => $dao->contact_id, - 'soft_credit_id' => $dao->id, - 'currency' => $dao->currency, - 'amount' => $dao->amount, - 'contact_name' => $dao->display_name, - 'soft_credit_type' => $dao->soft_credit_type_id, - 'soft_credit_type_label' => CRM_Core_OptionGroup::getLabel('soft_credit_type', $dao->soft_credit_type_id) - ); - $count++; - } - - /* - * FIX API before deleting this - $cs = new CRM_Contribute_DAO_ContributionSoft(); - $cs->copyValues($params); - $softContribution = array(); - $cs->find(); - - if ($cs->N > 0) { - $count = 1; - while ($cs->fetch()) { + if ($dao->pcp_id) { if ($all) { foreach ($pcpFields as $val) { - $softContribution['pcp'][$val] = $cs->$val; + $softContribution[$val] = $dao->$val; } + $softContribution['pcp_soft_credit_to_name'] = $dao->display_name; + $softContribution['pcp_soft_credit_to_id'] = $dao->contact_id; } - + } + else { $softContribution['soft_credit'][$count] = array( - 'soft_credit_to' => $cs->contact_id, - 'soft_credit_id' => $cs->id, - 'soft_credit_amount' => $cs->amount, + 'contact_id' => $dao->contact_id, + 'soft_credit_id' => $dao->id, + 'currency' => $dao->currency, + 'amount' => $dao->amount, + 'contact_name' => $dao->display_name, + 'soft_credit_type' => $dao->soft_credit_type_id, + 'soft_credit_type_label' => CRM_Core_OptionGroup::getLabel('soft_credit_type', $dao->soft_credit_type_id) ); $count++; } } - */ return $softContribution; } - static function getSoftCreditType($contributionID) { + static function getSoftCreditIds($contributionID , $isPCP = FALSE) { $query = " - SELECT id, pcp_id + SELECT id FROM civicrm_contribution_soft WHERE contribution_id = %1 "; + + if ($isPCP) { + $query .= " AND pcp_id IS NOT NULL"; + } $params = array(1 => array($contributionID, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); $id = array(); $type = ''; while ($dao->fetch()) { - if ($dao->pcp_id) { - $type = 'pcp'; - } - else { - $type = 'soft'; + if ($isPCP) { + return $dao->id; } $id[] = $dao->id; } - return array($type, $id); + return $id; } /** diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index b1dc39ade9..cdb5d94e7f 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -655,7 +655,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP unset($status[CRM_Utils_Array::key('Overdue', $statusName)]); } } - + if ($this->_id) { $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id'); $name = CRM_Utils_Array::value($contributionStatus, $statusName); @@ -1031,23 +1031,22 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $pcp[$f] = CRM_Utils_Array::value($f, $submittedValues); } } + + $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id'])); + if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) { + //Delete existing soft credit records if soft credit list is empty on update + CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id)); + } else { - $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id'])); - if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) { - //Delete existing soft credit records if soft credit list is empty on update - CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id)); - } - else { - //build soft credit params - $softParams = $softIDs =array(); - foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) { - if ($val && $submittedValues['soft_credit_amount'][$key]) { - $softParams[$key]['contact_id'] = $val; - $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]); - $softParams[$key]['soft_credit_type_id'] = $submittedValues['soft_credit_type'][$key]; - if (!empty($submittedValues['soft_credit_id'][$key])) { - $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key]; - } + //build soft credit params + $softParams = $softIDs =array(); + foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) { + if ($val && $submittedValues['soft_credit_amount'][$key]) { + $softParams[$key]['contact_id'] = $val; + $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]); + $softParams[$key]['soft_credit_type_id'] = $submittedValues['soft_credit_type'][$key]; + if (!empty($submittedValues['soft_credit_id'][$key])) { + $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key]; } } } diff --git a/CRM/Contribute/Form/ContributionView.php b/CRM/Contribute/Form/ContributionView.php index 735c461644..f003909004 100644 --- a/CRM/Contribute/Form/ContributionView.php +++ b/CRM/Contribute/Form/ContributionView.php @@ -116,8 +116,15 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { $values['billing_address'] = $addressDetails[0]['display']; } - //get soft credit record if exists. - $values['softContributions'] = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id']); + //assign soft credit record if exists. + $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); + $this->assign('softContributions', $SCRecords['soft_credit']); + unset($SCRecords['soft_credit']); + + //assign pcp record if exists + foreach ($SCRecords as $name => $value) { + $this->assign($name, $value); + } $lineItems = array(); if ($id) { diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index db9170ba9f..cd9bd77406 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -153,11 +153,6 @@ class CRM_Contribute_Form_SoftCredit { CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"), array('id' => 'sct_default_id') ); - - // Tell tpl to hide soft credit field if contribution is linked directly to a PCP Page - if (!empty($form->_values['pcp_made_through_id'])) { - $form->assign('pcpLinked', 1); - } } /** @@ -171,7 +166,7 @@ class CRM_Contribute_Form_SoftCredit { $defaults["soft_credit_type[$key]"] = $value['soft_credit_type']; } } - elseif (!empty($form->_softCreditInfo['pcp_id'])) { + if (!empty($form->_softCreditInfo['pcp_id'])) { $pcpInfo = $form->_softCreditInfo; $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo); $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title'); diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 79f05effbf..9910569466 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -229,26 +229,33 @@
- {if $siteHasPCPs} - - - - + + + +
+ {include file="CRM/Contribute/Form/SoftCredit.tpl"} +
+
+ + + + + {if $siteHasPCPs} +
+
+ {ts}Personal Campaign Page{/ts} {help id="id-pcp"} +
+
+ +
{$form.pcp_made_through_id.label} {$form.pcp_made_through_id.html}   - - {ts}unlink from personal campaign page{/ts} -
{ts}Search for the Personal Campaign Page by the fund-raiser's last name or email address.{/ts}
-
+
@@ -273,16 +280,12 @@ - {/if} - - - -
{$form.pcp_display_in_roll.label}
- {include file="CRM/Contribute/Form/SoftCredit.tpl"} -
+
+
- - + {/if} + + {if !$contributionMode}
diff --git a/templates/CRM/Contribute/Form/ContributionView.tpl b/templates/CRM/Contribute/Form/ContributionView.tpl index 985e7e37cd..d13cf73fb3 100644 --- a/templates/CRM/Contribute/Form/ContributionView.tpl +++ b/templates/CRM/Contribute/Form/ContributionView.tpl @@ -194,14 +194,14 @@ {/if} -{if $softContributions and !$pcp_id} {* We show soft credit name with PCP section if contribution is linked to a PCP. *} +{if count($softContributions)} {* We show soft credit name with PCP section if contribution is linked to a PCP. *}
{ts}Soft Credit{/ts}
- {foreach from=$softContributions.soft_credit item="softCont"} + {foreach from=$softContributions item="softCont"} - - + diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index 43ba52e2ca..b9e762e6f9 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -119,6 +119,7 @@ }); $('.soft-credit-delete-link').click(function(){ + $(this).closest('tr').find('input').val(''); $(this).closest('tr').addClass('hiddenElement').removeAttr('style'); $('#addMoreSoftCredit').show(); return false; diff --git a/templates/CRM/Contribute/Page/Tab.hlp b/templates/CRM/Contribute/Page/Tab.hlp index 5f01073387..a2a6c66d93 100644 --- a/templates/CRM/Contribute/Page/Tab.hlp +++ b/templates/CRM/Contribute/Page/Tab.hlp @@ -66,6 +66,18 @@

{ts}When a contribution is made via a Personal Campaign Page, a soft credit for that contribution is automatically assigned to the contact who created the Personal Campaign Page.{/ts}

+{/htxt} + +{htxt id="id-pcp-title"} + {ts}Personal Campaign Page{/ts} +{/htxt} +{htxt id="id-pcp"} +

+{ts}Use to indicate that a contact has a relationship with the actual donor and / or was indirectly responsible for the contribution. For example, if one family member makes a large contribution - it is often useful to record a Soft Credit for the other family member(s). You can record a soft credit while adding or editing a contribution record from this tab.{/ts} +

+

+{ts}When a contribution is made via a Personal Campaign Page, a soft credit for that contribution is automatically assigned to the contact who created the Personal Campaign Page.{/ts} +

{/htxt} {htxt id="adjust-payment-amount-title"} -- 2.25.1
{ts}Personal Campaign Page{/ts}{$pcp}
+
{$pcp_title}
{ts}Contribution was made through this personal campaign page.{/ts}
{ts}Soft Credit To{/ts}{$softCreditToName}{$pcp_soft_credit_to_name}
{ts}In Public Honor Roll?{/ts}