-
-
Notifications
You must be signed in to change notification settings - Fork 178
Add the option to choose a dynamic billing period. #1309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Ferks-FK
wants to merge
11
commits into
Ctrlpanel-gg:development
Choose a base branch
from
Ferks-FK:1285
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b3ebd09
Just sintax fix.
Ferks-FK a5418e8
Add the option to choose a dynamic billing period.
Ferks-FK 1502f35
Fix some things of the copilot review.
Ferks-FK 8c675fd
update charge servers logic.
Ferks-FK b5d2667
Update some logics.
Ferks-FK 41dec5d
Update migration to not use translated labels.
Ferks-FK 8a5f174
Remove forget select.
Ferks-FK 0332165
Update the default value logic to a logic where the administrator can…
Ferks-FK 4b589dd
Remove comments.
Ferks-FK 8487f6c
Remove more comments..
Ferks-FK 421aecb
Update product crud.
Ferks-FK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| enum BillingPeriod: int | ||
| { | ||
| case HOURLY = 1; | ||
| case DAILY = 2; | ||
| case WEEKLY = 3; | ||
| case MONTHLY = 4; | ||
| case QUARTERLY = 5; | ||
| case HALF_ANNUALLY = 6; | ||
| case ANNUALLY = 7; | ||
|
|
||
| public function label(): string | ||
| { | ||
| return match($this) { | ||
| self::HOURLY => __('Hourly'), | ||
| self::DAILY => __('Daily'), | ||
| self::WEEKLY => __('Weekly'), | ||
| self::MONTHLY => __('Monthly'), | ||
| self::QUARTERLY => __('Quarterly'), | ||
| self::HALF_ANNUALLY => __('Half Annually'), | ||
| self::ANNUALLY => __('Annually'), | ||
| }; | ||
| } | ||
|
|
||
| public function description(): string | ||
| { | ||
| return match($this) { | ||
| self::HOURLY => __('Charge the server every hour.'), | ||
| self::DAILY => __('Charge the server every day.'), | ||
| self::WEEKLY => __('Charge the server every week.'), | ||
| self::MONTHLY => __('Charge the server every month.'), | ||
| self::QUARTERLY => __('Charge the server every quarter.'), | ||
| self::HALF_ANNUALLY => __('Charge the server every half year.'), | ||
| self::ANNUALLY => __('Charge the server every year.'), | ||
| }; | ||
| } | ||
|
|
||
| public static function options(): array | ||
| { | ||
| return collect(self::cases())->mapWithKeys(function ($period) { | ||
| return [$period->value => $period->label()]; | ||
| })->toArray(); | ||
| } | ||
|
|
||
| public static function fromValue(int $value): ?self | ||
| { | ||
| return self::tryFrom($value); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...base/migrations/2026_02_08_084601_add_default_billing_period_column_to_products_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| use App\Enums\BillingPeriod; | ||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('products', function (Blueprint $table) { | ||
| $table->tinyInteger('default_billing_period')->after('default_billing_priority'); | ||
| }); | ||
|
Ferks-FK marked this conversation as resolved.
Outdated
|
||
|
|
||
| $periodMapping = [ | ||
| 'hourly' => BillingPeriod::HOURLY->value, | ||
| 'daily' => BillingPeriod::DAILY->value, | ||
| 'weekly' => BillingPeriod::WEEKLY->value, | ||
| 'monthly' => BillingPeriod::MONTHLY->value, | ||
| 'quarterly' => BillingPeriod::QUARTERLY->value, | ||
| 'half-annually' => BillingPeriod::HALF_ANNUALLY->value, | ||
| 'annually' => BillingPeriod::ANNUALLY->value, | ||
| ]; | ||
|
|
||
| DB::table('products')->select('id', 'billing_period')->get()->each(function ($product) use($periodMapping) { | ||
| $period = $periodMapping[$product->billing_period] ?? null; | ||
|
|
||
| if ($period) { | ||
| DB::table('products') | ||
| ->where('id', $product->id) | ||
| ->update(['default_billing_period' => $period]); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::table('products', function (Blueprint $table) { | ||
| $table->dropColumn('default_billing_period'); | ||
| }); | ||
| } | ||
| }; | ||
40 changes: 40 additions & 0 deletions
40
database/migrations/2026_02_08_094217_drop_billing_period_column_of_products_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| use App\Enums\BillingPeriod; | ||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('products', function (Blueprint $table) { | ||
| $table->dropColumn('billing_period'); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::table('products', function (Blueprint $table) { | ||
| $table->string('billing_period')->after('minimum_credits'); | ||
| }); | ||
|
|
||
| DB::table('products')->select('id', 'default_billing_period')->get()->each(function ($product) { | ||
| $period = BillingPeriod::fromValue($product->default_billing_period); | ||
|
|
||
| if ($period) { | ||
| DB::table('products') | ||
| ->where('id', $product->id) | ||
| ->update(['billing_period' => str_replace(' ', '-', strtolower($period->label()))]); | ||
|
Ferks-FK marked this conversation as resolved.
Outdated
|
||
| } | ||
| }); | ||
| } | ||
| }; | ||
28 changes: 28 additions & 0 deletions
28
database/migrations/2026_02_08_094845_add_billing_period_column_to_servers_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('servers', function (Blueprint $table) { | ||
| $table->tinyInteger('billing_period')->after('billing_priority')->nullable(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::table('servers', function (Blueprint $table) { | ||
| $table->dropColumn('billing_period'); | ||
| }); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.