created mining taxes invoice job

This commit is contained in:
2021-02-07 01:55:47 +09:00
parent d4954bc7bf
commit 3ff24118a5
3 changed files with 63 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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,<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 " . $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));
}
}

View File

@@ -27,7 +27,7 @@ class CreateMiningTaxTables extends Migration
'Late',
'Paid Late',
'Deferred',
]);
])->default('Pending');
$table->timestamps();
});