added new structure controller function

This commit is contained in:
2019-01-05 04:28:57 -06:00
parent e022d2881a
commit 1c9efc5e01
9 changed files with 268 additions and 6 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Finances;
use DB;
use App\Library\Esi;
use App\Models\Finances\StructureIndustryTaxJournal;
class StructureIndustryTax {
public function InsertStructureIndustryTax($journal, $corpId, $division) {
//Create the ESI Helper class
$esiHelper = new Esi;
//Check to see if we can find the entry in the database already.
//If we don't then add it to the database
if(!CorpMarketJournal::where(['id' => $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();
}
}
}
?>

View File

@@ -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') {

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models\Finances;
use Illuminate\Database\Eloquent\Model;
class StructureIndustryTaxJournal extends Model
{
/**
* Table Name
*/
protected $table = 'structure_industry_tax_journal';
/**
* Timestamps
*/
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'id',
'corporation_id',
'division',
'amount',
'balance',
'context_id',
'context_id_type',
'date',
'description',
'first_party_id',
'reason',
'ref_type',
'second_party_id',
'tax',
'tax_receiver_id',
];
}

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStructureIndustryTaxTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('structure_industry_tax_journal')) {
Schema::create('structure_industry_tax_journal', function(Blueprint $table) {
$table->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');
}
}

View File

@@ -0,0 +1,30 @@
@extends('layouts.b4')
@section('content')
<div class="container">
<div class="card">
<div class="card-header">
Structure Industry Taxes
</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<th>Month</th>
<th>Structure</th>
<th>Industry Taxes</th>
</thead>
<tbody>
@for($i = 0; $i < $months; $i++)
<tr>
<td>{{ $totalTaxes[$i]['MonthStart'] }}</td>
<td>{{ $totalTaxes[$i]['Structure'] }}</td>
<td>{{ $totalTaxes[$i]['IndustryTaxes'] }}</td>
</tr>
@endfor
</tbody>
</table>
</div>
</div>
</div>
@endsection

View File

@@ -18,7 +18,6 @@ return array(
'App\\HelpDeskTicket' => $baseDir . '/app/Models/HelpDesk/HelpDeskTicket.php',
'App\\HelpDeskTicketResponse' => $baseDir . '/app/Models/HelpDesk/HelpDeskTicketResponse.php',
'App\\Http\\Controllers\\AdminController' => $baseDir . '/app/Http/Controllers/AdminController.php',
'App\\Http\\Controllers\\AjaxController' => $baseDir . '/app/Http/Controllers/AjaxController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => $baseDir . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => $baseDir . '/app/Http/Controllers/Auth/RegisterController.php',
@@ -62,11 +61,11 @@ return array(
'App\\Library\\Moons\\MoonCalc' => $baseDir . '/app/Library/Moons/MoonCalc.php',
'App\\Library\\Moons\\MoonMine' => $baseDir . '/app/Library/Moons/MoonMine.php',
'App\\Library\\SeatHelper' => $baseDir . '/app/Library/SeatHelper.php',
'App\\Library\\Structures\\JumpBridgeFuel' => $baseDir . '/app/Library/Structures/JumpBridgeFuel.php',
'App\\Library\\Structures\\StructureTaxHelper' => $baseDir . '/app/Library/Structures/StructureTaxHelper.php',
'App\\Models\\Character\\CharacterToCorporation' => $baseDir . '/app/Models/Charcter/CharacterToCorporation.php',
'App\\Models\\Config' => $baseDir . '/app/Models/Config.php',
'App\\Models\\Corporation\\AllianceCorp' => $baseDir . '/app/Models/Corporation/AllianceCorp.php',
'App\\Models\\Corporation\\CorpJournal' => $baseDir . '/app/Models/Corporation/CorpJournal.php',
'App\\Models\\Corporation\\CorpStructure' => $baseDir . '/app/Models/Corporation/CorpStructure.php',
'App\\Models\\Corporation\\CorporationToAlliance' => $baseDir . '/app/Models/Corporation/CorporationToAlliance.php',
'App\\Models\\Corporation\\HoldingCorpJournal' => $baseDir . '/app/Models/Corporation/HoldingCorpJournal.php',
@@ -76,7 +75,6 @@ return array(
'App\\Models\\Doku\\DokuUser' => $baseDir . '/app/Models/Doku/DokuUser.php',
'App\\Models\\Esi\\EsiScope' => $baseDir . '/app/Models/Esi/EsiScope.php',
'App\\Models\\Esi\\EsiToken' => $baseDir . '/app/Models/Esi/EsiToken.php',
'App\\Models\\EveMail' => $baseDir . '/app/Models/EveMail.php',
'App\\Models\\Finances\\CorpMarketJournal' => $baseDir . '/app/Models/Finances/CorpMarketJournal.php',
'App\\Models\\Finances\\JumpBridgeJournal' => $baseDir . '/app/Models/Finances/JumpBridgeJournal.php',
'App\\Models\\Finances\\PlayerDonationJournal' => $baseDir . '/app/Models/Finances/PlayerDonationJournal.php',
@@ -84,6 +82,7 @@ return array(
'App\\Models\\Fleet\\Fleet' => $baseDir . '/app/Models/Fleet/Fleet.php',
'App\\Models\\Fleet\\FleetActivity' => $baseDir . '/app/Models/Fleet/FleetActivity.php',
'App\\Models\\Logistics\\Contract' => $baseDir . '/app/Models/Logistics/Contract.php',
'App\\Models\\Mail\\EveMail' => $baseDir . '/app/Models/Mail/EveMail.php',
'App\\Models\\Market\\MarketOrder' => $baseDir . '/app/Models/Market/MarketOrder.php',
'App\\Models\\Market\\MonthlyMarketTax' => $baseDir . '/app/Models/Market/MonthlyMarketTax.php',
'App\\Models\\Moon\\ItemComposition' => $baseDir . '/app/Models/Moon/ItemComposition.php',

View File

@@ -472,7 +472,6 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\HelpDeskTicket' => __DIR__ . '/../..' . '/app/Models/HelpDesk/HelpDeskTicket.php',
'App\\HelpDeskTicketResponse' => __DIR__ . '/../..' . '/app/Models/HelpDesk/HelpDeskTicketResponse.php',
'App\\Http\\Controllers\\AdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/AdminController.php',
'App\\Http\\Controllers\\AjaxController' => __DIR__ . '/../..' . '/app/Http/Controllers/AjaxController.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
'App\\Http\\Controllers\\Auth\\LoginController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/LoginController.php',
'App\\Http\\Controllers\\Auth\\RegisterController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/RegisterController.php',
@@ -516,11 +515,11 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Library\\Moons\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/Moons/MoonCalc.php',
'App\\Library\\Moons\\MoonMine' => __DIR__ . '/../..' . '/app/Library/Moons/MoonMine.php',
'App\\Library\\SeatHelper' => __DIR__ . '/../..' . '/app/Library/SeatHelper.php',
'App\\Library\\Structures\\JumpBridgeFuel' => __DIR__ . '/../..' . '/app/Library/Structures/JumpBridgeFuel.php',
'App\\Library\\Structures\\StructureTaxHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureTaxHelper.php',
'App\\Models\\Character\\CharacterToCorporation' => __DIR__ . '/../..' . '/app/Models/Charcter/CharacterToCorporation.php',
'App\\Models\\Config' => __DIR__ . '/../..' . '/app/Models/Config.php',
'App\\Models\\Corporation\\AllianceCorp' => __DIR__ . '/../..' . '/app/Models/Corporation/AllianceCorp.php',
'App\\Models\\Corporation\\CorpJournal' => __DIR__ . '/../..' . '/app/Models/Corporation/CorpJournal.php',
'App\\Models\\Corporation\\CorpStructure' => __DIR__ . '/../..' . '/app/Models/Corporation/CorpStructure.php',
'App\\Models\\Corporation\\CorporationToAlliance' => __DIR__ . '/../..' . '/app/Models/Corporation/CorporationToAlliance.php',
'App\\Models\\Corporation\\HoldingCorpJournal' => __DIR__ . '/../..' . '/app/Models/Corporation/HoldingCorpJournal.php',
@@ -530,7 +529,6 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Models\\Doku\\DokuUser' => __DIR__ . '/../..' . '/app/Models/Doku/DokuUser.php',
'App\\Models\\Esi\\EsiScope' => __DIR__ . '/../..' . '/app/Models/Esi/EsiScope.php',
'App\\Models\\Esi\\EsiToken' => __DIR__ . '/../..' . '/app/Models/Esi/EsiToken.php',
'App\\Models\\EveMail' => __DIR__ . '/../..' . '/app/Models/EveMail.php',
'App\\Models\\Finances\\CorpMarketJournal' => __DIR__ . '/../..' . '/app/Models/Finances/CorpMarketJournal.php',
'App\\Models\\Finances\\JumpBridgeJournal' => __DIR__ . '/../..' . '/app/Models/Finances/JumpBridgeJournal.php',
'App\\Models\\Finances\\PlayerDonationJournal' => __DIR__ . '/../..' . '/app/Models/Finances/PlayerDonationJournal.php',
@@ -538,6 +536,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Models\\Fleet\\Fleet' => __DIR__ . '/../..' . '/app/Models/Fleet/Fleet.php',
'App\\Models\\Fleet\\FleetActivity' => __DIR__ . '/../..' . '/app/Models/Fleet/FleetActivity.php',
'App\\Models\\Logistics\\Contract' => __DIR__ . '/../..' . '/app/Models/Logistics/Contract.php',
'App\\Models\\Mail\\EveMail' => __DIR__ . '/../..' . '/app/Models/Mail/EveMail.php',
'App\\Models\\Market\\MarketOrder' => __DIR__ . '/../..' . '/app/Models/Market/MarketOrder.php',
'App\\Models\\Market\\MonthlyMarketTax' => __DIR__ . '/../..' . '/app/Models/Market/MonthlyMarketTax.php',
'App\\Models\\Moon\\ItemComposition' => __DIR__ . '/../..' . '/app/Models/Moon/ItemComposition.php',