From 388592d86a0fc0574c94b126b0ef2c1da34e8c1a Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Tue, 22 Oct 2019 01:39:13 -0500 Subject: [PATCH] hauling configuration and hauling controller updates --- .../Controllers/Hauling/HaulingController.php | 33 ++++++++++----- app/Models/Config/HaulingConfig.php | 26 ++++++++++++ ..._22_060603_create_hualing_config_table.php | 37 +++++++++++++++++ database/seeds/HaulingConfigSeeder.php | 40 +++++++++++++++++++ vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 6 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 app/Models/Config/HaulingConfig.php create mode 100644 database/migrations/2019_10_22_060603_create_hualing_config_table.php create mode 100644 database/seeds/HaulingConfigSeeder.php diff --git a/app/Http/Controllers/Hauling/HaulingController.php b/app/Http/Controllers/Hauling/HaulingController.php index 8e678ae..81de596 100644 --- a/app/Http/Controllers/Hauling/HaulingController.php +++ b/app/Http/Controllers/Hauling/HaulingController.php @@ -13,6 +13,7 @@ use App\Library\Hauling\HaulingHelper; //Models use App\Models\Lookups\SolarSystem; +use App\Models\Config\HaulingConfig; class HaulingController extends Controller { @@ -40,7 +41,7 @@ class HaulingController extends Controller 'pickup' => 'required', 'destination' => 'required', 'collateral' => 'required', - 'size' => 'required', + 'size' => 'required|max:800000', ]); //Declare the class helper @@ -48,12 +49,26 @@ class HaulingController extends Controller //Declare some variables we will need $size = $request->size; - $collateral = $request->collateral; $time = '1 week'; $duration = '3 days'; $pickup = $request->pickup; $destination = $request->destination; + //Calculate the collateral + if(preg_match('(m|M|b|B)', $request->collateral) === 1) { + if(preg_match('(m|M)', $request->collateral) === 1) { + $collateral = $request->collateral * 1000000.00; + } else if(preg_match('(b|B)', $request->collaterial) === 1) { + $collateral = $request->collateral * 1000000000.00; + } + } else { + $collateral = $request->collateral; + } + + //Get some configuration data for the haul + $hConfig = HaulingConfig::all(); + + //Determine if both systems are in high sec $system1 = SolarSystem::where(['name' => $pickup])->first(); $system2 = SolarSystem::where(['name' => $destination])->first(); @@ -65,15 +80,11 @@ class HaulingController extends Controller //Calculate the jumps needed $jumps = $hHelper->JumpsBetweenSystems($pickup, $destination); - //Calculate the cost based on jumps multiplied by the fee. - if($size > 0 && $size <= 8000) { - $cost = $jumps * 600000; - } else if($size > 8000 && $size <= 57500) { - $cost = $jumps * 800000; - } else if($size > 57500 && $size <= 800000) { - $cost = $jumps * 1000000; - } else { - return redirect('/')->with('error', 'Size cannot be greater than 800k m3.'); + //Calculte the cost based on jumps multiplied by the fee. + foreach($hConfig as $config) { + if($size > $config->min_load_size && $size <= $config->max_load_size) { + $cost = $jumps * $hConfig->price_per_jump; + } } return view('hauling.display.results')->with('jumps', $jumps) diff --git a/app/Models/Config/HaulingConfig.php b/app/Models/Config/HaulingConfig.php new file mode 100644 index 0000000..9ddbca1 --- /dev/null +++ b/app/Models/Config/HaulingConfig.php @@ -0,0 +1,26 @@ +increments('id'); + $table->string('load_size')->unique(); + $table->unsignedBigInteger('min_load_size'); + $table->ungiendBigInteger('max_load_size'); + $table->decimal('price_per_jump'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('hualing_config'); + } +} diff --git a/database/seeds/HaulingConfigSeeder.php b/database/seeds/HaulingConfigSeeder.php new file mode 100644 index 0000000..82d1c14 --- /dev/null +++ b/database/seeds/HaulingConfigSeeder.php @@ -0,0 +1,40 @@ + 'small', + 'min_load_size' => 0, + 'max_load_size' => 8000, + 'price_per_jump' => 600000, + ]); + + HaulingConfig::insert([ + 'load_size' => 'medium', + 'min_load_size' => 8000, + 'max_load_size' => 57500, + 'price_per_jump' => 800000, + ]); + + HaulingConfig::insert([ + 'load_size' => 'large', + 'min_load_size' => 57500, + 'max_load_size' => 800000, + 'price_per_jump' => 1000000, + ]); + + printf("Finished adding hauling configuration.\r\n"); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 5252275..78bff55 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1026,6 +1026,7 @@ return array( 'Hamcrest\\Type\\IsString' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php', 'Hamcrest\\Util' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php', 'Hamcrest\\Xml\\HasXPath' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php', + 'HaulingConfigSeeder' => $baseDir . '/database/seeds/HaulingConfigSeeder.php', 'Highlight\\Autoloader' => $vendorDir . '/scrivo/highlight.php/Highlight/Autoloader.php', 'Highlight\\Highlighter' => $vendorDir . '/scrivo/highlight.php/Highlight/Highlighter.php', 'Highlight\\JsonRef' => $vendorDir . '/scrivo/highlight.php/Highlight/JsonRef.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 588775a..9def391 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -1506,6 +1506,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04 'Hamcrest\\Type\\IsString' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php', 'Hamcrest\\Util' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php', 'Hamcrest\\Xml\\HasXPath' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php', + 'HaulingConfigSeeder' => __DIR__ . '/../..' . '/database/seeds/HaulingConfigSeeder.php', 'Highlight\\Autoloader' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/Autoloader.php', 'Highlight\\Highlighter' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/Highlighter.php', 'Highlight\\JsonRef' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/JsonRef.php',