From ade9da5be75dd88994e52efa3a2b9a1e4a3ba81f Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Mon, 15 Mar 2021 20:44:27 +0900 Subject: [PATCH] item price update issue --- .../Commands/Eve/ItemPricesUpdateCommand.php | 2 +- .../MiningTaxes/MiningTaxesInvoices.php | 41 ++++++------- app/Console/Kernel.php | 4 -- .../FetchMiningTaxesLedgersJob.php | 2 +- .../ProcessMiningTaxesLedgersJob.php | 57 ++++++++++++------- app/Models/MiningTax/Invoice.php | 1 + ..._01_10_164334_create_mining_tax_tables.php | 1 + 7 files changed, 61 insertions(+), 47 deletions(-) diff --git a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php index 8c279b075..db22b7e30 100644 --- a/app/Console/Commands/Eve/ItemPricesUpdateCommand.php +++ b/app/Console/Commands/Eve/ItemPricesUpdateCommand.php @@ -6,7 +6,7 @@ use Illuminate\Console\Command; //Library use App\Library\Moons\MoonCalc; -use Comamnds\Library\CommandHelper; +use Commands\Library\CommandHelper; //Job use App\Jobs\Commands\Eve\ItemPricesUpdateJob; diff --git a/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php b/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php index 2213b9256..36a796b3b 100644 --- a/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php +++ b/app/Console/Commands/MiningTaxes/MiningTaxesInvoices.php @@ -95,26 +95,6 @@ class MiningTaxesInvoices extends Command //Generate a unique invoice id $invoiceId = uniqid(); - - //Save the invoice model - $invoice = new Invoice; - $invoice->character_id = $charId; - $invoice->character_name = $charName; - $invoice->invoice_id = $invoiceId; - $invoice->invoice_amount = $invoiceAmount; - $invoice->date_issued = Carbon::now(); - $invoice->date_due = Carbon::now()->addDays(7); - $invoice->status = 'Pending'; - $invoice->save(); - - //Update the ledger entries - Ledger::where([ - 'character_id' => $charId, - 'invoiced' => 'No', - ])->update([ - 'invoiced' => 'Yes', - 'invoice_id' => $invoiceId, - ]); //Create the mail body $body .= "Dear Miner,

