diff --git a/app/Http/Controllers/StructureController.php b/app/Http/Controllers/StructureController.php index 8fa5a2f69..fc0391c62 100644 --- a/app/Http/Controllers/StructureController.php +++ b/app/Http/Controllers/StructureController.php @@ -15,6 +15,11 @@ use App\User; use App\Models\User\UserRole; use App\Models\User\UserPermission; use App\Models\Corporation\CorpStructure; +use App\Models\Finances\StructureIndustryTaxJournal; + +use Seat\Eseye\Containers\EsiAuthentication; +use Seat\Eseye\Eseye; +use Seat\Eseye\Exceptions\RequestFailedException; class StructureController extends Controller { @@ -23,6 +28,68 @@ class StructureController extends Controller $this->middleware('permission:structure.operator'); } + public function displayIndustryTaxes() { + $this->middelware('role:Admin'); + + $corpId = 98287666; + $months = 3; + $name = array(); + + //Declare the structure tax helper class + $sHelper = new StructureTaxHelper(); + + //Get the dates we are working with + $dates = $sHelper->GetTimeFrameInMonths($months); + + //Get a list of structures + $structures = StructureIndustryTaxJournal::select('context_id') + ->whereBetween('date', [$start, $end]) + ->groupBy('context_id') + ->get(); + + //Get the ESI refresh token for the corporation to add new wallet journals into the database + $token = EsiToken::where(['character_id' => 93738489])->get(['refresh_token']); + + //Create an ESI authentication container + $config = config('esi'); + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + 'refresh_token' => $token[0]->refresh_token, + ]); + + //Create the esi class varialble + $esi = new Eseye($authentication); + + //Cycle through all of the structures and build a list of names + for($i = 0; $i < sizeof($structures); $i++) { + //Get the structure name from the ESI API + try { + $temp = $esi->invoke('get', '/universe/structures/{structure_id}/', [ + 'structure_id' => $structures[$j]->context_id, + ]); + + $name[$i] = $temp->name; + } catch(RequestFailedException $e) { + $name[$i] = ' '; + } + } + + //Cycle through all of the structures and get the revenue + for($j = 0; $j < sizeof($structures); $j++) { + for($i = 0; $i < $months; $i++) { + $totalTaxes[$i] = [ + 'IndustryTaxes' => number_format($sHelper->GetIndustryTaxes($dates[$i]['start'], $dates[$i]['end'], $structures[$j])), + 'MonthStart' => $dates[$i]['start']->toFormattedDateString(), + 'Structure' => $name[$j], + ]; + } + } + + + return view('structures.taxhistory')->with(compact('totalTaxes', 'months')); + } + public function chooseCorpTaxes() { $corps = CorpStructure::pluck('corporation_name', 'corporation_id'); return view('structures.choosecorporation')->with('corps', $corps); diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php index d86bebaa7..cf43a64e8 100644 --- a/app/Library/Finances/Helper/FinanceHelper.php +++ b/app/Library/Finances/Helper/FinanceHelper.php @@ -17,6 +17,7 @@ use App\Library\Finances\MarketTax; use App\Library\Finances\PlayerDonation; use App\Library\Finances\ReprocessingTax; use App\Library\Finances\JumpBridgeTax; +use App\Library\Finances\StructureIndustryTax; use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Eseye; @@ -83,6 +84,9 @@ class FinanceHelper { ($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) { $other = new PlayerDonation(); $other->InsertPlayerDonation($entry, $corpId, $division); + } else if($entry['ref_type'] == 'industry_facility_tax' && $entry['second_party_id'] == 98287666) { + $industry = new StructureIndustryTax(); + $industry->InsertStructureIndustryTax($entry, $corpId, $division); } } diff --git a/app/Library/Finances/StructureIndustryTax.php b/app/Library/Finances/StructureIndustryTax.php new file mode 100644 index 000000000..35b0c3a22 --- /dev/null +++ b/app/Library/Finances/StructureIndustryTax.php @@ -0,0 +1,64 @@ + $journal['id']])->exists()) { + $entry = new CorpMarketJournal; + $entry->id = $journal['id']; + $entry->corporation_id = $corpId; + $entry->division = $division; + if(isset($journal['amount'])) { + $entry->amount = $journal['amount']; + } + if(isset($journal['balance'])) { + $entry->balance = $journal['balance']; + } + if(isset($journal['context_id'])) { + $entry->context_id = $journal['context_id']; + } + if(isset($journal['context_id_type'])) { + $entry->context_id_type = $journal['context_id_type']; + } + $entry->date = $esiHelper->DecodeDate($journal['date']); + $entry->description = $journal['description']; + if(isset($journal['first_party_id'])) { + $entry->first_party_id = $journal['first_party_id']; + } + if(isset($journal['reason'])) { + $entry->reason = $journal['reason']; + } + $entry->ref_type = $journal['ref_type']; + if(isset($journal['second_party_id'])) { + $entry->second_party_id = $journal['second_party_id']; + } + if(isset($journal['tax'])) { + $entry->tax = $journal['tax']; + } + if(isset($journal['tax_receiver_id'])) { + $entry->tax_receiver_id = $journal['tax_receiver_id']; + } + $entry->save(); + } + } +} + +?> \ No newline at end of file diff --git a/app/Library/Structures/StructureTaxHelper.php b/app/Library/Structures/StructureTaxHelper.php index d3507b513..7cc63cef4 100644 --- a/app/Library/Structures/StructureTaxHelper.php +++ b/app/Library/Structures/StructureTaxHelper.php @@ -12,6 +12,7 @@ use App\Models\User\UserPermission; use App\Models\Corporation\CorpStructure; use App\Models\Finances\CorpMarketJournal; use App\Models\Finances\ReprocessingTaxJournal; +use App\Models\Finances\StructureIndustryTaxJournal; class StructureTaxHelper { private $corpId; @@ -62,6 +63,16 @@ class StructureTaxHelper { return $taxOwed; } + public function GetIndustryRevenue($start, $end) { + $revenue = 0.00; + + $revenue = StructureIndustryTaxJournal::where(['ref_type' => 'facility_industry_tax', 'second_party_id' => '98287666']) + ->whereBetween('date', [$start, $end]) + ->sum('amount'); + + return $revenue; + } + public function GetRevenue($corpId, $refType, $start, $end) { $revenue = 0.00; if($refType == 'Market') { diff --git a/app/Models/Finances/StructureIndustryTaxJournal.php b/app/Models/Finances/StructureIndustryTaxJournal.php new file mode 100644 index 000000000..b63247837 --- /dev/null +++ b/app/Models/Finances/StructureIndustryTaxJournal.php @@ -0,0 +1,41 @@ +string('id')->unique(); + $table->integer('corporation_id')->nullabe(); + $table->integer('division')->default(0); + $table->decimal('amount', 20, 2)->nullable(); + $table->decimal('balance', 20, 2)->nullable(); + $table->integer('context_id')->nullable(); + $table->string('context_id_type')->nullable(); + $table->dateTime('date')->nullabe(); + $table->string('description')->nullabe(); + $table->integer('first_party_id')->nullable(); + $table->string('reason')->default(' '); + $table->string('ref_type')->nullabe(); + $table->integer('second_party_id')->nullable(); + $table->decimal('tax', 20, 2)->default(0.00); + $table->integer('tax_receiver_id')->nullable(); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('structure_industry_tax'); + } +} diff --git a/resources/views/structures/industrytaxes.blade.php b/resources/views/structures/industrytaxes.blade.php new file mode 100644 index 000000000..9e27dc6ac --- /dev/null +++ b/resources/views/structures/industrytaxes.blade.php @@ -0,0 +1,30 @@ +@extends('layouts.b4') +@section('content') + +
| Month | +Structure | +Industry Taxes | + + + @for($i = 0; $i < $months; $i++) +
|---|---|---|
| {{ $totalTaxes[$i]['MonthStart'] }} | +{{ $totalTaxes[$i]['Structure'] }} | +{{ $totalTaxes[$i]['IndustryTaxes'] }} | +