start modifying Contribution View to display multiple soft credits
[civicrm-core.git] / CRM / Contribute / Form / ContributionView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for Payment-Instrument
38 *
39 */
40class CRM_Contribute_Form_ContributionView extends CRM_Core_Form {
41
42 /**
43 * Function to set variables up before form is built
44 *
45 * @return void
46 * @access public
47 */
48 public function preProcess() {
49 $id = $this->get('id');
50 $values = $ids = array();
51 $params = array('id' => $id);
52 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
53 $this->assign('context', $context);
54
55 CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
56
57 $softParams = array('contribution_id' => CRM_Utils_Array::value('contribution_id', $values));
0a6ab5cb 58 $softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, TRUE);
485dfaad
JL
59// if ($softContribution) {
60// $values = array_merge($values, $softContribution);
61// }
6a488035
TO
62 CRM_Contribute_BAO_Contribution::resolveDefaults($values);
63
64 if (CRM_Utils_Array::value('contribution_page_id', $values)) {
65 $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
66 $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
67 }
68
69 // get recieved into i.e to_financial_account_id from last trxn
70 $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
71 $values['to_financial_account'] = '';
72 if (CRM_Utils_Array::value('financialTrxnId', $financialTrxnId)) {
73 $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
74 if ($values['to_financial_account_id']) {
75 $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']);
76 }
77 }
78
79 if (CRM_Utils_Array::value('honor_contact_id', $values)) {
80 $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1";
81 $params = array(1 => array($values['honor_contact_id'], 'Integer'));
82 $dao = CRM_Core_DAO::executeQuery($sql, $params);
83 if ($dao->fetch()) {
84 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$values[honor_contact_id]");
85 $values['honor_display'] = "<A href = $url>" . $dao->display_name . "</A>";
86 }
87 $honor = CRM_Core_PseudoConstant::honor();
88 $values['honor_type'] = CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $values), $honor);
89 }
90
91 if (CRM_Utils_Array::value('contribution_recur_id', $values)) {
92 $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
93 $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
94 $dao = CRM_Core_DAO::executeQuery($sql, $params);
95 if ($dao->fetch()) {
96 $values['recur_installments'] = $dao->installments;
97 $values['recur_frequency_unit'] = $dao->frequency_unit;
98 $values['recur_frequency_interval'] = $dao->frequency_interval;
99 }
100 }
101
102 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
103 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
104
105 $premiumId = NULL;
106 if ($id) {
107 $dao = new CRM_Contribute_DAO_ContributionProduct();
108 $dao->contribution_id = $id;
109 if ($dao->find(TRUE)) {
110 $premiumId = $dao->id;
111 $productID = $dao->product_id;
112 }
113 }
114
115 if ($premiumId) {
116 $productDAO = new CRM_Contribute_DAO_Product();
117 $productDAO->id = $productID;
118 $productDAO->find(TRUE);
119
120 $this->assign('premium', $productDAO->name);
121 $this->assign('option', $dao->product_option);
122 $this->assign('fulfilled', $dao->fulfilled_date);
123 }
124
125 // Get Note
126 $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution');
127 $values['note'] = array_values($noteValue);
128
129 // show billing address location details, if exists
130 if (CRM_Utils_Array::value('address_id', $values)) {
131 $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
132 $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
133 $addressDetails = array_values($addressDetails);
134 $values['billing_address'] = $addressDetails[0]['display'];
135 }
136
137 //get soft credit record if exists.
485dfaad 138 //FIXME: The next line seems really inefficient. Can't we just check the length of the array?
6a488035
TO
139 if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
140
141 $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
142 $softContribution['soft_credit_to'], 'display_name'
143 );
144 //hack to avoid dispalyName conflict
145 //for viewing softcredit record.
146 $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
147 $values['contact_id'], 'display_name'
148 );
149 $values = array_merge($values, $softContribution);
150 }
151
152 $lineItems = array();
153 if ($id) {
154 $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1);
155 empty($lineItem) ? null :$lineItems[] = $lineItem;
156 }
157 $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
158 $values['totalAmount'] = $values['total_amount'];
159
160 //do check for campaigns
161 if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
162 $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
163 $values['campaign'] = $campaigns[$campaignId];
164 }
165
166 // assign values to the template
167 $this->assign($values);
168
169 $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
170 $this->assign('displayName', $displayName);
171
172 // Check if this is default domain contact CRM-10482
173 if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
174 $displayName .= ' (' . ts('default organization') . ')';
175 }
176
177 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
178 CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName);
179
180 // add viewed contribution to recent items list
181 $url = CRM_Utils_System::url('civicrm/contact/view/contribution',
182 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
183 );
184
185 $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')';
186
187 $recentOther = array();
188 if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
189 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution',
190 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
191 );
192 }
193 if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
194 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution',
195 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
196 );
197 }
198 CRM_Utils_Recent::add($title,
199 $url,
200 $values['id'],
201 'Contribution',
202 $values['contact_id'],
203 NULL,
204 $recentOther
205 );
206 }
207
208 /**
209 * Function to build the form
210 *
211 * @return None
212 * @access public
213 */
214 public function buildQuickForm() {
215
216 $this->addButtons(array(
217 array(
218 'type' => 'cancel',
219 'name' => ts('Done'),
220 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
221 'isDefault' => TRUE,
222 ),
223 )
224 );
225 }
226}
227