diff --git a/app/Http/Controllers/MoonRental/MoonRentalController.php b/app/Http/Controllers/MoonRental/MoonRentalController.php index e20f0f0f3..fc006e90c 100644 --- a/app/Http/Controllers/MoonRental/MoonRentalController.php +++ b/app/Http/Controllers/MoonRental/MoonRentalController.php @@ -29,7 +29,7 @@ class MoonRentalController extends Controller * Display moon rental request form */ public function displayMoonRentalRequestForm() { - + } /** diff --git a/app/Http/Controllers/Test/TestController.php b/app/Http/Controllers/Test/TestController.php index fadd3a10f..927592e90 100644 --- a/app/Http/Controllers/Test/TestController.php +++ b/app/Http/Controllers/Test/TestController.php @@ -13,8 +13,11 @@ use Illuminate\Support\Str; //Application Library use App\Library\Helpers\LookupHelper; use App\Library\Esi\Esi; +use App\Library\Moons\MoonCalc; //Models +use App\Models\MoonRental\AllianceMoon; +use App\Models\MoonRental\AllianceMoonOre; use App\Models\MiningTax\Invoice; use App\Models\MiningTax\Ledger; use App\Models\MiningTax\Observer; @@ -33,6 +36,31 @@ class TestController extends Controller return view('test.char.display')->with('char', $char); } + public function TestAllianceMoonWorth() { + //Declare variables + $lookup = new LookupHelper; + $mHelper = new MoonCalc; + $months = 3; + $rentalTax = 0.25; + + $moons = AllianceMoon::all(); + + foreach($moons as $moon) { + //Declare the arrays needed + $ores = array(); + + $ores = AllianceMoonOre::where([ + 'moon_id' => $moon->moon_id, + ])->get(['ore_id', 'quantity'])->toArray(); + + //one of these two ways will work + $worth = $mHelper->MoonTotalWorth($ores[0][0], $ores[0][1], $ores[1][0], $ores[1][1], $ores[2][0], $ores[2][1], $ores[3][0], $ores[3[1]]); + dd($worth); + $worth = $mHelper->MoonTotalWorth($ores[0], $ores[1], $ores[2], $ores[3], $ores[4], $ores[5], $ores[6], $ores[7]); + + return view('test.moonworth.moon')->with('worth', $worth); + } + public function DebugMiningTaxesInvoices() { $lookup = new LookupHelper; $ledgers = new Collection; diff --git a/app/Jobs/Commands/MoonRental/UpdateAllianceMoonRentalWorth.php b/app/Jobs/Commands/MoonRental/UpdateAllianceMoonRentalWorth.php new file mode 100644 index 000000000..d58d3ca80 --- /dev/null +++ b/app/Jobs/Commands/MoonRental/UpdateAllianceMoonRentalWorth.php @@ -0,0 +1,74 @@ +connection('redis'); + $this->onQueue('default'); + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + //Declare variables + $lookup = new LookupHelper; + $mHelper = new MoonCalc; + $months = 3; + $rentalTax = 0.25; + + $moons = AllianceMoon::all(); + + foreach($moons as $moon) { + //Declare the arrays needed + $ores = array(); + + $ores = AllianceMoonOre::where([ + 'moon_id' => $moon->moon_id, + ])->get(['ore_id', 'quantity'])->toArray(); + + //one of these two ways will work + $worth = $mHelper->MoonTotalWorth($ores[0][0], $ores[0][1], $ores[1][0], $ores[1][1], $ores[2][0], $ores[2][1], $ores[3][0], $ores[3[1]]); + dd($worth); + $worth = $mHelper->MoonTotalWorth($ores[0], $ores[1], $ores[2], $ores[3], $ores[4], $ores[5], $ores[6], $ores[7]); + $rentalAmount = $worth * $rentalTax * $months; + + AllianceMoon::where([ + 'moon_id' => $moon->moon_id, + ])->update([ + 'worth_amount' => $worth, + 'rental_amount' => $rentalAmount, + ]); + } + } +} diff --git a/app/Library/Moons/MoonCalc.php b/app/Library/Moons/MoonCalc.php index e6fbf6e08..ff25dd479 100644 --- a/app/Library/Moons/MoonCalc.php +++ b/app/Library/Moons/MoonCalc.php @@ -43,67 +43,29 @@ class MoonCalc { /** * Calculate the total worth of a moon */ - public function SpatialMoonsTotalWorth($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) { + public function MoonTotalWorth($firstOre = null, $firstQuan = 0.00, $secondOre = null, $secondQuan = 0.00, $thirdOre = null, $thirdQuan = 0.00, $fourthOre = null, $fourthQuan = 0.00) { //Declare variables - $totalPriceMined = 0.00; - - //Get the configuration for pricing calculations - $config = DB::table('Config')->get(); + $total = 0.00; //Convert the quantities into numbers we want to utilize - $this->ConvertPercentages($firstPerc, $firstQuan, $secondPerc, $secondQuan, $thirdPerc, $thirdQuan, $fourthPerc, $fourthQuan); + $this->ConvertPercentages($firstQuan, $secondQuan, $thirdQuan, $fourthQuan); //Calculate the prices from the ores - if($firstOre != 'None') { - $totalPriceMined += $this->CalcMoonPrice($firstOre, $firstPerc); + if($firstOre != null) { + $total += $this->CalcMoonPrice($firstOre, $firstPerc); } - if($secondOre != 'None') { - $totalPriceMined += $this->CalcMoonPrice($secondOre, $secondPerc); + if($secondOre != null) { + $total += $this->CalcMoonPrice($secondOre, $secondPerc); } - if($thirdOre != 'None') { - $totalPriceMined += $this->CalcMoonPrice($thirdOre, $thirdPerc); + if($thirdOre != null) { + $total += $this->CalcMoonPrice($thirdOre, $thirdPerc); } - if($fourthOre != 'None') { - $totalPriceMined += $this->CalcMoonPrice($fourthOre, $fourthPerc); + if($fourthOre != null) { + $total += $this->CalcMoonPrice($fourthOre, $fourthPerc); } //Return the rental price to the caller - return $totalPriceMined; - } - - /** - * Calculate the rental price - */ - public function SpatialMoons($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) { - //Declare variables - $totalPrice = 0.00; - - //Get the configuration for pricing calculations - $config = DB::table('Config')->get(); - - //Convert the quantities into numbers we want to utilize - $this->ConvertPercentages($firstPerc, $firstQuan, $secondPerc, $secondQuan, $thirdPerc, $thirdQuan, $fourthPerc, $fourthQuan); - - //Calculate the prices from the ores - if($firstOre != 'None') { - $totalPrice += $this->CalcRentalPrice($firstOre, $firstPerc); - } - if($secondOre != 'None') { - $totalPrice += $this->CalcRentalPrice($secondOre, $secondPerc); - } - if($thirdOre != 'None') { - $totalPrice += $this->CalcRentalPrice($thirdOre, $thirdPerc); - } - if($fourthOre != 'None') { - $totalPrice += $this->CalcRentalPrice($fourthOre, $fourthPerc); - } - - //Calculate the rental price. Refined rate is already included in the price from rental composition - $rentalPrice['alliance'] = $totalPrice * ($config[0]->RentalTax / 100.00); - $rentalPrice['outofalliance'] = $totalPrice * ($config[0]->AllyRentalTax / 100.00); - - //Return the rental price to the caller - return $rentalPrice; + return $total; } /** @@ -480,7 +442,7 @@ class MoonCalc { /** * Calculate the moon's total price */ - private function CalcMoonPrice($ore, $percentage) { + public function CalcMoonPrice($ore, $percentage) { //Specify the total pull amount $totalPull = $this->CalculateTotalMoonPull(); @@ -612,34 +574,24 @@ class MoonCalc { /** * Convert percentages from quantities into a normalized percentage */ - private function ConvertPercentages(&$firstPerc, $firstQuan, &$secondPerc, $secondQuan, &$thirdPerc, $thirdQuan, &$fourthPerc, $fourthQuan) { - //Set the base percentages for the if statements - $firstPerc = 0.00; - $secondPerc = 0.00; - $thirdPerc = 0.00; - $fourthPerc = 0.00; - + public function ConvertPercentages(&$firstPerc, &$secondPerc, &$thirdPerc, &$fourthPerc) { //Convert the quantities into numbers we want to utilize - if($firstQuan >= 1.00) { - $firstPerc = $this->ConvertToPercentage($firstQuan); - } else { - $firstPerc = $firstQuan; - } + if($firstPerc >= 1.00) { + $firstPerc = $this->ConvertToPercentage($firstPerc); + } + if($secondQuan >= 1.00) { - $secondPerc = $this->ConvertToPercentage($secondQuan); - } else { - $secondPerc = $secondQuan; - } + $secondPerc = $this->ConvertToPercentage($secondPerc); + } + if($thirdQuan >= 1.00) { - $thirdPerc = $this->ConvertToPercentage($thirdQuan); - } else { - $thirdPerc = $thirdQuan; - } + $thirdPerc = $this->ConvertToPercentage($thirdPerc); + } + if($fourthQuan >= 1.00) { - $fourthPerc = $this->ConvertToPercentage($fourthQuan); - } else { - $fourthPerc = $fourthQuan; - } + $fourthPerc = $this->ConvertToPercentage($fourthPerc); + } + //Add up all the percentages $totalPerc = $firstPerc + $secondPerc + $thirdPerc + $fourthPerc; diff --git a/resources/views/test/moonworth/moon.blade.php b/resources/views/test/moonworth/moon.blade.php new file mode 100644 index 000000000..8abb07411 --- /dev/null +++ b/resources/views/test/moonworth/moon.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.user.dashb4') +@section('content') +{{ var_dump($worth) }} +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4ba9e30f2..de4776417 100644 --- a/routes/web.php +++ b/routes/web.php @@ -150,6 +150,7 @@ Route::group(['middleware' => ['auth']], function(){ Route::get('/test/char/display', 'Test\TestController@displayCharTest'); Route::get('/test/miningtax/invoice', 'Test\TestController@DebugMiningTaxesInvoices'); Route::get('/test/miningtax/observers', 'Test\TestController@DebugMiningObservers'); + Route::get('/test/moon/worth', 'Test\TestController@TestAllianceMoonWorth'); });