Compare commits
1 Commits
v0.3
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7660b2aa67 |
22
.env
22
.env
@@ -2,7 +2,7 @@ APP_NAME='W4RP Services'
|
|||||||
APP_ENV=local
|
APP_ENV=local
|
||||||
APP_KEY=base64:PBOxrGFJAtwj9SDF4F0DZ1J+6MjrJmRiPZJQwRdy3XQ=
|
APP_KEY=base64:PBOxrGFJAtwj9SDF4F0DZ1J+6MjrJmRiPZJQwRdy3XQ=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=https://services.w4rp.space
|
APP_URL=http://localhost
|
||||||
|
|
||||||
LOG_CHANNEL=daily
|
LOG_CHANNEL=daily
|
||||||
|
|
||||||
@@ -11,15 +11,13 @@ DB_HOST=127.0.0.1
|
|||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_DATABASE=w4rpservices2
|
DB_DATABASE=w4rpservices2
|
||||||
DB_USERNAME=minerva
|
DB_USERNAME=minerva
|
||||||
DB_PASSWORD=FuckingShit12
|
DB_PASSWORD=strtmage
|
||||||
|
|
||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=redis
|
CACHE_DRIVER=file
|
||||||
CACHE_PREFIX=w4rpservices_cache
|
|
||||||
|
|
||||||
QUEUE_DRIVER=redis
|
QUEUE_DRIVER=redis
|
||||||
QUEUE_CONNECTION=redis
|
QUEUE_CONNECTION=sync
|
||||||
QUEUE_PREFIX=w4rpservices_queue
|
|
||||||
|
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
@@ -27,8 +25,6 @@ SESSION_LIFETIME=120
|
|||||||
REDIS_HOST=127.0.0.1
|
REDIS_HOST=127.0.0.1
|
||||||
REDIS_PASSWORD=null
|
REDIS_PASSWORD=null
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_DATABASE=0
|
|
||||||
REDIS_CACHE_DB=1
|
|
||||||
|
|
||||||
MAIL_DRIVER=smtp
|
MAIL_DRIVER=smtp
|
||||||
MAIL_HOST=smtp.mailtrap.io
|
MAIL_HOST=smtp.mailtrap.io
|
||||||
@@ -37,11 +33,13 @@ MAIL_USERNAME=null
|
|||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=null
|
MAIL_ENCRYPTION=null
|
||||||
|
|
||||||
ESI_CLIENT_ID=91a051aea72742068b51801042397c38
|
ESI_CLIENT_ID=e5848fea3618427a8ee0dccb6a04fc62
|
||||||
ESI_SECRET_KEY=1co6qRMoXyx1dG2iBbAZ1z6NUOoaJWyQnqEnsqoj
|
ESI_SECRET_KEY=TdnNGRM8RTNSifZdaIc9yHTTkYPgYEEXHRIbT6oY
|
||||||
ESI_USERAGENT='W4RP Services'
|
ESI_USERAGENT='W4RP Services'
|
||||||
ESI_CALLBACK_URI=https://services.w4rp.space/callback/
|
ESI_CALLBACK_URI='http://services.w4rp.space/callback'
|
||||||
ESI_PRIMARY_CHAR=93738489
|
ESI_PRIMARY_CHAR=93738489
|
||||||
ESI_ALLIANCE=99004116
|
ESI_ALLIANCE=99004116
|
||||||
|
|
||||||
HORIZON_PREFIX=w4rpservices_horizon
|
EVEONLINE_CLIENT_ID=e5848fea3618427a8ee0dccb6a04fc62
|
||||||
|
EVEONLINE_CLIENT_SECRET=TdnNGRM8RTNSifZdaIc9yHTTkYPgYEEXHRIbT6oY
|
||||||
|
EVEONLINE_REDIRECT='https://services.w4rp.space/callback'
|
||||||
|
|||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -5,7 +5,5 @@
|
|||||||
/public/logs/*
|
/public/logs/*
|
||||||
worker.log
|
worker.log
|
||||||
/public/cache/*
|
/public/cache/*
|
||||||
.env
|
/.env
|
||||||
.vscode
|
.vscode
|
||||||
/storage/logs
|
|
||||||
worker.log
|
|
||||||
103
app/Console/Commands/Assets/GetAssets.php
Normal file
103
app/Console/Commands/Assets/GetAssets.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use DB;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Job
|
||||||
|
use App\Jobs\ProcessAssetsJob;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
use App\Library\Assets\AssetHelper;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Jobs\JobProcessAsset;
|
||||||
|
|
||||||
|
class GetAssetsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:GetAssets';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Gets all of the assets of the holding corporation.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$assets = null;
|
||||||
|
$pages = 0;
|
||||||
|
|
||||||
|
//Create the command helper container
|
||||||
|
$task = new CommandHelper('GetAssets');
|
||||||
|
//Add the entry into the jobs table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Declare some variables
|
||||||
|
$charId = $config['primary'];
|
||||||
|
$corpId = 98287666;
|
||||||
|
|
||||||
|
//ESI Scope Check
|
||||||
|
$esiHelper = new Esi();
|
||||||
|
$assetScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-assets.read_corporation_assets.v1');
|
||||||
|
|
||||||
|
if($assetScope == false) {
|
||||||
|
Log::critical("Scope check for esi-assets.read_corporation_assets.v1 failed.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the refresh token from the database
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
//Create the authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$assets = $esi->page(1)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/assets/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
]);
|
||||||
|
} catch (RequestFailedException $e) {
|
||||||
|
Log::critical("Failed to get asset list.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pages = $assets->pages;
|
||||||
|
|
||||||
|
for($i = 1; $i <= $pages; $i++) {
|
||||||
|
$job = new JobProcessAsset;
|
||||||
|
$job->charId = $charId;
|
||||||
|
$job->corpId = $corpId;
|
||||||
|
$job->page = $i;
|
||||||
|
ProcessAssetsJob::dispatch($job)->onQueue('assets');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
89
app/Console/Commands/Corps/GetCorps.php
Normal file
89
app/Console/Commands/Corps/GetCorps.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Corporation\AllianceCorp;
|
||||||
|
use App\Models\ScheduledTask\ScheduleJob;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
class GetCorpsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:GetCorps';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get corporations in alliance and store in db.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('CorpJournal');
|
||||||
|
//Add the entry into the jobs table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
//Declare some variables
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
//try the esi call to get all of the corporations in the alliance
|
||||||
|
try {
|
||||||
|
$corporations = $esi->invoke('get', '/alliances/{alliance_id}/corporations/', [
|
||||||
|
'alliance_id' => 99004116,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e){
|
||||||
|
dd($e->getEsiResponse());
|
||||||
|
}
|
||||||
|
//Delete all of the entries in the AllianceCorps table
|
||||||
|
AllianceCorp::truncate();
|
||||||
|
|
||||||
|
//Foreach corporation, make entries into the database.
|
||||||
|
foreach($corporations as $corp) {
|
||||||
|
try {
|
||||||
|
$corpInfo = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||||
|
'corporation_id' => $corp,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return $e->getEsiResponse();
|
||||||
|
}
|
||||||
|
$entry = new AllianceCorp;
|
||||||
|
$entry->corporation_id = $corp;
|
||||||
|
$entry->name = $corpInfo->name;
|
||||||
|
$entry->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
//Internal Library
|
//Internal Library
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Log;
|
|
||||||
|
//Library
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Lookups\AllianceLookup;
|
use App\Models\Lookups\AllianceLookup;
|
||||||
@@ -28,7 +30,7 @@ class CleanStaleDataCommand extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'data:CleanData';
|
protected $signature = 'services:CleanData';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -54,6 +56,9 @@ class CleanStaleDataCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$command = new CommandHelper;
|
||||||
|
$command->CleanJobStatusTable();
|
||||||
|
|
||||||
//Empty the item lookup table
|
//Empty the item lookup table
|
||||||
ItemLookup::truncate();
|
ItemLookup::truncate();
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
//Internal Library
|
//Internal Library
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Structure\Structure;
|
use App\Models\Structure\Structure;
|
||||||
use App\Models\Structure\Service;
|
use App\Models\Structure\Service;
|
||||||
use App\Models\Structure\Asset;
|
use App\Models\Stock\Asset;
|
||||||
|
|
||||||
class EmptyJumpBridges extends Command
|
class EmptyJumpBridges extends Command
|
||||||
{
|
{
|
||||||
@@ -17,7 +20,7 @@ class EmptyJumpBridges extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'data:EmptyJumpBridges';
|
protected $signature = 'services:EmptyJumpBridges';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@@ -43,8 +46,16 @@ class EmptyJumpBridges extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$task = new CommandHelper('EmptyJumpBridges');
|
||||||
|
|
||||||
|
//Add entry into the table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
Structure::truncate();
|
Structure::truncate();
|
||||||
Service::truncate();
|
Service::truncate();
|
||||||
Asset::truncate();
|
Asset::truncate();
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Corporation\AllianceCorp;
|
|
||||||
use App\Models\ScheduledTask\ScheduleJob;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
class GetCorpsCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'data:GetCorps';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Get corporations in alliance and store in db.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare some variables
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication();
|
|
||||||
|
|
||||||
//try the esi call to get all of the corporations in the alliance
|
|
||||||
try {
|
|
||||||
$corporations = $esi->invoke('get', '/alliances/{alliance_id}/corporations/', [
|
|
||||||
'alliance_id' => 99004116,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e){
|
|
||||||
dd($e->getEsiResponse());
|
|
||||||
}
|
|
||||||
//Delete all of the entries in the AllianceCorps table
|
|
||||||
AllianceCorp::truncate();
|
|
||||||
|
|
||||||
//Foreach corporation, make entries into the database.
|
|
||||||
foreach($corporations as $corp) {
|
|
||||||
try {
|
|
||||||
$corpInfo = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
|
||||||
'corporation_id' => $corp,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
return $e->getEsiResponse();
|
|
||||||
}
|
|
||||||
$entry = new AllianceCorp;
|
|
||||||
$entry->corporation_id = $corp;
|
|
||||||
$entry->name = $corpInfo->name;
|
|
||||||
$entry->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Moons\PurgeMoonLedgerJob;
|
|
||||||
|
|
||||||
class PurgeCorpMoonLedgers extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'data:PurgeCorpLedgers';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Purge old corp ledgers data';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
PurgeMoonLedgerJob::dispatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Libraries
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\User\UserPermission;
|
|
||||||
use App\Models\User\UserRole;
|
|
||||||
use App\Models\Admin\AllowedLogin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The PurgeUsers command takes care of updating any user changes in terms of login role, as well as purging any users without at least
|
|
||||||
* the 'User' role. This command heavily relies on ESI being available. If no ESI is available, then the function does nothing, in order to prevent
|
|
||||||
* unwanted changes.
|
|
||||||
*/
|
|
||||||
class PurgeUsers extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'data:PurgeUsers';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Update and purge users from the database.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare some variables
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Setup the esi variable
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication();
|
|
||||||
|
|
||||||
//Get all of the users from the database
|
|
||||||
$users = User::all();
|
|
||||||
|
|
||||||
//Get the allowed logins
|
|
||||||
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
|
|
||||||
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
|
|
||||||
|
|
||||||
//Cycle through all of the users, and either update their role, or delete them.
|
|
||||||
foreach($users as $user) {
|
|
||||||
//Set the fail bit to false for the next user to check
|
|
||||||
$failed = false;
|
|
||||||
|
|
||||||
//Note a screen entry for when doing cli stuff
|
|
||||||
printf("Processing character with id of " . $user->character_id . "\r\n");
|
|
||||||
|
|
||||||
//Get the character information
|
|
||||||
try {
|
|
||||||
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$corp_info = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
|
||||||
'corporation_id' => $character_info->corporation_id,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::warning('Failed to get character information in purge user command for user ' . $user->character_id);
|
|
||||||
$failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the fail bit is still false, then continue
|
|
||||||
if($failed === false) {
|
|
||||||
//Get the user's role
|
|
||||||
$role = UserRole::where(['character_id' => $user->character_id])->first();
|
|
||||||
|
|
||||||
//We don't want to modify Admin and SuperUsers. Admins and SuperUsers are removed via a different process.
|
|
||||||
if($role->role != 'Admin') {
|
|
||||||
//Check if the user is allowed to login
|
|
||||||
if(isset($corp_info->alliance_id)) {
|
|
||||||
//Warped Intentions is allowed to login
|
|
||||||
if($corp_info->alliance_id == '99004116') {
|
|
||||||
//If the alliance is Warped Intentions, then modify the role if we need to
|
|
||||||
if($role->role != 'User') {
|
|
||||||
//Upate the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'User',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'W4RP',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else if(in_array($corp_info->alliance_id, $legacy)) { //Legacy Users
|
|
||||||
if($role->role != 'User') {
|
|
||||||
//Update the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'User',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'Legacy',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else if(in_array($corp_info->alliance_id, $renter)) { //Renter Users
|
|
||||||
if($role->role != 'Renter') {
|
|
||||||
//Update the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'Renter',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'Renter',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//If the user is part of no valid login group, then delete the user.
|
|
||||||
//Delete all of the permissions first
|
|
||||||
UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Delete the user's role
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Delete any alts the user might have registered.
|
|
||||||
$altCount = UserAlt::where(['main_id' => $user->character_id])->count();
|
|
||||||
if($altCount > 0) {
|
|
||||||
UserAlt::where([
|
|
||||||
'main_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete the user from the user table
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
EsiScope::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
EsiToken::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Data;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\ScheduledTask\ScheduleJob;
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use Seat\Eseye\Cache\NullCache;
|
|
||||||
use Seat\Eseye\Configuration;
|
|
||||||
use App\Library\Helpers\FinanceHelper;
|
|
||||||
|
|
||||||
class Test extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'data:test';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Test ESI stuff.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
$recipient = $config['primary'];
|
|
||||||
$recipientType = 'character';
|
|
||||||
$subject = "Just A Test for Eseye";
|
|
||||||
$sender = $config['primary'];
|
|
||||||
$body = "F0KlvSA9vrXWYK0IuMhSAbfaOAMmQO5U2CD69Dn0JOk26B8HnSPPkhSG3JzlawHjbBd16HAIbaawbv9304EaoTRctpu5cnZo0GoHINi3R7pNGi0IZTWKG4EArwWbSujwX9KPvMqGNbcSorrIEslw6neXWW1kcDN0GMcvV6SeoM23cSkK33cAbR4DTeqUXZ9ULuFy31UPXfEcaNzKREbqKPlgChYcGdCyHG1J25qrEmPlOTPI1NQQkh71HvHJTVA7bmTgLEJMdFYHbc3ZzGOB9RFLfhdkGEGl2f3OQNyDAJIKW2mNQVlRVGc3Emvm42czpsH8ojn3BX5nuEFxNfjgue8hhdBIZSKm232U2l0xsPGZOzHvQdYs8bLw7ZQX1drV9qOPnbhgzbFLxEvQoGDquhKAdlo7bhkgoCn5IiY3BbQ5qnKVodymb58gj9Pd67GxjJ8K0854c91KkrJNEOCyiVcqKYqNDtKkB7hgjBLZUKRtWUkOf9j1qIRARoGzTGdqK20yvfaVIWetVqjw5UvzQC2pynHkvIw2X3aD49ghY7UOzXUceKJ8taF4ZaMvW34r5OvyTrjVo4PKV9TylIODmzg1U0s4joxz58f1A6BNp2fCs1YzNOObuMaxGjek47jv2gDgyhQnmi5uaREcGn5AAwgMUc55GPY2jevRTHo9scMqm5amaJUBQ3TgXvFSfS33LxD8xJjdKw7KB06stDQzdjyVb52mAdm5WchOOpGy3EXntBSzsfUHc4XEqql7lKTPLgBzeYxt9EagGP96Li4dABg2MaLuU4i1CWdV49ZdPwOt1OjwNU4QtfR02C6Vw7raCFl3mqWBgLke9O5dC8Lh3ojg7FBATstSuur2n41Rn4YwzGaiWJ3qKwTsJGL3k8PaHEsvwvq56w4Qjt8CqJsmAV1nsfKMFZaVlcbK3PFN5oHaDbQwDh4IVdwA8UPPnrn2wSuugi8QlVyUA8z9iVYMW8OdzHFn98zl7a2Bua5M";
|
|
||||||
|
|
||||||
SendEveMail::dispatch($body, $recipient, $recipientType, $subject, $sender);
|
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
$response = $esi->setBody([
|
|
||||||
'approved_cost' => 100,
|
|
||||||
'body' => "Welcome to this test message.<br>" . $body,
|
|
||||||
'recipients' => [[
|
|
||||||
'recipient_id' => $config['primary'],
|
|
||||||
'recipient_type' => 'character',
|
|
||||||
]],
|
|
||||||
'subject' => 'Just a Test',
|
|
||||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
|
||||||
'character_id' => $config['primary'],
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var_dump($response);
|
|
||||||
dd($response->getErrorCode());
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Eve;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
//Job
|
|
||||||
use App\Jobs\Commands\Eve\ItemPricesUpdateJob;
|
|
||||||
|
|
||||||
class ItemPricesUpdateCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'services:ItemPriceUpdate';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Update mineral and ore prices';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$moonHelper = new MoonCalc;
|
|
||||||
|
|
||||||
//Fetch new prices from fuzzwork.co.uk for the item pricing schemes
|
|
||||||
$moonHelper->FetchNewPrices();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
//Namespace
|
|
||||||
namespace App\Console\Commands\Files;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Http\File;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use DB;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MoonRental\AllianceMoonOre;
|
|
||||||
use App\Models\MoonRental\AllianceMoon;
|
|
||||||
|
|
||||||
class ImportAllianceMoons extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'files:import:moons';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Import moons from tab-delimited text.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
//Create the collection of lines for the input file.
|
|
||||||
$lines = new Collection;
|
|
||||||
|
|
||||||
///universe/moons/{moon_id}/
|
|
||||||
|
|
||||||
//Create the file handler
|
|
||||||
$data = Storage::get('public/alliance_moons.txt');
|
|
||||||
//Split the string into separate arrays based on the line
|
|
||||||
$data = preg_split("/\n\t/", $data);
|
|
||||||
|
|
||||||
var_dump($data);
|
|
||||||
dd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands\Files;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Files;
|
|
||||||
|
|
||||||
//Internal Stuff
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
|
|
||||||
class UpdateItemCompositionFromSDECommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'sde:update:ItemCompositions';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Updates item compositions from sql file.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The SDE storage path
|
|
||||||
*
|
|
||||||
* @var
|
|
||||||
*/
|
|
||||||
protected $storage_path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query the sql file for the related database information
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Start by warning the user about the command which will be run
|
|
||||||
$this->comment('Warning! This Laravel command uses exec() to execute a ');
|
|
||||||
$this->comment('mysql shell command to import an extracted dump. Due');
|
|
||||||
$this->comment('to the way the command is constructed, should someone ');
|
|
||||||
$this->comment('view the current running processes of your server, they ');
|
|
||||||
$this->comment('will be able to see your SeAT database users password.');
|
|
||||||
$this->line('');
|
|
||||||
$this->line('Ensure that you understand this before continuing.');
|
|
||||||
|
|
||||||
//Test we have valid database parameters
|
|
||||||
DB::connection()->getDatabaseName();
|
|
||||||
|
|
||||||
//Warn the user about the operation to begin
|
|
||||||
if (! $this->confirm('Are you sure you want to update to the latest EVE SDE?', true)) {
|
|
||||||
$this->warn('Exiting');
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fileName = $this->getSde();
|
|
||||||
$this->importSde($fileName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download the EVE Sde from Fuzzwork and save it
|
|
||||||
* in the storage_path/sde folder
|
|
||||||
*/
|
|
||||||
public function getSde() {
|
|
||||||
|
|
||||||
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the SDE file downloaded and run the MySQL command to import the table into the database
|
|
||||||
*/
|
|
||||||
public function importSde($fileName) {
|
|
||||||
$import_command = 'mysql -u username -p password database < ' . $file;
|
|
||||||
|
|
||||||
//run the command
|
|
||||||
exec($import_command, $output, $exit_code);
|
|
||||||
|
|
||||||
if($exit_code !== 0) {
|
|
||||||
$this->error('Warning: Import failed with exit code ' .
|
|
||||||
$exit_code . ' and command outut: ' . implode('\n', $output));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
89
app/Console/Commands/Finances/HoldingFinances.php
Normal file
89
app/Console/Commands/Finances/HoldingFinances.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
use App\Library\Finances\Helper\FinanceHelper;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessWalletJournalJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Jobs\JobProcessWalletJournal;
|
||||||
|
|
||||||
|
class HoldingFinancesCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:HoldingJournal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get the holding corps finances.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Get the total pages for the journal for the holding corporation
|
||||||
|
$pages = $finance->GetJournalPageCount(1, $config['primary']);
|
||||||
|
|
||||||
|
//Dispatch a single job for each page to process
|
||||||
|
for($i = 1; $i <= $pages; $i++) {
|
||||||
|
$job = new JobProcessWalletJournal;
|
||||||
|
$job->division = 1;
|
||||||
|
$job->charId = $config['primary'];
|
||||||
|
$job->page = $i;
|
||||||
|
ProcessWalletJournalJob::dispatch($job)->onQueue('journal');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the total pages for the journal for the sov bills from the holding corporation
|
||||||
|
$pages = $finance->GetJournalPageCount(6, $config['primary']);
|
||||||
|
|
||||||
|
//Dispatch a job for each page to process
|
||||||
|
for($i = 1; $i <= $pages; $i++) {
|
||||||
|
$job = new JobProcessWalletJournal;
|
||||||
|
$job->division = 6;
|
||||||
|
$job->charId = $config['primary'];
|
||||||
|
$job->page = $i;
|
||||||
|
ProcessWalletJournalJob::dispatch($job)->onQueue('journal');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
142
app/Console/Commands/Finances/SovBills.php
Normal file
142
app/Console/Commands/Finances/SovBills.php
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
use App\Library\Finances\Helper\FinanceHelper;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessWalletJournalJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Jobs\JobProcessWalletJournal;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Finances\AllianceMarketTax;
|
||||||
|
use App\Library\Finances\CorpMarketTax;
|
||||||
|
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 App\Library\Finances\OfficeFee;
|
||||||
|
use App\Library\Finances\PlanetProductionTax;
|
||||||
|
use App\Library\Finances\PISale;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\Finances\SovBillExpenses;
|
||||||
|
|
||||||
|
//Seat Stuff
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
|
||||||
|
class SovBillsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:SovBills';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get the holding corps sov bills from wallet 6.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$sovBill = new SovBillExpenses;
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$finance = new FinanceHelper();
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
//Create the command helper container
|
||||||
|
$task = new CommandHelper('SovBills');
|
||||||
|
|
||||||
|
//Add the entry into the jobs table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||||
|
if($token == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create an ESI authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
$esi->setVersion('v4');
|
||||||
|
|
||||||
|
//Reference to see if the character is in our look up table for corporations and characters
|
||||||
|
$char = $lookup->GetCharacterInfo($config['primary']);
|
||||||
|
$corpId = $char->corporation_id;
|
||||||
|
|
||||||
|
//Get the total pages for the journal for the sov bills from the holding corporation
|
||||||
|
$pages = $finance->GetJournalPageCount(6, $config['primary']);
|
||||||
|
|
||||||
|
//Dispatch a job for each page to process
|
||||||
|
//for($i = 1; $i <= $pages; $i++) {
|
||||||
|
// $job = new JobProcessWalletJournal;
|
||||||
|
// $job->division = 6;
|
||||||
|
// $job->charId = $config['primary'];
|
||||||
|
// $job->page = $i;
|
||||||
|
// ProcessWalletJournalJob::dispatch($job)->onQueue('journal');
|
||||||
|
//}
|
||||||
|
|
||||||
|
//Try to figure it out from the command itself.
|
||||||
|
for($i = 1; $i <= $pages; $i++) {
|
||||||
|
printf("Getting page: " . $i . "\n");
|
||||||
|
|
||||||
|
try {
|
||||||
|
$journals = $esi->page($i)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
'division' => 6,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Decode the wallet from json into an array
|
||||||
|
$wallet = json_decode($journals->raw, true);
|
||||||
|
dd($wallet);
|
||||||
|
foreach($wallet as $entry) {
|
||||||
|
if($entry['ref_type'] == 'infrastructure_hub_maintenance' && $entry['first_party_id'] == 98287666) {
|
||||||
|
$sovBill->InsertSovBillExpense($entry, $corpId, $division);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Finances;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\FinanceHelper;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Finances\UpdateAllianceWalletJournalJob;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Finances\AllianceWalletJournal;
|
|
||||||
|
|
||||||
class UpdateAllianceWalletJournal extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'finances:UpdateJournals';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = "Update the holding corporation's finance journal.";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
UpdateAllianceWalletJournalJob::dispatch()->onQueue('finances');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
134
app/Console/Commands/Flex/FlexStructureCommand.php
Normal file
134
app/Console/Commands/Flex/FlexStructureCommand.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Flex\FlexStructure;
|
||||||
|
use App\Models\Mail\SentMail;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
|
class FlexStructureCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:FlexStructures';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Mail out reminder for flex structure bills';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Create the new command helper container
|
||||||
|
$task = new CommandHelper('FlexStructureMailer');
|
||||||
|
//Add the entry into the jobs table saying the job has started
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
//Create other variables
|
||||||
|
$body = null;
|
||||||
|
$delay = 5;
|
||||||
|
|
||||||
|
//Get today's date
|
||||||
|
$today = Carbon::now();
|
||||||
|
$today->second = 2;
|
||||||
|
$today->minute = 0;
|
||||||
|
$today->hour = 0;
|
||||||
|
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Get all of the contacts for the flex structures
|
||||||
|
$contacts = FlexStructure::select('requestor_id')->orderBy('requestor_id')->get();
|
||||||
|
|
||||||
|
//For each of the contacts, send a reminder mail about the total of the structures they are paying for
|
||||||
|
foreach($contacts as $contact) {
|
||||||
|
//Get all of the structures for requestor
|
||||||
|
$structures = FlexStructure::where([
|
||||||
|
'requestor_id' => $contact->requestor_id,
|
||||||
|
])->get();
|
||||||
|
|
||||||
|
//Totalize the total cost of everything
|
||||||
|
$totalCost = $this->TotalizeCost($structures);
|
||||||
|
|
||||||
|
//Build the body of the mail
|
||||||
|
$body = "Flex Structure Overhead Cost is due for the following structures:<br>";
|
||||||
|
foreach($structures as $structure) {
|
||||||
|
$body += "System: " . $structure->system . " - " . $structure->structure_type . ": " . $structure->structure_cost . " ISK<br>";
|
||||||
|
}
|
||||||
|
$body += "Total Cost: " . number_format($totalCost, 2,".", ",");
|
||||||
|
$body += "Please remit payment to Spatial Forces by the 3rd of the month.<br>";
|
||||||
|
$body += "Sincerely,<br>";
|
||||||
|
$body += "Warped Intentions Leadership<br>";
|
||||||
|
|
||||||
|
//Dispatch the mail job
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = "Warped Intentions Flex Structures Payment Due for " . $today->englishMonth;
|
||||||
|
$mail->body = $body;
|
||||||
|
$mail->recipient = (int)$structure->requestor_id;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueueu('mail')->delay($delay);
|
||||||
|
|
||||||
|
//Increment the delay for the mail to not hit the rate limits
|
||||||
|
$delay += 60;
|
||||||
|
|
||||||
|
//After the mail is dispatched, save the sent mail record
|
||||||
|
$this->SaveSentRecord($mail->sender, $mail->subject, $mail->body, $mail->recipient, $mail->recipient_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function TotalizeCost($structures) {
|
||||||
|
//Declare the total cost
|
||||||
|
$totalCost = 0.00;
|
||||||
|
|
||||||
|
foreach($structures as $structure) {
|
||||||
|
$totalCost += $structure->structure_cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $totalCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {
|
||||||
|
$sentmail = new SentMail;
|
||||||
|
$sentmail->sender = $sender;
|
||||||
|
$sentmail->subject = $subject;
|
||||||
|
$sentmail->body = $body;
|
||||||
|
$sentmail->recipient = $recipient;
|
||||||
|
$sentmail->recipient_type = $recipientType;
|
||||||
|
$sentmail->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
48
app/Console/Commands/Library/CommandHelper.php
Normal file
48
app/Console/Commands/Library/CommandHelper.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Commands\Library;
|
||||||
|
|
||||||
|
//Internal Libraries
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\ScheduledTask\ScheduleJob;
|
||||||
|
|
||||||
|
class CommandHelper {
|
||||||
|
|
||||||
|
private $job_name;
|
||||||
|
private $job_state;
|
||||||
|
private $system_time;
|
||||||
|
|
||||||
|
public function __construct($name) {
|
||||||
|
$this->job_name = $name;
|
||||||
|
$this->job_state = 'Starting';
|
||||||
|
$this->system_time = Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetStartStatus() {
|
||||||
|
//Add an entry into the jobs table
|
||||||
|
$job = new ScheduleJob;
|
||||||
|
$job->job_name = $this->job_name;
|
||||||
|
$job->job_state = $this->job_state;
|
||||||
|
$job->system_time = $this->system_time;
|
||||||
|
$job->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetStopStatus() {
|
||||||
|
//Mark the job as finished
|
||||||
|
ScheduleJob::where([
|
||||||
|
'system_time' => $this->system_time,
|
||||||
|
'job_name' => $this->job_name,
|
||||||
|
])->update([
|
||||||
|
'job_state' => 'Finished',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function CleanJobStatusTable() {
|
||||||
|
//Delete old jobs
|
||||||
|
ScheduleJob::where(['system_time', '<', Carbon::now()->subMonths(3)])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\MiningTaxes\PreFetchMiningTaxesLedgers as PreFetch;
|
|
||||||
|
|
||||||
class ExecuteMiningTaxesLedgersCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'mt:ledgers';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Execute mining taxes ledgers jobs.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
PreFetch::dispatch()->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\MiningTaxes\FetchMiningTaxesObservers as FetchObservers;
|
|
||||||
|
|
||||||
class ExecuteMiningTaxesObserversCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'mt:observer';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Dispatch a mining tax observer job.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
FetchObservers::dispatch()->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\MiningTaxes\ProcessMiningTaxesPayments as PMTP;
|
|
||||||
|
|
||||||
class ExecuteProcesssMiningTaxesPaymentsCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'mt:payments';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Process Mining Taxes payments from the console.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
PMTP::dispatch()->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\MiningTaxes\SendMiningTaxesInvoices as SendInvoice;
|
|
||||||
|
|
||||||
class ExecuteSendMiningTaxesInvoiceCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'mt:send';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Execute send mining tax invoices.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
SendInvoice::dispatch()->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
226
app/Console/Commands/Moons/MoonMailer.php
Normal file
226
app/Console/Commands/Moons/MoonMailer.php
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
use App\Library\Moons\MoonCalc;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Moon\RentalMoon;
|
||||||
|
use App\Models\MoonRent\MoonRental;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
use App\Models\Mail\SentMail;
|
||||||
|
|
||||||
|
class MoonMailerCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Next update will include checking for if the moon has been paid in advance.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:MoonMailer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Mail out the moon rental bills automatically';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Create the new command helper container
|
||||||
|
$task = new CommandHelper('MoonMailer');
|
||||||
|
//Add the entry into the jobs table saying the job has started
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
//Create other variables
|
||||||
|
$body = null;
|
||||||
|
$delay = 5;
|
||||||
|
|
||||||
|
//Get today's date.
|
||||||
|
$today = Carbon::now();
|
||||||
|
$today->second = 1;
|
||||||
|
$today->minute = 0;
|
||||||
|
$today->hour = 0;
|
||||||
|
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Get all contacts from the rentals group
|
||||||
|
$contacts = MoonRental::select('Contact')->groupBy('Contact')->get();
|
||||||
|
|
||||||
|
//For each of the contacts totalize the moon rental, and create the mail to send to them,
|
||||||
|
//then update parameters of the moon
|
||||||
|
foreach($contacts as $contact) {
|
||||||
|
//Get the moons the renter is renting. Also only get the moons which are not paid as of today
|
||||||
|
$rentals = MoonRental::where(['Contact' => $contact->Contact])->get();
|
||||||
|
|
||||||
|
//Totalize the cost of the moons
|
||||||
|
$cost = $this->TotalizeMoonCost($rentals);
|
||||||
|
|
||||||
|
//Get the list of moons in a list format
|
||||||
|
$listItems = $this->GetMoonList($rentals);
|
||||||
|
|
||||||
|
//Build the mail body
|
||||||
|
$body = "Moon Rent is due for the following moons:<br>";
|
||||||
|
foreach($listItems as $item) {
|
||||||
|
$body .= $item . "<br>";
|
||||||
|
}
|
||||||
|
$body .= "The price for the next month's rent is " . number_format($cost, 2, ".", ",") . "<br>";
|
||||||
|
$body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.<br>";
|
||||||
|
$body .= "Sincerely,<br>";
|
||||||
|
$body .= "Warped Intentions Leadership<br>";
|
||||||
|
|
||||||
|
//Dispatch the mail job
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = "Warped Intentions Moon Rental Payment Due for " . $today->englishMonth;
|
||||||
|
$mail->body = $body;
|
||||||
|
$mail->recipient = (int)$contact->Contact;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay($delay);
|
||||||
|
//Increment the delay for the mail to not hit rate limits
|
||||||
|
$delay += 30;
|
||||||
|
|
||||||
|
//Update the moon as not being paid for the next month?
|
||||||
|
foreach($rentals as $rental) {
|
||||||
|
$previous = new Carbon($rental->Paid_Until);
|
||||||
|
|
||||||
|
if($today->greaterThanOrEqualTo($previous)) {
|
||||||
|
$this->UpdateNotPaid($rental);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function SendMail() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function UpdateNotPaid(MoonRental $rental) {
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $rental->System,
|
||||||
|
'Planet'=> $rental->Planet,
|
||||||
|
'Moon'=> $rental->Moon,
|
||||||
|
])->update([
|
||||||
|
'Paid' => 'No',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetMoonList($moons) {
|
||||||
|
//Declare the variable to be used as a global part of the function
|
||||||
|
$list = array();
|
||||||
|
|
||||||
|
//For each of the moons, build the System Planet and Moon.
|
||||||
|
foreach($moons as $moon) {
|
||||||
|
$temp = 'Moon: ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon;
|
||||||
|
array_push($list, $temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return the list
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetRentalMoons($contact) {
|
||||||
|
$rentals = MoonRental::where([
|
||||||
|
'Contact' => $contact,
|
||||||
|
])->get();
|
||||||
|
|
||||||
|
return $rentals;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function TotalizeMoonCost($rentals) {
|
||||||
|
//Delcare variables and classes
|
||||||
|
$moonCalc = new MoonCalc;
|
||||||
|
$totalCost = 0.00;
|
||||||
|
$price = null;
|
||||||
|
|
||||||
|
//Create the date for today
|
||||||
|
$today = Carbon::now();
|
||||||
|
$today->second = 1;
|
||||||
|
$today->minute = 0;
|
||||||
|
$today->hour = 0;
|
||||||
|
|
||||||
|
foreach($rentals as $rental) {
|
||||||
|
$moon = RentalMoon::where([
|
||||||
|
'System' => $rental->System,
|
||||||
|
'Planet' => $rental->Planet,
|
||||||
|
'Moon' => $rental->Moon,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
//Create the date time object for the rental end
|
||||||
|
$end = new Carbon($rental->Paid_Until);
|
||||||
|
|
||||||
|
//If today is greater than the rental end, then calculate the moon cost
|
||||||
|
if($today->greaterThanOrEqualTo($end)) {
|
||||||
|
//Get the updated price for the moon
|
||||||
|
$price = $moonCalc->SpatialMoonsOnlyGooMailer($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||||
|
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||||
|
|
||||||
|
//Check the type and figure out which price to add in
|
||||||
|
if($rental->Type == 'alliance') {
|
||||||
|
$totalCost += $price['alliance'];
|
||||||
|
} else{
|
||||||
|
$totalCost += $price['outofalliance'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return the total cost back to the calling function
|
||||||
|
return $totalCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetRentalType($rentals) {
|
||||||
|
$alliance = 0;
|
||||||
|
$outofalliance = 0;
|
||||||
|
|
||||||
|
//Go through the data and log whether the renter is in the alliance,
|
||||||
|
//or the renter is out of the alliance
|
||||||
|
foreach($rentals as $rental) {
|
||||||
|
if($rental->Type == 'alliance') {
|
||||||
|
$alliance++;
|
||||||
|
} else {
|
||||||
|
$outofalliance++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return the rental type
|
||||||
|
if($alliance > $outofalliance) {
|
||||||
|
return 'alliance';
|
||||||
|
} else {
|
||||||
|
return 'outofalliance';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
app/Console/Commands/Moons/UpdateMoonPricing.php
Normal file
55
app/Console/Commands/Moons/UpdateMoonPricing.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
|
use App\Library\Moons\MoonCalc;
|
||||||
|
|
||||||
|
class UpdateMoonPriceCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:UpdateMoonPrice';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Update moon pricing on a scheduled basis';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('CorpJournal');
|
||||||
|
//Add the entry into the jobs table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
$moonCalc = new MoonCalc();
|
||||||
|
$moonCalc->FetchNewPrices();
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Structures;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\Assets\FetchAllianceAssets as FAA;
|
|
||||||
|
|
||||||
class ExecuteFetchAllianceAssetsCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'structure:assets';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Execute fetch alliance command.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
FAA::dispatch();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Structures;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
use App\Jobs\Commands\Structures\FetchAllianceStructures as FAS;
|
|
||||||
|
|
||||||
class ExecuteFetchAllianceStructuresCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'structure:structure';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Fetch alliance structures command.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
FAS::dispatch();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
119
app/Console/Commands/Structures/GetStructures.php
Normal file
119
app/Console/Commands/Structures/GetStructures.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Structures\StructureHelper;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
|
||||||
|
//Job
|
||||||
|
use App\Jobs\ProcessStructureJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Jobs\JobProcessStructure;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
|
||||||
|
class GetStructuresCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:GetStructures';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Get the list of structures ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('GetStructures');
|
||||||
|
//Add the entry into the jobs table saying the job is starting
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
//Get the esi config
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Declare some variables
|
||||||
|
$charId = $config['primary'];
|
||||||
|
$corpId = 98287666;
|
||||||
|
$sHelper = new StructureHelper($charId, $corpId);
|
||||||
|
$structures = null;
|
||||||
|
|
||||||
|
//ESI Scope Check
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$structureScope = $esiHelper->HaveEsiScope($charId, 'esi-universe.read_structures.v1');
|
||||||
|
$corpStructureScope = $esiHelper->HaveEsiScope($charId, 'esi-corporations.read_structures.v1');
|
||||||
|
|
||||||
|
//Check scopes
|
||||||
|
if($structureScope == false || $corpStructureScope == false) {
|
||||||
|
if($structureScope == false) {
|
||||||
|
Log::critical("Scope check for esi-universe.read_structures.v1 has failed.");
|
||||||
|
}
|
||||||
|
if($corpStructureScope == false) {
|
||||||
|
Log::critical("Scope check for esi-corporations.read_structures.v1 has failed.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the refresh token from the database
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
//Create the esi authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
|
||||||
|
//Set the current page
|
||||||
|
$currentPage = 1;
|
||||||
|
//Set our default total pages, and we will refresh this later
|
||||||
|
$totalPages = 1;
|
||||||
|
|
||||||
|
//Try to get the ESI data
|
||||||
|
try {
|
||||||
|
$structures = $esi->page($currentPage)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/structures/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
]);
|
||||||
|
} catch (RequestFailedException $e) {
|
||||||
|
Log::critical("Failed to get structure list.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalPages = $structures->pages;
|
||||||
|
|
||||||
|
for($i = 1; $i <= $totalPages; $i++) {
|
||||||
|
$job = new JobProcessStructure;
|
||||||
|
$job->charId = $charId;
|
||||||
|
$job->corpId = $corpId;
|
||||||
|
$job->page = $currentPage;
|
||||||
|
ProcessStructureJob::dispatch($job)->onQueue('structures');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the job as finished
|
||||||
|
$task->SetStopStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\SupplyChain;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Contracts\SupplyChainContract;
|
|
||||||
|
|
||||||
//Job
|
|
||||||
use App\Jobs\Commands\SupplyChain\EndSupplyChainContractJob;
|
|
||||||
|
|
||||||
class EndSupplyChainContractCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'services:supplychain';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Checks and ends any supply chain contracts needs to be closed.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$today = Carbon::now();
|
|
||||||
|
|
||||||
//Get the supply chain contracts which are open, but need to be closed.
|
|
||||||
$contracts = SupplyChainContract::where([
|
|
||||||
'state' => 'open',
|
|
||||||
])->where('end_date', '>', $today)->get();
|
|
||||||
|
|
||||||
//Create jobs to complete each contract
|
|
||||||
foreach($contracts as $contract) {
|
|
||||||
EndSupplyChainContractJob::dispatch($contract)->onQueue('default');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
193
app/Console/Commands/Users/PurgeUsers.php
Normal file
193
app/Console/Commands/Users/PurgeUsers.php
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Libraries
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\User\User;
|
||||||
|
use App\Models\User\UserAlt;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\User\UserPermission;
|
||||||
|
use App\Models\User\UserRole;
|
||||||
|
use App\Models\Admin\AllowedLogin;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PurgeUsers command takes care of updating any user changes in terms of login role, as well as purging any users without at least
|
||||||
|
* the 'User' role. This command heavily relies on ESI being available. If no ESI is available, then the function does nothing, in order to prevent
|
||||||
|
* unwanted changes.
|
||||||
|
*/
|
||||||
|
class PurgeUsers extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:PurgeUsers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Update and purge users from the database.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Declare some variables
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Setup the esi variable
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
//Get all of the users from the database
|
||||||
|
$users = User::all();
|
||||||
|
|
||||||
|
//Get the allowed logins
|
||||||
|
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
|
||||||
|
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
|
||||||
|
|
||||||
|
//Cycle through all of the users, and either update their role, or delete them.
|
||||||
|
foreach($users as $user) {
|
||||||
|
//Set the fail bit to false for the next user to check
|
||||||
|
$failed = false;
|
||||||
|
|
||||||
|
//Note a screen entry for when doing cli stuff
|
||||||
|
printf("Processing character with id of " . $user->character_id . "\r\n");
|
||||||
|
|
||||||
|
//Get the character information
|
||||||
|
try {
|
||||||
|
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$corp_info = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||||
|
'corporation_id' => $character_info->corporation_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning('Failed to get character information in purge user command for user ' . $user->character_id);
|
||||||
|
$failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the fail bit is still false, then continue
|
||||||
|
if($failed === false) {
|
||||||
|
//Get the user's role
|
||||||
|
$role = UserRole::where(['character_id' => $user->character_id])->first();
|
||||||
|
|
||||||
|
//We don't want to modify Admin and SuperUsers. Admins and SuperUsers are removed via a different process.
|
||||||
|
if($role->role != 'Admin') {
|
||||||
|
//Check if the user is allowed to login
|
||||||
|
if(isset($corp_info->alliance_id)) {
|
||||||
|
//Warped Intentions is allowed to login
|
||||||
|
if($corp_info->alliance_id == '99004116') {
|
||||||
|
//If the alliance is Warped Intentions, then modify the role if we need to
|
||||||
|
if($role->role != 'User') {
|
||||||
|
//Upate the role of the user
|
||||||
|
UserRole::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'role' => 'User',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the user type
|
||||||
|
User::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'user_type' => 'W4RP',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else if(in_array($corp_info->alliance_id, $legacy)) { //Legacy Users
|
||||||
|
if($role->role != 'User') {
|
||||||
|
//Update the role of the user
|
||||||
|
UserRole::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'role' => 'User',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the user type
|
||||||
|
User::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'user_type' => 'Legacy',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else if(in_array($corp_info->alliance_id, $renter)) { //Renter Users
|
||||||
|
if($role->role != 'Renter') {
|
||||||
|
//Update the role of the user
|
||||||
|
UserRole::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'role' => 'Renter',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the user type
|
||||||
|
User::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->update([
|
||||||
|
'user_type' => 'Renter',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//If the user is part of no valid login group, then delete the user.
|
||||||
|
//Delete all of the permissions first
|
||||||
|
UserPermission::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
//Delete the user's role
|
||||||
|
UserRole::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
//Delete any alts the user might have registered.
|
||||||
|
$altCount = UserAlt::where(['main_id' => $user->character_id])->count();
|
||||||
|
if($altCount > 0) {
|
||||||
|
UserAlt::where([
|
||||||
|
'main_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete the user from the user table
|
||||||
|
User::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
EsiScope::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
EsiToken::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Console/Commands/Wormholes/PurgeWormholes.php
Normal file
50
app/Console/Commands/Wormholes/PurgeWormholes.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Wormholes\AllianceWormhole;
|
||||||
|
|
||||||
|
class PurgeWormholes extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'services:PurgeWormholeData';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Purge stale wormhole data automatically';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Time of now
|
||||||
|
$currentTime = Carbon::now();
|
||||||
|
|
||||||
|
AllianceWormhole::where('created_at', '<', $currentTime->subHours(48))->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,20 +6,8 @@ namespace App\Console;
|
|||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
//Jobs
|
//Library
|
||||||
use App\Jobs\Commands\MiningTaxes\PreFetchMiningTaxesLedgers;
|
use Commands\Library\CommandHelper;
|
||||||
use App\Jobs\Commands\MiningTaxes\FetchMiningTaxesObservers;
|
|
||||||
use App\Jobs\Commands\MiningTaxes\ProcessMiningTaxesPayments;
|
|
||||||
use App\Jobs\Commands\MiningTaxes\SendMiningTaxesInvoices;
|
|
||||||
use App\Jobs\Commands\MiningTaxes\UpdateMiningTaxesLateInvoices1st;
|
|
||||||
use App\Jobs\Commands\MiningTaxes\UpdateMiningTaxesLateInvoices15th;
|
|
||||||
use App\Jobs\Commands\Finances\UpdateAllianceWalletJournalJob;
|
|
||||||
use App\Jobs\Commands\Finances\UpdateItemPrices as UpdateItemPricesJob;
|
|
||||||
use App\Jobs\Commands\Data\PurgeUsers as PurgeUsersJob;
|
|
||||||
use App\Jobs\Commands\Structures\FetchAllianceStructures;
|
|
||||||
use App\Jobs\Commands\Structures\PurgeAllianceStructures;
|
|
||||||
use App\Jobs\Commands\Assets\FetchAllianceAssets;
|
|
||||||
use App\Jobs\Commands\Assets\PurgeAllianceAssets;
|
|
||||||
|
|
||||||
class Kernel extends ConsoleKernel
|
class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
@@ -29,17 +17,18 @@ class Kernel extends ConsoleKernel
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
Commands\Data\PurgeUsers::class,
|
Commands\GetCorpsCommand::class,
|
||||||
Commands\Data\Test::class,
|
Commands\UpdateMoonPriceCommand::class,
|
||||||
Commands\Eve\ItemPricesUpdateCommand::class,
|
Commands\HoldingFinancesCommand::class,
|
||||||
Commands\Finances\UpdateAllianceWalletJournal::class,
|
Commands\MoonMailerCommand::class,
|
||||||
Commands\MiningTaxes\ExecuteMiningTaxesObserversCommand::class,
|
Commands\GetStructuresCommand::class,
|
||||||
Commands\MiningTaxes\ExecuteMiningTaxesLedgersCommand::class,
|
Commands\GetAssetsCommand::class,
|
||||||
Commands\MiningTaxes\ExecuteSendMiningTaxesInvoiceCommand::class,
|
Commands\PurgeUsers::class,
|
||||||
Commands\MiningTaxes\ExecuteProcesssMiningTaxesPaymentsCommand::class,
|
Commands\FlexStructureCommand::class,
|
||||||
Commands\Structures\ExecuteFetchAllianceStructuresCommand::class,
|
Commands\EmptyJumpBridges::class,
|
||||||
Commands\Structures\ExecuteFetchAllianceAssetsCommand::class,
|
Commands\PurgeWormholes::class,
|
||||||
Commands\Files\ImportAllianceMoons::class,
|
Commands\SovBillsCommand::class,
|
||||||
|
Commands\CleanStaleDataCommand::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,71 +39,51 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
//Schedule Monitor Jobs
|
//Command to get the holding journal finances
|
||||||
$schedule->command('schedule-monitor:sync')->dailyAt('04:56');
|
$schedule->command('services:HoldingJournal')
|
||||||
$schedule->command('schedule-monitor:clean')->daily();
|
->hourly()
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Command to update moon rental pricing
|
||||||
|
$schedule->command('services:UpdateMoonPrice')
|
||||||
|
->hourly()
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Get the corps within the alliance
|
||||||
|
$schedule->command('services:GetCorps')
|
||||||
|
->monthlyOn(1, '09:00')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Update the moons, and send out mails for current moon rentals
|
||||||
|
$schedule->command('services:MoonMailer')
|
||||||
|
->monthlyOn(1, '00:01')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Get the structures within the alliance and their information
|
||||||
|
$schedule->command('services:GetStructures')
|
||||||
|
->dailyAt('09:00')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Get the assets for the alliance. Only saves the Liquid Ozone for jump bridges
|
||||||
|
$schedule->command('services:GetAssets')
|
||||||
|
->hourlyAt('22')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Clean old data from the database
|
||||||
|
$schedule->command('services:CleanData')
|
||||||
|
->monthlyOn(15, '18:00');
|
||||||
|
//Purge users from the database which don't belong and reset the user roles as necessary
|
||||||
|
$schedule->command('services:PurgeUsers')
|
||||||
|
->dailyAt('23:00')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Mail about payments for flex structures
|
||||||
|
$schedule->command('services:FlexStructures')
|
||||||
|
->monthlyOn(2, '00:01')
|
||||||
|
->withoutOverlapping();
|
||||||
|
//Wormhole data purge
|
||||||
|
$schedule->command('services:PurgeWormholeData')
|
||||||
|
->hourlyAt(20);
|
||||||
|
//Purge old data from the database
|
||||||
|
$schedule->command('services:CleanData')
|
||||||
|
->weekly(7, '11:00')
|
||||||
|
->withoutOverlapping();
|
||||||
|
|
||||||
//Horizon Graph Schedule
|
//Horizon Graph Schedule
|
||||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||||
|
|
||||||
/**
|
|
||||||
* Purge Data Schedule
|
|
||||||
*/
|
|
||||||
$schedule->job(new PurgeUsersJob)
|
|
||||||
->weekly();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finances Update Schedule
|
|
||||||
*/
|
|
||||||
$schedule->job(new UpdateAllianceWalletJournalJob)
|
|
||||||
->hourlyAt('45')
|
|
||||||
->withoutOverlapping();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Item Update Schedule
|
|
||||||
*/
|
|
||||||
$schedule->job(new UpdateItemPricesJob)
|
|
||||||
->hourlyAT('30')
|
|
||||||
->withoutOverlapping();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mining Tax Schedule
|
|
||||||
*/
|
|
||||||
$schedule->job(new FetchMiningTaxesObservers)
|
|
||||||
->dailyAt('22:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new PreFetchMiningTaxesLedgers)
|
|
||||||
->dailyAt('20:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new SendMiningTaxesInvoices)
|
|
||||||
->weeklyOn(1, '06:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new ProcessMiningTaxesPayments)
|
|
||||||
->hourlyAt('15')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new UpdateMiningTaxesLateInvoices1st)
|
|
||||||
->monthlyOn(1, '16:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new UpdateMiningTaxesLateInvoices15th)
|
|
||||||
->monthlyOn(15, '16:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alliance Structure and Assets Schedule
|
|
||||||
*/
|
|
||||||
$schedule->job(new FetchAllianceStructures)
|
|
||||||
->dailyAt('21:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new FetchAllianceAssets)
|
|
||||||
->hourlyAt('15')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new PurgeAllianceStructures)
|
|
||||||
->monthlyOn(2, '14:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
$schedule->job(new PurgeAllianceAssets)
|
|
||||||
->monthlyOn(2, '15:00')
|
|
||||||
->withoutOverlapping();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,14 +97,4 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the timezone that should be used by default for scheduled events.
|
|
||||||
*
|
|
||||||
* @return \DateTimeZone|string|null
|
|
||||||
*/
|
|
||||||
protected function scheduleTimezone()
|
|
||||||
{
|
|
||||||
return 'UTC';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
//use Exception;
|
use Exception;
|
||||||
use Throwable;
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
@@ -33,7 +32,7 @@ class Handler extends ExceptionHandler
|
|||||||
* @param \Exception $exception
|
* @param \Exception $exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function report(Throwable $exception)
|
public function report(Exception $exception)
|
||||||
{
|
{
|
||||||
parent::report($exception);
|
parent::report($exception);
|
||||||
}
|
}
|
||||||
@@ -45,7 +44,7 @@ class Handler extends ExceptionHandler
|
|||||||
* @param \Exception $exception
|
* @param \Exception $exception
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function render($request, Throwable $exception)
|
public function render($request, Exception $exception)
|
||||||
{
|
{
|
||||||
return parent::render($request, $exception);
|
return parent::render($request, $exception);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\AfterActionReports;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class AfterActionReportsAdminController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('permission:fc.lead');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DeleteReport() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DeleteComment() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function PruneReports() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DisplayStastics() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\AfterActionReports;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\AfterActionReports\AfterActionReport;
|
|
||||||
use App\Models\AfterActionReports\AfterActionReportComment;
|
|
||||||
|
|
||||||
class AfterActionReportsController extends Controller
|
|
||||||
{
|
|
||||||
public function __contstruct() {
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('permission:fc.team');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DisplayReportForm() {
|
|
||||||
return view('reports.user.form.report');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function StoreReport(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'location' => 'required',
|
|
||||||
'time' => 'required',
|
|
||||||
'comms' => 'required',
|
|
||||||
'doctrine' => 'required',
|
|
||||||
'objective' => 'required',
|
|
||||||
'result' => 'required',
|
|
||||||
'summary' => 'required',
|
|
||||||
'improvements' => 'required',
|
|
||||||
'well' => 'required',
|
|
||||||
'comments' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$report = new Report;
|
|
||||||
$report->fc_id = auth()->user()->getId();
|
|
||||||
$report->fc_name = auth()->user()->getName();
|
|
||||||
$report->formup_time = $request->time;
|
|
||||||
$report->formup_location = $request->location;
|
|
||||||
$report->comms = $request->comms;
|
|
||||||
$report->doctrine = $request->doctrine;
|
|
||||||
$report->objective = $request->objective;
|
|
||||||
$report->objective_result = $request->result;
|
|
||||||
$report->summary = $request->summary;
|
|
||||||
$report->improvements = $request->improvements;
|
|
||||||
$report->worked_well = $request->well;
|
|
||||||
$report->additonal_comments = $request->comments;
|
|
||||||
$report->save();
|
|
||||||
|
|
||||||
return redirect('/reports/display/all')->with('success', 'Added report to the database.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DisplayCommentForm($id) {
|
|
||||||
return view('reports.user.form.comment')->with('id', $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function StoreComment(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'reportId' => 'required',
|
|
||||||
'comments' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$comment = new AfterActionReportComment;
|
|
||||||
$comment->report_id = $request->reportId;
|
|
||||||
$comment->character_id = auth()->user()->getId();
|
|
||||||
$comment->character_name = auth()->user()->getName();
|
|
||||||
$comment->comments = $required->comments;
|
|
||||||
$comment->save();
|
|
||||||
|
|
||||||
return redirect('/reports/display/all')->with('success', 'Added comemnt to the report.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DisplayAllReports() {
|
|
||||||
//Grab all the reports
|
|
||||||
$reports = AfterActionReport::where('created_at', '>=', Carbon::now()->subDays(30));
|
|
||||||
$comments = AfterActionReportComment::where('created_at', '>=', Carbon::now()->subDays(30));
|
|
||||||
$reportCount = AfterActionReport::where('created_at', '>=', Carbon::now()->subDays(30))->count();
|
|
||||||
|
|
||||||
return view('reports.user.displayreports')->with('reports', $reports)
|
|
||||||
->with('comments', $comments)
|
|
||||||
->with('reportCount', $reportCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,15 +6,13 @@ namespace App\Http\Controllers\Auth;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Socialite;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Laravel\Socialite\Contracts\Factory as Socialite;
|
|
||||||
use Laravel\Socialite\Two\User as SocialiteUser;
|
|
||||||
|
|
||||||
//Library
|
//Library
|
||||||
use Seat\Eseye\Cache\NullCache;
|
use Seat\Eseye\Cache\NullCache;
|
||||||
use Seat\Eseye\Configuration;
|
use Seat\Eseye\Configuration;
|
||||||
use App\Library\Esi\Esi;
|
use App\Library\Esi\Esi;
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\User\User;
|
use App\Models\User\User;
|
||||||
@@ -75,80 +73,50 @@ class LoginController extends Controller
|
|||||||
*
|
*
|
||||||
* @return Socialite
|
* @return Socialite
|
||||||
*/
|
*/
|
||||||
public function redirectToProvider($profile = null, Socialite $social) {
|
public function redirectToProvider() {
|
||||||
//The default scope is public data for everyone due to OAuth2 Tokens
|
return Socialite::driver('eveonline')->redirect();
|
||||||
//We also add the send mail scope in order to be able to send mails more efficiently through jobs when other scopes are required.
|
|
||||||
$scopes = ['publicData', 'esi-mail.send_mail.v1'];
|
|
||||||
|
|
||||||
//Collect any other scopes we need if we are logged in.
|
|
||||||
//If we are logged in we are linking another character to this one.
|
|
||||||
//Attempt to use the same scopes for this character as the original one
|
|
||||||
if(Auth::check()) {
|
|
||||||
$extraScopes = EsiScope::where([
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->get(['scope']);
|
|
||||||
|
|
||||||
//Pop each scope onto the array of scopes
|
|
||||||
foreach($extraScopes as $extra) {
|
|
||||||
array_push($scopes, $extra->scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Place the scopes in the session.
|
|
||||||
* Place the original character id in the session.
|
|
||||||
*/
|
|
||||||
session()->put('scopes', $scopes);
|
|
||||||
session()->put('orgCharacter', auth()->user()->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $social->driver('eveonline')
|
|
||||||
->scopes($scopes)
|
|
||||||
->redirect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get token from callback
|
* Get token from callback
|
||||||
* Redirect to the dashboard if logging in successfully.
|
* Redirect to the dashboard if logging in successfully.
|
||||||
*/
|
*/
|
||||||
public function handleProviderCallback(Socialite $social) {
|
public function handleProviderCallback() {
|
||||||
//Get the sso user from the socialite driver
|
//Get the sso user from the socialite driver
|
||||||
$ssoUser = $social->driver('eveonline')->user();
|
$ssoUser = Socialite::driver('eveonline')->user();
|
||||||
|
|
||||||
$scpSession = session()->pull('scopes');
|
|
||||||
|
|
||||||
//If the user was already logged in, let's do some checks to see if we are adding
|
|
||||||
//additional scopes to the user's account
|
|
||||||
if(Auth::check()) {
|
if(Auth::check()) {
|
||||||
//If we are logged in already and the session contains the original characters, then we are creating an alt
|
//If a refresh token is present, then we are doing a scope callback
|
||||||
//for the original character
|
//to update scopes for an access token
|
||||||
if(session()->has('orgCharacter')) {
|
|
||||||
$orgCharacter = session()->pull('orgCharacter');
|
|
||||||
|
|
||||||
if($this->createAlt($ssoUser, $orgCharacter)) {
|
if(isset($ssoUser->refreshToken)) {
|
||||||
return redirect()->to('/profile')->with('success', 'Alt registered.');
|
//See if an access token is present already
|
||||||
} else {
|
$tokenCount = EsiToken::where('character_id', $ssoUser->id)->count();
|
||||||
return redirect()->to('/profile')->with('error', 'Unable to register alt or it was previously registered.');
|
if($tokenCount > 0) {
|
||||||
|
//Update the esi token
|
||||||
|
$this->UpdateEsiToken($ssoUser);
|
||||||
|
} else {
|
||||||
|
//Save the ESI token
|
||||||
|
$this->SaveEsiToken($ssoUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//After creating the token, we need to update the table for scopes
|
||||||
|
$this->SetScopes($ssoUser->user['Scopes'], $ssoUser->id);
|
||||||
|
|
||||||
|
return redirect()->to('/dashboard')->with('success', 'Successfully updated ESI Scopes.');
|
||||||
} else {
|
} else {
|
||||||
if(sizeof($ssoUser->scopes) > 1) {
|
$created = $this->createAlt($ssoUser);
|
||||||
$tokenCount = EsiToken::where([
|
if($created == 1) {
|
||||||
'character_id' => $ssoUser->id,
|
return redirect()->to('/profile')->with('success', 'Alt registered.');
|
||||||
])->count();
|
} else {
|
||||||
if($tokenCount > 0) {
|
return redirect()->to('/profile')->with('error', 'Alt was previously registered.');
|
||||||
$this->UpdateEsiToken($ssoUser);
|
|
||||||
} else {
|
|
||||||
$this->SaveEsiToken($ssoUser);
|
|
||||||
}
|
|
||||||
$this->SetScopes($ssoUser->scopes, $ssoUser->id);
|
|
||||||
return redirect()->to('/dashboard')->with('success', 'Successfully updated ESI scopes.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//If the user wasn't logged in, then create a new user
|
|
||||||
$user = $this->createOrGetUser($ssoUser);
|
$user = $this->createOrGetUser($ssoUser);
|
||||||
//Login in the new user
|
|
||||||
auth()->login($user, true);
|
auth()->login($user, true);
|
||||||
//Redirect back to the dashboard
|
|
||||||
return redirect()->to('/dashboard')->with('success', 'Successfully Logged In.');
|
return redirect()->to('/dashboard')->with('success', 'Successfully Logged In.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,19 +127,12 @@ class LoginController extends Controller
|
|||||||
*
|
*
|
||||||
* @param \Laravel\Socialite\Two\User $user
|
* @param \Laravel\Socialite\Two\User $user
|
||||||
*/
|
*/
|
||||||
private function createAlt($user, $orgCharacter) {
|
private function createAlt($user) {
|
||||||
//Check to see if the alt is already in the database
|
$altCount = UserAlt::where('character_id', $user->id)->count();
|
||||||
$altCount = UserAlt::where(['character_id' => $user->id])->count();
|
if($altCount == 0) {
|
||||||
|
|
||||||
//Check to see if the new character being added is already a main character
|
|
||||||
$mainCount = User::where(['character_id' => $user->id])->count();
|
|
||||||
|
|
||||||
//If not already in the database, then add the new character
|
|
||||||
if($altCount == 0 && $mainCount == 0) {
|
|
||||||
//Create the new alt in the table
|
|
||||||
$newAlt = new UserAlt;
|
$newAlt = new UserAlt;
|
||||||
$newAlt->name = $user->getName();
|
$newAlt->name = $user->getName();
|
||||||
$newAlt->main_id = $orgCharacter;
|
$newAlt->main_id = auth()->user()->getId();
|
||||||
$newAlt->character_id = $user->id;
|
$newAlt->character_id = $user->id;
|
||||||
$newAlt->avatar = $user->avatar;
|
$newAlt->avatar = $user->avatar;
|
||||||
$newAlt->access_token = $user->token;
|
$newAlt->access_token = $user->token;
|
||||||
@@ -179,22 +140,8 @@ class LoginController extends Controller
|
|||||||
$newAlt->inserted_at = time();
|
$newAlt->inserted_at = time();
|
||||||
$newAlt->expires_in = $user->expiresIn;
|
$newAlt->expires_in = $user->expiresIn;
|
||||||
$newAlt->save();
|
$newAlt->save();
|
||||||
|
|
||||||
//Create the entry into the EsiToken table
|
|
||||||
if(EsiToken::where(['character_id' => $user->id])->count() == 0) {
|
|
||||||
$this->SaveEsiToken($user);
|
|
||||||
} else {
|
|
||||||
$this->UpdateEsiToken($user);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create the entry into the EsiScopes table
|
|
||||||
if(sizeof($user->scopes) > 1) {
|
|
||||||
$this->SetScopes($user->scopes, $user->id);
|
|
||||||
}
|
|
||||||
//Return the successfull conclusion of the function
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
//Return the unsuccessfull conclusion of the function
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,48 +152,44 @@ class LoginController extends Controller
|
|||||||
*
|
*
|
||||||
* @param \Laravel\Socialite\Two\User $user
|
* @param \Laravel\Socialite\Two\User $user
|
||||||
*/
|
*/
|
||||||
private function createOrGetUser($eveUser) {
|
private function createOrGetUser($eve_user) {
|
||||||
$authUser = null;
|
$authUser = null;
|
||||||
|
|
||||||
//Search to see if we have a matching user in the database.
|
//Search to see if we have a matching user in the database.
|
||||||
//At this point we don't care about the information
|
//At this point we don't care about the information
|
||||||
$userCount = User::where([
|
$userCount = User::where('character_id', $eve_user->id)->count();
|
||||||
'character_id' => $eveUser->id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
//If the user is found, do more checks to see what type of login we are doing
|
//If the user is found, do more checks to see what type of login we are doing
|
||||||
if($userCount > 0) {
|
if($userCount > 0) {
|
||||||
//Search for user in the database
|
//Search for user in the database
|
||||||
$authUser = User::where([
|
$authUser = User::where('character_id', $eve_user->id)->first();
|
||||||
'character_id' => $eveUser->id,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
//Check to see if the owner has changed
|
//Check to see if the owner has changed
|
||||||
//If the owner has changed, then update their roles and permissions
|
//If the owner has changed, then update their roles and permissions
|
||||||
if($this->OwnerHasChanged($authUser->owner_hash, $eveUser->owner_hash)) {
|
if($this->OwnerHasChanged($authUser->owner_hash, $eve_user->owner_hash)) {
|
||||||
//Get the right role for the user
|
//Get the right role for the user
|
||||||
$role = $this->GetRole(null, $eveUser->id);
|
$role = $this->GetRole(null, $eve_user->id);
|
||||||
//Set the role for the user
|
//Set the role for the user
|
||||||
$this->SetRole($role, $eveUser->id);
|
$this->SetRole($role, $eve_user->id);
|
||||||
|
|
||||||
//Update the user information never the less.
|
//Update the user information never the less.
|
||||||
$this->UpdateUser($eveUser, $role);
|
$this->UpdateUser($eve_user, $role);
|
||||||
|
|
||||||
//Update the user's roles and permission
|
//Update the user's roles and permission
|
||||||
$this->UpdatePermission($eveUser, $role);
|
$this->UpdatePermission($eve_user, $role);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return the user to the calling auth function
|
//Return the user to the calling auth function
|
||||||
return $authUser;
|
return $authUser;
|
||||||
} else {
|
} else {
|
||||||
//Get the role for the character to be stored in the database
|
//Get the role for the character to be stored in the database
|
||||||
$role = $this->GetRole(null, $eveUser->id);
|
$role = $this->GetRole(null, $eve_user->id);
|
||||||
|
|
||||||
//Create the user account
|
//Create the user account
|
||||||
$user = $this->CreateNewUser($eveUser);
|
$user = $this->CreateNewUser($eve_user);
|
||||||
|
|
||||||
//Set the role for the user
|
//Set the role for the user
|
||||||
$this->SetRole($role, $eveUser->id);
|
$this->SetRole($role, $eve_user->id);
|
||||||
|
|
||||||
//Create a user account
|
//Create a user account
|
||||||
return $user;
|
return $user;
|
||||||
@@ -256,45 +199,45 @@ class LoginController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Update the ESI Token
|
* Update the ESI Token
|
||||||
*/
|
*/
|
||||||
private function UpdateEsiToken($eveUser) {
|
private function UpdateEsiToken($eve_user) {
|
||||||
EsiToken::where('character_id', $eveUser->id)->update([
|
EsiToken::where('character_id', $eve_user->id)->update([
|
||||||
'character_id' => $eveUser->getId(),
|
'character_id' => $eve_user->getId(),
|
||||||
'access_token' => $eveUser->token,
|
'access_token' => $eve_user->token,
|
||||||
'refresh_token' => $eveUser->refreshToken,
|
'refresh_token' => $eve_user->refreshToken,
|
||||||
'inserted_at' => time(),
|
'inserted_at' => time(),
|
||||||
'expires_in' => $eveUser->expiresIn,
|
'expires_in' => $eve_user->expiresIn,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ESI Token in the database
|
* Create a new ESI Token in the database
|
||||||
*/
|
*/
|
||||||
private function SaveEsiToken($eveUser) {
|
private function SaveEsiToken($eve_user) {
|
||||||
$token = new EsiToken;
|
$token = new EsiToken;
|
||||||
$token->character_id = $eveUser->id;
|
$token->character_id = $eve_user->id;
|
||||||
$token->access_token = $eveUser->token;
|
$token->access_token = $eve_user->token;
|
||||||
$token->refresh_token = $eveUser->refreshToken;
|
$token->refresh_token = $eve_user->refreshToken;
|
||||||
$token->inserted_at = time();
|
$token->inserted_at = time();
|
||||||
$token->expires_in = $eveUser->expiresIn;
|
$token->expires_in = $eve_user->expiresIn;
|
||||||
$token->save();
|
$token->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update avatar
|
* Update avatar
|
||||||
*/
|
*/
|
||||||
private function UpdateAvatar($eveUser) {
|
private function UpdateAvatar($eve_user) {
|
||||||
User::where('character_id', $eveUser->id)->update([
|
User::where('character_id', $eve_user->id)->update([
|
||||||
'avatar' => $eveUser->avatar,
|
'avatar' => $eve_user->avatar,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update user permission
|
* Update user permission
|
||||||
*/
|
*/
|
||||||
private function UpdatePermission($eveUser, $role) {
|
private function UpdatePermission($eve_user, $role) {
|
||||||
UserPermission::where(['character_id' => $eveUser->id])->delete();
|
UserPermission::where(['character_id' => $eve_user->id])->delete();
|
||||||
$perm = new UserPermission();
|
$perm = new UserPermission();
|
||||||
$perm->character_id = $eveUser->id;
|
$perm->character_id = $eve_user->id;
|
||||||
$perm->permission = $role;
|
$perm->permission = $role;
|
||||||
$perm->save();
|
$perm->save();
|
||||||
}
|
}
|
||||||
@@ -302,10 +245,10 @@ class LoginController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Update the user
|
* Update the user
|
||||||
*/
|
*/
|
||||||
private function UpdateUser($eveUser, $role) {
|
private function UpdateUser($eve_user, $role) {
|
||||||
User::where('character_id', $eveUser->id)->update([
|
User::where('character_id', $eve_user->id)->update([
|
||||||
'avatar' => $eveUser->avatar,
|
'avatar' => $eve_user->avatar,
|
||||||
'owner_hash' => $eveUser->owner_hash,
|
'owner_hash' => $eve_user->owner_hash,
|
||||||
'role' => $role,
|
'role' => $role,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -313,41 +256,17 @@ class LoginController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Create a new user account
|
* Create a new user account
|
||||||
*/
|
*/
|
||||||
private function CreateNewUser($eveUser) {
|
private function CreateNewUser($eve_user) {
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'name' => $eveUser->getName(),
|
'name' => $eve_user->getName(),
|
||||||
'avatar' => $eveUser->avatar,
|
'avatar' => $eve_user->avatar,
|
||||||
'owner_hash' => $eveUser->owner_hash,
|
'owner_hash' => $eve_user->owner_hash,
|
||||||
'character_id' => $eveUser->getId(),
|
'character_id' => $eve_user->getId(),
|
||||||
'inserted_at' => time(),
|
'inserted_at' => time(),
|
||||||
'expires_in' => $eveUser->expiresIn,
|
'expires_in' => $eve_user->expiresIn,
|
||||||
'user_type' => $this->GetAccountType(null, $eveUser->id),
|
'access_token' => $eve_user->token,
|
||||||
|
'user_type' => $this->GetAccountType(null, $eve_user->id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Look for an existing token for the characters
|
|
||||||
$tokenFound = EsiToken::where([
|
|
||||||
'character_id' => $eveUser->id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($tokenFound == 0) {
|
|
||||||
$token = new EsiToken;
|
|
||||||
$token->character_id = $eveUser->id;
|
|
||||||
$token->access_token = $eveUser->token;
|
|
||||||
$token->refresh_token = $eveUser->refreshToken;
|
|
||||||
$token->inserted_at = time();
|
|
||||||
$token->expires_in = $eveUser->expiresIn;
|
|
||||||
$token->save();
|
|
||||||
} else {
|
|
||||||
EsiToken::where([
|
|
||||||
'character_id' => $eveUser->id,
|
|
||||||
])->update([
|
|
||||||
'character_id' => $eveUser->id,
|
|
||||||
'access_token' => $eveUser->token,
|
|
||||||
'refresh_token' => $eveUser->refreshToken,
|
|
||||||
'inserted_at' => time(),
|
|
||||||
'expires_in' => $eveUser->expiresIn,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
@@ -374,6 +293,7 @@ class LoginController extends Controller
|
|||||||
private function SetScopes($scopes, $charId) {
|
private function SetScopes($scopes, $charId) {
|
||||||
//Delete the current scopes, so we can add new scopes into the database
|
//Delete the current scopes, so we can add new scopes into the database
|
||||||
EsiScope::where('character_id', $charId)->delete();
|
EsiScope::where('character_id', $charId)->delete();
|
||||||
|
$scopes = explode(' ', $scopes);
|
||||||
foreach($scopes as $scope) {
|
foreach($scopes as $scope) {
|
||||||
$data = new EsiScope;
|
$data = new EsiScope;
|
||||||
$data->character_id = $charId;
|
$data->character_id = $charId;
|
||||||
@@ -430,7 +350,6 @@ class LoginController extends Controller
|
|||||||
private function GetAccountType($refreshToken, $charId) {
|
private function GetAccountType($refreshToken, $charId) {
|
||||||
//Declare some variables
|
//Declare some variables
|
||||||
$esiHelper = new Esi;
|
$esiHelper = new Esi;
|
||||||
$lookup = new LookupHelper;
|
|
||||||
|
|
||||||
//Instantiate a new ESI isntance
|
//Instantiate a new ESI isntance
|
||||||
$esi = $esiHelper->SetupEsiAuthentication();
|
$esi = $esiHelper->SetupEsiAuthentication();
|
||||||
@@ -440,10 +359,10 @@ class LoginController extends Controller
|
|||||||
$configuration->cache = NullCache::class;
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
//Get the character information
|
//Get the character information
|
||||||
$character_info = $lookup->GetCharacterInfo($charId);
|
$character_info = $esiHelper->GetCharacterData($charId);
|
||||||
|
|
||||||
//Get the corporation information
|
//Get the corporation information
|
||||||
$corp_info = $lookup->GetCorporationInfo($character_info->corporation_id);
|
$corp_info = $esiHelper->GetCorporationData($character_info->corporation_id);
|
||||||
|
|
||||||
if($character_info == null || $corp_info == null) {
|
if($character_info == null || $corp_info == null) {
|
||||||
return redirect('/')->with('error', 'Could not create user at this time.');
|
return redirect('/')->with('error', 'Could not create user at this time.');
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use Log;
|
|||||||
use DB;
|
use DB;
|
||||||
|
|
||||||
//Library
|
//Library
|
||||||
use App\Library\Helpers\LookupHelper;
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Blacklist\BlacklistEntity;
|
use App\Models\Blacklist\BlacklistEntity;
|
||||||
@@ -38,7 +38,7 @@ class BlacklistController extends Controller
|
|||||||
|
|
||||||
public function AddToBlacklist(Request $request) {
|
public function AddToBlacklist(Request $request) {
|
||||||
//Middleware needed for the function
|
//Middleware needed for the function
|
||||||
$this->middleware('permission:blacklist.admin');
|
$this->middleware('permission:alliance.recruiter');
|
||||||
|
|
||||||
//Validate the user input
|
//Validate the user input
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
@@ -84,16 +84,15 @@ class BlacklistController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Store the entity in the table
|
//Store the entity in the table
|
||||||
$blacklist = new BlacklistEntity;
|
BlacklistEntity::insert([
|
||||||
$blacklist->entity_id = $entityId;
|
'entity_id' => $entityId,
|
||||||
$blacklist->entity_name = $request->name;
|
'entity_name' => $request->name,
|
||||||
$blacklist->entity_type = $request->type;
|
'entity_type' => $request->type,
|
||||||
$blacklist->reason = $request->reason;
|
'reason' => $request->reason,
|
||||||
$blacklist->alts = $request->alts;
|
'alts' => $request->alts,
|
||||||
$blacklist->lister_id = auth()->user()->getId();
|
'lister_id' => auth()->user()->getId(),
|
||||||
$blacklist->lister_name = auth()->user()->getName();
|
'lister_name' => auth()->user()->getName(),
|
||||||
$blacklist->validity = 'Valid';
|
]);
|
||||||
$blacklist->save();
|
|
||||||
|
|
||||||
//Return to the view
|
//Return to the view
|
||||||
return redirect('/blacklist/display/add')->with('success', $request->name . ' added to the blacklist.');
|
return redirect('/blacklist/display/add')->with('success', $request->name . ' added to the blacklist.');
|
||||||
@@ -109,22 +108,17 @@ class BlacklistController extends Controller
|
|||||||
|
|
||||||
public function RemoveFromBlacklist(Request $request) {
|
public function RemoveFromBlacklist(Request $request) {
|
||||||
//Middleware needed
|
//Middleware needed
|
||||||
$this->middleware('permission:blacklist.admin');
|
$this->middleware('permission:alliance.recruiter');
|
||||||
|
|
||||||
//Validate the input request
|
//Validate the input request
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Set the character on the blacklist to removed
|
//Delete the blacklist character
|
||||||
BlacklistEntity::where([
|
BlacklistEntity::where([
|
||||||
'entity_name' => $request->name,
|
'entity_name' => $request->name,
|
||||||
])->update([
|
])->delete();
|
||||||
'validity' => 'Invalid',
|
|
||||||
'removed_by_id' => auth()->user()->getId(),
|
|
||||||
'removed_by_name' => auth()->user()->getName(),
|
|
||||||
'removed_notes' => $request->notes,
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Return the view
|
//Return the view
|
||||||
return redirect('/blacklist/display')->with('success', 'Character removed from the blacklist.');
|
return redirect('/blacklist/display')->with('success', 'Character removed from the blacklist.');
|
||||||
@@ -133,9 +127,7 @@ class BlacklistController extends Controller
|
|||||||
public function DisplayBlacklist() {
|
public function DisplayBlacklist() {
|
||||||
|
|
||||||
//Get the entire blacklist
|
//Get the entire blacklist
|
||||||
$blacklist = BlacklistEntity::where([
|
$blacklist = BlacklistEntity::orderBy('entity_name', 'asc')->paginate(50);
|
||||||
'validity' => 'Valid',
|
|
||||||
])->orderBy('entity_name', 'asc')->paginate(50);
|
|
||||||
|
|
||||||
//Return the view with the data
|
//Return the view with the data
|
||||||
return view('blacklist.list')->with('blacklist', $blacklist);
|
return view('blacklist.list')->with('blacklist', $blacklist);
|
||||||
@@ -149,9 +141,9 @@ class BlacklistController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$blacklist = DB::table('alliance_blacklist')->where('entity_name', 'like', $request->parameter . "%")
|
$blacklist = DB::table('alliance_blacklist')->where('entity_name', 'like', $request->parameter . "%")
|
||||||
->orWhere('entity_type', 'like', "%" . $request->parameter . "%")
|
->orWhere('entity_type', 'like', $request->parameter . "%")
|
||||||
->orWhere('alts', 'like', "%" . $request->parameter . "%")
|
->orWhere('alts', 'like', $request->parameter . "%")
|
||||||
->orWhere('reason', 'like', "%" . $request->parameter . "%")
|
->orWhere('reason', 'like', $request->parameter . "%")
|
||||||
->orderBy('entity_name', 'asc')
|
->orderBy('entity_name', 'asc')
|
||||||
->paginate(50);
|
->paginate(50);
|
||||||
|
|
||||||
|
|||||||
198
app/Http/Controllers/Contracts/ContractAdminController.php
Normal file
198
app/Http/Controllers/Contracts/ContractAdminController.php
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Contracts;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Libraries
|
||||||
|
use App\Library\Esi\Mail;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\User\User;
|
||||||
|
use App\Models\User\UserPermission;
|
||||||
|
use App\Models\Contracts\Contract;
|
||||||
|
use App\Models\Contracts\Bid;
|
||||||
|
use App\Models\Contracts\AcceptedBid;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
|
class ContractAdminController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:User');
|
||||||
|
$this->middleware('permission:contract.admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contract display functions
|
||||||
|
*/
|
||||||
|
public function displayContractDashboard() {
|
||||||
|
$contracts = Contract::where(['finished' => false])->get();
|
||||||
|
|
||||||
|
return view('contracts.admin.contractpanel')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayPastContracts() {
|
||||||
|
$contracts = Contract::where(['finished' => true])->get();
|
||||||
|
|
||||||
|
return view('contracs.admin.past')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New contract functionality
|
||||||
|
*/
|
||||||
|
public function displayNewContract() {
|
||||||
|
return view('contracts.admin.newcontract');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeNewContract(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'name' => 'required',
|
||||||
|
'date' => 'required',
|
||||||
|
'body' => 'required',
|
||||||
|
'type' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$date = new Carbon($request->date);
|
||||||
|
$body = nl2br($request->body);
|
||||||
|
|
||||||
|
//Store the contract in the database
|
||||||
|
$contract = new Contract;
|
||||||
|
$contract->title = $request->name;
|
||||||
|
$contract->end_date = $request->date;
|
||||||
|
$contract->body = $body;
|
||||||
|
$contract->type = $request->type;
|
||||||
|
$contract->save();
|
||||||
|
|
||||||
|
//Send a mail out to all of the people who can bid on a contract
|
||||||
|
$this->NewContractMail();
|
||||||
|
|
||||||
|
return redirect('/contracts/admin/display')->with('success', 'Contract written.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to store a finished contract in the database
|
||||||
|
*/
|
||||||
|
public function storeAcceptContract(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'contract_id' => 'required',
|
||||||
|
'bid_id' => 'required',
|
||||||
|
'character_id' => 'required',
|
||||||
|
'bid_amount' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the contract
|
||||||
|
Contract::where([
|
||||||
|
'contract_id' => $request->contract_id,
|
||||||
|
])->update([
|
||||||
|
'finished' => true,
|
||||||
|
'final_cost' => $request->bid_amount,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Save the accepted bid in the database
|
||||||
|
$accepted = new AcceptedBid;
|
||||||
|
$accepted->contract_id = $request->contract_id;
|
||||||
|
$accepted->bid_id = $request->bid_id;
|
||||||
|
$accepted->bid_amount = $request->bid_amount;
|
||||||
|
$accepted->save();
|
||||||
|
|
||||||
|
return redirect('/contracts/admin/display')->with('success', 'Contract accepted and closed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a contract from every user
|
||||||
|
*/
|
||||||
|
public function deleteContract($id) {
|
||||||
|
|
||||||
|
Contract::where(['contract_id' => $id])->delete();
|
||||||
|
|
||||||
|
Bid::where(['contract_id' => $id])->delete();
|
||||||
|
|
||||||
|
return redirect('/contracts/admin/display')->with('success', 'Contract has been deleted.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End Contract Functionality
|
||||||
|
*/
|
||||||
|
public function displayEndContract($id) {
|
||||||
|
//Gather the information for the contract, and all bids on the contract
|
||||||
|
$contract = Contract::where(['contract_id' => $id])->first()->toArray();
|
||||||
|
$bids = Bid::where(['contract_id' => $id])->get()->toArray();
|
||||||
|
|
||||||
|
return view('contracts.admin.displayend')->with('contract', $contract)
|
||||||
|
->with('bids', $bids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeEndContract(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'contract_id' => 'required',
|
||||||
|
'accept' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare class variables
|
||||||
|
$tries = 1;
|
||||||
|
|
||||||
|
//Get the esi config
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
$contract = Contract::where(['contract_id' => $request->contract_id])->first()->toArray();
|
||||||
|
$bid = Bid::where(['id' => $request->accept, 'contract_id' => $request->contract_id])->first()->toArray();
|
||||||
|
|
||||||
|
//Send mail out to winner of the contract
|
||||||
|
$subject = 'Contract Won';
|
||||||
|
$body = 'You have been accepted to perform the following contract:<br>';
|
||||||
|
$body .= $contract['contract_id'] . ' : ' . $contract['title'] . '<br>';
|
||||||
|
$body .= 'Notes:<br>';
|
||||||
|
$body .= $contract['body'] . '<br>';
|
||||||
|
$body .= 'Please remit contract when the items are ready to Spatial Forces. Description should be the contract identification number. Request ISK should be the bid amount.';
|
||||||
|
$body .= 'Sincerely,<br>Spatial Forces Contracting Department';
|
||||||
|
|
||||||
|
//Setup the mail job
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->subject = $subject;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
$mail->recipient = $bid['character_id'];
|
||||||
|
$mail->body = $body;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
//Dispatch the mail job
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
|
||||||
|
|
||||||
|
//Tidy up the contract by doing a few things.
|
||||||
|
$this->TidyContract($contract, $bid);
|
||||||
|
|
||||||
|
//Redirect back to the contract admin dashboard.
|
||||||
|
return redirect('/contracts/admin/display')->with('success', 'Contract finalized. Mail has been sent to the queue for processing.');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function TidyContract($contract, $bid) {
|
||||||
|
Contract::where(['contract_id' => $contract['contract_id']])->update([
|
||||||
|
'finished' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Create the accepted contract entry into the table
|
||||||
|
$accepted = new AcceptedBid;
|
||||||
|
$accepted->contract_id = $contract['contract_id'];
|
||||||
|
$accepted->bid_id = $bid['id'];
|
||||||
|
$accepted->bid_amount = $bid['bid_amount'];
|
||||||
|
$accepted->notes = $bid['notes'];
|
||||||
|
$accepted->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function NewContractMail() {
|
||||||
|
//Get the esi config
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = 'New Alliance Production Contract Available';
|
||||||
|
$mail->recipient = $config['alliance'];
|
||||||
|
$mail->recipient_type = 'alliance';
|
||||||
|
$mail->body = "A new contract is available for the alliance contracting system. Please check out <a href='https://services.w4rp.space'>Services Site</a> if you want to bid on the production contract.<br><br>Sincerely,<br>Warped Intentions Leadership";
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
|
||||||
|
}
|
||||||
|
}
|
||||||
322
app/Http/Controllers/Contracts/ContractController.php
Normal file
322
app/Http/Controllers/Contracts/ContractController.php
Normal file
@@ -0,0 +1,322 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Contracts;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Libraries
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\User\User;
|
||||||
|
use App\Models\User\UserPermission;
|
||||||
|
use App\Models\Contracts\Contract;
|
||||||
|
use App\Models\Contracts\Bid;
|
||||||
|
|
||||||
|
class ContractController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:User');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display the bids placed on contracts
|
||||||
|
*/
|
||||||
|
public function displayBids($id) {
|
||||||
|
$bids = Bids::where(['contract_id' => $id, 'character_name' => auth()->user()->getName()])->get();
|
||||||
|
|
||||||
|
return view('contracts.bids')->with('bids', $bids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Controller function to display all current open contracts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function displayContracts() {
|
||||||
|
//Calculate today's date to know which contracts to display
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
//Declare our array variables
|
||||||
|
$bids = array();
|
||||||
|
$contracts = array();
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
//Fetch all of the current contracts from the database
|
||||||
|
$contractsTemp = Contract::where('end_date', '>=', $today)
|
||||||
|
->where(['finished' => false])->get()->toArray();
|
||||||
|
|
||||||
|
//Count the number of bids, and add them to the arrays
|
||||||
|
for($i = 0; $i < sizeof($contractsTemp); $i++) {
|
||||||
|
$tempCount = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->count('contract_id');
|
||||||
|
$bids = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->get()->toArray();
|
||||||
|
|
||||||
|
//Assemble the finaly array
|
||||||
|
$contracts[$i] = $contractsTemp[$i];
|
||||||
|
$contracts[$i]['bid_count'] = $tempCount;
|
||||||
|
$contracts[$i]['bids'] = $bids;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Call for the view to be displayed
|
||||||
|
return view('contracts.allcontracts')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display all current public contracts
|
||||||
|
*/
|
||||||
|
public function displayPublicContracts() {
|
||||||
|
//Calculate today's date to know which contracts to display
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
//Declare our array variables
|
||||||
|
$bids = array();
|
||||||
|
$contracts = array();
|
||||||
|
$i = 0;
|
||||||
|
$lowestBid = null;
|
||||||
|
$lowestCorp = null;
|
||||||
|
$lowestChar = null;
|
||||||
|
|
||||||
|
//Fetch all of the current contracts from the database
|
||||||
|
$contractsTemp = Contract::where('end_date', '>=', $today)
|
||||||
|
->where(['type' => 'Public', 'finished' => false])->get()->toArray();
|
||||||
|
|
||||||
|
//Count the number of bids, and add them to the arrays
|
||||||
|
for($i = 0; $i < sizeof($contractsTemp); $i++) {
|
||||||
|
$tempCount = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->count('contract_id');
|
||||||
|
$bids = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->get()->toArray();
|
||||||
|
|
||||||
|
foreach($bids as $bid) {
|
||||||
|
if($lowestBid == null) {
|
||||||
|
$lowestBid = $bid['bid_amount'];
|
||||||
|
$lowestCorp = $bid['corporation_name'];
|
||||||
|
$lowestChar = $bid['character_name'];
|
||||||
|
} else {
|
||||||
|
if($bid['bid_amount'] < $lowestBid) {
|
||||||
|
$lowestBid = $bid['bid_amount'];
|
||||||
|
$lowestCorp = $bid['corporation_name'];
|
||||||
|
$lowestChar = $bid['character_name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lowestBid == null) {
|
||||||
|
$lowestBid = 'No Bids Placed.';
|
||||||
|
$lowestCorp = 'No Corporation has placed a bid.';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Assemble the finaly array
|
||||||
|
$contracts[$i] = $contractsTemp[$i];
|
||||||
|
$contracts[$i]['bid_count'] = $tempCount;
|
||||||
|
$contracts[$i]['bids'] = $bids;
|
||||||
|
$contracts[$i]['lowestbid'] = $lowestBid;
|
||||||
|
$contracts[$i]['lowestcorp'] = $lowestCorp;
|
||||||
|
$contracts[$i]['lowestchar'] = $lowestChar;
|
||||||
|
|
||||||
|
//Reset the lowestBid back to null
|
||||||
|
$lowestBid = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Call for the view to be displayed
|
||||||
|
return view('contracts.publiccontracts')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display current private contracts
|
||||||
|
*/
|
||||||
|
public function displayPrivateContracts() {
|
||||||
|
//Declare our array variables
|
||||||
|
$bids = array();
|
||||||
|
$contracts = array();
|
||||||
|
$lowestBid = null;
|
||||||
|
|
||||||
|
//Calucate today's date to know which contracts to display
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
//Fetch all of the current contracts from the database
|
||||||
|
$contractsTemp = Contract::where('end_date', '>=', $today)
|
||||||
|
->where(['type' => 'Private', 'finished' => false])->get();
|
||||||
|
|
||||||
|
//Count the number of bids, and add them to the arrays
|
||||||
|
for($i = 0; $i < sizeof($contractsTemp); $i++) {
|
||||||
|
$tempCount = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->count('contract_id');
|
||||||
|
$bids = Bid::where(['contract_id' => $contractsTemp[$i]['contract_id']])->get()->toArray();
|
||||||
|
|
||||||
|
foreach($bids as $bid) {
|
||||||
|
if($lowestBid == null) {
|
||||||
|
$lowestBid = $bid['bid_amount'];
|
||||||
|
} else {
|
||||||
|
if($bid['bid_amount'] < $lowestBid) {
|
||||||
|
$lowestBid = $bid['bid_amount'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lowestBid == null) {
|
||||||
|
$lowestBid = 'No Bids Placed.';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Assemble the finaly array
|
||||||
|
$contracts[$i] = $contractsTemp[$i];
|
||||||
|
$contracts[$i]['bid_count'] = $tempCount;
|
||||||
|
$contracts[$i]['bids'] = $bids;
|
||||||
|
$contracts[$i]['lowestbid'] = $lowestBid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view ('contracts.privatecontracts')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display expired contracts
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function displayExpiredContracts() {
|
||||||
|
//Calculate today's date to know which contracts to display
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
//Retrieve the contracts from the database
|
||||||
|
$contracts = Contract::where('end_date', '<', $today)->get();
|
||||||
|
|
||||||
|
return view('contracts.expiredcontracts')->with('contracts', $contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display a page to allow a bid
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function displayNewBid($id) {
|
||||||
|
|
||||||
|
$contractId = $id;
|
||||||
|
|
||||||
|
return view('contracts.enterbid')->with('contractId', $contractId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to store a new bid
|
||||||
|
*/
|
||||||
|
public function storeBid(Request $request) {
|
||||||
|
//Valid the request from the enter bid page
|
||||||
|
$this->validate($request, [
|
||||||
|
'contract_id' => 'required',
|
||||||
|
'bid' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Delcare some class variables we will need
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
$amount = 0.00;
|
||||||
|
|
||||||
|
//Convert the amount to a whole number from abbreviations
|
||||||
|
if($request->suffix == 'B') {
|
||||||
|
$amount = $request->bid * 1000000000.00;
|
||||||
|
} else if($request->suffix == 'M') {
|
||||||
|
$amount = $request->bid * 1000000.00;
|
||||||
|
} else {
|
||||||
|
$amount = $request->bid * 1.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($request->notes)) {
|
||||||
|
$notes = nl2br($request->notes);
|
||||||
|
} else {
|
||||||
|
$notes = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the character id and character name from the auth of the user calling
|
||||||
|
//this function
|
||||||
|
$characterId = auth()->user()->getId();
|
||||||
|
$characterName = auth()->user()->getName();
|
||||||
|
//Use the lookup helper in order to find the user's corporation id and name
|
||||||
|
$char = $lookup->GetCharacterInfo($characterId);
|
||||||
|
$corporationId = $char->corporation_id;
|
||||||
|
//use the lookup helper in order to find the corporation's name from it's id.
|
||||||
|
$corp = $lookup->GetCorporationInfo($corporationId);
|
||||||
|
$corporationName = $corp->name;
|
||||||
|
|
||||||
|
//Before saving a bid let's check to see if the user already placed a bid on the contract
|
||||||
|
$found = Bid::where([
|
||||||
|
'contract_id' => $request->contract_id,
|
||||||
|
'character_id' => $characterId,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if(isset($found->contract_id)) {
|
||||||
|
return redirect('/contracts/display/all')->with('error', 'You have already placed a bid for this contract. Please modify the existing bid.');
|
||||||
|
} else {
|
||||||
|
//Create the model object to save data to
|
||||||
|
$bid = new Bid;
|
||||||
|
$bid->contract_id = $request->contract_id;
|
||||||
|
$bid->bid_amount = $amount;
|
||||||
|
$bid->character_id = $characterId;
|
||||||
|
$bid->character_name = $characterName;
|
||||||
|
$bid->corporation_id = $corporationId;
|
||||||
|
$bid->corporation_name = $corporationName;
|
||||||
|
$bid->notes = $notes;
|
||||||
|
$bid->save();
|
||||||
|
|
||||||
|
//Redirect to the correct page
|
||||||
|
return redirect('/contracts/display/all')->with('success', 'Bid accepted.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to delete a bid
|
||||||
|
*/
|
||||||
|
public function deleteBid($id) {
|
||||||
|
//Delete the bid entry from the database
|
||||||
|
Bid::where([
|
||||||
|
'id' => $id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
return redirect('/contracts/display/public')->with('success', 'Bid deleted.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to display modify bid page
|
||||||
|
*/
|
||||||
|
public function displayModifyBid($id) {
|
||||||
|
//With the bid id number, look up the bid in the database to get the contract information
|
||||||
|
$bid = Bid::where(['id' => $id])->first();
|
||||||
|
|
||||||
|
//Retrieve the contract from the database
|
||||||
|
$contract = Contract::where(['contract_id' => $bid->contract_id])->first()->toArray();
|
||||||
|
|
||||||
|
return view('contracts.modifybid')->with('contract', $contract)
|
||||||
|
->with('bid', $bid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller function to modify a bid
|
||||||
|
*/
|
||||||
|
public function modifyBid(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'bid' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$amount = $request->bid;
|
||||||
|
$type = $request->type;
|
||||||
|
$contractId = $request->contract_id;
|
||||||
|
|
||||||
|
if($request->suffix == 'B') {
|
||||||
|
$amount = $amount * 1000000000.00;
|
||||||
|
} else if($request->suffix == 'M') {
|
||||||
|
$amount = $amount * 1000000.00;
|
||||||
|
} else {
|
||||||
|
$amount = $amount * 1.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bid::where([
|
||||||
|
'character_id' => auth()->user()->getId(),
|
||||||
|
'contract_id' => $contractId,
|
||||||
|
])->update([
|
||||||
|
'bid_amount' => $amount,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($type == 'public') {
|
||||||
|
return redirect('/contracts/display/public')->with('success', 'Bid modified.');
|
||||||
|
} else {
|
||||||
|
return redirect('/contracts/display/private')->with('success', 'Bid modified');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,501 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Contracts;
|
|
||||||
|
|
||||||
//Internal Libraries
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Libraries
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\Contracts\SupplyChainBid;
|
|
||||||
use App\Models\Contracts\SupplyChainContract;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class SupplyChainController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('role:Renter');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the supply chain dashboard
|
|
||||||
* Should contain a section for open contracts, closed contracts, and expired contracts.
|
|
||||||
*/
|
|
||||||
public function displaySupplyChainDashboard() {
|
|
||||||
$openContracts = SupplyChainContract::where([
|
|
||||||
'state' => 'open',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
$closedContracts = SupplyChainContract::where([
|
|
||||||
'state' => 'closed',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
$completedContracts = SupplyChainContract::where([
|
|
||||||
'state' => 'completed',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
return view('supplychain.dashboard.main')->with('openContracts', $openContracts)
|
|
||||||
->with('closedContracts', $closedContracts)
|
|
||||||
->with('completedContracts', $completedContracts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display my supply chain contracts dashboard
|
|
||||||
* Should contain a section for open contracts, closed contracts, and expired contracts
|
|
||||||
*/
|
|
||||||
public function displayMySupplyChainDashboard() {
|
|
||||||
$openContracts = SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'state' => 'open',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
$closedContracts = SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'state' => 'closed',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
$completedContracts = SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'state' => 'completed',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
return view('supplychain.dashboard.main')->with('openContracts', $openContracts)
|
|
||||||
->with('closedContracts', $closedContracts)
|
|
||||||
->with('completedContracts', $completedContracts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display new contract page
|
|
||||||
*/
|
|
||||||
public function displayNewSupplyChainContract() {
|
|
||||||
return view('supplychain.forms.newcontract');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store new contract page
|
|
||||||
*/
|
|
||||||
public function storeNewSupplyChainContract(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'name' => 'required',
|
|
||||||
'date' => 'required',
|
|
||||||
'delivery' => 'required',
|
|
||||||
'body' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$contract = new SupplyChainContract;
|
|
||||||
$contract->issuer_id = auth()->user()->getId();
|
|
||||||
$contract->issuer_name = auth()->user()->getName();
|
|
||||||
$contract->title = $request->name;
|
|
||||||
$contract->end_date = $request->date;
|
|
||||||
$contract->delivery_by = $request->delivery;
|
|
||||||
$contract->body = $request->body;
|
|
||||||
$contract->state = 'open';
|
|
||||||
$contract->bids = 0;
|
|
||||||
$contract->save();
|
|
||||||
|
|
||||||
$this->NewSupplyChainContractMail($contract);
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'New Contract created.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the delete contract page
|
|
||||||
*/
|
|
||||||
public function displayDeleteSupplyChainContract() {
|
|
||||||
$contracts = SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'state' => 'open',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
return view('supplychain.forms.delete')->with('contracts', $contracts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a supply chain contract
|
|
||||||
*/
|
|
||||||
public function deleteSupplyChainContract(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'contractId' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$contractId = $request->contractId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the supply chain contract if it's yours.
|
|
||||||
*/
|
|
||||||
$count = SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($count > 0) {
|
|
||||||
//Remove the supply chain contract
|
|
||||||
SupplyChainContract::where([
|
|
||||||
'issuer_id' => auth()->user()->getId(),
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Remove all bids associated with the supply chain contract
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'Supply Chain Contract deleted successfully.');
|
|
||||||
} else {
|
|
||||||
return redirect('/supplychain/dashboard')->with('error', 'Unable to delete supply chain contract.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the end supply chain contrage page
|
|
||||||
*/
|
|
||||||
public function displayEndSupplyChainContract() {
|
|
||||||
return view('supplychain.forms.end');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process the end supply chain contract page
|
|
||||||
*/
|
|
||||||
public function storeEndSupplyChainContract(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'accept' => 'required',
|
|
||||||
'contractId' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Check to make sure the user owns the contract
|
|
||||||
$count = SupplyChainContract::where([
|
|
||||||
'issuer_name' => auth()->user()->getName(),
|
|
||||||
'contract_id' => $request->contractId,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
//If the count is greater than 0, the user owns the contract.
|
|
||||||
//Proceed with ending the contract
|
|
||||||
if($count > 0) {
|
|
||||||
SupplyChainContract::where([
|
|
||||||
|
|
||||||
])->update([
|
|
||||||
|
|
||||||
]);
|
|
||||||
|
|
||||||
SupplyChainBid::where([
|
|
||||||
|
|
||||||
])->update([
|
|
||||||
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'Contract ended, and mails sent to the winning bidder.');
|
|
||||||
} else {
|
|
||||||
//If the count is zero, then redirect with error messsage
|
|
||||||
return redirect('/supplychain/dashboard')->with('error', 'Contract was not yours to end.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display supply chain contract bids page
|
|
||||||
*/
|
|
||||||
public function displaySupplyChainBids() {
|
|
||||||
//Display bids for the user on a page
|
|
||||||
$bids = array();
|
|
||||||
|
|
||||||
$bidsCount = SupplyChainBid::where([
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
'bid_type' => 'pending',
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
$myBids = SupplyChainBid::where([
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
'bid_type' => 'pending',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
foreach($myBids as $bid) {
|
|
||||||
//Declare the temporary array
|
|
||||||
$temp = array();
|
|
||||||
|
|
||||||
//Get the contract information for the bid
|
|
||||||
$contract = SupplyChainContract::where([
|
|
||||||
'contract_id' => $bid->contract_id,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
$temp['bid_id'] = $bid->bid_id;
|
|
||||||
$temp['contract_id'] = $bid->contract_id;
|
|
||||||
$temp['issuer_name'] = $contract->issuer_name;
|
|
||||||
$temp['title'] = $contract->title;
|
|
||||||
$temp['end_date'] = $contract->end_date;
|
|
||||||
$temp['body'] = $contract->body;
|
|
||||||
$temp['bid_amount'] = $bid->bid_amount;
|
|
||||||
|
|
||||||
array_push($bids, $temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('supplychain.dashboard.bids')->with('bids', $bids)
|
|
||||||
->with('bidsCount', $bidsCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display expired supply chain contracts page
|
|
||||||
*/
|
|
||||||
public function displayExpiredSupplyChainContracts() {
|
|
||||||
|
|
||||||
return view('supplychain.dashboard.expired');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the new bid on a supply chain contract page
|
|
||||||
*/
|
|
||||||
public function displaySupplyChainContractBid($contract) {
|
|
||||||
$contractId = $contract;
|
|
||||||
|
|
||||||
return view('supplychain.forms.enterbid')->with('contractId', $contractId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter a new bid on a supply chain contract
|
|
||||||
*/
|
|
||||||
public function storeSupplyChainContractBid(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'bid' => 'required',
|
|
||||||
'contract_id' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Declare some needed variables
|
|
||||||
$bidAmount = 0.00;
|
|
||||||
|
|
||||||
//See if a bid has been placed by the user for this contract
|
|
||||||
$count = SupplyChainBid::where([
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
'entity_name' => auth()->user()->getName(),
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
//If the person already has a bid in, then deny them the option to place another bid on the same contract.
|
|
||||||
//Otherwise, enter the bid into the database
|
|
||||||
if($count > 0) {
|
|
||||||
return redirect('/supplychain/dashboard')->with('error', 'Unable to insert bid as one is already present for the supply chain contract.');
|
|
||||||
} else {
|
|
||||||
//Sanitize the bid amount
|
|
||||||
if(preg_match('(m|M|b|B)', $request->bid) === 1) {
|
|
||||||
if(preg_match('(m|M)', $request->bid) === 1) {
|
|
||||||
$cStringSize = strlen($request->bid);
|
|
||||||
$tempCol = str_split($request->bid, $cStringSize - 1);
|
|
||||||
$bidAmount = $tempCol[0];
|
|
||||||
$bidAmount = $bidAmount * 1000000.00;
|
|
||||||
} else if(preg_match('(b|B)', $request->bid) === 1) {
|
|
||||||
$cStringSize = strlen($request->bid);
|
|
||||||
$tempCol = str_split($request->bid, $cStringSize - 1);
|
|
||||||
$bidAmount = $tempCol[0];
|
|
||||||
$bidAmount = $bidAmount * 1000000000.00;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$bidAmount = $request->bid;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create the database entry
|
|
||||||
$bid = new SupplyChainBid;
|
|
||||||
$bid->contract_id = $request->contract_id;
|
|
||||||
$bid->bid_amount = $bidAmount;
|
|
||||||
$bid->entity_id = auth()->user()->getId();
|
|
||||||
$bid->entity_name = auth()->user()->getName();
|
|
||||||
$bid->entity_type = 'character';
|
|
||||||
if(isset($request->notes)) {
|
|
||||||
$bid->bid_note = $request->notes;
|
|
||||||
}
|
|
||||||
$bid->bid_type = 'pending';
|
|
||||||
$bid->save();
|
|
||||||
|
|
||||||
//Update the database entry for the supply chain contract bid number
|
|
||||||
$num = SupplyChainContract::where([
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
])->select('bids')->first();
|
|
||||||
|
|
||||||
//Increment the number of bids
|
|
||||||
$numBids = $num->bids + 1;
|
|
||||||
|
|
||||||
//Update the database
|
|
||||||
SupplyChainContract::where([
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
])->update([
|
|
||||||
'bids' => $numBids,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'Bid succesfully entered into the contract.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a bid on a supply chain contract
|
|
||||||
*
|
|
||||||
* @var contractId
|
|
||||||
* @var bidId
|
|
||||||
*/
|
|
||||||
public function deleteSupplyChainContractBid($contractId, $bidId) {
|
|
||||||
|
|
||||||
//See if the user has put in a bid. If not, then redirect to failure.
|
|
||||||
$count = SupplyChainBid::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
'bid_id' => $bidId,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($count > 0) {
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
'bid_id' => $bidId,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Update the database entry for the supply chain contract bid number
|
|
||||||
$num = SupplyChainContract::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->select('bids')->first();
|
|
||||||
|
|
||||||
//Decrement the number of bids
|
|
||||||
$numBids = $num->bids - 1;
|
|
||||||
|
|
||||||
//Update the database
|
|
||||||
SupplyChainContract::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->update([
|
|
||||||
'bids' => $numBids,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'Deleted supply chain contract bid.');
|
|
||||||
} else {
|
|
||||||
return redirect('/supplychain/dashboard')->with('error', 'No bid found to delete.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the modify a bid on supply chain contract page
|
|
||||||
*/
|
|
||||||
public function displayModifySupplyChainContractBid(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'contract_id' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Get the contract id
|
|
||||||
$contractId = $request->contract_id;
|
|
||||||
//Get the bid id to be modified later
|
|
||||||
$bid = SupplyChainBid::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
$bidId = $bid->id;
|
|
||||||
|
|
||||||
return view('supplychain.forms.modifybid')->with('contractId', $contractId)
|
|
||||||
->with('bidId', $bidId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify a bid on a supply chain contract
|
|
||||||
*/
|
|
||||||
public function modifySupplyChainContractBid(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'bid_id' => 'required',
|
|
||||||
'contract_id' => 'required',
|
|
||||||
'bid_amount' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Check for the owner of the bid
|
|
||||||
$count = SupplyChainBid::where([
|
|
||||||
'bid_id' => $request->bid_id,
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($count > 0) {
|
|
||||||
if(isset($request->bid_note)) {
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'bid_id' => $request->bid_id,
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
])->update([
|
|
||||||
'bid_amount' => $request->bid_amount,
|
|
||||||
'bid_note' => $request->bid_note,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'bid_id' => $request->bid_id,
|
|
||||||
'contract_id' => $request->contract_id,
|
|
||||||
'entity_id' => auth()->user()->getId(),
|
|
||||||
])->update([
|
|
||||||
'bid_amount' => $request->bid_amount,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect('/supplychain/dashboard')->with('success', 'Modified supply chain contract bid.');
|
|
||||||
} else {
|
|
||||||
return redirect('/supplychain/dashboard')->with('error', 'Not able to modify supply chain contract bid.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send out a new supply chain contract mail
|
|
||||||
*/
|
|
||||||
private function NewSupplyChainContractMail(SupplyChainContract $contract) {
|
|
||||||
//Get the config for the esi
|
|
||||||
$config = config('esi');
|
|
||||||
$todayDate = Carbon::now()->toFormattedDateString();
|
|
||||||
|
|
||||||
$subject = 'New Supply Chain Contract ' . $todayDate;
|
|
||||||
$body = "A supply chain contract is available.<br>";
|
|
||||||
$body .= "Contract: " . $contract->title . "<br>";
|
|
||||||
$body .= "Notes: " . $contract->body . "<br>";
|
|
||||||
$body .= "Delivery Date: " . $contract->delivery_date . "<br>";
|
|
||||||
$body .= "<br>Sincerely on behalf of,<br>" . $contract->issuer_name . "<br>";
|
|
||||||
SendEveMail::dispatch($body, 145223267, 'mailing_list', $subject, $config['primary'])->delay(Carbon::now()->addSeconds(30));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send out a mail when the supply chain contract has been deleted
|
|
||||||
*/
|
|
||||||
private function DeleteSupplyChainContractMail($contract) {
|
|
||||||
//Get the esi config
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
$subject = 'Production Contract Removal';
|
|
||||||
$body = "A production contract has been deleted.<br>";
|
|
||||||
$body .= "Contract: " . $contract->title . "<br>";
|
|
||||||
$body .= "Notes: " . $contract->note . "<br>";
|
|
||||||
$body .= "<br>Sincerely on behalf of,<br>" . $contract->issuer_name;
|
|
||||||
SendEveMail::dispatch($body, 145223267, 'mailing_list', $subject, $config['primary'])->delay(Carbon::now()->addSeconds(30));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tidy up datatables from a completed supply chain contract
|
|
||||||
*/
|
|
||||||
private function TidySupplyChainContract($contract, $bid) {
|
|
||||||
//Set the contract as finished
|
|
||||||
SupplyChainContract::where([
|
|
||||||
'contract_id' => $contract->contract_id,
|
|
||||||
])->update([
|
|
||||||
'state' => 'finished',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Set all of the bids as not_accepted as default
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'contract_id' => $contract->contract_id,
|
|
||||||
])->update([
|
|
||||||
'bid_type' => 'not_accepted',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Set the correct bid as accepted
|
|
||||||
SupplyChainBid::where([
|
|
||||||
'contract_id' => $contract->contract_id,
|
|
||||||
'bid_id' => $bid->bid_id,
|
|
||||||
])->update([
|
|
||||||
'bid_type' => 'accepted',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
486
app/Http/Controllers/Dashboard/AdminController.php
Normal file
486
app/Http/Controllers/Dashboard/AdminController.php
Normal file
@@ -0,0 +1,486 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Dashboard;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use DB;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Libraries
|
||||||
|
use App\Library\Taxes\TaxesHelper;
|
||||||
|
use App\Library\Wiki\WikiHelper;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\SRP\SRPHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\User\User;
|
||||||
|
use App\Models\User\UserRole;
|
||||||
|
use App\Models\User\UserPermission;
|
||||||
|
use App\Models\User\AvailableUserPermission;
|
||||||
|
use App\Models\Admin\AllowedLogin;
|
||||||
|
use App\Models\Doku\DokuGroupNames;
|
||||||
|
use App\Models\Doku\DokuMember;
|
||||||
|
use App\Models\Doku\DokuUser;
|
||||||
|
|
||||||
|
class AdminController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayTestAdminDashboard() {
|
||||||
|
return view('admin.dashboards.testdashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showJournalEntries() {
|
||||||
|
$dateInit = Carbon::now();
|
||||||
|
$date = $dateInit->subDays(30);
|
||||||
|
|
||||||
|
$journal = DB::select('SELECT amount,reason,description,date FROM `player_donation_journal` WHERE corporation_id=98287666 AND date >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) ORDER BY date DESC');
|
||||||
|
|
||||||
|
return view('admin.dashboards.walletjournal')->with('journal', $journal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayUsersPaginated() {
|
||||||
|
//Declare array variables
|
||||||
|
$user = array();
|
||||||
|
$permission = array();
|
||||||
|
$userArr = array();
|
||||||
|
$permString = null;
|
||||||
|
|
||||||
|
$usersArr = User::orderBy('name', 'asc')->paginate(50);
|
||||||
|
|
||||||
|
foreach($usersArr as $user) {
|
||||||
|
$user->role = $user->getRole();
|
||||||
|
|
||||||
|
$permCount = UserPermission::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
if($permCount > 0) {
|
||||||
|
$perms = UserPermission::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->get('permission')->toArray();
|
||||||
|
|
||||||
|
foreach($perms as $perm) {
|
||||||
|
$permString .= $perm['permission'] . ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->permission = $permString;
|
||||||
|
} else {
|
||||||
|
$user->permission = 'No Permissions';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.dashboards.userspaged')->with('usersArr', $usersArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchUsers(Request $request) {
|
||||||
|
//Declare array variables
|
||||||
|
$user = array();
|
||||||
|
$permission = array();
|
||||||
|
$userArr = array();
|
||||||
|
$permString = null;
|
||||||
|
|
||||||
|
//Validate the input from the form
|
||||||
|
$this->validate($request, [
|
||||||
|
'parameter' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$usersArr = User::where('name', 'like', $request->parameter . "%")->paginate(50);
|
||||||
|
|
||||||
|
foreach($usersArr as $user) {
|
||||||
|
$user->role = $user->getRole();
|
||||||
|
|
||||||
|
$permCount = UserPermission::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
if($permCount > 0) {
|
||||||
|
$perms = UserPermission::where([
|
||||||
|
'character_id' => $user->character_id,
|
||||||
|
])->get('permission')->toArray();
|
||||||
|
|
||||||
|
foreach($perms as $perm) {
|
||||||
|
$permString .= $perm['permission'] . ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->permission = $permString;
|
||||||
|
} else {
|
||||||
|
$user->permission = 'No Permissions';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.dashboards.users.searched')->with('usersArr', $usersArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayAllowedLogins() {
|
||||||
|
//Declare array variables
|
||||||
|
$entities = array();
|
||||||
|
|
||||||
|
/** Entities for allowed logins */
|
||||||
|
$legacys = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_name')->toArray();
|
||||||
|
$renters = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_name')->toArray();
|
||||||
|
//Compile a list of entities by their entity_id
|
||||||
|
foreach($legacys as $legacy) {
|
||||||
|
$entities[] = $legacy;
|
||||||
|
}
|
||||||
|
foreach($renters as $renter) {
|
||||||
|
$entities[] = $renter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.dashboards.allowed_logins')->with('entities', $entities);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayTaxes() {
|
||||||
|
//Declare variables needed for displaying items on the page
|
||||||
|
$months = 3;
|
||||||
|
$pi = array();
|
||||||
|
$industry = array();
|
||||||
|
$reprocessing = array();
|
||||||
|
$office = array();
|
||||||
|
$corpId = 98287666;
|
||||||
|
$srpActual = array();
|
||||||
|
$srpLoss = array();
|
||||||
|
|
||||||
|
/** Taxes Pane */
|
||||||
|
//Declare classes needed for displaying items on the page
|
||||||
|
$tHelper = new TaxesHelper();
|
||||||
|
$srpHelper = new SRPHelper();
|
||||||
|
//Get the dates for the tab panes
|
||||||
|
$dates = $tHelper->GetTimeFrameInMonths($months);
|
||||||
|
//Get the data for the Taxes Pane
|
||||||
|
foreach($dates as $date) {
|
||||||
|
//Get the srp actual pay out for the date range
|
||||||
|
$srpActual[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($srpHelper->GetAllianceSRPActual($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the srp loss value for the date range
|
||||||
|
$srpLoss[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($srpHelper->GetAllianceSRPLoss($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the pi taxes for the date range
|
||||||
|
$pis[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetPIGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the industry taxes for the date range
|
||||||
|
$industrys[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetIndustryGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the reprocessing taxes for the date range
|
||||||
|
$reprocessings[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetReprocessingGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the office taxes for the date range
|
||||||
|
$offices[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetOfficeGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the market taxes for the date range
|
||||||
|
$markets[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetAllianceMarketGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the jump gate taxes for the date range
|
||||||
|
$jumpgates[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetJumpGateGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.dashboards.taxes')->with('pis', $pis)
|
||||||
|
->with('industrys', $industrys)
|
||||||
|
->with('offices', $offices)
|
||||||
|
->with('markets', $markets)
|
||||||
|
->with('jumpgates', $jumpgates)
|
||||||
|
->with('reprocessings', $reprocessings)
|
||||||
|
->with('srpActual', $srpActual)
|
||||||
|
->with('srpLoss', $srpLoss);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayModifyUser(Request $request) {
|
||||||
|
$permissions = array();
|
||||||
|
|
||||||
|
$name = $request->user;
|
||||||
|
|
||||||
|
//Get the user information from the name
|
||||||
|
$user = User::where(['name' => $name])->first();
|
||||||
|
|
||||||
|
$perms = AvailableUserPermission::all();
|
||||||
|
foreach($perms as $p) {
|
||||||
|
$permissions[$p->permission] = $p->permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Pass the user information to the page for hidden text entries
|
||||||
|
return view('admin.user.modify')->with('user', $user)
|
||||||
|
->with('permissions', $permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function modifyUser(Request $request) {
|
||||||
|
$type = $request->type;
|
||||||
|
if(isset($request->permission)) {
|
||||||
|
$permission = $request->permission;
|
||||||
|
}
|
||||||
|
if(isset($request->user)) {
|
||||||
|
$user = $request->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/users')->with('error', 'Not Implemented Yet.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPermission(Request $request) {
|
||||||
|
//Get the user and permission from the form
|
||||||
|
$user = $request->user;
|
||||||
|
$permission = $request->permission;
|
||||||
|
|
||||||
|
//Get the character id from the username using the user table
|
||||||
|
$character = User::where(['name' => $user])->get(['character_id']);
|
||||||
|
|
||||||
|
//Check to see if the character already has the permission
|
||||||
|
$check = UserPermission::where(['character_id' => $character[0]->character_id, 'permission' => $permission])->get(['permission']);
|
||||||
|
|
||||||
|
if(!isset($check[0]->permission)) {
|
||||||
|
$perm = new UserPermission;
|
||||||
|
$perm->character_id = $character[0]->character_id;
|
||||||
|
$perm->permission = $permission;
|
||||||
|
$perm->save();
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/users')->with('success', 'User udpated!');
|
||||||
|
} else {
|
||||||
|
return redirect('/admin/dashboard/users')->with('error', 'User not updated or already has the permission.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeUser(Request $request) {
|
||||||
|
//Get the user from the form to delete
|
||||||
|
$user = $request->user;
|
||||||
|
|
||||||
|
//Get the user data from the table
|
||||||
|
$data = User::where(['name' => $user])->get();
|
||||||
|
|
||||||
|
//Delete the user's ESI Scopes
|
||||||
|
DB::table('EsiScopes')->where(['character_id' => $data[0]->character_id])->delete();
|
||||||
|
|
||||||
|
//Delete the user's ESI Token
|
||||||
|
DB::table('EsiTokens')->where(['character_id' => $data[0]->character_id])->delete();
|
||||||
|
|
||||||
|
//Delete the user's role from the roles table
|
||||||
|
DB::table('user_roles')->where(['character_id' => $data[0]->character_id])->delete();
|
||||||
|
|
||||||
|
//Delete the user from the user table
|
||||||
|
DB::table('users')->where(['character_id' => $data[0]->character_id])->delete();
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/users')->with('success', 'User deleted from the site.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAllowedLogin(Request $request) {
|
||||||
|
//Set the parameters to validate the form
|
||||||
|
$this->validate($request, [
|
||||||
|
'allowedEntityId' => 'required',
|
||||||
|
'allowedEntityType' => 'required',
|
||||||
|
'allowedEntityName' => 'required',
|
||||||
|
'allowedLoginType' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Check to see if the entity exists in the database already
|
||||||
|
$found = AllowedLogin::where([
|
||||||
|
'entity_type' => $request->allowedentityType,
|
||||||
|
'entity_name' => $request->allowedEntityName,
|
||||||
|
])->count();
|
||||||
|
if($found != 0) {
|
||||||
|
AllowedLogin::where([
|
||||||
|
'entity_type' => $request->allowedEntityType,
|
||||||
|
'entity_name' => $request->allowedEntityName,
|
||||||
|
])->update([
|
||||||
|
'entity_id' => $request->allowedEntityId,
|
||||||
|
'entity_type' => $request->allowedEntityType,
|
||||||
|
'entity_name' => $request->allowedEntityName,
|
||||||
|
'login_type' => $request->allowedLoginType,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$login = new AllowedLogin;
|
||||||
|
$login->entity_id = $request->allowedEntityId;
|
||||||
|
$login->entity_name = $request->allowedEntityName;
|
||||||
|
$login->entity_type = $request->allowedEntityType;
|
||||||
|
$login->login_type = $request->allowedLoginType;
|
||||||
|
$login->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard')->with('success', 'Entity added to allowed login list.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeAllowedLogin(Request $request) {
|
||||||
|
//Set the parameters to validate the form
|
||||||
|
$this->validate($request, [
|
||||||
|
'removeAllowedLogin' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
AllowedLogin::where([
|
||||||
|
'entity_name' => $request->removeAllowedLogin,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard')->with('success', 'Entity removed from allowed login list.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the wiki dashboard for wiki functions
|
||||||
|
*/
|
||||||
|
public function displayWikiDashboard() {
|
||||||
|
//Declare some variables
|
||||||
|
$wikiUsers = array();
|
||||||
|
$wikiGroups = array();
|
||||||
|
|
||||||
|
$tempUsers = DokuUser::all();
|
||||||
|
$tempGroups = DokuGroupNames::all();
|
||||||
|
$wikiMembership = DokuMember::all();
|
||||||
|
|
||||||
|
//Create a list of users based on id and name for the select form
|
||||||
|
foreach($tempUsers as $temp) {
|
||||||
|
$wikiUsers[$temp->id] = $temp->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
asort($wikiUsers);
|
||||||
|
|
||||||
|
foreach($tempGroups as $temp) {
|
||||||
|
$wikiGroups[$temp->id] = $temp->gname;
|
||||||
|
}
|
||||||
|
|
||||||
|
asort($wikiGroups);
|
||||||
|
|
||||||
|
return view('admin.dashboards.wiki')->with('wikiUsers', $wikiUsers)
|
||||||
|
->with('wikiGroups', $wikiGroups)
|
||||||
|
->with('wikiMembership', $wikiMembership);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a wiki user
|
||||||
|
*/
|
||||||
|
public function deleteWikiUser(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'user' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare helper variable
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
$wikiHelper->DeleteWikiUser($request->user);
|
||||||
|
|
||||||
|
redirect('/admin/dashboard/wiki')->with('success', 'User: ' . $request->user . ' has been deleted.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a group to a wiki user
|
||||||
|
*/
|
||||||
|
public function addWikiUserGroup(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'user' => 'required', //User Id number
|
||||||
|
'groupname' => 'required', //Group Id number
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare some helper variables
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
//Check to see if the user has the group we are going to add first
|
||||||
|
if($wikiHelper->UserHasGroup($request->user, $request->groupname)) {
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('error', 'User already has the group.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add the user to the wiki group
|
||||||
|
$wikiHelper->AddUserToGroup($request->user, $request->groupname);
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('success', 'User added to group for the wiki.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a group from a wiki user
|
||||||
|
*/
|
||||||
|
public function removeWikiUserGroup(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'user' => 'required',
|
||||||
|
'groupname' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare some helper variables
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
//Check to see if the user has the group we are going to remove them from
|
||||||
|
if(!$wikiHelper->UserHasGroup($request->user, $request->groupname)) {
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('error', 'User does not have the group to remove.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove the user from the wiki group
|
||||||
|
$wikiHelper->RemoveUserFromGroup($request->user, $request->groupname);
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('success', 'Removed user from group ' . $request->grouopname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a user from all wiki groups
|
||||||
|
*/
|
||||||
|
public function removeWikiUserAllGroups(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'user' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare variable
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
$wikiHelper->RemoveUserFromAllGroups($request->user);
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('success', 'User successfully removed from all groups.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new group for wiki user's to be added to
|
||||||
|
*/
|
||||||
|
public function insertNewWikiUserGroup(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'group' => 'required',
|
||||||
|
'description' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare variable
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
$wikiHelper->AddNewUserGroup($request->group, $request->description);
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('success', 'Added new user group.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function purgeWikiUsers(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'admin' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare helper classes
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$wikiHelper = new WikiHelper;
|
||||||
|
|
||||||
|
//Search the names and verify against the lookup table
|
||||||
|
//to find the corporation and / or alliance they belong to.
|
||||||
|
foreach($users as $user) {
|
||||||
|
//Let's look up the character in the user table by their name.
|
||||||
|
//If no name is found, then delete the user and have them start over with the wiki permissions
|
||||||
|
$count = User::where(['name' => $user])->count();
|
||||||
|
if($count > 0) {
|
||||||
|
//If the user is not allowed, then delete the user, otherwise, leave the user untouched
|
||||||
|
if(!$wikiHelper->AllowedUser($user)) {
|
||||||
|
$wikiHelper->DeleteWikiUser($user);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$wikiHelper->DeleteWikiUser($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect('/admin/dashboard/wiki')->with('success', 'Wiki has been purged.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,18 +10,13 @@ use Khill\Lavacharts\Lavacharts;
|
|||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
//Libraries
|
//Libraries
|
||||||
use App\Library\Helpers\TaxesHelper;
|
use App\Library\Taxes\TaxesHelper;
|
||||||
use App\Library\Helpers\LookupHelper;
|
use App\Library\Wiki\WikiHelper;
|
||||||
use App\Library\Helpers\SRPHelper;
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\SRP\SRPHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\User\UserRole;
|
|
||||||
use App\Models\User\UserPermission;
|
|
||||||
use App\Models\User\AvailableUserPermission;
|
|
||||||
use App\Models\User\AvailableUserRole;
|
|
||||||
use App\Models\Admin\AllowedLogin;
|
|
||||||
use App\Models\Finances\AllianceWalletJournal;
|
|
||||||
|
|
||||||
class AdminDashboardController extends Controller
|
class AdminDashboardController extends Controller
|
||||||
{
|
{
|
||||||
@@ -33,7 +28,7 @@ class AdminDashboardController extends Controller
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->middleware('auth');
|
$this->middleware('auth');
|
||||||
$this->middleware('role:Admin');
|
$this->middleware('role:User');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,364 +41,19 @@ class AdminDashboardController extends Controller
|
|||||||
redirect('/dashboard');
|
redirect('/dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Declare variables we will need
|
||||||
return view('admin.dashboards.dashboard');
|
$days = 30;
|
||||||
}
|
$sovBills = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Display users in a paginated format
|
|
||||||
*/
|
|
||||||
public function displayUsersPaginated() {
|
|
||||||
//Declare array variables
|
|
||||||
$user = array();
|
|
||||||
$permission = array();
|
|
||||||
$userArr = array();
|
|
||||||
$permString = null;
|
|
||||||
|
|
||||||
$usersArr = User::orderBy('name', 'asc')->paginate(50);
|
|
||||||
|
|
||||||
foreach($usersArr as $user) {
|
|
||||||
$user->role = $user->getRole();
|
|
||||||
|
|
||||||
$permCount = UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($permCount > 0) {
|
|
||||||
$perms = UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->get('permission')->toArray();
|
|
||||||
|
|
||||||
foreach($perms as $perm) {
|
|
||||||
$permString .= $perm['permission'] . ', ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->permission = $permString;
|
|
||||||
} else {
|
|
||||||
$user->permission = 'No Permissions';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.dashboards.userspaged')->with('usersArr', $usersArr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search users for a specific user
|
|
||||||
*/
|
|
||||||
public function searchUsers(Request $request) {
|
|
||||||
//Declare array variables
|
|
||||||
$user = array();
|
|
||||||
$permission = array();
|
|
||||||
$userArr = array();
|
|
||||||
$permString = null;
|
|
||||||
|
|
||||||
//Validate the input from the form
|
|
||||||
$this->validate($request, [
|
|
||||||
'parameter' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$usersArr = User::where('name', 'like', $request->parameter . "%")->paginate(50);
|
|
||||||
|
|
||||||
foreach($usersArr as $user) {
|
|
||||||
$user->role = $user->getRole();
|
|
||||||
|
|
||||||
$permCount = UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($permCount > 0) {
|
|
||||||
$perms = UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->get('permission')->toArray();
|
|
||||||
|
|
||||||
foreach($perms as $perm) {
|
|
||||||
$permString .= $perm['permission'] . ', ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->permission = $permString;
|
|
||||||
} else {
|
|
||||||
$user->permission = 'No Permissions';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.dashboards.users.searched')->with('usersArr', $usersArr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the allowed logins
|
|
||||||
*/
|
|
||||||
public function displayAllowedLogins() {
|
|
||||||
//Declare array variables
|
|
||||||
$entities = array();
|
|
||||||
|
|
||||||
/** Entities for allowed logins */
|
|
||||||
$legacys = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_name')->toArray();
|
|
||||||
$renters = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_name')->toArray();
|
|
||||||
//Compile a list of entities by their entity_id
|
|
||||||
foreach($legacys as $legacy) {
|
|
||||||
$entities[] = $legacy;
|
|
||||||
}
|
|
||||||
foreach($renters as $renter) {
|
|
||||||
$entities[] = $renter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.dashboards.allowed_logins')->with('entities', $entities);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the taxes for the alliance
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function displayTaxes() {
|
|
||||||
//Declare variables needed for displaying items on the page
|
|
||||||
$months = 3;
|
|
||||||
$pi = array();
|
$pi = array();
|
||||||
$industry = array();
|
$industry = array();
|
||||||
$reprocessing = array();
|
$reprocessing = array();
|
||||||
$office = array();
|
$office = array();
|
||||||
$corpId = 98287666;
|
$sprActual = array();
|
||||||
$srpActual = array();
|
|
||||||
$srpLoss = array();
|
$srpLoss = array();
|
||||||
$miningTaxes = array();
|
|
||||||
$miningTaxesLate = array();
|
|
||||||
|
|
||||||
/** Taxes Pane */
|
//Get the data for the sov expenses for a graph
|
||||||
//Declare classes needed for displaying items on the page
|
|
||||||
$tHelper = new TaxesHelper();
|
|
||||||
$srpHelper = new SRPHelper();
|
|
||||||
//Get the dates for the tab panes
|
|
||||||
$dates = $tHelper->GetTimeFrameInMonths($months);
|
|
||||||
|
|
||||||
//Get the data for the Taxes Pane
|
|
||||||
foreach($dates as $date) {
|
|
||||||
//Get the srp actual pay out for the date range
|
|
||||||
$srpActual[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($srpHelper->GetAllianceSRPActual($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
|
|
||||||
//Get the srp loss value for the date range
|
|
||||||
$srpLoss[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($srpHelper->GetAllianceSRPLoss($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
|
|
||||||
//Get the pi taxes for the date range
|
|
||||||
$pis[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetPIGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
//Get the industry taxes for the date range
|
|
||||||
$industrys[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetIndustryGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
//Get the reprocessing taxes for the date range
|
|
||||||
$reprocessings[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetReprocessingGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
//Get the office taxes for the date range
|
|
||||||
$offices[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetOfficeGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
//Get the market taxes for the date range
|
|
||||||
$markets[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetAllianceMarketGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
//Get the jump gate taxes for the date range
|
|
||||||
$jumpgates[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetJumpGateGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
|
|
||||||
$miningTaxes[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetMoonMiningTaxesGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
|
|
||||||
$miningTaxesLate[] = [
|
|
||||||
'date' => $date['start']->toFormattedDateString(),
|
|
||||||
'gross' => number_format($tHelper->GetMoonMiningTaxesLateGross($date['start'], $date['end']), 2, ".", ","),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.dashboards.taxes')->with('pis', $pis)
|
|
||||||
->with('industrys', $industrys)
|
|
||||||
->with('offices', $offices)
|
|
||||||
->with('markets', $markets)
|
|
||||||
->with('jumpgates', $jumpgates)
|
|
||||||
->with('reprocessings', $reprocessings)
|
|
||||||
->with('srpActual', $srpActual)
|
|
||||||
->with('srpLoss', $srpLoss)
|
|
||||||
->with('miningTaxes', $miningTaxes)
|
|
||||||
->with('miningTaxesLate', $miningTaxesLate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the modify user form
|
|
||||||
*/
|
|
||||||
public function displayModifyUser(Request $request) {
|
|
||||||
$permissions = array();
|
|
||||||
$roles = array();
|
|
||||||
|
|
||||||
$name = $request->user;
|
|
||||||
|
|
||||||
//Get the user information from the name
|
return view('admin.dashboards.dashboard');
|
||||||
$user = User::where(['name' => $name])->first();
|
|
||||||
|
|
||||||
$perms = AvailableUserPermission::all();
|
|
||||||
foreach($perms as $p) {
|
|
||||||
$permissions[$p->permission] = $p->permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRoles = AvailableUserRole::all();
|
|
||||||
|
|
||||||
foreach($tempRoles as $tempRole) {
|
|
||||||
array_push($roles, [
|
|
||||||
$tempRole['role'] => $tempRole['role']
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$role = $user->getRole();
|
|
||||||
|
|
||||||
//Pass the user information to the page for hidden text entries
|
|
||||||
return view('admin.user.modify')->with('user', $user)
|
|
||||||
->with('permissions', $permissions)
|
|
||||||
->with('role', $role)
|
|
||||||
->with('roles', $roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify a user's role
|
|
||||||
*/
|
|
||||||
public function modifyRole(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'user' => 'required',
|
|
||||||
'role' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserRole::where(['character_id' => $request->user])->update([
|
|
||||||
'role' => $request->role,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect('/admin/dashboard/users')->with('success', "User: " . $request->user . " has been modified to a new role: " . $request->role . ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addPermission(Request $request) {
|
|
||||||
//Get the user and permission from the form
|
|
||||||
$character = $request->user;
|
|
||||||
$permission = $request->permission;
|
|
||||||
|
|
||||||
//Check to see if the character already has the permission
|
|
||||||
$check = UserPermission::where(['character_id' => $character, 'permission' => $permission])->get(['permission']);
|
|
||||||
|
|
||||||
if(!isset($check[0]->permission)) {
|
|
||||||
$perm = new UserPermission;
|
|
||||||
$perm->character_id = $character;
|
|
||||||
$perm->permission = $permission;
|
|
||||||
$perm->save();
|
|
||||||
|
|
||||||
return redirect('/admin/dashboard/users')->with('success', 'User udpated!');
|
|
||||||
} else {
|
|
||||||
return redirect('/admin/dashboard/users')->with('error', 'User not updated or already has the permission.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a user to reset their permissions
|
|
||||||
*/
|
|
||||||
public function removeUser(Request $request) {
|
|
||||||
//Get the user from the form to delete
|
|
||||||
$user = $request->user;
|
|
||||||
|
|
||||||
//Get the user data from the table
|
|
||||||
$data = User::where(['name' => $user])->get();
|
|
||||||
|
|
||||||
//Delete the user's ESI Scopes
|
|
||||||
DB::table('EsiScopes')->where(['character_id' => $data[0]->character_id])->delete();
|
|
||||||
|
|
||||||
//Delete the user's ESI Token
|
|
||||||
DB::table('EsiTokens')->where(['character_id' => $data[0]->character_id])->delete();
|
|
||||||
|
|
||||||
//Delete the user's role from the roles table
|
|
||||||
DB::table('user_roles')->where(['character_id' => $data[0]->character_id])->delete();
|
|
||||||
|
|
||||||
//Delete the user from the user table
|
|
||||||
DB::table('users')->where(['character_id' => $data[0]->character_id])->delete();
|
|
||||||
|
|
||||||
return redirect('/admin/dashboard/users')->with('success', 'User deleted from the site.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an entity to the allowed login table
|
|
||||||
*/
|
|
||||||
public function addAllowedLogin(Request $request) {
|
|
||||||
//Set the parameters to validate the form
|
|
||||||
$this->validate($request, [
|
|
||||||
'allowedEntityId' => 'required',
|
|
||||||
'allowedEntityType' => 'required',
|
|
||||||
'allowedEntityName' => 'required',
|
|
||||||
'allowedLoginType' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Check to see if the entity exists in the database already
|
|
||||||
$found = AllowedLogin::where([
|
|
||||||
'entity_type' => $request->allowedentityType,
|
|
||||||
'entity_name' => $request->allowedEntityName,
|
|
||||||
])->count();
|
|
||||||
if($found != 0) {
|
|
||||||
AllowedLogin::where([
|
|
||||||
'entity_type' => $request->allowedEntityType,
|
|
||||||
'entity_name' => $request->allowedEntityName,
|
|
||||||
])->update([
|
|
||||||
'entity_id' => $request->allowedEntityId,
|
|
||||||
'entity_type' => $request->allowedEntityType,
|
|
||||||
'entity_name' => $request->allowedEntityName,
|
|
||||||
'login_type' => $request->allowedLoginType,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$login = new AllowedLogin;
|
|
||||||
$login->entity_id = $request->allowedEntityId;
|
|
||||||
$login->entity_name = $request->allowedEntityName;
|
|
||||||
$login->entity_type = $request->allowedEntityType;
|
|
||||||
$login->login_type = $request->allowedLoginType;
|
|
||||||
$login->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect('/admin/dashboard')->with('success', 'Entity added to allowed login list.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an entity from the allowed login table
|
|
||||||
*/
|
|
||||||
public function removeAllowedLogin(Request $request) {
|
|
||||||
//Set the parameters to validate the form
|
|
||||||
$this->validate($request, [
|
|
||||||
'removeAllowedLogin' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
AllowedLogin::where([
|
|
||||||
'entity_name' => $request->removeAllowedLogin,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
return redirect('/admin/dashboard')->with('success', 'Entity removed from allowed login list.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show journal entries in a table for admins from alliance wallets
|
|
||||||
*/
|
|
||||||
public function displayJournalEntries() {
|
|
||||||
$date = Carbon::now()->subDays(60);
|
|
||||||
|
|
||||||
$journal = AllianceWalletJournal::where('date', '>=', $date)
|
|
||||||
->where([
|
|
||||||
'corporation_id' => 98287666,
|
|
||||||
'ref_type' => 'player_donation',
|
|
||||||
])->orderByDesc('date',)->get(['amount', 'reason', 'description', 'date']);
|
|
||||||
|
|
||||||
return view('admin.dashboards.walletjournal')->with('journal', $journal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ use Illuminate\Support\Facades\DB;
|
|||||||
use Khill\Lavacharts\Lavacharts;
|
use Khill\Lavacharts\Lavacharts;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\StructureHelper;
|
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Esi\EsiScope;
|
use App\Models\Esi\EsiScope;
|
||||||
use App\Models\Esi\EsiToken;
|
use App\Models\Esi\EsiToken;
|
||||||
@@ -21,8 +17,6 @@ use App\Models\User\UserPermission;
|
|||||||
use App\Models\User\UserRole;
|
use App\Models\User\UserRole;
|
||||||
use App\Models\SRP\SRPShip;
|
use App\Models\SRP\SRPShip;
|
||||||
use App\Models\User\UserAlt;
|
use App\Models\User\UserAlt;
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
|
|
||||||
class DashboardController extends Controller
|
class DashboardController extends Controller
|
||||||
{
|
{
|
||||||
@@ -48,19 +42,9 @@ class DashboardController extends Controller
|
|||||||
$open = array();
|
$open = array();
|
||||||
$approved = array();
|
$approved = array();
|
||||||
$denied = array();
|
$denied = array();
|
||||||
$ores = array();
|
|
||||||
$altCount = null;
|
$altCount = null;
|
||||||
$alts = null;
|
$alts = null;
|
||||||
$structures = array();
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$config = config('esi');
|
|
||||||
$sHelper = new StructureHelper($config['primary'], $config['corporation']);
|
|
||||||
$lava = new Lavacharts;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alt Counts
|
|
||||||
*/
|
|
||||||
//Get the number of the user's alt which are registered so we can process the alt's on the main dashboard page
|
//Get the number of the user's alt which are registered so we can process the alt's on the main dashboard page
|
||||||
$altCount = UserAlt::where([
|
$altCount = UserAlt::where([
|
||||||
'main_id' => auth()->user()->character_id,
|
'main_id' => auth()->user()->character_id,
|
||||||
@@ -73,9 +57,6 @@ class DashboardController extends Controller
|
|||||||
])->get();
|
])->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* SRP Items
|
|
||||||
*/
|
|
||||||
//See if we can get all of the open SRP requests
|
//See if we can get all of the open SRP requests
|
||||||
$openCount = SRPShip::where([
|
$openCount = SRPShip::where([
|
||||||
'character_id' => auth()->user()->character_id,
|
'character_id' => auth()->user()->character_id,
|
||||||
@@ -179,6 +160,8 @@ class DashboardController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create a chart of number of approved, denied, and open requests via a fuel gauge chart
|
//Create a chart of number of approved, denied, and open requests via a fuel gauge chart
|
||||||
|
$lava = new Lavacharts;
|
||||||
|
|
||||||
$adur = $lava->DataTable();
|
$adur = $lava->DataTable();
|
||||||
|
|
||||||
$adur->addStringColumn('Type')
|
$adur->addStringColumn('Type')
|
||||||
@@ -201,93 +184,13 @@ class DashboardController extends Controller
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Mining Tax Items
|
|
||||||
*/
|
|
||||||
//Check for the correct scopes
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
|
||||||
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the correct scopes for the services site.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
//Get the esi data for extractions
|
|
||||||
try {
|
|
||||||
$extractions = $esi->invoke('get', '/corporation/{corporation_id}/mining/extractions', [
|
|
||||||
'corporation_id' => $config['corporation'],
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::critical('Could not retrieve the extractions from ESI in DisplayExtractionCalendar in MiningTaxesController');
|
|
||||||
return redirect('/dashboard')->with('error', 'Failed to get extraction data from ESI');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a 3 month calendar for the past, current, and future extractions
|
|
||||||
*/
|
|
||||||
//Create the data tables
|
|
||||||
$calendar = $lava->DataTable();
|
|
||||||
|
|
||||||
$calendar->addDateTimeColumn('Date')
|
|
||||||
->addNumberColumn('Total');
|
|
||||||
|
|
||||||
foreach($extractions as $extraction) {
|
|
||||||
$sInfo = $sHelper->GetStructureInfo($extraction->structure_id);
|
|
||||||
array_push($structures, [
|
|
||||||
'date' => $esiHelper->DecodeDate($extraction->chunk_arrival_time),
|
|
||||||
'total' => 0,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($extractions as $extraction) {
|
|
||||||
for($i = 0; $i < sizeof($structures); $i++) {
|
|
||||||
//Create the dates in a carbon object, then only get the Y-m-d to compare.
|
|
||||||
$tempStructureDate = Carbon::createFromFormat('Y-m-d H:i:s', $structures[$i]['date'])->toDateString();
|
|
||||||
$extractionDate = Carbon::createFromFormat('Y-m-d H:i:s', $esiHelper->DecodeDate($extraction->chunk_arrival_time))->toDateString();
|
|
||||||
//check if the dates are equal then increase the total by 1
|
|
||||||
if($tempStructureDate == $extractionDate) {
|
|
||||||
$structures[$i]['total'] += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($structures as $structure) {
|
|
||||||
$calendar->addRow([
|
|
||||||
$structure['date'],
|
|
||||||
$structure['total'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lava->CalendarChart('Extractions', $calendar, [
|
|
||||||
'title' => 'Upcoming Extractions',
|
|
||||||
'unusedMonthOutlineColor' => [
|
|
||||||
'stroke' => '#ECECEC',
|
|
||||||
'strokeOpacity' => 0.75,
|
|
||||||
'strokeWidth' => 1,
|
|
||||||
],
|
|
||||||
'dayOfWeekLabel' => [
|
|
||||||
'color' => '#4f5b0d',
|
|
||||||
'fontSize' => 16,
|
|
||||||
'italic' => true,
|
|
||||||
],
|
|
||||||
'noDataPattern' => [
|
|
||||||
'color' => '#DDD',
|
|
||||||
'backgroundColor' => '#11FFFF',
|
|
||||||
],
|
|
||||||
'colorAxis' => [
|
|
||||||
'values' => [0, 5],
|
|
||||||
'colors' => ['green', 'red'],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
return view('dashboard')->with('openCount', $openCount)
|
return view('dashboard')->with('openCount', $openCount)
|
||||||
->with('approvedCount', $approvedCount)
|
->with('approvedCount', $approvedCount)
|
||||||
->with('deniedCount', $deniedCount)
|
->with('deniedCount', $deniedCount)
|
||||||
->with('open', $open)
|
->with('open', $open)
|
||||||
->with('approved', $approved)
|
->with('approved', $approved)
|
||||||
->with('denied', $denied)
|
->with('denied', $denied)
|
||||||
->with('lava', $lava)
|
->with('lava', $lava);
|
||||||
->with('calendar', $calendar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
400
app/Http/Controllers/Dashboard/StatisticsController.php
Normal file
400
app/Http/Controllers/Dashboard/StatisticsController.php
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Dashboard;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Khill\Lavacharts\Lavacharts;
|
||||||
|
|
||||||
|
//Libraries
|
||||||
|
use App\Library\Taxes\TaxesHelper;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\SRP\SRPHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\User\User;
|
||||||
|
use App\Models\Doku\DokuGroupNames;
|
||||||
|
use App\Models\Doku\DokuMember;
|
||||||
|
use App\Models\Doku\DokuUser;
|
||||||
|
use App\Models\SRP\SrpFleetType;
|
||||||
|
use App\Models\SRP\SRPShip;
|
||||||
|
use App\Models\SRP\SrpShipType;
|
||||||
|
use App\Models\SRP\SrpPayout;
|
||||||
|
|
||||||
|
|
||||||
|
class StatisticsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new controller instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display Jump Bridge Statistics
|
||||||
|
*/
|
||||||
|
public function displayJumpBridgeStatistics() {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
$lava = new Lavacharts;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display Taxes Statistics
|
||||||
|
*/
|
||||||
|
public function displayTaxes() {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
//Declare variables needed for displaying items on the page
|
||||||
|
$months = 3;
|
||||||
|
$pi = array();
|
||||||
|
$industry = array();
|
||||||
|
$reprocessing = array();
|
||||||
|
$office = array();
|
||||||
|
$corpId = 98287666;
|
||||||
|
$srpActual = array();
|
||||||
|
$srpLoss = array();
|
||||||
|
|
||||||
|
/** Taxes Pane */
|
||||||
|
//Declare classes needed for displaying items on the page
|
||||||
|
$tHelper = new TaxesHelper;
|
||||||
|
$srpHelper = new SRPHelper;
|
||||||
|
//Get the dates for the tab panes
|
||||||
|
$dates = $tHelper->GetTimeFrameInMonths($months);
|
||||||
|
//Get the data for the Taxes Pane
|
||||||
|
foreach($dates as $date) {
|
||||||
|
//Get the srp actual pay out for the date range
|
||||||
|
$srpActual[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($srpHelper->GetAllianceSRPActual($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the srp loss value for the date range
|
||||||
|
$srpLoss[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($srpHelper->GetAllianceSRPLoss($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the pi taxes for the date range
|
||||||
|
$pis[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetPIGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the industry taxes for the date range
|
||||||
|
$industrys[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetIndustryGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the reprocessing taxes for the date range
|
||||||
|
$reprocessings[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetReprocessingGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the office taxes for the date range
|
||||||
|
$offices[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetOfficeGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the market taxes for the date range
|
||||||
|
$markets[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetAllianceMarketGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
//Get the jump gate taxes for the date range
|
||||||
|
$jumpgates[] = [
|
||||||
|
'date' => $date['start']->toFormattedDateString(),
|
||||||
|
'gross' => number_format($tHelper->GetJumpGateGross($date['start'], $date['end']), 2, ".", ","),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.dashboards.taxes')->with('pis', $pis)
|
||||||
|
->with('industrys', $industrys)
|
||||||
|
->with('offices', $offices)
|
||||||
|
->with('markets', $markets)
|
||||||
|
->with('jumpgates', $jumpgates)
|
||||||
|
->with('reprocessings', $reprocessings)
|
||||||
|
->with('srpActual', $srpActual)
|
||||||
|
->with('srpLoss', $srpLoss);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display wiki statistics
|
||||||
|
*/
|
||||||
|
public function displayWikiStatistics() {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display SRP Statistics
|
||||||
|
*/
|
||||||
|
public function displaySRPStatistics() {
|
||||||
|
$months = 3;
|
||||||
|
$barChartData = array();
|
||||||
|
$start = Carbon::now()->toDateTimeString();
|
||||||
|
$end = Carbon::now()->subMonths(1)->toDateTimeString();
|
||||||
|
|
||||||
|
//Declare the Lavacharts variable
|
||||||
|
$lava = new Lavacharts;
|
||||||
|
|
||||||
|
//We need a function from this library rather than recreating a new library
|
||||||
|
$srpHelper = new SRPHelper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pie chart for the number of approved, denied, and under review payouts currently in the system.
|
||||||
|
*/
|
||||||
|
//Get the count of open srp requests
|
||||||
|
$pieOpen = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
['created_at', '>=', $end],
|
||||||
|
])->count();
|
||||||
|
//Get the count of approved srp requests
|
||||||
|
$pieApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
['created_at', '>=', $end],
|
||||||
|
])->count();
|
||||||
|
//Get the count of denied srp requests
|
||||||
|
$pieDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
['created_at', '>=', $end],
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
//Create a new datatable for the lavachart.
|
||||||
|
$srp = $lava->DataTable();
|
||||||
|
//Add string columns, number columns, and data rows for the chart
|
||||||
|
$srp->addStringColumn('ISK Value')
|
||||||
|
->addNumberColumn('ISK')
|
||||||
|
->addRow(['Approved', $pieApproved])
|
||||||
|
->addRow(['Denied', $pieDenied])
|
||||||
|
->addRow(['Under Review', $pieOpen]);
|
||||||
|
//Create the pie chart in memory with any options needed to render the chart
|
||||||
|
$lava->PieChart('SRP Stats', $srp, [
|
||||||
|
'title' => 'SRP Stats',
|
||||||
|
'is3D' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gauage chart for showing number of open srp requests
|
||||||
|
*/
|
||||||
|
//Create a new datatable in the
|
||||||
|
$adur = $lava->DataTable();
|
||||||
|
//Add string columns, number columns, and data row for the chart
|
||||||
|
$adur->addStringColumn('Type')
|
||||||
|
->addNumberColumn('Value')
|
||||||
|
->addRow(['Under Review', $pieOpen]);
|
||||||
|
//Create the gauge chart with any options needed to render the chart
|
||||||
|
$lava->GaugeChart('SRP', $adur, [
|
||||||
|
'width' => 400,
|
||||||
|
'greenFrom' => 0,
|
||||||
|
'greenTo' => 20,
|
||||||
|
'yellowFrom' => 20,
|
||||||
|
'yellowTo' => 40,
|
||||||
|
'redFrom' => 40,
|
||||||
|
'redTo' => 100,
|
||||||
|
'majorTicks' => [
|
||||||
|
'Safe',
|
||||||
|
'Critical',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a vertical chart of all of the cost codes for the ships being SRP'ed.
|
||||||
|
* The chart will be by cost code of ships being replaced
|
||||||
|
*/
|
||||||
|
//Declare the data table
|
||||||
|
$costCodeChart = $lava->DataTable();
|
||||||
|
|
||||||
|
//Get the approved, under review, and denied cost codes and amounts
|
||||||
|
$t1fdcApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T1FDC',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t1fdcUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T1FDC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t1fdcDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T1FDC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t1bcApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T1BC',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t1bcUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T1BC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t1bcDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T1BC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t2fdApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T2FD',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t2fdUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T2FD',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t2fdDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T2FD',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t3dApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T3D',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t3dUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T3D',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t3dDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T3D',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t1t2logiApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T1T2Logi',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t1t2logiUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T1T2Logi',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t1t2logiDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T1T2Logi',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$reconsApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'REC',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$reconsUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'REC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$reconsDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'REC',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t2cApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T2C',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t2cUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T2C',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t2cDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T2C',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t3cApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T3C',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t3cUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T3C',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t3cDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T3C',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$commandApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'COM',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$commandUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'COM',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$commandDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'COM',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$interdictorApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'INTD',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$interdictorUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'INTD',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$interdictorDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'INTD',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$t1bsApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'T1BS',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$t1bsUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'T1BS',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$t1bsDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'T1BS',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
$dksApproved = SRPShip::where([
|
||||||
|
'approved' => 'Approved',
|
||||||
|
'ship_type' => 'DKS',
|
||||||
|
])->sum('paid_value');
|
||||||
|
$dksUnderReview = SRPShip::where([
|
||||||
|
'approved' => 'Under Review',
|
||||||
|
'ship_type' => 'DKS',
|
||||||
|
])->sum('loss_value');
|
||||||
|
$dksDenied = SRPShip::where([
|
||||||
|
'approved' => 'Denied',
|
||||||
|
'ship_type' => 'DKS',
|
||||||
|
])->sum('loss_value');
|
||||||
|
|
||||||
|
|
||||||
|
//Add string column, number columns.
|
||||||
|
$costCodeChart->addStringColumn('SRP Costs')
|
||||||
|
->addNumberColumn('Approved')
|
||||||
|
->addNumberColumn('Under Review')
|
||||||
|
->addNumberColumn('Denied')
|
||||||
|
->addRow(['T1FDC', $t1fdcApproved, $t1fdcUnderReview, $t1fdcDenied])
|
||||||
|
->addRow(['T1BC', $t1bcApproved, $t1bcUnderReview, $t1bcDenied])
|
||||||
|
->addRow(['T1BS', $t1bsApproved, $t1bsUnderReview, $t1bsDenied])
|
||||||
|
->addRow(['T2FD', $t2fdApproved, $t2fdUnderReview, $t2fdDenied])
|
||||||
|
->addRow(['T2C', $t2cApproved, $t2cUnderReview, $t2cDenied])
|
||||||
|
->addRow(['T1T2Logi', $t1t2logiApproved, $t1t2logiUnderReview, $t1t2logiDenied])
|
||||||
|
->addRow(['T3D', $t3dApproved, $t3dUnderReview, $t3dDenied])
|
||||||
|
->addRow(['T3C', $t3cApproved, $t3cUnderReview, $t3cDenied])
|
||||||
|
->addRow(['RECON', $reconsApproved, $reconsUnderReview, $reconsDenied])
|
||||||
|
->addRow(['COMMAND', $commandApproved, $commandUnderReview, $commandDenied])
|
||||||
|
->addRow(['DKS', $dksApproved, $dksUnderReview, $dksDenied]);
|
||||||
|
|
||||||
|
$lava->ColumnChart('Cost Codes', $costCodeChart, [
|
||||||
|
'columns' => 4,
|
||||||
|
'title' => 'Cost Code SRP Chart',
|
||||||
|
'titleTextStyle' => [
|
||||||
|
'color' => '#eb6b2c',
|
||||||
|
'fontSize' => 14,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return view('srp.admin.statistics')->with('lava', $lava);
|
||||||
|
}
|
||||||
|
}
|
||||||
133
app/Http/Controllers/Flex/FlexAdminController.php
Normal file
133
app/Http/Controllers/Flex/FlexAdminController.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Flex;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Auth;
|
||||||
|
use DB;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Flex\FlexStructure;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
class FlexAdminController extends Controller
|
||||||
|
{
|
||||||
|
//Constructor
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display all active flex structures and
|
||||||
|
* the information regarding the flex structure
|
||||||
|
*/
|
||||||
|
public function displayFlexStructures() {
|
||||||
|
//Get the structures from the database
|
||||||
|
$structures = FlexStructure::all();
|
||||||
|
|
||||||
|
//Return the view with the data
|
||||||
|
return view('flex.list')->with('structures', $structures);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display form for adding new flex structure
|
||||||
|
*/
|
||||||
|
public function displayAddFlexStructure() {
|
||||||
|
return view('flex.add');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to add new flex structure to the database
|
||||||
|
*/
|
||||||
|
public function addFlexStructure(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'requestor_name' => 'required',
|
||||||
|
'requestor_corp_name' => 'required',
|
||||||
|
'system' => 'required',
|
||||||
|
'structure_type' => 'required',
|
||||||
|
'structure_cost' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Delcare variables and classes
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
//From the character name find the character id
|
||||||
|
$charId = $lookup->CharacterNameToId($request->requestor_name);
|
||||||
|
|
||||||
|
//From the corporation name find the corporation id
|
||||||
|
$corpId = $lookup->CorporationNameToId($request->requestor_corp_name);
|
||||||
|
|
||||||
|
//From the system name find the system id
|
||||||
|
$systemId = $lookup->SystemNameToId($request->system);
|
||||||
|
|
||||||
|
//Create the database model
|
||||||
|
$flex = new FlexStructure;
|
||||||
|
$flex->requestor_id = $charId;
|
||||||
|
$flex->requestor_name = $request->requestor_name;
|
||||||
|
$flex->requestor_corp_id = $corpId;
|
||||||
|
$flex->requestor_corp_name = $request->requestor_corp_name;
|
||||||
|
$flex->system_id = $systemId;
|
||||||
|
$flex->system = $request->system;
|
||||||
|
$flex->structure_type = $request->structure_type;
|
||||||
|
$flex->structure_cost = $request->structure_cost;
|
||||||
|
if(isset($request->paid_until)) {
|
||||||
|
$flex->paid_until = $request->paid_until;
|
||||||
|
}
|
||||||
|
$flex->save();
|
||||||
|
|
||||||
|
return redirect('/flex/display')->with('success', 'Flex Structure Added.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to update paid until section of the flex structure in the database
|
||||||
|
*/
|
||||||
|
public function updateFlexStructure(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'paid_until' => 'required',
|
||||||
|
'requestor_id' => 'required',
|
||||||
|
'requestor_corp_id' => 'required',
|
||||||
|
'system_id' => 'required',
|
||||||
|
'structure_type' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
FlexStructure::where([
|
||||||
|
'requestor_id' => $request->requestor_id,
|
||||||
|
'requestor_corp_id' => $request->requestor_corp_id,
|
||||||
|
'system_id' => $request->system_id,
|
||||||
|
'structure_type' => $request->structure_type,
|
||||||
|
])->update([
|
||||||
|
'paid_until' => $request->paid_until,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect('/flex/display')->with('success', 'Flex Structure Updated.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Funciton to remove flex structure from the database
|
||||||
|
*/
|
||||||
|
public function removeFlexStructure(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'requestor_id' => 'required',
|
||||||
|
'requestor_corp_id' => 'required',
|
||||||
|
'system_id' => 'required',
|
||||||
|
'structure_type' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
FlexStructure::where([
|
||||||
|
'requestor_id' => $request->requestor_id,
|
||||||
|
'requestor_corp_id' => $request->requestor_corp_id,
|
||||||
|
'system' => $request->system_id,
|
||||||
|
'structure_type' => $request->structure_type,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
return redirect('/flex/display')->with('success', 'Flex Structure Entry Removed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,13 +13,11 @@ use Auth;
|
|||||||
use Charts;
|
use Charts;
|
||||||
|
|
||||||
//Library Helpers
|
//Library Helpers
|
||||||
use App\Library\Helpers\AssetHelper;
|
use App\Library\Assets\AssetHelper;
|
||||||
use App\Library\Helpers\StructureHelper;
|
use App\Library\Structures\StructureHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Structure\Structure;
|
use App\Models\Structure\Structure;
|
||||||
use App\Models\Structure\Asset;
|
|
||||||
use App\Models\Structure\Service;
|
|
||||||
|
|
||||||
class FuelController extends Controller
|
class FuelController extends Controller
|
||||||
{
|
{
|
||||||
@@ -83,6 +81,6 @@ class FuelController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return view('logistics.fuel')->with('jumpGates', $jumpGates)
|
return view('logistics.fuel')->with('jumpGates', $jumpGates)
|
||||||
->with('lava', $lava);
|
->with('lava', $lava);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Logistics;
|
||||||
|
|
||||||
|
//Internal Libraries
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Logistics\AnchorStructure;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
|
class StructureRequestAdminController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('permission:fc.team');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayRequests() {
|
||||||
|
$reqs = AnchorStructure::all();
|
||||||
|
|
||||||
|
return view('structurerequest.display.structurerequests')->with('reqs', $reqs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteRequest(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'id' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
AnchorStructure::where([
|
||||||
|
'id' => $request->id,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
return redirect('/structures/display/requests');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Logistics;
|
||||||
|
|
||||||
|
//Internal Libraries
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Library Helpers
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Logistics\AnchorStructure;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
use App\Models\User\UserPermission;
|
||||||
|
|
||||||
|
class StructureRequestController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:User');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayForm() {
|
||||||
|
return view('structurerequest.requeststructure');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeForm(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'corporation_name' => 'required',
|
||||||
|
'system' => 'required',
|
||||||
|
'structure_size' => 'required',
|
||||||
|
'structure_type' => 'required',
|
||||||
|
'requested_drop_time' => 'required',
|
||||||
|
'requester' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
$requesterId = $lookup->CharacterNameToId($request->requester);
|
||||||
|
$corporationId = $lookup->CorporationNameToId($request->corporation_name);
|
||||||
|
|
||||||
|
AnchorStructure::insert([
|
||||||
|
'corporation_id' => $corporationId,
|
||||||
|
'corporation_name' => $request->corporation_name,
|
||||||
|
'system' => $request->system,
|
||||||
|
'structure_size' => $request->structure_size,
|
||||||
|
'structure_type' => $request->structure_type,
|
||||||
|
'requested_drop_time' => $request->requested_drop_time,
|
||||||
|
'requester_id' => $requesterId,
|
||||||
|
'requester' => $request->requester,
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Send a mail out to the FC Team
|
||||||
|
$fcTeam = UserPermission::where([
|
||||||
|
'permission' => 'fc.team',
|
||||||
|
])->get();
|
||||||
|
|
||||||
|
//Set the mail delay
|
||||||
|
$delay = 5;
|
||||||
|
|
||||||
|
foreach($fcTeam as $fc) {
|
||||||
|
$body = "Structure Anchor Request has been entered.<br>";
|
||||||
|
$body .= "Please check the W4RP Services Site for the structure information.<br>";
|
||||||
|
$body .= "<br>Sincerely,<br>";
|
||||||
|
$body .= "Warped Intentions Leadership<br>";
|
||||||
|
|
||||||
|
//Dispatch the mail job
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = "New Structure Anchor Request";
|
||||||
|
$mail->body = $body;
|
||||||
|
$mail->recipient = (int)$fc->character_id;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay($delay);
|
||||||
|
|
||||||
|
$delay += 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect('/structures/display/requests');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Khill\Lavacharts\Lavacharts;
|
|
||||||
use Auth;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Helpers\StructureHelper;
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\MiningTax\Payment;
|
|
||||||
use App\Models\Moon\ItemComposition;
|
|
||||||
use App\Models\Moon\MineralPrice;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
|
|
||||||
class MiningTaxesAdminController extends Controller
|
|
||||||
{
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('role:Admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the page to setup the form for corporations to rent a moon
|
|
||||||
*/
|
|
||||||
public function DisplayMoonRentalForm() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the details for the form for corporations renting a specific moon
|
|
||||||
*/
|
|
||||||
public function StoreMoonRentalForm() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a moon from being rented from a specific corporation
|
|
||||||
*/
|
|
||||||
public function DeleteMoonRental(Request $request) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display current unpaid invoices
|
|
||||||
*/
|
|
||||||
public function DisplayUnpaidInvoice() {
|
|
||||||
$invoices = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Late',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Deferred',
|
|
||||||
])->orderByDesc('invoice_id')->paginate(50);
|
|
||||||
|
|
||||||
$totalAmount = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Late',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Deferred',
|
|
||||||
])->sum('invoice_amount');
|
|
||||||
|
|
||||||
return view('miningtax.admin.display.unpaid')->with('invoices', $invoices);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search unpaid invoices
|
|
||||||
*/
|
|
||||||
public function SearchUnpaidInvoice(Request $request) {
|
|
||||||
$invoices = Invoice::where('invoice_id', 'LIKE', '%' . $request->q . '%')
|
|
||||||
->where(['status' => 'Pending'])
|
|
||||||
->orWhere(['status' => 'Late'])
|
|
||||||
->orWhere(['status' => 'Deferred'])
|
|
||||||
->orderByDesc('invoice_id')
|
|
||||||
->paginate(25);
|
|
||||||
|
|
||||||
if(count($invoices) > 0) {
|
|
||||||
return view('miningtax.admin.display.unpaid')->with('invoices', $invoices);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('miningtax.admin.display.unpaid')->with('error', 'No invoices found');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display page to modify an unpaid invoice
|
|
||||||
*/
|
|
||||||
public function DisplayModifyInvoice() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify an unpaid invoice
|
|
||||||
*/
|
|
||||||
public function ProcessModifyInvoice() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark an invoice paid
|
|
||||||
*/
|
|
||||||
public function UpdateInvoice(Request $request) {
|
|
||||||
$this->validate($request, [
|
|
||||||
'invoiceId' => 'required',
|
|
||||||
'status' => 'required',
|
|
||||||
]);
|
|
||||||
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $request->invoiceId,
|
|
||||||
])->update([
|
|
||||||
'status' => $request->status,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect('/miningtax/admin/display/unpaid')->with('success', 'Invoice successfully updated.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display past paid invoices
|
|
||||||
*/
|
|
||||||
public function DisplayPaidInvoices() {
|
|
||||||
$invoices = Invoice::where([
|
|
||||||
'status' => 'Paid',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Paid Late',
|
|
||||||
])->paginate(50);
|
|
||||||
|
|
||||||
$totalAmount = Invoice::where([
|
|
||||||
'status' => 'Paid',
|
|
||||||
])->orWhere([
|
|
||||||
'status' => 'Paid Late',
|
|
||||||
])->sum('invoice_amount');
|
|
||||||
|
|
||||||
return view('miningtax.admin.display.paidinvoices')->with('invoices', $invoices)
|
|
||||||
->with('totalAmount', $totalAmount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,310 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use DB;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Khill\Lavacharts\Lavacharts;
|
|
||||||
use Auth;
|
|
||||||
//Collection Stuff
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
//Library Helpers
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Helpers\StructureHelper;
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Moon\ItemComposition;
|
|
||||||
use App\Models\Moon\MineralPrice;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
use App\Models\User\User;
|
|
||||||
|
|
||||||
class MiningTaxesController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Construct to deal with middleware and other items
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('role:User');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display an invoice based on it's id
|
|
||||||
*
|
|
||||||
* @var $invoiceId
|
|
||||||
*/
|
|
||||||
public function DisplayInvoice($invoiceId) {
|
|
||||||
$ores = array();
|
|
||||||
$totalPrice = 0.00;
|
|
||||||
|
|
||||||
$invoice = Invoice::where([
|
|
||||||
'invoice_id' => $invoiceId,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
$items = Ledger::where([
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
'invoice_id' => $invoice,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
foreach($items as $item) {
|
|
||||||
if(!isset($ores[$item['ore_name']])) {
|
|
||||||
$ores[$item['ore_name']] = 0;
|
|
||||||
}
|
|
||||||
$ores[$item['ore_name']] = $ores[$item['ore_name']] + $item['quantity'];
|
|
||||||
|
|
||||||
$totalPrice += $item['amount'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('miningtax.user.display.details.invoice')->with('ores', $ores)
|
|
||||||
->with('invoice', $invoice)
|
|
||||||
->with('totalPrice', $totalPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the users invoices
|
|
||||||
*/
|
|
||||||
public function DisplayInvoices() {
|
|
||||||
//Declare variables
|
|
||||||
$paidAmount = 0.00;
|
|
||||||
$unpaidAmount = 0.00;
|
|
||||||
|
|
||||||
//Get the unpaid invoices
|
|
||||||
$unpaid = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->paginate(15);
|
|
||||||
|
|
||||||
//Get the late invoices
|
|
||||||
$late = Invoice::where([
|
|
||||||
'status' => 'Late',
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->paginate(10);
|
|
||||||
|
|
||||||
//Get the deferred invoices
|
|
||||||
$deferred = Invoice::where([
|
|
||||||
'status' => 'Deferred',
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->paginate(10);
|
|
||||||
|
|
||||||
//Get the paid invoices
|
|
||||||
$paid = Invoice::where([
|
|
||||||
'status' => 'Paid',
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->paginate(15);
|
|
||||||
|
|
||||||
//Total up the unpaid invoices
|
|
||||||
foreach($unpaid as $un) {
|
|
||||||
$unpaidAmount += $un->invoice_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Total up the paid invoices
|
|
||||||
foreach($paid as $p) {
|
|
||||||
$paidAmount += $p->invoice_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('miningtax.user.display.invoices')->with('unpaid', $unpaid)
|
|
||||||
->with('late', $late)
|
|
||||||
->with('deferred', $deferred)
|
|
||||||
->with('paid', $paid)
|
|
||||||
->with('unpaidAmount', $unpaidAmount)
|
|
||||||
->with('paidAmount', $paidAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display all of the upcoming extractions
|
|
||||||
*/
|
|
||||||
public function DisplayUpcomingExtractions() {
|
|
||||||
|
|
||||||
//Declare variables
|
|
||||||
$structures = array();
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$config = config('esi');
|
|
||||||
$sHelper = new StructureHelper($config['primary'], $config['corporation']);
|
|
||||||
$structures = array();
|
|
||||||
$structuresCalendar = array();
|
|
||||||
$lava = new Lavacharts;
|
|
||||||
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
|
||||||
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the correct scopes for the services site.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
//Get the esi data for extractions
|
|
||||||
try {
|
|
||||||
$extractions = $esi->invoke('get', '/corporation/{corporation_id}/mining/extractions/', [
|
|
||||||
'corporation_id' => $config['corporation'],
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::warning('Could not retrieve extractions from ESI in MiningTaxesController.php');
|
|
||||||
return redirect('/dashboard')->with('error', "Could not pull extractions from ESI data.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Basically get the structure info and attach it to the variable set
|
|
||||||
foreach($extractions as $ex) {
|
|
||||||
$sName = $sHelper->GetStructureInfo($ex->structure_id);
|
|
||||||
array_push($structures, [
|
|
||||||
'structure_name' => $sName->name,
|
|
||||||
'start_time' => $esiHelper->DecodeDate($ex->extraction_start_time),
|
|
||||||
'arrival_time' => $esiHelper->DecodeDate($ex->chunk_arrival_time),
|
|
||||||
'decay_time' => $esiHelper->DecodeDate($ex->natural_decay_time),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Sort extractions by arrival time
|
|
||||||
$structuresCollection = collect($structures);
|
|
||||||
$sorted = $structuresCollection->sortBy('arrival_time');
|
|
||||||
//Store the sorted collection back into the variable before being used again.
|
|
||||||
$structures = $sorted->all();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a 3 month calendar for the past, current, and future extractions
|
|
||||||
*/
|
|
||||||
//Create the data tables
|
|
||||||
$calendar = $lava->DataTable();
|
|
||||||
|
|
||||||
$calendar->addDateTimeColumn('Date')
|
|
||||||
->addNumberColumn('Total');
|
|
||||||
|
|
||||||
foreach($extractions as $extraction) {
|
|
||||||
array_push($structuresCalendar, [
|
|
||||||
'date' => $esiHelper->DecodeDate($extraction->chunk_arrival_time),
|
|
||||||
'total' => 0,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($extractions as $extraction) {
|
|
||||||
for($i = 0; $i < sizeof($structuresCalendar); $i++) {
|
|
||||||
//Create the dates in a carbon object, then only get the Y-m-d to compare.
|
|
||||||
$tempStructureDate = Carbon::createFromFormat('Y-m-d H:i:s', $structuresCalendar[$i]['date'])->toDateString();
|
|
||||||
$extractionDate = Carbon::createFromFormat('Y-m-d H:i:s', $esiHelper->DecodeDate($extraction->chunk_arrival_time))->toDateString();
|
|
||||||
//check if the dates are equal then increase the total by 1
|
|
||||||
if($tempStructureDate == $extractionDate) {
|
|
||||||
$structuresCalendar[$i]['total'] += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($structuresCalendar as $structureC) {
|
|
||||||
$calendar->addRow([
|
|
||||||
$structureC['date'],
|
|
||||||
$structureC['total'],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lava->CalendarChart('Extractions', $calendar, [
|
|
||||||
'title' => 'Upcoming Extractions',
|
|
||||||
'unusedMonthOutlineColor' => [
|
|
||||||
'stroke' => '#ECECEC',
|
|
||||||
'strokeOpacity' => 0.75,
|
|
||||||
'strokeWidth' => 1,
|
|
||||||
],
|
|
||||||
'dayOfWeekLabel' => [
|
|
||||||
'color' => '#4f5b0d',
|
|
||||||
'fontSize' => 16,
|
|
||||||
'italic' => true,
|
|
||||||
],
|
|
||||||
'noDataPattern' => [
|
|
||||||
'color' => '#DDD',
|
|
||||||
'backgroundColor' => '#11FFFF',
|
|
||||||
],
|
|
||||||
'colorAxis' => [
|
|
||||||
'values' => [0, 5],
|
|
||||||
'colors' => ['green', 'red'],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Return the view with the extractions variable for html processing
|
|
||||||
return view('miningtax.user.display.upcoming')->with('structures', $structures)
|
|
||||||
->with('lava', $lava)
|
|
||||||
->with('calendar', $calendar);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the ledger for the moons.
|
|
||||||
*/
|
|
||||||
public function DisplayMoonLedgers() {
|
|
||||||
//Declare variables
|
|
||||||
$structures = array();
|
|
||||||
$tempLedgers = array();
|
|
||||||
$miningLedgers = array();
|
|
||||||
$ledgers = array();
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Check for the esi scope
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
|
||||||
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp for corp mining.');
|
|
||||||
} else {
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) {
|
|
||||||
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp for structures.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the refresh token if scope checks have passed
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
|
|
||||||
//Setup the esi container
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
//Declare the structure helper after the esi container has been created
|
|
||||||
$sHelper = new StructureHelper($config['primary'], $config['corporation'], $esi);
|
|
||||||
|
|
||||||
//Get the character data from the lookup table if possible or esi
|
|
||||||
$character = $lookup->GetCharacterInfo($config['primary']);
|
|
||||||
|
|
||||||
//Get the corporation information from the character id
|
|
||||||
$corpInfo = $lookup->GetCorporationInfo($character->corporation_id);
|
|
||||||
|
|
||||||
//Get the observers from the database
|
|
||||||
$observers = Observer::all();
|
|
||||||
|
|
||||||
//Get the ledgers for each structure one at a time
|
|
||||||
foreach($observers as $obs) {
|
|
||||||
//Get the structure information
|
|
||||||
$structureInfo = $sHelper->GetStructureInfo($obs->observer_id);
|
|
||||||
|
|
||||||
//Add the name to the structures array
|
|
||||||
array_push($structures, $structureInfo->name);
|
|
||||||
/**
|
|
||||||
* Get the ledger from each observer.
|
|
||||||
* We don't care about observer type as it can only be an Athanor or Tatara
|
|
||||||
*/
|
|
||||||
$ledgers = Ledger::where([
|
|
||||||
'observer_id' => $obs->observer_id,
|
|
||||||
'character_id' => auth()->user()->getId(),
|
|
||||||
])->where('last_updated', '>=', Carbon::now()->subDays(30))->get();
|
|
||||||
|
|
||||||
if($ledgers->count() > 0) {
|
|
||||||
foreach($ledgers as $ledger) {
|
|
||||||
//Foreach ledger add it to the array
|
|
||||||
array_push($miningLedgers, [
|
|
||||||
'structure' => $structureInfo->name,
|
|
||||||
'character' => auth()->user()->getName(),
|
|
||||||
'corpTicker' => $corpInfo->ticker,
|
|
||||||
'ore' => $ledger->ore_name,
|
|
||||||
'quantity' => $ledger->quantity,
|
|
||||||
'updated' => $ledger->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return the view
|
|
||||||
return view('miningtax.user.display.ledger')->with('miningLedgers', $miningLedgers)
|
|
||||||
->with('structures', $structures);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\MoonRental;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class MoonRentalAdminController extends Controller
|
|
||||||
{
|
|
||||||
//Constructor
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('role:Admin');
|
|
||||||
$this->middleware('permission:moon.rental.manager');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display rental requests
|
|
||||||
*/
|
|
||||||
public function displayRentalRequests() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create monthly moon rental
|
|
||||||
*/
|
|
||||||
public function storeRentalRequest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete / remove monthly moon rental
|
|
||||||
*/
|
|
||||||
public function updateRentalRequest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display current monthly moon rentals
|
|
||||||
*/
|
|
||||||
public function displayCurrentRentals() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\MoonRental;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
class MoonRentalController extends Controller
|
|
||||||
{
|
|
||||||
//Constructor
|
|
||||||
public function __construct() {
|
|
||||||
$this->middleware('role:user');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display all of the available moons for rental
|
|
||||||
*/
|
|
||||||
public function displayMoons() {
|
|
||||||
$moons = AllianceMoon::where([
|
|
||||||
'rented' => 'No',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
return view('moon.rental.available.display')->with('moons', $moons);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display moon rental request form
|
|
||||||
*/
|
|
||||||
public function displayMoonRentalRequestForm() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store moon rental from the request form
|
|
||||||
*/
|
|
||||||
public function storeMoonRentalRequest() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request a mail job be added to the mail queue to resend mining bill instantly
|
|
||||||
*/
|
|
||||||
public function requestMoonRentalBill() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
234
app/Http/Controllers/Moons/MoonLedgerController.php
Normal file
234
app/Http/Controllers/Moons/MoonLedgerController.php
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Moons;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Structures\StructureHelper;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
|
//App Models
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Lookups\ItemLookup;
|
||||||
|
use App\Models\MoonRent\MoonRental;
|
||||||
|
use App\Models\Moon\RentalMoon;
|
||||||
|
|
||||||
|
class MoonLedgerController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:User');
|
||||||
|
$this->middleware('permission:corp.lead');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayMoonLedger() {
|
||||||
|
//Declare variables
|
||||||
|
$structures = array();
|
||||||
|
$miningLedgers = array();
|
||||||
|
$tempMiningLedger = array();
|
||||||
|
$tempMining = array();
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$response = null;
|
||||||
|
$structureInfo = null;
|
||||||
|
|
||||||
|
//Check for the esi scope
|
||||||
|
if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-industry.read_corporation_mining.v1')) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Need to add scopes for esi-industry.read_corporation_mining.v1');
|
||||||
|
} else {
|
||||||
|
if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-universe.read_structures.v1')) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Need to add scope for esi-universe.read_structures.v1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the refresh token if scope checks have passed
|
||||||
|
$refreshToken = $esiHelper->GetRefreshToken(auth()->user()->getId());
|
||||||
|
|
||||||
|
//Setup the esi container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||||
|
|
||||||
|
//Get the character data from the lookup table if possible or esi
|
||||||
|
$character = $lookup->GetCharacterInfo(auth()->user()->getId());
|
||||||
|
|
||||||
|
//Try to get the mining observers for the corporation from esi
|
||||||
|
try {
|
||||||
|
$responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
||||||
|
'corporation_id' => $character->corporation_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
//If an exception has occurred for some reason redirect back to the dashboard with an error message
|
||||||
|
return redirect('/dashboard')->with('error', 'Failed to get mining structures.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//For each mining observer, let's build the array of data to show on the page
|
||||||
|
foreach($responses as $response) {
|
||||||
|
//Try to get the structure information from esi
|
||||||
|
try {
|
||||||
|
$structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||||
|
'structure_id' => $response->observer_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
//If an exception has occurred, then do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
//We don't really care about the key, but it is better than just 0 through whatever number
|
||||||
|
$structures[$response->observer_id] = $structureInfo->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//For each of the structures we want to address it by it's key value pair.
|
||||||
|
//This will allow us to do some interesting things in the display.
|
||||||
|
foreach($structures as $key => $value) {
|
||||||
|
try {
|
||||||
|
$ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
||||||
|
'corporation_id' => $character->corporation_id,
|
||||||
|
'observer_id' => $key,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
$ledgers = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($ledgers != null) {
|
||||||
|
foreach($ledgers as $ledger) {
|
||||||
|
//Declare a variable that will need to be cleared each time the foreach processes
|
||||||
|
$tempArray = array();
|
||||||
|
|
||||||
|
//Get the character information from the character id
|
||||||
|
$charInfo = $lookup->GetCharacterInfo($ledger->character_id);
|
||||||
|
//Get the corp ticker
|
||||||
|
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||||
|
//Get the ore name from the type id
|
||||||
|
$ore = $lookup->ItemIdToName($ledger->type_id);
|
||||||
|
|
||||||
|
//We only want to push the mining ledger entry into the array if it matches
|
||||||
|
//the date within 30 days
|
||||||
|
$sortTime = Carbon::now()->subDays(30);
|
||||||
|
$current = Carbon::createFromFormat('Y-m-d', $ledger->last_updated);
|
||||||
|
if($current->greaterThanOrEqualTo($sortTime)) {
|
||||||
|
array_push($miningLedgers, [
|
||||||
|
'structure' => $value,
|
||||||
|
'character' => $charInfo->name,
|
||||||
|
'corpTicker' => $corpInfo->ticker,
|
||||||
|
'ore' => $ore,
|
||||||
|
'quantity' => $ledger->quantity,
|
||||||
|
'updated' => $ledger->last_updated,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('moons.ledger.corpmoons')->with('miningLedgers', $miningLedgers)
|
||||||
|
->with('structures', $structures);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayRentalMoonLedger() {
|
||||||
|
//Declare variables
|
||||||
|
$structures = array();
|
||||||
|
$miningLedgers = array();
|
||||||
|
$tempMiningLedger = array();
|
||||||
|
$tempMining = array();
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$response = null;
|
||||||
|
$structureInfo = null;
|
||||||
|
|
||||||
|
//Get the configuration for the main site
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Check for the esi scope
|
||||||
|
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.');
|
||||||
|
} else {
|
||||||
|
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the refresh token if scope checks have passed
|
||||||
|
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
||||||
|
|
||||||
|
//Setup the esi container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||||
|
|
||||||
|
//Get the character data from the lookup table if possible or esi
|
||||||
|
$character = $lookup->GetCharacterInfo($config['primary']);
|
||||||
|
|
||||||
|
//Try to get the mining observers for the corporation from esi
|
||||||
|
try {
|
||||||
|
$responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
||||||
|
'corporation_id' => $character->corporation_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
//If an exception has occurred for some reason redirect back to the dashboard with an error message
|
||||||
|
return redirect('/dashboard')->with('error', 'Failed to get mining structures.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//For each mining observer, let's build the array of data to show on the page
|
||||||
|
foreach($responses as $response) {
|
||||||
|
//Try to get the structure information from esi
|
||||||
|
try {
|
||||||
|
$structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||||
|
'structure_id' => $response->observer_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
//If an exception has occurred, then do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
//We don't really care about the key, but it is better than just 0 through whatever number
|
||||||
|
$structures[$response->observer_id] = $structureInfo->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//For each of the structures we want to address it by it's key value pair.
|
||||||
|
//This will allow us to do some interesting things in the display.
|
||||||
|
foreach($structures as $key => $value) {
|
||||||
|
try {
|
||||||
|
$ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
||||||
|
'corporation_id' => $character->corporation_id,
|
||||||
|
'observer_id' => $key,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
$ledgers = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($ledgers != null) {
|
||||||
|
foreach($ledgers as $ledger) {
|
||||||
|
//Declare a variable that will need to be cleared each time the foreach processes
|
||||||
|
$tempArray = array();
|
||||||
|
|
||||||
|
//Get the character information from the character id
|
||||||
|
$charInfo = $lookup->GetCharacterInfo($ledger->character_id);
|
||||||
|
//Get the corp ticker
|
||||||
|
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||||
|
//Get the ore name from the type id
|
||||||
|
$ore = $lookup->ItemIdToName($ledger->type_id);
|
||||||
|
|
||||||
|
//We only want to push the mining ledger entry into the array if it matches
|
||||||
|
//the date within 30 days
|
||||||
|
$sortTime = Carbon::now()->subDays(30);
|
||||||
|
$current = Carbon::createFromFormat('Y-m-d', $ledger->last_updated);
|
||||||
|
if($current->greaterThanOrEqualTo($sortTime)) {
|
||||||
|
array_push($miningLedgers, [
|
||||||
|
'structure' => $value,
|
||||||
|
'character' => $charInfo->name,
|
||||||
|
'corpTicker' => $corpInfo->ticker,
|
||||||
|
'ore' => $ore,
|
||||||
|
'quantity' => $ledger->quantity,
|
||||||
|
'updated' => $ledger->last_updated,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('moons.ledger.corpmoons')->with('miningLedgers', $miningLedgers)
|
||||||
|
->with('structures', $structures);
|
||||||
|
}
|
||||||
|
}
|
||||||
541
app/Http/Controllers/Moons/MoonsAdminController.php
Normal file
541
app/Http/Controllers/Moons/MoonsAdminController.php
Normal file
@@ -0,0 +1,541 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Moons;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Moon\Config;
|
||||||
|
use App\Models\Moon\ItemComposition;
|
||||||
|
use App\Models\Moon\RentalMoon;
|
||||||
|
use App\Models\Moon\OrePrice;
|
||||||
|
use App\Models\Moon\Price;
|
||||||
|
use App\Models\MoonRent\MoonRental;
|
||||||
|
use App\Models\Moon\AllianceMoon;
|
||||||
|
use App\Models\Moon\AllianceMoonRequest;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Moons\MoonCalc;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
|
//Jobs
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
class MoonsAdminController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor for the class
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display moon requests
|
||||||
|
*/
|
||||||
|
public function displayMoonRequests() {
|
||||||
|
$requests = AllianceMoonRequest::where([
|
||||||
|
'status' => 'Pending',
|
||||||
|
])->get();
|
||||||
|
|
||||||
|
return view('moons.admin.moonrequest')->with('requests', $requests);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to approve a moon request
|
||||||
|
*/
|
||||||
|
public function storeApprovedMoonRequest(Request $request) {
|
||||||
|
//Validate the input request
|
||||||
|
$this->validate($request, [
|
||||||
|
'id' => 'required',
|
||||||
|
'status' => 'required',
|
||||||
|
'system' => 'required',
|
||||||
|
'planet' => 'required',
|
||||||
|
'moon' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
//Get the request data which holds all of the information for the request user
|
||||||
|
$moon = AllianceMoonRequest::where([
|
||||||
|
'id' => $request->id,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
//Get the configuration data to use later in the function
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//If the request is approved, then update everything.
|
||||||
|
if($request->status == 'Approved') {
|
||||||
|
//Update the alliance moon request to either approved or denied
|
||||||
|
AllianceMoonRequest::where([
|
||||||
|
'id' => $request->id,
|
||||||
|
])->update([
|
||||||
|
'status' => $request->status,
|
||||||
|
'approver_name' => auth()->user()->getName(),
|
||||||
|
'approver_id' => auth()->user()->getId(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the alliance moon in the table to the correct status
|
||||||
|
AllianceMoon::where([
|
||||||
|
'System' => $request->system,
|
||||||
|
'Planet' => $request->planet,
|
||||||
|
'Moon' => $request->moon,
|
||||||
|
])->update([
|
||||||
|
'Corporation' => $moon->corporation_ticker,
|
||||||
|
'Availability' => 'Deployed',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Send an eve mail to the requestor stating they can set a moon up.
|
||||||
|
//Setup the mail body
|
||||||
|
$body = 'The moon request for ' . $request->system . ' - ' . $request->planet . ' - ' . $request->moon . ' has changed status.<br>';
|
||||||
|
$body .= 'The request has been ' . $request->status . '.<br>';
|
||||||
|
$body .= 'Please contact the FC Team should it be necessary to arrange a fleet to cover the structure drop.<br>';
|
||||||
|
$body .= 'Sincerely,<br>';
|
||||||
|
$body .= 'Warped Intentions Leadership<br>';
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//If the status was Denied, then update the request, and mark the moon available again.
|
||||||
|
AllianceMoonRequest::where([
|
||||||
|
'id' => $request->id,
|
||||||
|
])->update([
|
||||||
|
'status' => $request->status,
|
||||||
|
'approver_name' => auth()->user()->getName(),
|
||||||
|
'approver_id' => auth()->user()->getId(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Update the alliance moon in the table to the correct status
|
||||||
|
AllianceMoon::where([
|
||||||
|
'System' => (string)$request->system,
|
||||||
|
'Planet' => (string)$request->planet,
|
||||||
|
'Moon' => (string)$request->moon,
|
||||||
|
])->update([
|
||||||
|
'Availability' => 'Available',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Send an eve mail to the requestor stating they can set a moon up.
|
||||||
|
//Setup the mail body
|
||||||
|
$body = 'The moon request for ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon . ' has changed status.<br>';
|
||||||
|
$body .= 'The request has been ' . $request->status . '.<br>';
|
||||||
|
$body .= 'Should you have questions please contact alliance leadership for further clarification.<br>';
|
||||||
|
$body .= 'Sincerely,<br>';
|
||||||
|
$body .= 'Warped Intentions Leadership<br>';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setup the mail model
|
||||||
|
$mail = new JobSendEveMail;
|
||||||
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = 'Warped Intentions Moon Request';
|
||||||
|
$mail->body = $body;
|
||||||
|
$mail->recipient = (int)$moon->requestor_id;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail');
|
||||||
|
|
||||||
|
return redirect('/moons/admin/display/request')->with('success', 'Moon has been processed, and mail has been sent out.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display the moons to admins
|
||||||
|
*/
|
||||||
|
public function displayRentalMoonsAdmin() {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
$lookupHelper = new LookupHelper;
|
||||||
|
$contact = '';
|
||||||
|
$paid = '';
|
||||||
|
$rentalEnd = '';
|
||||||
|
$renter = '';
|
||||||
|
$ticker = '';
|
||||||
|
|
||||||
|
//Setup calls to the MoonCalc class
|
||||||
|
$moonCalc = new MoonCalc();
|
||||||
|
//Get all of the moons from the database
|
||||||
|
$moons = RentalMoon::orderBy('System', 'asc')->get();
|
||||||
|
//Declare the html variable and set it to null
|
||||||
|
$table = array();
|
||||||
|
//Set carbon dates as needed
|
||||||
|
$lastMonth = Carbon::now()->subMonth();
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
foreach($moons as $moon) {
|
||||||
|
//Get the rental data for the moon
|
||||||
|
$count = MoonRental::where([
|
||||||
|
'System' => $moon->System,
|
||||||
|
'Planet' => $moon->Planet,
|
||||||
|
'Moon' => $moon->Moon,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
//Check if their is a current rental for a moon going on
|
||||||
|
if($count == 0) {
|
||||||
|
//If we don't find a rental record, mark the moon as not paid
|
||||||
|
$paid = 'No';
|
||||||
|
|
||||||
|
//If we don't find a rental record, set the rental date as last month
|
||||||
|
$rentalTemp = $lastMonth;
|
||||||
|
$rentalEnd = $rentalTemp->format('m-d');
|
||||||
|
|
||||||
|
//If we don't find a rental record, set the paid until date as last month
|
||||||
|
$paidUntilTemp = $lastMonth;
|
||||||
|
$paidUntil = $paidUntilTemp->format('m-d');
|
||||||
|
|
||||||
|
//Set the contact info
|
||||||
|
$contact = 'None';
|
||||||
|
|
||||||
|
//Set the renter info
|
||||||
|
$renter = 'None';
|
||||||
|
|
||||||
|
//Set the ticker info
|
||||||
|
$ticker = 'N/A';
|
||||||
|
|
||||||
|
//Set the type info as it's needed
|
||||||
|
$type = 'N/A';
|
||||||
|
} else {
|
||||||
|
//Get the rental data for the moon
|
||||||
|
$rental = MoonRental::where([
|
||||||
|
'System' => $moon->System,
|
||||||
|
'Planet' => $moon->Planet,
|
||||||
|
'Moon' => $moon->Moon,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
//If we find a rental record, mark the moon as whether it's paid or not
|
||||||
|
$paid = $rental->Paid;
|
||||||
|
$paidUntil = new Carbon($rental->Paid_Until);
|
||||||
|
$paidUntil = $paidUntil->format('m-d');
|
||||||
|
|
||||||
|
//Set the rental date up
|
||||||
|
$rentalTemp = new Carbon($rental->RentalEnd);
|
||||||
|
$rentalEnd = $rentalTemp->format('m-d');
|
||||||
|
|
||||||
|
//Set the contact name
|
||||||
|
$contact = $lookupHelper->CharacterIdToName($rental->Contact);
|
||||||
|
|
||||||
|
//Set up the renter whether it's a corporation in W4RP or another alliance
|
||||||
|
$ticker = $rental->RentalCorp;
|
||||||
|
$type = $rental->Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the color for the table
|
||||||
|
if($rentalTemp->diffInDays($today) < 3 ) {
|
||||||
|
$color = 'table-warning';
|
||||||
|
} else if( $today > $rentalTemp) {
|
||||||
|
$color = 'table-success';
|
||||||
|
} else {
|
||||||
|
$color = 'table-danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calculate hte price of the moon based on what is in the moon
|
||||||
|
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||||
|
|
||||||
|
//Add the data to the html string to be passed to the view
|
||||||
|
array_push($table, [
|
||||||
|
'SPM' => $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon,
|
||||||
|
'StructureName' => $moon->StructureName,
|
||||||
|
'AlliancePrice' => $price['alliance'],
|
||||||
|
'OutOfAlliancePrice' => $price['outofalliance'],
|
||||||
|
'RentalEnd' => $rentalEnd,
|
||||||
|
'RowColor' => $color,
|
||||||
|
'Paid' => $paid,
|
||||||
|
'PaidUntil' => $paidUntil,
|
||||||
|
'Contact' => $contact,
|
||||||
|
'Type' => $type,
|
||||||
|
'Renter' => $ticker,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('moons.admin.adminmoon')->with('table', $table);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to remove a renter from a moon
|
||||||
|
*/
|
||||||
|
public function storeMoonRemoval(Request $request) {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'remove' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$str_array = explode(" - ", $request->remove);
|
||||||
|
|
||||||
|
//Decode the value for the SPM into a system, planet, and moon for the database to update
|
||||||
|
$system = $str_array[0];
|
||||||
|
$planet = $str_array[1];
|
||||||
|
$moon = $str_array[2];
|
||||||
|
|
||||||
|
$found = MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $moon,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
if($found != 0) {
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $moon,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
return redirect('/moons/admin/display/rentals')->with('success', 'Renter removed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Redirect back to the moon page, which should call the page to be displayed correctly
|
||||||
|
return redirect('/moons/admin/display/rentals')->with('error', 'Something went wrong.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function displays the ability for admins to update moons with who is renting, and when it ends.
|
||||||
|
*/
|
||||||
|
public function updateMoon() {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
//Declare some variables
|
||||||
|
$system = null;
|
||||||
|
$planet = null;
|
||||||
|
$moon = null;
|
||||||
|
$name = null;
|
||||||
|
$spmnTemp = array();
|
||||||
|
$spmn = array();
|
||||||
|
|
||||||
|
//Get the moons and put in order by System, Planet, then Moon number
|
||||||
|
$moons = RentalMoon::orderBy('System', 'ASC')
|
||||||
|
->orderBy('Planet', 'ASC')
|
||||||
|
->orderBy('Moon', 'ASC')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
//Push our default value onto the stack
|
||||||
|
array_push($spmn, 'N/A');
|
||||||
|
|
||||||
|
//Form our array of strings for each system, planet, and moon combination.
|
||||||
|
foreach($moons as $m) {
|
||||||
|
$temp = $m->System . " - " . $m->Planet . " - " . $m->Moon . " - " . $m->StructureName;
|
||||||
|
array_push($spmnTemp, $temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//From our temporary array with all the values in a numbered key, create the real array with the value being the key
|
||||||
|
foreach($spmnTemp as $key => $value) {
|
||||||
|
$spmn[$value] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return the view and the form from the blade display
|
||||||
|
//Pass the data to the view as well
|
||||||
|
return view('moons.admin.updatemoon')->with('spmn', $spmn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the updated moon
|
||||||
|
*/
|
||||||
|
public function storeUpdateMoon(Request $request) {
|
||||||
|
$this->middleware('role:Admin');
|
||||||
|
|
||||||
|
//Declare some static variables as needed
|
||||||
|
$moonCalc = new MoonCalc;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$paid = false;
|
||||||
|
$system = null;
|
||||||
|
$planet = null;
|
||||||
|
$mn = null;
|
||||||
|
$name = null;
|
||||||
|
|
||||||
|
//Validate our request from the html form
|
||||||
|
$this->validate($request, [
|
||||||
|
'spmn' => 'required',
|
||||||
|
'contact' => 'required',
|
||||||
|
'paid_until' => 'required',
|
||||||
|
'rental_end' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Decode the System, Planet, Moon, Name combinatio sent from the controller
|
||||||
|
$str_array = explode(" - ", $request->spmn);
|
||||||
|
$system = $str_array[0];
|
||||||
|
$planet = $str_array[1];
|
||||||
|
$mn = $str_array[2];
|
||||||
|
$name = $str_array[3];
|
||||||
|
|
||||||
|
//Take the contact name and create a character_id from it
|
||||||
|
if($request->contact == 'None') {
|
||||||
|
$contact = -1;
|
||||||
|
} else {
|
||||||
|
$contact = $lookup->CharacterNameToId($request->contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
//After we get the contact, from his name to the character Id, let's do some other functions before continuing.
|
||||||
|
//Let's find the corporation and alliance information to ascertain whethery they are in Warped Intentions or another Legacy Alliance
|
||||||
|
$char = $lookup->GetCharacterInfo($contact);
|
||||||
|
//Takes the corp id and looks up the corporation info
|
||||||
|
$corp = $lookup->GetCorporationInfo($char->corporation_id);
|
||||||
|
$alliance = $lookup->GetAllianceInfo($corp->alliance_id);
|
||||||
|
$allianceId = $corp->alliance_id;
|
||||||
|
|
||||||
|
//Update the paid value for database entry
|
||||||
|
if($request->paid == 'Yes') {
|
||||||
|
$paid = 'Yes';
|
||||||
|
} else {
|
||||||
|
$paid = 'No';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the rnetal ticker if the corp is in Warped Intentions, otherwise just display the alliance ticker
|
||||||
|
if($allianceId == 99004116) {
|
||||||
|
$renter = $corp->ticker;
|
||||||
|
} else {
|
||||||
|
$renter = $alliance->ticker;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the paid until date
|
||||||
|
if(isset($request->paid_until)) {
|
||||||
|
$paidUntil = new Carbon($request->paid_until . '00:00:01');
|
||||||
|
} else {
|
||||||
|
$paidUntil = Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the rental end date
|
||||||
|
if(isset($request->rental_end)) {
|
||||||
|
$rentalEnd = new Carbon($request->rental_end . '23:59:59');
|
||||||
|
} else {
|
||||||
|
$rentalEnd = Carbon::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calculate the price of the moon for when it's updated
|
||||||
|
$moon = RentalMoon::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
//Calculate the price of the rental and store it in the database
|
||||||
|
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||||
|
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||||
|
|
||||||
|
//Count how many rentals we find for later database processing
|
||||||
|
$count = MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
'Contact' => $contact,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
//If the database entry isn't found, then insert it into the database,
|
||||||
|
//otherwise, account for it being in the system already.
|
||||||
|
//Also check for the weird condition of more than one moon entry existing
|
||||||
|
if($count > 1) {
|
||||||
|
//If more than one entry is found for a particular system, planet, moon combo, then delete all the entries, and put in
|
||||||
|
// a single new entry
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $moon,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
if($allianceId == 99004116) {
|
||||||
|
$store = new MoonRental;
|
||||||
|
$store->System = $system;
|
||||||
|
$store->Planet = $planet;
|
||||||
|
$store->Moon = $mn;
|
||||||
|
$store->RentalCorp = $renter;
|
||||||
|
$store->RentalEnd = $rentalEnd;
|
||||||
|
$store->Contact = $contact;
|
||||||
|
$store->Price = $price['alliance'];
|
||||||
|
$store->Type = 'alliance';
|
||||||
|
$store->Paid = $paid;
|
||||||
|
$store->Paid_Until = $paidUntil;
|
||||||
|
$store->save();
|
||||||
|
} else {
|
||||||
|
$store = new MoonRental;
|
||||||
|
$store->System = $system;
|
||||||
|
$store->Planet = $planet;
|
||||||
|
$store->Moon = $mn;
|
||||||
|
$store->RentalCorp = $renter;
|
||||||
|
$store->RentalEnd = $rentalEnd;
|
||||||
|
$store->Contact = $contact;
|
||||||
|
$store->Price = $price['outofalliance'];
|
||||||
|
$store->Type = 'outofalliance';
|
||||||
|
$store->Paid = $paid;
|
||||||
|
$store->Paid_Until = $paidUntil;
|
||||||
|
$store->save();
|
||||||
|
}
|
||||||
|
} else if($count == 1) {
|
||||||
|
if($allianceId = 99004116) {
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
'Contact' => $contact,
|
||||||
|
])->update([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
'RentalCorp' => $renter,
|
||||||
|
'RentalEnd' => $rentalEnd,
|
||||||
|
'Contact' => $contact,
|
||||||
|
'Price' => $price['alliance'],
|
||||||
|
'Type' => 'alliance',
|
||||||
|
'Paid' => $paid,
|
||||||
|
'Paid_Until' => $paidUntil,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
'Contact' => $contact,
|
||||||
|
])->update([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $mn,
|
||||||
|
'RentalCorp' => $renter,
|
||||||
|
'RentalEnd' => $rentalEnd,
|
||||||
|
'Contact' => $contact,
|
||||||
|
'Price' => $price['outofalliance'],
|
||||||
|
'Type' => 'outofalliance',
|
||||||
|
'Paid' => $paid,
|
||||||
|
'Paid_Until' => $paidUntil,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//If the entry is not found, then attempt to delete whatever existing data is there, then
|
||||||
|
//insert the new data
|
||||||
|
MoonRental::where([
|
||||||
|
'System' => $system,
|
||||||
|
'Planet' => $planet,
|
||||||
|
'Moon' => $moon,
|
||||||
|
])->delete();
|
||||||
|
|
||||||
|
if($allianceId == 99004116) {
|
||||||
|
$store = new MoonRental;
|
||||||
|
$store->System = $system;
|
||||||
|
$store->Planet = $planet;
|
||||||
|
$store->Moon = $mn;
|
||||||
|
$store->RentalCorp = $renter;
|
||||||
|
$store->RentalEnd = $rentalEnd;
|
||||||
|
$store->Contact = $contact;
|
||||||
|
$store->Price = $price['alliance'];
|
||||||
|
$store->Type = 'alliance';
|
||||||
|
$store->Paid = $paid;
|
||||||
|
$store->Paid_Until = $paidUntil;
|
||||||
|
$store->save();
|
||||||
|
} else {
|
||||||
|
$store = new MoonRental;
|
||||||
|
$store->System = $system;
|
||||||
|
$store->Planet = $planet;
|
||||||
|
$store->Moon = $mn;
|
||||||
|
$store->RentalCorp = $renter;
|
||||||
|
$store->RentalEnd = $rentalEnd;
|
||||||
|
$store->Contact = $contact;
|
||||||
|
$store->Price = $price['outofalliance'];
|
||||||
|
$store->Type = 'outofalliance';
|
||||||
|
$store->Paid = $paid;
|
||||||
|
$store->Paid_Until = $paidUntil;
|
||||||
|
$store->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Redirect to the update moon page
|
||||||
|
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated');
|
||||||
|
}
|
||||||
|
}
|
||||||
544
app/Http/Controllers/Moons/MoonsController.php
Normal file
544
app/Http/Controllers/Moons/MoonsController.php
Normal file
@@ -0,0 +1,544 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Moons;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Auth;
|
||||||
|
use DB;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Moon\Config;
|
||||||
|
use App\Models\Moon\ItemComposition;
|
||||||
|
use App\Models\Moon\RentalMoon;
|
||||||
|
use App\Models\Moon\OrePrice;
|
||||||
|
use App\Models\Moon\Price;
|
||||||
|
use App\Models\MoonRent\MoonRental;
|
||||||
|
use App\Models\Moon\AllianceMoon;
|
||||||
|
use App\Models\Moon\AllianceMoonRequest;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Moons\MoonCalc;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
|
||||||
|
class MoonsController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:Renter');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display all alliance moons and pass data to the blade template
|
||||||
|
*/
|
||||||
|
public function displayMoons() {
|
||||||
|
//Setup variables for moons
|
||||||
|
$moons = array();
|
||||||
|
$systems = array();
|
||||||
|
|
||||||
|
//Get all of the alliance moon systems from the database
|
||||||
|
$systems = AllianceMoon::groupBy('System')->pluck('System');
|
||||||
|
|
||||||
|
//Get all of the alliance moons from the database
|
||||||
|
$moons = AllianceMoon::all();
|
||||||
|
|
||||||
|
$gasGoo = [
|
||||||
|
'Zeolites',
|
||||||
|
'Sylvite',
|
||||||
|
'Bitumens',
|
||||||
|
'Coesite',
|
||||||
|
];
|
||||||
|
|
||||||
|
$r8Goo = [
|
||||||
|
'Cobaltite',
|
||||||
|
'Euxenite',
|
||||||
|
'Titanite',
|
||||||
|
'Scheelite',
|
||||||
|
];
|
||||||
|
|
||||||
|
$r16Goo = [
|
||||||
|
'Otavite',
|
||||||
|
'Sperrylite',
|
||||||
|
'Vanadinite',
|
||||||
|
'Chromite',
|
||||||
|
];
|
||||||
|
|
||||||
|
$r32Goo = [
|
||||||
|
'Carnotite',
|
||||||
|
'Zircon',
|
||||||
|
'Pollucite',
|
||||||
|
'Cinnabar',
|
||||||
|
];
|
||||||
|
|
||||||
|
$r64Goo = [
|
||||||
|
'Xenotime',
|
||||||
|
'Monazite',
|
||||||
|
'Loparite',
|
||||||
|
'Ytterbite',
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('moons.user.allmoons')->with('systems', $systems)
|
||||||
|
->with('moons', $moons)
|
||||||
|
->with('gasGoo', $gasGoo)
|
||||||
|
->with('r8Goo', $r8Goo)
|
||||||
|
->with('r16Goo', $r16Goo)
|
||||||
|
->with('r32Goo', $r32Goo)
|
||||||
|
->with('r64Goo', $r64Goo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display moon request form
|
||||||
|
*/
|
||||||
|
public function displayRequestAllianceMoon() {
|
||||||
|
return view('moons.user.requestmoon');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to store the moon request
|
||||||
|
*/
|
||||||
|
public function storeRequestAllianceMoon(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'system' => 'required',
|
||||||
|
'planet' => 'required',
|
||||||
|
'moon' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare some necessary arrays for figuring out what region a moon resides in
|
||||||
|
$catch = [
|
||||||
|
'6X7-JO',
|
||||||
|
'A803-L',
|
||||||
|
'I8-D0G',
|
||||||
|
'WQH-4K',
|
||||||
|
'GJ0-JO',
|
||||||
|
'Q-S7ZD',
|
||||||
|
'JWZ2-V',
|
||||||
|
'J-ODE7',
|
||||||
|
'OGL8-Q',
|
||||||
|
'R-K4QY',
|
||||||
|
];
|
||||||
|
|
||||||
|
$immensea = [
|
||||||
|
'ZBP-TP',
|
||||||
|
'XVV-21',
|
||||||
|
'B9E-H6',
|
||||||
|
'JDAS-0',
|
||||||
|
'Y19P-1',
|
||||||
|
'LN-56V',
|
||||||
|
'O7-7UX',
|
||||||
|
'Y2-QUV',
|
||||||
|
'SPBS-6',
|
||||||
|
'A4B-V5',
|
||||||
|
'GXK-7F',
|
||||||
|
'78TS-Q',
|
||||||
|
'CJNF-J',
|
||||||
|
'EA-HSA',
|
||||||
|
'FYI-49',
|
||||||
|
'WYF8-8',
|
||||||
|
'NS2L-4',
|
||||||
|
'B-S347',
|
||||||
|
'AF0-V5',
|
||||||
|
'QI-S9W',
|
||||||
|
'B-A587',
|
||||||
|
'PPFB-U',
|
||||||
|
'L-5JCJ',
|
||||||
|
'4-GB14',
|
||||||
|
'REB-KR',
|
||||||
|
'QE-E1D',
|
||||||
|
'LK1K-5',
|
||||||
|
'Z-H2MA',
|
||||||
|
'B-KDOZ',
|
||||||
|
'E8-YS9',
|
||||||
|
];
|
||||||
|
|
||||||
|
//Declare lookup variables
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
//Get all of the information needed to create the database entry
|
||||||
|
$charId = auth()->user()->getId();
|
||||||
|
$charInfo = $lookup->GetCharacterInfo($charId);
|
||||||
|
$charName = $charInfo->name;
|
||||||
|
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||||
|
$corpId = $corpInfo->corporation_id;
|
||||||
|
$corpName = $corpInfo->name;
|
||||||
|
$corpTicker = $corpInfo->ticker;
|
||||||
|
//Declare the region variable as null for the lookup if statement
|
||||||
|
$region = null;
|
||||||
|
|
||||||
|
//Get the region the moon resides in from the system
|
||||||
|
if(in_array($request->system, $catch, true)) {
|
||||||
|
$region = 'Catch';
|
||||||
|
} else if(in_array($request->system, $immensea, true)) {
|
||||||
|
$region = 'Immensea';
|
||||||
|
} else {
|
||||||
|
//False value. Redirect back to page
|
||||||
|
return redirct('/moons/display/request')->with('error', 'Region was not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not working correctly with certain systems
|
||||||
|
//Check to see if the moon is not available
|
||||||
|
$future = AllianceMoon::where([
|
||||||
|
'Region' => (string)$region,
|
||||||
|
'System' => (string)$request->system,
|
||||||
|
'Planet' => (string)$request->planet,
|
||||||
|
'Moon' => (string)$request->moon,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if($future->Availability != 'Available') {
|
||||||
|
return redirect('/moons/display/request')->with('error', 'The moon has already been reserved by another party.');
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Check to see if the moon has been previously inputted for
|
||||||
|
$allMoons = AllianceMoon::all();
|
||||||
|
foreach($allMoons as $moon) {
|
||||||
|
if($moon->Region == $region && $moon->System == $request->system && $moon->Planet == $request->planet && $moon->Moon == $request->moon) {
|
||||||
|
if($moon->Availability != 'Available') {
|
||||||
|
return redirect('moons/display/request')->with('error', 'The moon has already been reserved by another party.');
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the new object to save into the database
|
||||||
|
$moonRequest = new AllianceMoonRequest;
|
||||||
|
$moonRequest->region = $region;
|
||||||
|
$moonRequest->system = $request->system;
|
||||||
|
$moonRequest->planet = $request->planet;
|
||||||
|
$moonRequest->moon = $request->moon;
|
||||||
|
$moonRequest->corporation_id = $corpId;
|
||||||
|
$moonRequest->corporation_name = $corpName;
|
||||||
|
$moonRequest->corporation_ticker = $corpTicker;
|
||||||
|
$moonRequest->requestor_name = $charName;
|
||||||
|
$moonRequest->requestor_id = $charId;
|
||||||
|
$moonRequest->status = 'Pending';
|
||||||
|
$moonRequest->save();
|
||||||
|
|
||||||
|
//Update the current moon's status in the model AllianceMoon
|
||||||
|
AllianceMoon::where([
|
||||||
|
'Region' => $region,
|
||||||
|
'System' => $request->system,
|
||||||
|
'Planet' => $request->planet,
|
||||||
|
'Moon' => $request->moon,
|
||||||
|
])->update([
|
||||||
|
'Availability' => 'Request Pending',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect('/moons/display/request')->with('success', 'Moon request submitted.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to display the moons and pass data to the blade template
|
||||||
|
*/
|
||||||
|
public function displayRentalMoons() {
|
||||||
|
$rentalEnd = '';
|
||||||
|
|
||||||
|
//Get the user type from the user Auth class
|
||||||
|
$type = Auth::user()->getUserType();
|
||||||
|
//Setup calls to the MoonCalc class
|
||||||
|
$moonCalc = new MoonCalc();
|
||||||
|
//get all of the rental moons from the database
|
||||||
|
$moons = DB::table('RentalMoons')->orderBy('System', 'asc')->get();
|
||||||
|
//Set the rental date as last month for moons not rented
|
||||||
|
$lastMonth = Carbon::now()->subMonth();
|
||||||
|
//Set a variable for today's date
|
||||||
|
$today = Carbon::now();
|
||||||
|
|
||||||
|
//declare the html variable and set it to null
|
||||||
|
|
||||||
|
$table = array();
|
||||||
|
$moonprice = null;
|
||||||
|
foreach($moons as $moon) {
|
||||||
|
//get the rental data for the moon
|
||||||
|
$rental = MoonRental::where([
|
||||||
|
'System' => $moon->System,
|
||||||
|
'Planet' => $moon->Planet,
|
||||||
|
'Moon' => $moon->Moon,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if($rental == false) {
|
||||||
|
//If we don't find a rental record, set the rental date as last month
|
||||||
|
$rentalTemp = $lastMonth;
|
||||||
|
$rentalEnd = $rentalTemp->format('m-d');
|
||||||
|
} else {
|
||||||
|
//Set the rental date up
|
||||||
|
$rentalTemp = new Carbon($rental->RentalEnd);
|
||||||
|
$rentalEnd = $rentalTemp->format('m-d');
|
||||||
|
}
|
||||||
|
|
||||||
|
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||||
|
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||||
|
|
||||||
|
$worth = $moonCalc->SpatialMoonsTotalWorth($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||||
|
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||||
|
|
||||||
|
if($type == 'W4RP') {
|
||||||
|
$moonprice = $price['alliance'];
|
||||||
|
} else {
|
||||||
|
$moonprice = $price['outofalliance'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($rentalTemp->diffInDays($today) < 3 ) {
|
||||||
|
$color = 'table-warning';
|
||||||
|
} else if( $today > $rentalTemp) {
|
||||||
|
$color = 'table-primary';
|
||||||
|
} else {
|
||||||
|
$color = 'table-danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add the data to the html string to be passed to the view
|
||||||
|
array_push($table, [
|
||||||
|
'SPM' => $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon,
|
||||||
|
'StructureName' => $moon->StructureName,
|
||||||
|
'FirstOre' => $moon->FirstOre,
|
||||||
|
'FirstQuantity' => $moon->FirstQuantity,
|
||||||
|
'SecondOre' => $moon->SecondOre,
|
||||||
|
'SecondQuantity' => $moon->SecondQuantity,
|
||||||
|
'ThirdOre' => $moon->ThirdOre,
|
||||||
|
'ThirdQuantity' => $moon->ThirdQuantity,
|
||||||
|
'FourthOre' => $moon->FourthOre,
|
||||||
|
'FourthQuantity' => $moon->FourthQuantity,
|
||||||
|
'Price' => $moonprice,
|
||||||
|
'Worth' => number_format($worth, "2", ".", ","),
|
||||||
|
'RentalEnd' => $rentalEnd,
|
||||||
|
'RowColor' => $color,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('moons.user.moon')->with('table', $table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayTotalWorthForm() {
|
||||||
|
return view('moons.user.formTotalWorth');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayTotalWorth(Request $request) {
|
||||||
|
//Setup calls to the MoonCalc class
|
||||||
|
$moonCalc = new MoonCalc();
|
||||||
|
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
|
||||||
|
$composition = [
|
||||||
|
'Tritanium' => 0,
|
||||||
|
'Pyerite' => 0,
|
||||||
|
'Mexallon' => 0,
|
||||||
|
'Isogen' => 0,
|
||||||
|
'Nocxium' => 0,
|
||||||
|
'Zydrine' => 0,
|
||||||
|
'Megacyte' => 0,
|
||||||
|
'Atmospheric_Gases' => 0,
|
||||||
|
'Evaporite_Deposits' => 0,
|
||||||
|
'Hydrocarbons' => 0,
|
||||||
|
'Silicates' => 0,
|
||||||
|
'Cobalt' => 0,
|
||||||
|
'Platinum' => 0,
|
||||||
|
'Vanadium'=> 0,
|
||||||
|
'Chromium' => 0,
|
||||||
|
'Technetium' => 0,
|
||||||
|
'Hafnium' => 0,
|
||||||
|
'Caesium' => 0,
|
||||||
|
'Mercury' => 0,
|
||||||
|
'Dysprosium' => 0,
|
||||||
|
'Neodymium' => 0,
|
||||||
|
'Promethium' => 0,
|
||||||
|
'Thulium' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$firstOre = $request->firstOre;
|
||||||
|
if($request->firstQuantity >= 1.00) {
|
||||||
|
$firstQuantity = $request->firstQuantity / 100.00;
|
||||||
|
} else {
|
||||||
|
$firstQuantity = $request->firstQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$secondOre = $request->secondOre;
|
||||||
|
if($request->secondQuantity >= 1.00) {
|
||||||
|
$secondQuantity = $request->secondQuantity / 100.00;
|
||||||
|
} else {
|
||||||
|
$secondQuantity = $request->secondQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$thirdOre = $request->thirdOre;
|
||||||
|
if($request->thirdQuantity >= 1.00) {
|
||||||
|
$thirdQuantity = $request->thirdQuantity / 100.00;
|
||||||
|
} else {
|
||||||
|
$thirdQuantity = $request->thirdQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fourthOre = $request->fourthOre;
|
||||||
|
if($request->fourthQuantity >= 1.00) {
|
||||||
|
$fourthQuantity = $request->fourthQuantity / 100.00;
|
||||||
|
} else {
|
||||||
|
$fourthQuantity = $request->fourthQuantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->reprocessing >= 1.00) {
|
||||||
|
$reprocessing = $request->reprocessing / 100.00;
|
||||||
|
} else {
|
||||||
|
$reprocessing = $request->reprocessing;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the reprocessing level for 84% if the value is null
|
||||||
|
if($request->reprocessing == null) {
|
||||||
|
$reprocessing = 0.84;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calculate the total moon goo value
|
||||||
|
$totalGoo = $moonCalc->SpatialMoonsOnlyGooTotalWorth($firstOre, $firstQuantity, $secondOre, $secondQuantity,
|
||||||
|
$thirdOre, $thirdQuantity, $fourthOre, $fourthQuantity);
|
||||||
|
//Format the number to send to the blade
|
||||||
|
$totalGoo = number_format($totalGoo, 2, ".", ",");
|
||||||
|
|
||||||
|
//Calculate the total worth of the moon
|
||||||
|
$totalWorth = $moonCalc->SpatialMoonsTotalWorth($firstOre, $firstQuantity, $secondOre, $secondQuantity,
|
||||||
|
$thirdOre, $thirdQuantity, $fourthOre, $fourthQuantity);
|
||||||
|
//Format the number to send to the blade.
|
||||||
|
$totalWorth = number_format($totalWorth, 2, ".", ",");
|
||||||
|
|
||||||
|
//Get the composition for the first ore if it is not None.
|
||||||
|
//Add the first ore composition to the final composition
|
||||||
|
if($firstOre != 'None') {
|
||||||
|
//Get the ore's composition
|
||||||
|
$firstComp = $moonCalc->GetOreComposition($firstOre);
|
||||||
|
//Get the amount of units mine-able from the moon
|
||||||
|
$mUnits = $moonCalc->CalcOreUnits($firstOre, $firstQuantity);
|
||||||
|
//Calculate the number of reprocessing units to happen from moon units
|
||||||
|
$rUnits = floor($mUnits / 100.0);
|
||||||
|
|
||||||
|
//Compile the composition of the ore
|
||||||
|
$composition['Tritanium'] += floor(($firstComp->Tritanium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Pyerite'] += floor(($firstComp->Pyerite * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mexallon'] += floor(($firstComp->Mexallon * $rUnits) * $reprocessing);
|
||||||
|
$composition['Isogen'] += floor(($firstComp->Isogen * $rUnits) * $reprocessing);
|
||||||
|
$composition['Nocxium'] += floor(($firstComp->Nocxium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Zydrine'] += floor(($firstComp->Zydrine * $rUnits) * $reprocessing);
|
||||||
|
$composition['Megacyte'] += floor(($firstComp->Megacyte * $rUnits) * $reprocessing);
|
||||||
|
$composition['Atmospheric_Gases'] += floor(($firstComp->AtmosphericGases * $rUnits) * $reprocessing);
|
||||||
|
$composition['Evaporite_Deposits'] += floor(($firstComp->EvaporiteDeposits * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hydrocarbons'] += floor(($firstComp->Hydrocarbons * $rUnits) * $reprocessing);
|
||||||
|
$composition['Silicates'] += floor(($firstComp->Silicates * $rUnits) * $reprocessing);
|
||||||
|
$composition['Cobalt'] += floor(($firstComp->Cobalt * $rUnits) * $reprocessing);
|
||||||
|
$composition['Platinum'] += floor(($firstComp->Platinium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Vanadium'] += floor(($firstComp->Vanadium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Chromium'] += floor(($firstComp->Chromium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Technetium'] += floor(($firstComp->Technetium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hafnium'] += floor(($firstComp->Hafnium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Caesium'] += floor(($firstComp->Caesium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mercury'] += floor(($firstComp->Mercury * $rUnits) * $reprocessing);
|
||||||
|
$composition['Dysprosium'] += floor(($firstComp->Dysprosium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Neodymium'] += floor(($firstComp->Neodymium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Promethium'] += floor(($firstComp->Promethium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Thulium'] += floor(($firstComp->Thulium * $rUnits) * $reprocessing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the composition for the second ore if it is not None.
|
||||||
|
//Add the second ore composition to the final composition
|
||||||
|
if($secondOre != 'None') {
|
||||||
|
//Get the ore's composition
|
||||||
|
$secondComp = $moonCalc->GetOreComposition($secondOre);
|
||||||
|
//Get the amount of units mine-able from the moon
|
||||||
|
$mUnits = $moonCalc->CalcOreUnits($secondOre, $secondQuantity);
|
||||||
|
//Calculate the number of reprocessing units to happen from moon units
|
||||||
|
$rUnits = floor($mUnits / 100.0);
|
||||||
|
|
||||||
|
$composition['Tritanium'] += floor(($secondComp->Tritanium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Pyerite'] += floor(($secondComp->Pyerite * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mexallon'] += floor(($secondComp->Mexallon * $rUnits) * $reprocessing);
|
||||||
|
$composition['Isogen'] += floor(($secondComp->Isogen * $rUnits) * $reprocessing);
|
||||||
|
$composition['Nocxium'] += floor(($secondComp->Nocxium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Zydrine'] += floor(($secondComp->Zydrine * $rUnits) * $reprocessing);
|
||||||
|
$composition['Megacyte'] += floor(($secondComp->Megacyte * $rUnits) * $reprocessing);
|
||||||
|
$composition['Atmospheric_Gases'] += floor(($secondComp->AtmosphericGases * $rUnits) * $reprocessing);
|
||||||
|
$composition['Evaporite_Deposits'] += floor(($secondComp->EvaporiteDeposits * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hydrocarbons'] += floor(($secondComp->Hydrocarbons * $rUnits) * $reprocessing);
|
||||||
|
$composition['Silicates'] += floor(($secondComp->Silicates * $rUnits) * $reprocessing);
|
||||||
|
$composition['Cobalt'] += floor(($secondComp->Cobalt * $rUnits) * $reprocessing);
|
||||||
|
$composition['Platinum'] += floor(($secondComp->Platinium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Vanadium'] += floor(($secondComp->Vanadium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Chromium'] += floor(($secondComp->Chromium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Technetium'] += floor(($secondComp->Technetium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hafnium'] += floor(($secondComp->Hafnium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Caesium'] += floor(($secondComp->Caesium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mercury'] += floor(($secondComp->Mercury * $rUnits) * $reprocessing);
|
||||||
|
$composition['Dysprosium'] += floor(($secondComp->Dysprosium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Neodymium'] += floor(($secondComp->Neodymium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Promethium'] += floor(($secondComp->Promethium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Thulium'] += floor(($secondComp->Thulium * $rUnits) * $reprocessing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the composition for the third ore if it is not None.
|
||||||
|
//Add the third ore composition to the final composition
|
||||||
|
if($thirdOre != 'None') {
|
||||||
|
//Get the ore's composition
|
||||||
|
$thirdComp = $moonCalc->GetOreComposition($thirdOre);
|
||||||
|
//Get the amount of units mine-able from the moon
|
||||||
|
$mUnits = $moonCalc->CalcOreUnits($thirdOre, $thirdQuantity);
|
||||||
|
//Calculate the number of reprocessing units to happen from moon units
|
||||||
|
$rUnits = floor($mUnits / 100.0);
|
||||||
|
|
||||||
|
$composition['Tritanium'] += floor(($thirdComp->Tritanium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Pyerite'] += floor(($thirdComp->Pyerite * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mexallon'] += floor(($thirdComp->Mexallon * $rUnits) * $reprocessing);
|
||||||
|
$composition['Isogen'] += floor(($thirdComp->Isogen * $rUnits) * $reprocessing);
|
||||||
|
$composition['Nocxium'] += floor(($thirdComp->Nocxium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Zydrine'] += floor(($thirdComp->Zydrine * $rUnits) * $reprocessing);
|
||||||
|
$composition['Megacyte'] += floor(($thirdComp->Megacyte * $rUnits) * $reprocessing);
|
||||||
|
$composition['Atmospheric_Gases'] += floor(($thirdComp->AtmosphericGases * $rUnits) * $reprocessing);
|
||||||
|
$composition['Evaporite_Deposits'] += floor(($thirdComp->EvaporiteDeposits * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hydrocarbons'] += floor(($thirdComp->Hydrocarbons * $rUnits) * $reprocessing);
|
||||||
|
$composition['Silicates'] += floor(($thirdComp->Silicates * $rUnits) * $reprocessing);
|
||||||
|
$composition['Cobalt'] += floor(($thirdComp->Cobalt * $rUnits) * $reprocessing);
|
||||||
|
$composition['Platinum'] += floor(($thirdComp->Platinium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Vanadium'] += floor(($thirdComp->Vanadium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Chromium'] += floor(($thirdComp->Chromium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Technetium'] += floor(($thirdComp->Technetium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hafnium'] += floor(($thirdComp->Hafnium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Caesium'] += floor(($thirdComp->Caesium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mercury'] += floor(($thirdComp->Mercury * $rUnits) * $reprocessing);
|
||||||
|
$composition['Dysprosium'] += floor(($thirdComp->Dysprosium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Neodymium'] += floor(($thirdComp->Neodymium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Promethium'] += floor(($thirdComp->Promethium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Thulium'] += floor(($thirdComp->Thulium * $rUnits) * $reprocessing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the composition for the fourth ore if it is not None.
|
||||||
|
//Add the fourth ore composition to the final composition
|
||||||
|
if($fourthOre != 'None') {
|
||||||
|
//Get the ore's composition
|
||||||
|
$fourthComp = $moonCalc->GetOreComposition($fourthOre);
|
||||||
|
//Get the amount of units mine-able from the moon
|
||||||
|
$mUnits = $moonCalc->CalcOreUnits($fourthOre, $fourthQuantity);
|
||||||
|
//Calculate the number of reprocessing units to happen from moon units
|
||||||
|
$rUnits = floor($mUnits / 100.0);
|
||||||
|
|
||||||
|
$composition['Tritanium'] += floor(($fourthComp->Tritanium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Pyerite'] += floor(($fourthComp->Pyerite * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mexallon'] += floor(($fourthComp->Mexallon * $rUnits) * $reprocessing);
|
||||||
|
$composition['Isogen'] += floor(($fourthComp->Isogen * $rUnits) * $reprocessing);
|
||||||
|
$composition['Nocxium'] += floor(($fourthComp->Nocxium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Zydrine'] += floor(($fourthComp->Zydrine * $rUnits) * $reprocessing);
|
||||||
|
$composition['Megacyte'] += floor(($fourthComp->Megacyte * $rUnits) * $reprocessing);
|
||||||
|
$composition['Atmospheric_Gases'] += floor(($fourthComp->AtmosphericGases * $rUnits) * $reprocessing);
|
||||||
|
$composition['Evaporite_Deposits'] += floor(($fourthComp->EvaporiteDeposits * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hydrocarbons'] += floor(($fourthComp->Hydrocarbons * $rUnits) * $reprocessing);
|
||||||
|
$composition['Silicates'] += floor(($fourthComp->Silicates * $rUnits) * $reprocessing);
|
||||||
|
$composition['Cobalt'] += floor(($fourthComp->Cobalt * $rUnits) * $reprocessing);
|
||||||
|
$composition['Platinum'] += floor(($fourthComp->Platinium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Vanadium'] += floor(($fourthComp->Vanadium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Chromium'] += floor(($fourthComp->Chromium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Technetium'] += floor(($fourthComp->Technetium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Hafnium'] += floor(($fourthComp->Hafnium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Caesium'] += floor(($fourthComp->Caesium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Mercury'] += floor(($fourthComp->Mercury * $rUnits) * $reprocessing);
|
||||||
|
$composition['Dysprosium'] += floor(($fourthComp->Dysprosium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Neodymium'] += floor(($fourthComp->Neodymium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Promethium'] += floor(($fourthComp->Promethium * $rUnits) * $reprocessing);
|
||||||
|
$composition['Thulium'] += floor(($fourthComp->Thulium * $rUnits) * $reprocessing);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('moons.user.displayTotalWorth')->with('totalWorth', $totalWorth)
|
||||||
|
->with('totalGoo', $totalGoo)
|
||||||
|
->with('composition', $composition)
|
||||||
|
->with('reprocessing', $reprocessing);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ use Khill\Lavacharts\Lavacharts;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
//User Libraries
|
//User Libraries
|
||||||
use App\Library\Helpers\SRPHelper;
|
use App\Library\SRP\SRPHelper;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\SRP\SRPShip;
|
use App\Models\SRP\SRPShip;
|
||||||
@@ -85,13 +85,8 @@ class SRPAdminController extends Controller
|
|||||||
//Calculate the recommended srp amount
|
//Calculate the recommended srp amount
|
||||||
foreach($payouts as $p) {
|
foreach($payouts as $p) {
|
||||||
if($r['ship_type'] == $p->code) {
|
if($r['ship_type'] == $p->code) {
|
||||||
$payout = $p->payout;
|
$temp['actual_srp'] = $r['loss_value'] * ($p->payout / 100.00 );
|
||||||
if($temp['character_name'] == $temp['fleet_commander_name']) {
|
$temp['payout_percentage'] = $p->payout;
|
||||||
$payout = 100.00;
|
|
||||||
}
|
|
||||||
|
|
||||||
$temp['actual_srp'] = $r['loss_value'] * ($payout / 100.00 );
|
|
||||||
$temp['payout_percentage'] = $payout;
|
|
||||||
$sum_actual += $temp['actual_srp'];
|
$sum_actual += $temp['actual_srp'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ use Illuminate\Http\Request;
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Auth;
|
use Auth;
|
||||||
|
|
||||||
//Application Libraries
|
//User Libraries
|
||||||
use App\Library\Helpers\SRPHelper;
|
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\SRP\SRPShip;
|
use App\Models\SRP\SRPShip;
|
||||||
|
|||||||
@@ -2,24 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Test;
|
namespace App\Http\Controllers\Test;
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
//Application Library
|
use App\Library\Lookups\LookupHelper;
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
use App\Models\User\User;
|
|
||||||
|
|
||||||
class TestController extends Controller
|
class TestController extends Controller
|
||||||
{
|
{
|
||||||
@@ -33,149 +19,7 @@ class TestController extends Controller
|
|||||||
return view('test.char.display')->with('char', $char);
|
return view('test.char.display')->with('char', $char);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DebugMiningTaxesInvoices() {
|
public function CharacterLookupTest(Request $request) {
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$ledgers = new Collection;
|
|
||||||
$perms = new Collection;
|
|
||||||
|
|
||||||
|
|
||||||
var_dump(auth()->user()->getAlts());
|
|
||||||
dd(auth()->user()->altCount());
|
|
||||||
|
|
||||||
//Get all of the users in the database
|
|
||||||
$users = User::all();
|
|
||||||
|
|
||||||
//Get a list of the alts for each character, then process the ledgers and combine them to send one mail out
|
|
||||||
//in this first part
|
|
||||||
foreach($users as $char) {
|
|
||||||
$altCount = $char->altCount();
|
|
||||||
|
|
||||||
if($altCount > 0) {
|
|
||||||
$alts = $char->getAlts();
|
|
||||||
|
|
||||||
foreach($alts as $alt) {
|
|
||||||
$perms->push([
|
|
||||||
'main_id' => $char->character_id,
|
|
||||||
'alt_id' => $alt->character_id,
|
|
||||||
'count' => $altCount,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$perms->push([
|
|
||||||
'main_id' => $char->character_id,
|
|
||||||
'alt_id' => null,
|
|
||||||
'count' => 0,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('test.miningtax.invoice')->with('perms', $perms);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function DebugMiningObservers() {
|
|
||||||
//Declare variables
|
|
||||||
$mailDelay = 15;
|
|
||||||
$config = config('esi');
|
|
||||||
$mains = new Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This section will determine if users are mains or alts of a main.
|
|
||||||
* If they are mains, we keep the key. If they are alts of a main, then we delete
|
|
||||||
* the key from the collection.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Pluck all the users from the database of ledgers to determine if they are mains or alts.
|
|
||||||
$tempMains = Ledger::where([
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subMonths(3))->pluck('character_id');
|
|
||||||
|
|
||||||
//Get the unique character ids from the ledgers in the previous statement
|
|
||||||
$tempMains = $tempMains->unique()->values()->all();
|
|
||||||
|
|
||||||
for($i = 0; $i < sizeof($tempMains); $i++) {
|
|
||||||
if(UserAlt::where(['character_id' => $tempMains[$i]])->count() == 0) {
|
|
||||||
$mains->push($tempMains[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For each of the users, let's determine if there are any ledgers,
|
|
||||||
* then determine if there are any alts and ledgers associated with the alts.
|
|
||||||
*/
|
|
||||||
foreach($mains as $main) {
|
|
||||||
//Declare some variables for each run through the for loop
|
|
||||||
$mainLedgerCount = 0;
|
|
||||||
$ledgers = new Collection;
|
|
||||||
|
|
||||||
//Count the ledgers for the main
|
|
||||||
$mainLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subMonths(3))->count();
|
|
||||||
|
|
||||||
//If there are ledgers for the main, then let's grab them
|
|
||||||
if($mainLedgerCount > 0) {
|
|
||||||
$mainLedgers = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subMonths(3))->get();
|
|
||||||
|
|
||||||
//Cycle through the entries, and add them to the ledger to send with the invoice
|
|
||||||
foreach($mainLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => $row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the alt count for the main character
|
|
||||||
$altCount = UserAlt::where(['main_id' => $main])->count();
|
|
||||||
//If more than 0 alts, grab all the alts.
|
|
||||||
if($altCount > 0) {
|
|
||||||
$alts = UserAlt::where([
|
|
||||||
'main_id' => $main,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Cycle through the alts, and get the ledgers, and push onto the stack
|
|
||||||
foreach($alts as $alt) {
|
|
||||||
$altLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subMonths(3))->count();
|
|
||||||
|
|
||||||
if($altLedgerCount > 0) {
|
|
||||||
$altLedgers = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subMonths(3))->get();
|
|
||||||
|
|
||||||
foreach($altLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => $row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($ledgers->count() > 0) {
|
|
||||||
var_dump($ledgers);
|
|
||||||
var_dump(round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
152
app/Http/Controllers/Wiki/WikiController.php
Normal file
152
app/Http/Controllers/Wiki/WikiController.php
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Wiki;
|
||||||
|
|
||||||
|
//Laravel libraries
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Auth;
|
||||||
|
|
||||||
|
//User Libraries
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\Wiki\WikiHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Doku\DokuGroupNames;
|
||||||
|
use App\Models\Doku\DokuMember;
|
||||||
|
use App\Models\Doku\DokuUser;
|
||||||
|
use App\Models\Admin\AllowedLogin;
|
||||||
|
use App\Models\User\User;
|
||||||
|
|
||||||
|
class WikiController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:Renter');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayRegister() {
|
||||||
|
//make user name syntax like we want it.
|
||||||
|
$name = Auth::user()->name;
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = str_replace(' ', '_', $name);
|
||||||
|
|
||||||
|
//Check to see if the user is already registered in the database
|
||||||
|
$count = DokuUser::where([
|
||||||
|
'login' => $name,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
//If the count is greater than zero, also check the login name as a reference
|
||||||
|
if($count > 0) {
|
||||||
|
$check = DokuUser::where([
|
||||||
|
'login' => $name,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if($check->login === $name) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Already registered for the wiki!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('wiki.user.register')->with('name', $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeRegister(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'password' => 'required',
|
||||||
|
'password2' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$password = '';
|
||||||
|
|
||||||
|
//Check to make sure the password matches
|
||||||
|
if($request->password !== $request->password2) {
|
||||||
|
return view('/dashboard')->with('error');
|
||||||
|
} else {
|
||||||
|
$password = md5($request->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Auth::user()->hasRole('User')) {
|
||||||
|
$role = 1; //User role id from wiki_groupname table
|
||||||
|
$roleDescription = 'user';
|
||||||
|
} else if(Auth::user()->hasRole('Renter')) {
|
||||||
|
$role = 8; //Renter role id from wiki_groupname table
|
||||||
|
$roleDescription = 'renter';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Load the model
|
||||||
|
$user = new DokuUser;
|
||||||
|
$member = new DokuMember;
|
||||||
|
|
||||||
|
//make user name syntax like we want it.
|
||||||
|
$name = Auth::user()->name;
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = str_replace(' ', '_', $name);
|
||||||
|
|
||||||
|
//Add the new user to the wiki
|
||||||
|
$user->login = $name;
|
||||||
|
$user->pass = $password;
|
||||||
|
$user->name = Auth::user()->name;
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
//Get the user from the table to get the uid
|
||||||
|
$uid = DokuUser::where([
|
||||||
|
'login' => $name,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
//Save information in the model
|
||||||
|
$member->uid = $uid->id;
|
||||||
|
$member->gid = $role;
|
||||||
|
$member->groupname = $roleDescription;
|
||||||
|
$member->save();
|
||||||
|
|
||||||
|
//Return to the dashboard view
|
||||||
|
return redirect('/dashboard')->with('success', 'Registration successful. Your username is: ' . $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayChangePassword() {
|
||||||
|
$name = Auth::user()->name;
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = str_replace(' ', '_', $name);
|
||||||
|
|
||||||
|
//Get the password
|
||||||
|
$check = DokuUser::where([
|
||||||
|
'login' => $name
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
if($check == 0) {
|
||||||
|
return redirect('/dashboard')->with('error', 'Login Not Found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('wiki.user.changepassword')->with('name', $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function changePassword(Request $request) {
|
||||||
|
$this->validate($request, [
|
||||||
|
'password' => 'required',
|
||||||
|
'password2' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Check for a valid password
|
||||||
|
$password = '';
|
||||||
|
if($request->password !== $request->password2) {
|
||||||
|
return redirect('/wiki/changepassword')->with('error', 'Passwords did not match');
|
||||||
|
} else {
|
||||||
|
$password = md5($request->password);
|
||||||
|
}
|
||||||
|
//Get a model ready for the database
|
||||||
|
$user = new DokuUser;
|
||||||
|
//Find the username for the database through the character name in auth
|
||||||
|
$name = Auth::user()->name;
|
||||||
|
$name = strtolower($name);
|
||||||
|
$name = str_replace(' ', '_', $name);
|
||||||
|
|
||||||
|
//Update the password for the login name
|
||||||
|
DokuUser::where([
|
||||||
|
'login' => $name,
|
||||||
|
])->update([
|
||||||
|
'pass' => $password,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect('/dashboard')->with('success', 'Password changed successfully. Your username is: ' . $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
148
app/Http/Controllers/Wormholes/WormholeController.php
Normal file
148
app/Http/Controllers/Wormholes/WormholeController.php
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Wormholes;
|
||||||
|
|
||||||
|
//Laravel Libraries
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//User Libraries
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Wormholes\AllianceWormhole;
|
||||||
|
use App\Models\Wormholes\WormholeType;
|
||||||
|
|
||||||
|
class WormholeController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct() {
|
||||||
|
$this->middleware('auth');
|
||||||
|
$this->middleware('role:User');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayWormholeForm() {
|
||||||
|
//Declare a few array variables
|
||||||
|
$duration = array();
|
||||||
|
$class = array();
|
||||||
|
$stability = array();
|
||||||
|
$size = array();
|
||||||
|
|
||||||
|
//Get the duration from the table
|
||||||
|
$duration = [
|
||||||
|
'This wormhole has not yet begun its natural cycle of decay and should last at least another day.',
|
||||||
|
'This wormhole is beginning to decay, but will not last another day.',
|
||||||
|
'This wormhole is reaching the end of its natural lifetime',
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the wh classes from the table
|
||||||
|
$class = [
|
||||||
|
'C1',
|
||||||
|
'C2',
|
||||||
|
'C3',
|
||||||
|
'C4',
|
||||||
|
'C5',
|
||||||
|
'C6',
|
||||||
|
'C7',
|
||||||
|
'C8',
|
||||||
|
'C9',
|
||||||
|
'C13',
|
||||||
|
'Drifter',
|
||||||
|
'Thera',
|
||||||
|
'Exit WH',
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the wh types from the table
|
||||||
|
$type = WormholeType::groupBy('type')->pluck('type');
|
||||||
|
|
||||||
|
//Get the wh sizes from the table
|
||||||
|
$size = [
|
||||||
|
'XS',
|
||||||
|
'S',
|
||||||
|
'M',
|
||||||
|
'L',
|
||||||
|
'XL',
|
||||||
|
];
|
||||||
|
|
||||||
|
//Get the wh stabilities from the table
|
||||||
|
$stability = [
|
||||||
|
'Stable',
|
||||||
|
'Non-Critical',
|
||||||
|
'Critical',
|
||||||
|
];
|
||||||
|
|
||||||
|
//Return all the variables to the view
|
||||||
|
return view('wormholes.form')->with('class', $class)
|
||||||
|
->with('type', $type)
|
||||||
|
->with('size', $size)
|
||||||
|
->with('stability', $stability)
|
||||||
|
->with('duration', $duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeWormhole() {
|
||||||
|
$this->validate($request, [
|
||||||
|
'sig' => 'required',
|
||||||
|
'duration' => 'required',
|
||||||
|
'dateTiume' => 'required',
|
||||||
|
'class' => 'required',
|
||||||
|
'size' => 'required',
|
||||||
|
'stability' => 'required',
|
||||||
|
'system' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
//Declare some variables
|
||||||
|
$duration = null;
|
||||||
|
|
||||||
|
//Create the stable time for the database
|
||||||
|
if($request->duration == 'This wormhole has not yet begun its natural cycle of decay and should last at least another day.') {
|
||||||
|
$duration = '>24 hours';
|
||||||
|
} else if ($request->duration == 'This wormhole is beginning to decay, but will not last another day.') {
|
||||||
|
$duration = '>4 hours <24 hours';
|
||||||
|
} else if($request->duration == 'This wormhole is reaching the end of its natural lifetime') {
|
||||||
|
'<4 hours';
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the wormhole type from the database so we can enter other details
|
||||||
|
$wormholeType = WormholeType::where([
|
||||||
|
'type' => $request->type,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
$found = AllianceWormhole::where([
|
||||||
|
'system' => $request->system,
|
||||||
|
'sig_ig' => $request->sig,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
if($found == 0) {
|
||||||
|
AllianceWormhole::insert([
|
||||||
|
'system' => $request->system,
|
||||||
|
'sig_id' => $request->sig_id,
|
||||||
|
'duration_left' => $duration,
|
||||||
|
'dateTime' => $request->dateTime,
|
||||||
|
'class' => $request->class,
|
||||||
|
'type' => $request->class,
|
||||||
|
'hole_size' => $request->size,
|
||||||
|
'stability' => $request->stability,
|
||||||
|
'details' => $request->details,
|
||||||
|
'link' => $request->link,
|
||||||
|
'mass_allowed' => $wormholeType->mass_allowed,
|
||||||
|
'individual_mass' => $wormholeType->individual_mass,
|
||||||
|
'regeneration' => $wormholeType->regeneration,
|
||||||
|
'max_stable_time' => $wormholeType->max_stable_time,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect('/wormholes/display')->with('success', 'Wormhole Info Added.');
|
||||||
|
} else {
|
||||||
|
return redirect('/wormholes/display')->with('error', 'Wormhole already in database.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function displayWormholes() {
|
||||||
|
//Create the date and time
|
||||||
|
$dateTime = Carbon::now()->subDays(2);
|
||||||
|
|
||||||
|
//Get all of the wormholes from the last 48 hours from the database to display
|
||||||
|
$wormholes = AllianceWormhole::where('created_at', '>=', $dateTime)->get();
|
||||||
|
|
||||||
|
return view('wormholes.display')->with('wormholes', $wormholes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ class Kernel extends HttpKernel
|
|||||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
'callback' => \App\Http\Middleware\Callback::class,
|
||||||
'role' => \App\Http\Middleware\RequireRole::class,
|
'role' => \App\Http\Middleware\RequireRole::class,
|
||||||
'permission' => \App\Http\Middleware\RequirePermission::class,
|
'permission' => \App\Http\Middleware\RequirePermission::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Authenticate extends Middleware
|
|||||||
protected function redirectTo($request)
|
protected function redirectTo($request)
|
||||||
{
|
{
|
||||||
if(!$this->auth->check()){
|
if(!$this->auth->check()){
|
||||||
return '/';
|
return route('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
app/Http/Middleware/Callback.php
Normal file
30
app/Http/Middleware/Callback.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
use Socialite;
|
||||||
|
use DB;
|
||||||
|
use App\Models\User\User;
|
||||||
|
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
use Seat\Eseye\Containers\EsiAuthentication;
|
||||||
|
use Seat\Eseye\Eseye;
|
||||||
|
|
||||||
|
class Callback
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next, $guard = null)
|
||||||
|
{
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ class TrimStrings extends Middleware
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $except = [
|
protected $except = [
|
||||||
//
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
|
|
||||||
abstract class Request extends FormRequest
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Assets;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Asset;
|
|
||||||
|
|
||||||
class FetchAllianceAssets implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('assets');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$config = config('esi');
|
|
||||||
$corpId = 98287666;
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Get the refresh token from the database
|
|
||||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
//Create the esi authentication container
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
|
||||||
|
|
||||||
//Check the esi scope
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-assets.read_corporation_assets.v1')) {
|
|
||||||
Log::critical("Scope check failed in FetchAllianceAssets for esi-assets.read_corporation_assets.v1");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set the current page
|
|
||||||
$currentPage = 1;
|
|
||||||
//Set our default pages
|
|
||||||
$totalPages = 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
//Attempt to get the assets
|
|
||||||
$assets = $esi->page($currentPage)
|
|
||||||
->invoke('get', '/corporations/{corporation_id}/assets/', [
|
|
||||||
'corporation_id' => $corpId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
//If on the first page, then update the total number of pages
|
|
||||||
if($currentPage == 1) {
|
|
||||||
$totalPages = $assets->pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
//For each asset retrieved, let's process it.
|
|
||||||
foreach($assets as $a) {
|
|
||||||
ProcessAllianceAssets::dispatch($a);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Increment the current page
|
|
||||||
$currentPage++;
|
|
||||||
} while($currentPage <= $totalPages);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The job failed to process
|
|
||||||
* @param Exception $exception
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function failed($exception) {
|
|
||||||
if(!exception instanceof RequestFailedException) {
|
|
||||||
//If not a failure due to ESI, then log it. Otherwise,
|
|
||||||
//deduce why the exception occurred.
|
|
||||||
Log::critical($exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((is_object($exception->getEsiResponse()) && (stristr($exception->getEsiResponse()->error, 'Too many errors') || stristr($exception->getEsiResponse()->error, 'This software has exceeded the error limit for ESI'))) ||
|
|
||||||
(is_string($exception->getEsiResponse()) && (stristr($exception->getEsiResponse(), 'Too many errors') || stristr($exception->getEsiResponse(), 'This software has exceeded the error limit for ESI')))) {
|
|
||||||
|
|
||||||
//We have hit the error rate limiter, wait 120 seconds before releasing the job back into the queue.
|
|
||||||
Log::info('FetchMiningTaxesObservers has hit the error rate limiter. Releasing the job back into the wild in 2 minutes.');
|
|
||||||
$this->release(120);
|
|
||||||
} else {
|
|
||||||
$errorCode = $exception->getEsiResponse()->getErrorCode();
|
|
||||||
|
|
||||||
switch($errorCode) {
|
|
||||||
case 400: //Bad Request
|
|
||||||
Log::critical("Bad request has occurred in FetchMiningTaxesObservers. Job has been discarded");
|
|
||||||
break;
|
|
||||||
case 401: //Unauthorized Request
|
|
||||||
Log::critical("Unauthorized request has occurred in FetchMiningTaxesObservers at " . Carbon::now()->toDateTimeString() . ".\r\nCancelling the job.");
|
|
||||||
break;
|
|
||||||
case 403: //Forbidden
|
|
||||||
Log::critical("FetchMiningTaxesObservers has incurred a forbidden error. Cancelling the job.");
|
|
||||||
break;
|
|
||||||
case 420: //Error Limited
|
|
||||||
Log::warning("Error rate limit occurred in FetchMiningTaxesObservers. Restarting job in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 500: //Internal Server Error
|
|
||||||
Log::critical("Internal Server Error for ESI in FetchMiningTaxesObservers. Attempting a restart in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 503: //Service Unavailable
|
|
||||||
Log::critical("Service Unavailabe for ESI in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 504: //Gateway Timeout
|
|
||||||
Log::critical("Gateway timeout in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 201: //Good response code
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
//If no code is given, then log and break out of switch.
|
|
||||||
default:
|
|
||||||
Log::warning("No response code received from esi call in FetchMiningTaxesObservers.\r\n");
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags for jobs
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['FetchAllianceAssets', 'AllianceStructures', 'Assets'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Assets;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Asset;
|
|
||||||
|
|
||||||
class ProcessAllianceAssets implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
//Private variable
|
|
||||||
private $asset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($a)
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('assets');
|
|
||||||
|
|
||||||
$this->asset = $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* If the asset is not in the database, then let's save it to the database,
|
|
||||||
* otherwise, we just update the old asset
|
|
||||||
*/
|
|
||||||
$count = Asset::where([
|
|
||||||
'item_id' => $this->asset->item_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($count == 0) {
|
|
||||||
$as = new Asset;
|
|
||||||
if(isset($this->asset->is_blueprint_copy)) {
|
|
||||||
$as->is_blueprint_copy = $this->asset->is_blueprint_copy;
|
|
||||||
}
|
|
||||||
$as->is_singleton = $this->asset->is_singleton;
|
|
||||||
$as->item_id = $this->asset->item_id;
|
|
||||||
$as->location_flag = $this->asset->location_flag;
|
|
||||||
$as->location_id = $this->asset->location_id;
|
|
||||||
$as->location_type = $this->asset->location_type;
|
|
||||||
$as->quantity = $this->asset->quantity;
|
|
||||||
$as->type_id = $this->asset->type_id;
|
|
||||||
$as->save();
|
|
||||||
} else {
|
|
||||||
//Update the previously found asset
|
|
||||||
Asset::where([
|
|
||||||
'item_id' => $this->asset->item_id,
|
|
||||||
])->update([
|
|
||||||
'is_singleton' => $this->asset->is_singleton,
|
|
||||||
'location_flag' => $this->asset->location_flag,
|
|
||||||
'location_id' => $this->asset->location_id,
|
|
||||||
'location_type' => $this->asset->location_type,
|
|
||||||
'quantity' => $this->asset->quantity,
|
|
||||||
'type_id' => $this->asset->type_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if(isset($this->asset->is_blueprint_copy)) {
|
|
||||||
Asset::where([
|
|
||||||
'item_id' => $this->asset->item_id,
|
|
||||||
])->update([
|
|
||||||
'is_blueprint_copy' => $this->asset->is_blueprint_copy,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags for jobs
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['FetchAllianceAssets', 'AllianceStructures', 'Assets'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Assets;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Assets\FetchAllianceAssets;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Asset;
|
|
||||||
|
|
||||||
class PurgeAllianceAssets implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('assets');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
Asset::truncate();
|
|
||||||
|
|
||||||
FetchAllianceAssets::dispatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Data;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Libraries
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\User\UserPermission;
|
|
||||||
use App\Models\User\UserRole;
|
|
||||||
use App\Models\Admin\AllowedLogin;
|
|
||||||
|
|
||||||
class PurgeUsers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $retries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('default');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare some variables
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Setup the esi variable
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication();
|
|
||||||
|
|
||||||
//Get all of the users from the database
|
|
||||||
$users = User::all();
|
|
||||||
|
|
||||||
//Get the allowed logins
|
|
||||||
$legacy = AllowedLogin::where(['login_type' => 'Legacy'])->pluck('entity_id')->toArray();
|
|
||||||
$renter = AllowedLogin::where(['login_type' => 'Renter'])->pluck('entity_id')->toArray();
|
|
||||||
|
|
||||||
//Cycle through all of the users, and either update their role, or delete them.
|
|
||||||
foreach($users as $user) {
|
|
||||||
//Set the fail bit to false for the next user to check
|
|
||||||
$failed = false;
|
|
||||||
|
|
||||||
//Note a screen entry for when doing cli stuff
|
|
||||||
printf("Processing character with id of " . $user->character_id . "\r\n");
|
|
||||||
|
|
||||||
//Get the character information
|
|
||||||
try {
|
|
||||||
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$corp_info = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
|
||||||
'corporation_id' => $character_info->corporation_id,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::warning('Failed to get character information in purge user command for user ' . $user->character_id);
|
|
||||||
$failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the fail bit is still false, then continue
|
|
||||||
if($failed === false) {
|
|
||||||
//Get the user's role
|
|
||||||
$role = UserRole::where(['character_id' => $user->character_id])->first();
|
|
||||||
|
|
||||||
//We don't want to modify Admin and SuperUsers. Admins and SuperUsers are removed via a different process.
|
|
||||||
if($role->role != 'Admin') {
|
|
||||||
//Check if the user is allowed to login
|
|
||||||
if(isset($corp_info->alliance_id)) {
|
|
||||||
//Warped Intentions is allowed to login
|
|
||||||
if($corp_info->alliance_id == '99004116') {
|
|
||||||
//If the alliance is Warped Intentions, then modify the role if we need to
|
|
||||||
if($role->role != 'User') {
|
|
||||||
//Upate the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'User',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'W4RP',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else if(in_array($corp_info->alliance_id, $legacy)) { //Legacy Users
|
|
||||||
if($role->role != 'User') {
|
|
||||||
//Update the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'User',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'Legacy',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else if(in_array($corp_info->alliance_id, $renter)) { //Renter Users
|
|
||||||
if($role->role != 'Renter') {
|
|
||||||
//Update the role of the user
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'role' => 'Renter',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Update the user type
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->update([
|
|
||||||
'user_type' => 'Renter',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//If the user is part of no valid login group, then delete the user.
|
|
||||||
//Delete all of the permissions first
|
|
||||||
UserPermission::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Delete the user's role
|
|
||||||
UserRole::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
//Delete any alts the user might have registered.
|
|
||||||
$altCount = UserAlt::where(['main_id' => $user->character_id])->count();
|
|
||||||
if($altCount > 0) {
|
|
||||||
UserAlt::where([
|
|
||||||
'main_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete the user from the user table
|
|
||||||
User::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
EsiScope::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
|
|
||||||
EsiToken::where([
|
|
||||||
'character_id' => $user->character_id,
|
|
||||||
])->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['Data', 'PurgeUsers'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Eve;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
class ItemPricesUpdate implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('default');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$moonHelper = new MoonCalc;
|
|
||||||
|
|
||||||
$moonHelper->FetchNewPrices();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['Eve', 'ItemPricesUpdate'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Eve;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Spatie\RateLimitedMiddleware\RateLimited;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use Seat\Eseye\Cache\NullCache;
|
|
||||||
use Seat\Eseye\Configuration;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\Jobs\JobStatus;
|
|
||||||
use App\Models\Mail\SentMail;
|
|
||||||
use Seat\Eseye\Containers\EsiResponse;
|
|
||||||
|
|
||||||
class SendEveMail implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries
|
|
||||||
* With new rate limiting, we need a retry basis versus timeout basis
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $retries = 1;
|
|
||||||
|
|
||||||
private $sender;
|
|
||||||
private $body;
|
|
||||||
private $recipient;
|
|
||||||
private $recipient_type;
|
|
||||||
private $subject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($body, $recipient, $recipient_type, $subject, $sender) {
|
|
||||||
//Set the connection
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('mail');
|
|
||||||
|
|
||||||
//Set the middleware for the job
|
|
||||||
$this->middleware = $this->middleware();
|
|
||||||
|
|
||||||
//Private variables
|
|
||||||
$this->body = $body;
|
|
||||||
$this->recipient = $recipient;
|
|
||||||
$this->recipient_type = $recipient_type;
|
|
||||||
$this->subject = $subject;
|
|
||||||
$this->sender = $sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
* Utilized by using SendEveMail::dispatch($mail);
|
|
||||||
* The model is passed into the dispatch function, then added to the queue
|
|
||||||
* for processing.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare some variables
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$errorCode = null;
|
|
||||||
|
|
||||||
//Get the esi configuration
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Retrieve the token for main character to send mails from
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
//Create the ESI authentication container
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
//Check to see if the token is valid or not
|
|
||||||
if($esiHelper->TokenExpired($refreshToken)) {
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$esi->setBody([
|
|
||||||
'approved_cost' => 10000,
|
|
||||||
'body' => $this->body,
|
|
||||||
'recipients' => [[
|
|
||||||
'recipient_id' => $this->recipient,
|
|
||||||
'recipient_type' => $this->recipient_type,
|
|
||||||
]],
|
|
||||||
'subject' => $this->subject,
|
|
||||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
|
||||||
'character_id'=> $this->sender,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Middleware to only allow 4 jobs to be run per minute
|
|
||||||
* After a failed job, the job is released back into the queue for at least 1 minute x the number of times attempted
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function middleware() {
|
|
||||||
|
|
||||||
//Allow 4 jobs per minute, and implement a rate limited backoff on failed jobs
|
|
||||||
$rateLimitedMiddleware = (new RateLimited())
|
|
||||||
->enabled()
|
|
||||||
->key('psemj')
|
|
||||||
->connectionName('default')
|
|
||||||
->allow(4)
|
|
||||||
->everySeconds(60)
|
|
||||||
->releaseAfterOneMinute()
|
|
||||||
->releaseAfterBackoff($this->attempts());
|
|
||||||
|
|
||||||
return [$rateLimitedMiddleware];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Determine the time at which the job should timeout.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function retryUntil() : \DateTime
|
|
||||||
{
|
|
||||||
return Carbon::now()->addDay();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The job failed to process.
|
|
||||||
*
|
|
||||||
* @param Exception $exception
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function failed($exception)
|
|
||||||
{
|
|
||||||
if(!exception instanceof RequestFailedException) {
|
|
||||||
//If not a failure due to ESI, then log it. Otherwise,
|
|
||||||
//deduce why the exception occurred.
|
|
||||||
Log::critical($exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((is_object($exception->getEsiResponse()) && (stristr($exception->getEsiResponse()->error, 'Too many errors') || stristr($exception->getEsiResponse()->error, 'This software has exceeded the error limit for ESI'))) ||
|
|
||||||
(is_string($exception->getEsiResponse()) && (stristr($exception->getEsiResponse(), 'Too many errors') || stristr($exception->getEsiResponse(), 'This software has exceeded the error limit for ESI')))) {
|
|
||||||
|
|
||||||
//We have hit the error rate limiter, wait 120 seconds before releasing the job back into the queue.
|
|
||||||
Log::info('SendEveMail has hit the error rate limiter. Releasing the job back into the wild in 2 minutes.');
|
|
||||||
$this->release(120);
|
|
||||||
} else {
|
|
||||||
$errorCode = $exception->getEsiResponse()->getErrorCode();
|
|
||||||
|
|
||||||
switch($errorCode) {
|
|
||||||
case 400: //Bad Request
|
|
||||||
Log::critical("Bad request has occurred in SendEveMail. Job has been discarded");
|
|
||||||
break;
|
|
||||||
case 401: //Unauthorized Request
|
|
||||||
Log::critical("Unauthorized request has occurred in SendEveMail at " . Carbon::now()->toDateTimeString() . ".\r\nCancelling the job.");
|
|
||||||
break;
|
|
||||||
case 403: //Forbidden
|
|
||||||
Log::critical("SendEveMail has incurred a forbidden error. Cancelling the job.");
|
|
||||||
break;
|
|
||||||
case 420: //Error Limited
|
|
||||||
Log::warning("Error rate limit occurred in SendEveMail. Restarting job in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 500: //Internal Server Error
|
|
||||||
Log::critical("Internal Server Error for ESI in SendEveMail. Attempting a restart in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 503: //Service Unavailable
|
|
||||||
Log::critical("Service Unavailabe for ESI in SendEveMail. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 504: //Gateway Timeout
|
|
||||||
Log::critical("Gateway timeout in SendEveMail. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 520: //Internal Error -- Mostly comes when rate limited hit
|
|
||||||
Log::warning("Rate limit hit for SendEveMail. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 201: //Good response code
|
|
||||||
$this->SaveSentRecord($this->sender, $this->subject, $this->body, $this->recipient, $this->recipient_type);
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
//If no code is given, then log and break out of switch.
|
|
||||||
default:
|
|
||||||
Log::warning("No response code received from esi call in SendEveMail.\r\n");
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tags() {
|
|
||||||
return ['ProcessEveMails'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {
|
|
||||||
$sentmail = new SentMail;
|
|
||||||
$sentmail->sender = $sender;
|
|
||||||
$sentmail->subject = $subject;
|
|
||||||
$sentmail->body = $body;
|
|
||||||
$sentmail->recipient = $recipient;
|
|
||||||
$sentmail->recipient_type = $recipientType;
|
|
||||||
$sentmail->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Finances;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\FinanceHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Finances\AllianceWalletJournal;
|
|
||||||
|
|
||||||
class UpdateAllianceWalletJournalJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 1800;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $retries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('finances');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$fHelper = new FinanceHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
$pages = $fHelper->GetAllianceWalletJournalPages(1, $config['primary']);
|
|
||||||
|
|
||||||
for($i = 1; $i <= $pages; $i++) {
|
|
||||||
UpdateAllianceWalletJournalPage::dispatch(1, $config['primary'], $i)->onQueue('journal');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['UpdateAllianceWalletJournal', 'Finances'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Finances;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use Seat\Eseye\Cache\NullCache;
|
|
||||||
use Seat\Eseye\Configuration;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Finances\AllianceWalletJournal;
|
|
||||||
|
|
||||||
class UpdateAllianceWalletJournalPage implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
private $division;
|
|
||||||
private $charId;
|
|
||||||
private $page;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($division, $charId, $page)
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('finances');
|
|
||||||
|
|
||||||
$this->division = $division;
|
|
||||||
$this->charId = $charId;
|
|
||||||
$this->page = $page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables in the handler
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Setup the esi container.
|
|
||||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
|
||||||
|
|
||||||
//Check the scope
|
|
||||||
if(!$esiHelper->HaveEsiScope($this->charId, 'esi-wallet.read_corporation_wallets.v1')) {
|
|
||||||
Log::critical('Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($esiHelper->TokenExpired($token)) {
|
|
||||||
$token = $esiHelper->GetRefreshToken($this->charId);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Reference the character id to the corporation id
|
|
||||||
$char = $lookup->GetCharacterInfo($this->charId);
|
|
||||||
$corpId = $char->corporation_id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to get the data from the esi api. If it fails, we skip the page, and go onto the next page, unless
|
|
||||||
* the failed page is the first page.
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
$journals = $esi->page($this->page)
|
|
||||||
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
|
||||||
'corporation_id' => $corpId,
|
|
||||||
'division' => $this->division,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::warning('Failed to get wallet journal page ' . $currentPage . ' for character id: ' . $charId);
|
|
||||||
Log::warning($e);
|
|
||||||
$this->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Decode the json data, and return it as an array
|
|
||||||
$wallet = json_decode($journals->raw, true);
|
|
||||||
|
|
||||||
//Foreach journal entry, add the journal entry to the table
|
|
||||||
foreach($wallet as $entry) {
|
|
||||||
//See if we find the entry id in the database already
|
|
||||||
$found = AllianceWalletJournal::where([
|
|
||||||
'id' => $entry['id'],
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($found == 0) {
|
|
||||||
$awj = new AllianceWalletJournal;
|
|
||||||
$awj->id = $entry['id'];
|
|
||||||
$awj->corporation_id = $corpId;
|
|
||||||
$awj->division = $this->division;
|
|
||||||
if(isset($entry['amount'])) {
|
|
||||||
$awj->amount = $entry['amount'];
|
|
||||||
}
|
|
||||||
if(isset($entry['balance'])) {
|
|
||||||
$awj->balance = $entry['balance'];
|
|
||||||
}
|
|
||||||
if(isset($entry['context_id'])) {
|
|
||||||
$awj->context_id = $entry['context_id'];
|
|
||||||
}
|
|
||||||
if(isset($entry['date'])) {
|
|
||||||
$awj->date = $esiHelper->DecodeDate($entry['date']);
|
|
||||||
}
|
|
||||||
if(isset($entry['description'])) {
|
|
||||||
$awj->description = $entry['description'];
|
|
||||||
}
|
|
||||||
if(isset($entry['first_party_id'])) {
|
|
||||||
$awj->first_party_id = $entry['first_party_id'];
|
|
||||||
}
|
|
||||||
if(isset($entry['reason'])) {
|
|
||||||
$awj->reason = $entry['reason'];
|
|
||||||
}
|
|
||||||
if(isset($entry['ref_type'])) {
|
|
||||||
$awj->ref_type = $entry['ref_type'];
|
|
||||||
}
|
|
||||||
if(isset($entry['tax'])) {
|
|
||||||
$awj->tax = $entry['tax'];
|
|
||||||
}
|
|
||||||
if(isset($entry['tax_receiver_id'])) {
|
|
||||||
$awj->tax_receiver_id = $entry['tax_receiver_id'];
|
|
||||||
}
|
|
||||||
$awj->save();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return as completed
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['UpdateAllianceWalletJournalPage', 'Finances'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Finances;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Library Functions
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
class UpdateItemPrices implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 1800;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $retries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('default');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$moonHelper = new MoonCalc;
|
|
||||||
//Fetch new prices from fuzzwork.co.uk for the item pricing schemes
|
|
||||||
$moonHelper->FetchNewPrices();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['UpdateItemPrices', 'Finances'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
|
|
||||||
class CreateMiningTaxesInvoice implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$mainAlts = array();
|
|
||||||
$mainIds = new Collection;
|
|
||||||
|
|
||||||
//Get all of the users in the database
|
|
||||||
$characters = User::all();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//App Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\MiningTaxes\ProcessMiningTaxesLedgers;
|
|
||||||
|
|
||||||
//App Models
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\Moon\MineralPrice;
|
|
||||||
use App\Models\Moon\ItemComposition;
|
|
||||||
use App\Models\Esi\EsiToken;
|
|
||||||
use App\Models\Esi\EsiScope;
|
|
||||||
|
|
||||||
class FetchMiningTaxesLedgers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Job Variables
|
|
||||||
*/
|
|
||||||
private $charId;
|
|
||||||
private $corpId;
|
|
||||||
private $observerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($charId, $corpId, $observerId)
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
//Import the variables from the calling function
|
|
||||||
$this->charId = $charId;
|
|
||||||
$this->corpId = $corpId;
|
|
||||||
$this->observerId = $observerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$mHelper = new MoonCalc;
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$pageFailed = false;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Check for the correct scope
|
|
||||||
if(!$esiHelper->haveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1')) {
|
|
||||||
Log::critical('Character: ' . $this->charId . ' did not have the correct esi scope in FetchMiningTaxesLedgersJob.');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the esi token in order to pull data from esi
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($this->charId);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
//Set the current page
|
|
||||||
$currentPage = 1;
|
|
||||||
$totalPages = 1;
|
|
||||||
|
|
||||||
//Setup a do-while loop to sort through the ledgers by pages
|
|
||||||
do {
|
|
||||||
/**
|
|
||||||
* During the course of the operation, we want to ensure our token stays valid.
|
|
||||||
* If the token, expires, then we want to refresh the token through the esi helper
|
|
||||||
* library functionality.
|
|
||||||
*/
|
|
||||||
if($esiHelper->TokenExpired($refreshToken)) {
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($this->charId);
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to get the data from the esi api. If it fails, we skip the page
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
$response = $esi->page($currentPage)
|
|
||||||
->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
|
||||||
'corporation_id' => $config['corporation'],
|
|
||||||
'observer_id' => $this->observerId,
|
|
||||||
]);
|
|
||||||
} catch(RequestFailedException $e) {
|
|
||||||
Log::warning('Failed to get the mining ledger in FetchMiningTaxesLedgersCommand for observer id: ' . $this->observerId);
|
|
||||||
$pageFailed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the current page is the first one and the page didn't fail, then update the total pages.
|
|
||||||
* If the first page failed, just return as we aren't going to be able to get the total amount of data needed.
|
|
||||||
*/
|
|
||||||
if($currentPage == 1 && $pageFailed == false) {
|
|
||||||
$totalPages = $response->pages;
|
|
||||||
} else if($currentPage == 1 && $pageFailed == true) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($pageFailed == true) {
|
|
||||||
//If the page failed, then reset the variable, and skip the current iteration
|
|
||||||
//of creating the jobs.
|
|
||||||
$pageFailed = false;
|
|
||||||
} else {
|
|
||||||
//Decode the json response from the ledgers
|
|
||||||
$ledgers = json_decode($response->raw);
|
|
||||||
|
|
||||||
//Dispatch jobs to process each of the mining ledger entries
|
|
||||||
foreach($ledgers as $ledger) {
|
|
||||||
ProcessMiningTaxesLedgers::dispatch($ledger, $this->observerId)->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Increment the current pages
|
|
||||||
$currentPage++;
|
|
||||||
|
|
||||||
} while($currentPage <= $totalPages);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['FetchMiningTaxesLedgers', 'MiningTaxes', 'MiningTaxesLedgers'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Helpers\StructureHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
|
|
||||||
class FetchMiningTaxesObservers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$config = config('esi');
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$sHelper = new StructureHelper($config['primary'], $config['corporation']);
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Check for the ESI scope needed.
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
|
||||||
Log::critical('Esi scopes were not found for FetchMiningTaxesObserversJob.');
|
|
||||||
print("Esi scopes not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Check for the other ESI scope needed.
|
|
||||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) {
|
|
||||||
Log::critical('Esi scope esi-universe.read_structures.v1 was not found for FetchMiningTaxesObserversJob.');
|
|
||||||
print("Esi scopes not found 2");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the refresh token for the character
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
//Get the esi variable
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
|
||||||
|
|
||||||
//Invoke the call to ESI API.
|
|
||||||
$response = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
|
||||||
'corporation_id' => $config['corporation'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Decode the json response, but leave it as objects rather than an array
|
|
||||||
$resp = json_decode($response->raw, false);
|
|
||||||
|
|
||||||
//Run through the mining observers, and add them to the database
|
|
||||||
foreach($resp as $observer) {
|
|
||||||
//See if the observer is found in the database
|
|
||||||
$found = Observer::where([
|
|
||||||
'observer_id' => $observer->observer_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
//Get the observer name from esi
|
|
||||||
$structureInfo = $sHelper->GetStructureInfo($observer->observer_id);
|
|
||||||
|
|
||||||
//If found, then update the structure
|
|
||||||
if($found > 0) {
|
|
||||||
//Update the existing structure in the database
|
|
||||||
Observer::where([
|
|
||||||
'observer_id' => $observer->observer_id,
|
|
||||||
])->update([
|
|
||||||
'observer_id' => $observer->observer_id,
|
|
||||||
'observer_name' => $structureInfo->name,
|
|
||||||
'last_updated' => $observer->last_updated,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
//Add a new observer into the observer table
|
|
||||||
$newObs = new Observer;
|
|
||||||
$newObs->observer_id = $observer->observer_id;
|
|
||||||
$newObs->observer_type = $observer->observer_type;
|
|
||||||
$newObs->observer_name = $structureInfo->name;
|
|
||||||
$newObs->last_updated = $observer->last_updated;
|
|
||||||
$newObs->solar_system_id = $structureInfo->solar_system_id;
|
|
||||||
$newObs->solar_system_name = $lookup->SystemIdToName($structureInfo->solar_system_id);
|
|
||||||
$newObs->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cleanup stale data that hasn't been updated in at least 1 week.
|
|
||||||
*/
|
|
||||||
$date = Carbon::now()->subDays(7);
|
|
||||||
Observer::where('last_updated', '<', $date)->delete();
|
|
||||||
|
|
||||||
//Return 0 saying everything is fine
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The job failed to process
|
|
||||||
* @param Exception $exception
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function failed($exception) {
|
|
||||||
if(!exception instanceof RequestFailedException) {
|
|
||||||
//If not a failure due to ESI, then log it. Otherwise,
|
|
||||||
//deduce why the exception occurred.
|
|
||||||
Log::critical($exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((is_object($exception->getEsiResponse()) && (stristr($exception->getEsiResponse()->error, 'Too many errors') || stristr($exception->getEsiResponse()->error, 'This software has exceeded the error limit for ESI'))) ||
|
|
||||||
(is_string($exception->getEsiResponse()) && (stristr($exception->getEsiResponse(), 'Too many errors') || stristr($exception->getEsiResponse(), 'This software has exceeded the error limit for ESI')))) {
|
|
||||||
|
|
||||||
//We have hit the error rate limiter, wait 120 seconds before releasing the job back into the queue.
|
|
||||||
Log::info('FetchMiningTaxesObservers has hit the error rate limiter. Releasing the job back into the wild in 2 minutes.');
|
|
||||||
$this->release(120);
|
|
||||||
} else {
|
|
||||||
$errorCode = $exception->getEsiResponse()->getErrorCode();
|
|
||||||
|
|
||||||
switch($errorCode) {
|
|
||||||
case 400: //Bad Request
|
|
||||||
Log::critical("Bad request has occurred in FetchMiningTaxesObservers. Job has been discarded");
|
|
||||||
break;
|
|
||||||
case 401: //Unauthorized Request
|
|
||||||
Log::critical("Unauthorized request has occurred in FetchMiningTaxesObservers at " . Carbon::now()->toDateTimeString() . ".\r\nCancelling the job.");
|
|
||||||
break;
|
|
||||||
case 403: //Forbidden
|
|
||||||
Log::critical("FetchMiningTaxesObservers has incurred a forbidden error. Cancelling the job.");
|
|
||||||
break;
|
|
||||||
case 420: //Error Limited
|
|
||||||
Log::warning("Error rate limit occurred in FetchMiningTaxesObservers. Restarting job in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 500: //Internal Server Error
|
|
||||||
Log::critical("Internal Server Error for ESI in FetchMiningTaxesObservers. Attempting a restart in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 503: //Service Unavailable
|
|
||||||
Log::critical("Service Unavailabe for ESI in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 504: //Gateway Timeout
|
|
||||||
Log::critical("Gateway timeout in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 201: //Good response code
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
//If no code is given, then log and break out of switch.
|
|
||||||
default:
|
|
||||||
Log::warning("No response code received from esi call in FetchMiningTaxesObservers.\r\n");
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horizon
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['FetchMiningObservers', 'MiningTaxes'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\MiningTaxes\FetchMiningTaxesLedgers;
|
|
||||||
|
|
||||||
class PreFetchMiningTaxesLedgers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Get the site configuration which holds some data we need
|
|
||||||
$config = config('esi');
|
|
||||||
//Get the observers from the database
|
|
||||||
$observers = Observer::all();
|
|
||||||
|
|
||||||
//For each of the observers, send a job to fetch the mining ledger
|
|
||||||
foreach($observers as $obs) {
|
|
||||||
//Dispatch the mining taxes ledger jobs
|
|
||||||
FetchMiningTaxesLedgers::dispatch($config['primary'], $config['corporation'], $obs->observer_id)->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['PreFetchMiningTaxesLedgers', 'MiningTaxes', 'MiningTaxesLedgers'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//App Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\Moon\MineralPrice;
|
|
||||||
use App\Models\Moon\ItemComposition;
|
|
||||||
|
|
||||||
class ProcessMiningTaxesLedgers implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Job Variables
|
|
||||||
*/
|
|
||||||
private $ledger;
|
|
||||||
private $observerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($ledger, $observerId)
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
|
|
||||||
//Import variables from the calling function
|
|
||||||
$this->ledger = $ledger;
|
|
||||||
$this->observerId = $observerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$mHelper = new MoonCalc;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Create a starting date for the ledger
|
|
||||||
$ledgerDate = Carbon::createFromFormat('Y-m-d', $this->ledger->last_updated);
|
|
||||||
|
|
||||||
//If the ledger is more than one day old, then process it, otherwise, we don't process it
|
|
||||||
//or add it to the database as it may still be updating.
|
|
||||||
if($ledgerDate->lessThan(Carbon::now()->subDay())) {
|
|
||||||
//Get some of the basic information we need to work with
|
|
||||||
$charName = $lookup->CharacterIdToName($this->ledger->character_id);
|
|
||||||
//Get the type name from the ledger ore
|
|
||||||
$typeName = $lookup->ItemIdToName($this->ledger->type_id);
|
|
||||||
//Get the price from the helper function
|
|
||||||
$price = $mHelper->CalculateOrePrice($this->ledger->type_id);
|
|
||||||
//Calculate the total price based on the amount
|
|
||||||
$amount = (($price * $this->ledger->quantity) * $config['refine_rate']);
|
|
||||||
|
|
||||||
$found = Ledger::where([
|
|
||||||
'character_id' => $this->ledger->character_id,
|
|
||||||
'observer_id' => $this->observerId,
|
|
||||||
'type_id' => $this->ledger->type_id,
|
|
||||||
'last_updated' => $this->ledger->last_updated,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($found == 0) {
|
|
||||||
$ledg = new Ledger;
|
|
||||||
$ledg->character_id = $this->ledger->character_id;
|
|
||||||
$ledg->character_name = $charName;
|
|
||||||
$ledg->observer_id = $this->observerId;
|
|
||||||
$ledg->last_updated = $this->ledger->last_updated;
|
|
||||||
$ledg->type_id = $this->ledger->type_id;
|
|
||||||
$ledg->ore_name = $typeName;
|
|
||||||
$ledg->quantity = $this->ledger->quantity;
|
|
||||||
$ledg->amount = $amount;
|
|
||||||
$ledg->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['ProcessMiningTaxesLedgers', 'MiningTaxes', 'MiningTaxesLedgers'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Payment;
|
|
||||||
use App\Models\Finances\AllianceWalletJournal;
|
|
||||||
|
|
||||||
class ProcessMiningTaxesPayments implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare the variables we will need
|
|
||||||
$looup = new LookupHelper;
|
|
||||||
$currentTime = Carbon::now();
|
|
||||||
|
|
||||||
//Get the outstanding invoices
|
|
||||||
$outstanding = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Use the player donation journal from finances to see if the invoice_id is present
|
|
||||||
//as a reason
|
|
||||||
foreach($outstanding as $invoice) {
|
|
||||||
//See if we have a reason with the correct uniqid from the player donation journal
|
|
||||||
$found = AllianceWalletJournal::where([
|
|
||||||
'reason' => $invoice->invoice_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
//If we have received the invoice, then mark the invoice as paid
|
|
||||||
if($found > 0) {
|
|
||||||
//If we have the count, then grab the journal entry in order to do some things with it
|
|
||||||
$journal = AllianceWalletJournal::where([
|
|
||||||
'reason' => $invoice->invoice_id,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
//If the bill is paid on time, then update the invoice as such
|
|
||||||
if($currentTime->lessThanOrEqualTo($journal->inserted_at)) {
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Paid',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($currentTime->greaterThan($journal->inserted_at)) {
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Paid Late',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$count = AllianceWalletJournal::where([
|
|
||||||
'reason' => $invoice->invoice_id,
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if($count > 0) {
|
|
||||||
//If we have the count, then grab the journal entry in order to do some things with it
|
|
||||||
$journal = AllianceWalletJournal::where([
|
|
||||||
'reason' => $invoice->invoice_id,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
//If the bill is paid on time, then update the invoice as such
|
|
||||||
if($currentTime->lessThanOrEqualTo($journal->inserted_at)) {
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Paid',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($currentTime->greaterThan($journal->inserted_at)) {
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Paid Late',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Use the contract descriptions from the esi to see if the invoice_id is present.
|
|
||||||
//If the invoice is present, then mark it off as sent in correctly
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['ProcessMiningTaxesPayments', 'MiningTaxes', 'Payments'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
use App\Models\User\User;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class SendMiningTaxesInvoices implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$mailDelay = 15;
|
|
||||||
$mains = new Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This section will determine if users are mains or alts of a main.
|
|
||||||
* If they are mains, we keep the key. If they are alts of a main, then we delete
|
|
||||||
* the key from the collection.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Pluck all the users from the database of ledgers to determine if they are mains or alts.
|
|
||||||
$tempMains = Ledger::where([
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->pluck('character_id');
|
|
||||||
|
|
||||||
//Get the unique character ids from the ledgers in the previous statement
|
|
||||||
$tempMains = $tempMains->unique()->values()->all();
|
|
||||||
|
|
||||||
//Cycle through the array of mains, and remove any characters which are in the User Alt table,
|
|
||||||
//as those characters will be grouped with their correct main later.
|
|
||||||
for($i = 0; $i < sizeof($tempMains); $i++) {
|
|
||||||
if(UserAlt::where(['character_id' => $tempMains[$i]])->count() == 0) {
|
|
||||||
$mains->push($tempMains[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For each of the users, let's determine if there are any ledgers,
|
|
||||||
* then determine if there are any alts and ledgers associated with the alts.
|
|
||||||
*/
|
|
||||||
foreach($mains as $main) {
|
|
||||||
//Declare some variables for each run through the for loop
|
|
||||||
$ledgers = new Collection;
|
|
||||||
|
|
||||||
//Count the ledgers for the main
|
|
||||||
$mainLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
|
|
||||||
|
|
||||||
//If there are ledgers for the main, then let's grab them
|
|
||||||
if($mainLedgerCount > 0) {
|
|
||||||
$mainLedgers = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
|
|
||||||
|
|
||||||
//Cycle through the entries, and add them to the ledger to send with the invoice
|
|
||||||
foreach($mainLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => (int)$row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the alt count for the main character
|
|
||||||
$altCount = UserAlt::where(['main_id' => $main])->count();
|
|
||||||
//If more than 0 alts, grab all the alts.
|
|
||||||
if($altCount > 0) {
|
|
||||||
$alts = UserAlt::where([
|
|
||||||
'main_id' => $main,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Cycle through the alts, and get the ledgers, and push onto the stack
|
|
||||||
foreach($alts as $alt) {
|
|
||||||
$altLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
|
|
||||||
|
|
||||||
if($altLedgerCount > 0) {
|
|
||||||
$altLedgers = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
|
|
||||||
|
|
||||||
foreach($altLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => (int)$row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the collected information over to the function to send the actual mail
|
|
||||||
*/
|
|
||||||
if($ledgers->count() > 0) {
|
|
||||||
$this->CreateInvoice($main, $ledgers, $mailDelay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the invoice to the mail out
|
|
||||||
*
|
|
||||||
* @var charId
|
|
||||||
* @var ledgers
|
|
||||||
* @var mailDelay
|
|
||||||
*/
|
|
||||||
private function CreateInvoice($charId, Collection $ledgers, int &$mailDelay) {
|
|
||||||
$ores = array();
|
|
||||||
$characters = array();
|
|
||||||
$characterIds = array();
|
|
||||||
$totalPrice = 0.00;
|
|
||||||
$body = null;
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Create an invoice id
|
|
||||||
$invoiceId = "M" . uniqid();
|
|
||||||
|
|
||||||
//Get the sum of all the ledgers
|
|
||||||
$invoiceAmount = round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2);
|
|
||||||
|
|
||||||
//Get the character name from the lookup table
|
|
||||||
$charName = $lookup->CharacterIdToName($charId);
|
|
||||||
|
|
||||||
//Create the date due and the invoice date
|
|
||||||
$dateDue = Carbon::now()->addDays(7);
|
|
||||||
$invoiceDate = Carbon::now();
|
|
||||||
|
|
||||||
//Set the mining tax from the config file
|
|
||||||
$numberMiningTax = number_format(((float)$config['mining_tax'] * (float)100.00), 2, ".", ",");
|
|
||||||
|
|
||||||
//Create the list of ores to put in the mail
|
|
||||||
$temp = $ledgers->toArray();
|
|
||||||
foreach($temp as $t) {
|
|
||||||
//If the key isn't set, set it to the default of 0
|
|
||||||
if(!isset($ores[$t['type_id']])) {
|
|
||||||
$ores[$t['type_id']] = (int)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add the quantity into the ores array
|
|
||||||
$ores[$t['type_id']] += (int)$t['quantity'];
|
|
||||||
|
|
||||||
//Create a list of character names
|
|
||||||
if(!isset($characters[$t['character_name']])) {
|
|
||||||
$characters[$t['character_name']] = $t['character_name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a list of character ids
|
|
||||||
if(!isset($characterIds[$t['character_id']])) {
|
|
||||||
$characterIds[$t['character_id']] = $t['character_id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the mail body to send to the main character
|
|
||||||
*/
|
|
||||||
$body .= "Dear " . $charName . ",<br><br>";
|
|
||||||
$body .= "Mining Taxes are due for the following ores mined from alliance moons: <br>";
|
|
||||||
foreach($ores as $ore => $quantity) {
|
|
||||||
$oreName = $lookup->ItemIdToName($ore);
|
|
||||||
$body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "<br>";
|
|
||||||
$body .= "Set the reason for transfer as " . $invoiceId . "<br>";
|
|
||||||
$body .= "The mining taxes are currently set to " . $numberMiningTax . "%.<br>";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "You can also send a contract with the following ores in the contract with the reason set as: " . $invoiceId . "<br>";
|
|
||||||
foreach($ores as $ore => $quantity) {
|
|
||||||
$oreName = $lookup->ItemIdToName($ore);
|
|
||||||
$body .= $oreName . ": " . number_format(round($quantity * $config['mining_tax']), 0, ".", ",") . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "Characters Processed: <br>";
|
|
||||||
foreach($characters as $character) {
|
|
||||||
$body .= $character . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//Check if the mail body is greater than 2000 characters. If greater than 2,000 characters, then
|
|
||||||
if(strlen($body) > 2000) {
|
|
||||||
$body = "Dear " . $charName . "<br><br>";
|
|
||||||
$body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "<br>";
|
|
||||||
$body .= "Set the reason for transfer as: " . $invoiceId . "<br>";
|
|
||||||
$body .= "The mining taxes are currently set to " . $numberMiningTax . "%.<br>";
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Mail the invoice to the character if the character is in
|
|
||||||
//Warped Intentions or Legacy
|
|
||||||
$subject = 'Warped Intentions Mining Taxes';
|
|
||||||
$sender = $config['primary'];
|
|
||||||
$recipientType = 'character';
|
|
||||||
$recipient = $charId;
|
|
||||||
|
|
||||||
//Send the Eve Mail Job to the queue to be dispatched
|
|
||||||
SendEveMail::dispatch($body, $recipient, $recipientType, $subject, $sender)->delay(Carbon::now()->addSeconds($mailDelay));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new invoice model, and save it to the database
|
|
||||||
*/
|
|
||||||
$invoice = new Invoice;
|
|
||||||
$invoice->character_id = $charId;
|
|
||||||
$invoice->character_name = $charName;
|
|
||||||
$invoice->invoice_id = $invoiceId;
|
|
||||||
$invoice->invoice_amount = $invoiceAmount;
|
|
||||||
$invoice->date_issued = $invoiceDate;
|
|
||||||
$invoice->date_due = $dateDue;
|
|
||||||
$invoice->status = 'Pending';
|
|
||||||
$invoice->mail_body = $body;
|
|
||||||
$invoice->save();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark the invoices as paid
|
|
||||||
*/
|
|
||||||
foreach($characterIds as $char) {
|
|
||||||
Ledger::where([
|
|
||||||
'character_id' => $char,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->update([
|
|
||||||
'invoice' => $invoiceId,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increment the mail delay for the next cycle
|
|
||||||
*/
|
|
||||||
$mailDelay += 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horizon
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['MiningTaxes', 'SendMiningTaxesInvoics', 'Invoices'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,316 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
use App\Models\User\User;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class SendMiningTaxesInvoicesOld implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$mailDelay = 15;
|
|
||||||
$mains = new Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This section will determine if users are mains or alts of a main.
|
|
||||||
* If they are mains, we keep the key. If they are alts of a main, then we delete
|
|
||||||
* the key from the collection.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Pluck all the users from the database of ledgers to determine if they are mains or alts.
|
|
||||||
$tempMains = Ledger::where([
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->pluck('character_id');
|
|
||||||
|
|
||||||
//Get the unique character ids from the ledgers in the previous statement
|
|
||||||
$tempMains = $tempMains->unique()->values()->all();
|
|
||||||
|
|
||||||
//Cycle through the array of mains, and remove any characters which are in the User Alt table,
|
|
||||||
//as those characters will be grouped with their correct main later.
|
|
||||||
for($i = 0; $i < sizeof($tempMains); $i++) {
|
|
||||||
if(UserAlt::where(['character_id' => $tempMains[$i]])->count() == 0) {
|
|
||||||
$mains->push($tempMains[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For each of the users, let's determine if there are any ledgers,
|
|
||||||
* then determine if there are any alts and ledgers associated with the alts.
|
|
||||||
*/
|
|
||||||
foreach($mains as $main) {
|
|
||||||
//Declare some variables for each run through the for loop
|
|
||||||
$ledgers = new Collection;
|
|
||||||
|
|
||||||
//Count the ledgers for the main
|
|
||||||
$mainLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
|
|
||||||
|
|
||||||
//If there are ledgers for the main, then let's grab them
|
|
||||||
if($mainLedgerCount > 0) {
|
|
||||||
$mainLedgers = Ledger::where([
|
|
||||||
'character_id' => $main,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
|
|
||||||
|
|
||||||
//Cycle through the entries, and add them to the ledger to send with the invoice
|
|
||||||
foreach($mainLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => (int)$row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the alt count for the main character
|
|
||||||
$altCount = UserAlt::where(['main_id' => $main])->count();
|
|
||||||
//If more than 0 alts, grab all the alts.
|
|
||||||
if($altCount > 0) {
|
|
||||||
$alts = UserAlt::where([
|
|
||||||
'main_id' => $main,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Cycle through the alts, and get the ledgers, and push onto the stack
|
|
||||||
foreach($alts as $alt) {
|
|
||||||
$altLedgerCount = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
|
|
||||||
|
|
||||||
if($altLedgerCount > 0) {
|
|
||||||
$altLedgers = Ledger::where([
|
|
||||||
'character_id' => $alt->character_id,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
|
|
||||||
|
|
||||||
foreach($altLedgers as $row) {
|
|
||||||
$ledgers->push([
|
|
||||||
'character_id' => $row->character_id,
|
|
||||||
'character_name' => $row->character_name,
|
|
||||||
'observer_id' => $row->observer_id,
|
|
||||||
'type_id' => $row->type_id,
|
|
||||||
'ore_name' => $row->ore_name,
|
|
||||||
'quantity' => (int)$row->quantity,
|
|
||||||
'amount' => (float)$row->amount,
|
|
||||||
'last_updated' => $row->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the collected information over to the function to send the actual mail
|
|
||||||
*/
|
|
||||||
if($ledgers->count() > 0) {
|
|
||||||
$this->CreateInvoice($main, $ledgers, $mailDelay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the invoice to the mail out
|
|
||||||
*
|
|
||||||
* @var charId
|
|
||||||
* @var ledgers
|
|
||||||
* @var mailDelay
|
|
||||||
*/
|
|
||||||
private function CreateInvoice($charId, Collection $ledgers, int &$mailDelay) {
|
|
||||||
$ores = array();
|
|
||||||
$characters = array();
|
|
||||||
$characterIds = array();
|
|
||||||
$totalPrice = 0.00;
|
|
||||||
$body = null;
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Create an invoice id
|
|
||||||
$invoiceId = "M" . uniqid();
|
|
||||||
|
|
||||||
//Get the sum of all the ledgers
|
|
||||||
$invoiceAmount = round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2);
|
|
||||||
|
|
||||||
//Get the character name from the lookup table
|
|
||||||
$charName = $lookup->CharacterIdToName($charId);
|
|
||||||
|
|
||||||
//Create the date due and the invoice date
|
|
||||||
$dateDue = Carbon::now()->addDays(7);
|
|
||||||
$invoiceDate = Carbon::now();
|
|
||||||
|
|
||||||
//Set the mining tax from the config file
|
|
||||||
$numberMiningTax = number_format(((float)$config['mining_tax'] * (float)100.00), 2, ".", ",");
|
|
||||||
|
|
||||||
//Create the list of ores to put in the mail
|
|
||||||
$temp = $ledgers->toArray();
|
|
||||||
foreach($temp as $t) {
|
|
||||||
//If the key isn't set, set it to the default of 0
|
|
||||||
if(!isset($ores[$t['type_id']])) {
|
|
||||||
$ores[$t['type_id']] = (int)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add the quantity into the ores array
|
|
||||||
$ores[$t['type_id']] += (int)$t['quantity'];
|
|
||||||
|
|
||||||
//Create a list of character names
|
|
||||||
if(!isset($characters[$t['character_name']])) {
|
|
||||||
$characters[$t['character_name']] = $t['character_name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Create a list of character ids
|
|
||||||
if(!isset($characterIds[$t['character_id']])) {
|
|
||||||
$characterIds[$t['character_id']] = $t['character_id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the mail body to send to the main character
|
|
||||||
*/
|
|
||||||
$body .= "Dear " . $charName . ",<br><br>";
|
|
||||||
$body .= "Mining Taxes are due for the following ores mined from alliance moons: <br>";
|
|
||||||
foreach($ores as $ore => $quantity) {
|
|
||||||
$oreName = $lookup->ItemIdToName($ore);
|
|
||||||
$body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "<br>";
|
|
||||||
$body .= "Set the reason for transfer as " . $invoiceId . "<br>";
|
|
||||||
$body .= "The mining taxes are currently set to " . $numberMiningTax . "%.<br>";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "You can also send a contract with the following ores in the contract with the reason set as: " . $invoiceId . "<br>";
|
|
||||||
foreach($ores as $ore => $quantity) {
|
|
||||||
$oreName = $lookup->ItemIdToName($ore);
|
|
||||||
$body .= $oreName . ": " . number_format(round($quantity * $config['mining_tax']), 0, ".", ",") . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "Characters Processed: <br>";
|
|
||||||
foreach($characters as $character) {
|
|
||||||
$body .= $character . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//Check if the mail body is greater than 2000 characters. If greater than 2,000 characters, then
|
|
||||||
if(strlen($body) > 2000) {
|
|
||||||
$body = "Dear " . $charName . "<br><br>";
|
|
||||||
$body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
|
|
||||||
$body .= "<br><br>";
|
|
||||||
$body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "<br>";
|
|
||||||
$body .= "Set the reason for transfer as: " . $invoiceId . "<br>";
|
|
||||||
$body .= "The mining taxes are currently set to " . $numberMiningTax . "%.<br>";
|
|
||||||
$body .= "<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Mail the invoice to the character if the character is in
|
|
||||||
//Warped Intentions or Legacy
|
|
||||||
$subject = 'Warped Intentions Mining Taxes';
|
|
||||||
$sender = $config['primary'];
|
|
||||||
$recipientType = 'character';
|
|
||||||
$recipient = $charId;
|
|
||||||
|
|
||||||
//Send the Eve Mail Job to the queue to be dispatched
|
|
||||||
SendEveMail::dispatch($body, $recipient, $recipientType, $subject, $sender)->delay(Carbon::now()->addSeconds($mailDelay));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new invoice model, and save it to the database
|
|
||||||
*/
|
|
||||||
$invoice = new Invoice;
|
|
||||||
$invoice->character_id = $charId;
|
|
||||||
$invoice->character_name = $charName;
|
|
||||||
$invoice->invoice_id = $invoiceId;
|
|
||||||
$invoice->invoice_amount = $invoiceAmount;
|
|
||||||
$invoice->date_issued = $invoiceDate;
|
|
||||||
$invoice->date_due = $dateDue;
|
|
||||||
$invoice->status = 'Pending';
|
|
||||||
$invoice->mail_body = $body;
|
|
||||||
$invoice->save();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark the invoices as paid
|
|
||||||
*/
|
|
||||||
foreach($characterIds as $char) {
|
|
||||||
Ledger::where([
|
|
||||||
'character_id' => $char,
|
|
||||||
'invoiced' => 'No',
|
|
||||||
])->update([
|
|
||||||
'invoice' => $invoiceId,
|
|
||||||
'invoiced' => 'Yes',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increment the mail delay for the next cycle
|
|
||||||
*/
|
|
||||||
$mailDelay += 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horizon
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['MiningTaxes', 'SendMiningTaxesInvoics', 'Invoices'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class UpdateMiningTaxesLateInvoices15th implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
$mailDelay = 15;
|
|
||||||
$today = Carbon::now();
|
|
||||||
|
|
||||||
//Get all of the invoices that are still pending.
|
|
||||||
$invoices = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Cycle through the invoices, and see if they are late or not.
|
|
||||||
foreach($invoices as $invoice) {
|
|
||||||
$dueDate = Carbon::create($invoice->date_due);
|
|
||||||
|
|
||||||
if($dueDate->greaterThan($today->subDays(7))) {
|
|
||||||
//Update the invoice in the database
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Late',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Build the mail
|
|
||||||
$subject = 'Warped Intentions Mining Taxes - Invoice Late';
|
|
||||||
$sender = $config['primary'];
|
|
||||||
$recipientType = 'character';
|
|
||||||
$recipient = $invoice->character_id;
|
|
||||||
|
|
||||||
$body = "Dear " . $invoice->character_name . ",<br><br>";
|
|
||||||
$body .= "The Mining Invoice: " . $invoice->invoice_id . " is late.<br>";
|
|
||||||
$body .= "Please remite " . number_format($invoice->invoice_amount, 2, ".", ",") . "to Spatial Forces.<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//Send a reminder to the user through eve mail about the late invoice
|
|
||||||
SendEveMail::dispatch($body, $recipient, $recipientType, $subject, $sender)->delay(Carbon::now()->addSeconds($mailDelay));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['UpdateMiningTaxesLateInvoices', 'MiningTaxes', 'Invoices'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
use App\Models\User\User;
|
|
||||||
use App\Models\User\UserAlt;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class UpdateMiningTaxesLateInvoices1st implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('miningtaxes');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$config = config('esi');
|
|
||||||
$mailDelay = 15;
|
|
||||||
$today = Carbon::now();
|
|
||||||
|
|
||||||
//Get all of the invoices that are still pending.
|
|
||||||
$invoices = Invoice::where([
|
|
||||||
'status' => 'Pending',
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Cycle through the invoices, and see if they are late or not.
|
|
||||||
foreach($invoices as $invoice) {
|
|
||||||
$dueDate = Carbon::create($invoice->date_due);
|
|
||||||
|
|
||||||
if($dueDate->greaterThan($today->subDays(7))) {
|
|
||||||
//Update the invoice in the database
|
|
||||||
Invoice::where([
|
|
||||||
'invoice_id' => $invoice->invoice_id,
|
|
||||||
])->update([
|
|
||||||
'status' => 'Late',
|
|
||||||
]);
|
|
||||||
|
|
||||||
//Build the mail
|
|
||||||
$subject = 'Warped Intentions Mining Taxes - Invoice Late';
|
|
||||||
$sender = $config['primary'];
|
|
||||||
$recipientType = 'character';
|
|
||||||
$recipient = $invoice->character_id;
|
|
||||||
|
|
||||||
$body = "Dear " . $invoice->character_name . ",<br><br>";
|
|
||||||
$body .= "The Mining Invoice: " . $invoice->invoice_id . " is late.<br>";
|
|
||||||
$body .= "Please remite " . number_format($invoice->invoice_amount, 2, ".", ",") . "to Spatial Forces.<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//Send a reminder to the user through eve mail about the late invoice
|
|
||||||
SendEveMail::dispatch($body, $recipient, $recipientType, $subject, $sender)->delay(Carbon::now()->addSeconds($mailDelay));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for Horzion
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['UpdateMiningTaxesLateInvoices', 'MiningTaxes', 'Invoices'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,174 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Structures;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use Seat\Eseye\Exception\RequestFailedException;
|
|
||||||
use App\Library\Structures\StructureHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Structure;
|
|
||||||
use App\Models\Structure\Service;
|
|
||||||
|
|
||||||
class FetchAllianceStructures implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('structures');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$config = config('esi');
|
|
||||||
$corpId = 98287666;
|
|
||||||
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
$structureScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1');
|
|
||||||
$corpStructureScope = $esiHelper->HaveEsiScope($config['primary'], 'esi-corporations.read_structures.v1');
|
|
||||||
|
|
||||||
//Check scopes
|
|
||||||
if($structureScope == false || $corpStructureScope == false) {
|
|
||||||
if($structureScope == false) {
|
|
||||||
Log::critical("Scope check for esi-universe.read_structures.v1 has failed.");
|
|
||||||
}
|
|
||||||
if($corpStructureScope == false) {
|
|
||||||
Log::critical("Scope check for esi-corporations.read_structures.v1 has failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the refresh token from the database
|
|
||||||
$token = $esiHelper->GetRefreshToken($config['primary']);
|
|
||||||
//Create the esi authentication container
|
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($token);
|
|
||||||
|
|
||||||
//Set the current page
|
|
||||||
$currentPage = 1;
|
|
||||||
//Set our default pages
|
|
||||||
$totalPages = 1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
//Attempt to get the entire page worth of structures
|
|
||||||
$structures = $esi->page($currentPage)
|
|
||||||
->invoke('get', '/corporations/{corporation_id}/structures/', [
|
|
||||||
'corporation_id' => $corpId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
//If on the first page, then update the total number of pages
|
|
||||||
if($currentPage == 1) {
|
|
||||||
$totalPages = $structures->pages;
|
|
||||||
}
|
|
||||||
|
|
||||||
//For each asset retrieved, let's process it.
|
|
||||||
foreach($structures as $s) {
|
|
||||||
ProcessAllianceStructures::dispatch($s)->onQueue('structures');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Increment the current page
|
|
||||||
$currentPage++;
|
|
||||||
} while($currentPage <= $totalPages);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The job failed to process
|
|
||||||
* @param Exception $exception
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function failed($exception) {
|
|
||||||
if(!exception instanceof RequestFailedException) {
|
|
||||||
//If not a failure due to ESI, then log it. Otherwise,
|
|
||||||
//deduce why the exception occurred.
|
|
||||||
Log::critical($exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((is_object($exception->getEsiResponse()) && (stristr($exception->getEsiResponse()->error, 'Too many errors') || stristr($exception->getEsiResponse()->error, 'This software has exceeded the error limit for ESI'))) ||
|
|
||||||
(is_string($exception->getEsiResponse()) && (stristr($exception->getEsiResponse(), 'Too many errors') || stristr($exception->getEsiResponse(), 'This software has exceeded the error limit for ESI')))) {
|
|
||||||
|
|
||||||
//We have hit the error rate limiter, wait 120 seconds before releasing the job back into the queue.
|
|
||||||
Log::info('FetchMiningTaxesObservers has hit the error rate limiter. Releasing the job back into the wild in 2 minutes.');
|
|
||||||
$this->release(120);
|
|
||||||
} else {
|
|
||||||
$errorCode = $exception->getEsiResponse()->getErrorCode();
|
|
||||||
|
|
||||||
switch($errorCode) {
|
|
||||||
case 400: //Bad Request
|
|
||||||
Log::critical("Bad request has occurred in FetchMiningTaxesObservers. Job has been discarded");
|
|
||||||
break;
|
|
||||||
case 401: //Unauthorized Request
|
|
||||||
Log::critical("Unauthorized request has occurred in FetchMiningTaxesObservers at " . Carbon::now()->toDateTimeString() . ".\r\nCancelling the job.");
|
|
||||||
break;
|
|
||||||
case 403: //Forbidden
|
|
||||||
Log::critical("FetchMiningTaxesObservers has incurred a forbidden error. Cancelling the job.");
|
|
||||||
break;
|
|
||||||
case 420: //Error Limited
|
|
||||||
Log::warning("Error rate limit occurred in FetchMiningTaxesObservers. Restarting job in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 500: //Internal Server Error
|
|
||||||
Log::critical("Internal Server Error for ESI in FetchMiningTaxesObservers. Attempting a restart in 120 seconds.");
|
|
||||||
$this->release(120);
|
|
||||||
break;
|
|
||||||
case 503: //Service Unavailable
|
|
||||||
Log::critical("Service Unavailabe for ESI in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 504: //Gateway Timeout
|
|
||||||
Log::critical("Gateway timeout in FetchMiningTaxesObservers. Releasing the job back to the queue in 30 seconds.");
|
|
||||||
$this->release(30);
|
|
||||||
break;
|
|
||||||
case 201: //Good response code
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
//If no code is given, then log and break out of switch.
|
|
||||||
default:
|
|
||||||
Log::warning("No response code received from esi call in FetchMiningTaxesObservers.\r\n");
|
|
||||||
$this->delete();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tags() {
|
|
||||||
return ['FetchAllianceStructures', 'AllianceStructures', 'Structures'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Structures;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Application Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Structure;
|
|
||||||
use App\Models\Structure\Service;
|
|
||||||
|
|
||||||
class ProcessAllianceStructures implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
private $structure;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($s)
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('structures');
|
|
||||||
|
|
||||||
//Set variables
|
|
||||||
$this->structure = $s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Update the structure if it already exists, or add the structure if it doesn't exist in the database
|
|
||||||
*/
|
|
||||||
if(Structure::where(['structure_id' => $this->structure->structure_id])->count() > 0) {
|
|
||||||
$this->UpdateStructure($this->structure);
|
|
||||||
} else {
|
|
||||||
$this->SaveNewStructure($this->structure);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for the job
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['ProcessAllianceStructures', 'AllianceStructures', 'Structures'];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function SaveNewStructure($structure) {
|
|
||||||
//Declare variables
|
|
||||||
$lookup = new LookupHelper;
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
//Get the solar system name
|
|
||||||
$solarName = $lookup->SystemIdToName($structure->system_id);
|
|
||||||
|
|
||||||
$s = new Structure;
|
|
||||||
$s->structure_id = $structure->structure_id;
|
|
||||||
$s->structure_name = $structure->name;
|
|
||||||
$s->solar_system_id = $structure->system_id;
|
|
||||||
$s->solar_system_name = $solarName;
|
|
||||||
$s->type_id = $structure->type_id;
|
|
||||||
$s->type_name = $lookup->StructureTypeIdToName($structure->type_id);
|
|
||||||
$s->corporation_id = $structure->corporation_id;
|
|
||||||
if(isset($structure->services)) {
|
|
||||||
$s->services = true;
|
|
||||||
foreach($structure->services as $service) {
|
|
||||||
$serv = new Service;
|
|
||||||
$serv->structure_id = $structure->structure_id;
|
|
||||||
$serv->name = $service->name;
|
|
||||||
$serv->state = $service->state;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$s->services = false;
|
|
||||||
}
|
|
||||||
$s->state = $structure->state;
|
|
||||||
if(isset($structre->state_timer_start)) {
|
|
||||||
$s->state_timer_start = $esiHelper->DecodeDate($structure->state_timer_start);
|
|
||||||
}
|
|
||||||
if(isset($structure->state_timer_end)) {
|
|
||||||
$s->state_timer_end = $esiHelper->DecodeDate($structure->state_timer_end);
|
|
||||||
}
|
|
||||||
if(isset($structure->fuel_expires)) {
|
|
||||||
$s->fuel_expires = $esiHelper->DecodeDate($structure->fuel_expires);
|
|
||||||
}
|
|
||||||
$s->profile_id = $structure->profile_id;
|
|
||||||
if(isset($structure->next_reinforce_apply)) {
|
|
||||||
$s->next_reinforce_apply = $structure->next_reinforce_apply;
|
|
||||||
}
|
|
||||||
if(isset($structure->next_reinforce_hour)) {
|
|
||||||
$s->next_reinforce_hour = $structure->next_reinforce_hour;
|
|
||||||
}
|
|
||||||
$s->reinforce_hour = $structure->reinforce_hour;
|
|
||||||
if(isset($structure->unanchors_at)) {
|
|
||||||
$s->unanchors_at = $esiHelper->DecodeDate($s->unanchors_at);
|
|
||||||
}
|
|
||||||
$s->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function UpdateStructure($structure) {
|
|
||||||
$esiHelper = new Esi;
|
|
||||||
|
|
||||||
if(isset($structure->corporation_id)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'corporation_id' => $structure->corporation_id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->state)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'state' => $structure->state,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->state_timer_start)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'state_timer_start' => $esiHelper->DecodeDate($structure->state_timer_start),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->state_timer_end)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'state_timer_end' => $esiHelper->DecodeDate($structure->state_timer_end),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->fuel_expires)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'fuel_expires' => $esiHelper->DecodeDate($structure->fuel_expires),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->profile_id)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'profile_id' => $structure->profile_id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->next_reinforce_apply)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'next_reinforce_apply' => $structure->next_reinforce_apply,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->next_reinforce_hour)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'next_reinforce_hour' => $structure->next_reinforce_hour,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->reinforce_hour)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'reinforce_hour' => $structure->reinforce_hour,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
if(isset($structure->unanchors_at)) {
|
|
||||||
Structure::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'unanchors_at' => $esiHelper->DecodeDate($structure->unanchors_at),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Service::where(['structure_id' => $structure->structure_id])->count() > 0) {
|
|
||||||
foreach($structure->services as $service) {
|
|
||||||
Service::where([
|
|
||||||
'structure_id' => $structure->structure_id,
|
|
||||||
])->update([
|
|
||||||
'state' => $service->state,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\Structures;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\FetchAllianceStructures;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Structure\Structure;
|
|
||||||
use App\Models\Structure\Service;
|
|
||||||
|
|
||||||
class PurgeAllianceStructures implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Set the connection for the job
|
|
||||||
$this->connection = 'redis';
|
|
||||||
$this->onQueue('structures');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
Structure::truncate();
|
|
||||||
Service::truncate();
|
|
||||||
|
|
||||||
FetchAllianceStructures::dispatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tags for the job
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public function tags() {
|
|
||||||
return ['PurgeAllianceStructures', 'AllianceStructures', 'Structures'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\SupplyChain;
|
|
||||||
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Lookups\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Contracts\SupplyChainBid;
|
|
||||||
use App\Models\Contracts\SupplyChainContract;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
|
||||||
|
|
||||||
class EndSupplyChainContractJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 1200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $retries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private Variables
|
|
||||||
*/
|
|
||||||
private $contractId;
|
|
||||||
private $issuerId;
|
|
||||||
private $issuerName;
|
|
||||||
private $title;
|
|
||||||
private $endDate;
|
|
||||||
private $deliveryBy;
|
|
||||||
private $body;
|
|
||||||
private $state;
|
|
||||||
private $finalCost;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(SupplyChainContract $contract)
|
|
||||||
{
|
|
||||||
//Set the queue connection up
|
|
||||||
$this->connection = 'redis';
|
|
||||||
|
|
||||||
//Set the variables
|
|
||||||
$contractId = $contract->contract_id;
|
|
||||||
$issuerId = $contract->issuer_id;
|
|
||||||
$issuerName = $contract->issuer_name;
|
|
||||||
$title = $contract->title;
|
|
||||||
$endDate = $contract->end_date;
|
|
||||||
$deliveryBy = $contract->delivery_by;
|
|
||||||
$body = $contract->body;
|
|
||||||
$state = $contract->state;
|
|
||||||
$finalCost = $contract->final_cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$bidId = null;
|
|
||||||
$bidAmount = null;
|
|
||||||
|
|
||||||
//Get all of the bids from the contract
|
|
||||||
$bids = SupplyChainBids::where([
|
|
||||||
'contract_id' => $contractId,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
//Loop through the bids and find the lowest bid
|
|
||||||
foreach($bids as $bid) {
|
|
||||||
if($bidId == null) {
|
|
||||||
$bidId = $bid->id;
|
|
||||||
$bidAmount = $bid->bid_amount;
|
|
||||||
} else {
|
|
||||||
if($bid->bid_amount < $bidAmount) {
|
|
||||||
$bidId = $bid->id;
|
|
||||||
$bidAmount = $bid->bid_amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Clean up the bids and update the contract with the winning bid
|
|
||||||
SupplyChainContract::where([
|
|
||||||
'contract_id' => $this->contractId,
|
|
||||||
])->update([
|
|
||||||
'final_cost' => $bidAmount,
|
|
||||||
'winning_bid_id' => $bidId,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
101
app/Jobs/ProcessAssetsJob.php
Normal file
101
app/Jobs/ProcessAssetsJob.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use App\Library\Structures\StructureHelper;
|
||||||
|
use App\Jobs\Library\JobHelper;
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
use Seat\Eseye\Containers\EsiAuthentication;
|
||||||
|
use Seat\Eseye\Eseye;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use App\Library\Assets\AssetHelper;
|
||||||
|
|
||||||
|
//App Models
|
||||||
|
use App\Models\Jobs\JobProcessAsset;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
use App\Models\Stock\Asset;
|
||||||
|
|
||||||
|
class ProcessAssetsJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout in seconds
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $timeout = 3600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of job retries
|
||||||
|
*/
|
||||||
|
public $tries = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Job Variables
|
||||||
|
*/
|
||||||
|
private $charId;
|
||||||
|
private $corpId;
|
||||||
|
private $page;
|
||||||
|
private $esi;
|
||||||
|
|
||||||
|
protected $location_array = [
|
||||||
|
'StructureFuel',
|
||||||
|
'FighterBay',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(JobProcessAsset $jpa)
|
||||||
|
{
|
||||||
|
$this->charId = $jpa->charId;
|
||||||
|
$this->corpId = $jpa->corpId;
|
||||||
|
$this->page = $jpa->page;
|
||||||
|
|
||||||
|
//Set the connection for the job
|
||||||
|
$this->connection = 'redis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
* The job's task is to get all fo the information for all of the assets in
|
||||||
|
* a structure and store them in the database. This task can take a few seconds
|
||||||
|
* therefore we want the Horizon job queue to take care of the request rather
|
||||||
|
* than the cronjob.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Declare the asset helper
|
||||||
|
$aHelper = new AssetHelper($this->charId, $this->corpId, $this->page);
|
||||||
|
|
||||||
|
//Get a page of assets
|
||||||
|
$assets = $aHelper->GetAssetsByPage();
|
||||||
|
|
||||||
|
//Cycle through the assets, and attmept to store them.
|
||||||
|
foreach($assets as $asset) {
|
||||||
|
//If the asset is in one of the locations we want, then store
|
||||||
|
//or update the asset
|
||||||
|
if(in_array($asset->location_flag, $this->location_array)) {
|
||||||
|
//Attempt to store the asset
|
||||||
|
$aHelper->StoreNewAsset($asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Purge Stale Data
|
||||||
|
$aHelper->PurgeStaleData();
|
||||||
|
}
|
||||||
|
}
|
||||||
134
app/Jobs/ProcessSendEveMailJob.php
Normal file
134
app/Jobs/ProcessSendEveMailJob.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
use App\Models\Mail\SentMail;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
|
class ProcessSendEveMailJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout in seconds
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $timeout = 3600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retries
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $retries = 3;
|
||||||
|
|
||||||
|
private $sender;
|
||||||
|
private $body;
|
||||||
|
private $recipient;
|
||||||
|
private $recipient_type;
|
||||||
|
private $subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(JobSendEveMail $mail) {
|
||||||
|
$this->body = $mail->body;
|
||||||
|
$this->recipient = $mail->recipient;
|
||||||
|
$this->recipient_type = $mail->recipient_type;
|
||||||
|
$this->subject = $mail->subject;
|
||||||
|
$this->sender = $mail->sender;
|
||||||
|
|
||||||
|
$this->connection = 'redis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
* Utilized by using ProcessSendEveMailJob::dispatch($mail);
|
||||||
|
* The model is passed into the dispatch function, then added to the queue
|
||||||
|
* for processing.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Declare some variables
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Get the esi configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Retrieve the token for main character to send mails from
|
||||||
|
$token = $esiHelper->GetRefreshToken($config['primary']);
|
||||||
|
|
||||||
|
//Create the ESI authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
//Attemp to send the mail
|
||||||
|
try {
|
||||||
|
$esi->setBody([
|
||||||
|
'approved_cost' => 100,
|
||||||
|
'body' => $this->body,
|
||||||
|
'recipients' => [[
|
||||||
|
'recipient_id' => $this->recipient,
|
||||||
|
'recipient_type' => $this->recipient_type,
|
||||||
|
]],
|
||||||
|
'subject' => $this->subject,
|
||||||
|
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||||
|
'character_id'=> $this->sender,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning($e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SaveSentRecord($this->sender, $this->subject, $this->body, $this->recipient, $this->recipient_type);
|
||||||
|
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The job failed to process.
|
||||||
|
*
|
||||||
|
* @param Exception $exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function failed($exception)
|
||||||
|
{
|
||||||
|
Log::critical($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {
|
||||||
|
$sentmail = new SentMail;
|
||||||
|
$sentmail->sender = $sender;
|
||||||
|
$sentmail->subject = $subject;
|
||||||
|
$sentmail->body = $body;
|
||||||
|
$sentmail->recipient = $recipient;
|
||||||
|
$sentmail->recipient_type = $recipientType;
|
||||||
|
$sentmail->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
79
app/Jobs/ProcessStructureJob.php
Normal file
79
app/Jobs/ProcessStructureJob.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use App\Library\Structures\StructureHelper;
|
||||||
|
|
||||||
|
//App Models
|
||||||
|
use App\Models\Jobs\JobProcessStructure;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
|
||||||
|
class ProcessStructureJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout in seconds
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $timeout = 3600;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of job retries
|
||||||
|
*/
|
||||||
|
public $tries = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Job Variables
|
||||||
|
*/
|
||||||
|
private $charId;
|
||||||
|
private $corpId;
|
||||||
|
private $page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(JobProcessStructure $jps)
|
||||||
|
{
|
||||||
|
$this->charId = $jps->charId;
|
||||||
|
$this->corpId = $jps->corpId;
|
||||||
|
$this->page = $jps->page;
|
||||||
|
|
||||||
|
//Set the connection for the job
|
||||||
|
$this->connection = 'redis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
* The job's task is to get all of the information for a particular structure
|
||||||
|
* and store it in the database. This task can take a few seconds because of the ESI
|
||||||
|
* calls required to store the information. We leave this type of job up to the queue
|
||||||
|
* in order to take the load off of the cron job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$sHelper = new StructureHelper($this->charId, $this->corpId);
|
||||||
|
|
||||||
|
$structures = $sHelper->GetStructuresByPage($this->page);
|
||||||
|
|
||||||
|
foreach($structures as $structure) {
|
||||||
|
$sHelper->ProcessStructure($structure);
|
||||||
|
}
|
||||||
|
|
||||||
|
//After the job is completed, delete the job
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
80
app/Jobs/ProcessWalletJournalJob.php
Normal file
80
app/Jobs/ProcessWalletJournalJob.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
//Internal Libraries
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use App\Library\Finances\Helper\FinanceHelper;
|
||||||
|
use App\Jobs\Library\JobHelper;
|
||||||
|
|
||||||
|
//App Models
|
||||||
|
use App\Models\Jobs\JobProcessWalletJournal;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
|
||||||
|
class ProcessWalletJournalJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout in seconds
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $timeout = 3600;
|
||||||
|
|
||||||
|
public $tries = 3;
|
||||||
|
|
||||||
|
private $division;
|
||||||
|
private $charId;
|
||||||
|
private $page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(JobProcessWalletJournal $pwj) {
|
||||||
|
$this->division = $pwj->division;
|
||||||
|
$this->charId = $pwj->charId;
|
||||||
|
$this->page = $pwj->page;
|
||||||
|
|
||||||
|
$this->connection = 'redis';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
* Utilized by using ProcessWalletJournalJob::dispatch()
|
||||||
|
* The model is passed into the dispatch function, then added to the queue
|
||||||
|
* for processing.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Declare the class variable we need
|
||||||
|
$finance = new FinanceHelper();
|
||||||
|
|
||||||
|
$finance->GetWalletJournalPage($this->division, $this->charId, $this->page);
|
||||||
|
|
||||||
|
//After the job is completed, delete the job
|
||||||
|
$this->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The job failed to process.
|
||||||
|
*
|
||||||
|
* @param Exception $exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function failed($exception)
|
||||||
|
{
|
||||||
|
Log::critical($exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
145
app/Library/Assets/AssetHelper.php
Normal file
145
app/Library/Assets/AssetHelper.php
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Library\Assets;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//App Library
|
||||||
|
use App\Jobs\Library\JobHelper;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
|
||||||
|
use App\Models\Jobs\JobProcessAsset;
|
||||||
|
use App\Models\Jobs\JobStatus;
|
||||||
|
use App\Models\Stock\Asset;
|
||||||
|
|
||||||
|
class AssetHelper {
|
||||||
|
|
||||||
|
private $charId;
|
||||||
|
private $corpId;
|
||||||
|
private $page;
|
||||||
|
|
||||||
|
public function __construct($char, $corp, $pg = null) {
|
||||||
|
$this->charId = $char;
|
||||||
|
$this->corpId = $corp;
|
||||||
|
$this->page = $pg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Assets By Page in order to store in the database
|
||||||
|
*/
|
||||||
|
public function GetAssetsByPage() {
|
||||||
|
//Declare the variable for the esi helper
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
//Check for the scope needed
|
||||||
|
$hasScope = $esiHelper->HaveEsiScope($this->charId, 'esi-assets.read_corporation_assets.v1');
|
||||||
|
if($hasScope == false) {
|
||||||
|
Log::critical('ESI Scope check has failed for esi-assets.read_corporation_assets.v1 for character id: ' . $this->charId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the refresh token from the database
|
||||||
|
$token = $esiHelper->GetRefreshToken($this->charId);
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$assets = $esi->page($this->page)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/assets/', [
|
||||||
|
'corporation_id' => $this->corpId,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::critical("Failed to get page of assets from ESI.");
|
||||||
|
$assets = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a new asset record in the database
|
||||||
|
*/
|
||||||
|
public function StoreNewAsset($asset) {
|
||||||
|
//See if we find any assets which already exist
|
||||||
|
$found = Asset::where([
|
||||||
|
'item_id' => $asset->item_id,
|
||||||
|
])->count();
|
||||||
|
|
||||||
|
//If nothing is found
|
||||||
|
if($found == 0) {
|
||||||
|
$item = new Asset;
|
||||||
|
if(isset($asset->is_blueprint_copy)) {
|
||||||
|
$item->is_blueprint_copy = $asset->is_blueprint_copy;
|
||||||
|
}
|
||||||
|
$item->is_singleton = $asset->is_singleton;
|
||||||
|
$item->item_id = $asset->item_id;
|
||||||
|
$item->location_flag = $asset->location_flag;
|
||||||
|
$item->location_id = $asset->location_id;
|
||||||
|
$item->location_type = $asset->location_type;
|
||||||
|
$item->quantity = $asset->quantity;
|
||||||
|
$item->type_id = $asset->type_id;
|
||||||
|
$item->save();
|
||||||
|
} else {
|
||||||
|
$this->UpdateAsset($asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purge old data, so we don't run into data issues
|
||||||
|
*/
|
||||||
|
public function PurgeStaleData() {
|
||||||
|
$date = Carbon::now()->subDay(1);
|
||||||
|
|
||||||
|
Asset::where('updated_at', '<', $date)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the liquid ozone asset
|
||||||
|
*/
|
||||||
|
public function GetAssetByType($type, $structureId) {
|
||||||
|
//See if the row is in the database table
|
||||||
|
$count = Asset::where([
|
||||||
|
'location_id' => $structureId,
|
||||||
|
'type_id' => $type,
|
||||||
|
'location_flag' => 'StructureFuel',
|
||||||
|
])->count();
|
||||||
|
//Get the row if it is in the table
|
||||||
|
$asset = Asset::where([
|
||||||
|
'location_id' => $structureId,
|
||||||
|
'type_id' => $type,
|
||||||
|
'location_flag' => 'StructureFuel',
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if($count == 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return $asset['quantity'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing asset based off the esi pull
|
||||||
|
*/
|
||||||
|
private function UpdateAsset($asset) {
|
||||||
|
|
||||||
|
Asset::where([
|
||||||
|
'item_id' => $asset->item_id,
|
||||||
|
])->update([
|
||||||
|
'is_singleton' => $asset->is_singleton,
|
||||||
|
'location_flag' => $asset->location_flag,
|
||||||
|
'location_id' => $asset->location_id,
|
||||||
|
'location_type' => $asset->location_type,
|
||||||
|
'quantity' => $asset->quantity,
|
||||||
|
'type_id' => $asset->type_id,
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -4,16 +4,14 @@ namespace App\Library\Esi;
|
|||||||
|
|
||||||
//Internal Libraries
|
//Internal Libraries
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\Esi\EsiToken;
|
use App\Models\Esi\EsiToken;
|
||||||
use App\Models\Esi\EsiScope;
|
use App\Models\Esi\EsiScope;
|
||||||
|
use App\Models\Jobs\JobSendEveMail;
|
||||||
|
|
||||||
//Jobs
|
//Jobs
|
||||||
use App\Jobs\Commands\Eve\SendEveMail;
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
//Seat Stuff
|
//Seat Stuff
|
||||||
use Seat\Eseye\Cache\NullCache;
|
use Seat\Eseye\Cache\NullCache;
|
||||||
@@ -43,16 +41,115 @@ class Esi {
|
|||||||
$check = EsiScope::where(['character_id' => $charId, 'scope' => $scope])->count();
|
$check = EsiScope::where(['character_id' => $charId, 'scope' => $scope])->count();
|
||||||
if($check == 0) {
|
if($check == 0) {
|
||||||
//Compose a mail to send to the user if the scope is not found
|
//Compose a mail to send to the user if the scope is not found
|
||||||
$subject = 'W4RP Services - Incorrect ESI Scope';
|
$mail = new JobSendEveMail;
|
||||||
$body = "Please register on https://services.w4rp.space with the scope: " . $scope;
|
$mail->sender = $config['primary'];
|
||||||
|
$mail->subject = 'W4RP Services - Incorrect ESI Scope';
|
||||||
|
$mail->body = "Please register on https://services.w4rp.space with the scope: " . $scope;
|
||||||
|
$mail->recipient = (int)$charId;
|
||||||
|
$mail->recipient_type = 'character';
|
||||||
|
|
||||||
SendEveMail::dispatch($body, (int)$charId, 'character', $subject, $config['primary'])->delay(Carbon::now()->addSeconds(5));
|
ProcessSendEveMailJob::dispatch($mail)->onQueue('mail')->delay(5);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetCharacterData($charId) {
|
||||||
|
$esi = $this->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||||
|
'character_id' => $charId,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $character;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetCorporationData($corpId) {
|
||||||
|
$esi = $this->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $corporation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetCharacterName($charId) {
|
||||||
|
$esi = $this->SetupEsiAuthentication;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||||
|
'character_id' => $charId,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $character->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function FindCharacterId($name) {
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
|
$esi = $this->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$character = $esi->setBody(array(
|
||||||
|
$name,
|
||||||
|
))->invoke('post', '/universe/ids/');
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($character->characters[0]->id)) {
|
||||||
|
return $character->characters[0]->id;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function FindCorporationId($charId) {
|
||||||
|
$esi = $this->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||||
|
'character_id' => $charId,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $character->corporation_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function FindCorporationName($charId) {
|
||||||
|
$esi = $this->SetupEsiAuthentication();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||||
|
'character_id' => $charId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
|
||||||
|
'corporation_id' => $character->corporation_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $corporation->name;
|
||||||
|
}
|
||||||
|
|
||||||
public function DecodeDate($date) {
|
public function DecodeDate($date) {
|
||||||
//Find the end of the date
|
//Find the end of the date
|
||||||
$dateEnd = strpos($date, "T");
|
$dateEnd = strpos($date, "T");
|
||||||
@@ -68,115 +165,39 @@ class Esi {
|
|||||||
return $realDate;
|
return $realDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function TokenExpired($token) {
|
|
||||||
$currentTime = Carbon::now();
|
|
||||||
|
|
||||||
//Create the carbon time for expiration time
|
|
||||||
$expires = $token->inserted_at + $token->expires_in;
|
|
||||||
$tokenExpiration = Carbon::createFromTimeStamp($expires);
|
|
||||||
|
|
||||||
if($currentTime->greaterThan($tokenExpiration->subSeconds(5))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetRefreshToken($charId) {
|
public function GetRefreshToken($charId) {
|
||||||
//Declare variables
|
//Get the refresh token from the database
|
||||||
$currentTime = Carbon::now();
|
$tokenCount = EsiToken::where([
|
||||||
$scopes = null;
|
'character_id' => $charId,
|
||||||
$i = 0;
|
])->count();
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//If the program doesn't find an ESI Token, there is nothing to return
|
//If the token is not found, then don't return it.
|
||||||
if(EsiToken::where(['character_id' => $charId])->count() == 0) {
|
if($tokenCount == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the ESI Token from the database
|
|
||||||
$token = EsiToken::where([
|
$token = EsiToken::where([
|
||||||
'character_id' => $charId,
|
'character_id' => $charId,
|
||||||
])->first();
|
])->first();
|
||||||
|
|
||||||
//Check the expiration of the token to see if the token has expired and needs to be refreshed using the refresh token
|
return $token->refresh_token;
|
||||||
$expires = $token->inserted_at + $token->expires_in;
|
|
||||||
$tokenExpiration = Carbon::createFromTimestamp($expires);
|
|
||||||
//If the access token has expired, we need to do a request for a new access token
|
|
||||||
//We give ourselves around 5 seconds leeway in order to deal with an expired token
|
|
||||||
if($currentTime->greaterThan($tokenExpiration->subSeconds(5))) {
|
|
||||||
//Get the current scopes of the token
|
|
||||||
$scopesArr = EsiScope::where([
|
|
||||||
'character_id' => $token->character_id,
|
|
||||||
])->get(['scope'])->toArray();
|
|
||||||
|
|
||||||
//Cycle through the scopes, and create the string for scopes to send with the token
|
|
||||||
foreach($scopesArr as $scp) {
|
|
||||||
$scopes .= $scp['scope'];
|
|
||||||
$i++;
|
|
||||||
if($i < sizeof($scopesArr)) {
|
|
||||||
$scopes .= '%20';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Setup the guzzle client for the request to get a new token
|
|
||||||
$client = new Client(['base_uri' => 'https://login.eveonline.com']);
|
|
||||||
$response = $client->request('POST', '/v2/oauth/token', [
|
|
||||||
'headers' => [
|
|
||||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
||||||
'Host' => 'login.eveonline.com',
|
|
||||||
'Authorization' => "Basic " . base64_encode($config['client_id'] . ":" . $config['secret']),
|
|
||||||
],
|
|
||||||
'form_params' => [
|
|
||||||
'grant_type' => 'refresh_token',
|
|
||||||
'refresh_token' => $token->refresh_token,
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
//Decode the body of the response which has the token information
|
|
||||||
$body = json_decode($response->getBody(), true);
|
|
||||||
//Update the old token, then send the new token back to the calling function
|
|
||||||
EsiToken::where([
|
|
||||||
'character_id' => $charId,
|
|
||||||
])->update([
|
|
||||||
'access_token' => $body['access_token'],
|
|
||||||
'refresh_token' => $body['refresh_token'],
|
|
||||||
'expires_in' => $body['expires_in'],
|
|
||||||
'inserted_at' => time(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$newToken = new EsiToken;
|
|
||||||
$newToken->character_id = $charId;
|
|
||||||
$newToken->access_token = $body['access_token'];
|
|
||||||
$newToken->refresh_token = $body['refresh_token'];
|
|
||||||
$newToken->inserted_at = time();
|
|
||||||
$newToken->expires_in = $body['expires_in'];
|
|
||||||
|
|
||||||
//Return the new token model
|
|
||||||
return $newToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If we had a good token which has not expired yet, return the data
|
|
||||||
return $token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetupEsiAuthentication($token = null) {
|
public function SetupEsiAuthentication($token = null) {
|
||||||
|
//Get the platform configuration
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
//Declare some variables
|
//Declare some variables
|
||||||
$authentication = null;
|
$authentication = null;
|
||||||
$esi = null;
|
$esi = null;
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
if($token == null) {
|
if($token == null) {
|
||||||
$esi = new Eseye();
|
$esi = new Eseye();
|
||||||
} else {
|
} else {
|
||||||
$tokenExpires = $token->inserted_at + $token->expires_in;
|
|
||||||
|
|
||||||
//Setup the esi authentication container
|
|
||||||
$authentication = new EsiAuthentication([
|
$authentication = new EsiAuthentication([
|
||||||
'client_id' => $config['client_id'],
|
'client_id' => $config['client_id'],
|
||||||
'secret' => $config['secret'],
|
'secret' => $config['secret'],
|
||||||
'refresh_token' => $token->refresh_token,
|
'refresh_token' => $token,
|
||||||
'access_token' => $token->access_token,
|
|
||||||
'token_expires' => $tokenExpires,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Setup the esi variable
|
//Setup the esi variable
|
||||||
|
|||||||
71
app/Library/Finances/AllianceMarketTax.php
Normal file
71
app/Library/Finances/AllianceMarketTax.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Finances\AllianceMarketJournal;
|
||||||
|
|
||||||
|
class AllianceMarketTax {
|
||||||
|
public function EntryExists($journal) {
|
||||||
|
if(AllianceMarketJournal::where(['id' => $journal['id']])->exists()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function InsertMarketTax($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(!AllianceMarketJournal::where(['id' => $journal['id']])->exists()) {
|
||||||
|
$entry = new AllianceMarketJournal;
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
390
app/Library/Finances/Helper/FinanceHelper.php
Normal file
390
app/Library/Finances/Helper/FinanceHelper.php
Normal file
@@ -0,0 +1,390 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances\Helper;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
//Job
|
||||||
|
use App\Jobs\ProcessSendEveMailJob;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Finances\AllianceMarketTax;
|
||||||
|
use App\Library\Finances\CorpMarketTax;
|
||||||
|
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 App\Library\Finances\OfficeFee;
|
||||||
|
use App\Library\Finances\PlanetProductionTax;
|
||||||
|
use App\Library\Finances\PISale;
|
||||||
|
use App\Library\Lookups\LookupHelper;
|
||||||
|
use App\Library\Finances\SovBillExpenses;
|
||||||
|
|
||||||
|
//Seat Stuff
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use Seat\Eseye\Cache\NullCache;
|
||||||
|
use Seat\Eseye\Configuration;
|
||||||
|
|
||||||
|
class FinanceHelper {
|
||||||
|
|
||||||
|
public function GetWalletJournal($division, $charId) {
|
||||||
|
//Declare new class variables
|
||||||
|
$market = new MarketTax();
|
||||||
|
$reprocessing = new ReprocessingTax();
|
||||||
|
$jb = new JumpBridgeTax();
|
||||||
|
$other = new PlayerDonation();
|
||||||
|
$industry = new StructureIndustryTax();
|
||||||
|
$office = new OfficeFee();
|
||||||
|
$esiHelper = new Esi();
|
||||||
|
$sovBillHelper = new SovBillExpenses();
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
|
||||||
|
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||||
|
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||||
|
if($hasScope == false) {
|
||||||
|
Log::critical('Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
if($token == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Reference to see if the character is in our look up table for corporations and characters
|
||||||
|
$char = $lookup->GetCharacterInfo($charId);
|
||||||
|
$corpId = $char->corporation_id;
|
||||||
|
|
||||||
|
//Create an ESI authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
//Set the version
|
||||||
|
$esi->setVersion('v4');
|
||||||
|
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
//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 null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($currentPage == 1) {
|
||||||
|
//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['ref_type'] == 'brokers_fee') {
|
||||||
|
$market->InsertMarketTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'reprocessing_tax') {
|
||||||
|
$reprocessing->InsertReprocessingTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'structure_gate_jump') {
|
||||||
|
$jb->InsertJumpBridgeTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'player_donation' ||
|
||||||
|
($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) {
|
||||||
|
$other->InsertPlayerDonation($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'industry_job_tax' && $entry['second_party_id'] == 98287666) {
|
||||||
|
$industry->InsertStructureIndustryTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'office_rental_fee' && $entry['second_party_id'] == 98287666) {
|
||||||
|
$office->InsertOfficeFee($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'infrastructure_hub_maintenance' && $entry['first_party_id'] == 98287666) {
|
||||||
|
$sovBillHelper->InsertSovBillExpense($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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetJournalPageCount($division, $charId) {
|
||||||
|
//Declare class variables
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||||
|
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||||
|
if($hasScope == false) {
|
||||||
|
Log::critical('Esi Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
if($token == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Refrence to see if the character is in our look up table for corporation and characters
|
||||||
|
$char = $lookup->GetCharacterInfo($charId);
|
||||||
|
$corpId = $char->corporation_id;
|
||||||
|
|
||||||
|
//Create the ESI authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
|
||||||
|
//Set the esi version to v4
|
||||||
|
$esi->setVersion('v4');
|
||||||
|
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
//Call the first page so we can get the header data for the number of pages
|
||||||
|
try {
|
||||||
|
$journals = $esi->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
'division' => $division,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning($e->getEsiResponse());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pages = $journals->pages;
|
||||||
|
|
||||||
|
return $pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetCorpWalletJournalPage($division, $charId, $corpId, $page = 1) {
|
||||||
|
//Declare new class variables
|
||||||
|
$corpMarket = new MarketTax();
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
|
||||||
|
//Setup the esi authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
$esi->setVersion('v4');
|
||||||
|
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
//Call the page of the wallet journal
|
||||||
|
try {
|
||||||
|
$journals = $esi->page($page)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
'division' => $division,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning($e->getEsiResponse());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Decode the wallet from json into an array
|
||||||
|
$wallets = json_decode($journals->raw, true);
|
||||||
|
|
||||||
|
//For each journal entry, attempt to store the information into the database
|
||||||
|
foreach($wallets as $wallet) {
|
||||||
|
if($wallet['amount'] > 0) {
|
||||||
|
if($wallet['ref_type'] == 'brokers_fee') {
|
||||||
|
$corpMarket->InsertCorpMarketTax($wallet, $corpId, $division);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetWalletJournalPage($division, $charId, $page = 1) {
|
||||||
|
//Declare new class variables
|
||||||
|
$market = new AllianceMarketTax;
|
||||||
|
$reprocessing = new ReprocessingTax;
|
||||||
|
$jb = new JumpBridgeTax;
|
||||||
|
$other = new PlayerDonation;
|
||||||
|
$industry = new StructureIndustryTax;
|
||||||
|
$office = new OfficeFee;
|
||||||
|
$pi = new PlanetProductionTax;
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$sovBill = new SovBillExpenses;
|
||||||
|
|
||||||
|
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||||
|
$hasScope = $esiHelper->HaveEsiScope($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||||
|
if($hasScope == false) {
|
||||||
|
Log::critical('Esi Scope check failed for esi-wallet.read_corporation_wallets.v1 for character id: ' . $charId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$token = $esiHelper->GetRefreshToken($charId);
|
||||||
|
if($token == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Reference to see if the character is in our look up table for corporations and characters
|
||||||
|
$char = $lookup->GetCharacterInfo($charId);
|
||||||
|
$corpId = $char->corporation_id;
|
||||||
|
|
||||||
|
//Create an ESI authentication container
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($token);
|
||||||
|
$esi->setVersion('v4');
|
||||||
|
|
||||||
|
//Set caching to null
|
||||||
|
$configuration = Configuration::getInstance();
|
||||||
|
$configuration->cache = NullCache::class;
|
||||||
|
|
||||||
|
//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($page)
|
||||||
|
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
||||||
|
'corporation_id' => $corpId,
|
||||||
|
'division' => $division,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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['ref_type'] == 'brokers_fee') {
|
||||||
|
$market->InsertMarketTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'reprocessing_tax') {
|
||||||
|
$reprocessing->InsertReprocessingTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'structure_gate_jump') {
|
||||||
|
$jb->InsertJumpBridgeTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'player_donation' ||
|
||||||
|
($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) {
|
||||||
|
$other->InsertPlayerDonation($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'industry_job_tax' && $entry['second_party_id'] == 98287666) {
|
||||||
|
$industry->InsertStructureIndustryTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'office_rental_fee' && $entry['second_party_id'] == 98287666) {
|
||||||
|
$office->InsertOfficeFee($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'planetary_export_tax' || $entry['ref_type'] == 'planetary_import_tax') {
|
||||||
|
$pi->InsertPlanetProductionTax($entry, $corpId, $division);
|
||||||
|
} else if($entry['ref_type'] == 'infrastructure_hub_maintenance' && $entry['first_party_id'] == 98287666) {
|
||||||
|
$sovBill->InsertSovBillExpense($entry, $corpId, $division);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetPIMaterialsArray() {
|
||||||
|
//Setup array for PI items
|
||||||
|
$pi_items = [
|
||||||
|
//R0 Materials
|
||||||
|
'2073',
|
||||||
|
'2667',
|
||||||
|
'2268',
|
||||||
|
'2270',
|
||||||
|
'2272',
|
||||||
|
'2286',
|
||||||
|
'2287',
|
||||||
|
'2288',
|
||||||
|
'2305',
|
||||||
|
'2306',
|
||||||
|
'2307',
|
||||||
|
'2308',
|
||||||
|
'2309',
|
||||||
|
'2310',
|
||||||
|
'2311',
|
||||||
|
//P1 Materials
|
||||||
|
'2389',
|
||||||
|
'2390',
|
||||||
|
'2392',
|
||||||
|
'2393',
|
||||||
|
'2395',
|
||||||
|
'2396',
|
||||||
|
'2397',
|
||||||
|
'2398',
|
||||||
|
'2399',
|
||||||
|
'2400',
|
||||||
|
'2401',
|
||||||
|
'3645',
|
||||||
|
'3683',
|
||||||
|
'3779',
|
||||||
|
'9828',
|
||||||
|
//P2 Materials
|
||||||
|
'44',
|
||||||
|
'2312',
|
||||||
|
'2317',
|
||||||
|
'2319',
|
||||||
|
'2321',
|
||||||
|
'2327',
|
||||||
|
'2328',
|
||||||
|
'2329',
|
||||||
|
'2463',
|
||||||
|
'3689',
|
||||||
|
'3691',
|
||||||
|
'3693',
|
||||||
|
'3695',
|
||||||
|
'3697',
|
||||||
|
'3725',
|
||||||
|
'3775',
|
||||||
|
'3828',
|
||||||
|
'9830',
|
||||||
|
'9832',
|
||||||
|
'9836',
|
||||||
|
'9838',
|
||||||
|
'9840',
|
||||||
|
'9842',
|
||||||
|
'15317',
|
||||||
|
//P3 Materials
|
||||||
|
'2344',
|
||||||
|
'2345',
|
||||||
|
'2346',
|
||||||
|
'2348',
|
||||||
|
'2349',
|
||||||
|
'2351',
|
||||||
|
'2352',
|
||||||
|
'2354',
|
||||||
|
'2358',
|
||||||
|
'2360',
|
||||||
|
'2361',
|
||||||
|
'2366',
|
||||||
|
'2367',
|
||||||
|
'9834',
|
||||||
|
'9846',
|
||||||
|
'9848',
|
||||||
|
'12836',
|
||||||
|
'17136',
|
||||||
|
'17392',
|
||||||
|
'17898',
|
||||||
|
'28974',
|
||||||
|
//P4 Materials
|
||||||
|
'2867',
|
||||||
|
'2868',
|
||||||
|
'2869',
|
||||||
|
'2870',
|
||||||
|
'2871',
|
||||||
|
'2872',
|
||||||
|
'2875',
|
||||||
|
'2876',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $pi_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
109
app/Library/Finances/JumpBridgeTax.php
Normal file
109
app/Library/Finances/JumpBridgeTax.php
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use DB;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Finances\JumpBridgeJournal;
|
||||||
|
|
||||||
|
class JumpBridgeTax {
|
||||||
|
private $date;
|
||||||
|
private $days;
|
||||||
|
|
||||||
|
public function __construct($days = null) {
|
||||||
|
if($days === null) {
|
||||||
|
$this->date = Carbon::now();
|
||||||
|
$this->days = 0;
|
||||||
|
} else {
|
||||||
|
$this->date = Carbon::now()->subDays($days);
|
||||||
|
$this->days = $days;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to insert journal entries into the database
|
||||||
|
*/
|
||||||
|
public function InsertJumpBridgeTax($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(!JumpBridgeJournal::where(['id' => $journal['id']])->exists()) {
|
||||||
|
$entry = new JumpBridgeJournal;
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the overall usage for statistics
|
||||||
|
*/
|
||||||
|
public function OverallTax() {
|
||||||
|
|
||||||
|
//Get the total usage
|
||||||
|
$usage = JumpBridgeJournal::select('amount')
|
||||||
|
->whereTime('date', '>', $this->date)
|
||||||
|
->sum('amount');
|
||||||
|
|
||||||
|
//Return the usage
|
||||||
|
return $usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a specific briddge usage statistics for overall usage
|
||||||
|
*/
|
||||||
|
public function JBOverallUsage($structure) {
|
||||||
|
|
||||||
|
$usage = DB::table('jump_bridge_journal')
|
||||||
|
->select('amount')
|
||||||
|
->where('context_id', $structure)
|
||||||
|
->sum('amount');
|
||||||
|
|
||||||
|
return $usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
64
app/Library/Finances/OfficeFee.php
Normal file
64
app/Library/Finances/OfficeFee.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
58
app/Library/Finances/PISale.php
Normal file
58
app/Library/Finances/PISale.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Finances\PISaleJournal;
|
||||||
|
|
||||||
|
class PISale {
|
||||||
|
|
||||||
|
public function InsertPISale($journal, $corpId) {
|
||||||
|
//Create the ESI Helper class
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
|
||||||
|
//Insert the PI Sale into the database
|
||||||
|
if(!PISaleJournal::where(['journal_ref_id' => $journal['journal_ref_id']])->exists()) {
|
||||||
|
$entry = new PISaleJournal;
|
||||||
|
if(isset($journal['client_id'])) {
|
||||||
|
$entry->client_id = $journal['client_id'];
|
||||||
|
}
|
||||||
|
if(isset($journal['date'])) {
|
||||||
|
$entry->date = $esiHelper->DecodeDate($journal['date']);
|
||||||
|
}
|
||||||
|
if(isset($journal['is_buy'])) {
|
||||||
|
$entry->is_buy = $journal['is_buy'];
|
||||||
|
}
|
||||||
|
if(isset($journal['journal_ref_id'])) {
|
||||||
|
$entry->journal_ref_id = $journal['journal_ref_id'];
|
||||||
|
}
|
||||||
|
if(isset($journal['location_id'])) {
|
||||||
|
$entry->location_id = $journal['location_id'];
|
||||||
|
}
|
||||||
|
if(isset($journal['quantity'])) {
|
||||||
|
$entry->quantity = $journal['quantity'];
|
||||||
|
}
|
||||||
|
if(isset($journal['transaction_id'])) {
|
||||||
|
$entry->transaction_id = $journal['transaction_id'];
|
||||||
|
}
|
||||||
|
if(isset($journal['type_id'])) {
|
||||||
|
$entry->type_id = $journal['type_id'];
|
||||||
|
}
|
||||||
|
if(isset($journal['unit_price'])) {
|
||||||
|
$entry->unit_price = $journal['unit_price'];
|
||||||
|
}
|
||||||
|
$entry->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
64
app/Library/Finances/PlanetProductionTax.php
Normal file
64
app/Library/Finances/PlanetProductionTax.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* W4RP Services
|
||||||
|
* GNU Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Library\Finances;
|
||||||
|
|
||||||
|
//Library
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Finances\PlanetProductionTaxJournal;
|
||||||
|
|
||||||
|
class PlanetProductionTax {
|
||||||
|
|
||||||
|
public function InsertPlanetProductionTax($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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user