financials

This commit is contained in:
2019-01-06 03:36:01 -06:00
parent 1026bf370a
commit 062939d2c8
16 changed files with 526 additions and 6 deletions

View File

@@ -10,11 +10,7 @@ use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
use App\Library\Esi\Esi;
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Corporation\Structure;
use App\Models\Corporation\CorpStructure;
use App\Models\ScheduledTask\ScheduleJob;
use Carbon\Carbon;

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
class holdingfinances extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:holdingjournal';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('HoldingFinances');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Setup the Finances container
$finance = new FinanceHelper();
$finance->GetHoldingWalletJournal(1);
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel
Commands\DumpFleets::class,
Commands\CalculateMarketTax::class,
//Commands\GetLogisticsContracts::class,
Commands\holdingfinances::class,
];
/**
@@ -45,6 +46,9 @@ class Kernel extends ConsoleKernel
$schedule->command('services:calculatemarkettax')
->monthlyOn(1, '08:00')
->withoutOverlapping();
$schedule->command('services:holdingjournal')
->hourly()
->withoutOverlapping();
}
/**

View File

@@ -8,6 +8,61 @@ class FinancesController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('role:Director');
}
$this->middleware('role:Admin');
}
public function displayFinances() {
$months = 1;
$income = 0.00;
$expenses = 0.00;
$corpId = 98287666;
$finances = array();
$total = array();
$sHelper = new StructureTaxHelper();
$date = $sHelper->GetTimeFrameInMonths($months);
$revenue = [
'date' => $date['start']->toFormattedDateString(),
'industry' => StructureIndustryTaxJournal::select('amount')->whereBetween('date', [$date['start'], $date['end']])->sum('amount'),
'reprocessing' => $sHelper->GetRevenue($corpId, 'Refinery', $date['start'], $date['end']),
'offices' => OfficeFeesJournal::select('amount')->whereBetween('date', [$date['start'], $date['end']])->sum('amount'),
'market' => $sHelper->GetRevenue($corpId, 'Market', $date['start'], $date['end']),
'rentals' => 9500000000000,
'pi' => PlanetProductionTaxJournal::select('amount')->whereBetween('date', [$date['start'], $date['end']])->sum('amount'),
];
$expenditures = [
'fuel' => 9187200000,
'sov' => 8666870000,
'srp' => 1000000000,
];
$income = $revenue['industry'] + $revenue['reprocessing'] + $revenue['offices'] + $revenue['market'] + $revenue['rentals'] + $revenue['pi'];
$expenses = $expenditures['fuel'] + $expenditures['sov'] + $expenditures['srp'];
$total[] = [
'income' => $income,
'expenses' => $expenses,
];
$chart = app()->chartjs
->name('Income & Expenditure Chart')
->type('pie')
->size(['width' => 400, 'height' => 200])
->labels(['Income', 'Expenses'])
->datasets([
[
'backgroundColor' => ['#FF6384', '#36A2EB'],
'hoverBackgroundColor' => ['#FF6384', '#36A2EB'],
'data' => [$total['income'], $total['expenses']]
]
])
->options([]);
return view('finances.holding')->with('chart', $chart);
}
}

View File

@@ -141,6 +141,84 @@ class FinanceHelper {
}
}
public function GetHoldingWalletJournal($division) {
//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']);
$corpId = 98287666;
//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);
$esi->setVersion('v4');
//Set our current page to 1 which is the one we are starting on.
$currentPage = 1;
//Set our default total pages to 1 in case our try section fails out.
$totalPages = 1;
//If more than one page is found, decode the first set of wallet entries, then call for the next pages
do {
//Call the first page of the wallet journal, as we are always going to get at least one page.
//If we have more pages, then we will continue through the while loop.
try {
$journals = $esi->page($currentPage)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
'corporation_id' => $corpId,
'division' => $division,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
//Set the total pages we need to cycle through.
$totalPages = $journals->pages;
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//For each journal entry, attempt to store it in the database.
//The PutWalletJournal function checks to see if it's already in the database.
foreach($wallet as $entry) {
if($entry['amount'] > 0) {
if($entry['ref_type'] == 'brokers_fee') {
$market = new MarketTax();
$market->InsertMarketTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'reprocessing_tax') {
$reprocessing = new ReprocessingTax();
$reprocessing->InsertReprocessingTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'structure_gate_jump') {
$jb = new JumpBridgeTax();
$jb->InsertJumpBridgeTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'player_donation' ||
$entry['ref_type'] == 'corporation_account_withdrawal') {
$other = new PlayerDonation();
$other->InsertPlayerDonation($entry, $corpId, $division);
} else if($entry['ref_type'] == 'industry_job_tax') {
$industry = new StructureIndustryTax();
$industry->InsertStructureIndustryTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'planetary_import_tax' || $entry['ref_type'] == 'planetary_export_tax') {
$pi = new PlanetaryProductionTax();
$pi->InsertPlanetaryProductionTax($entry, $corpId, $division);
} else if($entry['ref_type'] == 'office_rental_fee') {
$office = new OfficeFee();
$office->InsertOfficeFee($entry, $corpId, $division);
}
}
}
//Increment the current page we are on.
$currentPage++;
//Continue looping through the do while loop until the current page is greater than or equal to the total pages.
} while ($currentPage < $totalPages);
}
}
?>

View File

@@ -0,0 +1,64 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Finances;
use DB;
use App\Library\Esi\Esi;
use App\Models\Finances\OfficeFeesJournal;
class OfficeFee {
public function InsertOfficeFee($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(!OfficeFeesJournal::where(['id' => $journal['id']])->exists()) {
$entry = new OfficeFeesJournal;
$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

@@ -0,0 +1,64 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Finances;
use DB;
use App\Library\Esi\Esi;
use App\Models\Finances\PlanetProductionTaxJournal;
class OfficeFee {
public function InsertOfficeFee($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(!PlanetProductionTaxJournal::where(['id' => $journal['id']])->exists()) {
$entry = new PlanetProductionTaxJournal;
$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

@@ -166,6 +166,15 @@ class StructureTaxHelper {
$end->minute = 59;
$end->second = 59;
if($months == 1) {
$dates = [
'start' => $start,
'end' => $end,
];
return $dates;
}
//Create an array of dates
for($i = 0; $i < $months; $i++) {
if($i == 0) {

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models\Finances;
use Illuminate\Database\Eloquent\Model;
class OfficeFeesJournal extends Model
{
/**
* Table Name
*/
protected $table = 'office_fees_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,41 @@
<?php
namespace App\Models\Finances;
use Illuminate\Database\Eloquent\Model;
class PlanetProductionTaxJournal extends Model
{
/**
* Table Name
*/
protected $table = 'planet_production_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,48 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePlanetProductionTaxJournal extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('planet_production_tax_journal')) {
Schema::create('planet_production_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('planet_production_tax_journal');
}
}