"; @@ -143,6 +123,27 @@ class MiningTaxesInvoices extends Command //Send the Eve Mail Job to the queue to be dispatched ProcessSendEveMailJob::dispatch($body, $recipient, $recipientType, $subject, $sender)->onQueue('mail'); + + //Save the invoice model + $invoice = new Invoice; + $invoice->character_id = $charId; + $invoice->character_name = $charName; + $invoice->invoice_id = $invoiceId; + $invoice->invoice_amount = $invoiceAmount; + $invoice->date_issued = Carbon::now(); + $invoice->date_due = Carbon::now()->addDays(7); + $invoice->status = 'Pending'; + $invoice->mail_body = $body; + $invoice->save(); + + //Update the ledger entries + Ledger::where([ + 'character_id' => $charId, + 'invoiced' => 'No', + ])->update([ + 'invoiced' => 'Yes', + 'invoice_id' => $invoiceId, + ]); } //Set the task as stopped diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b33523a80..3b4f8b177 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -36,7 +36,6 @@ class Kernel extends ConsoleKernel Commands\MiningTaxes\MiningTaxesLedgers::class, Commands\MiningTaxes\MiningTaxesObservers::class, Commands\MiningTaxes\MiningTaxesPayments::class, - Commands\MiningTaxes\MiningTaxesDataCleanup::class, ]; /** @@ -89,9 +88,6 @@ class Kernel extends ConsoleKernel $schedule->command('MiningTaxes:Payments') ->hourlyAt('15') ->withoutOverlapping(); - $schedule->command('MiningTaxes:CleanupData') - ->weekly(7, '11:15') - ->withoutOverlapping(); } /** diff --git a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesLedgersJob.php b/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesLedgersJob.php index 7d701ec29..3b09d31c2 100644 --- a/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesLedgersJob.php +++ b/app/Jobs/Commands/MiningTaxes/FetchMiningTaxesLedgersJob.php @@ -141,7 +141,7 @@ class FetchMiningTaxesLedgersJob implements ShouldQueue //Dispatch jobs to process each of the mining ledger entries foreach($ledgers as $ledger) { - ProcessMiningTaxesLedgersJob::dispatch($ledger)->onQueue('miningtaxes'); + ProcessMiningTaxesLedgersJob::dispatch($ledger, $this->observerId)->onQueue('miningtaxes'); } } diff --git a/app/Jobs/Commands/MiningTaxes/ProcessMiningTaxesLedgersJob.php b/app/Jobs/Commands/MiningTaxes/ProcessMiningTaxesLedgersJob.php index 5774eb8fe..72575c526 100644 --- a/app/Jobs/Commands/MiningTaxes/ProcessMiningTaxesLedgersJob.php +++ b/app/Jobs/Commands/MiningTaxes/ProcessMiningTaxesLedgersJob.php @@ -40,19 +40,21 @@ class ProcessMiningTaxesLedgersJob implements ShouldQueue * Job Variables */ private $ledger; + private $observerId; /** * Create a new job instance. * * @return void */ - public function __construct($ledger) + public function __construct($ledger, $observerId) { //Set the connection for the job $this->connection = 'redis'; //Import variables from the calling function $this->ledger = $ledger; + $this->observerId = $observerId; } /** @@ -74,25 +76,38 @@ class ProcessMiningTaxesLedgersJob implements ShouldQueue //Calculate the total price based on the amount $amount = $price * $this->ledger->quantity; - //Insert or update the entry in the database - $item = Ledger::updateOrCreate([ - 'character_id' => $ledger->character_id, - 'character_name' => $charName, - 'observer_id' => $obs->observer_id, - 'last_updated' => $ledger->last_updated, - 'type_id' => $ledger->type_id, - 'ore_name' => $typeName, - 'quantity' => $ledger->quantity, - 'amount' => $amount, - ], [ - 'character_id' => $ledger->character_id, - 'character_name' => $charName, - 'observer_id' => $obs->observer_id, - 'last_updated' => $ledger->last_updated, - 'type_id' => $ledger->type_id, - 'ore_name' => $typeName, - 'quantity' => $ledger->quantity, - 'amount' => $amount, - ]); + $found = Ledger::where([ + + ])->count(); + + if($found > 0) { + Ledger::where([ + 'character_id' => $this->ledger->character_id, + 'character_name' => $charName, + 'observer_id' => $this->observerId, + 'type_id' => $this->ledger->type_id, + 'ore_name' => $typeName, + ])->update([ + 'character_id' => $this->ledger->character_id, + 'character_name' => $charName, + 'observer_id' => $this->observerId, + 'last_updated' => $this->ledger->last_updated, + 'type_id' => $this->ledger->type_id, + 'ore_name' => $typeName, + 'quantity' => $this->ledger->quantity, + 'amount' => $amount, + ]); + } else { + $ledg = new Ledger; + $ledg->character_id = $this->character_id; + $ledg->character_name = $charName; + $ledg->observer_id = $this->observerId; + $ledg->last_updated = $ledger->last_updated; + $ledg->type_id = $ledger->type_id; + $ledg->ore_name = $typeName; + $ledg->quantity = $ledger->quantity; + $ledg->amount = $amount; + $ledg->save(); + } } } diff --git a/app/Models/MiningTax/Invoice.php b/app/Models/MiningTax/Invoice.php index 154dae5b3..a6e084a66 100644 --- a/app/Models/MiningTax/Invoice.php +++ b/app/Models/MiningTax/Invoice.php @@ -28,6 +28,7 @@ class Invoice extends Model 'date_issued', 'date_due', 'status', + 'mail_body', ]; public function getPayment() { 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 b0d1005bd..4a6901030 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 @@ -30,6 +30,7 @@ class CreateMiningTaxTables extends Migration 'Deferred', 'Deleted', ])->default('Pending'); + $table->text('mail_body')->nullable(); $table->timestamps(); }); }