update for pi sales to store in database

This commit is contained in:
2019-04-19 22:08:25 -05:00
parent 1ef6e4bb22
commit 1116514c22
4 changed files with 180 additions and 19 deletions

View File

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

View File

@@ -0,0 +1,59 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Finances;
use DB;
use App\Models\Finances\PISaleJournal;
class PISale {
public InsertPISale($journal, $corpId) {
//Insert the PI Sale into the database
if(!PISaleJournal::where(['id' => $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();
}
}
}
?>

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models\Finances;
use Illuminate\Database\Eloquent\Model;
class PISaleJournal extends Model
{
/**
* Table Name
*/
protected $table = 'pi_sale_journal';
/**
* Timestamps
*/
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'id',
'corporation_id',
'division',
'amount',
'balance',
'context_id',
'context_id_type',
'date',
'description',
'first_party_id',
'reason',
'ref_type',
'second_party_id',
'tax',
'tax_receiver_id',
];
}

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePISaleJournal extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('pi_sale_journal')) {
Schema::create('pi_sale_journal', function(Blueprint $table) {
$table->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');
}
}