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