financials
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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) {
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user