From 07c0b8a655df03debaacb437dfd2896a1c1a5afc Mon Sep 17 00:00:00 2001 From: cp6 Date: Mon, 16 May 2022 12:07:35 +1000 Subject: [PATCH] Added Seed box CRUD Added Seed box CRUD --- app/Http/Controllers/SeedBoxesController.php | 169 ++++++++++++++ app/Models/SeedBoxes.php | 58 +++++ ...22_05_15_105254_create_seedboxes_table.php | 44 ++++ resources/views/layouts/navigation.blade.php | 1 + resources/views/seedboxes/create.blade.php | 173 ++++++++++++++ resources/views/seedboxes/edit.blade.php | 219 ++++++++++++++++++ resources/views/seedboxes/index.blade.php | 124 ++++++++++ resources/views/seedboxes/show.blade.php | 145 ++++++++++++ routes/web.php | 3 + 9 files changed, 936 insertions(+) create mode 100644 app/Http/Controllers/SeedBoxesController.php create mode 100644 app/Models/SeedBoxes.php create mode 100644 database/migrations/2022_05_15_105254_create_seedboxes_table.php create mode 100644 resources/views/seedboxes/create.blade.php create mode 100644 resources/views/seedboxes/edit.blade.php create mode 100644 resources/views/seedboxes/index.blade.php create mode 100644 resources/views/seedboxes/show.blade.php diff --git a/app/Http/Controllers/SeedBoxesController.php b/app/Http/Controllers/SeedBoxesController.php new file mode 100644 index 0000000..adf1b35 --- /dev/null +++ b/app/Http/Controllers/SeedBoxesController.php @@ -0,0 +1,169 @@ +validate([ + 'title' => 'required|string', + 'hostname' => 'string|nullable', + 'seed_box_type' => 'required', + 'provider_id' => 'numeric', + 'location_id' => 'numeric', + 'price' => 'numeric', + 'payment_term' => 'numeric', + 'was_promo' => 'numeric', + 'owned_since' => 'date', + 'disk' => 'numeric', + 'bandwidth' => 'numeric', + 'port_speed' => 'numeric', + 'next_due_date' => 'required|date' + ]); + + $seedbox_id = Str::random(8); + + $pricing = new Pricing(); + + $as_usd = $pricing->convertToUSD($request->price, $request->currency); + + $pricing->insertPricing(6, $seedbox_id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); + + Labels::deleteLabelsAssignedTo($seedbox_id); + + Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $seedbox_id); + + SeedBoxes::create([ + 'id' => $seedbox_id, + 'title' => $request->title, + 'hostname' => $request->hostname, + 'seed_box_type' => $request->seed_box_type, + 'provider_id' => $request->provider_id, + 'location_id' => $request->location_id, + 'disk' => $request->disk, + 'disk_type' => 'GB', + 'disk_as_gb' => $request->disk, + 'owned_since' => $request->owned_since, + 'bandwidth' => $request->bandwidth, + 'port_speed' => $request->port_speed, + 'was_promo' => $request->was_promo + ]); + + SeedBoxes::seedBoxRelatedCacheForget(); + + return redirect()->route('seedboxes.index') + ->with('success', 'Seed box created Successfully.'); + + } + + public function show(SeedBoxes $seedbox) + { + $seedbox_extras = SeedBoxes::seedBoxDataShowPage($seedbox->id); + + $labels = Labels::labelsForService($seedbox->id); + + return view('seedboxes.show', compact(['seedbox', 'seedbox_extras', 'labels'])); + } + + public function edit(SeedBoxes $seedbox) + { + $seedbox = SeedBoxes::seedBoxEditDataPage($seedbox->id); + + $labels = Labels::labelsForService($seedbox[0]->id); + + return view('seedboxes.edit', compact(['seedbox', 'labels'])); + } + + public function update(Request $request, SeedBoxes $seedbox) + { + $request->validate([ + 'id' => 'required|size:8', + 'title' => 'required|string', + 'hostname' => 'string|nullable', + 'seed_box_type' => 'required', + 'disk' => 'numeric', + 'provider_id' => 'numeric', + 'location_id' => 'numeric', + 'price' => 'numeric', + 'payment_term' => 'numeric', + 'was_promo' => 'numeric', + 'owned_since' => 'date', + 'bandwidth' => 'numeric', + 'port_speed' => 'numeric' + ]); + + DB::table('seedboxes') + ->where('id', $seedbox->id) + ->update([ + 'title' => $request->title, + 'hostname' => $request->hostname, + 'seed_box_type' => $request->seed_box_type, + 'location_id' => $request->location_id, + 'provider_id' => $request->provider_id, + 'disk' => $request->disk, + 'disk_type' => 'GB', + 'disk_as_gb' => $request->disk, + 'owned_since' => $request->owned_since, + 'bandwidth' => $request->bandwidth, + 'port_speed' => $request->port_speed, + 'was_promo' => $request->was_promo + ]); + + $pricing = new Pricing(); + + $as_usd = $pricing->convertToUSD($request->price, $request->currency); + + $pricing->updatePricing($seedbox->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date); + + Labels::deleteLabelsAssignedTo($seedbox->id); + + Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $seedbox->id); + + Cache::forget("labels_for_service.{$seedbox->id}"); + + SeedBoxes::seedBoxRelatedCacheForget(); + + return redirect()->route('seedboxes.index') + ->with('success', 'Seed box updated Successfully.'); + } + + public function destroy(SeedBoxes $seedbox) + { + $seedbox_id = $seedbox->id; + $items = SeedBoxes::find($seedbox_id); + $items->delete(); + + $p = new Pricing(); + $p->deletePricing($seedbox_id); + + Labels::deleteLabelsAssignedTo($seedbox_id); + + SeedBoxes::seedBoxRelatedCacheForget(); + + return redirect()->route('seedboxes.index') + ->with('success', 'Seed box was deleted Successfully.'); + } +} diff --git a/app/Models/SeedBoxes.php b/app/Models/SeedBoxes.php new file mode 100644 index 0000000..3c810ba --- /dev/null +++ b/app/Models/SeedBoxes.php @@ -0,0 +1,58 @@ +join('providers as p', 's.provider_id', '=', 'p.id') + ->join('locations as l', 's.location_id', '=', 'l.id') + ->join('pricings as pr', 's.id', '=', 'pr.service_id') + ->get(['s.*', 'p.name as provider_name', 'pr.*', 'l.name as location']); + } + + public static function seedBoxDataShowPage(string $seed_box_id) + { + return DB::table('seedboxes as s') + ->join('pricings as pr', 's.id', '=', 'pr.service_id') + ->join('providers as p', 's.provider_id', '=', 'p.id') + ->join('locations as l', 's.location_id', '=', 'l.id') + ->where('s.id', '=', $seed_box_id) + ->get(['s.*', 'p.name as provider_name', 'l.name as location', 'pr.*']); + } + + public static function seedBoxEditDataPage(string $seed_box_id) + { + return DB::table('seedboxes as s') + ->join('pricings as pr', 's.id', '=', 'pr.service_id') + ->join('providers as p', 's.provider_id', '=', 'p.id') + ->join('locations as l', 's.location_id', '=', 'l.id') + ->where('s.id', '=', $seed_box_id) + ->get(['s.*', 'p.name as provider_name', 'l.name as location', 'pr.*']); + } + + +} diff --git a/database/migrations/2022_05_15_105254_create_seedboxes_table.php b/database/migrations/2022_05_15_105254_create_seedboxes_table.php new file mode 100644 index 0000000..0bca195 --- /dev/null +++ b/database/migrations/2022_05_15_105254_create_seedboxes_table.php @@ -0,0 +1,44 @@ +char('id', 8)->primary(); + $table->tinyInteger('active')->default(1); + $table->string('title'); + $table->string('hostname')->nullable(); + $table->string('seed_box_type')->nullable(); + $table->unsignedBigInteger('provider_id')->default(9999); + $table->unsignedBigInteger('location_id')->default(9999); + $table->integer('bandwidth')->nullable(); + $table->integer('port_speed')->nullable(); + $table->integer('disk')->default(10); + $table->char('disk_type', 2)->default('GB'); + $table->integer('disk_as_gb')->nullable()->default(0); + $table->tinyInteger('was_promo')->default(0); + $table->date('owned_since')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('seedboxes'); + } +}; diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 7c75def..243e8d1 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -36,6 +36,7 @@
  • Locations
  • OS
  • Providers
  • +
  • Seedboxes
  • YABs
  • Settings
  • Account
  • diff --git a/resources/views/seedboxes/create.blade.php b/resources/views/seedboxes/create.blade.php new file mode 100644 index 0000000..108a989 --- /dev/null +++ b/resources/views/seedboxes/create.blade.php @@ -0,0 +1,173 @@ +@section('title') {{'Enter new seed box'}} @endsection + + + {{ __('Insert a new seed box') }} + +
    +
    +
    +

    Seed box information

    + + + Go back + +
    + @csrf +
    +
    +
    +
    Title
    + + @error('title') {{ $message }} + @enderror +
    +
    +
    +
    +
    Hostname
    + +
    +
    +
    +
    +
    Type
    + +
    +
    +
    +
    +
    + + 10 + +
    +
    + + Price + price + 2.50 + 9999 + 0.01 + + +
    +
    + +
    +
    + + {{Session::get('default_currency')}} + +
    +
    +
    +
    + + 1 + +
    +
    + + Was promo + was_promo + 0 + +
    +
    + + Owned since + owned_since + {{Carbon\Carbon::now()->format('Y-m-d') }} + +
    +
    + + Next due date + next_due_date + {{Carbon\Carbon::now()->addDays(30)->format('Y-m-d') }} + +
    +
    +
    +
    + + Disk GB + disk + 1 + 999999 + 1 + 500 + +
    +
    + + Bandwidth GB + bandwidth + 1 + 999999 + 1 + 1000 + +
    +
    + + Port speed Mbps + port_speed + 1 + 999999 + 1 + 1000 + +
    +
    +
    +
    + + label + label1 + +
    +
    + + label + label2 + +
    +
    + + label + label3 + +
    +
    + + label + label4 + +
    +
    +
    + +
    +
    +
    +
    +
    +
    diff --git a/resources/views/seedboxes/edit.blade.php b/resources/views/seedboxes/edit.blade.php new file mode 100644 index 0000000..e846120 --- /dev/null +++ b/resources/views/seedboxes/edit.blade.php @@ -0,0 +1,219 @@ +@section('title') {{$seedbox[0]->title}} {{'edit'}} @endsection + + + Edit {{ $seedbox[0]->title }} + +
    +
    +
    + + Back to seed boxes + + +
    + @csrf + @method('PUT') +
    +
    +
    +
    Title
    + + @error('title') {{ $message }} + @enderror +
    +
    +
    +
    +
    Hostname
    + +
    +
    +
    + +
    +
    Type
    + +
    +
    +
    +
    +
    + + {{$seedbox[0]->provider_id}} + +
    +
    + + Price + price + {{$seedbox[0]->price}} + 9999 + 0.01 + + +
    +
    + + {{$seedbox[0]->term}} + +
    +
    + + {{$seedbox[0]->currency}} + +
    +
    +
    +
    + + {{$seedbox[0]->location_id}} + +
    +
    + + Promo price + was_promo + {{ $seedbox[0]->was_promo }} + +
    +
    + + Owned since + owned_since + {{$seedbox[0]->owned_since }} + +
    +
    + + Next due date + next_due_date + {{$seedbox[0]->next_due_date }} + +
    +
    +
    +
    + + Disk GB + disk + 1 + 999999 + 1 + {{$seedbox[0]->disk_as_gb}} + +
    +
    + + Bandwidth GB + bandwidth + 1 + 999999 + 1 + {{$seedbox[0]->bandwidth}} + +
    +
    + + Port speed GB + port_speed + 1 + 999999 + 1 + {{$seedbox[0]->port_speed}} + +
    +
    +
    +
    + + label + label1 + @if(isset($labels[0]->id)) + {{$labels[0]->id}} + @endif + +
    +
    + + label + label2 + @if(isset($labels[1]->id)) + {{$labels[1]->id}} + @endif + +
    +
    + + label + label3 + @if(isset($labels[2]->id)) + {{$labels[2]->id}} + @endif + +
    +
    + + label + label4 + @if(isset($labels[3]->id)) + {{$labels[3]->id}} + @endif + +
    +
    +
    + active === 1) ? 'checked' : '' }}> + +
    +
    + +
    +
    +
    +
    +
    +
    diff --git a/resources/views/seedboxes/index.blade.php b/resources/views/seedboxes/index.blade.php new file mode 100644 index 0000000..4e07d1b --- /dev/null +++ b/resources/views/seedboxes/index.blade.php @@ -0,0 +1,124 @@ +@section('title') {{'Seed boxes'}} @endsection +@section('style') + +@endsection +@section('scripts') + + +@endsection + + + {{ __('Seed boxes') }} + +
    + +
    +
    + Add a seed box + @if ($message = Session::get('success')) + + @endif +
    + + + + + + + + + + + + + + + + + + @if(isset($seedboxes[0])) + @foreach($seedboxes as $row) + + + + + + + + + + + + + + @endforeach + @else + + + + @endif + +
    TitleTypeLocationProviderDiskBWidthPortPriceDueHad sinceActions
    {{ $row->title }}{{ $row->seed_box_type }}{{ $row->location }}{{ $row->provider_name }} + @if($row->disk_as_gb >= 1000) + {{ number_format($row->disk_as_gb / 1000,1) }} TB + @else + {{ $row->disk_as_gb }} GB + @endif + + @if($row->bandwidth >= 1000) + {{ number_format($row->bandwidth / 1000,1) }} TB + @else + {{ $row->bandwidth }} GB + @endif + + @if($row->port_speed >= 1000) + {{ number_format($row->port_speed / 1000,1) }} Gbps + @else + {{ $row->port_speed }} Mbps + @endif + {{ $row->price }} {{$row->currency}} {{\App\Process::paymentTermIntToString($row->term)}}{{Carbon\Carbon::parse($row->next_due_date)->diffForHumans()}}{{ $row->owned_since }} +
    + @csrf + + + + + + + +
    +
    No seed boxes found.
    +
    +
    +
    + @if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1) +

    Built on Laravel + v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})

    + @endif +
    + + +
    diff --git a/resources/views/seedboxes/show.blade.php b/resources/views/seedboxes/show.blade.php new file mode 100644 index 0000000..b52f480 --- /dev/null +++ b/resources/views/seedboxes/show.blade.php @@ -0,0 +1,145 @@ +@section('title') {{$seedbox->title}} {{'Seed box'}} @endsection + + + {{ __('Seed box details') }} + +
    + +
    +
    +

    {{ $seedbox->title }}

    + @foreach($labels as $label) + @if($loop->last) + {{$label->label}} + @else + {{$label->label}}, + @endif + @endforeach +
    +
    +
    {{ $seedbox->id }}
    + @if($seedbox->active !== 1) +
    not active
    + @endif +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Type{{ $seedbox->seed_box_type }}
    Hostname{{ $seedbox_extras[0]->hostname }}
    Location{{ $seedbox_extras[0]->location }}
    Provider{{ $seedbox_extras[0]->provider_name }}
    Price{{ $seedbox_extras[0]->price }} {{ $seedbox_extras[0]->currency }} + {{\App\Process::paymentTermIntToString($seedbox_extras[0]->term)}} +
    Was promo{{ ($seedbox_extras[0]->was_promo === 1) ? 'Yes' : 'No' }}
    Owned since + @if(!is_null($seedbox->owned_since)) + {{ date_format(new DateTime($seedbox->owned_since), 'jS F Y') }} + @endif +
    Next due date{{Carbon\Carbon::parse($seedbox_extras[0]->next_due_date)->diffForHumans()}} + ({{Carbon\Carbon::parse($seedbox_extras[0]->next_due_date)->format('d/m/Y')}}) +
    Inserted + @if(!is_null($seedbox->created_at)) + {{ date_format(new DateTime($seedbox->created_at), 'jS M y g:i a') }} + @endif +
    Updated + @if(!is_null($seedbox->updated_at)) + {{ date_format(new DateTime($seedbox->updated_at), 'jS M y g:i a') }} + @endif +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    Disk + @if($seedbox->disk_as_gb >= 1000) + {{ number_format($seedbox->disk_as_gb / 1000,1) }} TB + @else + {{ $seedbox->disk_as_gb }} GB + @endif +
    Bandwidth + @if($seedbox->bandwidth >= 1000) + {{ number_format($seedbox->bandwidth / 1000,1) }} TB + @else + {{ $seedbox->bandwidth }} GB + @endif +
    Port speed + @if($seedbox->port_speed >= 1000) + {{ number_format($seedbox->port_speed / 1000,1) }} Gbps + @else + {{ $seedbox->port_speed }} Mbps + @endif +
    + +
    +
    + + Go back + + + Edit + +
    + @if(Session::has('timer_version_footer') && Session::get('timer_version_footer') === 1) +

    + Built on Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }} + ) +

    + @endif +
    +
    diff --git a/routes/web.php b/routes/web.php index 1e0522d..db71eaa 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ use App\Http\Controllers\MiscController; use App\Http\Controllers\OsController; use App\Http\Controllers\ProvidersController; use App\Http\Controllers\ResellerController; +use App\Http\Controllers\SeedBoxesController; use App\Http\Controllers\ServerController; use App\Http\Controllers\SettingsController; use App\Http\Controllers\SharedController; @@ -63,6 +64,8 @@ Route::resource('servers', ServerController::class)->middleware(['auth']); Route::resource('settings', SettingsController::class)->middleware(['auth']); +Route::resource('seedboxes', SeedBoxesController::class)->middleware(['auth']); + Route::resource('shared', SharedController::class)->middleware(['auth']); Route::resource('yabs', YabsController::class)->middleware(['auth']);