diff --git a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php index 46c009bf1..8c279b075 100644 --- a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php +++ b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php @@ -6,6 +6,7 @@ use Illuminate\Console\Command; //Library use App\Library\Moons\MoonCalc; +use Comamnds\Library\CommandHelper; //Job use App\Jobs\Commands\Eve\ItemPricesUpdateJob; @@ -43,9 +44,19 @@ class ItemPricesUpdateCommand extends Command */ public function handle() { + //Declare variables $moonHelper = new MoonCalc; + $task = new CommandHelper('ItemPricesUpdateCommand'); + + //Set the task as started + $task->SetStartStatus(); + + //Fetch new prices from fuzzwork.co.uk for the item pricing schemes $moonHelper->FetchNewPrices(); - //ItemPricesUpdateJob::dispatch()->onQueue('default'); + //Set the task as completed + $task->SetStopStatus(); + + return 0; } } diff --git a/app/Console/Commands/Finances/UpdateAllianceWalletJournal.php b/app/Console/Commands/Finances/UpdateAllianceWalletJournal.php new file mode 100644 index 000000000..ea2f30ea4 --- /dev/null +++ b/app/Console/Commands/Finances/UpdateAllianceWalletJournal.php @@ -0,0 +1,64 @@ +SetStartStatus(); + + $fHelper->GetApiWalletJournal(1, $config['primary']); + + //Set the task as stopped + $task->SetStopStatus(); + + return 0; + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1dba96012..0dff4d665 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,10 @@ class Kernel extends ConsoleKernel * Eve Commands */ Commands\Eve\ItemPricesUpdateCommand::class, + /** + * Finance Commands + */ + Commands\Finances\UpdateAllianceWalletJournal::class, /** * Mining Tax Commands */ @@ -57,6 +61,13 @@ class Kernel extends ConsoleKernel $schedule->command('data:PurgeUsers') ->dailyAt('23:00'); + /** + * Finances Update Schedule + */ + $schedule->command('finances:UpdateJournals') + ->hourlyAt('45') + ->withoutOverlapping(); + /** * Item Update Schedule */ diff --git a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php index 69c1ab496..188ffe901 100644 --- a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php +++ b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php @@ -51,7 +51,7 @@ class MiningTaxesAdminController extends Controller /** * Mark an invoice paid */ - public function UpdateInvoice() { + public function UpdateInvoice(Request $request) { $this->validate($request, [ 'invoice_id' => 'required', 'status' => 'required', @@ -69,7 +69,7 @@ class MiningTaxesAdminController extends Controller /** * Delete an invoice and mark items paid */ - public function DeleteInvoice() { + public function DeleteInvoice(Request $request) { $this->validate($request, [ 'invoice_id' => 'required', ]); diff --git a/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php b/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php deleted file mode 100644 index 72de3eb23..000000000 --- a/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php +++ /dev/null @@ -1,77 +0,0 @@ -mHelper = new MoonCalc; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - //Get the characters for each non-invoiced ledger entry - $chars = Ledger::distinct('character_id')->pluck('character_id'); - - //Foreach character tally up the mining ledger totals to create an invoice - foreach($chars as $char) { - //Declare some variables we need for each loop - $invoice = array(); - $ores = array(); - $totalPrice = 0.00; - //Get the rows from the database for each character and the requirement of not been - //invoiced yet - $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; - } - - //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 - $totalPrice = $totalPrice * 0.20; - - //Create the invoice job - CreateMiningTaxesInvoiceJob::dispatch($ores, $totalPrice, $char->character_id); - } - } -} diff --git a/app/Jobs/Commands/MiningTaxes/CreateMiningTaxesInvoiceJob.php b/app/Jobs/Commands/MiningTaxes/CreateMiningTaxesInvoiceJob.php deleted file mode 100644 index e240d8530..000000000 --- a/app/Jobs/Commands/MiningTaxes/CreateMiningTaxesInvoiceJob.php +++ /dev/null @@ -1,105 +0,0 @@ -ores = $ores; - $this->totalPrice = $totalPrice; - $this->charId = $charId; - - $this->connection = 'redis'; - } - - /** - * Execute the job. - * - * @return void - */ - public function handle() - { - //Declare variables - $lookup = new LookupHelper; - $config = config('esi'); - $body = ''; - - //Get the character name from the character id - $charName = $lookup->CharacterIdToName($this->charId); - - //Generate an invoice id - $invoiceId = uniqid(); - - //Get the mining ledgers, and totalize the price - - $invoice = new Invoice; - $invoice->character_id = $this->charId; - $invoice->character_name = $charName; - $invoice->invoice_id = $invoiceId; - $invoice->invoice_amount = $this->totalPrice; - $invoice->date_issued = Carbon::now(); - $invoice->date_due = Carbon::now()->addDays(7); - $invoice->status = 'Pending'; - $invoice->save(); - - //Update the entries in the mining tax ledgers table to show the ore has been invoiced - Ledger::where([ - 'character_id' => $this->charId, - 'invoiced' => 'No', - ])->update([ - 'invoiced' => 'Yes', - 'invoice_id' => $invoiceId, - ]); - - $body .= "Dear Miner,

