finance helper

This commit is contained in:
2019-04-19 22:30:16 -05:00
parent 9820bb8870
commit 675ace12d1

View File

@@ -10,7 +10,6 @@ namespace App\Library\Finances\Helper;
use DB;
use App\Jobs\SendEveMail;
use App\Models\User\UserToCorporation;
use App\Models\Esi\EsiToken;
use App\Models\Esi\EsiScope;
use App\Models\Mail\EveMail;
@@ -24,6 +23,7 @@ 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 Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
@@ -35,6 +35,8 @@ class FinanceHelper {
//Get the ESI refresh token for the corporation to add new wallet journals into the database
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
$scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']);
//Declare the Lookup Helper Class
$lookups = new LookupHelper;
//Setup array for PI items
$pi_items = [
@@ -58,7 +60,7 @@ class FinanceHelper {
}
//Reference to see if the character is in our look up table for corporations and characters
$corpId = $this->GetCharCorp($charId);
$corpId = $lookup->LookupCharacter($charId);
//Create an ESI authentication container
$config = config('esi');
@@ -136,49 +138,6 @@ class FinanceHelper {
} while ($currentPage < $totalPages);
}
/**
* Returns the corporation a character is in if found in the lookup table, otherwise,
* adds the character to the lookup table, and returns the corporation id
*
* @param charId
* @return corpId
*/
private function GetCharCorp($charId) {
//Check for the character the user_to_corporation table
$found = UserToCorporation::where('character_id', $charId)->get(['corporation_id']);
//If we don't find the character in the table, then let's retrieve the information from ESI
if(!isset($found[0]->corporation_id)) {
//Get the configuration for ESI from the environmental variables
$config = config('esi');
//Setup a new ESI container
$esi = new Eseye();
//Try to get the character information, then the corporation information
try {
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character->corporation_id,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
return $e->getEsiResponse();
}
//Save all of the data to the database
$char = new UserToCorporation;
$char->character_id = $charId;
$char->character_name = $character->name;
$char->corporation_id = $character->corporation_id;
$char->corporation_name = $corporation->name;
$char->save();
//Return the corporation_id which is what the calling function is looking for
return $character->corporation_id;
} else {
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
return $found[0]->corporation_id;
}
}
public function GetHoldingWalletJournal($division) {
//Get the ESI refresh token for the corporation to add new wallet journals into the database
$token = EsiToken::where(['character_id' => 93738489])->get(['refresh_token']);