3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class generates form components for Payment-Instrument.
37 class CRM_Contribute_Form_ContributionView
extends CRM_Core_Form
{
40 * Set variables up before form is built.
42 public function preProcess() {
43 $id = $this->get('id');
44 $params = array('id' => $id);
45 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
46 $this->assign('context', $context);
48 $values = CRM_Contribute_BAO_Contribution
::getValuesWithMappings($params);
50 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && $this->_action
& CRM_Core_Action
::VIEW
) {
51 $financialTypeID = CRM_Contribute_PseudoConstant
::financialType($values['financial_type_id']);
52 CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'view');
53 if (CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'edit', FALSE)) {
54 $this->assign('canEdit', TRUE);
56 if (CRM_Financial_BAO_FinancialType
::checkPermissionedLineItems($id, 'delete', FALSE)) {
57 $this->assign('canDelete', TRUE);
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.'));
63 elseif ($this->_action
& CRM_Core_Action
::VIEW
) {
64 $this->assign('noACL', TRUE);
66 CRM_Contribute_BAO_Contribution
::resolveDefaults($values);
67 // @todo - I believe this cancelledStatus is unused - if someone reaches the same conclusion
68 // by grepping then the next few lines can go.
69 $cancelledStatus = TRUE;
70 $status = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
71 if (CRM_Utils_Array
::value('contribution_status_id', $values) == array_search('Cancelled', $status)) {
72 $cancelledStatus = FALSE;
74 $this->assign('cancelledStatus', $cancelledStatus);
76 if (!empty($values['contribution_page_id'])) {
77 $contribPages = CRM_Contribute_PseudoConstant
::contributionPage(NULL, TRUE);
78 $values['contribution_page_title'] = CRM_Utils_Array
::value(CRM_Utils_Array
::value('contribution_page_id', $values), $contribPages);
81 // get received into i.e to_financial_account_id from last trxn
82 $financialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($values['contribution_id'], 'DESC');
83 $values['to_financial_account'] = '';
84 if (!empty($financialTrxnId['financialTrxnId'])) {
85 $values['to_financial_account_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
86 if ($values['to_financial_account_id']) {
87 $values['to_financial_account'] = CRM_Contribute_PseudoConstant
::financialAccount($values['to_financial_account_id']);
89 $values['payment_processor_id'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
90 if ($values['payment_processor_id']) {
91 $values['payment_processor_name'] = CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
95 if (!empty($values['contribution_recur_id'])) {
96 $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
97 $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
98 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
100 $values['recur_installments'] = $dao->installments
;
101 $values['recur_frequency_unit'] = $dao->frequency_unit
;
102 $values['recur_frequency_interval'] = $dao->frequency_interval
;
106 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Contribution', $this, $id, 0, CRM_Utils_Array
::value('financial_type_id', $values));
107 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
111 $dao = new CRM_Contribute_DAO_ContributionProduct();
112 $dao->contribution_id
= $id;
113 if ($dao->find(TRUE)) {
114 $premiumId = $dao->id
;
115 $productID = $dao->product_id
;
120 $productDAO = new CRM_Contribute_DAO_Product();
121 $productDAO->id
= $productID;
122 $productDAO->find(TRUE);
124 $this->assign('premium', $productDAO->name
);
125 $this->assign('option', $dao->product_option
);
126 $this->assign('fulfilled', $dao->fulfilled_date
);
130 $noteValue = CRM_Core_BAO_Note
::getNote(CRM_Utils_Array
::value('id', $values), 'civicrm_contribution');
131 $values['note'] = array_values($noteValue);
133 // show billing address location details, if exists
134 if (!empty($values['address_id'])) {
135 $addressParams = array('id' => CRM_Utils_Array
::value('address_id', $values));
136 $addressDetails = CRM_Core_BAO_Address
::getValues($addressParams, FALSE, 'id');
137 $addressDetails = array_values($addressDetails);
138 $values['billing_address'] = $addressDetails[0]['display'];
141 //assign soft credit record if exists.
142 $SCRecords = CRM_Contribute_BAO_ContributionSoft
::getSoftContribution($values['contribution_id'], TRUE);
143 if (!empty($SCRecords['soft_credit'])) {
144 $this->assign('softContributions', $SCRecords['soft_credit']);
145 unset($SCRecords['soft_credit']);
148 //assign pcp record if exists
149 foreach ($SCRecords as $name => $value) {
150 $this->assign($name, $value);
153 $lineItems = array();
154 $displayLineItems = FALSE;
156 $lineItems = array(CRM_Price_BAO_LineItem
::getLineItemsByContributionID(($id)));
157 $firstLineItem = reset($lineItems[0]);
158 $priceSet = civicrm_api3('PriceSet', 'getsingle', array('id' => $firstLineItem['price_set_id'], 'return' => 'is_quick_config, id'));
159 $displayLineItems = !$priceSet['is_quick_config'];
161 $this->assign('lineItem', $lineItems);
162 $this->assign('displayLineItems', $displayLineItems);
163 $values['totalAmount'] = $values['total_amount'];
164 $this->assign('displayLineItemFinancialType', TRUE);
166 //do check for campaigns
167 if ($campaignId = CRM_Utils_Array
::value('campaign_id', $values)) {
168 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
169 $values['campaign'] = $campaigns[$campaignId];
171 if ($values['contribution_status'] == 'Refunded') {
172 $this->assign('refund_trxn_id', CRM_Core_BAO_FinancialTrxn
::getRefundTransactionTrxnID($id));
175 // assign values to the template
176 $this->assign($values);
177 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
178 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
179 $this->assign('invoicing', $invoicing);
180 $this->assign('isDeferred', CRM_Utils_Array
::value('deferred_revenue_enabled', $invoiceSettings));
181 if ($invoicing && isset($values['tax_amount'])) {
182 $this->assign('totalTaxAmount', $values['tax_amount']);
185 $displayName = CRM_Contact_BAO_Contact
::displayName($values['contact_id']);
186 $this->assign('displayName', $displayName);
188 // Check if this is default domain contact CRM-10482
189 if (CRM_Contact_BAO_Contact
::checkDomainContact($values['contact_id'])) {
190 $displayName .= ' (' . ts('default organization') . ')';
193 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
194 CRM_Utils_System
::setTitle(ts('View Contribution from') . ' ' . $displayName);
196 // add viewed contribution to recent items list
197 $url = CRM_Utils_System
::url('civicrm/contact/view/contribution',
198 "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
201 $title = $displayName . ' - (' . CRM_Utils_Money
::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')';
203 $recentOther = array();
204 if (CRM_Core_Permission
::checkActionPermission('CiviContribute', CRM_Core_Action
::UPDATE
)) {
205 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/view/contribution',
206 "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
209 if (CRM_Core_Permission
::checkActionPermission('CiviContribute', CRM_Core_Action
::DELETE
)) {
210 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/contribution',
211 "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
214 CRM_Utils_Recent
::add($title,
218 $values['contact_id'],
222 $contributionStatus = $status[$values['contribution_status_id']];
223 if (in_array($contributionStatus, array('Partially paid', 'Pending refund'))
224 ||
($contributionStatus == 'Pending' && $values['is_pay_later'])
226 if ($contributionStatus == 'Pending refund') {
227 $this->assign('paymentButtonName', ts('Record Refund'));
230 $this->assign('paymentButtonName', ts('Record Payment'));
232 $this->assign('addRecordPayment', TRUE);
233 $this->assign('contactId', $values['contact_id']);
234 $this->assign('componentId', $id);
235 $this->assign('component', 'contribution');
240 * Build the form object.
242 public function buildQuickForm() {
244 $this->addButtons(array(
247 'name' => ts('Done'),
248 'spacing' => ' ',