3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
33 class CRM_Invoicing_Utils
{
36 * Function to call when invoicing is toggled on or off.
38 * We add or remove invoicing from the user dashboard here.
40 * @param bool $oldValue
41 * @param bool $newValue
42 * @param array $metadata
44 public static function onToggle($oldValue, $newValue, $metadata) {
45 if ($oldValue == $newValue) {
48 $existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config
::domainID()]['user_dashboard_options'];
49 $optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values'];
50 $invoiceKey = array_search('Invoices / Credit Notes', $optionValues);
51 $existingIndex = in_array($invoiceKey, $existingUserViewOptions);
53 if ($newValue && $existingIndex === FALSE) {
54 $existingUserViewOptions[] = $invoiceKey;
56 elseif (!$newValue && $existingIndex !== FALSE) {
57 unset($existingUserViewOptions[$existingIndex]);
59 civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]);
63 * Function to call to determine if invoicing is enabled.
65 * Historically the invoicing was declared as a setting but actually
66 * set within contribution_invoice_settings (which stores multiple settings
67 * as an array in a non-standard way).
69 * We check both here. But will deprecate the latter in time.
71 public static function isInvoicingEnabled() {
72 if (Civi
::settings()->get('invoicing')) {
75 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
76 return CRM_Utils_Array
::value('invoicing', $invoiceSettings);
80 * Function to call to determine default invoice page.
82 * Historically the invoicing was declared as a setting but actually
83 * set within contribution_invoice_settings (which stores multiple settings
84 * as an array in a non-standard way).
86 * We check both here. But will deprecate the latter in time.
88 public static function getDefaultPaymentPage() {
89 $value = Civi
::settings()->get('default_invoice_page');
90 if (is_numeric($value)) {
93 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
94 return CRM_Utils_Array
::value('default_invoice_page', $invoiceSettings);
98 * Function to get the tax term.
100 * The value is nested in the contribution_invoice_settings setting - which
101 * is unsupported. Here we have a wrapper function to make later cleanup easier.
103 public static function getTaxTerm() {
104 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
105 return CRM_Utils_Array
::value('tax_term', $invoiceSettings);