removed structure taxes from program

This commit is contained in:
2019-05-22 00:03:16 -05:00
parent 85d1c30e81
commit c5a7a9e3ea
10 changed files with 0 additions and 746 deletions

View File

@@ -1,106 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Carbon\Carbon;
use DB;
//Jobs
use App\Jobs\SendEveMailJob;
//Libraries
use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
use App\Library\Structures\StructureTaxHelper;
use App\Library\Esi\Esi;
//Models
use App\Models\Market\MonthlyMarketTax;
use App\Models\ScheduledTask\ScheduleJob;
use App\Models\Corporation\CorpStructure;
use App\Models\User\UserToCorporation;
use App\Models\Jobs\JobSendEveMail;
class CalculateMarketTaxCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:CalculateMarketTax';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Calculate the market taxes owed to the holding corporation and store in the database.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('CorpJournal');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Setup helper classes
$hFinances = new FinanceHelper();
$sHelper = new StructureTaxHelper();
$start = Carbon::now()->startOfMonth()->subMonth();
$end = Carbon::now()->endOfMOnth()->subMonth();
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
//Get the set of corporations from the structure table
$corps = CorpStructure::select('corporation_id')->groupBy('corporation_id')->get();
$this->line('Got all of the corps with markets.' . sizeof($corps));
foreach($corps as $corp) {
if($corp->corporation_id != 98287666) {
$finalTaxes = $sHelper->GetTaxes($corp->corporation_id, 'Market', $start, $end);
if($finalTaxes < 0.00) {
$finalTaxes = 0.00;
}
//Get the info about the structures from the database
$info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first();
$character = UserToCorporation::where(['character_id' => $info->character_id])->first();
$mail = new JobSendEveMail;
$mail->sender = 93738489;
$mail->subject = 'Market Taxes Owed';
$mail->body = 'Year ' . $start->year . ' ' .
'Month: ' .
$start->month .
'<br>Market Taxes Owed: ' .
number_format($finalTaxes, 2, '.', ',') .
'<br>Please remit to Spatial Forces';
$mail->recipient = (int)$info->character_id;
$mail->recipient_type = 'character';
SendEveMailJob::dispatch($mail)->onQueue('default');
}
}
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -1,90 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
//Libraries
use Commands\Library\CommandHelper;
use App\Library\Finances\Helper\FinanceHelper;
//Jobs
use App\Jobs\ProcessWalletJournalJob;
//Models
use App\Models\Corporation\CorpStructure;
use App\Models\Jobs\JobProcessWalletJournal;
class CorpJournalCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:CorpJournal';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Grabs the corporation journals and deposit in db.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('CorpJournal');
//Add the entry into the jobs table saying the job is starting
$task->SetStartStatus();
//Setup the Finances Container
$finance = new FinanceHelper();
//Setup an array to store corporations which have been logged so we don't keep calling the same ones. We need
//this step in order to save time during the cronjob.
$finishedCorps = array();
$corpCompleted = false;
//Get the corps with structures logged in the database
$corps = CorpStructure::select('corporation_id')->groupBy('corporation_id')->get();
//For all of the corporations, go through each structure and get wallet data
foreach($corps as $corp) {
//If the corporation isn't the holding corporation, then process the data.
//We process holding corporation data elsewhere.
if($corp->corporation_id != 98287666) {
$structure = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first();
$pages = $finance->GetJournalPageCount(1, $structure->character_id);
for($i = 1; $i <= $pages; $i++) {
$job = new JobProcessWalletJournal;
$job->division = 1;
$job->charId = $structure->character_id;
$job->page = $i;
ProcessWalletJournalJob::dispatch($job)->onQueue('journal');
}
}
}
//Mark the job as finished
$task->SetStopStatus();
}
}

View File

@@ -30,9 +30,6 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('services:CorpJournal')
->hourly()
->withoutOverlapping();
$schedule->command('services:HoldingJournal')
->hourly()
->withoutOverlapping();
@@ -42,9 +39,6 @@ class Kernel extends ConsoleKernel
$schedule->command('services:GetCorps')
->monthlyOn(1, '09:00')
->withoutOverlapping();
$schedule->command('services:CalculateMarketTax')
->monthlyOn(1, '08:00')
->withoutOverlapping();
$schedule->command('services:MoonMailer')
->monthlyOn(1, '00:01')
->withoutOverlapping();

View File

