From c2312e32558ec0de8d3f9bdbfe39fd6111f539e2 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Fri, 7 Dec 2018 02:38:24 -0600 Subject: [PATCH] new permissions --- app/Http/Controllers/FinancesController.php | 181 +----------------- app/Http/Controllers/StructureController.php | 173 +++++++++++++++++ app/Http/Middleware/RequirePermission.php | 29 +++ app/Http/Middleware/RequireRole.php | 2 +- .../{finances => structures}/taxes.blade.php | 0 routes/web.php | 10 +- 6 files changed, 208 insertions(+), 187 deletions(-) create mode 100644 app/Http/Controllers/StructureController.php create mode 100644 app/Http/Middleware/RequirePermission.php rename resources/views/{finances => structures}/taxes.blade.php (100%) diff --git a/app/Http/Controllers/FinancesController.php b/app/Http/Controllers/FinancesController.php index 573a9f951..81dc3943c 100644 --- a/app/Http/Controllers/FinancesController.php +++ b/app/Http/Controllers/FinancesController.php @@ -4,189 +4,10 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use DB; -use Socialite; -use Auth; -use Carbon\Carbon; - -use App\User; -use App\Models\User\UserRole; -use App\Models\User\UserPermission; -use App\Models\Corporation\CorpJournal; - -use App\Library\FinanceHelper; -use App\Library\Esi; -use App\Library\SeatHelper; - -use Seat\Eseye\Cache\NullCache; -use Seat\Eseye\Configuration; -use Seat\Eseye\Containers\EsiAuthentication; -use Seat\Eseye\Eseye; - class FinancesController extends Controller { public function __construct() { $this->middleware('auth'); $this->middleware('role:Director'); - } - - public function displayWallet() { - $helper = new FinanceHelper(); - - $helper->GetWalletJournal(1, 92626011); - dd($helper); - } - - public function displayTaxesHistory() { - //Make the helper ESI Class - $helper = new Esi(); - //Make the helper class for finances - $hFinances = new FinanceHelper(); - - //Get the character's corporation from esi - $corporation = $helper->FindCorporationName(Auth::user()->character_id); - $corpId = $helper->FindCorporationId(Auth::user()->character_id); - - //Set the carbon date for the first day of this month, last day of this month - $currentStart = Carbon::now()->startOfMonth(); - $currentEnd = Carbon::now()->endOfMonth(); - //Setup the currentEnd to end at 23:59:59 - $currentEnd->hour = 23; - $currentEnd->minute = 59; - $currentEnd->second = 59; - - $dates = $this->RenderDates(); - $totalTaxes = array(); - $i = 0; - foreach($dates as $date) { - //Get the taxes for each month and store in the totalTaxes array and store the date as well. - $start = $date; - $end = new Carbon($date); - $end = $end->endOfMonth(); - $end->hour = 23; - $end->minute = 59; - $end->second = 59; - - //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 each type from the database - $marketTaxes = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); - $reprocessingTaxes = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); - - /** - * In this next section we are going to remove the cost of fuel blocks from the structure taxes - */ - //Market Taxes with fuel blocks added in - $marketTaxes = $marketTaxes - ($hFinances->CalculateFuelBlockCost('market') * $citadelCount); - if($marketTaxes < 0.00) { - $marketTaxes = 0.00; - } - - //Reprocessing Taxes with fuel blocks added in - $reprocessingTaxes = $reprocessingTaxes - ($hFinances->CalculateFuelBlockCost('reprocessing') * $refineryCount); - if($reprocessingTaxes < 0.00) { - $reprocessingTaxes = 0.00; - } - - //Add to the totalTaxes array to be sent out with the view - $totalTaxes[$i] = [ - 'date' => $start, - 'reprocessing' => number_format($reprocessingTaxes, 2, '.', ','), - 'market' => number_format($marketTaxes, 2, '.', ','), - ]; - //Increment $i for the next iteration - $i++; - } - - //Return the data to the view - return view('finances.taxes')->with('totalTaxes', $totalTaxes); - } - - public function displayJumpGateStatistics() { - - } - - public function displayTaxes() { - //Make the helper esi class - $helper = new Esi(); - //Make the helper class for finances - $hFinances = new FinanceHelper(); - //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(); - $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; - - //Get the character's corporation from esi - $corporation = $helper->FindCorporationName(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 - //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' - $monthTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); - $lastTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'"); - $monthTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); - $lastTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'"); - - /** - * In this next section we are removing the cost of fuel blocks from one structure - */ - $monthTaxesMarket = $monthTaxesMarket - ($hFinances->CalculateFuelBlockCost('market') * $citadelCount); - if($monthTaxesMarket < 0.00) { - $monthTaxesMarket = 0.00; - } - - $lastTaxesMarket = $lastTaxesMarket - ($hFinances->CalculateFuelBlocksCost('market') * $citadelCount); - if($lastTaxesMarket < 0.00) { - $lastTaxesMarket = 0.00; - } - - $monthTaxesReprocessing = $monthTaxesReprocessing - ($hFinances->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' => number_format($monthTaxesReprocessing, 2, '.', ','), - 'lastMonthReprocessing' => number_format($lastTaxesReprocessing, 2, '.', ','), - 'thisMonthMarket' => number_format($monthTaxesMarket, 2, '.', ','), - 'lastMonthMarket' => number_format($lastTaxesMarket, 2, '.', ','), - ]; - - return view('finances.taxes')->with('totalTaxes', $totalTaxes); - - } - - private function RenderDates() - { - $start = Carbon::now()->subYear()->startOfYear(); - $months_to_render = Carbon::now()->diffInMonths($start); - - $dates = []; - - for($i = 0; $i <= $months_to_render; $i++) { - $dates[] = $start->toDateTimeString(); - $start->addMonth(); - } - - return $dates; - } + } } diff --git a/app/Http/Controllers/StructureController.php b/app/Http/Controllers/StructureController.php new file mode 100644 index 000000000..da7c4c90b --- /dev/null +++ b/app/Http/Controllers/StructureController.php @@ -0,0 +1,173 @@ +middleware('auth'); + $this->middleware('permission:structure.operator'); + } + + public function displayTaxes() { + //Make the helper esi class + $helper = new Esi(); + //Make the helper class for finances + $hFinances = new FinanceHelper(); + //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(); + $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; + + //Get the character's corporation from esi + $corporation = $helper->FindCorporationName(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 + //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' + $monthTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); + $lastTaxesMarket = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'"); + $monthTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); + $lastTaxesReprocessing = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $startLast . "' AND '" . $endLast . "'"); + + /** + * In this next section we are removing the cost of fuel blocks from one structure + */ + $monthTaxesMarket = $monthTaxesMarket - ($hFinances->CalculateFuelBlockCost('market') * $citadelCount); + if($monthTaxesMarket < 0.00) { + $monthTaxesMarket = 0.00; + } + + $lastTaxesMarket = $lastTaxesMarket - ($hFinances->CalculateFuelBlocksCost('market') * $citadelCount); + if($lastTaxesMarket < 0.00) { + $lastTaxesMarket = 0.00; + } + + $monthTaxesReprocessing = $monthTaxesReprocessing - ($hFinances->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' => number_format($monthTaxesReprocessing, 2, '.', ','), + 'lastMonthReprocessing' => number_format($lastTaxesReprocessing, 2, '.', ','), + 'thisMonthMarket' => number_format($monthTaxesMarket, 2, '.', ','), + 'lastMonthMarket' => number_format($lastTaxesMarket, 2, '.', ','), + ]; + + return view('structures.taxes')->with('totalTaxes', $totalTaxes); + } + + public function displayTaxesHistory() { + //Make the helper ESI Class + $helper = new Esi(); + //Make the helper class for finances + $hFinances = new FinanceHelper(); + + //Get the character's corporation from esi + $corporation = $helper->FindCorporationName(Auth::user()->character_id); + $corpId = $helper->FindCorporationId(Auth::user()->character_id); + + //Set the carbon date for the first day of this month, last day of this month + $currentStart = Carbon::now()->startOfMonth(); + $currentEnd = Carbon::now()->endOfMonth(); + //Setup the currentEnd to end at 23:59:59 + $currentEnd->hour = 23; + $currentEnd->minute = 59; + $currentEnd->second = 59; + + $dates = $this->RenderDates(); + $totalTaxes = array(); + $i = 0; + foreach($dates as $date) { + //Get the taxes for each month and store in the totalTaxes array and store the date as well. + $start = $date; + $end = new Carbon($date); + $end = $end->endOfMonth(); + $end->hour = 23; + $end->minute = 59; + $end->second = 59; + + //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 each type from the database + $marketTaxes = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='brokers_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); + $reprocessingTaxes = DB::select("SELECT SUM(amount) FROM CorpJournals WHERE ref_type='reprocessing_fee' AND corporation_id='" . $corpId . "' AND date BETWEEN '" . $start . "' AND '" . $end . "'"); + + /** + * In this next section we are going to remove the cost of fuel blocks from the structure taxes + */ + //Market Taxes with fuel blocks added in + $marketTaxes = $marketTaxes - ($hFinances->CalculateFuelBlockCost('market') * $citadelCount); + if($marketTaxes < 0.00) { + $marketTaxes = 0.00; + } + + //Reprocessing Taxes with fuel blocks added in + $reprocessingTaxes = $reprocessingTaxes - ($hFinances->CalculateFuelBlockCost('reprocessing') * $refineryCount); + if($reprocessingTaxes < 0.00) { + $reprocessingTaxes = 0.00; + } + + //Add to the totalTaxes array to be sent out with the view + $totalTaxes[$i] = [ + 'date' => $start, + 'reprocessing' => number_format($reprocessingTaxes, 2, '.', ','), + 'market' => number_format($marketTaxes, 2, '.', ','), + ]; + //Increment $i for the next iteration + $i++; + } + + //Return the data to the view + return view('structures.taxhistory')->with('totalTaxes', $totalTaxes); + } + + private function RenderDates() + { + $start = Carbon::now()->subYear()->startOfYear(); + $months_to_render = Carbon::now()->diffInMonths($start); + + $dates = []; + + for($i = 0; $i <= $months_to_render; $i++) { + $dates[] = $start->toDateTimeString(); + $start->addMonth(); + } + + return $dates; + } +} diff --git a/app/Http/Middleware/RequirePermission.php b/app/Http/Middleware/RequirePermission.php new file mode 100644 index 000000000..eb71994f4 --- /dev/null +++ b/app/Http/Middleware/RequirePermission.php @@ -0,0 +1,29 @@ + auth()->user()->character_id, 'permission' => $permission])->get(['permission']); + if(!isset($check[0]->permission)) { + abort(403, "You don't have permission to access this area."); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/RequireRole.php b/app/Http/Middleware/RequireRole.php index d4ca8d90f..07ef3556b 100644 --- a/app/Http/Middleware/RequireRole.php +++ b/app/Http/Middleware/RequireRole.php @@ -4,7 +4,7 @@ namespace App\Http\Middleware; use Closure; use DB; -use \App\Models\User\UserRole; +use App\Models\User\UserRole; class RequireRole { diff --git a/resources/views/finances/taxes.blade.php b/resources/views/structures/taxes.blade.php similarity index 100% rename from resources/views/finances/taxes.blade.php rename to resources/views/structures/taxes.blade.php diff --git a/routes/web.php b/routes/web.php index 608c82032..121c382b6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -58,14 +58,12 @@ Route::post('/admin/addRole', 'AdminController@addRole'); Route::post('/admin/removeRole', 'AdminController@removeRole'); Route::post('/admin/addPermission', 'AdminController@addPermission'); -//Finances Controller display pages -Route::get('/finances/display', 'FinancesController@displayWallet'); -Route::get('/finances/taxes', 'FinancesController@displayTaxes')->name('structure_taxes'); - -//Structures Controller display pages +//Register Structures Controller display pages Route::get('/structures/register', 'RegisterStructureController@displayRegisterstructure'); Route::post('/structures/store', 'RegisterStructureController@storeStructure'); -Route::get('/structures/taxes', 'FinancesController@displayTaxes'); +//Structure Controller display pages +Route::get('/structures/taxes', 'Structurecontroller@displayTaxes'); +Route::get('/structures/taxes/history', 'StructureController@displayTaxHistory'); //AJAX Controller display pages Route::get('ajax',function() {