added requests and some old commands
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
|
|||||||
|
|
||||||
//Library
|
//Library
|
||||||
use App\Library\Moons\MoonCalc;
|
use App\Library\Moons\MoonCalc;
|
||||||
|
use Comamnds\Library\CommandHelper;
|
||||||
|
|
||||||
//Job
|
//Job
|
||||||
use App\Jobs\Commands\Eve\ItemPricesUpdateJob;
|
use App\Jobs\Commands\Eve\ItemPricesUpdateJob;
|
||||||
@@ -43,9 +44,19 @@ class ItemPricesUpdateCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
//Declare variables
|
||||||
$moonHelper = new MoonCalc;
|
$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();
|
$moonHelper->FetchNewPrices();
|
||||||
|
|
||||||
//ItemPricesUpdateJob::dispatch()->onQueue('default');
|
//Set the task as completed
|
||||||
|
$task->SetStopStatus();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Finances;
|
||||||
|
|
||||||
|
//Internal Library
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
//Application Library
|
||||||
|
use App\Library\Helpers\FinanceHelper;
|
||||||
|
use Commands\Library\CommandHelper;
|
||||||
|
|
||||||
|
//Models
|
||||||
|
use App\Models\Finances\AllianceWalletJournal;
|
||||||
|
|
||||||
|
class UpdateAllianceWalletJournal extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'finances:UpdateJournals';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = "Update the holding corporation's finance journal.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
//Declare variables
|
||||||
|
$fHelper = new FinanceHelper;
|
||||||
|
$config = config('esi');
|
||||||
|
$task = new CommandHelper('UpdateAllianceWalletJournal');
|
||||||
|
//Set the task as started
|
||||||
|
$task->SetStartStatus();
|
||||||
|
|
||||||
|
$fHelper->GetApiWalletJournal(1, $config['primary']);
|
||||||
|
|
||||||
|
//Set the task as stopped
|
||||||
|
$task->SetStopStatus();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,10 @@ class Kernel extends ConsoleKernel
|
|||||||
* Eve Commands
|
* Eve Commands
|
||||||
*/
|
*/
|
||||||
Commands\Eve\ItemPricesUpdateCommand::class,
|
Commands\Eve\ItemPricesUpdateCommand::class,
|
||||||
|
/**
|
||||||
|
* Finance Commands
|
||||||
|
*/
|
||||||
|
Commands\Finances\UpdateAllianceWalletJournal::class,
|
||||||
/**
|
/**
|
||||||
* Mining Tax Commands
|
* Mining Tax Commands
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +61,13 @@ class Kernel extends ConsoleKernel
|
|||||||
$schedule->command('data:PurgeUsers')
|
$schedule->command('data:PurgeUsers')
|
||||||
->dailyAt('23:00');
|
->dailyAt('23:00');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finances Update Schedule
|
||||||
|
*/
|
||||||
|
$schedule->command('finances:UpdateJournals')
|
||||||
|
->hourlyAt('45')
|
||||||
|
->withoutOverlapping();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item Update Schedule
|
* Item Update Schedule
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class MiningTaxesAdminController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Mark an invoice paid
|
* Mark an invoice paid
|
||||||
*/
|
*/
|
||||||
public function UpdateInvoice() {
|
public function UpdateInvoice(Request $request) {
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'invoice_id' => 'required',
|
'invoice_id' => 'required',
|
||||||
'status' => 'required',
|
'status' => 'required',
|
||||||
@@ -69,7 +69,7 @@ class MiningTaxesAdminController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Delete an invoice and mark items paid
|
* Delete an invoice and mark items paid
|
||||||
*/
|
*/
|
||||||
public function DeleteInvoice() {
|
public function DeleteInvoice(Request $request) {
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'invoice_id' => 'required',
|
'invoice_id' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTax\Ledger;
|
|
||||||
use App\Models\MiningTax\Invoice;
|
|
||||||
|
|
||||||
class CalculateMiningTaxesJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
//Private variables
|
|
||||||
private $mHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//Declare variables for use in the handler
|
|
||||||
$this->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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\Commands\Eve\ProcessSendEveMailJob;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\MiningTaxes\Invoice;
|
|
||||||
use App\Models\MiningTaxes\Ledger;
|
|
||||||
|
|
||||||
class CreateMiningTaxesInvoiceJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
//Private Variables
|
|
||||||
private $ores;
|
|
||||||
private $totalPrices;
|
|
||||||
private $charId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($ores = [], $totalPrice, $charId)
|
|
||||||
{
|
|
||||||
$this->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,<br><br>";
|
|
||||||
$body .= "Mining Taxes are due for the following ores mined from alliance moons: <br>";
|
|
||||||
foreach($this->ores as $ore => $quantity) {
|
|
||||||
$oreName = $lookup->ItemIdToName($ore);
|
|
||||||
$body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "Please remit " . number_format($this->totalPrice, 2, ".", ",") . " ISK to Spatial Forces by " . $invoice->date_due . "<br>";
|
|
||||||
$body .= "Set the reason for transfer as MMT: " . $invoice->invoice_id . "<br>";
|
|
||||||
$body .= "<br>Sincerely,<br>Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs\Commands\MiningTaxes;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Log;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//App Library
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use App\Library\Helpers\LookupHelper;
|
|
||||||
|
|
||||||
//App Models
|
|
||||||
use App\Models\MiningTax\Observer;
|
|
||||||
|
|
||||||
class FetchMiningTaxesObserversJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout in seconds
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $timeout = 3600;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Number of job retries
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $tries = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Job Variables
|
|
||||||
*/
|
|
||||||
private $charId;
|
|
||||||
private $corpId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($charId = null, $corpId = null)
|
|
||||||
{
|
|
||||||
$this->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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -127,7 +127,7 @@ class FinanceHelper {
|
|||||||
if(isset($entry['first_party_id'])) {
|
if(isset($entry['first_party_id'])) {
|
||||||
$awj->first_party_id = $entry['first_party_id'];
|
$awj->first_party_id = $entry['first_party_id'];
|
||||||
}
|
}
|
||||||
if(isset($entry['rason'])) {
|
if(isset($entry['reason'])) {
|
||||||
$awj->reason = $entry['reason'];
|
$awj->reason = $entry['reason'];
|
||||||
}
|
}
|
||||||
if(isset($entry['ref_type'])) {
|
if(isset($entry['ref_type'])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user