Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
95cdcc0f | 35 | * This class generates form components for Payment-Instrument. |
6a488035 TO |
36 | */ |
37 | class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Set variables up before form is built. |
6a488035 TO |
41 | */ |
42 | public function preProcess() { | |
353ffa53 TO |
43 | $id = $this->get('id'); |
44 | $values = $ids = array(); | |
45 | $params = array('id' => $id); | |
6a488035 TO |
46 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
47 | $this->assign('context', $context); | |
48 | ||
49 | CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); | |
66af7c48 | 50 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) { |
c0f5a838 | 51 | $financialTypeID = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']); |
59ccc8cd E |
52 | CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'view'); |
53 | if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'edit', FALSE)) { | |
54 | $this->assign('canEdit', TRUE); | |
55 | } | |
56 | if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'delete', FALSE)) { | |
57 | $this->assign('canDelete', TRUE); | |
58 | } | |
c0f5a838 E |
59 | if (!CRM_Core_Permission::check('view contributions of type ' . $financialTypeID)) { |
60 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); | |
61 | } | |
62 | } | |
895d596d E |
63 | elseif ($this->_action & CRM_Core_Action::VIEW) { |
64 | $this->assign('noACL', TRUE); | |
65 | } | |
6a488035 | 66 | CRM_Contribute_BAO_Contribution::resolveDefaults($values); |
914c8124 | 67 | $cancelledStatus = TRUE; |
d230e755 | 68 | $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); |
914c8124 PB |
69 | if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) { |
70 | $cancelledStatus = FALSE; | |
71 | } | |
d230e755 | 72 | $this->assign('cancelledStatus', $cancelledStatus); |
6a488035 | 73 | |
a7488080 | 74 | if (!empty($values['contribution_page_id'])) { |
6a488035 TO |
75 | $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE); |
76 | $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages); | |
77 | } | |
78 | ||
b44e3f84 | 79 | // get received into i.e to_financial_account_id from last trxn |
6a488035 TO |
80 | $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC'); |
81 | $values['to_financial_account'] = ''; | |
a7488080 | 82 | if (!empty($financialTrxnId['financialTrxnId'])) { |
eea16664 | 83 | $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id'); |
6a488035 | 84 | if ($values['to_financial_account_id']) { |
eea16664 | 85 | $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']); |
6a488035 | 86 | } |
2cc6b631 DG |
87 | $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id'); |
88 | if ($values['payment_processor_id']) { | |
89 | $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name'); | |
90 | } | |
6a488035 | 91 | } |
eea16664 | 92 | |
a7488080 | 93 | if (!empty($values['contribution_recur_id'])) { |
353ffa53 | 94 | $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; |
6a488035 | 95 | $params = array(1 => array($values['contribution_recur_id'], 'Integer')); |
353ffa53 | 96 | $dao = CRM_Core_DAO::executeQuery($sql, $params); |
6a488035 TO |
97 | if ($dao->fetch()) { |
98 | $values['recur_installments'] = $dao->installments; | |
99 | $values['recur_frequency_unit'] = $dao->frequency_unit; | |
100 | $values['recur_frequency_interval'] = $dao->frequency_interval; | |
101 | } | |
102 | } | |
103 | ||
104 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values)); | |
105 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); | |
106 | ||
107 | $premiumId = NULL; | |
108 | if ($id) { | |
109 | $dao = new CRM_Contribute_DAO_ContributionProduct(); | |
110 | $dao->contribution_id = $id; | |
111 | if ($dao->find(TRUE)) { | |
112 | $premiumId = $dao->id; | |
113 | $productID = $dao->product_id; | |
114 | } | |
115 | } | |
116 | ||
117 | if ($premiumId) { | |
118 | $productDAO = new CRM_Contribute_DAO_Product(); | |
119 | $productDAO->id = $productID; | |
120 | $productDAO->find(TRUE); | |
121 | ||
122 | $this->assign('premium', $productDAO->name); | |
123 | $this->assign('option', $dao->product_option); | |
124 | $this->assign('fulfilled', $dao->fulfilled_date); | |
125 | } | |
126 | ||
127 | // Get Note | |
128 | $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution'); | |
129 | $values['note'] = array_values($noteValue); | |
130 | ||
131 | // show billing address location details, if exists | |
a7488080 | 132 | if (!empty($values['address_id'])) { |
6a488035 TO |
133 | $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); |
134 | $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); | |
135 | $addressDetails = array_values($addressDetails); | |
136 | $values['billing_address'] = $addressDetails[0]['display']; | |
137 | } | |
138 | ||
b6545333 | 139 | //assign soft credit record if exists. |
140 | $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); | |
00a1afe2 | 141 | if (!empty($SCRecords['soft_credit'])) { |
142 | $this->assign('softContributions', $SCRecords['soft_credit']); | |
143 | unset($SCRecords['soft_credit']); | |
144 | } | |
b6545333 | 145 | |
146 | //assign pcp record if exists | |
147 | foreach ($SCRecords as $name => $value) { | |
148 | $this->assign($name, $value); | |
149 | } | |
6a488035 TO |
150 | |
151 | $lineItems = array(); | |
152 | if ($id) { | |
0d6f29cd | 153 | $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE); |
154 | if (!empty($lineItem)) { | |
155 | $lineItems[] = $lineItem; | |
156 | } | |
157 | ||
6a488035 TO |
158 | } |
159 | $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems); | |
160 | $values['totalAmount'] = $values['total_amount']; | |
161 | ||
162 | //do check for campaigns | |
163 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { | |
164 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
165 | $values['campaign'] = $campaigns[$campaignId]; | |
166 | } | |
167 | ||
168 | // assign values to the template | |
169 | $this->assign($values); | |
874c9be7 | 170 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
03b412ae PB |
171 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); |
172 | $this->assign('invoicing', $invoicing); | |
173 | if ($invoicing && isset($values['tax_amount'])) { | |
a32709be PB |
174 | $this->assign('totalTaxAmount', $values['tax_amount']); |
175 | } | |
6a488035 TO |
176 | |
177 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
178 | $this->assign('displayName', $displayName); | |
eea16664 | 179 | |
6a488035 TO |
180 | // Check if this is default domain contact CRM-10482 |
181 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
182 | $displayName .= ' (' . ts('default organization') . ')'; | |
183 | } | |
184 | ||
185 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
86bfa4f6 | 186 | CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName); |
6a488035 TO |
187 | |
188 | // add viewed contribution to recent items list | |
189 | $url = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
190 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
191 | ); | |
192 | ||
193 | $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')'; | |
194 | ||
195 | $recentOther = array(); | |
196 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { | |
197 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
198 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
199 | ); | |
200 | } | |
201 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { | |
202 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
203 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
204 | ); | |
205 | } | |
206 | CRM_Utils_Recent::add($title, | |
207 | $url, | |
208 | $values['id'], | |
209 | 'Contribution', | |
210 | $values['contact_id'], | |
211 | NULL, | |
212 | $recentOther | |
213 | ); | |
214 | } | |
215 | ||
216 | /** | |
fe482240 | 217 | * Build the form object. |
6a488035 TO |
218 | */ |
219 | public function buildQuickForm() { | |
220 | ||
221 | $this->addButtons(array( | |
222 | array( | |
223 | 'type' => 'cancel', | |
224 | 'name' => ts('Done'), | |
225 | 'spacing' => ' ', | |
226 | 'isDefault' => TRUE, | |
227 | ), | |
228 | ) | |
229 | ); | |
230 | } | |
96025800 | 231 | |
6a488035 | 232 | } |