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 @@
{{ $message }}
+Title | +Type | +Location | +Provider | +Disk | +BWidth | +Port | +Price | +Due | +Had since | +Actions | +
---|---|---|---|---|---|---|---|---|---|---|
{{ $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 }} | ++ + | +
No seed boxes found. | +
Built on Laravel + v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})
+ @endif +@foreach($labels as $label)
+ @if($loop->last)
+ {{$label->label}}
+ @else
+ {{$label->label}},
+ @endif
+ @endforeach
+ 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 + | +
+ Built on Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }} + ) +
+ @endif +