Localization digit separator feature. (#8915)

Provides an ability to localize the purchase_cost field in front-end hardware index table.
Has two digit separator formats in admin settings with comma and dot.
This commit is contained in:
Evgeny 2020-12-15 22:49:13 +03:00 committed by GitHub
parent 4a5cb94d94
commit bbf7fbcff4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 2 deletions

View file

@ -577,6 +577,7 @@ class SettingsController extends Controller
$setting->default_currency = $request->input('default_currency', '$');
$setting->date_display_format = $request->input('date_display_format');
$setting->time_display_format = $request->input('time_display_format');
$setting->digit_separator = $request->input('digit_separator');
if ($setting->save()) {
return redirect()->route('settings.index')

View file

@ -146,6 +146,7 @@ class AssetPresenter extends Presenter
"searchable" => true,
"sortable" => true,
"title" => trans('general.purchase_cost'),
"formatter" => 'numberWithCommas',
"footerFormatter" => 'sumFormatter',
], [
"field" => "order_number",

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddDigitSeparatorToSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->char('digit_separator')->nullable()->default('1234.56');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('digit_separator');
});
}
}

View file

@ -411,6 +411,25 @@ Form::macro('time_display_format', function ($name = "time_display_format", $sel
});
Form::macro('digit_separator', function ($name = "digit_separator", $selected = null, $class = null) {
$formats = [
'1234.56',
'1.234,56',
];
foreach ($formats as $format) {
}
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:120px">';
foreach ($formats as $format_inner ) {
$select .= '<option value="'.$format_inner.'"'.($selected == $format_inner ? ' selected="selected"' : '').'>'.$format_inner.'</option> ';
}
$select .= '</select>';
return $select;
});
/**
* Barcode macro
* Generates the dropdown menu of available 1D barcodes

View file

@ -592,11 +592,19 @@
var total_sum = data.reduce(function(sum, row) {
return (sum) + (parseFloat(row[field]) || 0);
}, 0);
return total_sum.toFixed(2);
return numberWithCommas(total_sum.toFixed(2));
}
return 'not an array';
}
function numberWithCommas(value) {
if ((value) && ("{{$snipeSettings->digit_separator}}" == "1.234,56")){
var parts = value.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".");
return parts.join(",");
}
return value
}
$(function () {
$('#bulkEdit').click(function () {

View file

@ -72,7 +72,10 @@
{{ Form::label('default_currency', trans('admin/settings/general.default_currency')) }}
</div>
<div class="col-md-9">
{{ Form::text('default_currency', old('default_currency', $setting->default_currency), array('class' => 'form-control','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px;')) }}
{{ Form::text('default_currency', old('default_currency', $setting->default_currency), array('class' => 'form-control select2-container','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px; display: inline-block; ')) }}
{!! Form::digit_separator('digit_separator', old('digit_separator', $setting->digit_separator), 'select2') !!}
{!! $errors->first('default_currency', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>