3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Payment-Instrument.
21 class CRM_Contribute_Form_ContributionView
extends CRM_Core_Form
{
24 * Set variables up before form is built.
26 public function preProcess() {
27 $id = $this->get('id');
29 throw new CRM_Core_Exception('Contribution ID is required');
31 $params = ['id' => $id];
32 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
33 $this->assign('context', $context);
35 $values = CRM_Contribute_BAO_Contribution
::getValuesWithMappings($params);
37 $force_create_template = CRM_Utils_Request
::retrieve('force_create_template', 'Boolean', $this, FALSE, FALSE);
38 if ($force_create_template && !empty($values['contribution_recur_id']) && empty($values['is_template'])) {
39 // Create a template contribution.
40 $templateContributionId = CRM_Contribute_BAO_ContributionRecur
::ensureTemplateContributionExists($values['contribution_recur_id']);
41 if (!empty($templateContributionId)) {
42 $id = $templateContributionId;
43 $params = ['id' => $id];
44 $values = CRM_Contribute_BAO_Contribution
::getValuesWithMappings($params);
47 $this->assign('is_template', $values['is_template']);
49 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && $this->_action
& CRM_Core_Action
::VIEW
) {
50 $financialTypeID = CRM_Contribute_PseudoConstant
::financialType($values['financial_type_id']);
51 CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'view');
52 if (CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'edit', FALSE)) {
53 $this->assign('canEdit', TRUE);
55 if (CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'delete', FALSE)) {
56 $this->assign('canDelete', TRUE);
58 if (!CRM_Core_Permission
::check('view contributions of type ' . $financialTypeID)) {
59 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
62 elseif ($this->_action
& CRM_Core_Action
::VIEW
) {
63 $this->assign('noACL', TRUE);
65 CRM_Contribute_BAO_Contribution
::resolveDefaults($values);
67 if (!empty($values['contribution_page_id'])) {
68 $contribPages = CRM_Contribute_PseudoConstant
::contributionPage(NULL, TRUE);
69 $values['contribution_page_title'] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('contribution_page_id', $values), $contribPages);
72 // get received into i.e to_financial_account_id from last trxn
73 $financialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($values['contribution_id'], 'DESC');
74 $values['to_financial_account'] = '';
75 if (!empty($financialTrxnId['financialTrxnId'])) {
76 $values['to_financial_account_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
77 if ($values['to_financial_account_id']) {
78 $values['to_financial_account'] = CRM_Contribute_PseudoConstant
::financialAccount($values['to_financial_account_id']);
80 $values['payment_processor_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
81 if ($values['payment_processor_id']) {
82 $values['payment_processor_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
86 if (!empty($values['contribution_recur_id'])) {
87 $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
88 $params = [1 => [$values['contribution_recur_id'], 'Integer']];
89 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
91 $values['recur_installments'] = $dao->installments
;
92 $values['recur_frequency_unit'] = $dao->frequency_unit
;
93 $values['recur_frequency_interval'] = $dao->frequency_interval
;
97 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Contribution', NULL, $id, 0, $values['financial_type_id'] ??
NULL,
98 NULL, TRUE, NULL, FALSE, CRM_Core_Permission
::VIEW
);
99 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
102 $dao = new CRM_Contribute_DAO_ContributionProduct();
103 $dao->contribution_id
= $id;
104 if ($dao->find(TRUE)) {
105 $premiumId = $dao->id
;
106 $productID = $dao->product_id
;
110 $productDAO = new CRM_Contribute_DAO_Product();
111 $productDAO->id
= $productID;
112 $productDAO->find(TRUE);
114 $this->assign('premium', $productDAO->name
);
115 $this->assign('option', $dao->product_option
);
116 $this->assign('fulfilled', $dao->fulfilled_date
);
120 $noteValue = CRM_Core_BAO_Note
::getNote(CRM_Utils_Array
::value('id', $values), 'civicrm_contribution');
121 $values['note'] = array_values($noteValue);
123 // show billing address location details, if exists
124 if (!empty($values['address_id'])) {
125 $addressParams = ['id' => $values['address_id']];
126 $addressDetails = CRM_Core_BAO_Address
::getValues($addressParams, FALSE, 'id');
127 $addressDetails = array_values($addressDetails);
128 $values['billing_address'] = $addressDetails[0]['display'];
131 //assign soft credit record if exists.
132 $SCRecords = CRM_Contribute_BAO_ContributionSoft
::getSoftContribution($values['contribution_id'], TRUE);
133 if (!empty($SCRecords['soft_credit'])) {
134 $this->assign('softContributions', $SCRecords['soft_credit']);
135 unset($SCRecords['soft_credit']);
138 //assign pcp record if exists
139 foreach ($SCRecords as $name => $value) {
140 $this->assign($name, $value);
143 $lineItems = [CRM_Price_BAO_LineItem
::getLineItemsByContributionID(($id))];
144 $this->assign('lineItem', $lineItems);
145 $values['totalAmount'] = $values['total_amount'];
146 $this->assign('displayLineItemFinancialType', TRUE);
148 //do check for campaigns
149 if ($campaignId = CRM_Utils_Array
::value('campaign_id', $values)) {
150 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
151 $values['campaign'] = $campaigns[$campaignId];
153 if ($values['contribution_status'] == 'Refunded') {
154 $this->assign('refund_trxn_id', CRM_Core_BAO_FinancialTrxn
::getRefundTransactionTrxnID($id));
157 // assign values to the template
158 $this->assignVariables($values, array_keys($values));
159 $invoicing = CRM_Invoicing_Utils
::isInvoicingEnabled();
160 $this->assign('invoicing', $invoicing);
161 $this->assign('isDeferred', Civi
::settings()->get('deferred_revenue_enabled'));
162 if ($invoicing && isset($values['tax_amount'])) {
163 $this->assign('totalTaxAmount', $values['tax_amount']);
166 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
167 $displayName = CRM_Contact_BAO_Contact
::displayName($values['contact_id']);
168 $this->assign('displayName', $displayName);
169 // Check if this is default domain contact CRM-10482
170 if (CRM_Contact_BAO_Contact
::checkDomainContact($values['contact_id'])) {
171 $displayName .= ' (' . ts('default organization') . ')';
174 if (empty($values['is_template'])) {
175 $this->setTitle(ts('View Contribution from') . ' ' . $displayName);
178 $this->setTitle(ts('View Template Contribution from') . ' ' . $displayName);
181 // add viewed contribution to recent items list
182 $url = CRM_Utils_System
::url('civicrm/contact/view/contribution',
183 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
186 $title = $displayName . ' - (' . CRM_Utils_Money
::format($values['total_amount'], $values['currency']) . ' ' . ' - ' . $values['financial_type'] . ')';
189 if (CRM_Core_Permission
::checkActionPermission('CiviContribute', CRM_Core_Action
::UPDATE
)) {
190 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/view/contribution',
191 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
194 if (CRM_Core_Permission
::checkActionPermission('CiviContribute', CRM_Core_Action
::DELETE
)) {
195 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/contribution',
196 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
199 CRM_Utils_Recent
::add($title,
203 $values['contact_id'],
207 $statusOptionValueNames = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
208 $contributionStatus = $statusOptionValueNames[$values['contribution_status_id']];
209 if (in_array($contributionStatus, ['Partially paid', 'Pending refund'])
210 ||
($contributionStatus == 'Pending' && $values['is_pay_later'])
212 if ($contributionStatus == 'Pending refund') {
213 $this->assign('paymentButtonName', ts('Record Refund'));
216 $this->assign('paymentButtonName', ts('Record Payment'));
218 $this->assign('addRecordPayment', TRUE);
219 $this->assign('contactId', $values['contact_id']);
220 $this->assign('componentId', $id);
221 $this->assign('component', 'contribution');
223 $this->assignPaymentInfoBlock($id);
227 * Build the form object.
229 public function buildQuickForm() {
233 'name' => ts('Done'),
234 'spacing' => ' ',
241 * Assign the values to build the payment info block.
243 * @todo - this is a bit too much copy & paste from AbstractEditPayment
244 * (justifying on the basis it's 'pretty short' and in a different inheritance
245 * tree. I feel like traits are probably the longer term answer).
252 protected function assignPaymentInfoBlock($id) {
253 // component is used in getPaymentInfo primarily to retrieve the contribution id, we
254 // already have that.
255 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($id, 'contribution', TRUE);
256 $title = ts('View Payment');
257 $this->assign('transaction', TRUE);
258 $this->assign('payments', $paymentInfo['transaction']);
259 $this->assign('paymentLinks', $paymentInfo['payment_links']);