structure market tax
This commit is contained in:
+48
-5
@@ -39,11 +39,9 @@ class Esi {
|
||||
$config = config('esi');
|
||||
|
||||
//Check for an esi scope
|
||||
$checks = DB::table('EsiScopes')->where('character_id', $charId)->get();
|
||||
foreach($checks as $check) {
|
||||
if($check->scope === $scope) {
|
||||
return true;
|
||||
}
|
||||
$check = EsiScope::where(['character_id' => $charId, 'scope' => $scope])->count();
|
||||
if($check == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$mail = new EveMail;
|
||||
@@ -155,6 +153,51 @@ class Esi {
|
||||
//Return the combined date in the correct format
|
||||
return $realDate;
|
||||
}
|
||||
|
||||
public function GetToken($charId, $scope) {
|
||||
//Get the refresh token from the database
|
||||
$tokenCount = EsiToken::where([
|
||||
'character_id' => $charId,
|
||||
])->count();
|
||||
|
||||
if($tokenCount == 0) {
|
||||
$config = config('esi');
|
||||
|
||||
$mail = new EveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = 'W4RP Services - No Token Found';
|
||||
$mail->body = "Please register at https://services.w4rp.space with the scope: " . $scope;
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
SendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$token = EsiToken::where([
|
||||
'character_id' => $charId,
|
||||
])->first();
|
||||
|
||||
$scope = EsiScope::where([
|
||||
'character_id' => $charId,
|
||||
'scope' => $scope,
|
||||
])->count();
|
||||
|
||||
if($scope == 0) {
|
||||
$mail = new EveMail;
|
||||
$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';
|
||||
|
||||
SendEveMailJob::dispatch($mail)->onQueue('mail')->delay(Carbon::now()->addSeconds(5));
|
||||
|
||||
return null;
|
||||
} else {
|
||||
return $token->refresh_token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* W4RP Services
|
||||
* GNU Public License
|
||||
*/
|
||||
|
||||
namespace App\Library\Finances;
|
||||
|
||||
use DB;
|
||||
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
use App\Models\Finances\CorpMarketJournal;
|
||||
|
||||
class CorpMarketTax {
|
||||
public function InsertCorpMarketTax($journal, $corpId, $division) {
|
||||
//Create the ESI Helper class
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Check to see if we can find the entry in the database already.
|
||||
//If we don't then add it to the database
|
||||
if(!CorpMarketJournal::where(['id' => $journal['id']])->exists()) {
|
||||
$entry = new CorpMarketJournal;
|
||||
$entry->id = $journal['id'];
|
||||
$entry->corporation_id = $corpId;
|
||||
$entry->division = $division;
|
||||
if(isset($journal['amount'])) {
|
||||
$entry->amount = $journal['amount'];
|
||||
}
|
||||
if(isset($journal['balance'])) {
|
||||
$entry->balance = $journal['balance'];
|
||||
}
|
||||
if(isset($journal['context_id'])) {
|
||||
$entry->context_id = $journal['context_id'];
|
||||
}
|
||||
if(isset($journal['context_id_type'])) {
|
||||
$entry->context_id_type = $journal['context_id_type'];
|
||||
}
|
||||
$entry->date = $esiHelper->DecodeDate($journal['date']);
|
||||
$entry->description = $journal['description'];
|
||||
if(isset($journal['first_party_id'])) {
|
||||
$entry->first_party_id = $journal['first_party_id'];
|
||||
}
|
||||
if(isset($journal['reason'])) {
|
||||
$entry->reason = $journal['reason'];
|
||||
}
|
||||
$entry->ref_type = $journal['ref_type'];
|
||||
if(isset($journal['second_party_id'])) {
|
||||
$entry->second_party_id = $journal['second_party_id'];
|
||||
}
|
||||
if(isset($journal['tax'])) {
|
||||
$entry->tax = $journal['tax'];
|
||||
}
|
||||
if(isset($journal['tax_receiver_id'])) {
|
||||
$entry->tax_receiver_id = $journal['tax_receiver_id'];
|
||||
}
|
||||
$entry->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -21,6 +21,7 @@ use App\Models\Mail\EveMail;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use App\Library\Finances\CorpMarketJournal;
|
||||
use App\Library\Finances\MarketTax;
|
||||
use App\Library\Finances\PlayerDonation;
|
||||
use App\Library\Finances\ReprocessingTax;
|
||||
@@ -39,20 +40,16 @@ use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
class FinanceHelper {
|
||||
|
||||
public function GetWalletTransaction($division, $charId) {
|
||||
//Declare the lookup class helper
|
||||
//Declare the class helpers
|
||||
$lookups = new LookupHelper;
|
||||
$esiHelper = new Esi;
|
||||
|
||||
//Setup array for PI items
|
||||
$pi_items = $this->GetPIMaterialsArray();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
|
||||
//If the token is not found, send the user an eve mail, and just exit out of the function
|
||||
if($this->TokenNotFound($token, $scope, $charId)) {
|
||||
//Log::critical('Token not found. Character Id: ' . $charId);
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -64,7 +61,7 @@ class FinanceHelper {
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
@@ -106,18 +103,13 @@ class FinanceHelper {
|
||||
$office = new OfficeFee();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Declare the lookup class helper
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//If the token is not found, send the user an eve mail, and just exit out of the function
|
||||
if($this->TokenNotFound($token, $scope, $charId)) {
|
||||
//Log::critical('Token not found.' . 'Character Id: ' . $charId);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Reference to see if the character is in our look up table for corporations and characters
|
||||
$corpId = $lookups->LookupCharacter($charId);
|
||||
@@ -127,7 +119,7 @@ class FinanceHelper {
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
@@ -189,12 +181,9 @@ class FinanceHelper {
|
||||
//Declare class variables
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
|
||||
if($this->TokenNotFound($token, $scope, $charId)) {
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -206,7 +195,7 @@ class FinanceHelper {
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class variable
|
||||
@@ -229,6 +218,52 @@ class FinanceHelper {
|
||||
return $pages;
|
||||
}
|
||||
|
||||
public function GetCorpWalletJournalPage($division, $charId, $corpId, $page = 1) {
|
||||
//Declare new class variables
|
||||
$corpMarket = new MarketTax();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenIfno($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
|
||||
//Create an ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
$esi = new Eseye($authentication);
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//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 MarketTax();
|
||||
@@ -240,9 +275,10 @@ class FinanceHelper {
|
||||
$pi = new PlanetProductionTax();
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
$token = $esiHelper->GetToken($charId, 'esi-wallet.read_corporation_wallets.v1');
|
||||
if($token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Declare the lookup class helper
|
||||
$lookups = new LookupHelper;
|
||||
@@ -255,7 +291,7 @@ class FinanceHelper {
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
'refresh_token' => $token,
|
||||
]);
|
||||
|
||||
//Create the esi class varialble
|
||||
@@ -301,42 +337,6 @@ class FinanceHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private function TokenInfo($charId) {
|
||||
//Get the ESI refresh token for the corporation to add a new wallet jouranls into the database
|
||||
//send the token and scope back to the calling function
|
||||
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||
$scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']);
|
||||
|
||||
$data = [
|
||||
'token' => $token,
|
||||
'scope' => $scope,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function TokenNotFound($token, $scope, $charId) {
|
||||
//Get the esi config
|
||||
$config = config('esi');
|
||||
|
||||
|
||||
if(!isset($token[0]->refresh_token) || !isset($scope[0]->scope)) {
|
||||
//Register a mail to be dispatched as a job
|
||||
$mail = new EveMail;
|
||||
$mail->sender = $config['primary'];
|
||||
$mail->subject = 'W4RP Services ESI API';
|
||||
$mail->body = 'You need to register an ESI API on the services site for esi-wallet.read_corporation_wallet.v1<br>This is also labeled Corporation Wallets';
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
|
||||
SendEveMailJob::dispatch($mail)->onQueue('mail');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function GetPIMaterialsArray() {
|
||||
//Setup array for PI items
|
||||
$pi_items = [
|
||||
|
||||
@@ -31,6 +31,17 @@ class TaxesHelper {
|
||||
$this->end = $en;
|
||||
}
|
||||
|
||||
public function GetStructureMarketGross($start, $end, $corpId) {
|
||||
$revenue = 0.00;
|
||||
|
||||
$revenu = CorpMarketJournal::where([
|
||||
'second_party_id' => $corpId,
|
||||
])->whereBetween('date', [$start, $end])
|
||||
->sum('amount');
|
||||
|
||||
return $revenue;
|
||||
}
|
||||
|
||||
public function GetJumpGateGross($start, $end) {
|
||||
$revenue = 0.00;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user