store update moon function

This commit is contained in:
2020-06-04 03:28:59 -05:00
parent 9b7eb27e01
commit af9a8e955b
2 changed files with 83 additions and 173 deletions

View File

@@ -347,213 +347,119 @@ class MoonsAdminController extends Controller
} }
/** /**
* Store the updated moon * Function to store the updates from the moons.
* New function based on new table. Will update
* the description in a future update
*/ */
public function storeUpdateMoon(Request $request) { public function storeUpdateMoonNew(Request $request) {
//Require the site administration role
$this->middleware('role:Admin'); $this->middleware('role:Admin');
//Declare some static variables as needed //Declare some variables we will need
$moonCalc = new MoonCalc; $moonCalc = new MoonCalc;
$lookup = new LookupHelper; $lookup = new LookupHelper;
$paid = false; $paid = false;
$system = null; $system = null;
$planet = null; $planet = null;
$mn = null; $mn = null;
$name = null;
//Validate our request from the html form //Validate our request from the html form
$this->validate($request, [ $this->validate($request, [
'spmn' => 'required', 'spmn' => 'required',
'contact' => 'required', 'contact' => 'required',
'contact_type' => 'required',
'paid_until' => 'required', 'paid_until' => 'required',
'rental_end' => 'required', 'rental_end' => 'required',
]); ]);
//Decode the System, Planet, Moon, Name combinatio sent from the controller //Decode the spmn
$str_array = explode(" - ", $request->spmn); $str_array = explode(" - ", $request->spmn);
$system = $str_array[0]; $system = $str_array[0];
$planet = $str_array[1]; $planet = $str_array[1];
$mn = $str_array[2]; $mn = $str_array[2];
$name = $str_array[3]; $name = $str_array[3];
//Take the contact name and create a character_id from it //Update the paid value from the request value
if($request->contact == 'None') {
$contact = -1;
} else {
$contact = $lookup->CharacterNameToId($request->contact);
}
//After we get the contact, from his name to the character Id, let's do some other functions before continuing.
//Let's find the corporation and alliance information to ascertain whethery they are in Warped Intentions or another Legacy Alliance
$char = $lookup->GetCharacterInfo($contact);
//Takes the corp id and looks up the corporation info
$corp = $lookup->GetCorporationInfo($char->corporation_id);
$alliance = $lookup->GetAllianceInfo($corp->alliance_id);
$allianceId = $corp->alliance_id;
//Update the paid value for database entry
if($request->paid == 'Yes') { if($request->paid == 'Yes') {
$paid = 'Yes'; $paid = 'Yes';
} else { } else {
$paid = 'No'; $paid = 'No';
} }
//Create the rnetal ticker if the corp is in Warped Intentions, otherwise just display the alliance ticker //Setup the rental end and paid until variables
if($allianceId == 99004116) { $rentalEnd = $request->rental_end . " 23:59:59";
$renter = $corp->ticker; $paidUntil = $request->paid_until . " 23:59:59";
} else {
$renter = $alliance->ticker;
}
//Create the paid until date //Check if the alliance is renting the moon for itself
if(isset($request->paid_until)) { if($request->contact_type == 'Corporation' && $request->contact == 'Spatial Forces') {
$paidUntil = new Carbon($request->paid_until . '00:00:01'); AllianceMoonRental::where([
} else { 'system' => $str_array[0],
$paidUntil = Carbon::now(); 'planet' => $str_array[1],
} 'moon' => $str_array[2],
//Create the rental end date
if(isset($request->rental_end)) {
$rentalEnd = new Carbon($request->rental_end . '23:59:59');
} else {
$rentalEnd = Carbon::now();
}
//Calculate the price of the moon for when it's updated
$moon = RentalMoon::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $mn,
])->first();
//Calculate the price of the rental and store it in the database
$price = $moonCalc->SpatialMoons($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
//Count how many rentals we find for later database processing
$count = MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $mn,
'Contact' => $contact,
])->count();
//If the database entry isn't found, then insert it into the database,
//otherwise, account for it being in the system already.
//Also check for the weird condition of more than one moon entry existing
if($count > 1) {
//If more than one entry is found for a particular system, planet, moon combo, then delete all the entries, and put in
// a single new entry
MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $moon,
])->delete();
if($allianceId == 99004116) {
$store = new MoonRental;
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $rentalEnd;
$store->Contact = $contact;
$store->Price = $price['alliance'];
$store->Type = 'alliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
} else {
$store = new MoonRental;
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $rentalEnd;
$store->Contact = $contact;
$store->Price = $price['outofalliance'];
$store->Type = 'outofalliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
}
} else if($count == 1) {
if($allianceId = 99004116) {
MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $mn,
'Contact' => $contact,
])->update([ ])->update([
'System' => $system, 'rental_type' => 'Alliance',
'Planet' => $planet, 'rental_until' => $request->rental_end . " 23:59:59",
'Moon' => $mn, 'rental_contact_id' => 98287666,
'RentalCorp' => $renter, 'rental_contact_type' => 'Alliance',
'RentalEnd' => $rentalEnd, 'paid' => 'No',
'Contact' => $contact, 'paid_until' => null,
'Price' => $price['alliance'], 'alliance_use_until' => $request->rental_end . " 23:59:59",
'Type' => 'alliance',
'Paid' => $paid,
'Paid_Until' => $paidUntil,
]); ]);
} else if($request->contact_type == 'Character') {
//Get the character id from the lookup helper
$charId = $lookup->CharacterNameToId($request->contact);
//Get the corporation id from the lookup helper, followed by the alliance id
//so we can determine if it's in alliance or out of alliance
$corp = $lookup->GetCorporationInfo($charId);
if($corp->alliance_id == 99004116) {
$type = 'In Alliance';
} else { } else {
MoonRental::where([ $type = 'Out of Alliance';
'System' => $system, }
'Planet' => $planet,
'Moon' => $mn, AllianceMoonRental::where([
'Contact' => $contact, 'system' => $str_array[0],
'planet' => $str_array[1],
'moon' => $str_array[2],
])->update([ ])->update([
'System' => $system, 'rental_type' => $type,
'Planet' => $planet, 'rental_until' => $request->rental_end . " 23:59:59",
'Moon' => $mn, 'rental_contact_id' => $charId,
'RentalCorp' => $renter, 'rental_contact_type' => 'Character',
'RentalEnd' => $rentalEnd, 'paid' => $paid,
'Contact' => $contact, 'paid_until' => $request->paid_until . " 23:59:59",
'Price' => $price['outofalliance'], 'alliance_use_until' => null,
'Type' => 'outofalliance', ]);
'Paid' => $paid,
'Paid_Until' => $paidUntil, } else if($request->contact_type == 'Corporation') {
//Get the corporation id from the lookup helper
$corpId = $lookup->CorporationNameToId($request->contact);
//Get the corporation information to determine if they are in Warped Intentions or not.
$corporation = $lookup->GetCorporationInfo($request->contact);
if($corp->alliance_id == 99004116) {
$type = 'In Alliance';
} else {
$type = 'Out of Alliance';
}
AllianceMoonRental::where([
'system' => $str_array[0],
'planet' => $str_array[1],
'moon' => $str_array[2],
])->update([
'rental_type' => $type,
'rental_until' => $request->rental_end . " 23:59:59",
'rental_contact_id' => $corpId,
'rental_contact_type' => 'Corporation',
'paid' => $paid,
'paid_until' => $request->paid_until . " 23:59:59",
'alliance_use_until' => null,
]); ]);
} }
} else {
//If the entry is not found, then attempt to delete whatever existing data is there, then
//insert the new data
MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $moon,
])->delete();
if($allianceId == 99004116) { //Redirect to the previous screen.
$store = new MoonRental; return redirect('/moons/admin/updatemoon')->with('success', 'Moon Rental updated.');
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $rentalEnd;
$store->Contact = $contact;
$store->Price = $price['alliance'];
$store->Type = 'alliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
} else {
$store = new MoonRental;
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $rentalEnd;
$store->Contact = $contact;
$store->Price = $price['outofalliance'];
$store->Type = 'outofalliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
}
}
//Redirect to the update moon page
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated');
} }
} }

View File

@@ -15,6 +15,10 @@
{{ Form::label('contact', 'Contact') }} {{ Form::label('contact', 'Contact') }}
{{ Form::text('contact', '', ['class' => 'form-control', 'placeholder' => 'Character']) }} {{ Form::text('contact', '', ['class' => 'form-control', 'placeholder' => 'Character']) }}
</div> </div>
<div class="form-group col-md-6">
{{ Form::label('contact_type', 'Contact Type') }}
{{ Form::select('contact_type', ['Character' => 'Character', 'Corporation' => 'Corporation'], 'Character') }}
</div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
{{ Form::label('rental_end', 'Rental End Date') }} {{ Form::label('rental_end', 'Rental End Date') }}
{{ Form::date('rental_end', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }} {{ Form::date('rental_end', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}