corp rental moons
This commit is contained in:
@@ -17,8 +17,6 @@ use App\Library\Lookups\LookupHelper;
|
|||||||
//App Models
|
//App Models
|
||||||
use App\Models\Esi\EsiToken;
|
use App\Models\Esi\EsiToken;
|
||||||
use App\Models\Esi\EsiScope;
|
use App\Models\Esi\EsiScope;
|
||||||
use App\Models\Structure\Structure;
|
|
||||||
use App\Models\Structure\Service;
|
|
||||||
use App\Models\Lookups\ItemLookup;
|
use App\Models\Lookups\ItemLookup;
|
||||||
use App\Models\MoonRent\MoonRental;
|
use App\Models\MoonRent\MoonRental;
|
||||||
use App\Models\Moon\Moon;
|
use App\Models\Moon\Moon;
|
||||||
@@ -31,10 +29,6 @@ class MoonLedgerController extends Controller
|
|||||||
$this->middleware('permission:corp.lead');
|
$this->middleware('permission:corp.lead');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayRentalMoon() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function displayMoonLedger() {
|
public function displayMoonLedger() {
|
||||||
//Declare variables
|
//Declare variables
|
||||||
$structures = array();
|
$structures = array();
|
||||||
@@ -135,35 +129,41 @@ class MoonLedgerController extends Controller
|
|||||||
->with('structures', $structures);
|
->with('structures', $structures);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displaySelection() {
|
public function displayRentalMoonLedger() {
|
||||||
//Declare variables
|
//Declare variables
|
||||||
$structures = array();
|
$structures = array();
|
||||||
|
$miningLedgers = array();
|
||||||
|
$tempMiningLedger = array();
|
||||||
|
$tempMining = array();
|
||||||
$esiHelper = new Esi;
|
$esiHelper = new Esi;
|
||||||
$lookup = new LookupHelper;
|
$lookup = new LookupHelper;
|
||||||
$response = null;
|
$response = null;
|
||||||
$structureInfo = null;
|
$structureInfo = null;
|
||||||
|
|
||||||
|
//Get the configuration for the main site
|
||||||
|
$config = config('esi');
|
||||||
|
|
||||||
//Check for the esi scope
|
//Check for the esi scope
|
||||||
if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-industry.read_corporation_mining.v1')) {
|
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
||||||
return redirect('/dashboard')->with('error', 'Need to add scopes for esi-industry.read_corporation_mining.v1');
|
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.');
|
||||||
} else {
|
} else {
|
||||||
if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-universe.read_structures.v1')) {
|
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-universe.read_structures.v1')) {
|
||||||
return redirect('/dashboard')->with('error', 'Need to add scope for 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
|
//Get the refresh token if scope checks have passed
|
||||||
$refreshToken = $esiHelper->GetRefreshToken(auth()->user()->getId());
|
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
||||||
|
|
||||||
//Setup the esi container
|
//Setup the esi container
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||||
|
|
||||||
//Get the character data from the lookup table if possible or esi
|
//Get the character data from the lookup table if possible or esi
|
||||||
$character = $lookup->GetCharacterInfo(auth()->user()->getId());
|
$character = $lookup->GetCharacterInfo($config['primary']);
|
||||||
|
|
||||||
//Try to get the mining observers for the corporation from esi
|
//Try to get the mining observers for the corporation from esi
|
||||||
try {
|
try {
|
||||||
$response = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
$responses = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/', [
|
||||||
'corporation_id' => $character->corporation_id,
|
'corporation_id' => $character->corporation_id,
|
||||||
]);
|
]);
|
||||||
} catch(RequestFailedException $e) {
|
} catch(RequestFailedException $e) {
|
||||||
@@ -171,88 +171,64 @@ class MoonLedgerController extends Controller
|
|||||||
return redirect('/dashboard')->with('error', 'Failed to get mining structures.');
|
return redirect('/dashboard')->with('error', 'Failed to get mining structures.');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($response as $resp) {
|
//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 to get the structure information from esi
|
||||||
try {
|
try {
|
||||||
$structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
$structureInfo = $esi->invoke('get', '/universe/structures/{structure_id}/', [
|
||||||
'structure_id' => $resp->observer_id,
|
'structure_id' => $response->observer_id,
|
||||||
]);
|
]);
|
||||||
} catch(RequestFailedException $e) {
|
} catch(RequestFailedException $e) {
|
||||||
//If an exception has occurred, then do nothing
|
//If an exception has occurred, then do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
$structures[$resp->observer_id] = $structureInfo->name;
|
//We don't really care about the key, but it is better than just 0 through whatever number
|
||||||
|
$structures[$response->observer_id] = $structureInfo->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('moons.ledger.displayselect')->with('structures', $structures);
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
public function displayLedger(Request $request) {
|
if($ledgers != null) {
|
||||||
//Declare variables
|
foreach($ledgers as $ledger) {
|
||||||
$esiHelper = new Esi;
|
//Declare a variable that will need to be cleared each time the foreach processes
|
||||||
$lookup = new LookupHelper;
|
$tempArray = array();
|
||||||
$tempMining = array();
|
|
||||||
$mining = array();
|
|
||||||
$temp = array();
|
|
||||||
$ledgerEntries = array();
|
|
||||||
|
|
||||||
//Check for the esi scope
|
//Get the character information from the character id
|
||||||
if(!$esiHelper->HaveEsiScope(auth()->user()->getId(), 'esi-industry.read_corporation_mining.v1')) {
|
$charInfo = $lookup->GetCharacterInfo($ledger->character_id);
|
||||||
//If the scope check fails, return with a redirect and error message
|
//Get the corp ticker
|
||||||
return redirect('/dashboar')->with('error', 'Could not find the scope for esi-industry.read_corporation_mining.v1');
|
$corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id);
|
||||||
}
|
//Get the ore name from the type id
|
||||||
|
$ore = $lookup->ItemIdToName($ledger->type_id);
|
||||||
|
|
||||||
$refreshToken = $esiHelper->GetRefreshToken(auth()->user()->getId());
|
//We only want to push the mining ledger entry into the array if it matches
|
||||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
//the date within 30 days
|
||||||
|
$sortTime = Carbon::now()->subDays(30);
|
||||||
//Get the character data from the lookup table if possible or esi
|
$current = Carbon::createFromFormat('Y-m-d', $ledger->last_updated);
|
||||||
$character = $lookup->GetCharacterInfo(auth()->user()->getId());
|
if($current->greaterThanOrEqualTo($sortTime)) {
|
||||||
|
array_push($miningLedgers, [
|
||||||
//Try to get the mining ledger for the corporation observer
|
'structure' => $value,
|
||||||
try {
|
'character' => $charInfo->name,
|
||||||
$ledgers = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
'corpTicker' => $corpInfo->ticker,
|
||||||
'corporation_id' => $character->corporation_id,
|
'ore' => $ore,
|
||||||
'observer_id' => $request->structure,
|
'quantity' => $ledger->quantity,
|
||||||
]);
|
'updated' => $ledger->last_updated,
|
||||||
} catch(RequestFailedException $e) {
|
]);
|
||||||
return redirect('/dashboard')->with('error', 'Failed to get the mining ledger.');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Cycle through each ledger entry and create a new array
|
|
||||||
foreach($ledgers as $ledger) {
|
|
||||||
//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);
|
|
||||||
|
|
||||||
//Push the data onto the mining arary
|
|
||||||
array_push($tempMining, [
|
|
||||||
'character' => $charInfo->name,
|
|
||||||
'corpTicker' => $corpInfo->ticker,
|
|
||||||
'ore' => $ore,
|
|
||||||
'quantity' => $ledger->quantity,
|
|
||||||
'updated' => $ledger->last_updated,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Sort through the array and reverse it so the last day is shown first
|
|
||||||
$tempMining = array_reverse($tempMining, true);
|
|
||||||
|
|
||||||
//Create the current time based on the current time and then subtract 30 days
|
|
||||||
$sortTime = Carbon::now()->subDays(30);
|
|
||||||
|
|
||||||
//Sort through the array and discard anything that is further than 30 days out.
|
|
||||||
foreach($tempMining as $entry) {
|
|
||||||
//Create the current time stamp from the current legder before sorting
|
|
||||||
$current = Carbon::createFromFormat('Y-m-d', $entry['updated']);
|
|
||||||
if($current->greaterThanOrEqualTo($sortTime)) {
|
|
||||||
array_push($mining, $entry);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return the view with the data
|
return view('moons.ledger.corpmoons')->with('miningLedgers', $miningLedgers)
|
||||||
return view('moons.ledger.displayledger')->with('mining', $mining);
|
->with('structures', $structures);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Models\User\UserRole;
|
|||||||
use App\Models\User\UserPermission;
|
use App\Models\User\UserPermission;
|
||||||
use App\Models\Esi\EsiScope;
|
use App\Models\Esi\EsiScope;
|
||||||
use App\Models\Esi\EsiToken;
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\MoonRent\MoonRental;
|
||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
@@ -117,4 +118,16 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
return $role->role;
|
return $role->role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isMoonRenter() {
|
||||||
|
$moonRental = MoonRent::where([
|
||||||
|
'Contact' => $this->character_id,
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
if($moonRental != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,10 @@
|
|||||||
<a class="dropdown-item" href="/moons/display/form/worth">Moon Worth</a>
|
<a class="dropdown-item" href="/moons/display/form/worth">Moon Worth</a>
|
||||||
<a class="dropdown-item" href="/moons/display/request">Moon Reservation</a>
|
<a class="dropdown-item" href="/moons/display/request">Moon Reservation</a>
|
||||||
@if(auth()->user()->hasPermission('corp.lead') && auth()->user()->hasEsiScope('esi-industry.read_corporation_mining.v1'))
|
@if(auth()->user()->hasPermission('corp.lead') && auth()->user()->hasEsiScope('esi-industry.read_corporation_mining.v1'))
|
||||||
<a class="dropdown-item" href="/moons/ledger/display/select">Mining Ledger</a>
|
<a class="dropdown-item" href="/moons/ledger/display/moons">Mining Ledger</a>
|
||||||
|
@endif
|
||||||
|
@if(auth()->user()->isMoonRenter())
|
||||||
|
<a class="dropdown-item" href="/moons/ledger/display/rentals">Moon Rental Ledger</a>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,34 +1,47 @@
|
|||||||
@extends('layouts.b4')
|
@extends('layouts.b4')
|
||||||
@section('content')
|
@section('content')
|
||||||
<br>
|
<div class="container-fluid">
|
||||||
<div class="container">
|
<div class="row">
|
||||||
<div class="card">
|
<div class="container">
|
||||||
<div class="card-header">
|
<h2>Moon Ledger</h2>
|
||||||
<h2>Moon Ledger</h2><br>
|
|
||||||
<p align="left">Shows mining from the last 30 days.</p>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<table class="table table-bordered table-striped">
|
|
||||||
<thead>
|
|
||||||
<th>Character</th>
|
|
||||||
<th>Corp Ticker</th>
|
|
||||||
<th>Ore Name</th>
|
|
||||||
<th>Quantity</th>
|
|
||||||
<th>Date</th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach($mining as $min)
|
|
||||||
<tr>
|
|
||||||
<td>{{ $min['character'] }}</td>
|
|
||||||
<td>{{ $min['corpTicker'] }}</td>
|
|
||||||
<td>{{ $min['ore'] }}</td>
|
|
||||||
<td>{{ $min['quantity'] }}</td>
|
|
||||||
<td>{{ $min['updated'] }}</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
@foreach($structures as $key => $value)
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-toggle="pill" href="#W4RP-{{str_replace(' ', '_', $value)}}">{{$value}}</a>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<div class="tab-content">
|
||||||
|
@foreach($structures as $key => $value)
|
||||||
|
<div id="W4RP-{{str_replace(' ', '_', $value)}}" class="tab-pane fade">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<th>Character</th>
|
||||||
|
<th>Corp Ticker</th>
|
||||||
|
<th>Ore Name</th>
|
||||||
|
<th>Quantity</th>
|
||||||
|
<th>Date</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($miningLedgers as $ledger)
|
||||||
|
@if($ledger['structure'] == $value)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $ledger['character'] }}</td>
|
||||||
|
<td>{{ $ledger['corpTicker'] }}</td>
|
||||||
|
<td>{{ $ledger['ore'] }}</td>
|
||||||
|
<td>{{ $ledger['quantity'] }}</td>
|
||||||
|
<td>{{ $ledger['updated'] }}</td>
|
||||||
|
</tr>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
@@ -133,9 +133,8 @@ Route::group(['middleware' => ['auth']], function(){
|
|||||||
/**
|
/**
|
||||||
* Moon Ledger Controller display pages
|
* Moon Ledger Controller display pages
|
||||||
*/
|
*/
|
||||||
Route::post('/moons/ledger/display/', 'Moons\MoonLedgerController@displayLedger');
|
|
||||||
Route::get('/moons/ledger/display/select', 'Moons\MoonLedgerController@displaySelection');
|
|
||||||
Route::get('/moons/ledger/display/moons', 'Moons\MoonLedgerController@displayMoonLedger');
|
Route::get('/moons/ledger/display/moons', 'Moons\MoonLedgerController@displayMoonLedger');
|
||||||
|
Route::get('/moons/ledger/display/rentals', 'Moons\MoonLedgerController@displayRentalMoonLedger');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scopes Controller display pages
|
* Scopes Controller display pages
|
||||||
|
|||||||
Reference in New Issue
Block a user