From de96d6d6d3ceaaf6bc17b51693d9d8beba2253cb Mon Sep 17 00:00:00 2001 From: IceToast Date: Wed, 27 Jul 2022 23:26:03 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Fixed=20credits?= =?UTF-8?q?=20check=20at=20server=20creation=20&=20formatted=20prices=20ni?= =?UTF-8?q?cely?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/ChargeServers.php | 2 +- app/Http/Controllers/ServerController.php | 4 +++- resources/views/servers/create.blade.php | 15 ++++++++++++--- resources/views/servers/index.blade.php | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/ChargeServers.php b/app/Console/Commands/ChargeServers.php index 72b5bab4..014af963 100644 --- a/app/Console/Commands/ChargeServers.php +++ b/app/Console/Commands/ChargeServers.php @@ -91,7 +91,7 @@ class ChargeServers extends Command } // check if the server is canceled or if user has enough credits to charge the server or - if ( $server->cancelled || $user->credits < $product->price) { + if ( $server->cancelled || $user->credits <= $product->price) { try { // suspend server $this->line("{$server->name} from user: {$user->name} has been suspended!"); diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 16732588..a740fbdb 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -105,11 +105,13 @@ class ServerController extends Controller // minimum credits if (FacadesRequest::has("product")) { $product = Product::findOrFail(FacadesRequest::input("product")); + if ( Auth::user()->credits < ($product->minimum_credits == -1 ? config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50) - : $product->minimum_credits) + : $product->minimum_credits) || + Auth::user()->credits <= $product->price ) { return redirect()->route('servers.index')->with('error', "You do not have the required amount of " . CREDITS_DISPLAY_NAME . " to use this product!"); } diff --git a/resources/views/servers/create.blade.php b/resources/views/servers/create.blade.php index 02ab8915..d91499e6 100644 --- a/resources/views/servers/create.blade.php +++ b/resources/views/servers/create.blade.php @@ -223,10 +223,10 @@ @@ -354,6 +354,7 @@ .catch(console.error) this.fetchedProducts = true; + // TODO: Sortable by user chosen property (cpu, ram, disk...) this.products = response.data.sort((p1, p2) => p1.price > p2.price && 1 || -1) @@ -362,11 +363,19 @@ product.cpu = product.cpu / 100; }) + //format price to have no decimals if it is a whole number + this.products.forEach(product => { + if (product.price % 1 === 0) { + product.price = Math.round(product.price); + } + }) + this.loading = false; this.updateSelectedObjects() }, + /** * @description map selected id's to selected objects * @note being used in the server info box diff --git a/resources/views/servers/index.blade.php b/resources/views/servers/index.blade.php index a9c57994..0e5d6950 100644 --- a/resources/views/servers/index.blade.php +++ b/resources/views/servers/index.blade.php @@ -188,7 +188,7 @@ @endif - {{ $server->product->price }} + {{ number_format($server->product->price) }}