@@ -1,56 +0,0 @@
<?php
namespace App\Http\Controllers\Structures;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use DB;
use App\Models\Corporation\CorpStructure;
use App\Models\Corporation\CorpTaxRatio;
use App\Library\Esi\Esi;
class RegisterStructureController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('role:User');
$this->middleware('permission:structure.operator');
}
public function displayRegisterStructure() {
//Check to see if the user has the read corp journal esi scope before allowing to register a structure
if(Auth()->user()->hasEsiScope('esi-wallet.read_corporation_wallets.v1')) {
return view('structures.register.register');
} else {
return view('dashboard')->with('error', 'You need to setup your esi scope for read corporation wallets');
}
}
public function storeStructure(Request $request) {
$this->validate($request, [
'system' => 'required',
'structure_name' => 'required',
'tax' => 'required',
'structure_type' => 'required',
]);
$eHelper = new Esi;
$tax = floatval($request->tax);
$structure = new CorpStructure();
$structure->character_id = Auth::user()->character_id;
$structure->corporation_id = $eHelper->FindCorporationId(Auth::user()->character_id);
$structure->corporation_name = $eHelper->FindCorporationName(Auth::user()->character_id);
$structure->region = $request->region;
$structure->system = $request->system;
$structure->structure_name = $request->structure_name;
$structure->structure_type = $request->structure_type;
$structure->save();
//Return the view and the message of user updated
return redirect('/dashboard')->with('success', 'Structure Added to Database');
}
}

View File

@@ -1,58 +0,0 @@
<?php
namespace App\Http\Controllers\Structures;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class StructureAdminController extends Controller
{
public function __construct() {
$this->middleware('role:Admin');
}
public function displayDashboard() {
return view('structures.admin.dashboard');
}
public function storeTaxRatio(Request $request) {
$this->validate($request, [
'corpId',
'corporation',
'type',
'ratio',
]);
$ratio = new CorpTaxRatio;
$ratio->corporation_id = $request->corpId;
$ratio->corporation_name = $request->corporation;
$ratio->structure_type = $request->type;
$ratio->ratio = $request->ratio;
$ratio->save();
return redirect('structure.admin.dashboard');
}
public function updateTaxRatio(Request $request) {
$this->validate($request, [
'corporation',
'type',
'ratio',
]);
CorpTaxRatio::where([
'corporation_name' => $request->corporation,
'structure_type' => $request->type,
])->update([
'ratio' => $request->ratio,
]);
return redirect('/structure/admin/dashboard')->with('success', 'Tax Ratio updated for structure type: ' . $request->type . ' and corporation: ' . $request->corporation);
}
public function displayTaxRatios() {
$taxRatios = CorpTaxRation::all();
return view('structure.admin.taxratios')->with('structures', $structures);
}
}

View File

@@ -1,124 +0,0 @@
<?php
namespace App\Http\Controllers\Structures;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use DB;
use Carbon\Carbon;
use App\Library\Structures\StructureTaxHelper;
use App\Library\Esi\Esi;
use App\Library\Lookups\LookupHelper;
use App\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
use App\Models\Corporation\CorpStructure;
use App\Models\Finances\StructureIndustryTaxJournal;
use App\Models\Esi\EsiToken;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;
class StructureController extends Controller
{
public function __construct() {
$this->middleware('auth');
$this->middleware('role:User');
$this->middleware('permission:structure.operator');
}
public function chooseCorpTaxes() {
$this->middleware('role:Admin');
$corps = CorpStructure::pluck('corporation_name', 'corporation_id');
return view('structures.admin.choosecorporation')->with('corps', $corps);
}
public function displayCorpTaxes(Request $request) {
$this->middleware('role:Admin');
$corpId = $request->corpId;
$months = 3;
//Declare the structure tax helper class
$sHelper = new StructureTaxHelper();
//Get the dates we are working with
$dates = $sHelper->GetTimeFrameInMonths($months);
foreach($dates as $date) {
$totalTaxes[] = [
'date' => $date['start']->toFormattedDateString(),
'tax' => number_format($sHelper->GetTaxes($corpId, 'Market', $date['start'], $date['end']), 2, '.', ','),
'revenue' => number_format($sHelper->GetRevenue($corpId, 'Market', $date['start'], $date['end']), 2, '.', ',')
];
}
//Return the view with the data passed to it
return view('structures.admin.choosecorptaxes')->with('totalTaxes', $totalTaxes);
}
public function displayTaxes() {
//Declare new Lookup helper
$helper = new LookupHelper();
//Declare the structure tax helper class
$sHelper = new StructureTaxHelper();
$months = 3;
$totalTaxes = array();
//Get the character's corporation from the lookup table or esi
$corpId = $helper->LookupCharacter(Auth::user()->character_id);
//Get the dates we are working with
$dates = $sHelper->GetTimeFrameInMonths($months);
//Get the market taxes for this month from the database
foreach($dates as $date) {
$totalTaxes[] = [
'date' => $date['start']->toFormattedDateString(),
'tax' => number_format($sHelper->GetTaxes($corpId, 'Market', $date['start'], $date['end']), 2, '.', ','),
'revenue' => number_format($sHelper->GetRevenue($corpId, 'Market', $date['start'], $date['end']), 2, '.', ',')
];
}
return view('structures.user.taxes')->with('totalTaxes', $totalTaxes);
}
public function displayTaxHistory(Request $request) {
//Declare new Lookup helper
$helper = new LookupHelper();
//Get the months from the request
$months = $request->months;
//Get the character's corporation from the lookup table or esi
$corpId = $helper->LookupCharacter(Auth::user()->character_id);
//Declare the structure tax helper class
$sHelper = new StructureTaxHelper();
//Get the dates we are working with
$dates = $sHelper->GetTimeFrameInMonths($months);
//Build the array for displaying the data on the view
$totalTaxes = array();
foreach($dates as $date) {
$totalTaxes[] = [
'date' => $date['start']->toFormattedDateString(),
'tax' => number_format($sHelper->GetTaxes($corpId, 'Market', $date['start'], $date['end']), 2, '.', ','),
'revenue' => number_format($sHelper->GetRevenue($corpId, 'Market', $date['start'], $date['end']), 2, '.', ',')
];
}
return view('structures.user.taxhistory')->with(compact('totalTaxes', 'months'));
}
}

