From 59868bb63abe2fb00bebe8bce52161c6f04c3d4e Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 7 Mar 2021 06:20:19 +0900 Subject: [PATCH] mining taxes --- .../MiningTaxes/MiningTaxesInvoices.php | 9 ++- .../MiningTaxes/MiningTaxesPayments.php | 7 +- app/Console/Kernel.php | 11 +-- .../MiningTaxesAdminController.php | 24 +++--- .../MiningTaxes/MiningTaxesController.php | 80 ++++++++++++++++++- config/esi.php | 2 +- .../miningtax/user/display/calendar.blade.php | 14 ++++ routes/web.php | 4 +- 8 files changed, 129 insertions(+), 22 deletions(-) create mode 100644 resources/views/miningtax/user/display/calendar.blade.php diff --git a/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php b/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php index 1dc0eed4b..7f59c8b05 100644 --- a/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php +++ b/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php @@ -123,10 +123,17 @@ class MiningTaxesInvoices extends Command $body .= "Mining Taxes are due for the following ores mined from alliance moons:
"; foreach($ores as $ore => $quantity) { $oreName = $lookup->ItemIdToName($ore); - $body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "
"; + $body .= $oreName . ": " . number_format(round($quantity * $config['mining_tax']), 0, ".", ",") . "
"; } $body .= "Please remit " . number_format($totalPrice, 2, ".", ",") . " ISK to Spatial Forces by " . $invoice->date_due . "
"; $body .= "Set the reason for transfer as MMT: " . $invoice->invoice_id . "
"; + $body .= "

