Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-953: Move Angular Settings For Credit Note To Settings Class #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CRM/Financeextras/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Civi\Api4\OptionValue;
use Civi\Api4\Company;
use Civi\Financeextras\Utils\CurrencyUtils;

/**
* Get a list of settings for angular pages.
*/
class CRM_Financeextras_Settings {

/**
* Get a list of settings for angular pages.
*/
public static function getAll(): array {
$options = [
'shortDateFormat' => Civi::Settings()->get('dateformatshortdate'),
'canEditContribution' => CRM_Core_Permission::check('edit contributions'),
'currencyCodes' => CurrencyUtils::getCurrencies(),
];

$options['creditNoteStatus'] = OptionValue::get(FALSE)
->addSelect('id', 'value', 'name', 'label')
->addWhere('option_group_id:name', '=', 'financeextras_credit_note_status')
->execute()
->getArrayCopy();

$options['companies'] = Company::get(FALSE)
->addSelect('contact_id.organization_name', 'contact_id')
->execute()
->getArrayCopy();

return $options;
}

}
43 changes: 1 addition & 42 deletions ang/fe-creditnote.ang.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,6 @@
// in CiviCRM. See also:
// \https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules/n

use Civi\Api4\OptionValue;
use Civi\Financeextras\Utils\CurrencyUtils;

$options = [
'shortDateFormat' => Civi::Settings()->get('dateformatshortdate'),
'canEditContribution' => CRM_Core_Permission::check('edit contributions'),
];

/**
* Exposes currency codes to Angular.
*/
function financeextras_set_currency_codes(&$options) {
$options['currencyCodes'] = CurrencyUtils::getCurrencies();
}

/**
* Exposes credit note statuses to Angular.
*/
function financeextras_set_credit_note_status(&$options) {
$optionValues = OptionValue::get(FALSE)
->addSelect('id', 'value', 'name', 'label')
->addWhere('option_group_id:name', '=', 'financeextras_credit_note_status')
->execute();

$options['creditNoteStatus'] = $optionValues->getArrayCopy();
}

/**
* Exposes credit note statuses to Angular.
*/
function financeextras_set_companies(&$options) {
$options['companies'] = \Civi\Api4\Company::get(FALSE)
->addSelect('contact_id.organization_name', 'contact_id')
->execute()
->getArrayCopy();
}

financeextras_set_currency_codes($options);
financeextras_set_credit_note_status($options);
financeextras_set_companies($options);

return [
'js' => [
'js/strftime.js',
Expand All @@ -64,5 +23,5 @@ function financeextras_set_companies(&$options) {
'ngRoute',
'afsearchCreditNotes',
],
'settings' => $options,
'settingsFactory' => ['CRM_Financeextras_Settings', 'getAll'],
];
Loading