structure tax structure
This commit is contained in:
@@ -38,23 +38,67 @@ class FinancesController extends Controller
|
|||||||
public function displayTaxes() {
|
public function displayTaxes() {
|
||||||
//Make the helper esi class
|
//Make the helper esi class
|
||||||
$helper = new Esi();
|
$helper = new Esi();
|
||||||
//Set the carbon date for the first day of the month
|
//Make the helper class for finances
|
||||||
|
$hFinances = new Finances();
|
||||||
|
//Set the carbon date for the first day of this month, last day of this month, and the previous month's first and last days.
|
||||||
$start = Carbon::now()->startOfMonth();
|
$start = Carbon::now()->startOfMonth();
|
||||||
$end = Carbon::now()->endOfMonth();
|
$end = Carbon::now()->endOfMonth();
|
||||||
$totalTax = 0.00;
|
$end->hour = 23;
|
||||||
|
$end->minute = 59;
|
||||||
|
$end->second = 59;
|
||||||
|
$startLast = Carbon::now()->firstDayOfPreviousMonth();
|
||||||
|
$endLast = Carbon::now()->lastDayOfPreviousMonth();
|
||||||
|
$endLast->hour = 23;
|
||||||
|
$endLast->minute = 59;
|
||||||
|
$endLast->second = 59;
|
||||||
|
|
||||||
//Get the character's corporation from esi
|
//Get the character's corporation from esi
|
||||||
$corporation = $helper->FindCorporationName(Auth::user()->character_id);
|
$corporation = $helper->FindCorporationName(Auth::user()->character_id);
|
||||||
$corpId = $helper->FindCorporationId(Auth::user()->character_id);
|
$corpId = $helper->FindCorporationId(Auth::user()->character_id);
|
||||||
|
|
||||||
|
//Get the number of structures registered to a corporation
|
||||||
|
$citadelCount = DB::select("SELECT COUNT(structure_name) FROM CorpStructures WHERE corporation_id='" . $corporation . "' AND structure_type='Citadel'");
|
||||||
|
$refineryCount = DB::select("SELECT COUNT(structure_name) FROM CorpStructures WHERE corporation_id='" . $corporation . "' aND structure_type='Refinery'");
|
||||||
|
|
||||||
//Get the taxes for the corporation
|
//Get the taxes for the corporation
|
||||||
$taxes = DB::table('CorpJournals')
|
//SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND date BETWEEN '2018-11-01 00:00:00' AND '2018-11-31 23:59:59'
|
||||||
->where(['corporation_id'=> $corpId, 'ref_type' => 'brokers_fee'])
|
$monthTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'");
|
||||||
->whereBetween(['dateTime' => $start, 'dateTime' => $end])
|
$lastTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'");
|
||||||
->get();
|
$monthTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'");
|
||||||
foreach($taxes as $tax) {
|
$lastTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'");
|
||||||
$totalTax += $tax->amount;
|
|
||||||
|
/**
|
||||||
|
* In this next section we are removing the cost of fuel blocks from one structure
|
||||||
|
*/
|
||||||
|
$monthTaxesMarket = $monthTaxesMarket - ($hFinaces->CalculateFuelBlockCost('market') * $citadelCount);
|
||||||
|
if($monthTaxesMarket < 0.00) {
|
||||||
|
$monthTaxesMarket = 0.00;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('finances.taxes')->with('totalTax', $totalTax);
|
$lastTaxesMarket = $lastTaxesMarket - ($hFinances->CalculateFuelBlocksCost('market') * $citadelCount);
|
||||||
|
if($lastTaxesMarket < 0.00) {
|
||||||
|
$lastTaxesMarket = 0.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
$monthTaxesReprocessing = $monthTaxesReprocessing - ($hFinaces->CalculateFuelBlockCost('reprocessing') * $refineryCount);
|
||||||
|
if($monthTaxesReprocessing < 0.00) {
|
||||||
|
$monthTaxesReprocessing = 0.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lastTaxesReprocessing = $lastTaxesReprocessing - ($hFinances->CalculateFuelBlockCost('reprocessing') * $refineryCount);
|
||||||
|
if($lastTaxesReprocessing < 0.00) {
|
||||||
|
$lastTaxesReprocessing = 0.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Create the array to pass to the blade view
|
||||||
|
$totalTaxes = [
|
||||||
|
'thisMonthReprocessing' => $monthTaxesReprocessing,
|
||||||
|
'lastMonthReprocessing' => $lastTaxesReprocessing,
|
||||||
|
'thisMonthMarket' => $monthTaxesMarket,
|
||||||
|
'lastMonthMarket' => $lastTaxesMarket,
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('finances.taxes')->with('totalTaxes', $totalTaxes);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,42 +24,41 @@ use Seat\Eseye\Eseye;
|
|||||||
|
|
||||||
class Finances {
|
class Finances {
|
||||||
|
|
||||||
public function CalculateAverageFuelBlock() {
|
public function CalculateFuelBlockCost($type) {
|
||||||
|
//Calculate how many fuel blocks are used in a month by a structure type
|
||||||
|
if($type === 'market') {
|
||||||
|
$fuelBlocks = 30*32*24;
|
||||||
|
} else if ($type === 'reprocessing') {
|
||||||
|
$fuelBlocks = 8*30*24;
|
||||||
|
} else {
|
||||||
|
$fuelBlocks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Multiply the amount of fuel blocks used by the structure by 20,000.
|
||||||
|
$cost = $fuelBlocks * 20000;
|
||||||
|
//Return to the calling function
|
||||||
|
return $cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CalculateMonthlyRefineryTaxees($corpId, $month, $overallTax) {
|
public function CalculateTax($taxAmount, $overallTax, $type) {
|
||||||
$currentTime = Carbon::now();
|
//The alliance will get a ratio of the tax.
|
||||||
$monthWanted = $month;
|
//We need to calculate the correct ratio based on structure tax,
|
||||||
$untaxed = 0.00;
|
//Then figure out what is owed to the alliance
|
||||||
//Get the journal entries from the database
|
if($type === 'market') {
|
||||||
$entries = DB::table('CorpJournals')->where(['corporation_id' => $corpId, 'created_at' => $monthWanted, 'ref_type' => 'reprocessing_tax'])->get();
|
$ratioType = 2.5;
|
||||||
foreach($entries as $entry) {
|
} else if ($type === 'refinery') {
|
||||||
$untaxed += $entry->tax;
|
$ratioType = 1.0;
|
||||||
|
} else {
|
||||||
|
$ratioType = 1.5;
|
||||||
}
|
}
|
||||||
//The alliance will get 1.0 pts of the tax. We need to calculate the correct percentage and return the value
|
//Calculate the ratio since we have the base percentage the alliance takes
|
||||||
$taxRatio = $overallTax / 1.0;
|
$taxRatio = $overallTax / $ratioType;
|
||||||
$taxed = $untaxed / $taxRatio;
|
//Calculate the tax owed to the alliance by taking the tax amount collected
|
||||||
|
//and divide by the tax ratio.
|
||||||
|
$amount = $taxAmount / $taxRatio;
|
||||||
|
|
||||||
return $taxed;
|
//Return what is owed to the alliance
|
||||||
}
|
return $amount;
|
||||||
|
|
||||||
public function CalculateMonthlyMarketTaxes($corpId, $month, $overallTax) {
|
|
||||||
//Convert the current time to a time / date
|
|
||||||
$currentTime = Carbon::now();
|
|
||||||
$monthWanted = $month;
|
|
||||||
$untaxed = 0.00;
|
|
||||||
//Get the journal entries from the database
|
|
||||||
$entries = DB::table('CorpJournals')->where(['corporation_id' => $corpId, 'created_at' => $monthWanted, 'ref_type' => 'brokers_fee'])->get();
|
|
||||||
foreach($entries as $entry) {
|
|
||||||
$untaxed += $entry->tax;
|
|
||||||
}
|
|
||||||
//The alliance will get 2.5 pts of the tax. We need to calculate
|
|
||||||
//the correct percentage, and return the value
|
|
||||||
$taxRatio = $overallTax / 2.5;
|
|
||||||
$taxed = $untaxed / $taxRatio;
|
|
||||||
|
|
||||||
return $taxed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetWalletJournal($division, $charId) {
|
public function GetWalletJournal($division, $charId) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
@extends('layouts.b4')
|
@extends('layouts.b4')
|
||||||
@include('layouts.navbar')
|
|
||||||
@include('inc.messages')
|
|
||||||
|
|
||||||
{!! $html !!}
|
{!! $html !!}
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
@extends('layouts.b4')
|
@extends('layouts.b4')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
Structure Taxes
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
Reference in New Issue
Block a user