fix: 🚑️ Fixed credits check at server creation & formatted prices nicely
This commit is contained in:
parent
1fb855a684
commit
de96d6d6d3
|
@ -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("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
|
|
@ -223,10 +223,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<button type="submit" x-model="selectedProduct" name="product"
|
||||
:disabled="product.minimum_credits > user.credits"
|
||||
:class="product.minimum_credits > user.credits ? 'disabled' : ''"
|
||||
:disabled="product.minimum_credits > user.credits || product.price > user.credits"
|
||||
:class="product.minimum_credits > user.credits || product.price > user.credits ? 'disabled' : ''"
|
||||
class="btn btn-primary btn-block mt-2" @click="setProduct(product.id)"
|
||||
x-text=" product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}'">
|
||||
x-text="product.minimum_credits > user.credits || product.price > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}'">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
@endif
|
||||
</div>
|
||||
<span>
|
||||
{{ $server->product->price }}
|
||||
{{ number_format($server->product->price) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue