From 1116514c227e448359a25b48ea4f4a415f26851f Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Fri, 19 Apr 2019 22:08:25 -0500 Subject: [PATCH] update for pi sales to store in database --- app/Library/Finances/Helper/FinanceHelper.php | 52 ++++++++++------ app/Library/Finances/PISale.php | 59 +++++++++++++++++++ app/Models/Finances/PISaleJournal.php | 41 +++++++++++++ ...9_000000_create_pi_sale_journals_table.php | 47 +++++++++++++++ 4 files changed, 180 insertions(+), 19 deletions(-) create mode 100644 app/Library/Finances/PISale.php create mode 100644 app/Models/Finances/PISaleJournal.php create mode 100644 database/migrations/2019_04_19_000000_create_pi_sale_journals_table.php diff --git a/app/Library/Finances/Helper/FinanceHelper.php b/app/Library/Finances/Helper/FinanceHelper.php index be5a3d689..a4bb0192d 100644 --- a/app/Library/Finances/Helper/FinanceHelper.php +++ b/app/Library/Finances/Helper/FinanceHelper.php @@ -23,6 +23,7 @@ use App\Library\Finances\JumpBridgeTax; use App\Library\Finances\StructureIndustryTax; use App\Library\Finances\OfficeFee; use App\Library\Finances\PlanetProductionTax; +use App\Library\Finances\PISale; use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Eseye; @@ -34,6 +35,12 @@ class FinanceHelper { //Get the ESI refresh token for the corporation to add new wallet journals into the database $token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']); $scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']); + + //Setup array for PI items + $pi_items = [ + + ]; + //If the token is not found, send the user an eve mail, and just exit out of the function if(!isset($token[0]->refresh_token) || !isset($scope[0]->scope)) { //Register a mail to be dispatched as a job @@ -92,25 +99,32 @@ class FinanceHelper { //The PutWalletJournal function checks to see if it's already in the database. foreach($wallet as $entry) { if($entry['amount'] > 0) { - if($entry['ref_type'] == 'brokers_fee') { - $market = new MarketTax(); - $market->InsertMarketTax($entry, $corpId, $division); - } else if($entry['ref_type'] == 'reprocessing_tax') { - $reprocessing = new ReprocessingTax(); - $reprocessing->InsertReprocessingTax($entry, $corpId, $division); - } else if($entry['ref_type'] == 'structure_gate_jump') { - $jb = new JumpBridgeTax(); - $jb->InsertJumpBridgeTax($entry, $corpId, $division); - } else if($entry['ref_type'] == 'player_donation' || - ($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) { - $other = new PlayerDonation(); - $other->InsertPlayerDonation($entry, $corpId, $division); - } else if($entry['ref_type'] == 'industry_job_tax' && $entry['second_party_id'] == 98287666) { - $industry = new StructureIndustryTax(); - $industry->InsertStructureIndustryTax($entry, $corpId, $division); - } else if($entry['ref_type'] == 'office_rental_fee' && $entry['second_party_id'] == 98287666) { - $office = new OfficeFee(); - $office->InsertOfficeFee($entry, $corpId, $division); + if($division == 3 && $charId == 94415555) { + if(in_array($entry['type_id'], $pi_items, true)) { + $pi = new PISale(); + $pi->InsertPISale($entry); + } + } else { + if($entry['ref_type'] == 'brokers_fee') { + $market = new MarketTax(); + $market->InsertMarketTax($entry, $corpId, $division); + } else if($entry['ref_type'] == 'reprocessing_tax') { + $reprocessing = new ReprocessingTax(); + $reprocessing->InsertReprocessingTax($entry, $corpId, $division); + } else if($entry['ref_type'] == 'structure_gate_jump') { + $jb = new JumpBridgeTax(); + $jb->InsertJumpBridgeTax($entry, $corpId, $division); + } else if($entry['ref_type'] == 'player_donation' || + ($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) { + $other = new PlayerDonation(); + $other->InsertPlayerDonation($entry, $corpId, $division); + } else if($entry['ref_type'] == 'industry_job_tax' && $entry['second_party_id'] == 98287666) { + $industry = new StructureIndustryTax(); + $industry->InsertStructureIndustryTax($entry, $corpId, $division); + } else if($entry['ref_type'] == 'office_rental_fee' && $entry['second_party_id'] == 98287666) { + $office = new OfficeFee(); + $office->InsertOfficeFee($entry, $corpId, $division); + } } } diff --git a/app/Library/Finances/PISale.php b/app/Library/Finances/PISale.php new file mode 100644 index 000000000..c5ecd69fb --- /dev/null +++ b/app/Library/Finances/PISale.php @@ -0,0 +1,59 @@ + $journal['id']])->exists()) { + $entry = new PISaleJournal; + $entry->id = $journal['id']; + $entry->corporation_id = $corpId; + $entry->division = $division; + if(isset($journal['amount'])) { + $entry->amount = $journal['amount']; + } + if(isset($journal['balance'])) { + $entry->balance = $journal['balance']; + } + if(isset($journal['context_id'])) { + $entry->context_id = $journal['context_id']; + } + if(isset($journal['context_id_type'])) { + $entry->context_id_type = $journal['context_id_type']; + } + $entry->date = $esiHelper->DecodeDate($journal['date']); + $entry->description = $journal['description']; + if(isset($journal['first_party_id'])) { + $entry->first_party_id = $journal['first_party_id']; + } + if(isset($journal['reason'])) { + $entry->reason = $journal['reason']; + } + $entry->ref_type = $journal['ref_type']; + if(isset($journal['second_party_id'])) { + $entry->second_party_id = $journal['second_party_id']; + } + if(isset($journal['tax'])) { + $entry->tax = $journal['tax']; + } + if(isset($journal['tax_receiver_id'])) { + $entry->tax_receiver_id = $journal['tax_receiver_id']; + } + $entry->save(); + } + } + + } + +?> \ No newline at end of file diff --git a/app/Models/Finances/PISaleJournal.php b/app/Models/Finances/PISaleJournal.php new file mode 100644 index 000000000..ad00fccc1 --- /dev/null +++ b/app/Models/Finances/PISaleJournal.php @@ -0,0 +1,41 @@ +string('id')->unique(); + $table->integer('corporation_id')->nullabe(); + $table->integer('division')->default(0); + $table->decimal('amount', 20, 2)->nullable(); + $table->decimal('balance', 20, 2)->nullable(); + $table->bigInteger('context_id')->nullable(); + $table->string('context_id_type')->nullable(); + $table->dateTime('date')->nullabe(); + $table->string('description')->nullabe(); + $table->integer('first_party_id')->nullable(); + $table->string('reason')->default(' '); + $table->string('ref_type')->nullabe(); + $table->integer('second_party_id')->nullable(); + $table->decimal('tax', 20, 2)->default(0.00); + $table->integer('tax_receiver_id')->nullable(); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('pi_sale_journal'); + } +}