From 3ff24118a5ab7338ef21bb8428076e262bac886a Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 7 Feb 2021 01:55:47 +0900 Subject: [PATCH] created mining taxes invoice job --- .../MiningTaxes/CalculateMiningTaxesJob.php | 3 + .../CreateMiningTaxesInvoiceJob.php | 60 ++++++++++++++++++- ..._01_10_164334_create_mining_tax_tables.php | 2 +- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php b/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php index 1684d49ea..32d5f352d 100644 --- a/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php +++ b/app/Jobs/Commands/MiningTaxes/CalculateMiningTaxesJob.php @@ -74,6 +74,9 @@ class CalculateMiningTaxesJob implements ShouldQueue $totalPrice += $price * $quantity; } + //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 index 8e6b2c042..e0c6ddec5 100644 --- a/app/Jobs/Commands/MiningTaxes/CreateMiningTaxesInvoiceJob.php +++ b/app/Jobs/Commands/MiningTaxes/CreateMiningTaxesInvoiceJob.php @@ -2,11 +2,23 @@ namespace App\Jobs\Commands\MiningTaxes; +//App 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; + +//Library +use App\Library\Lookups\LookupHelper; + +//Jobs +use App\Jobs\Commands\Eve\ProcessSendEveMailJob; + +//Models +use App\Models\MiningTaxes\Invoice; +use App\Models\MiningTaxes\Ledger; class CreateMiningTaxesInvoiceJob implements ShouldQueue { @@ -36,6 +48,52 @@ class CreateMiningTaxesInvoiceJob implements ShouldQueue */ 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(); + + $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', + ]); + + $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 " . $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/database/migrations/2021_01_10_164334_create_mining_tax_tables.php b/database/migrations/2021_01_10_164334_create_mining_tax_tables.php index 06bf1b13a..5725165ec 100644 --- a/database/migrations/2021_01_10_164334_create_mining_tax_tables.php +++ b/database/migrations/2021_01_10_164334_create_mining_tax_tables.php @@ -27,7 +27,7 @@ class CreateMiningTaxTables extends Migration 'Late', 'Paid Late', 'Deferred', - ]); + ])->default('Pending'); $table->timestamps(); });