"; - $body .= "Mining Taxes are due for the following ores mined from alliance moons:
"; - foreach($this->ores as $ore => $quantity) { - $oreName = $lookup->ItemIdToName($ore); - $body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "
"; - } - $body .= "Please remit " . number_format($this->totalPrice, 2, ".", ",") . " ISK to Spatial Forces by " . $invoice->date_due . "
"; - $body .= "Set the reason for transfer as MMT: " . $invoice->invoice_id . "
"; - $body .= "
Sincerely,
Warped Intentions Leadership
"; - - //Mail the invoice to the character if the character is in - //Warped Intentions or Legacy - $subject = 'Warped Intentions Mining Taxes'; - $sender = $config['primary']; - $recipienttype = 'character'; - $recipient = $this->charId; - - ProcessSendEveMailJob::dispatch($body, $recipient, $recipientType, $subject, $sender)->onQueue('mail')->delay(Carbon::now()->addSeconds(30)); - } -} diff --git a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php b/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php deleted file mode 100644 index 505c3d506..000000000 --- a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesObserversJob.php +++ /dev/null @@ -1,116 +0,0 @@ -charId = $charId; - $this->corpId = $corpId; - - //Set the connection for the job - $this->connection = 'redis'; - } - - /** - * Execute the job. - * The job's duty is to get all of the corporation's moon mining observers, - * then store them in the database. - * - * @return void - */ - public function handle() - { - //Declare variables - $lookup = new LookupHelper; - $esiHelper = new Esi; - - //Get the configuration from the main site - $config = config('esi'); - - //Check for the esi scope - if(!$esiHelper->HaveEsiScope($this->charId, 'esi-industry.read_corporation_mining.v1') || !$esiHelper->HaveEsiScope($this->charId, 'esi-universe.read_structures.v1')) { - Log::critical('Esi scopes were not found for FetchMiningTaxesObserversJob.'); - return; - } - - //Get the refresh token for the character - $refreshToken = $esiHelper->GetRefreshToken($this->charId); - //Get the esi variable - $esi = $esiHelper->SetupEsiAuthentication($refreshToken); - - try { - $response = $esi->invoke('get', '/corporations/{corporation_id}/mining/observers', [ - 'corporation_id' => $this->corpId, - ]); - } catch(RequestFailedException $e) { - Log::critical("Failed to get moon observers in FetchMiningTaxesObservers"); - Log::critical($e); - } - - $resp = json_decode($response, false); - - //Run through the mining observers, and add them to the database - foreach($resp as $observer) { - - Observer::updateOrInsert([ - 'observer_id' => $observer->observer_id, - ], [ - 'observer_id' => $observer->observer_id, - 'observer_type' => $observer->observer_type, - 'last_updated' => $observer->last_updated, - ]); - } - - /** - * Cleanup stale data that hasn't been updated in at least 1 week. - */ - $date = Carbon::now()->subDays(60); - Observer::where('updated_at', '<', $date)->delete(); - } -} diff --git a/app/Library/Helpers/FinanceHelper.php b/app/Library/Helpers/FinanceHelper.php index f42f55f3d..77784d3a8 100644 --- a/app/Library/Helpers/FinanceHelper.php +++ b/app/Library/Helpers/FinanceHelper.php @@ -127,7 +127,7 @@ class FinanceHelper { if(isset($entry['first_party_id'])) { $awj->first_party_id = $entry['first_party_id']; } - if(isset($entry['rason'])) { + if(isset($entry['reason'])) { $awj->reason = $entry['reason']; } if(isset($entry['ref_type'])) {