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
17 class CRM_Invoicing_Utils
{
20 * Function to call when invoicing is toggled on or off.
22 * We add or remove invoicing from the user dashboard here.
24 * @param bool $oldValue
25 * @param bool $newValue
26 * @param array $metadata
28 public static function onToggle($oldValue, $newValue, $metadata) {
29 if ($oldValue == $newValue) {
32 $existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config
::domainID()]['user_dashboard_options'];
33 $optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values'];
34 $invoiceKey = array_search('Invoices / Credit Notes', $optionValues);
35 $existingIndex = in_array($invoiceKey, $existingUserViewOptions);
37 if ($newValue && $existingIndex === FALSE) {
38 $existingUserViewOptions[] = $invoiceKey;
40 elseif (!$newValue && $existingIndex !== FALSE) {
41 unset($existingUserViewOptions[$existingIndex]);
43 civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]);
47 * Function to call to determine if invoicing is enabled.
49 * Historically the invoicing was declared as a setting but actually
50 * set within contribution_invoice_settings (which stores multiple settings
51 * as an array in a non-standard way).
53 * We check both here. But will deprecate the latter in time.
55 public static function isInvoicingEnabled() {
56 if (Civi
::settings()->get('invoicing')) {
59 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
60 return CRM_Utils_Array
::value('invoicing', $invoiceSettings);
64 * Function to call to determine default invoice page.
66 * Historically the invoicing was declared as a setting but actually
67 * set within contribution_invoice_settings (which stores multiple settings
68 * as an array in a non-standard way).
70 * We check both here. But will deprecate the latter in time.
72 public static function getDefaultPaymentPage() {
73 $value = Civi
::settings()->get('default_invoice_page');
74 if (is_numeric($value)) {
77 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
78 return CRM_Utils_Array
::value('default_invoice_page', $invoiceSettings);
82 * Function to get the tax term.
84 * The value is nested in the contribution_invoice_settings setting - which
85 * is unsupported. Here we have a wrapper function to make later cleanup easier.
87 public static function getTaxTerm() {
88 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
89 return CRM_Utils_Array
::value('tax_term', $invoiceSettings);