currency fields
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
|
||||
|
||||
46
app/Http/Middleware/LoadCurrencies.php
Normal file
46
app/Http/Middleware/LoadCurrencies.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Akaunting\Money\Currency;
|
||||
use App\Models\Setting\Currency as Model;
|
||||
use Closure;
|
||||
|
||||
class LoadCurrencies
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$company_id = session('company_id');
|
||||
|
||||
if (empty($company_id)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$currencies = Model::all();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
if (!isset($currency->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);
|
||||
}
|
||||
|
||||
}
|
||||
41
app/Listeners/Updates/Version113.php
Normal file
41
app/Listeners/Updates/Version113.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
class Version113 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '1.1.3';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateFinished $event)
|
||||
{
|
||||
// Check if should listen
|
||||
if (!$this->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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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(),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user