Modified folders for commands.
Added job for retrieving assets from esi. Modified moon rental data to flow better with views.
This commit is contained in:
@@ -97,7 +97,6 @@ class GetAssetsCommand extends Command
|
||||
$job->charId = $charId;
|
||||
$job->corpId = $corpId;
|
||||
$job->page = $i;
|
||||
$job->esi = $esi;
|
||||
ProcessAssetJob::dispatch($job)->onQueue('default');
|
||||
}
|
||||
}
|
||||
44
app/Console/Commands/Data/CleanStaleDataCommand.php
Normal file
44
app/Console/Commands/Data/CleanStaleDataCommand.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Commands\Library\CommandHelper;
|
||||
|
||||
class CleanStaleDataCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'services:CleanData';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clean old database data';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$command = new CommandHelper;
|
||||
$command->CleanJobStatusTable();
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
//Library
|
||||
use Commands\Library\CommandHelper;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
@@ -45,6 +49,8 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('services:PiTransactions')
|
||||
->hourly()
|
||||
->withoutOverlapping();
|
||||
$schedule->command('services:CleanData')
|
||||
->monthlyOn(1, '18:00');
|
||||
|
||||
//Horizon Graph Schedule
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||
|
||||
@@ -29,38 +29,193 @@ class MoonsAdminController extends Controller
|
||||
$this->middleware('role:Admin');
|
||||
}
|
||||
|
||||
public function showJournalEntries() {
|
||||
$dateInit = Carbon::now();
|
||||
$date = $dateInit->subDays(30);
|
||||
/**
|
||||
* Function to display the moons to admins
|
||||
*/
|
||||
public function displayMoonsAdmin() {
|
||||
$lookup = new LookupHelper;
|
||||
$contact = '';
|
||||
$paid = '';
|
||||
$rentalEnd = '';
|
||||
$renter = '';
|
||||
$ticker = '';
|
||||
|
||||
$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('moons.admin.moonjournal')->with('journal', $journal);
|
||||
//Setup calls to the MoonCalc class
|
||||
$moonCalc = new MoonCalc();
|
||||
//Get all of the moons from the database
|
||||
$moons = Moon::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');
|
||||
|
||||
//Set the contact info
|
||||
$contact = 'None';
|
||||
|
||||
//Set the renter info
|
||||
$renter = 'None';
|
||||
|
||||
//Set the ticker info
|
||||
$ticker = '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;
|
||||
|
||||
//Set the rental date up
|
||||
$rentalTemp = new Carbon($rental->RentalEnd);
|
||||
$rentalEnd = $rentalTemp->format('m-d');
|
||||
|
||||
//Set the contact name
|
||||
$contact = $lookup->CharacterName($rental->Contact);
|
||||
|
||||
//Set up the renter whether it's W4RP or another corporation
|
||||
$corpId = $lookup->LookupCorporationId($rental->Contact);
|
||||
$allianceId = $lookup->LookupCorporation($corpId);
|
||||
$ticker = $lookup->LookupAllianceTicker($allianceId);
|
||||
}
|
||||
|
||||
//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,
|
||||
'Contact' => $contact,
|
||||
'Renter' => $ticker,
|
||||
]);
|
||||
}
|
||||
|
||||
return view('moons.admin.adminmoon')->with('table', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to remove a renter from a moon
|
||||
*/
|
||||
public function storeMoonRemoval(Request $request) {
|
||||
$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')->with('success', 'Renter removed.');
|
||||
}
|
||||
|
||||
//Redirect back to the moon page, which should call the page to be displayed correctly
|
||||
return redirect('/moons/admin/display')->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() {
|
||||
//Declare some variables
|
||||
$system = null;
|
||||
$planet = null;
|
||||
$moon = null;
|
||||
$name = null;
|
||||
$spmn = array();
|
||||
|
||||
//Get the moons and put in order by System, Planet, then Moon number
|
||||
$moons = Moon::all()->orderBy('System', 'ASC')
|
||||
->orderBy('Planet', 'ASC')
|
||||
->orderBy('Moon', 'ASC');
|
||||
|
||||
//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($spmn, $temp);
|
||||
}
|
||||
|
||||
//Return the view and the form from the blade display
|
||||
return view('moons.admin.updatemoon');
|
||||
//Pass the data to the view as well
|
||||
return view('moons.admin.updatemoon')->with('spmn', $spmn);
|
||||
}
|
||||
|
||||
public function storeUpdateMoon(Request $request) {
|
||||
$moonCalc = new MoonCalc;
|
||||
$lookup = new LookupHelper;
|
||||
$paid = false;
|
||||
$system = null;
|
||||
$planet = null;
|
||||
$moon = null;
|
||||
$name = null;
|
||||
|
||||
$this->validate($request, [
|
||||
'system' => 'required',
|
||||
'planet' => 'required',
|
||||
'moon' => 'required',
|
||||
'spmn' => 'required',
|
||||
'renter' => 'required',
|
||||
'date' => 'required',
|
||||
'contact' => 'required',
|
||||
]);
|
||||
|
||||
if($request->removal == true) {
|
||||
$this->RemoveRenter($request->system, $request->planet, $request->moon);
|
||||
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated and Renter Removed.');
|
||||
}
|
||||
//Decode the System, Planet, Moon, Name combinatio sent from the controller
|
||||
$str_array = explode(" - ", $request->spmn);
|
||||
$system = $str_array[0];
|
||||
$planet = $str_array[1];
|
||||
$moon = $str_array[2];
|
||||
$name = $str_array[3];
|
||||
|
||||
//Take the contact name and create a character_id from it
|
||||
if($request->contact == 'None') {
|
||||
@@ -88,33 +243,33 @@ class MoonsAdminController extends Controller
|
||||
$date = new Carbon($request->date . '00:00:01');
|
||||
|
||||
$count = MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'Contact' => $contact,
|
||||
])->count();
|
||||
|
||||
//Calculate the price of the moon for when it's updated
|
||||
$moon = Moon::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
])->first();
|
||||
|
||||
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||
|
||||
if(($count != 0) && $request->removal != true) {
|
||||
if($count != 0) {
|
||||
if($allianceId = 99004116) {
|
||||
MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'Contact' => $contact,
|
||||
])->update([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'RentalCorp' => $request->renter,
|
||||
'RentalEnd' => $date,
|
||||
'Contact' => $contact,
|
||||
@@ -125,14 +280,14 @@ class MoonsAdminController extends Controller
|
||||
]);
|
||||
} else {
|
||||
MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'Contact' => $contact,
|
||||
])->update([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'RentalCorp' => $request->renter,
|
||||
'RentalEnd' => $date,
|
||||
'Contact' => $contact,
|
||||
@@ -146,16 +301,16 @@ class MoonsAdminController extends Controller
|
||||
//If the entry is not found, then attempt to delete whatever existing data is there, then
|
||||
//insert the new data
|
||||
MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
])->delete();
|
||||
|
||||
if($allianceId = 99004116) {
|
||||
MoonRental::insert([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'RentalCorp' => $request->renter,
|
||||
'RentalEnd' => $date,
|
||||
'Contact' => $contact,
|
||||
@@ -165,9 +320,9 @@ class MoonsAdminController extends Controller
|
||||
]);
|
||||
} else {
|
||||
MoonRental::insert([
|
||||
'System' =>$request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
'RentalCorp' => $request->renter,
|
||||
'RentalEnd' => $date,
|
||||
'Contact' => $contact,
|
||||
@@ -182,219 +337,12 @@ class MoonsAdminController extends Controller
|
||||
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to display the moons to admins
|
||||
*/
|
||||
public function displayMoonsAdmin() {
|
||||
$lookup = new LookupHelper;
|
||||
$contact = '';
|
||||
$paid = '';
|
||||
$rentalEnd = '';
|
||||
$renter = '';
|
||||
$ticker = '';
|
||||
public function showJournalEntries() {
|
||||
$dateInit = Carbon::now();
|
||||
$date = $dateInit->subDays(30);
|
||||
|
||||
//Setup calls to the MoonCalc class
|
||||
$moonCalc = new MoonCalc();
|
||||
//Get all of the moons from the database
|
||||
$moons = Moon::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
|
||||
$rental = MoonRental::where([
|
||||
'System' => $moon->System,
|
||||
'Planet' => $moon->Planet,
|
||||
'Moon' => $moon->Moon,
|
||||
])->first();
|
||||
|
||||
//Check if their is a current rental for a moon going on
|
||||
if($rental == false) {
|
||||
//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');
|
||||
|
||||
//Set the contact info
|
||||
$contact = 'None';
|
||||
|
||||
//Set the renter info
|
||||
$renter = 'None';
|
||||
|
||||
//Set the ticker info
|
||||
$ticker = 'N/A';
|
||||
} else {
|
||||
//If we find a rental record, mark the moon as whether it's paid or not
|
||||
$paid = $rental->Paid;
|
||||
|
||||
//Set the rental date up
|
||||
$rentalTemp = new Carbon($rental->RentalEnd);
|
||||
$rentalEnd = $rentalTemp->format('m-d');
|
||||
|
||||
//Set the contact name
|
||||
$contact = $lookup->CharacterName($rental->Contact);
|
||||
|
||||
//Set up the renter whether it's W4RP or another corporation
|
||||
$corpId = $lookup->LookupCorporationId($rental->Contact);
|
||||
$allianceId = $lookup->LookupCorporation($corpId);
|
||||
$ticker = $lookup->LookupAllianceTicker($allianceId);
|
||||
}
|
||||
|
||||
//Set the color for the table
|
||||
if($rentalTemp->diffInDays($today) < 3 ) {
|
||||
$color = 'table-warning';
|
||||
} else if( $today > $rentalTemp) {
|
||||
$color = 'table-primary';
|
||||
} 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,
|
||||
'Contact' => $contact,
|
||||
'Renter' => $ticker,
|
||||
]);
|
||||
}
|
||||
|
||||
return view('moons.admin.adminmoon')->with('table', $table);
|
||||
}
|
||||
|
||||
public function UpdateMoonPaid(Request $request) {
|
||||
$this->validate($request, [
|
||||
'paid' => 'required',
|
||||
]);
|
||||
|
||||
$str_array = explode(" - ", $request->paid);
|
||||
|
||||
//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];
|
||||
|
||||
//Update the paid status of the moon
|
||||
MoonRental::where([
|
||||
'System' => $system,
|
||||
'Planet' => $planet,
|
||||
'Moon' => $moon,
|
||||
])->update([
|
||||
'Paid' => 'Yes',
|
||||
]);
|
||||
|
||||
//Redirect back to the moon page, which should call the page to be displayed correctly
|
||||
return redirect('/moons/admin/display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display function for adding a new rental moon to the pool
|
||||
*
|
||||
*/
|
||||
public function addMoon() {
|
||||
return view('moons.admin.addmoon');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new moon into the database
|
||||
*
|
||||
* @return \Illuminate\Http\Reponse
|
||||
*/
|
||||
public function storeMoon(Request $request) {
|
||||
$this->validate($request, [
|
||||
'region' => 'required',
|
||||
'system' => 'required',
|
||||
'structure' => 'required',
|
||||
]);
|
||||
|
||||
if($request->input('firstquan') < 1.00) {
|
||||
$firstQuan = $request->input('firstquan') * 100.00;
|
||||
} else {
|
||||
$firstQuan = $request->input('firstquan');
|
||||
}
|
||||
|
||||
if($request->input('secondquan') < 1.00) {
|
||||
$firstQuan = $request->input('secondquan') * 100.00;
|
||||
} else {
|
||||
$firstQuan = $request->input('secondquan');
|
||||
}
|
||||
|
||||
if($request->input('thirdquan') < 1.00) {
|
||||
$firstQuan = $request->input('thirdquan') * 100.00;
|
||||
} else {
|
||||
$firstQuan = $request->input('thirdquan');
|
||||
}
|
||||
|
||||
if($request->input('fourthquan') < 1.00) {
|
||||
$firstQuan = $request->input('fourthquan') * 100.00;
|
||||
} else {
|
||||
$firstQuan = $request->input('fourthquan');
|
||||
}
|
||||
|
||||
// Add new moon
|
||||
$moon = new Moon;
|
||||
$moon->Region = $request->input('region');
|
||||
$moon->System = $request->input('system');
|
||||
$moon->Planet = $request->input('planet');
|
||||
$moon->Moon = $request->input('moon');
|
||||
$moon->StructureName = $request->input('structure');
|
||||
$moon->FirstOre = $request->input('firstore');
|
||||
$moon->FirstQuantity = $request->input('firstquan');
|
||||
$moon->SecondOre = $request->input('secondore');
|
||||
$moon->SecondQuantity = $request->input('secondquan');
|
||||
$moon->ThirdOre = $request->input('thirdore');
|
||||
$moon->ThirdQuantity = $request->input('thirdquan');
|
||||
$moon->FourthOre = $request->input('fourthore');
|
||||
$moon->FourthQuantity = $request->input('fourthquan');
|
||||
$moon->save();
|
||||
|
||||
return redirect('/dashboard')->with('success', 'Moon Added');
|
||||
}
|
||||
|
||||
private function RemoveRenter($system, $planet, $moon) {
|
||||
$found = MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'Contact' => $contact,
|
||||
])->count();
|
||||
|
||||
if($found != 0) {
|
||||
MoonRental::where([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
])->delete();
|
||||
|
||||
MoonRental::insert([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'Contact' => 'None',
|
||||
'Paid' => 'No',
|
||||
'Paid_Until' => Carbon::now()->endOfMonth(),
|
||||
]);
|
||||
} else {
|
||||
MoonRental::insert([
|
||||
'System' => $request->system,
|
||||
'Planet' => $request->planet,
|
||||
'Moon' => $request->moon,
|
||||
'Contact' => 'None',
|
||||
'Paid' => 'No',
|
||||
'Paid_Until' => Carbon::now()->endOfMonth(),
|
||||
]);
|
||||
}
|
||||
$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('moons.admin.moonjournal')->with('journal', $journal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,17 +68,6 @@ class ProcessAssetsJob implements ShouldQueue
|
||||
$this->charId = $jpa->charId;
|
||||
$this->corpId = $jpa->corpId;
|
||||
$this->page = $jpa->page;
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
|
||||
$this->esi = new Eseye($authentication);
|
||||
|
||||
//Set the connection for the job
|
||||
$this->connection = 'redis';
|
||||
@@ -95,75 +84,19 @@ class ProcessAssetsJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Get the pages of the asset list
|
||||
$assets = $this->GePageOfAssets();
|
||||
//Declare the asset helper
|
||||
$aHelper = new AssetHelper($this->charId, $this->corpId);
|
||||
|
||||
//Get a page of assets
|
||||
$assets = $aHelper->GetAssetsByPage($jpba->page);
|
||||
|
||||
//Cycle through the assets, and attmept to store them.
|
||||
foreach($assets as $asset) {
|
||||
$found = Asset::where([
|
||||
'item_id' => $asset['item_id'],
|
||||
])->count();
|
||||
|
||||
//Update the asset if we found it, otherwise add the asset to the database
|
||||
if($found == 0) {
|
||||
if(in_array($asset['location_flag'], $this->location_array)) {
|
||||
$this->StoreNewAsset($asset);
|
||||
}
|
||||
} else {
|
||||
$this->UpdateAsset($asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function UpdateAsset($asset) {
|
||||
if(isset($asset['is_blueprint_copy'])) {
|
||||
Asset::where([
|
||||
'item_id' => $asset['item_id'],
|
||||
])->update([
|
||||
'is_blueprint_copy' => $asset['is_blueprint_copy'],
|
||||
]);
|
||||
//Attempt to store the asset
|
||||
$aHelper->StoreNewAsset($asset);
|
||||
}
|
||||
|
||||
Asset::where([
|
||||
'item_id' => $asset['item_id'],
|
||||
])->update([
|
||||
'is_singleton' => $asset['is_singleton'],
|
||||
'item_id' => $asset['item_id'],
|
||||
'location_flag' => $asset['location_flag'],
|
||||
'location_id' => $asset['location_id'],
|
||||
'location_type' => $asset['location_type'],
|
||||
'quantity' => $asset['quantity'],
|
||||
'type_id' => $asset['type_id'],
|
||||
]);
|
||||
//Purge Stale Data
|
||||
$aHelper->PurgeStaleData();
|
||||
}
|
||||
|
||||
private function StoreNewAsset($asset) {
|
||||
$new = new Asset;
|
||||
if(isset($asset['is_blueprint_copy'])) {
|
||||
$new->is_blueprint_copy = $asset['is_blueprint_copy'];
|
||||
}
|
||||
$new->is_singleton = $asset['is_singleton'];
|
||||
$new->item_id = $asset['item_id'];
|
||||
$new->location_flag = $asset['location_flag'];
|
||||
$new->location_id = $asset['location_id'];
|
||||
$new->location_type = $asset['location_type'];
|
||||
$new->quantity = $asset['quantity'];
|
||||
$new->type_id = $asset['type_id'];
|
||||
$new->save();
|
||||
}
|
||||
|
||||
private function GetPageOfAssets() {
|
||||
try {
|
||||
$assets = $this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
132
app/Library/Assets/AssetHelper.php
Normal file
132
app/Library/Assets/AssetHelper.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Assets;
|
||||
|
||||
//Internal Library
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
//App Library
|
||||
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\Esi\Esi;
|
||||
|
||||
use App\Models\Jobs\JobProcessAsset;
|
||||
use App\Models\Jobs\JobStatus;
|
||||
use App\Models\Models\Stock;
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Esi\EsiScope;
|
||||
|
||||
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($page) {
|
||||
// Disable all caching by setting the NullCache as the
|
||||
// preferred cache handler. By default, Eseye will use the
|
||||
// FileCache.
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
//Get the refresh token from the database
|
||||
$token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']);
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Setup the ESI variable
|
||||
$esi = new Eseye($authentication);
|
||||
|
||||
try {
|
||||
$assets = $esi->page($this->page)
|
||||
->invoke('get', '/corporations/{corporation_id}/assets', [
|
||||
'corporation_id' => $this->corId,
|
||||
]);
|
||||
} 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing asset based off the esi pull
|
||||
*/
|
||||
private function UpdateAsset($asset) {
|
||||
$item = Asset::where([
|
||||
'item_id' => $asset->item_id,
|
||||
])->count();
|
||||
|
||||
if($count != 0) {
|
||||
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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* W4RP Services
|
||||
* GNU Public License
|
||||
*/
|
||||
|
||||
namespace App\Library\Stock\Helper;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
|
||||
//Job
|
||||
use App\Jobs\ProcessStocksJob;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
|
||||
//Models
|
||||
use App\Models\Stock\StructureStock;
|
||||
|
||||
class StructureStockHelper {
|
||||
|
||||
private $scopeCheck;
|
||||
|
||||
public function __construct() {
|
||||
$esi = new Esi();
|
||||
|
||||
$assetScope = $esi->HaveEsiScope($charId, 'esi-assets.read_corporation_assets.v1');
|
||||
$structureScope = $esi->HaveEsiScope($charId, 'esi-universe.read_structurs.v1');
|
||||
|
||||
if($assetScope == false || $structureScope == false) {
|
||||
$scopeCheck = false;
|
||||
} else {
|
||||
$scopeCheck = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* W4RP Services
|
||||
* GNU Public License
|
||||
*/
|
||||
|
||||
namespace App\Library\Structures\Helper;
|
||||
|
||||
//Internal Library
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
//Job
|
||||
use App\Jobs\ProcessStocksJob;
|
||||
|
||||
//Library
|
||||
use App\Library\Esi\Esi;
|
||||
use Seat\Eseye\Cache\NullCache;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
|
||||
//Models
|
||||
use App\Models\Stock\StructureStock;
|
||||
|
||||
class StructureStockHelper {
|
||||
|
||||
private $scopeCheck;
|
||||
|
||||
public function __construct() {
|
||||
$esi = new Esi();
|
||||
|
||||
$assetScope = $esi->HaveEsiScope($charId, 'esi-assets.read_corporation_assets.v1');
|
||||
|
||||
if($assetScope == false) {
|
||||
$scopeCheck = false;
|
||||
} else {
|
||||
$scopeCheck = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAssetList() {
|
||||
if($this->scopeCheck == false) {
|
||||
Log::critical("Structure Stock Helper didn't have the correct scopes available.");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Setup the esi authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id'=> $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
]);
|
||||
|
||||
$esi = new Eseye($authentication);
|
||||
try {
|
||||
$newAssets = $esi->invoke('get', '/corporations/{corporation_id}/assets/', [
|
||||
'corporation_id' => 98287666,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::critical($e->getEsiExceptionResponse());
|
||||
return null;
|
||||
}
|
||||
|
||||
//How to deal with stale data in this table?
|
||||
|
||||
foreach($newAssets as $asset) {
|
||||
//See if the asset is in the asset table already.
|
||||
$found = Asset::where(['item_id' => $asset['item_id']])->count();
|
||||
if($found == 0) {
|
||||
$newItem = new Asset;
|
||||
if(isset($asset['is_blueprint_copy'])) {
|
||||
$newItem->is_blueprint_coopy = $asset['is_blueprint_copy'];
|
||||
}
|
||||
$newItem->is_singleton = $asset['is_singleton'];
|
||||
$newItem->item_id = $asset['item_id'];
|
||||
$newItem->location_flag = $asset['location_flag'];
|
||||
$newItem->location_id = $asset['location_id'];
|
||||
$newItem->location_type = $asset['location_type'];
|
||||
$newItem->quantity = $asset['quantity'];
|
||||
$newItem->type_id = $asset['type_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -4,7 +4,7 @@ namespace App\Models\Jobs;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class JobProcessAssets extends Model
|
||||
class JobProcessAsset extends Model
|
||||
{
|
||||
//no table name is needed
|
||||
|
||||
@@ -34,5 +34,6 @@ class Asset extends Model
|
||||
'location_type',
|
||||
'quantity',
|
||||
'type_id',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@extends('layouts.b4')
|
||||
@section('content')
|
||||
<br>
|
||||
{!! Form::open(['action' => 'Moons\MoonsAdminController@updateMoonPaid', 'method' => 'POST']) !!}
|
||||
{!! Form::open(['action' => 'Moons\MoonsAdminController@storeMoonRemoval', 'method' => 'POST']) !!}
|
||||
<div class="container col-md-12">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
@@ -30,7 +30,7 @@
|
||||
@else
|
||||
<td>No</td>
|
||||
@endif
|
||||
<td>{{ Form::radio('paid', $row['SPM'], false, ['class' => 'form-control']) }}</td>
|
||||
<td>{{ Form::radio('remove', $row['SPM'], false, ['class' => 'form-control']) }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@@ -50,7 +50,7 @@
|
||||
<div class="card-body">
|
||||
<table class="table table-striped">
|
||||
<tbody>
|
||||
<tr class="table-primary">
|
||||
<tr class="table-success">
|
||||
<td>Moon Available</td>
|
||||
</tr>
|
||||
<tr class="table-danger">
|
||||
|
||||
@@ -4,12 +4,8 @@
|
||||
<h2>Update Existing Moon</h2>
|
||||
{!! Form::open(['action' => 'Moons\MoonsAdminController@storeUpdateMoon', 'method' => 'POST']) !!}
|
||||
<div class="form-group col-md-6">
|
||||
{{ Form::label('system', 'System') }}
|
||||
{{ Form::text('system', '', ['class' => 'form-control', 'placeholder' => 'System']) }}
|
||||
{{ Form::label('planet', 'Planet') }}
|
||||
{{ Form::text('planet', '', ['class' => 'form-control', 'placeholder' => 'Planet']) }}
|
||||
{{ Form::label('moon', 'Moon') }}
|
||||
{{ Form::text('moon', '', ['class' => 'form-control', 'placeholder' => 'Moon']) }}
|
||||
{{ Form::label('spmn', 'Moon') }}
|
||||
{{ Form::select('spmn', $spmn, 'N/A') }}
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
{{ Form::label('renter', 'Renter') }}
|
||||
@@ -21,7 +17,7 @@
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
{{ Form::label('date', 'Rental End Date') }}
|
||||
{{ Form::date('date', \Carbon\Carbon::now()->addMonth(), ['class' => 'form-control']) }}
|
||||
{{ Form::date('date', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
Paid?<br>
|
||||
|
||||
@@ -39,7 +39,7 @@ Route::group(['middleware' => ['auth']], function(){
|
||||
Route::get('/moons/admin/updatemoon', 'Moons\MoonsAdminController@updateMoon');
|
||||
Route::post('/moons/admin/updatemoon', 'Moons\MoonsAdminController@storeUpdateMoon');
|
||||
Route::get('/moons/admin/journal', 'Moons\MoonsAdminController@showJournalEntries');
|
||||
Route::post('/moons/admin/display', 'Moons\MoonsAdminController@updateMoonPaid');
|
||||
Route::post('/moons/admin/display', 'Moons\MoonsAdminController@storeMoonRemoval');
|
||||
|
||||
/**
|
||||
* Wiki Controller display pages
|
||||
|
||||
Reference in New Issue
Block a user