"; + $body .= "You can also send a contract with the following ores in the contract with the reason set as MMT: " . $invoice->invoice_id . "
"; + foreach($ores as $ore => $quantity) { + $oreName = $lookup->ItemIdToName($ore); + $body .= $oreName . ": " . number_format(round($quantity * $config['mining_tax']), ".", ",") . "
"; + } + $body .= "
"; $body .= "
Sincerely,
Warped Intentions Leadership
"; //Mail the invoice to the character if the character is in diff --git a/app/Console/Commands/MiningTaxes/MiningTaxesPayments.php b/app/Console/Commands/MiningTaxes/MiningTaxesPayments.php index 3ab71c116..e9a091d8f 100644 --- a/app/Console/Commands/MiningTaxes/MiningTaxesPayments.php +++ b/app/Console/Commands/MiningTaxes/MiningTaxesPayments.php @@ -2,6 +2,7 @@ namespace App\Console\Commands\MiningTaxes; +//Internal Library use Illuminate\Console\Command; use Log; use Carbon\Carbon; @@ -9,6 +10,8 @@ use Carbon\Carbon; //Application Library use Commands\Library\CommandHelper; use App\Library\Lookup\LookupHelper; +use Seat\Eseye\Exceptions\RequestFailedException; +use App\Library\Esi\Esi; //Models use App\Models\MiningTaxes\Invoice; @@ -122,7 +125,7 @@ class MiningTaxesPayments extends Command } else { //If we didn't found a journal entry, then we shall check the contracts for a correct entry foreach($contracts as $contract) { - if(($contract->title == $invoice->invoice_id) && ($currentTime->lessThanOrEqualTo($invoice->due_date))) { + if(($contract->title == ("MMT: " . $invoice->invoice_id)) && ($currentTime->lessThanOrEqualTo($invoice->due_date))) { Invoice::where([ 'invoice_i' => $invoice->invoice_id, ])->update([ @@ -130,7 +133,7 @@ class MiningTaxesPayments extends Command ]); } - if(($contract->title == $invoice_id) && ($currentTime->greaterThan($invoice->due_date))) { + if(($contract->title == ("MMT: " . $invoice_id)) && ($currentTime->greaterThan($invoice->due_date))) { Invoice::where([ 'invoice_id' => $invoice->invoice_id, ])->update([ diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8a22faa10..18a23a4d4 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -71,14 +71,15 @@ class Kernel extends ConsoleKernel ->dailyAt('22:00') ->withoutOverlapping(); $schedule->command('MiningTaxes:Ledgers') - ->hourlyAt('05') + ->dailyAt('20:00') ->withoutOverlapping(); - /* $schedule->command('MiningTaxes:Invoices') - ->dailyAt('23:00'); + ->weeklyOn(1, '8:00') + ->withoutOverlapping(); $schedule->command('MiningTaxes:Payments') - ->dailyAt('23:50'); - */ + ->hourlyAt('15') + ->withoutOverlapping(); + } /** diff --git a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php index 3da32ae95..168c19005 100644 --- a/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php +++ b/app/Http/Controllers/MiningTaxes/MiningTaxesAdminController.php @@ -5,14 +5,26 @@ namespace App\Http\Controllers\MiningTaxes; //Internal Library use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Log; +use Carbon\Carbon; +use Khill\Lavacharts\Lavacharts; +use Auth; //Application Library +use App\Library\Helpers\LookupHelper; +use App\Library\Helpers\StructureHelper; +use Seat\Eseye\Exceptions\RequestFailedException; +use App\Library\Esi\Esi; //Models use App\Models\MiningTax\Invoice; use App\Models\MiningTax\Observer; use App\Models\MiningTax\Ledger; - +use App\Models\MiningTax\Payment; +use App\Models\Moon\ItemComposition; +use App\Models\Moon\MineralPrice; +use App\Models\Esi\EsiToken; +use App\Models\Esi\EsiScope; class MiningTaxesAdminController extends Controller { @@ -82,13 +94,5 @@ class MiningTaxesAdminController extends Controller ])->get()->paginate(50); return view('miningtax.admin.display.paidinvoices')->with('invoices', $invoices); - } - - /** - * Display admin mining ledgers by month - */ - public function DisplayMonthlyMiningLedgers() { - - } - + } } diff --git a/app/Http/Controllers/MiningTaxes/MiningTaxesController.php b/app/Http/Controllers/MiningTaxes/MiningTaxesController.php index 8e0c89d9b..cf18a8fb2 100644 --- a/app/Http/Controllers/MiningTaxes/MiningTaxesController.php +++ b/app/Http/Controllers/MiningTaxes/MiningTaxesController.php @@ -93,10 +93,16 @@ class MiningTaxesController extends Controller //Declare variables $structures = array(); $sHelper = new StructureHelper; + $esiHelper = new Esi; + $config = config('esi'); + + if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) { + return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the correct scopes for the services site.'); + } //Get the esi data for extractions try { - $extractions = $this->esi->invoke('get', '/corporation/{corporation_id}/mining/extractions/', [ + $extractions = $esi->invoke('get', '/corporation/{corporation_id}/mining/extractions/', [ 'corporation_id' => $config['corporation'], ]); } catch(RequestFailedException $e) { @@ -119,6 +125,78 @@ class MiningTaxesController extends Controller return view('miningtax.user.display.upcoming')->with('extractions', $extractions); } + /** + * Display a calendar of upcoming extractions + */ + public function DisplayExtractionCalendar() { + //Declare variables + $structures = array(); + $sHelper = new StructureHelper; + $lava = new Lavacharts; + $esiHelper = new Esi; + $config = config('esi'); + + //Check for the correct scopes + if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-industry.read_corporation_mining.v1')) { + return redirect('/dashboard')->with('error', 'Tell the nub Minerva to register the correct scopes for the services site.'); + } + + //Get the esi data for extractions + try { + $response = $esi->invoke('get', '/corporation/{corporation_id}/mining/extractions', [ + 'corporation_id' => $config['corporation'], + ]); + } catch(RequestFailedException $e) { + Log::critical('Could not retrieve the extractions from ESI in DisplayExtractionCalendar in MiningTaxesController'); + return redirect('/dashboard')->with('error', 'Failed to get extraction data from ESI'); + } + + //Decode the extraction data from ESI + $extractions = json_decode($response, false); + + /** + * Create a 3 month calendar for the past, current, and future extractions + */ + //Create the data tables + $calendar = $lava->DataTable(); + + $calendar->addDateTimeColumn('Date') + ->addBooleanColumn('YesNo') + ->addStringColumn('Extractions'); + + foreach($extractions as $extract) { + $calendar->addRow([ + $extract->chunk_arrival_time, + 1 + ]); + } + + $lava->CalendarChart('Extractions', $calendar, [ + 'title' => 'Upcoming Extractions', + 'unusedMonthOutlineColor' => [ + 'stroke' => '#ECECEC', + 'strokeOpacity' => 0.75, + 'strokeWidth' => 1, + ], + 'dayOfWeekLabel' => [ + 'color' => '#4f5b0d', + 'fontSize' => 16, + 'italic' => true, + ], + 'noDataPattern' => [ + 'color' => '#DDD', + 'backgroundColor' => '#11FFFF', + ], + 'colorAxis' => [ + 'values' => [0, 100], + 'colors' => ['black', 'green'], + ], + ]); + + return view('miningtax.user.display.calendar')->with('calendar', $calendar) + ->with('lava', $lava); + } + /** * Display the ledger for the moons. */ diff --git a/config/esi.php b/config/esi.php index 46b2ae3fc..98f4e6f69 100644 --- a/config/esi.php +++ b/config/esi.php @@ -7,6 +7,6 @@ 'primary' => env('ESI_PRIMARY_CHAR', 93738489), 'alliance' => env('ESI_ALLIANCE', 99004116), 'corporation' => env('ESI_CORPORATION', 98287666), - 'mining_tax' => 0.10, + 'mining_tax' => 0.15, ]; ?> \ No newline at end of file diff --git a/resources/views/miningtax/user/display/calendar.blade.php b/resources/views/miningtax/user/display/calendar.blade.php new file mode 100644 index 000000000..c0d41a4a0 --- /dev/null +++ b/resources/views/miningtax/user/display/calendar.blade.php @@ -0,0 +1,14 @@ +@extends('layouts.user.dashb4') +@section('content') +
+
+
+
+

