diff --git a/app/Http/Controllers/TaxesController.php b/app/Http/Controllers/TaxesController.php index 4638941ea..cd4b6523d 100644 --- a/app/Http/Controllers/TaxesController.php +++ b/app/Http/Controllers/TaxesController.php @@ -63,6 +63,11 @@ class TaxesController extends Controller 'date' => $date['start']->toFormattedDateString(), 'gross' => number_format($tHelper->GetJumpGateGross($date['start'], $date['end']), 2, ".", ","), ]; + + $pitransactions[] = [ + 'date' => $date['start']->toFormattedDateString(), + 'gross' => number_format($tHelper->GetPiGross($date['start'], $date['end']), 2, ".", ","), + ] } //Return the view with the compact variable list @@ -71,6 +76,7 @@ class TaxesController extends Controller ->with('reprocessings', $reprocessings) ->with('offices', $offices) ->with('markets', $markets) - ->with('jumpgates', $jumpgates); + ->with('jumpgates', $jumpgates) + ->with('pigross', $pitransactions); } } diff --git a/app/Library/Finances/PISale.php b/app/Library/Finances/PISale.php index c5ecd69fb..9a67cb261 100644 --- a/app/Library/Finances/PISale.php +++ b/app/Library/Finances/PISale.php @@ -9,46 +9,48 @@ use DB; + use App\Library\Esi\Esi; + use App\Models\Finances\PISaleJournal; class PISale { public InsertPISale($journal, $corpId) { + //Create the ESI Helper class + $esiHelper = new Esi; + //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['client_id'])) { + $entry->client_id = $journal['client_id']; } - if(isset($journal['balance'])) { - $entry->balance = $journal['balance']; + if(isset($journal['date'])) { + $entry->date = $esiHelper->DecoateDate($journal['date']); } - if(isset($journal['context_id'])) { - $entry->context_id = $journal['context_id']; + if(isset($journal['is_buy'])) { + $entry->is_buy = $journal['is_buy']; } - if(isset($journal['context_id_type'])) { - $entry->context_id_type = $journal['context_id_type']; + if(isset($journal['journal_ref_id'])) { + $entry->journal_ref_id = $journal['journal_ref_id']; } - $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['location_id'])) { + $entry->location_id = $journal['location_id']; } - if(isset($journal['reason'])) { - $entry->reason = $journal['reason']; + if(isset($journal['quantity'])) { + $entry->quantity = $journal['quantity']; } - $entry->ref_type = $journal['ref_type']; - if(isset($journal['second_party_id'])) { - $entry->second_party_id = $journal['second_party_id']; + if(isset($journal['transaction_id'])) { + $entry->transaction_id = $journal['transaction_id']; } - if(isset($journal['tax'])) { - $entry->tax = $journal['tax']; + if(isset($journal['type_id'])) { + $entry->type_id = $journal['type_id']; } - if(isset($journal['tax_receiver_id'])) { - $entry->tax_receiver_id = $journal['tax_receiver_id']; + if(isset($journal['unit_price'])) { + $entry->unit_price = $journal['unit_price']; } $entry->save(); } diff --git a/app/Library/Taxes/TaxesHelper.php b/app/Library/Taxes/TaxesHelper.php index ebcea5848..6c0a1c8c8 100644 --- a/app/Library/Taxes/TaxesHelper.php +++ b/app/Library/Taxes/TaxesHelper.php @@ -98,6 +98,18 @@ class TaxesHelper { return $revenue; } + public function GetPiGross($start, $end) { + $revenue = 0.00; + + $grosses = PISaleJournal::whereBetween('date', [$start, $end]); + + foreach($grosses as $gross) { + $revenue += ($gross['quantity'] * $gross['unit_price']); + } + + return $revenue; + } + /** * Returns a set of dates from now until the amount of months has passed * diff --git a/app/Models/Finances/PISaleJournal.php b/app/Models/Finances/PISaleJournal.php index ad00fccc1..770f96632 100644 --- a/app/Models/Finances/PISaleJournal.php +++ b/app/Models/Finances/PISaleJournal.php @@ -23,19 +23,16 @@ class PISaleJournal extends Model */ protected $fillable = [ 'id', - 'corporation_id', + 'corp_id', 'division', - 'amount', - 'balance', - 'context_id', - 'context_id_type', + 'client_id', 'date', - 'description', - 'first_party_id', - 'reason', - 'ref_type', - 'second_party_id', - 'tax', - 'tax_receiver_id', + 'is_buy', + 'journal_ref_id', + 'location_id', + 'quantity', + 'transaction_id', + 'type_id', + 'unit_price', ]; } diff --git a/database/migrations/2019_04_19_000000_create_pi_sale_journals_table.php b/database/migrations/2019_04_19_000000_create_pi_sale_journals_table.php index 6660c9ec0..a91cb0b39 100644 --- a/database/migrations/2019_04_19_000000_create_pi_sale_journals_table.php +++ b/database/migrations/2019_04_19_000000_create_pi_sale_journals_table.php @@ -16,20 +16,17 @@ class CreatePiSaleJournalsTable extends Migration 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->integer('corp_id'); + $table->integer('division'); + $table->integer('client_id'); + $table->string('date'); + $table->boolean('is_buy'); + $table->integer('journal_ref_id'); + $table->integer('location_id'); + $table->integer('quantity'); + $table->integer('transaction_id'); + $table->integer('type_id'); + $table->decimal('unit_price'); $table->timestamps(); }); }