Skip to content

Commit

Permalink
ESEB-76: Add Exchange Rate settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Oct 31, 2023
1 parent 5a0cc23 commit 5c73c72
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
75 changes: 75 additions & 0 deletions CRM/Financeextras/Form/ExchangeRateSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

use CRM_Financeextras_ExtensionUtil as E;

/**
* Exchange Rate Settings form controller
*/
class CRM_Financeextras_Form_ExchangeRateSettings extends CRM_Core_Form {

/**
* @inheritdoc
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Exchange Rate Settings'));

$this->add(
'checkbox',
'display_on_invoice',
ts('Display currency conversion for Tax on invoices')
);

$this->addCurrency('sales_tax_currency', ts('Sales Tax Currency'), FALSE);

$this->addButtons([
[
'type' => 'submit',
'name' => E::ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => E::ts('Cancel'),
'class' => 'btn-secondary-outline',
],
]);

$elementWithHelpTexts = ['display_on_invoice', 'sales_tax_currency'];

$this->assign('help', $elementWithHelpTexts);
$this->assign('elementNames', $this->getRenderableElementNames());
}

/**
* Called after form has been successfully submitted
*/
public function postProcess() {
$values = $this->exportValues();

Civi::settings()->set('fe_exchange_rate_settings', $values);

CRM_Core_Session::setStatus('Currency Exchange settings saved successfully', '', 'success');
}

public function setDefaultValues() {
return Civi::settings()->get('fe_exchange_rate_settings');
}

/**
* Get the fields/elements defined in this form.
*
* @return array (string)
*/
public function getRenderableElementNames() {
$elementNames = [];
foreach ($this->_elements as $element) {
/** @var HTML_QuickForm_Element $element */
$label = $element->getLabel();
if (!empty($label)) {
$elementNames[] = $element->getName();
}
}
return $elementNames;
}

}
17 changes: 17 additions & 0 deletions financeextras.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,20 @@ function financeextras_civicrm_buildForm($formName, &$form) {
$hook->buildForm();
}
}

/**
* Implements hook_civicrm_navigationMenu().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu/
*/
function financeextras_civicrm_navigationMenu(&$menu) {
_financeextras_civix_insert_navigation_menu($menu, 'Administer/CiviContribute', [
'label' => E::ts('Currency Exchange Settings'),
'name' => 'financeextras_exchangerate_settings',
'url' => 'civicrm/admin/setting/exchange-rate',
'permission' => 'administer CiviCRM',
'operator' => 'OR',
'separator' => 0,
]);
_financeextras_civix_navigationMenu($menu);
}
6 changes: 6 additions & 0 deletions templates/CRM/Financeextras/Form/ExchangeRateSettings.hlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{htxt id="display_on_invoice"}
{ts}Enabling this will display a section on an invoice or credit note with the currency conversation for any tax amounts from the invoice currency to the CiviCRM default currency.{/ts}
{/htxt}
{htxt id="sales_tax_currency"}
{ts}Specify the sales tax currency that any new invoice or credit note will display a currency conversion to.{/ts}
{/htxt}
46 changes: 46 additions & 0 deletions templates/CRM/Financeextras/Form/ExchangeRateSettings.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div id="bootstrap-theme">
<div class="panel panel-default fe__create-form-panel">
<div class="crm-submit-buttons panel-heading">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
<div class=" panel-body">
<div class="form-hoizontal">
{foreach from=$elementNames item=elementName}
<div class="form-group row {$elementName}">
<div class="col-sm-2 control-label">
{$form.$elementName.label}
{if in_array($elementName, $help)}
{help id="$elementName" file="CRM/Financeextras/Form/ExchangeRateSettings.hlp"}
{/if}
</div>
<div class="col-sm-7 col-md-5">
{$form.$elementName.html}
{if $elementName eq 'display_on_invoice'}
<span class="invoice-check"> Enable</span>
{/if}
</div>
</div>
{/foreach}
</div>
</div>

<div class="crm-submit-buttons panel-footer">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
</div>

{literal}
<style>
#bootstrap-theme > .fe__create-form-panel.panel > div.panel-body > div div.col-sm-2.control-label {
text-align: right;
}
#bootstrap-theme > .fe__create-form-panel.panel > div.panel-body > div div.col-sm-2.control-label > label {
display: inline;
text-align: right;
}
.invoice-check {
vertical-align: sub;
}
</style>
{/literal}
6 changes: 6 additions & 0 deletions xml/Menu/financeextras.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<title>Record a credit card refund</title>
<access_arguments>edit contributions</access_arguments>
</item>
<item>
<path>civicrm/admin/setting/exchange-rate</path>
<page_callback>CRM_Financeextras_Form_ExchangeRateSettings</page_callback>
<title>Excahnge Rate Settings</title>
<access_arguments>administer CiviCRM</access_arguments>
</item>
</menu>

0 comments on commit 5c73c72

Please sign in to comment.