Commit | Line | Data |
---|---|---|
8d334338 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
8d334338 | 5 | | | |
bc77d7c0 TO |
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 | | |
8d334338 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
8d334338 | 16 | */ |
8d334338 | 17 | class CRM_Invoicing_Utils { |
18 | ||
19 | /** | |
20 | * Function to call when invoicing is toggled on or off. | |
21 | * | |
22 | * We add or remove invoicing from the user dashboard here. | |
23 | * | |
24 | * @param bool $oldValue | |
25 | * @param bool $newValue | |
26 | * @param array $metadata | |
ff6f993e | 27 | * |
28 | * @throws \CiviCRM_API3_Exception | |
8d334338 | 29 | */ |
30 | public static function onToggle($oldValue, $newValue, $metadata) { | |
31 | if ($oldValue == $newValue) { | |
32 | return; | |
33 | } | |
34 | $existingUserViewOptions = civicrm_api3('Setting', 'get', ['return' => 'user_dashboard_options'])['values'][CRM_Core_Config::domainID()]['user_dashboard_options']; | |
d0df87f2 | 35 | $optionValues = civicrm_api3('Setting', 'getoptions', ['field' => 'user_dashboard_options'])['values']; |
8d334338 | 36 | $invoiceKey = array_search('Invoices / Credit Notes', $optionValues); |
ff6f993e | 37 | $existingIndex = array_search($invoiceKey, $existingUserViewOptions); |
8d334338 | 38 | |
39 | if ($newValue && $existingIndex === FALSE) { | |
40 | $existingUserViewOptions[] = $invoiceKey; | |
41 | } | |
42 | elseif (!$newValue && $existingIndex !== FALSE) { | |
43 | unset($existingUserViewOptions[$existingIndex]); | |
44 | } | |
45 | civicrm_api3('Setting', 'create', ['user_dashboard_options' => $existingUserViewOptions]); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Function to call to determine if invoicing is enabled. | |
50 | * | |
51 | * Historically the invoicing was declared as a setting but actually | |
52 | * set within contribution_invoice_settings (which stores multiple settings | |
53 | * as an array in a non-standard way). | |
54 | * | |
f8857611 | 55 | * We check both here. But will deprecate the latter in time. |
8d334338 | 56 | */ |
57 | public static function isInvoicingEnabled() { | |
58 | if (Civi::settings()->get('invoicing')) { | |
59 | return TRUE; | |
60 | } | |
61 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | |
914d3734 | 62 | return $invoiceSettings['invoicing'] ?? NULL; |
8d334338 | 63 | } |
64 | ||
ec5e7bcf | 65 | /** |
66 | * Function to get the tax term. | |
67 | * | |
68 | * The value is nested in the contribution_invoice_settings setting - which | |
69 | * is unsupported. Here we have a wrapper function to make later cleanup easier. | |
70 | */ | |
71 | public static function getTaxTerm() { | |
72 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); | |
914d3734 | 73 | return $invoiceSettings['tax_term'] ?? NULL; |
ec5e7bcf | 74 | } |
75 | ||
8d334338 | 76 | } |