diff --git a/app/Console/Commands/corpJournal.php b/app/Console/Commands/corpJournal.php index 60f217691..5043999c5 100644 --- a/app/Console/Commands/corpJournal.php +++ b/app/Console/Commands/corpJournal.php @@ -41,12 +41,14 @@ class corpJournal extends Command */ public function handle() { + //Setup the Finances Container + $finance = new Finances(); //Get the characters that have the esi-wallet.read_corporation_wallets.v1 //esi wallet scope $characters = DB::table('EsiScopes')->where('scopes', 'esi-wallet.read_corporation_wallets.v1')->get(); - - foreach($characters as $char) { + foreach($characters as $char) { + $finance->GetWalletJournal(1, $characters->character_id); } } } diff --git a/app/Console/Commands/sendmail.php b/app/Console/Commands/sendmail.php index 4a6679de7..aca327796 100644 --- a/app/Console/Commands/sendmail.php +++ b/app/Console/Commands/sendmail.php @@ -4,6 +4,8 @@ namespace App\Console\Commands; use Illuminate\Console\Command; +use App\Library\Finances; + class sendMail extends Command { /** @@ -32,6 +34,9 @@ class sendMail extends Command /** * Execute the console command. + * Gather the taxes needed and add them together. + * Send a mail to the character owning the ESI scope with the taxes + * owed to the holding corp * * @return mixed */ diff --git a/app/Http/Controllers/RegisterStructure.php b/app/Http/Controllers/RegisterStructure.php new file mode 100644 index 000000000..68a6b9aff --- /dev/null +++ b/app/Http/Controllers/RegisterStructure.php @@ -0,0 +1,45 @@ +middleware('auth'); + $this->middleware('role:Director'); + } + + public function displayRegisterStructure() { + return view('structures.register'); + } + + public function storeStructure(Request $request) { + $this->validate($request, [ + 'corporation_id' => 'required', + 'corporation_name' => 'required', + 'system' => 'required', + 'structure_name' => 'required', + 'tax' => 'required', + 'structure_type' => 'required', + ]); + + $structure = new CorpStructure(); + $structure->corporation_id = $request->corporation_id; + $structure->corporation_name = $request->corporation_name; + $structure->region = $request->region; + $structure->system = $request->system; + $structure->structure_name = $request->structure_name; + $structure->tax = $request->tax; + $structure->structure_type = $request->structure_type; + $structure->save(); + + //Return the view and the message of user updated + return redirect('/dashboard')->with('success', 'Structure Added to Database'); + } +} diff --git a/app/Http/Middleware/RequireRole.php b/app/Http/Middleware/RequireRole.php index b01bea425..7693c7a1e 100644 --- a/app/Http/Middleware/RequireRole.php +++ b/app/Http/Middleware/RequireRole.php @@ -22,7 +22,8 @@ class RequireRole 'None' => 0, 'Guest' => 1, 'User' => 2, - 'Admin' => 3, + 'Director' => 3, + 'Admin' => 4, ]; $check = DB::table('user_roles')->where('character_id', auth()->user()->character_id)->get(['role']); diff --git a/app/Library/Finances.php b/app/Library/Finances.php index 88a15569d..487f6f7c9 100644 --- a/app/Library/Finances.php +++ b/app/Library/Finances.php @@ -24,49 +24,6 @@ use Seat\Eseye\Eseye; class Finances { - public function PutWalletJournal($journal, $corpId, $division) { - $check = DB::table('CorpJournal')->where('id', $journal['id'])->get(); - //if we don't find the journal entry, add the journal entry to the database - if($check == null) { - $entry = new CorpJournal; - $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 = $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(); - } - - } - public function CalculateMonthlyRefineryTaxees($corpId, $month, $overallTax) { $currentTime = Carbon::now(); $monthWanted = $month; @@ -101,37 +58,6 @@ class Finances { return $taxed; } - public function SendMail($charId, $taxAmount, $subject) { - //Retrieve the token for Amund Risalo - $token = DB::table('EsiTokens')->where('character_id', 93738489)->get(); - $configuration = Configuration::getInstance(); - $configuration->cache = NullCache::class; - $configuration->logfile_location = '/var/www/w4rpservices/storage/logs/eseye'; - //Create the 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 variable - $esi = new Eseye($authentication); - try { - $esi->setBody([ - 'body' => $body, - 'receipients' => [ - 'recipient_id'=> $charId, - 'recipient_type' => 'character', - ], - 'subject' => $subject, - ])->invoke('post', '/characters/{character_id}/mail/', [ - 'character_id' => 93738489, - ]); - } catch(\Seat\Eseye\Exceptions\RequestFailedException $e) { - return $e->getEsiResponse(); - } - } - public function GetWalletJournal($division, $charId) { //Get the ESI token for the corporation to add new wallet journals into the database $token = DB::table('EsiTokens')->where('character_id', $charId)->get(); @@ -174,6 +100,49 @@ class Finances { } } + private function PutWalletJournal($journal, $corpId, $division) { + $check = DB::table('CorpJournal')->where('id', $journal['id'])->get(); + //if we don't find the journal entry, add the journal entry to the database + if($check == null) { + $entry = new CorpJournal; + $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 = $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/Mail.php b/app/Library/Mail.php index 6b04cb108..5455e2fbb 100644 --- a/app/Library/Mail.php +++ b/app/Library/Mail.php @@ -2,8 +2,48 @@ namespace App\Library; +use DB; + +use App\Models\EsiScope; +use App\Models\Esitoken; + +use Seat\Eseye\Cache\NullCache; +use Seat\Eseye\Configuration; +use Seat\Eseye\Containers\EsiAuthentication; +use Seat\Eseye\Eseye; + class Mail { - + + public function SendMail($charId, $taxAmount, $subject) { + //Retrieve the token for Amund Risalo + $token = DB::table('EsiTokens')->where('character_id', 93738489)->get(); + $configuration = Configuration::getInstance(); + $configuration->cache = NullCache::class; + $configuration->logfile_location = '/var/www/w4rpservices/storage/logs/eseye'; + //Create the 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 variable + $esi = new Eseye($authentication); + try { + $esi->setBody([ + 'body' => $body, + 'receipients' => [ + 'recipient_id'=> $charId, + 'recipient_type' => 'character', + ], + 'subject' => $subject, + ])->invoke('post', '/characters/{character_id}/mail/', [ + 'character_id' => 93738489, + ]); + } catch(\Seat\Eseye\Exceptions\RequestFailedException $e) { + return $e->getEsiResponse(); + } + } } ?> \ No newline at end of file diff --git a/app/Models/AllianceCorp.php b/app/Models/AllianceCorp.php index 3c02c2f11..34e24887a 100644 --- a/app/Models/AllianceCorp.php +++ b/app/Models/AllianceCorp.php @@ -1,6 +1,6 @@ define('isDirector', function($user) { + $check = DB::table('user_roles')->where('character_id', auth()->user()->character_id)->get(['role']); + if($check[0]->role === 'Director') { + return true; + } else { + return false; + } + }); + $gate->define('isUser', function($user) { $check = DB::table('user_roles')->where('character_id', auth()->user()->character_id)->get(['role']); if($check[0]->role === 'User') { diff --git a/database/migrations/2018_11_19_053751_create_corp_structures.php b/database/migrations/2018_11_19_053751_create_corp_structures.php new file mode 100644 index 000000000..3ab44889f --- /dev/null +++ b/database/migrations/2018_11_19_053751_create_corp_structures.php @@ -0,0 +1,39 @@ +increments('id'); + $table->integer('corporation_id'); + $table->string('corporation_name'); + $table->string('region'); + $table->string('system'); + $table->string('structure_name'); + $table->decimal('tax', 10, 2); + $table->string('structure_type'); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('CorpStructures'); + } +} diff --git a/resources/views/structures/display.blade.php b/resources/views/structures/display.blade.php new file mode 100644 index 000000000..e69de29bb diff --git a/resources/views/structures/register.blade.php b/resources/views/structures/register.blade.php new file mode 100644 index 000000000..a235d45c3 --- /dev/null +++ b/resources/views/structures/register.blade.php @@ -0,0 +1,25 @@ +@extends('layouts.b4') +@section('content') +
+

Register Structure

+ {!! Form::open(['action' => 'RegisterStructureController@storeStructure', 'method' => 'POST']) !!} +
+ {{ Form::label('corporation_id', 'Corporation ID')}} + {{ Form::text('corporation_id', '', ['class' => 'form-control']) }} + {{ Form::label('corporation_name', 'Corporation Name') }} + {{ Form::text('corporation_name', '', ['class' => 'form-control']) }} + {{ Form::label('region', 'Region') }} + {{ Form::text('region', '', ['class' => 'form-control']) }} + {{ Form::label('system', 'System') }} + {{ Form::text('system', '', ['class' => 'form-control']) }} + {{ Form::label('structure_name', 'Structure Name') }} + {{ Form::text('structure_name', '', ['class' => 'form-control']) }} + {{ Form::label('tax', 'Tax') }} + {{ Form::number('tax', '', ['class' => 'form-control']) }} + {{ Form::label('structure_type', 'Structure Type') }} + {{ Form::select('structure_type', ['Refinery' => 'Refinery', 'Citadel' => 'Citadel'], null, ['class' => 'form-control']) }} +
+ {{ Form::submit('Submit', ['class' => 'btn btn-primary']) }} + {!! Form::close() !!} +
+@endsection \ No newline at end of file diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 5df550276..06fcc489f 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -10,7 +10,6 @@ return array( 'App\\Console\\Commands\\getCorps' => $baseDir . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\sendMail' => $baseDir . '/app/Console/Commands/sendmail.php', 'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php', - 'App\\CorpJournal' => $baseDir . '/app/Models/CorpJournal.php', 'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php', 'App\\Http\\Controllers\\AdminController' => $baseDir . '/app/Http/Controllers/AdminController.php', 'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ForgotPasswordController.php', @@ -40,7 +39,9 @@ return array( 'App\\Library\\Mail' => $baseDir . '/app/Library/Mail.php', 'App\\Library\\MoonCalc' => $baseDir . '/app/Library/MoonCalc.php', 'App\\Library\\MoonMine' => $baseDir . '/app/Library/MoonMine.php', + 'App\\Models\\AllianceCorp' => $baseDir . '/app/Models/AllianceCorp.php', 'App\\Models\\Config' => $baseDir . '/app/Models/Config.php', + 'App\\Models\\CorpJournal' => $baseDir . '/app/Models/CorpJournal.php', 'App\\Models\\DokuGroupNames' => $baseDir . '/app/Models/DokuGroupNames.php', 'App\\Models\\DokuMember' => $baseDir . '/app/Models/DokuMember.php', 'App\\Models\\DokuUser' => $baseDir . '/app/Models/DokuUser.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 9ea40f4ae..8fbcdff0a 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -405,7 +405,6 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Console\\Commands\\getCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\sendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php', 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', - 'App\\CorpJournal' => __DIR__ . '/../..' . '/app/Models/CorpJournal.php', 'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php', 'App\\Http\\Controllers\\AdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/AdminController.php', 'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ForgotPasswordController.php', @@ -435,7 +434,9 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Library\\Mail' => __DIR__ . '/../..' . '/app/Library/Mail.php', 'App\\Library\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/MoonCalc.php', 'App\\Library\\MoonMine' => __DIR__ . '/../..' . '/app/Library/MoonMine.php', + 'App\\Models\\AllianceCorp' => __DIR__ . '/../..' . '/app/Models/AllianceCorp.php', 'App\\Models\\Config' => __DIR__ . '/../..' . '/app/Models/Config.php', + 'App\\Models\\CorpJournal' => __DIR__ . '/../..' . '/app/Models/CorpJournal.php', 'App\\Models\\DokuGroupNames' => __DIR__ . '/../..' . '/app/Models/DokuGroupNames.php', 'App\\Models\\DokuMember' => __DIR__ . '/../..' . '/app/Models/DokuMember.php', 'App\\Models\\DokuUser' => __DIR__ . '/../..' . '/app/Models/DokuUser.php',