diff --git a/app/Http/Controllers/FinancesController.php b/app/Http/Controllers/FinancesController.php index b94d0d2d0..b8d1b3de2 100644 --- a/app/Http/Controllers/FinancesController.php +++ b/app/Http/Controllers/FinancesController.php @@ -4,10 +4,16 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use DB; use Socialite; use Auth; + use App\User; use App\Libary\Finances; +use App\Library\Esi; +use App\Models\CorpJournal; + +use Carbon\Carbon; use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Configuration; @@ -18,20 +24,33 @@ class FinancesController extends Controller { public function __construct() { $this->middleware('auth'); - $this->middleware('role:Admin'); + $this->middleware('role:Director'); } public function displayWallet() { - $esi = new \App\Library\Finances(); - - //Get the Journal Entries and just return them - $journals = $esi->GetMasterWalletJournal(); - $journals = json_decode($journals->raw, true); - dd($journals); - return $journals; + // } public function displayTaxes() { - + //Make the helper esi class + $helper = new Esi(); + //Set the carbon date for the first day of the month + $start = Carbon::now()->startOfMonth(); + $end = Carbon::now()->endOfMonth(); + $totalTax = 0.00; + //Get the character's corporation from esi + $corporation = $helper->FindCorporationName(Auth::user()->character_id); + $corpId = $helper->FindCorporationId(Auth::user()->character_id); + //Get the taxes for the corporation + $taxes = DB::table('CorpJournals') + ->where(['corporation_id'=> $corpId, 'ref_type' => 46]) + ->whereBetween($start, $end) + ->get(); + foreach($taxes as $tax) { + $totalTax += $tax->amount; + } + + return view('finances.taxes')->with('totalTax', $totalTax); + } } diff --git a/app/Library/Esi.php b/app/Library/Esi.php index 9afcfeb4e..9b428acfb 100644 --- a/app/Library/Esi.php +++ b/app/Library/Esi.php @@ -57,6 +57,15 @@ class Esi { return $character['character']; } + public function FindCorporationName($charId) { + $esi = new Eseye(); + $character = $esi->invoke('get', '/characters/{character_id}/', [ + 'character_id' => $charId, + ]); + + return $character->corporation_name; + } + } ?> \ No newline at end of file diff --git a/app/Library/Finances.php b/app/Library/Finances.php index 487f6f7c9..ad15ddd77 100644 --- a/app/Library/Finances.php +++ b/app/Library/Finances.php @@ -24,6 +24,10 @@ use Seat\Eseye\Eseye; class Finances { + public function CalculateAverageFuelBlock() { + + } + public function CalculateMonthlyRefineryTaxees($corpId, $month, $overallTax) { $currentTime = Carbon::now(); $monthWanted = $month; @@ -96,7 +100,9 @@ class Finances { $journals = json_decode($journal->raw, true); //For each journal array, attempt to store in the database foreach($journals as $entry) { - $this->PutWalletJournal($entry, $corpId, $divison); + if($entry['ref_type'] == 46 || $entry['ref_type'] == 127) { + $this->PutWalletJournal($entry, $corpId, $divison); + } } } diff --git a/resources/views/finances/taxes.blade.php b/resources/views/finances/taxes.blade.php new file mode 100644 index 000000000..7cf47edd1 --- /dev/null +++ b/resources/views/finances/taxes.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.b4') +@section('content') + +@endsection \ No newline at end of file