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

Added validation to currency update. #17256

Open
wants to merge 2 commits into
base: developer
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions layouts/basic/modules/Settings/CurrencyUpdate/Index.tpl
Expand Up @@ -16,27 +16,28 @@
<strong>{\App\Language::translate('LBL_WARNING', $QUALIFIED_MODULE)}</strong> {\App\Language::translate('MSG_NO_NET_CONN', $QUALIFIED_MODULE)}
</div>
{/if}
<form class="form-horizontal" method="post" action="index.php?module={$MODULENAME}&view=Index&parent=Settings">
<form class="form-horizontal js-currency-update_form" method="post" action="index.php?module={$MODULENAME}&view=Index&parent=Settings" data-js="container">
<table class="table table-bordered currencyTable">
<tr>
<th class="blockHeader" colspan="4">{\App\Language::translate('LBL_SELECT_BANK', $QUALIFIED_MODULE)}</th>
</tr>
<tr>
<td class="fieldLabel">
<span class="float-right"><strong>{\App\Language::translate('LBL_BANK', $QUALIFIED_MODULE)}:</strong></span>
<span class="float-right"><strong>{\App\Language::translate('LBL_BANK', $QUALIFIED_MODULE)}:</strong><span class="redColor">*</span></span>
</td>
<td class="fieldValue">
<div class="row">
<div class="col-md-5">
<select name="bank" id="bank" class="select2 form-control">
<option value="0" {if !$ACTIVE_BANK}selected{/if}>{\App\Language::translate('LBL_SELECT_OPTION', $QUALIFIED_MODULE)}</option>
<select name="bank" id="bank" class="select2 form-control" data-validation-engine="validate[required]">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you set this field as mandatory if you want to be able to delete a bank

<optgroup>
<option value="" {if !$ACTIVE_BANK}selected{/if}>{\App\Language::translate('LBL_SELECT_OPTION', $QUALIFIED_MODULE)}</option>
</optgroup>
{foreach from=$BANK item=key}
<option value="{$key.id}" {if $key.active eq '1'}selected{/if} data-name="{$key.bank_name|escape}">{\App\Language::translate($key.bank_name, $QUALIFIED_MODULE)}</option>
{/foreach}
</select>
</div>
<div class="col-md-7 btn-toolbar justify-content-end">
{*<button class="btn btn-success float-right" name="save" type="submit"><strong>{\App\Language::translate('LBL_SET_DEFAULT_BANK', $QUALIFIED_MODULE)}</strong></button>*}
{if count($SUPPORTED_CURRENCIES) gt 0}
<button class="btn btn-info"
id="supportedCurrencies"
Expand Down Expand Up @@ -82,7 +83,7 @@
</tr>
<tr>
<td class="fieldLabel">
<span class="float-right"><strong>{\App\Language::translate('LBL_CAL_DATE', $QUALIFIED_MODULE)}:</strong></label>
<span class="float-right"><strong>{\App\Language::translate('LBL_CAL_DATE', $QUALIFIED_MODULE)}:</strong><span class="redColor">*</span></label>
</td>
<td class="fieldValue">
<div class="input-group">
Expand All @@ -91,7 +92,7 @@
<span class="fas fa-calendar-alt"></span>
</span>
</div>
<input id="datepicker" type="text" class="form-control dateField" name="duedate" data-date-format="{$USER_MODEL->get('date_format')}" value="{$DATE}" />
<input id="datepicker" type="text" class="form-control dateField" name="duedate" data-date-format="{$USER_MODEL->get('date_format')}" value="{$DATE}" data-validation-engine="validate[required]" />
<span class="input-group-append">
<button class="btn btn-success" name="download" value="download" type="submit">{\App\Language::translate('LBL_SHOW', $QUALIFIED_MODULE)}</button>
</span>
Expand Down
2 changes: 1 addition & 1 deletion modules/Settings/CurrencyUpdate/actions/SaveActiveBank.php
Expand Up @@ -9,7 +9,7 @@ class Settings_CurrencyUpdate_SaveActiveBank_Action extends Settings_Vtiger_Basi
{
public function process(App\Request $request)
{
$id = $request->getInteger('id');
$id = !$request->isEmpty('id') ? $request->getInteger('id') : '';
$qualifiedModule = $request->getModule(false);
$moduleModel = Settings_CurrencyUpdate_Module_Model::getCleanInstance();
if (!$moduleModel->setActiveBankById($id)) {
Expand Down
8 changes: 4 additions & 4 deletions modules/Settings/CurrencyUpdate/models/Module.php
Expand Up @@ -52,7 +52,7 @@ public function getCurrencyNum()
*/
public function fetchCurrencyRates($dateCur, $cron = false): bool
{
if (!\App\RequestUtil::isNetConnection() || \count(($currencies = \App\Fields\Currency::getAll(true))) <= 1) {
if (!\App\RequestUtil::isNetConnection() || \count($currencies = \App\Fields\Currency::getAll(true)) <= 1 || empty($this->getActiveBankName())) {
return false;
}
$notifyNewRates = false;
Expand Down Expand Up @@ -236,7 +236,7 @@ public function getUnSupportedCurrencies($bankName = null)
/**
* Sets systems exchange rate for chosen currency.
*
* @param string $currency - currency code
* @param string $currency - currency code
* @param <Float> $exchange - exchange rate
*/
public function setCRMConversionRate($currency, $exchange)
Expand Down Expand Up @@ -305,11 +305,11 @@ public function getActiveBankId()
/**
* Saves new active bank by id.
*
* @param <Integer> $bankId - bank id
* @param int|string $bankId - bank id
*
* @return bool - true on success or false
*/
public function setActiveBankById($bankId)
public function setActiveBankById($bankId): bool
{
$db = \App\Db::getInstance();
$result = $db->createCommand()->update('yetiforce_currencyupdate_banks', ['active' => 0])->execute();
Expand Down
Expand Up @@ -120,11 +120,13 @@ jQuery.Class(
* Register events
*/
registerEvents: function () {
var container = jQuery('#currencyUpdateContainer');
let container = jQuery('#currencyUpdateContainer');
App.Fields.Date.register('#datepicker', false, {});
let form = container.find('.js-currency-update_form');
form.validationEngine(app.validationEngineOptions);
this.registerBankChange(container);
this.registerInfoButton(container);
this.registerAlertButton(container);
this.registerBankChange(container);
}
}
);