Added new Library class called LookupHelper to assist in easier access to reference tables across all classes. Added lookup table migrations Added chartjs package to composer, and laravel service provider modified routes to make it easier to see what is going on rather than having different names for post things from get pages
161 lines
5.6 KiB
PHP
161 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Auth;
|
|
use DB;
|
|
use Carbon\Carbon;
|
|
|
|
use App\Models\Moon\Moon;
|
|
|
|
use App\Models\Finances\PlayerDonationJournal;
|
|
use App\Library\Moons\MoonCalc;
|
|
use App\Library\Esi\Esi;
|
|
|
|
class MoonsAdminController extends Controller
|
|
{
|
|
public function __construct() {
|
|
$this->middleware('auth');
|
|
$this->middleware('role:Admin');
|
|
}
|
|
|
|
public function showJournalEntries() {
|
|
$dateInit = Carbon::now();
|
|
$date = $dateInit->subDays(30);
|
|
|
|
$journal = DB::select('SELECT amount,reason,description,date FROM `PlayerDonationJournals` WHERE corporation_id=98287666 AND date >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH)');
|
|
|
|
return view('moons.moonjournal')->with('journal', $journal);
|
|
}
|
|
|
|
public function updateMoon() {
|
|
return view('moons.updatemoon');
|
|
}
|
|
|
|
public function storeUpdateMoon(Request $request) {
|
|
$this->validate($request, [
|
|
'system' => 'required',
|
|
'planet' => 'required',
|
|
'moon' => 'required',
|
|
'renter' => 'required',
|
|
'date' => 'required'
|
|
]);
|
|
|
|
$date = strtotime($request->date . '00:00:01');
|
|
//Update the database entry
|
|
Moon::where([
|
|
'System' => $request->system,
|
|
'Planet' => $request->planet,
|
|
'Moon' => $request->moon,
|
|
])->update([
|
|
'RentalCorp' => $request->renter,
|
|
'RentalEnd' => $date,
|
|
]);
|
|
|
|
return redirect('/moons/display')->with('success', 'Moon Updated');
|
|
}
|
|
|
|
public function addMoon() {
|
|
return view('moons.addmoon');
|
|
}
|
|
|
|
/**
|
|
* Add a new moon into the database
|
|
*
|
|
* @return \Illuminate\Http\Reponse
|
|
*/
|
|
public function storeMoon(Request $request) {
|
|
$this->validate($request, [
|
|
'region' => 'required',
|
|
'system' => 'required',
|
|
'structure' => 'required',
|
|
]);
|
|
|
|
if($request->input('firstquan') < 1.00) {
|
|
$firstQuan = $request->input('firstquan') * 100.00;
|
|
} else {
|
|
$firstQuan = $request->input('firstquan');
|
|
}
|
|
|
|
if($request->input('secondquan') < 1.00) {
|
|
$firstQuan = $request->input('secondquan') * 100.00;
|
|
} else {
|
|
$firstQuan = $request->input('secondquan');
|
|
}
|
|
|
|
if($request->input('thirdquan') < 1.00) {
|
|
$firstQuan = $request->input('thirdquan') * 100.00;
|
|
} else {
|
|
$firstQuan = $request->input('thirdquan');
|
|
}
|
|
|
|
if($request->input('fourthquan') < 1.00) {
|
|
$firstQuan = $request->input('fourthquan') * 100.00;
|
|
} else {
|
|
$firstQuan = $request->input('fourthquan');
|
|
}
|
|
|
|
// Add new moon
|
|
$moon = new Moon;
|
|
$moon->Region = $request->input('region');
|
|
$moon->System = $request->input('system');
|
|
$moon->Planet = $request->input('planet');
|
|
$moon->Moon = $request->input('moon');
|
|
$moon->StructureName = $request->input('structure');
|
|
$moon->FirstOre = $request->input('firstore');
|
|
$moon->FirstQuantity = $request->input('firstquan');
|
|
$moon->SecondOre = $request->input('secondore');
|
|
$moon->SecondQuantity = $request->input('secondquan');
|
|
$moon->ThirdOre = $request->input('thirdore');
|
|
$moon->ThirdQuantity = $request->input('thirdquan');
|
|
$moon->FourthOre = $request->input('fourthore');
|
|
$moon->FourthQuantity = $request->input('fourthquan');
|
|
$moon->save();
|
|
|
|
return redirect('/dashboard')->with('success', 'Moon Added');
|
|
}
|
|
|
|
/**
|
|
* Function to display the moons to admins
|
|
*/
|
|
public function displayMoonsAdmin() {
|
|
//Setup calls to the MoonCalc class
|
|
$moonCalc = new MoonCalc();
|
|
//Update the prices for the moon
|
|
$moonCalc->FetchNewPrices();
|
|
//get all of the moons from the database
|
|
$moons = Moon::orderBy('System', 'asc')->get();
|
|
//$moons = DB::table('Moons')->orderBy('System', 'asc')->get();
|
|
//declare the html variable and set it to null
|
|
$html = '';
|
|
foreach($moons as $moon) {
|
|
//Setup formats as needed
|
|
$spm = $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon;
|
|
$rentalEnd = date('m/d/Y', $moon->RentalEnd);
|
|
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
|
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
|
//Add the data to the html string to be passed to the view
|
|
$html .= '<tr>';
|
|
$html .= '<td>' . $spm . '</td>';
|
|
$html .= '<td>' . $moon->StructureName . '</td>';
|
|
$html .= '<td>' . $moon->FirstOre . '</td>';
|
|
$html .= '<td>' . $moon->FirstQuantity . '</td>';
|
|
$html .= '<td>' . $moon->SecondOre . '</td>';
|
|
$html .= '<td>' . $moon->SecondQuantity . '</td>';
|
|
$html .= '<td>' . $moon->ThirdOre . '</td>';
|
|
$html .= '<td>' . $moon->ThirdQuantity . '</td>';
|
|
$html .= '<td>' . $moon->FourthOre . '</td>';
|
|
$html .= '<td>' . $moon->FourthQuantity . '</td>';
|
|
$html .= '<td>' . $price['alliance'] . '</td>';
|
|
$html .= '<td>' . $price['outofalliance'] . '</td>';
|
|
$html .= '<td>' . $moon->RentalCorp . '</td>';
|
|
$html .= '<td>' . $rentalEnd . '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
return view('moons.adminmoon')->with('html', $html);
|
|
}
|
|
}
|