diff --git a/app/Http/Controllers/Settings/Currencies.php b/app/Http/Controllers/Settings/Currencies.php index bce09e152..79e675606 100644 --- a/app/Http/Controllers/Settings/Currencies.php +++ b/app/Http/Controllers/Settings/Currencies.php @@ -212,4 +212,20 @@ class Currencies extends Controller return response()->json($json); } + + public function config() + { + $json = new \stdClass(); + + $code = request('code'); + + if ($code) { + $currency = config('money.' . $code); + $currency['symbol_first'] = $currency['symbol_first'] ? 1 : 0; + + $json = (object) $currency; + } + + return response()->json($json); + } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 72f9d998d..bedca45ae 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -36,6 +36,7 @@ class Kernel extends HttpKernel \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\RedirectIfNotInstalled::class, \App\Http\Middleware\LoadSettings::class, + \App\Http\Middleware\LoadCurrencies::class, \App\Http\Middleware\AddXHeader::class, ], diff --git a/app/Http/Middleware/LoadCurrencies.php b/app/Http/Middleware/LoadCurrencies.php new file mode 100644 index 000000000..334788a66 --- /dev/null +++ b/app/Http/Middleware/LoadCurrencies.php @@ -0,0 +1,46 @@ +precision)) { + continue; + } + + config(['money.' . $currency->code . '.precision' => $currency->precision]); + config(['money.' . $currency->code . '.symbol' => $currency->symbol]); + config(['money.' . $currency->code . '.symbol_first' => $currency->symbol_first]); + config(['money.' . $currency->code . '.decimal_mark' => $currency->decimal_mark]); + config(['money.' . $currency->code . '.thousands_separator' => $currency->thousands_separator]); + } + + // Set currencies with new settings + Currency::setCurrencies(config('money')); + + return $next($request); + } + +} \ No newline at end of file diff --git a/app/Listeners/Updates/Version113.php b/app/Listeners/Updates/Version113.php new file mode 100644 index 000000000..ec04aeeb4 --- /dev/null +++ b/app/Listeners/Updates/Version113.php @@ -0,0 +1,41 @@ +check($event)) { + return; + } + + // Update currencies + $currencies = Currency::all(); + + foreach ($currencies as $currency) { + $currency->precision = config('money.' . $currency->code . '.precision'); + $currency->symbol = config('money.' . $currency->code . '.symbol'); + $currency->symbol_first = config('money.' . $currency->code . '.symbol_first') ? 1 : 0; + $currency->decimal_mark = config('money.' . $currency->code . '.decimal_mark'); + $currency->thousands_separator = config('money.' . $currency->code . '.thousands_separator'); + + $currency->save(); + } + + } +} diff --git a/app/Models/Setting/Currency.php b/app/Models/Setting/Currency.php index 704194b80..96ac2d1aa 100644 --- a/app/Models/Setting/Currency.php +++ b/app/Models/Setting/Currency.php @@ -14,7 +14,7 @@ class Currency extends Model * * @var array */ - protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled']; + protected $fillable = ['company_id', 'name', 'code', 'rate', 'enabled', 'precision', 'symbol', 'symbol_first', 'decimal_mark', 'thousands_separator']; /** * Sortable columns. diff --git a/app/Transformers/Setting/Currency.php b/app/Transformers/Setting/Currency.php index 836a8bf62..5f235fec8 100644 --- a/app/Transformers/Setting/Currency.php +++ b/app/Transformers/Setting/Currency.php @@ -20,6 +20,11 @@ class Currency extends TransformerAbstract 'code' => $model->code, 'rate' => $model->rate, 'enabled' => $model->enabled, + 'precision' => $model->precision, + 'symbol' => $model->symbol, + 'symbol_first' => $model->symbol_first, + 'decimal_mark' => $model->decimal_mark, + 'thousands_separator' => $model->thousands_separator, 'created_at' => $model->created_at->toIso8601String(), 'updated_at' => $model->updated_at->toIso8601String(), ]; diff --git a/database/migrations/2017_12_09_000000_add_currency_columns.php b/database/migrations/2017_12_09_000000_add_currency_columns.php new file mode 100644 index 000000000..0da22dcef --- /dev/null +++ b/database/migrations/2017_12_09_000000_add_currency_columns.php @@ -0,0 +1,38 @@ +string('precision')->nullable(); + $table->string('symbol')->nullable(); + $table->integer('symbol_first')->default(1); + $table->string('decimal_mark')->nullable(); + $table->string('thousands_separator')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('currencies', function ($table) { + $table->dropColumn('precision'); + $table->dropColumn('symbol'); + $table->dropColumn('symbol_first'); + $table->dropColumn('decimal_mark'); + $table->dropColumn('thousands_separator'); + }); + } +} diff --git a/resources/lang/en-GB/currencies.php b/resources/lang/en-GB/currencies.php index b50d6434b..959079f3a 100644 --- a/resources/lang/en-GB/currencies.php +++ b/resources/lang/en-GB/currencies.php @@ -5,5 +5,14 @@ return [ 'code' => 'Code', 'rate' => 'Rate', 'default' => 'Default Currency', + 'decimal_mark' => 'Decimal Mark', + 'thousands_separator' => 'Thousands Separator', + 'precision' => 'Precision', + 'symbol' => [ + 'symbol' => 'Symbol', + 'position' => 'Symbol Position', + 'before' => 'Before Amount', + 'after' => 'After Amount', + ] ]; diff --git a/resources/views/settings/currencies/create.blade.php b/resources/views/settings/currencies/create.blade.php index b4d70f050..1923307fc 100644 --- a/resources/views/settings/currencies/create.blade.php +++ b/resources/views/settings/currencies/create.blade.php @@ -10,13 +10,23 @@