mining taxes view controller start
This commit is contained in:
@@ -17,6 +17,8 @@ use App\Models\User\UserPermission;
|
||||
use App\Models\User\UserRole;
|
||||
use App\Models\SRP\SRPShip;
|
||||
use App\Models\User\UserAlt;
|
||||
use App\Models\MiningTax\Invoice;
|
||||
use App\Models\MiningTax\Ledger;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
@@ -42,9 +44,13 @@ class DashboardController extends Controller
|
||||
$open = array();
|
||||
$approved = array();
|
||||
$denied = array();
|
||||
$ores = array();
|
||||
$altCount = null;
|
||||
$alts = null;
|
||||
|
||||
/**
|
||||
* Alt Counts
|
||||
*/
|
||||
//Get the number of the user's alt which are registered so we can process the alt's on the main dashboard page
|
||||
$altCount = UserAlt::where([
|
||||
'main_id' => auth()->user()->character_id,
|
||||
@@ -57,6 +63,9 @@ class DashboardController extends Controller
|
||||
])->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* SRP Items
|
||||
*/
|
||||
//See if we can get all of the open SRP requests
|
||||
$openCount = SRPShip::where([
|
||||
'character_id' => auth()->user()->character_id,
|
||||
@@ -184,13 +193,32 @@ class DashboardController extends Controller
|
||||
],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Mining Tax Items
|
||||
*/
|
||||
$invoice = Ledger::where([
|
||||
'character_id' => auth()->user()->getId(),
|
||||
'invoiced' => 'No',
|
||||
])->sum('amount');
|
||||
|
||||
$rows = Ledger::where([
|
||||
'character_id' => auth()->user()->getId(),
|
||||
'invoiced' => 'No',
|
||||
])->get();
|
||||
|
||||
foreach($rows as $row) {
|
||||
$ores[$row->ore_name] = $ores[$row->ore_name] + $row->quantity;
|
||||
}
|
||||
|
||||
return view('dashboard')->with('openCount', $openCount)
|
||||
->with('approvedCount', $approvedCount)
|
||||
->with('deniedCount', $deniedCount)
|
||||
->with('open', $open)
|
||||
->with('approved', $approved)
|
||||
->with('denied', $denied)
|
||||
->with('lava', $lava);
|
||||
->with('lava', $lava)
|
||||
->with('invoice', $invoice)
|
||||
->with('ores', $ores);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,8 @@ use Auth;
|
||||
//Library Helpers
|
||||
use App\Library\Lookups\LookupHelper;
|
||||
use App\Library\Structures\StructureHelper;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
|
||||
//Models
|
||||
use App\Models\Moon\ItemComposition;
|
||||
@@ -20,37 +22,118 @@ use App\Models\Moon\MineralPrice;
|
||||
use App\Models\MiningTax\Ledger;
|
||||
use App\Models\MiningTax\Observer;
|
||||
use App\Models\MiningTax\Invoice;
|
||||
use App\Models\Esi\EsiToken;
|
||||
use App\Models\Esi\EsiScope;
|
||||
|
||||
class MiningTaxesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Construct to deal with middleware and other items
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('role:User');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all of the upcoming extractions
|
||||
*/
|
||||
public function DisplayUpcomingExtractions() {
|
||||
|
||||
//Declare variables
|
||||
$structures = array();
|
||||
$sHelper = new StructureHelper;
|
||||
|
||||
//Get all the current observers from the database
|
||||
//Get the esi data for extractions
|
||||
try {
|
||||
$extractions = $this->esi->invoke('get', '/corporation/{corporation_id}/mining/extractions/', [
|
||||
'corporation_id' => $config['corporation'],
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
Log::warning('Could not retrieve extractions from ESI in MiningTaxesController.php');
|
||||
$extractions = null;
|
||||
}
|
||||
|
||||
//Basically get the structure info and attach it to the variable set
|
||||
foreach($extractions as $ex) {
|
||||
$sName = $sHelper->GetStructureInfo($ex->structure_id);
|
||||
$ex->structure_name = $sName;
|
||||
|
||||
}
|
||||
|
||||
//Return the view with the extractions variable for html processing
|
||||
return view('miningtax.display.upcoming')->with('extractions', $extractions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the ledger for the moons.
|
||||
*/
|
||||
public function DisplayMoonLedgers() {
|
||||
//Declare variables
|
||||
$structures = array();
|
||||
$tempLedgers = array();
|
||||
$ledgers = array();
|
||||
$esiHelper = new Esi;
|
||||
$lookup = new LookupHelper;
|
||||
$sHelper = new StructureHelper;
|
||||
$config = config();
|
||||
|
||||
//Check for the esi scope
|
||||
if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) {
|
||||
return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the ESI for the holding corp.');
|
||||
} else {
|
||||
if(!$esiHelper->HaveEsiScope($config['primary'], '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
|
||||
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
||||
|
||||
//Setup the esi container
|
||||
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||
|
||||
//Get the character data from the lookup table if possible or esi
|
||||
$character = $lookup->GetCharacterInfo($config['primary']);
|
||||
|
||||
//Get the observers from the database
|
||||
$observers = Observer::all();
|
||||
|
||||
//Get the ledgers for each structure one at a time
|
||||
foreach($observers as $obs) {
|
||||
$extraction = $sHelper->GetExtractions();
|
||||
/**
|
||||
* Get the ledger from each observer.
|
||||
* We don't care about observer type as it can only be an Athanor or Tatara
|
||||
*/
|
||||
$ledgers = Ledger::where([
|
||||
'observer_id' => $obs->structure_id,
|
||||
])->where('last_updated', '>=', Carbon::now()->subDays(30))->get();
|
||||
|
||||
if($ledger != null) {
|
||||
foreach($ledgers as $ledger) {
|
||||
$tempArray = array();
|
||||
|
||||
//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 structure name from the database
|
||||
$structure = $sHelper->GetStructureInfo($obs->observer_id);
|
||||
|
||||
array_push($miningLedgers, [
|
||||
'structure' => $structure->name,
|
||||
'character' => $charInfo->name,
|
||||
'corpTicker' => $corpInfo->ticker,
|
||||
'ore' => $ore,
|
||||
'quantity' => $ledger->quantity,
|
||||
'updated' => $ledger->last_updated,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function DisplayMiningMoons() {
|
||||
|
||||
}
|
||||
|
||||
public function DisplayAccruedTaxes() {
|
||||
|
||||
}
|
||||
|
||||
public function DisplayLedgers() {
|
||||
|
||||
//Return the view
|
||||
return view('miningtax.display.ledger')->with('miningLedgers', $miningLedgers)
|
||||
->with('structures', $structures);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,20 +58,16 @@ class CalculateMiningTaxesJob implements ShouldQueue
|
||||
$rows = Ledger::where([
|
||||
'character_id' => $char->character_id,
|
||||
'invoiced' => 'No',
|
||||
]);
|
||||
])->get();
|
||||
|
||||
//Taly up the item composition from each row and multiply by the quantity
|
||||
foreach($rows as $row) {
|
||||
$ores[$row->type_id] = $ores[$row->type_id] + $row->quantity;
|
||||
}
|
||||
|
||||
//From the item composition for each of the totaled ores, let's get the components and find the price
|
||||
foreach($ores as $itemId => $quantity) {
|
||||
//Get the price from the helper function for each unit of ore
|
||||
$price = $this->mHelper->CalculateOrePrice($itemId);
|
||||
|
||||
//Add up the total and keep a running total
|
||||
$totalPrice += $price * $quantity;
|
||||
//Add up the total price from the ledger rows
|
||||
foreach($rows as $row) {
|
||||
$totalPrice = $totalPrice + $row->price;
|
||||
}
|
||||
|
||||
//Reduce the total price by the take percentage
|
||||
|
||||
@@ -14,10 +14,13 @@ use Carbon\Carbon;
|
||||
use Seat\Eseye\Exceptions\RequestionFailedException;
|
||||
use App\Library\Esi\Esi;
|
||||
use App\Library\Lookups\LookupHelper;
|
||||
use App\Library\Moons\MoonCalc;
|
||||
|
||||
//App Models
|
||||
use App\Models\MiningTax\Observer;
|
||||
use App\Models\MiningTax\Ledger;
|
||||
use App\Models\Moon\MineralPrice;
|
||||
use App\Models\Moon\ItemComposition;
|
||||
|
||||
class FetchMiningTaxesLedgersJob implements ShouldQueue
|
||||
{
|
||||
@@ -81,6 +84,7 @@ class FetchMiningTaxesLedgersJob implements ShouldQueue
|
||||
{
|
||||
//Declare variables
|
||||
$lookup = new LookupHelper;
|
||||
$mHelper = new MoonCalc;
|
||||
$final = array();
|
||||
$items = array();
|
||||
$notSorted = array();
|
||||
@@ -103,6 +107,9 @@ class FetchMiningTaxesLedgersJob implements ShouldQueue
|
||||
$typeName = $lookup->ItemIdToName($ledger->ore);
|
||||
$updated = $this->esi->DecodeDate($ledger->last_updated);
|
||||
|
||||
$price = $mHelper->CalculateOrePrice($ledger->type_id);
|
||||
$amount = $price * $ledger->quantity;
|
||||
|
||||
//Insert or update the entry in the database
|
||||
$item = Ledger::updateOrCreate([
|
||||
'character_id' => $ledger->character_id,
|
||||
@@ -111,6 +118,7 @@ class FetchMiningTaxesLedgersJob implements ShouldQueue
|
||||
'type_id' => $ledger->type_id,
|
||||
'ore_name' => $typeName,
|
||||
'quantity' => $ledger->quantity,
|
||||
'price' => $amount,
|
||||
], [
|
||||
'character_id' => $ledger->character_id,
|
||||
'character_name' => $charName,
|
||||
@@ -118,6 +126,7 @@ class FetchMiningTaxesLedgersJob implements ShouldQueue
|
||||
'type_id' => $ledger->type_id,
|
||||
'ore_name' => $typeName,
|
||||
'quantity' => $ledger->quantity,
|
||||
'price' => $amount,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,6 @@ class StructureHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public function GetExtractions() {
|
||||
//Try to get the ESI data
|
||||
}
|
||||
|
||||
public function GetStructuresByPage($page) {
|
||||
|
||||
//Try to get the ESI data
|
||||
|
||||
@@ -23,6 +23,7 @@ class Ledger extends Model
|
||||
'type_id',
|
||||
'ore_name',
|
||||
'quantity',
|
||||
'amount',
|
||||
'invoiced',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
'callback' => env('ESI_CALLBACK_URI'),
|
||||
'primary' => env('ESI_PRIMARY_CHAR', 93738489),
|
||||
'alliance' => env('ESI_ALLIANCE', 99004116),
|
||||
'corporation' => env('ESI_CORPORATION', 98287666)
|
||||
];
|
||||
?>
|
||||
Reference in New Issue
Block a user