Mining Calendar

+
+
+ @calendarchart('calendar', 'calendar_div') +
+
+
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 71c61579f..a81ffd54b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -69,12 +69,12 @@ Route::group(['middleware' => ['auth']], function(){ */ Route::get('/miningtax/display/invoices', 'MiningTaxes\MiningTaxesController@DisplayMiningTaxesInvoices'); Route::get('/miningtax/display/extractions', 'MiningTaxes\MiningTaxesController@DisplayUpcomingExtractions'); - Route::get('miningtax/display/ledgers', 'MiningTaxes\MiningTaxesController@DisplayMoonLedgers'); + Route::get('/miningtax/display/ledgers', 'MiningTaxes\MiningTaxesController@DisplayMoonLedgers'); + Route::get('/miningtax/display/calendar', 'MiningTaxes\MiningTaxesController@DisplayExtractionCalendar'); Route::get('/miningtax/admin/display/unpaid', 'MiningTaxes\MiningTaxesAdminController@DisplayUnpaidInvoice'); Route::post('/miningtax/admin/update/invoice', 'MiningTaxes\MiningTaxesAdminController@UpdateInvoice'); Route::post('/miningtax/admin/delete/invoice', 'MiningTaxes\MiningTaxesAdminController@DeleteInvoice'); Route::get('/miningtax/admin/display/paid', 'MiningTaxes\MiningTaxesAdminController@DisplayPaidInvoices'); - Route::get('/miningtax/admin/display/monthly/ledgers', 'MiningTaxes\MiningTaxesAdminController@DisplayMonthlyMiningLedgers'); /** * Scopes Controller display pages