Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Payment-Instrument | |
38 | * | |
39 | */ | |
40 | class 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); | |
6a488035 TO |
56 | CRM_Contribute_BAO_Contribution::resolveDefaults($values); |
57 | ||
a7488080 | 58 | if (!empty($values['contribution_page_id'])) { |
6a488035 TO |
59 | $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE); |
60 | $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages); | |
61 | } | |
62 | ||
63 | // get recieved into i.e to_financial_account_id from last trxn | |
64 | $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC'); | |
65 | $values['to_financial_account'] = ''; | |
a7488080 | 66 | if (!empty($financialTrxnId['financialTrxnId'])) { |
eea16664 | 67 | $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id'); |
6a488035 | 68 | if ($values['to_financial_account_id']) { |
eea16664 | 69 | $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']); |
6a488035 TO |
70 | } |
71 | } | |
eea16664 | 72 | |
a7488080 | 73 | if (!empty($values['contribution_recur_id'])) { |
6a488035 TO |
74 | $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; |
75 | $params = array(1 => array($values['contribution_recur_id'], 'Integer')); | |
76 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
77 | if ($dao->fetch()) { | |
78 | $values['recur_installments'] = $dao->installments; | |
79 | $values['recur_frequency_unit'] = $dao->frequency_unit; | |
80 | $values['recur_frequency_interval'] = $dao->frequency_interval; | |
81 | } | |
82 | } | |
83 | ||
84 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values)); | |
85 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); | |
86 | ||
87 | $premiumId = NULL; | |
88 | if ($id) { | |
89 | $dao = new CRM_Contribute_DAO_ContributionProduct(); | |
90 | $dao->contribution_id = $id; | |
91 | if ($dao->find(TRUE)) { | |
92 | $premiumId = $dao->id; | |
93 | $productID = $dao->product_id; | |
94 | } | |
95 | } | |
96 | ||
97 | if ($premiumId) { | |
98 | $productDAO = new CRM_Contribute_DAO_Product(); | |
99 | $productDAO->id = $productID; | |
100 | $productDAO->find(TRUE); | |
101 | ||
102 | $this->assign('premium', $productDAO->name); | |
103 | $this->assign('option', $dao->product_option); | |
104 | $this->assign('fulfilled', $dao->fulfilled_date); | |
105 | } | |
106 | ||
107 | // Get Note | |
108 | $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution'); | |
109 | $values['note'] = array_values($noteValue); | |
110 | ||
111 | // show billing address location details, if exists | |
a7488080 | 112 | if (!empty($values['address_id'])) { |
6a488035 TO |
113 | $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); |
114 | $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); | |
115 | $addressDetails = array_values($addressDetails); | |
116 | $values['billing_address'] = $addressDetails[0]['display']; | |
117 | } | |
118 | ||
b6545333 | 119 | //assign soft credit record if exists. |
120 | $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); | |
00a1afe2 | 121 | if (!empty($SCRecords['soft_credit'])) { |
122 | $this->assign('softContributions', $SCRecords['soft_credit']); | |
123 | unset($SCRecords['soft_credit']); | |
124 | } | |
b6545333 | 125 | |
126 | //assign pcp record if exists | |
127 | foreach ($SCRecords as $name => $value) { | |
128 | $this->assign($name, $value); | |
129 | } | |
6a488035 TO |
130 | |
131 | $lineItems = array(); | |
132 | if ($id) { | |
133 | $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1); | |
134 | empty($lineItem) ? null :$lineItems[] = $lineItem; | |
135 | } | |
136 | $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems); | |
137 | $values['totalAmount'] = $values['total_amount']; | |
138 | ||
139 | //do check for campaigns | |
140 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { | |
141 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
142 | $values['campaign'] = $campaigns[$campaignId]; | |
143 | } | |
144 | ||
145 | // assign values to the template | |
146 | $this->assign($values); | |
147 | ||
148 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
149 | $this->assign('displayName', $displayName); | |
eea16664 | 150 | |
6a488035 TO |
151 | // Check if this is default domain contact CRM-10482 |
152 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
153 | $displayName .= ' (' . ts('default organization') . ')'; | |
154 | } | |
155 | ||
156 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
157 | CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName); | |
158 | ||
159 | // add viewed contribution to recent items list | |
160 | $url = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
161 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
162 | ); | |
163 | ||
164 | $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')'; | |
165 | ||
166 | $recentOther = array(); | |
167 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { | |
168 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
169 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
170 | ); | |
171 | } | |
172 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { | |
173 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
174 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
175 | ); | |
176 | } | |
177 | CRM_Utils_Recent::add($title, | |
178 | $url, | |
179 | $values['id'], | |
180 | 'Contribution', | |
181 | $values['contact_id'], | |
182 | NULL, | |
183 | $recentOther | |
184 | ); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Function to build the form | |
189 | * | |
355ba699 | 190 | * @return void |
6a488035 TO |
191 | * @access public |
192 | */ | |
193 | public function buildQuickForm() { | |
194 | ||
195 | $this->addButtons(array( | |
196 | array( | |
197 | 'type' => 'cancel', | |
198 | 'name' => ts('Done'), | |
199 | 'spacing' => ' ', | |
200 | 'isDefault' => TRUE, | |
201 | ), | |
202 | ) | |
203 | ); | |
204 | } | |
205 | } | |
206 |