diff --git a/app/Console/Commands/moonmailer.php b/app/Console/Commands/moonmailer.php index 20f5f58da..0c2b1d784 100644 --- a/app/Console/Commands/moonmailer.php +++ b/app/Console/Commands/moonmailer.php @@ -16,7 +16,7 @@ use App\Library\Moons\MoonCalc; //Models use App\Models\Moon\Moon; -use App\Models\Moon\MoonRent; +use App\Models\MoonRent\MoonRent; use App\Models\Jobs\JobSendEveMail; class MoonMailerCommand extends Command @@ -81,8 +81,6 @@ class MoonMailerCommand extends Command foreach($contacts as $contact) { //Get the moons the renter is renting $rentals = $moonMailer->GetRentalMoons($contact); - - //Retrieve the date for each moon for when the moon is rented until //Totalize the cost of the moons $cost = $moonMailer->TotalizeMoonCost($rentals); diff --git a/app/Http/Controllers/MoonsAdminController.php b/app/Http/Controllers/MoonsAdminController.php index 78adb3ee7..9ae148b82 100644 --- a/app/Http/Controllers/MoonsAdminController.php +++ b/app/Http/Controllers/MoonsAdminController.php @@ -2,20 +2,22 @@ namespace App\Http\Controllers; +//Internal Library use Illuminate\Http\Request; - use Auth; use DB; use Carbon\Carbon; +//Models use App\Models\Moon\Config; use App\Models\Moon\ItemComposition; use App\Models\Moon\Moon; use App\Models\Moon\OrePrice; use App\Models\Moon\Price; -use App\Models\Moon\MoonRent; - +use App\Models\MoonRent\MoonRent; use App\Models\Finances\PlayerDonationJournal; + +//Library use App\Library\Moons\MoonCalc; use App\Library\Esi\Esi; use App\Library\Lookups\LookupHelper; @@ -40,6 +42,63 @@ class MoonsAdminController extends Controller return view('moons.admin.updatemoon'); } + public function storeUpdateMoonRental(Request $request) { + $moonCalc = new MoonCalc; + $lookup = new LookupHelper; + + $this->validate($request, [ + 'system' => 'required', + 'planet' => 'required', + 'moon' => 'required', + 'renter' => 'required', + 'date' => 'required', + 'contact' => 'required', + ]); + + //Take the contact name and create a character_id from it + if($request->contact == 'None') { + $contact = 'None'; + } else { + $contact = $lookup->CharacterNameToId($request->contact); + } + + //Let's find the corporation and alliance information to ascertain whethery they are in Warped Intentions or another Legacy Alliance + $allianceId = $lookup->LookupCorporation($lookup->LookupCharacter($contact)); + + //Create the date + $date = new Carbon($request->date . '00:00:01'); + + //Insert or update the moon rental database entry + if($allianceId = 99004116) { + MoonRent::insert([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'RentalCorp' => $request->renter, + 'RentalEnd' => $date, + 'Contact' => $contact, + 'Price' => $price['alliance'], + 'Type' => 'alliance', + 'Paid' => 'No', + ]); + } else { + MoonRent::insert([ + 'System' =>$request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'RentalCorp' => $request->renter, + 'RentalEnd' => $date, + 'Contact' => $contact, + 'Price' => $price['outofalliance'], + 'Type' => 'outofalliance', + 'Paid' => 'No', + ]); + } + + //Redirect to the update moon page + return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated'); + } + public function storeUpdateMoon(Request $request) { $moonCalc = new MoonCalc(); $lookup = new LookupHelper(); @@ -115,66 +174,6 @@ class MoonsAdminController extends Controller return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated'); } - public function addMoon() { - return view('moons.admin.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 */ @@ -272,4 +271,68 @@ class MoonsAdminController extends Controller //Redirect back to the moon page, which should call the page to be displayed correctly return redirect('/moons/admin/display'); } + + /** + * Display function for adding a new rental moon to the pool + * + */ + public function addMoon() { + return view('moons.admin.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'); + } } diff --git a/app/Http/Controllers/MoonsController.php b/app/Http/Controllers/MoonsController.php index f8e4faf68..1f88c80ca 100644 --- a/app/Http/Controllers/MoonsController.php +++ b/app/Http/Controllers/MoonsController.php @@ -13,6 +13,7 @@ use App\Models\Moon\ItemComposition; use App\Models\Moon\Moon; use App\Models\Moon\OrePrice; use App\Models\Moon\Price; +use App\Models\MoonRent\MoonRent; use App\Library\Moons\MoonCalc; @@ -52,6 +53,12 @@ class MoonsController extends Controller $worth = $moonCalc->SpatialMoonsTotalWorth($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); + $rental = MoonRent::where([ + 'System' => $moon->System, + 'Planet' => $moon->Planet, + 'Moon' => $moon->Moon, + ])->first(); + if($type == 'W4RP') { $moonprice = $price['alliance']; } else { @@ -80,7 +87,7 @@ class MoonsController extends Controller 'FourthQuantity' => $moon->FourthQuantity, 'Price' => $moonprice, 'Worth' => number_format($worth, "2", ".", ","), - 'RentalEnd' => $rentalEnd, + 'RentalEnd' => $rental->RentalEnd, 'RowColor' => $color, ]); } diff --git a/app/Library/Moons/MoonMailer.php b/app/Library/Moons/MoonMailer.php index 93f60ebec..e4fba4fd7 100644 --- a/app/Library/Moons/MoonMailer.php +++ b/app/Library/Moons/MoonMailer.php @@ -15,7 +15,7 @@ use App\Library\Moons\MoonCalc; use App\Models\Jobs\JobSendEveMail; use App\Models\Mail\SentMail; use App\Models\Moon\Moon; -use App\Models\Moon\MoonRent; +use App\Models\MoonRent\MoonRent; class MoonMailer { public function DeleteMoonRent(MoonRent $rental, Carbon $today) { @@ -29,7 +29,7 @@ class MoonMailer { } public function UpdateNotPaid(MoonRent $rental) { - Moon::where([ + MoonRent::where([ 'System' => $rental->System, 'Planet'=> $rental->Planet, 'Moon'=> $rental->Moon, @@ -89,6 +89,7 @@ class MoonMailer { $price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); + //Check the type and figure out which price to add in if($rental->Type == 'alliance') { $totalCost += $price['alliance']; } else{ diff --git a/app/Models/Moon/Moon.php b/app/Models/Moon/Moon.php index d35d1ebd7..b46962aae 100644 --- a/app/Models/Moon/Moon.php +++ b/app/Models/Moon/Moon.php @@ -29,9 +29,5 @@ class Moon extends Model 'ThirdQuantity', 'FourthOre', 'FourthQuantity', - 'RentalCorp', - 'RentalEnd', - 'Paid', - 'Paid_Until', ]; } diff --git a/app/Models/Moon/MoonRent.php b/app/Models/MoonRentals/MoonRent.php similarity index 87% rename from app/Models/Moon/MoonRent.php rename to app/Models/MoonRentals/MoonRent.php index cc96a864c..b12e4ea32 100644 --- a/app/Models/Moon/MoonRent.php +++ b/app/Models/MoonRentals/MoonRent.php @@ -1,6 +1,6 @@ 'form-control', 'placeholder' => 'Planet']) }} {{ Form::label('moon', 'Moon') }} {{ Form::text('moon', '', ['class' => 'form-control', 'placeholder' => 'Moon']) }} + +
{{ Form::label('renter', 'Renter') }} {{ Form::text('renter', '', ['class' => 'form-control', 'placeholder' => 'Renter']) }} + {{ Form::label('contact', 'Contact') }} +
+
+ {{ Form::text('contact', '', ['class' => 'form-control', 'placeholder' => 'Character']) }} {{ Form::label('date', 'Rental End Date') }} {{ Form::date('date', \Carbon\Carbon::now()->addMonth(), ['class' => 'form-control']) }} - {{ Form::label('contact', 'Contact') }} - {{ Form::text('contact', '', ['class' => 'form-control', 'placeholder' => 'Character']) }}
{{ Form::submit('Submit', ['class' => 'btn btn-primary']) }} {!! Form::close() !!}