View File

@@ -1,219 +0,0 @@
<?php
namespace App\Library\Structures;
use DB;
use Carbon\Carbon;
use App\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
use App\Models\Corporation\CorpStructure;
use App\Models\Corporation\CorpTaxRatio;
use App\Models\Finances\CorpMarketJournal;
use App\Models\Finances\ReprocessingTaxJournal;
use App\Models\Finances\StructureIndustryTaxJournal;
class StructureTaxHelper {
private $corpId;
private $refType;
private $start;
private $end;
public function __construct($corp = null, $ref = null, $st = null, $en = null) {
$this->corpId = $corp;
$this->refType = $ref;
$this->start = $st;
$this->end = $en;
}
public function GetTaxes($corpId, $refType, $start, $end) {
$taxOwed = 0.00;
//Get the number of structures of a certain type
$count = $this->GetStructureCount($corpId, $refType);
//Calculate the fuel cost for one type of structure
$fuelCost = $this->CalculateFuelBlockCost($refType);
//Get the ratio from the table to be divided against the tax to find the
//acutal tax owed to the alliance. Revenue will be a separate function
$ratio = CorpTaxRatio::where([
'corporation_id' => $corpId,
'structure_type' => $refType,
])->get(['ratio']);
$ratio = $ratio[0]->ratio;
//Get the total taxes produced by the structure(s) over a given set of dates
$revenue = $this->GetRevenue($corpId, $refType, $start, $end);
//Calculate the total fuel block cost
$totalFuelCost = $fuelCost * $count;
//Calculate the total revenue minus the fuel block cost
$totalRevenue = $revenue - $totalFuelCost;
//Check to see if the revenue is greater than zero to avoid division by zero error.
//Then calculate the tax owed which is revenue divided by ratio previously calcualted.
if($totalRevenue > 0.00) {
$taxOwed = $totalRevenue / $ratio;
} else {
$taxOwed = 0.00;
}
//Return the amount
return $taxOwed;
}
public function GetIndustryRevenue($start, $end) {
$revenue = 0.00;
$revenue = StructureIndustryTaxJournal::where(['ref_type' => 'facility_industry_tax', 'second_party_id' => '98287666'])
->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetRevenue($corpId, $refType, $start, $end) {
$revenue = 0.00;
if($refType == 'Market') {
//Get the revenue from the corp_market_journals table and add it up.
$revenue = CorpMarketJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId, 'second_party_id' => $corpId])
->whereBetween('date', [$start, $end])
->sum('amount');
} else if($refType == 'Refinery'){
//Get the revenue from the reprocessing_tax_journal table and add it up.
$revenue = ReprocessingTaxJournal::where(['ref_type' => 'reprocessing_tax', 'corporation_id' => $corpId, 'second_party_id' => $corpId])
->whereBetween('date', [$start, $end])
->sum('amount');
} else {
//If it's not from one of the above tables, then it doesn't mean anything, so return nothing.
$revenue = 0.00;
}
return (float)$revenue;
}
private function CalculateTaxRatio($corpId, $overallTax, $type) {
//Get the ratio based on what was decided upon for the ratio of taxes.
//Default rate is 2.5 ratio.
//The alliance will get a ratio of the tax.
//We need to calculate the correct ratio based on structure tax,
//Then figure out what is owed to the alliance
if($type == 'Market') {
$ratioType = 2.5;
} else if($type == 'Refinery') {
$ratioType = 1.0;
} else {
$ratioType = 1.0;
}
//Calculate the ratio since we have the base percentage the alliance takes
$taxRatio = $overallTax / $ratioType;
//Return what is owed to the alliance
return $taxRatio;
}
private function CalculateFuelBlockCost($type) {
//Calculate how many fuel blocks are used in a month by a structure type
if($type === 'Market') {
$fuelBlocks = 24*30*32;
} else if ($type === 'Refinery') {
$fuelBlocks = 24*30*8;
} 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 GetTimeFrame() {
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
$startLast = new Carbon('first day of last month');
$endLast = new Carbon('last day of last month');
$endLast->hour = 23;
$endLast->minute = 59;
$endLast->second = 59;
$dates = [
'ThisMonthStart' => $start,
'ThisMonthEnd' => $end,
'LastMonthStart' => $startLast,
'LastMonthEnd' => $endLast,
];
return $dates;
}
/**
* Returns a set of dates from now until the amount of months has passed
*
* @var integer
* @returns array
*/
public function GetTimeFrameInMonths($months) {
//Declare an array of dates
$dates = array();
//Setup the start of the array as the basis of our start and end dates
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
if($months == 1) {
$dates = [
'start' => $start,
'end' => $end,
];
return $dates;
}
//Create an array of dates
for($i = 0; $i < $months; $i++) {
if($i == 0) {
$dates[$i]['start'] = $start;
$dates[$i]['end'] = $end;
}
$start = Carbon::now()->startOfMonth()->subMonths($i);
$end = Carbon::now()->endOfMonth()->subMonths($i);
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
$dates[$i]['start'] = $start;
$dates[$i]['end'] = $end;
}
//Return the dates back to the calling function
return $dates;
}
private function GetStructureTax($corpId, $structureType) {
$tax = CorpStructure::where(['corporation_id' => $corpId, 'structure_type' => $structureType])->avg('tax');
return (float) $tax;
}
private function GetStructureCount($corpId, $structureType) {
$count = CorpStructure::where(['corporation_id' => $corpId, 'structure_type' => $structureType])->count();
return (int)$count;
}
}
?>

