Added dashboard currency setting
Added dashboard currency setting
This commit is contained in:
parent
ff280e6c62
commit
73f2d8f07f
|
@ -65,7 +65,8 @@ class HomeController extends Controller
|
||||||
'due_soon' => $due_soon,
|
'due_soon' => $due_soon,
|
||||||
'newest' => $recently_added,
|
'newest' => $recently_added,
|
||||||
'execution_time' => number_format($p->getTimeTaken(), 2),
|
'execution_time' => number_format($p->getTimeTaken(), 2),
|
||||||
'servers_summary' => $server_summary
|
'servers_summary' => $server_summary,
|
||||||
|
'currency' => Session::get('dashboard_currency')
|
||||||
);
|
);
|
||||||
|
|
||||||
return view('home', compact('information'));
|
return view('home', compact('information'));
|
||||||
|
|
|
@ -33,7 +33,8 @@ class SettingsController extends Controller
|
||||||
'default_currency' => 'required',
|
'default_currency' => 'required',
|
||||||
'default_server_os' => 'required',
|
'default_server_os' => 'required',
|
||||||
'due_soon_amount' => 'required|integer|between:0,12',
|
'due_soon_amount' => 'required|integer|between:0,12',
|
||||||
'recently_added_amount' => 'required|integer|between:0,12'
|
'recently_added_amount' => 'required|integer|between:0,12',
|
||||||
|
'currency' => 'required|string|size:3'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
DB::table('settings')
|
DB::table('settings')
|
||||||
|
@ -51,7 +52,8 @@ class SettingsController extends Controller
|
||||||
'default_currency' => $request->default_currency,
|
'default_currency' => $request->default_currency,
|
||||||
'default_server_os' => $request->default_server_os,
|
'default_server_os' => $request->default_server_os,
|
||||||
'due_soon_amount' => $request->due_soon_amount,
|
'due_soon_amount' => $request->due_soon_amount,
|
||||||
'recently_added_amount' => $request->recently_added_amount
|
'recently_added_amount' => $request->recently_added_amount,
|
||||||
|
'dashboard_currency' => $request->currency,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Settings::setSettingsToSession($settings);
|
Settings::setSettingsToSession($settings);
|
||||||
|
|
|
@ -119,24 +119,29 @@ class Home extends Model
|
||||||
$total_cost_weekly = $total_cost_pm = $inactive_count = 0;
|
$total_cost_weekly = $total_cost_pm = $inactive_count = 0;
|
||||||
foreach ($pricing as $price) {
|
foreach ($pricing as $price) {
|
||||||
if ($price['active'] === 1) {
|
if ($price['active'] === 1) {
|
||||||
|
if (Session::get('dashboard_currency') !== 'USD') {
|
||||||
|
$the_price = Pricing::convertFromUSD($price['as_usd'], Session::get('dashboard_currency'));
|
||||||
|
} else {
|
||||||
|
$the_price = $price['as_usd'];
|
||||||
|
}
|
||||||
if ($price['term'] === 1) {//1 month
|
if ($price['term'] === 1) {//1 month
|
||||||
$total_cost_weekly += ($price['as_usd'] / 4);
|
$total_cost_weekly += ($the_price / 4);
|
||||||
$total_cost_pm += $price['as_usd'];
|
$total_cost_pm += $the_price;
|
||||||
} elseif ($price['term'] === 2) {//3 months
|
} elseif ($price['term'] === 2) {//3 months
|
||||||
$total_cost_weekly += ($price['as_usd'] / 12);
|
$total_cost_weekly += ($the_price / 12);
|
||||||
$total_cost_pm += ($price['as_usd'] / 3);
|
$total_cost_pm += ($the_price / 3);
|
||||||
} elseif ($price['term'] === 3) {// 6 month
|
} elseif ($price['term'] === 3) {// 6 month
|
||||||
$total_cost_weekly += ($price['as_usd'] / 24);
|
$total_cost_weekly += ($the_price / 24);
|
||||||
$total_cost_pm += ($price['as_usd'] / 6);
|
$total_cost_pm += ($the_price / 6);
|
||||||
} elseif ($price['term'] === 4) {// 1 year
|
} elseif ($price['term'] === 4) {// 1 year
|
||||||
$total_cost_weekly += ($price['as_usd'] / 48);
|
$total_cost_weekly += ($the_price / 48);
|
||||||
$total_cost_pm += ($price['as_usd'] / 12);
|
$total_cost_pm += ($the_price / 12);
|
||||||
} elseif ($price['term'] === 5) {//2 years
|
} elseif ($price['term'] === 5) {//2 years
|
||||||
$total_cost_weekly += ($price['as_usd'] / 96);
|
$total_cost_weekly += ($the_price / 96);
|
||||||
$total_cost_pm += ($price['as_usd'] / 24);
|
$total_cost_pm += ($the_price / 24);
|
||||||
} elseif ($price['term'] === 6) {//3 years
|
} elseif ($price['term'] === 6) {//3 years
|
||||||
$total_cost_weekly += ($price['as_usd'] / 144);
|
$total_cost_weekly += ($the_price / 144);
|
||||||
$total_cost_pm += ($price['as_usd'] / 36);
|
$total_cost_pm += ($the_price / 36);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$inactive_count++;
|
$inactive_count++;
|
||||||
|
|
|
@ -14,6 +14,27 @@ class Pricing extends Model
|
||||||
|
|
||||||
protected $fillable = ['service_id', 'service_type', 'currency', 'price', 'term', 'as_usd', 'usd_per_month', 'next_due_date'];
|
protected $fillable = ['service_id', 'service_type', 'currency', 'price', 'term', 'as_usd', 'usd_per_month', 'next_due_date'];
|
||||||
|
|
||||||
|
public static function convertFromUSD(string $amount, string $convert_to): float
|
||||||
|
{//Code rates update from an API??
|
||||||
|
if ($convert_to === 'AUD') {
|
||||||
|
return (1.39 * $amount);
|
||||||
|
} elseif ($convert_to === "USD") {
|
||||||
|
return $amount;
|
||||||
|
} elseif ($convert_to === "GBP") {
|
||||||
|
return (0.79 * $amount);
|
||||||
|
} elseif ($convert_to === "EUR") {
|
||||||
|
return (0.93 * $amount);
|
||||||
|
} elseif ($convert_to === "NZD") {
|
||||||
|
return (1.53 * $amount);
|
||||||
|
} elseif ($convert_to === "JPY") {
|
||||||
|
return (127.12 * $amount);
|
||||||
|
} elseif ($convert_to === "CAD") {
|
||||||
|
return (1.27 * $amount);
|
||||||
|
} else {
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function convertToUSD(string $amount, string $convert_from): float
|
public function convertToUSD(string $amount, string $convert_from): float
|
||||||
{
|
{
|
||||||
if ($convert_from === 'AUD') {
|
if ($convert_from === 'AUD') {
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Settings extends Model
|
||||||
Session::put('default_server_os', $settings[0]->default_server_os ?? 1);
|
Session::put('default_server_os', $settings[0]->default_server_os ?? 1);
|
||||||
Session::put('due_soon_amount', $settings[0]->due_soon_amount ?? 6);
|
Session::put('due_soon_amount', $settings[0]->due_soon_amount ?? 6);
|
||||||
Session::put('recently_added_amount', $settings[0]->recently_added_amount ?? 6);
|
Session::put('recently_added_amount', $settings[0]->recently_added_amount ?? 6);
|
||||||
|
Session::put('dashboard_currency', $settings[0]->dashboard_currency ?? 'USD');
|
||||||
Session::save();
|
Session::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body text-center shadow">
|
<div class="card-body text-center shadow">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h4>{{$information['total_cost_weekly']}} <small class="text-muted">USD</small></h4>
|
<h4>{{$information['total_cost_weekly']}} <small class="text-muted">{{$information['currency']}}</small></h4>
|
||||||
<p>Weekly cost</p>
|
<p>Weekly cost</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body text-center shadow">
|
<div class="card-body text-center shadow">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h4>{{$information['total_cost_monthly']}} <small class="text-muted">USD</small>
|
<h4>{{$information['total_cost_monthly']}} <small class="text-muted">{{$information['currency']}}</small>
|
||||||
</h4>
|
</h4>
|
||||||
<p>Monthly cost</p>
|
<p>Monthly cost</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body text-center shadow">
|
<div class="card-body text-center shadow">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h4>{{$information['total_cost_yearly']}} <small class="text-muted">USD</small></h4>
|
<h4>{{$information['total_cost_yearly']}} <small class="text-muted">{{$information['currency']}}</small></h4>
|
||||||
<p>Yearly cost</p>
|
<p>Yearly cost</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -102,7 +102,7 @@
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body text-center shadow">
|
<div class="card-body text-center shadow">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h4>{{$information['total_cost_2_yearly']}} <small class="text-muted">USD</small>
|
<h4>{{$information['total_cost_2_yearly']}} <small class="text-muted">{{$information['currency']}}</small>
|
||||||
</h4>
|
</h4>
|
||||||
<p>2 yearly cost</p>
|
<p>2 yearly cost</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -214,6 +214,13 @@
|
||||||
</x-number-input>
|
</x-number-input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-12 col-md-4 mb-3">
|
||||||
|
<x-currency-select>
|
||||||
|
<x-slot name="current">{{$setting[0]->dashboard_currency}}</x-slot>
|
||||||
|
</x-currency-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 col-lg-4">
|
<div class="col-12 col-lg-4">
|
||||||
<x-submit-button>Update settings</x-submit-button>
|
<x-submit-button>Update settings</x-submit-button>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user