diff --git a/app/Console/Commands/GetAssets.php b/app/Console/Commands/Assets/GetAssets.php
similarity index 98%
rename from app/Console/Commands/GetAssets.php
rename to app/Console/Commands/Assets/GetAssets.php
index 379b041d3..86846574c 100644
--- a/app/Console/Commands/GetAssets.php
+++ b/app/Console/Commands/Assets/GetAssets.php
@@ -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');
}
}
diff --git a/app/Console/Commands/getCorps.php b/app/Console/Commands/Corps/GetCorps.php
similarity index 100%
rename from app/Console/Commands/getCorps.php
rename to app/Console/Commands/Corps/GetCorps.php
diff --git a/app/Console/Commands/Data/CleanStaleDataCommand.php b/app/Console/Commands/Data/CleanStaleDataCommand.php
new file mode 100644
index 000000000..8c3bb0452
--- /dev/null
+++ b/app/Console/Commands/Data/CleanStaleDataCommand.php
@@ -0,0 +1,44 @@
+CleanJobStatusTable();
+ }
+}
diff --git a/app/Console/Commands/holdingfinances.php b/app/Console/Commands/Finances/HoldingFinances.php
similarity index 100%
rename from app/Console/Commands/holdingfinances.php
rename to app/Console/Commands/Finances/HoldingFinances.php
diff --git a/app/Console/Commands/pitransactions.php b/app/Console/Commands/Finances/PiTransactions.php
similarity index 100%
rename from app/Console/Commands/pitransactions.php
rename to app/Console/Commands/Finances/PiTransactions.php
diff --git a/app/Console/Commands/moonmailer.php b/app/Console/Commands/Moons/MoonMailer.php
similarity index 100%
rename from app/Console/Commands/moonmailer.php
rename to app/Console/Commands/Moons/MoonMailer.php
diff --git a/app/Console/Commands/UpdateMoonPricing.php b/app/Console/Commands/Moons/UpdateMoonPricing.php
similarity index 100%
rename from app/Console/Commands/UpdateMoonPricing.php
rename to app/Console/Commands/Moons/UpdateMoonPricing.php
diff --git a/app/Console/Commands/UpdateMoonRental.php b/app/Console/Commands/Moons/UpdateMoonRental.php
similarity index 100%
rename from app/Console/Commands/UpdateMoonRental.php
rename to app/Console/Commands/Moons/UpdateMoonRental.php
diff --git a/app/Console/Commands/GetStructures.php b/app/Console/Commands/Structures/GetStructures.php
similarity index 100%
rename from app/Console/Commands/GetStructures.php
rename to app/Console/Commands/Structures/GetStructures.php
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index f4ccb5351..763898bdf 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -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();
diff --git a/app/Http/Controllers/Moons/MoonsAdminController.php b/app/Http/Controllers/Moons/MoonsAdminController.php
index 18e2c6f10..7f7760759 100644
--- a/app/Http/Controllers/Moons/MoonsAdminController.php
+++ b/app/Http/Controllers/Moons/MoonsAdminController.php
@@ -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);
}
}
diff --git a/app/Jobs/ProcessAssetsJob.php b/app/Jobs/ProcessAssetsJob.php
index 46acb7461..3d85a98d5 100644
--- a/app/Jobs/ProcessAssetsJob.php
+++ b/app/Jobs/ProcessAssetsJob.php
@@ -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;
- }
-
-
}
diff --git a/app/Library/Assets/AssetHelper.php b/app/Library/Assets/AssetHelper.php
new file mode 100644
index 000000000..625691c9a
--- /dev/null
+++ b/app/Library/Assets/AssetHelper.php
@@ -0,0 +1,132 @@
+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(),
+ ]);
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/app/Library/Stock/Helper/StructureStockHelper.php b/app/Library/Stock/Helper/StructureStockHelper.php
deleted file mode 100644
index 045b3a9a3..000000000
--- a/app/Library/Stock/Helper/StructureStockHelper.php
+++ /dev/null
@@ -1,47 +0,0 @@
-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;
- }
- }
-
-}
-
-?>
\ No newline at end of file
diff --git a/app/Library/Stock/StockHelper.php b/app/Library/Stock/StockHelper.php
deleted file mode 100644
index a0fb8ae68..000000000
--- a/app/Library/Stock/StockHelper.php
+++ /dev/null
@@ -1,90 +0,0 @@
-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'];
- }
- }
- }
-}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Jobs/JobProcessAssets.php b/app/Models/Jobs/JobProcessAsset.php
similarity index 87%
rename from app/Models/Jobs/JobProcessAssets.php
rename to app/Models/Jobs/JobProcessAsset.php
index b8e852906..015c73bf8 100644
--- a/app/Models/Jobs/JobProcessAssets.php
+++ b/app/Models/Jobs/JobProcessAsset.php
@@ -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
diff --git a/app/Models/Stock/Asset.php b/app/Models/Stock/Asset.php
index 94c3ddd41..1406aaedc 100644
--- a/app/Models/Stock/Asset.php
+++ b/app/Models/Stock/Asset.php
@@ -34,5 +34,6 @@ class Asset extends Model
'location_type',
'quantity',
'type_id',
+ 'updated_at',
];
}
diff --git a/resources/views/moons/admin/adminmoon.blade.php b/resources/views/moons/admin/adminmoon.blade.php
index 9a323b7d2..db1a74235 100644
--- a/resources/views/moons/admin/adminmoon.blade.php
+++ b/resources/views/moons/admin/adminmoon.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.b4')
@section('content')
-{!! Form::open(['action' => 'Moons\MoonsAdminController@updateMoonPaid', 'method' => 'POST']) !!}
+{!! Form::open(['action' => 'Moons\MoonsAdminController@storeMoonRemoval', 'method' => 'POST']) !!}
@@ -30,7 +30,7 @@
@else
| No |
@endif
- {{ Form::radio('paid', $row['SPM'], false, ['class' => 'form-control']) }} |
+ {{ Form::radio('remove', $row['SPM'], false, ['class' => 'form-control']) }} |
@endforeach
@@ -50,7 +50,7 @@
-
+
| Moon Available |
diff --git a/resources/views/moons/admin/updatemoon.blade.php b/resources/views/moons/admin/updatemoon.blade.php
index 984f32650..6666824fc 100644
--- a/resources/views/moons/admin/updatemoon.blade.php
+++ b/resources/views/moons/admin/updatemoon.blade.php
@@ -4,12 +4,8 @@
Update Existing Moon
{!! Form::open(['action' => 'Moons\MoonsAdminController@storeUpdateMoon', 'method' => 'POST']) !!}
- {{ 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') }}
{{ Form::label('renter', 'Renter') }}
@@ -21,7 +17,7 @@
{{ 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']) }}
Paid?
diff --git a/routes/web.php b/routes/web.php
index fb5e9fa0d..0a4214262 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -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