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); | |
6a488035 | 50 | CRM_Contribute_BAO_Contribution::resolveDefaults($values); |
914c8124 | 51 | $cancelledStatus = TRUE; |
d230e755 | 52 | $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); |
914c8124 PB |
53 | if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) { |
54 | $cancelledStatus = FALSE; | |
55 | } | |
d230e755 | 56 | $this->assign('cancelledStatus', $cancelledStatus); |
6a488035 | 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 | ||
b44e3f84 | 63 | // get received into i.e to_financial_account_id from last trxn |
6a488035 TO |
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 | 70 | } |
2cc6b631 DG |
71 | $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id'); |
72 | if ($values['payment_processor_id']) { | |
73 | $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name'); | |
74 | } | |
6a488035 | 75 | } |
eea16664 | 76 | |
a7488080 | 77 | if (!empty($values['contribution_recur_id'])) { |
353ffa53 | 78 | $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; |
6a488035 | 79 | $params = array(1 => array($values['contribution_recur_id'], 'Integer')); |
353ffa53 | 80 | $dao = CRM_Core_DAO::executeQuery($sql, $params); |
6a488035 TO |
81 | if ($dao->fetch()) { |
82 | $values['recur_installments'] = $dao->installments; | |
83 | $values['recur_frequency_unit'] = $dao->frequency_unit; | |
84 | $values['recur_frequency_interval'] = $dao->frequency_interval; | |
85 | } | |
86 | } | |
87 | ||
88 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values)); | |
89 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); | |
90 | ||
91 | $premiumId = NULL; | |
92 | if ($id) { | |
93 | $dao = new CRM_Contribute_DAO_ContributionProduct(); | |
94 | $dao->contribution_id = $id; | |
95 | if ($dao->find(TRUE)) { | |
96 | $premiumId = $dao->id; | |
97 | $productID = $dao->product_id; | |
98 | } | |
99 | } | |
100 | ||
101 | if ($premiumId) { | |
102 | $productDAO = new CRM_Contribute_DAO_Product(); | |
103 | $productDAO->id = $productID; | |
104 | $productDAO->find(TRUE); | |
105 | ||
106 | $this->assign('premium', $productDAO->name); | |
107 | $this->assign('option', $dao->product_option); | |
108 | $this->assign('fulfilled', $dao->fulfilled_date); | |
109 | } | |
110 | ||
111 | // Get Note | |
112 | $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution'); | |
113 | $values['note'] = array_values($noteValue); | |
114 | ||
115 | // show billing address location details, if exists | |
a7488080 | 116 | if (!empty($values['address_id'])) { |
6a488035 TO |
117 | $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); |
118 | $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); | |
119 | $addressDetails = array_values($addressDetails); | |
120 | $values['billing_address'] = $addressDetails[0]['display']; | |
121 | } | |
122 | ||
b6545333 | 123 | //assign soft credit record if exists. |
124 | $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); | |
00a1afe2 | 125 | if (!empty($SCRecords['soft_credit'])) { |
126 | $this->assign('softContributions', $SCRecords['soft_credit']); | |
127 | unset($SCRecords['soft_credit']); | |
128 | } | |
b6545333 | 129 | |
130 | //assign pcp record if exists | |
131 | foreach ($SCRecords as $name => $value) { | |
132 | $this->assign($name, $value); | |
133 | } | |
6a488035 TO |
134 | |
135 | $lineItems = array(); | |
136 | if ($id) { | |
0d6f29cd | 137 | $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE); |
138 | if (!empty($lineItem)) { | |
139 | $lineItems[] = $lineItem; | |
140 | } | |
141 | ||
6a488035 TO |
142 | } |
143 | $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems); | |
144 | $values['totalAmount'] = $values['total_amount']; | |
145 | ||
146 | //do check for campaigns | |
147 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { | |
148 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
149 | $values['campaign'] = $campaigns[$campaignId]; | |
150 | } | |
151 | ||
152 | // assign values to the template | |
153 | $this->assign($values); | |
874c9be7 | 154 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
03b412ae PB |
155 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); |
156 | $this->assign('invoicing', $invoicing); | |
157 | if ($invoicing && isset($values['tax_amount'])) { | |
a32709be PB |
158 | $this->assign('totalTaxAmount', $values['tax_amount']); |
159 | } | |
6a488035 TO |
160 | |
161 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
162 | $this->assign('displayName', $displayName); | |
eea16664 | 163 | |
6a488035 TO |
164 | // Check if this is default domain contact CRM-10482 |
165 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
166 | $displayName .= ' (' . ts('default organization') . ')'; | |
167 | } | |
168 | ||
169 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
86bfa4f6 | 170 | CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName); |
6a488035 TO |
171 | |
172 | // add viewed contribution to recent items list | |
173 | $url = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
174 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
175 | ); | |
176 | ||
177 | $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')'; | |
178 | ||
179 | $recentOther = array(); | |
180 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { | |
181 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
182 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
183 | ); | |
184 | } | |
185 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { | |
186 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
187 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
188 | ); | |
189 | } | |
190 | CRM_Utils_Recent::add($title, | |
191 | $url, | |
192 | $values['id'], | |
193 | 'Contribution', | |
194 | $values['contact_id'], | |
195 | NULL, | |
196 | $recentOther | |
197 | ); | |
198 | } | |
199 | ||
200 | /** | |
fe482240 | 201 | * Build the form object. |
6a488035 TO |
202 | */ |
203 | public function buildQuickForm() { | |
204 | ||
205 | $this->addButtons(array( | |
206 | array( | |
207 | 'type' => 'cancel', | |
208 | 'name' => ts('Done'), | |
209 | 'spacing' => ' ', | |
210 | 'isDefault' => TRUE, | |
211 | ), | |
212 | ) | |
213 | ); | |
214 | } | |
96025800 | 215 | |
6a488035 | 216 | } |