Skip to content

A free open source IT asset/license management system

Localization digit separator feature. (#8915)

Evgenybbf7fbcff4f6
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index c0903c98f1..2bdf6ca4a9 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -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')
diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php
index 5e009ebfa1..07ff9be0a1 100644
--- a/app/Presenters/AssetPresenter.php
+++ b/app/Presenters/AssetPresenter.php
@@ -146,6 +146,7 @@ class AssetPresenter extends Presenter
"searchable" => true,
"sortable" => true,
"title" => trans('general.purchase_cost'),
+ "formatter" => 'numberWithCommas',
"footerFormatter" => 'sumFormatter',
], [
"field" => "order_number",
diff --git a/database/migrations/2020_12_14_233815_add_digit_separator_to_settings.php b/database/migrations/2020_12_14_233815_add_digit_separator_to_settings.php
new file mode 100644
index 0000000000..8a5471233e
--- /dev/null
+++ b/database/migrations/2020_12_14_233815_add_digit_separator_to_settings.php
@@ -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');
+ });
+ }
+}
diff --git a/resources/macros/macros.php b/resources/macros/macros.php
index 410275b784..56e85ac9f9 100644
--- a/resources/macros/macros.php
+++ b/resources/macros/macros.php
@@ -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
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index c638c0a5ea..7777c030b3 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -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 () {
diff --git a/resources/views/settings/localization.blade.php b/resources/views/settings/localization.blade.php
index 76063944cf..af48bfc7a3 100644
--- a/resources/views/settings/localization.blade.php
+++ b/resources/views/settings/localization.blade.php
@@ -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>