View File

@@ -1,33 +0,0 @@
<?php
namespace App\Models\Corporation;
use Illuminate\Database\Eloquent\Model;
class CorpStructure extends Model
{
/**
* Table Name
*/
protected $table = 'CorpStructures';
/**
* Timestamps
*/
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'character_id',
'corporation_id',
'corporation_name',
'region',
'system',
'structure_name',
'structure_type',
];
}

View File

@@ -1,30 +0,0 @@
<?php
namespace App\Models\Corporation;
use Illuminate\Database\Eloquent\Model;
class CorpTaxRatio extends Model
{
/**
* Table Name
*/
protected $table = 'corp_tax_ratios';
/**
* Timestamps
*/
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'corporation_id',
'corporation_name',
'structure_type',
'ratio',
];
}

View File

@@ -65,30 +65,6 @@ Route::group(['middleware' => ['auth']], function(){
Route::post('/admin/add/allowedlogin', 'Dashboard\AdminController@addAllowedLogin');
Route::post('/admin/rmoeve/allowedlogin', 'Dashboard\AdminController@removeAllowedLogin');
/**
* Register structure controller display pages
*/
Route::get('/structures/register', 'Structures\RegisterStructureController@displayRegisterstructure');
Route::post('/structures/register', 'Structures\RegisterStructureController@storeStructure');
/**
* Structure Admin Controller display pages
*/
Route::get('/structures/admin/dashboard', 'Structures\StructureAdminController@displayDashboard');
Route::post('/structures/admin/add/taxratio', 'Strutures\StructureAdminController@storeTaxRatio');
Route::post('/structures/admin/update/taxratio', 'Structures\StructureAdminController@updateTaxRatio');
/**
* Structure Controller display pages
* To be removed in future release. Functionality will be removed as well.
*/
Route::get('/structures/taxes/display', 'Structures\StructureController@displayTaxes');
Route::get('/structures/admin/taxes/display', 'Structures\StructureController@chooseCorpTaxes');
Route::get('/structures/admin/taxes/display/execute', 'Structures\StructureController@displayCorpTaxes');
Route::get('/structures/admin/taxes/industry', 'Structures\StructureController@displayIndustryTaxes');
Route::get('/structures/admin/taxes/reprocessing', 'Structures\StructureController@displayReprocessingTaxes');
Route::get('/structures/admin/display', 'Structures\StructureController@displayAdminPanel');
/**
* Scopes Controller display pages
*/