View File

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

View File

@@ -0,0 +1,4 @@
@extends('layouts.b4')
@section('contents')
{!! $chart->render() !!}
@endsection

View File

@@ -82,6 +82,9 @@ Route::group(['middleware' => ['auth']], function(){
Route::get('/helpdesk/tickets/edit', 'HelpDeskController@editTicket');
Route::get('/helpdesk/tickets/new', 'HelpDeskController@displayNewTicket');
Route::post('/helpdesk/tickets/new', 'HelpDeskController@storeTicket');
//Finances Controller display pages
Route::get('/finances/admin', 'FinancesController@displayFinances');
});
//Login display pages

View File

@@ -13,6 +13,7 @@ return array(
'App\\Console\\Commands\\GetLogisticsContracts' => $baseDir . '/app/Console/Commands/GetLogisticContracts.php',
'App\\Console\\Commands\\SendMail' => $baseDir . '/app/Console/Commands/sendmail.php',
'App\\Console\\Commands\\UpdateMoonPricing' => $baseDir . '/app/Console/Commands/UpdateMoonPricing.php',
'App\\Console\\Commands\\holdingfinances' => $baseDir . '/app/Console/Commands/holdingfinances.php',
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\HelpDeskTicket' => $baseDir . '/app/Models/HelpDesk/HelpDeskTicket.php',
@@ -56,6 +57,7 @@ return array(
'App\\Library\\Finances\\MarketTax' => $baseDir . '/app/Library/Finances/MarketTax.php',
'App\\Library\\Finances\\PlayerDonation' => $baseDir . '/app/Library/Finances/PlayerDonation.php',
'App\\Library\\Finances\\ReprocessingTax' => $baseDir . '/app/Library/Finances/ReprocessingTax.php',
'App\\Library\\Finances\\StructureIndustryTax' => $baseDir . '/app/Library/Finances/StructureIndustryTax.php',
'App\\Library\\Fleets\\FleetHelper' => $baseDir . '/app/Library/Fleets/FleetHelper.php',
'App\\Library\\Lookups\\LookupHelper' => $baseDir . '/app/Library/Lookups/LookupHelper.php',
'App\\Library\\Moons\\MoonCalc' => $baseDir . '/app/Library/Moons/MoonCalc.php',
@@ -79,6 +81,7 @@ return array(
'App\\Models\\Finances\\JumpBridgeJournal' => $baseDir . '/app/Models/Finances/JumpBridgeJournal.php',
'App\\Models\\Finances\\PlayerDonationJournal' => $baseDir . '/app/Models/Finances/PlayerDonationJournal.php',
'App\\Models\\Finances\\ReprocessingTaxJournal' => $baseDir . '/app/Models/Finances/ReprocessingTaxJournal.php',
'App\\Models\\Finances\\StructureIndustryTaxJournal' => $baseDir . '/app/Models/Finances/StructureIndustryTaxJournal.php',
'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',
@@ -94,6 +97,8 @@ return array(
'App\\Models\\User\\UserPermission' => $baseDir . '/app/Models/User/UserPermission.php',
'App\\Models\\User\\UserRole' => $baseDir . '/app/Models/User/UserRole.php',
'App\\Models\\User\\UserToCorporation' => $baseDir . '/app/Models/User/UserToCorporation.php',
'App\\OfficeFeesJournal' => $baseDir . '/app/OfficeFeesJournal.php',
'App\\PlanetProductionTaxJournal' => $baseDir . '/app/PlanetProductionTaxJournal.php',
'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php',
'App\\Providers\\AuthServiceProvider' => $baseDir . '/app/Providers/AuthServiceProvider.php',
'App\\Providers\\BroadcastServiceProvider' => $baseDir . '/app/Providers/BroadcastServiceProvider.php',

View File

@@ -467,6 +467,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Console\\Commands\\GetLogisticsContracts' => __DIR__ . '/../..' . '/app/Console/Commands/GetLogisticContracts.php',
'App\\Console\\Commands\\SendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php',
'App\\Console\\Commands\\UpdateMoonPricing' => __DIR__ . '/../..' . '/app/Console/Commands/UpdateMoonPricing.php',
'App\\Console\\Commands\\holdingfinances' => __DIR__ . '/../..' . '/app/Console/Commands/holdingfinances.php',
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\HelpDeskTicket' => __DIR__ . '/../..' . '/app/Models/HelpDesk/HelpDeskTicket.php',
@@ -510,6 +511,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Library\\Finances\\MarketTax' => __DIR__ . '/../..' . '/app/Library/Finances/MarketTax.php',
'App\\Library\\Finances\\PlayerDonation' => __DIR__ . '/../..' . '/app/Library/Finances/PlayerDonation.php',
'App\\Library\\Finances\\ReprocessingTax' => __DIR__ . '/../..' . '/app/Library/Finances/ReprocessingTax.php',
'App\\Library\\Finances\\StructureIndustryTax' => __DIR__ . '/../..' . '/app/Library/Finances/StructureIndustryTax.php',
'App\\Library\\Fleets\\FleetHelper' => __DIR__ . '/../..' . '/app/Library/Fleets/FleetHelper.php',
'App\\Library\\Lookups\\LookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/LookupHelper.php',
'App\\Library\\Moons\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/Moons/MoonCalc.php',
@@ -533,6 +535,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Models\\Finances\\JumpBridgeJournal' => __DIR__ . '/../..' . '/app/Models/Finances/JumpBridgeJournal.php',
'App\\Models\\Finances\\PlayerDonationJournal' => __DIR__ . '/../..' . '/app/Models/Finances/PlayerDonationJournal.php',
'App\\Models\\Finances\\ReprocessingTaxJournal' => __DIR__ . '/../..' . '/app/Models/Finances/ReprocessingTaxJournal.php',
'App\\Models\\Finances\\StructureIndustryTaxJournal' => __DIR__ . '/../..' . '/app/Models/Finances/StructureIndustryTaxJournal.php',
'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',
@@ -548,6 +551,8 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Models\\User\\UserPermission' => __DIR__ . '/../..' . '/app/Models/User/UserPermission.php',
'App\\Models\\User\\UserRole' => __DIR__ . '/../..' . '/app/Models/User/UserRole.php',
'App\\Models\\User\\UserToCorporation' => __DIR__ . '/../..' . '/app/Models/User/UserToCorporation.php',
'App\\OfficeFeesJournal' => __DIR__ . '/../..' . '/app/OfficeFeesJournal.php',
'App\\PlanetProductionTaxJournal' => __DIR__ . '/../..' . '/app/PlanetProductionTaxJournal.php',
'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php',
'App\\Providers\\AuthServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AuthServiceProvider.php',
'App\\Providers\\BroadcastServiceProvider' => __DIR__ . '/../..' . '/app/Providers/BroadcastServiceProvider.php',