finances library
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\CreateEsiScopes;
|
||||
use App\Models\EsiScope;
|
||||
|
||||
use DB;
|
||||
|
||||
|
||||
+112
-30
@@ -10,50 +10,132 @@
|
||||
use Illuminate\Http\Request;
|
||||
use Session;
|
||||
use DB;
|
||||
|
||||
use App\Models\EsiScope;
|
||||
use App\Models\EsiToken;
|
||||
use App\Models\CorpJournal;
|
||||
|
||||
use App\Library\Esi;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use App\User;
|
||||
|
||||
class Finances {
|
||||
|
||||
protected $refreshToken;
|
||||
protected $expires;
|
||||
|
||||
private $esi;
|
||||
|
||||
public function __construct($charId = null) {
|
||||
public function PutWalletJournal($journal, $corpId, $division) {
|
||||
$check = DB::table('CorpJournal')->where('id', $journal['id'])->get();
|
||||
//if we don't find the journal entry, add the journal entry to the database
|
||||
if($check == null) {
|
||||
$entry = new CorpJournal;
|
||||
$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 = $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();
|
||||
}
|
||||
|
||||
$user = DB::table('users')->where('name', 'Minerva Arbosa')->first();
|
||||
|
||||
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
|
||||
'client_id' => env('ESI_CLIENT_ID'),
|
||||
'secret' => env('ESI_SECRET_KEY'),
|
||||
'refresh_token' => $user->refresh_token,
|
||||
}
|
||||
|
||||
public function CalculateMonthlyTaxes($corpId, $month, $overallTax) {
|
||||
//Convert the current time to a time / date
|
||||
$currentTime = Carbon::now();
|
||||
$monthWanted = $month;
|
||||
$untaxed = 0.00;
|
||||
//Get the journal entries from the database
|
||||
$entries = DB::table('CorpJournals')->where(['corporation_id' => $corpId, 'created_at' => $monthWanted, 'ref_type' => 46])->get();
|
||||
foreach($entries as $entry) {
|
||||
$untaxed += $entry->tax;
|
||||
}
|
||||
//The alliance will get 2.5 pts of the tax. We need to calculate
|
||||
//the correct percentage, and return the value
|
||||
$taxRatio = $overallTax / 2.5;
|
||||
$taxed = $untaxed / $taxRatio;
|
||||
|
||||
return $taxed;
|
||||
}
|
||||
|
||||
public function SendMail($charId) {
|
||||
//
|
||||
}
|
||||
|
||||
public function GetWalletJournal($division, $charId) {
|
||||
//Get the ESI token for the corporation to add new wallet journals into the database
|
||||
$token = DB::table('EsiTokens')->where('character_id', $charId)->get();
|
||||
//Disable all caching by setting the NullCache as the preferred cache handler.
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
$configuration->logfile_location = '/var/www/w4rpservices/storage/logs/eseye';
|
||||
//Create the ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['esi']['client_id'],
|
||||
'secret' => $config['esi']['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Create the esi class variable
|
||||
$esi = new Eseye($authentication);
|
||||
//Try an esi call to get public data to get the character information for corp id.
|
||||
try {
|
||||
$character = $esi->invoke('get', '/characters/{character_id}/', [
|
||||
'character_id' => $charId,
|
||||
]);
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
$this->esi = new \Seat\Eseye\Eseye($authentication);
|
||||
}
|
||||
|
||||
public function GetMarketGroups() {
|
||||
$instance = new \Seat\Eseye\Eseye();
|
||||
|
||||
$marketGroups = $instance->invoke('get', '/markets/groups/');
|
||||
}
|
||||
|
||||
public function GetMasterWalletJournal() {
|
||||
$journals = $this->esi->invoke('get', '/corporations/98287666/wallets/1/journal/');
|
||||
//Try the ESI call to get the wallet journal
|
||||
try {
|
||||
$journals = $esi->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
|
||||
'corporation_id' => $character->corporation_id,
|
||||
'division' => $division,
|
||||
]);
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
//Decode the journal from json into an array for future processing
|
||||
$journals = json_decode($journal->raw, true);
|
||||
//foreach($journals as $entry) {
|
||||
// DB::table('HoldingCorpFinancesJournal');
|
||||
//}
|
||||
|
||||
return $journals;
|
||||
|
||||
//For each journal array, attempt to store in the database
|
||||
foreach($journals as $entry) {
|
||||
$this->PutWalletJournal($entry, $corpId, $divison);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
+4
-16
@@ -66,9 +66,10 @@ class Fleet {
|
||||
//Get the FC's refresh token from the table
|
||||
$token = DB::table('EsiTokens')->where('character_id', $fc->character_id)->first();
|
||||
//Create the esi authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
|
||||
'client_id' => env('ESI_CLIENT_ID'),
|
||||
'secret' => env('ESI_SECRET_KEY'),
|
||||
'client_id' => $config['esi']['client_id'],
|
||||
'secret' => $config['esi']['secret'],
|
||||
'refresh_token' => $token->refresh_token,
|
||||
]);
|
||||
//Create the esi class
|
||||
@@ -111,20 +112,7 @@ class Fleet {
|
||||
'fleet_id' => $fleetId,
|
||||
]);
|
||||
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
|
||||
// The HTTP Response code and message can be retreived
|
||||
// from the exception...
|
||||
print $e->getCode() . PHP_EOL;
|
||||
print $e->getMessage() . PHP_EOL;
|
||||
|
||||
// .. or from the EsiResponse available from the Exception
|
||||
print $e->getEsiResponse()->getErrorCode() . PHP_EOL;
|
||||
print $e->getEsiResponse()->error() . PHP_EOL;
|
||||
|
||||
// You can also access the *actual* response we got from
|
||||
// ESI as a normal array.
|
||||
print_r($e->getEsiResponse());
|
||||
dd($e->getEsiResponse());
|
||||
return $e->getEsiResponse;
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CorpJournal extends Model
|
||||
{
|
||||
/**
|
||||
* Table Name
|
||||
*/
|
||||
protected $table = 'CorpJournal';
|
||||
|
||||
/**
|
||||
* Timestamps
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'corporation_id',
|
||||
'division',
|
||||
'amount',
|
||||
'balance',
|
||||
'context_id',
|
||||
'context_id_type',
|
||||
'date',
|
||||
'description',
|
||||
'first_party_id',
|
||||
'reason',
|
||||
'ref_type',
|
||||
'second_party_id',
|
||||
'tax',
|
||||
'tax_receiver_id',
|
||||
];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCorpJournal extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!Schema::hasTable('CorpJournals')) {
|
||||
Schema::create('CorpJournals', function(Blueprint $table) {
|
||||
$table->integer('id')->unique();
|
||||
$table->integer('corporation_id');
|
||||
$table->integer('division')->default(0);
|
||||
$table->decimal('amount', 20, 2);
|
||||
$table->decimal('balance', 20, 2);
|
||||
$table->integer('context_id');
|
||||
$table->string('context_id_type');
|
||||
$table->dateTime('date');
|
||||
$table->string('description');
|
||||
$table->integer('first_party_id')->nullable();
|
||||
$table->string('reason')->nullabe();
|
||||
$table->string('ref_type');
|
||||
$table->integer('second_party_id')->nullable();
|
||||
$table->decimal('tax', 20, 2)->default(0.00);
|
||||
$table->integer('tax_receiver_id')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('CorpWalletJournals')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user