testing moon worth job

This commit is contained in:
2021-05-30 22:37:16 +09:00
parent 2e159063b5
commit 1a24d95d31
6 changed files with 135 additions and 76 deletions

View File

@@ -29,7 +29,7 @@ class MoonRentalController extends Controller
* Display moon rental request form * Display moon rental request form
*/ */
public function displayMoonRentalRequestForm() { public function displayMoonRentalRequestForm() {
} }
/** /**

View File

@@ -13,8 +13,11 @@ use Illuminate\Support\Str;
//Application Library //Application Library
use App\Library\Helpers\LookupHelper; use App\Library\Helpers\LookupHelper;
use App\Library\Esi\Esi; use App\Library\Esi\Esi;
use App\Library\Moons\MoonCalc;
//Models //Models
use App\Models\MoonRental\AllianceMoon;
use App\Models\MoonRental\AllianceMoonOre;
use App\Models\MiningTax\Invoice; use App\Models\MiningTax\Invoice;
use App\Models\MiningTax\Ledger; use App\Models\MiningTax\Ledger;
use App\Models\MiningTax\Observer; use App\Models\MiningTax\Observer;
@@ -33,6 +36,31 @@ class TestController extends Controller
return view('test.char.display')->with('char', $char); 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() { public function DebugMiningTaxesInvoices() {
$lookup = new LookupHelper; $lookup = new LookupHelper;
$ledgers = new Collection; $ledgers = new Collection;

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Jobs\Commands\MoonRental;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
use Carbon\Carbon;
//Internal Library
use App\Library\Moons\MoonCalc;
use App\Library\Helpers\LookupHelper;
//Models
use App\Models\MoonRental\AllianceMoon;
use App\Models\MoonRental\AllianceMoonOre;
class UpdateAllianceMoonRentalWorth implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
$this->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,
]);
}
}
}

View File

@@ -43,67 +43,29 @@ class MoonCalc {
/** /**
* Calculate the total worth of a moon * 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 //Declare variables
$totalPriceMined = 0.00; $total = 0.00;
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
//Convert the quantities into numbers we want to utilize //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 //Calculate the prices from the ores
if($firstOre != 'None') { if($firstOre != null) {
$totalPriceMined += $this->CalcMoonPrice($firstOre, $firstPerc); $total += $this->CalcMoonPrice($firstOre, $firstPerc);
} }
if($secondOre != 'None') { if($secondOre != null) {
$totalPriceMined += $this->CalcMoonPrice($secondOre, $secondPerc); $total += $this->CalcMoonPrice($secondOre, $secondPerc);
} }
if($thirdOre != 'None') { if($thirdOre != null) {
$totalPriceMined += $this->CalcMoonPrice($thirdOre, $thirdPerc); $total += $this->CalcMoonPrice($thirdOre, $thirdPerc);
} }
if($fourthOre != 'None') { if($fourthOre != null) {
$totalPriceMined += $this->CalcMoonPrice($fourthOre, $fourthPerc); $total += $this->CalcMoonPrice($fourthOre, $fourthPerc);
} }
//Return the rental price to the caller //Return the rental price to the caller
return $totalPriceMined; return $total;
}
/**
* 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;
} }
/** /**
@@ -480,7 +442,7 @@ class MoonCalc {
/** /**
* Calculate the moon's total price * Calculate the moon's total price
*/ */
private function CalcMoonPrice($ore, $percentage) { public function CalcMoonPrice($ore, $percentage) {
//Specify the total pull amount //Specify the total pull amount
$totalPull = $this->CalculateTotalMoonPull(); $totalPull = $this->CalculateTotalMoonPull();
@@ -612,34 +574,24 @@ class MoonCalc {
/** /**
* Convert percentages from quantities into a normalized percentage * Convert percentages from quantities into a normalized percentage
*/ */
private function ConvertPercentages(&$firstPerc, $firstQuan, &$secondPerc, $secondQuan, &$thirdPerc, $thirdQuan, &$fourthPerc, $fourthQuan) { public function ConvertPercentages(&$firstPerc, &$secondPerc, &$thirdPerc, &$fourthPerc) {
//Set the base percentages for the if statements
$firstPerc = 0.00;
$secondPerc = 0.00;
$thirdPerc = 0.00;
$fourthPerc = 0.00;
//Convert the quantities into numbers we want to utilize //Convert the quantities into numbers we want to utilize
if($firstQuan >= 1.00) { if($firstPerc >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan); $firstPerc = $this->ConvertToPercentage($firstPerc);
} else { }
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) { if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan); $secondPerc = $this->ConvertToPercentage($secondPerc);
} else { }
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) { if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan); $thirdPerc = $this->ConvertToPercentage($thirdPerc);
} else { }
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) { if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan); $fourthPerc = $this->ConvertToPercentage($fourthPerc);
} else { }
$fourthPerc = $fourthQuan;
}
//Add up all the percentages //Add up all the percentages
$totalPerc = $firstPerc + $secondPerc + $thirdPerc + $fourthPerc; $totalPerc = $firstPerc + $secondPerc + $thirdPerc + $fourthPerc;

View File

@@ -0,0 +1,4 @@
@extends('layouts.user.dashb4')
@section('content')
{{ var_dump($worth) }}
@endsection

View File

@@ -150,6 +150,7 @@ Route::group(['middleware' => ['auth']], function(){
Route::get('/test/char/display', 'Test\TestController@displayCharTest'); Route::get('/test/char/display', 'Test\TestController@displayCharTest');
Route::get('/test/miningtax/invoice', 'Test\TestController@DebugMiningTaxesInvoices'); Route::get('/test/miningtax/invoice', 'Test\TestController@DebugMiningTaxesInvoices');
Route::get('/test/miningtax/observers', 'Test\TestController@DebugMiningObservers'); Route::get('/test/miningtax/observers', 'Test\TestController@DebugMiningObservers');
Route::get('/test/moon/worth', 'Test\TestController@TestAllianceMoonWorth');
}); });