parent
03cfc648b0
commit
99f4f3b3d8
@ -4,12 +4,23 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use App\Services\FinanceService;
|
||||||
use Igaster\LaravelTheme\Facades\Theme;
|
use Igaster\LaravelTheme\Facades\Theme;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class SettingsController extends Controller
|
class SettingsController extends Controller
|
||||||
{
|
{
|
||||||
|
private $financeSvc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FinanceService $financeSvc
|
||||||
|
*/
|
||||||
|
public function __construct(FinanceService $financeSvc)
|
||||||
|
{
|
||||||
|
$this->financeSvc = $financeSvc;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of themes formatted for a select box
|
* Get a list of themes formatted for a select box
|
||||||
*
|
*
|
||||||
@ -30,6 +41,22 @@ class SettingsController extends Controller
|
|||||||
return $theme_list;
|
return $theme_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the currency list
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getCurrencyList(): array
|
||||||
|
{
|
||||||
|
$curr = [];
|
||||||
|
foreach (config('money') as $currency => $attrs) {
|
||||||
|
$name = $attrs['name'].' ('.$attrs['symbol'].'/'.$currency.')';
|
||||||
|
$curr[$currency] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $curr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the settings. Group them by the setting group
|
* Display the settings. Group them by the setting group
|
||||||
*/
|
*/
|
||||||
@ -39,6 +66,7 @@ class SettingsController extends Controller
|
|||||||
$settings = $settings->groupBy('group');
|
$settings = $settings->groupBy('group');
|
||||||
|
|
||||||
return view('admin.settings.index', [
|
return view('admin.settings.index', [
|
||||||
|
'currencies' => $this->getCurrencyList(),
|
||||||
'grouped_settings' => $settings,
|
'grouped_settings' => $settings,
|
||||||
'themes' => $this->getThemes(),
|
'themes' => $this->getThemes(),
|
||||||
]);
|
]);
|
||||||
@ -68,6 +96,8 @@ class SettingsController extends Controller
|
|||||||
$setting->save();
|
$setting->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->financeSvc->changeJournalCurrencies();
|
||||||
|
|
||||||
flash('Settings saved!');
|
flash('Settings saved!');
|
||||||
|
|
||||||
return redirect('/admin/settings');
|
return redirect('/admin/settings');
|
||||||
|
@ -12,7 +12,7 @@ trait JournalTrait
|
|||||||
public static function bootJournalTrait()
|
public static function bootJournalTrait()
|
||||||
{
|
{
|
||||||
static::created(function ($model) {
|
static::created(function ($model) {
|
||||||
$model->initJournal(config('phpvms.currency'));
|
$model->initJournal(setting('units.currency'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class JournalRepository extends Repository implements CacheableInterface
|
|||||||
'journal_id' => $journal->id,
|
'journal_id' => $journal->id,
|
||||||
'credit' => $credit ? $credit->getAmount() : null,
|
'credit' => $credit ? $credit->getAmount() : null,
|
||||||
'debit' => $debit ? $debit->getAmount() : null,
|
'debit' => $debit ? $debit->getAmount() : null,
|
||||||
'currency' => config('phpvms.currency'),
|
'currency' => setting('units.currency', 'USD'),
|
||||||
'memo' => $memo,
|
'memo' => $memo,
|
||||||
'post_date' => $post_date,
|
'post_date' => $post_date,
|
||||||
'transaction_group' => $transaction_group,
|
'transaction_group' => $transaction_group,
|
||||||
|
@ -63,11 +63,11 @@ class PirepFinanceService extends Service
|
|||||||
public function processFinancesForPirep(Pirep $pirep)
|
public function processFinancesForPirep(Pirep $pirep)
|
||||||
{
|
{
|
||||||
if (!$pirep->airline->journal) {
|
if (!$pirep->airline->journal) {
|
||||||
$pirep->airline->journal = $pirep->airline->initJournal(config('phpvms.currency'));
|
$pirep->airline->journal = $pirep->airline->initJournal(setting('units.currency', 'USD'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$pirep->user->journal) {
|
if (!$pirep->user->journal) {
|
||||||
$pirep->user->journal = $pirep->user->initJournal(config('phpvms.currency'));
|
$pirep->user->journal = $pirep->user->initJournal(setting('units.currency', 'USD'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean out the expenses first
|
// Clean out the expenses first
|
||||||
|
@ -168,4 +168,16 @@ class FinanceService extends Service
|
|||||||
'transactions' => $transactions,
|
'transactions' => $transactions,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the currencies on the journals and transactions to the current currency value
|
||||||
|
*/
|
||||||
|
public function changeJournalCurrencies(): void
|
||||||
|
{
|
||||||
|
$currency = setting('units.currency', 'USD');
|
||||||
|
$update = ['currency' => $currency];
|
||||||
|
|
||||||
|
Journal::query()->update($update);
|
||||||
|
JournalTransaction::query()->update($update);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ class SeederService extends Service
|
|||||||
|
|
||||||
// See if any of the options have changed
|
// See if any of the options have changed
|
||||||
if ($row->type === 'select') {
|
if ($row->type === 'select') {
|
||||||
if ($row->options !== $setting['options']) {
|
if (!empty($row->options) && $row->options !== $setting['options']) {
|
||||||
Log::info('Options for '.$id.' changed, update available');
|
Log::info('Options for '.$id.' changed, update available');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class Money
|
|||||||
*/
|
*/
|
||||||
public static function convertToSubunit($amount)
|
public static function convertToSubunit($amount)
|
||||||
{
|
{
|
||||||
$currency = config('phpvms.currency');
|
$currency = setting('units.currency', 'USD');
|
||||||
return (int) $amount * config('money.'.$currency.'.subunit');
|
return (int) $amount * config('money.'.$currency.'.subunit');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ class Money
|
|||||||
public static function currency()
|
public static function currency()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return new Currency(config('phpvms.currency', 'USD'));
|
return new Currency(setting('units.currency', 'USD'));
|
||||||
} catch (\OutOfBoundsException $e) {
|
} catch (\OutOfBoundsException $e) {
|
||||||
return new Currency('USD');
|
return new Currency('USD');
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,6 @@ return [
|
|||||||
*/
|
*/
|
||||||
'registration_redirect' => '/profile',
|
'registration_redirect' => '/profile',
|
||||||
|
|
||||||
/*
|
|
||||||
* The ISO "Currency Code" to use, the list is in config/money.php
|
|
||||||
*
|
|
||||||
* Note, do not change this after you've set it, unless you don't
|
|
||||||
* care that the currencies aren't "exchanged" into the new format
|
|
||||||
*/
|
|
||||||
'currency' => 'USD',
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Point to the class to use to retrieve the METAR string. If this
|
* Point to the class to use to retrieve the METAR string. If this
|
||||||
* goes inactive at some date, it can be replaced
|
* goes inactive at some date, it can be replaced
|
||||||
|
@ -23,13 +23,7 @@ return [
|
|||||||
|
|
||||||
// Overrides config/phpvms.php
|
// Overrides config/phpvms.php
|
||||||
'phpvms' => [
|
'phpvms' => [
|
||||||
/**
|
|
||||||
* The ISO "Currency Code" to use, the list is in config/money.php
|
|
||||||
*
|
|
||||||
* Note, do not change this after you've set it, unless you don't
|
|
||||||
* care that the currencies aren't "exchanged" into the new format
|
|
||||||
*/
|
|
||||||
'currency' => 'USD',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
@if(count($aircraft->expenses) > 0)
|
@if(count($aircraft->expenses) > 0)
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Cost <span class="small">{{ currency(config('phpvms.currency')) }}</span></th>
|
<th>Cost <span class="small">{{ currency(setting('units.currency')) }}</span></th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
@if(count($airport->expenses))
|
@if(count($airport->expenses))
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Cost <span class="small">{{ currency(config('phpvms.currency')) }}</span></th>
|
<th>Cost <span class="small">{{ currency(setting('units.currency')) }}</span></th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
<td>{{ $entry->memo }}</td>
|
<td>{{ $entry->memo }}</td>
|
||||||
<td>
|
<td>
|
||||||
@if($entry->credit)
|
@if($entry->credit)
|
||||||
{{ money($entry->credit, config('phpvms.currency')) }}
|
{{ money($entry->credit, setting('units.currency')) }}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@if($entry->debit)
|
@if($entry->debit)
|
||||||
{{ money($entry->debit, config('phpvms.currency')) }}
|
{{ money($entry->debit, setting('units.currency')) }}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -37,6 +37,12 @@
|
|||||||
list_to_assoc($themes),
|
list_to_assoc($themes),
|
||||||
$setting->value,
|
$setting->value,
|
||||||
['class' => 'select2', 'style' => 'width: 100%; text-align: left;']) }}
|
['class' => 'select2', 'style' => 'width: 100%; text-align: left;']) }}
|
||||||
|
@elseif($setting->id === 'units_currency')
|
||||||
|
{{ Form::select(
|
||||||
|
$setting->id,
|
||||||
|
$currencies,
|
||||||
|
$setting->value,
|
||||||
|
['class' => 'select2', 'style' => 'width: 100%; text-align: left;']) }}
|
||||||
@else
|
@else
|
||||||
{{ Form::select(
|
{{ Form::select(
|
||||||
$setting->id,
|
$setting->id,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
@if(count($subfleet->expenses))
|
@if(count($subfleet->expenses))
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Cost <span class="small">{{ currency(config('phpvms.currency')) }}</span></th>
|
<th>Cost <span class="small">{{ currency(setting('units.currency', 'USD')) }}</span></th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -689,7 +689,7 @@ class FinanceTest extends TestCase
|
|||||||
$journalRepo = app(JournalRepository::class);
|
$journalRepo = app(JournalRepository::class);
|
||||||
|
|
||||||
[$user, $pirep, $fares] = $this->createFullPirep();
|
[$user, $pirep, $fares] = $this->createFullPirep();
|
||||||
$user->airline->initJournal(config('phpvms.currency'));
|
$user->airline->initJournal(setting('units.currency', 'USD'));
|
||||||
|
|
||||||
// Override the fares
|
// Override the fares
|
||||||
$fare_counts = [];
|
$fare_counts = [];
|
||||||
@ -744,7 +744,7 @@ class FinanceTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
[$user, $pirep, $fares] = $this->createFullPirep();
|
[$user, $pirep, $fares] = $this->createFullPirep();
|
||||||
$user->airline->initJournal(config('phpvms.currency'));
|
$user->airline->initJournal(setting('units.currency', 'USD'));
|
||||||
|
|
||||||
// Override the fares
|
// Override the fares
|
||||||
$fare_counts = [];
|
$fare_counts = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user