Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
95cdcc0f | 19 | * This class generates form components for Payment-Instrument. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Set variables up before form is built. |
6a488035 TO |
25 | */ |
26 | public function preProcess() { | |
353ffa53 | 27 | $id = $this->get('id'); |
be2fb01f | 28 | $params = ['id' => $id]; |
edc80cda | 29 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 TO |
30 | $this->assign('context', $context); |
31 | ||
99cdd94d | 32 | $values = CRM_Contribute_BAO_Contribution::getValuesWithMappings($params); |
33 | ||
66af7c48 | 34 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) { |
c0f5a838 | 35 | $financialTypeID = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']); |
59ccc8cd E |
36 | CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'view'); |
37 | if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'edit', FALSE)) { | |
38 | $this->assign('canEdit', TRUE); | |
39 | } | |
40 | if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'delete', FALSE)) { | |
41 | $this->assign('canDelete', TRUE); | |
42 | } | |
c0f5a838 | 43 | if (!CRM_Core_Permission::check('view contributions of type ' . $financialTypeID)) { |
e22ec653 | 44 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
c0f5a838 E |
45 | } |
46 | } | |
895d596d E |
47 | elseif ($this->_action & CRM_Core_Action::VIEW) { |
48 | $this->assign('noACL', TRUE); | |
49 | } | |
6a488035 TO |
50 | CRM_Contribute_BAO_Contribution::resolveDefaults($values); |
51 | ||
a7488080 | 52 | if (!empty($values['contribution_page_id'])) { |
6a488035 TO |
53 | $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE); |
54 | $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages); | |
55 | } | |
56 | ||
b44e3f84 | 57 | // get received into i.e to_financial_account_id from last trxn |
6a488035 TO |
58 | $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC'); |
59 | $values['to_financial_account'] = ''; | |
a7488080 | 60 | if (!empty($financialTrxnId['financialTrxnId'])) { |
eea16664 | 61 | $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id'); |
6a488035 | 62 | if ($values['to_financial_account_id']) { |
eea16664 | 63 | $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']); |
6a488035 | 64 | } |
2cc6b631 DG |
65 | $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id'); |
66 | if ($values['payment_processor_id']) { | |
67 | $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name'); | |
68 | } | |
6a488035 | 69 | } |
eea16664 | 70 | |
a7488080 | 71 | if (!empty($values['contribution_recur_id'])) { |
353ffa53 | 72 | $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; |
be2fb01f | 73 | $params = [1 => [$values['contribution_recur_id'], 'Integer']]; |
353ffa53 | 74 | $dao = CRM_Core_DAO::executeQuery($sql, $params); |
6a488035 TO |
75 | if ($dao->fetch()) { |
76 | $values['recur_installments'] = $dao->installments; | |
77 | $values['recur_frequency_unit'] = $dao->frequency_unit; | |
78 | $values['recur_frequency_interval'] = $dao->frequency_interval; | |
79 | } | |
80 | } | |
81 | ||
0b330e6d | 82 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', NULL, $id, 0, CRM_Utils_Array::value('financial_type_id', $values)); |
e34e6979 | 83 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id); |
6a488035 TO |
84 | |
85 | $premiumId = NULL; | |
86 | if ($id) { | |
87 | $dao = new CRM_Contribute_DAO_ContributionProduct(); | |
88 | $dao->contribution_id = $id; | |
89 | if ($dao->find(TRUE)) { | |
90 | $premiumId = $dao->id; | |
91 | $productID = $dao->product_id; | |
92 | } | |
93 | } | |
94 | ||
95 | if ($premiumId) { | |
96 | $productDAO = new CRM_Contribute_DAO_Product(); | |
97 | $productDAO->id = $productID; | |
98 | $productDAO->find(TRUE); | |
99 | ||
100 | $this->assign('premium', $productDAO->name); | |
101 | $this->assign('option', $dao->product_option); | |
102 | $this->assign('fulfilled', $dao->fulfilled_date); | |
103 | } | |
104 | ||
105 | // Get Note | |
106 | $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution'); | |
107 | $values['note'] = array_values($noteValue); | |
108 | ||
109 | // show billing address location details, if exists | |
a7488080 | 110 | if (!empty($values['address_id'])) { |
2cfe2cf4 | 111 | $addressParams = ['id' => $values['address_id']]; |
6a488035 TO |
112 | $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); |
113 | $addressDetails = array_values($addressDetails); | |
114 | $values['billing_address'] = $addressDetails[0]['display']; | |
115 | } | |
116 | ||
b6545333 | 117 | //assign soft credit record if exists. |
118 | $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE); | |
00a1afe2 | 119 | if (!empty($SCRecords['soft_credit'])) { |
120 | $this->assign('softContributions', $SCRecords['soft_credit']); | |
121 | unset($SCRecords['soft_credit']); | |
122 | } | |
b6545333 | 123 | |
124 | //assign pcp record if exists | |
125 | foreach ($SCRecords as $name => $value) { | |
126 | $this->assign($name, $value); | |
127 | } | |
6a488035 | 128 | |
be2fb01f | 129 | $lineItems = []; |
28b46c26 | 130 | $displayLineItems = FALSE; |
6a488035 | 131 | if ($id) { |
be2fb01f | 132 | $lineItems = [CRM_Price_BAO_LineItem::getLineItemsByContributionID(($id))]; |
28b46c26 | 133 | $firstLineItem = reset($lineItems[0]); |
32b709b4 AH |
134 | if (empty($firstLineItem['price_set_id'])) { |
135 | // CRM-20297 All we care is that it's not QuickConfig, so no price set | |
136 | // is no problem. | |
137 | $displayLineItems = TRUE; | |
138 | } | |
139 | else { | |
140 | try { | |
be2fb01f | 141 | $priceSet = civicrm_api3('PriceSet', 'getsingle', [ |
32b709b4 AH |
142 | 'id' => $firstLineItem['price_set_id'], |
143 | 'return' => 'is_quick_config, id', | |
be2fb01f | 144 | ]); |
32b709b4 AH |
145 | $displayLineItems = !$priceSet['is_quick_config']; |
146 | } | |
147 | catch (CiviCRM_API3_Exception $e) { | |
148 | throw new CRM_Core_Exception('Cannot find price set by ID'); | |
149 | } | |
150 | } | |
6a488035 | 151 | } |
28b46c26 | 152 | $this->assign('lineItem', $lineItems); |
153 | $this->assign('displayLineItems', $displayLineItems); | |
6a488035 | 154 | $values['totalAmount'] = $values['total_amount']; |
64525dae | 155 | $this->assign('displayLineItemFinancialType', TRUE); |
6a488035 TO |
156 | |
157 | //do check for campaigns | |
158 | if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { | |
159 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); | |
160 | $values['campaign'] = $campaigns[$campaignId]; | |
161 | } | |
99cdd94d | 162 | if ($values['contribution_status'] == 'Refunded') { |
15ce8a6b | 163 | $this->assign('refund_trxn_id', CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($id)); |
99cdd94d | 164 | } |
6a488035 TO |
165 | |
166 | // assign values to the template | |
167 | $this->assign($values); | |
d0df87f2 | 168 | $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled(); |
03b412ae | 169 | $this->assign('invoicing', $invoicing); |
fc7106d2 | 170 | $this->assign('isDeferred', Civi::settings()->get('deferred_revenue_enabled')); |
03b412ae | 171 | if ($invoicing && isset($values['tax_amount'])) { |
a32709be PB |
172 | $this->assign('totalTaxAmount', $values['tax_amount']); |
173 | } | |
6a488035 TO |
174 | |
175 | $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); | |
176 | $this->assign('displayName', $displayName); | |
eea16664 | 177 | |
6a488035 TO |
178 | // Check if this is default domain contact CRM-10482 |
179 | if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) { | |
180 | $displayName .= ' (' . ts('default organization') . ')'; | |
181 | } | |
182 | ||
183 | // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container | |
86bfa4f6 | 184 | CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName); |
6a488035 TO |
185 | |
186 | // add viewed contribution to recent items list | |
187 | $url = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
188 | "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
189 | ); | |
190 | ||
230ea74e | 191 | $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount'], $values['currency']) . ' ' . ' - ' . $values['financial_type'] . ')'; |
6a488035 | 192 | |
be2fb01f | 193 | $recentOther = []; |
6a488035 TO |
194 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { |
195 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
196 | "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
197 | ); | |
198 | } | |
199 | if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { | |
200 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', | |
201 | "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home" | |
202 | ); | |
203 | } | |
204 | CRM_Utils_Recent::add($title, | |
205 | $url, | |
206 | $values['id'], | |
207 | 'Contribution', | |
208 | $values['contact_id'], | |
209 | NULL, | |
210 | $recentOther | |
211 | ); | |
231d9162 | 212 | $statusOptionValueNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); |
213 | $contributionStatus = $statusOptionValueNames[$values['contribution_status_id']]; | |
be2fb01f | 214 | if (in_array($contributionStatus, ['Partially paid', 'Pending refund']) |
685dc433 PN |
215 | || ($contributionStatus == 'Pending' && $values['is_pay_later']) |
216 | ) { | |
217 | if ($contributionStatus == 'Pending refund') { | |
218 | $this->assign('paymentButtonName', ts('Record Refund')); | |
219 | } | |
220 | else { | |
221 | $this->assign('paymentButtonName', ts('Record Payment')); | |
222 | } | |
223 | $this->assign('addRecordPayment', TRUE); | |
224 | $this->assign('contactId', $values['contact_id']); | |
225 | $this->assign('componentId', $id); | |
226 | $this->assign('component', 'contribution'); | |
227 | } | |
02fc97b3 | 228 | $this->assignPaymentInfoBlock($id); |
6a488035 TO |
229 | } |
230 | ||
231 | /** | |
fe482240 | 232 | * Build the form object. |
6a488035 TO |
233 | */ |
234 | public function buildQuickForm() { | |
be2fb01f CW |
235 | $this->addButtons([ |
236 | [ | |
c6554998 AH |
237 | 'type' => 'cancel', |
238 | 'name' => ts('Done'), | |
239 | 'spacing' => ' ', | |
240 | 'isDefault' => TRUE, | |
be2fb01f CW |
241 | ], |
242 | ]); | |
6a488035 | 243 | } |
96025800 | 244 | |
02fc97b3 | 245 | /** |
246 | * Assign the values to build the payment info block. | |
247 | * | |
248 | * @todo - this is a bit too much copy & paste from AbstractEditPayment | |
249 | * (justifying on the basis it's 'pretty short' and in a different inheritance | |
250 | * tree. I feel like traits are probably the longer term answer). | |
251 | * | |
252 | * @param int $id | |
253 | * | |
1330f57a | 254 | * @return string |
02fc97b3 | 255 | * Block title. |
256 | */ | |
257 | protected function assignPaymentInfoBlock($id) { | |
258 | // component is used in getPaymentInfo primarily to retrieve the contribution id, we | |
259 | // already have that. | |
260 | $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($id, 'contribution', TRUE); | |
261 | $title = ts('View Payment'); | |
262 | $this->assign('transaction', TRUE); | |
263 | $this->assign('payments', $paymentInfo['transaction']); | |
264 | $this->assign('paymentLinks', $paymentInfo['payment_links']); | |
265 | return $title; | |
266 | } | |
267 | ||
6a488035 | 268 | } |