From 4f891cc9871184e1d6e4da754491168ce448cee1 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 5 May 2019 21:45:08 -0500 Subject: [PATCH] update moon rental --- app/Console/Commands/moonmailer.php | 69 ------------ app/Http/Controllers/MoonsAdminController.php | 105 ++++++++++++++---- app/Library/Moons/MoonMailer.php | 18 +-- 3 files changed, 94 insertions(+), 98 deletions(-) diff --git a/app/Console/Commands/moonmailer.php b/app/Console/Commands/moonmailer.php index 0c2b1d784..fa06bdc73 100644 --- a/app/Console/Commands/moonmailer.php +++ b/app/Console/Commands/moonmailer.php @@ -120,75 +120,6 @@ class MoonMailerCommand extends Command } } - /* - //Get all of the moons from the rental list - $rentals = MoonRent::all(); - - //Update the price for all moon rentals before sending out the mail - foreach($rentals as $rental) { - //Get the contents of the moon to re-price it out - $moon = Moon::where([ - 'System' => $rental->System, - 'Planet' => $rental->Planet, - 'Moon' => $rental->Moon, - ])->first(); - - //Get the updated price for the moon - $price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, - $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); - - //Create the mail body depending on if the price should be in alliance or out of alliance - if($rental->Type == 'alliance') { - $body = "Moon Rent is due for " . $rental->System . " Planet: " . $rental->Planet . " Moon: " . $rental->Moon . "
"; - $body .= "The price for next month's rent is " . $price['alliance'] . "
"; - $body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.
"; - $body .= "Sincerely,
"; - $body .= "Spatial Forces
"; - } else { - $body = "Moon Rent is due for " . $rental->System . " Planet: " . $rental->Planet . " Moon: " . $rental->Moon . "
"; - $body .= "The price for next month's rent is " . $price['outofalliance'] . "
"; - $body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.
"; - $body .= "Sincerely,
"; - $body .= "Spatial Forces
"; - } - - //Send a mail to the contact listing for the moon - $mail = new JobSendEveMail; - $mail->sender = 93738489; - $mail->subject = "Moon Rental"; - $mail->body = $body; - $mail->recipient = (int)$rental->Contact; - $mail->recipient_type = 'character'; - - //Dispatch the job and cycle to the next moon rental - SendEveMailJob::dispatch($mail); - - //After the mail is dispatched, saved the sent mail record, - $sentmail = new SentMail; - $sentmail->sender = $mail->sender; - $sentmail->subject = $mail->subject; - $sentmail->body = $mail->body; - $sentmail->recipient = $mail->recipient; - $sentmail->recipient_type = $mail->recipient_type; - $sentmail->save(); - - //After saving the record, delete the record from the database - if($today->greaterThanOrEqualTo($rental->RentalEnd)) { - MoonRent::where(['id' => $rental->id])->delete(); - } - - //Mark the moon as not paid for the next month - Moon::where([ - 'System' => $rental->System, - 'Planet' => $rental->Planet, - 'Moon' => $rental->Moon, - ])->update([ - 'Paid' => 'No', - ]); - - } - */ - //Mark the job as finished $task->SetStopStatus(); } diff --git a/app/Http/Controllers/MoonsAdminController.php b/app/Http/Controllers/MoonsAdminController.php index 5a69126c8..449dd3f38 100644 --- a/app/Http/Controllers/MoonsAdminController.php +++ b/app/Http/Controllers/MoonsAdminController.php @@ -62,37 +62,98 @@ class MoonsAdminController extends Controller $contact = $lookup->CharacterNameToId($request->contact); } + if(isset($request->Paid_Until)) { + $paidUntil = $request->Paid_Until; + } else { + $paidUntil = null; + } + //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) { - MoonRental::insert([ + $found = MoonRental::where([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'Contact' => $contact, + ])->first(); + + //If the entry is found, we are most likely just updating an entry to include new paid until data + if($found) { + if($allianceId = 99004116) { + MoonRental::where([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'Contact' => $contact, + ])->update([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'RentalCorp' => $request->renter, + 'RentalEnd' => $date, + 'Contact' => $contact, + 'Price' => $price['alliance'], + 'Type' => 'alliance', + 'Paid' => $paid, + 'Paid_Until' => $request->paid_until, + ]); + } else { + MoonRental::where([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'Contact' => $contact, + ])->update([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + 'RentalCorp' => $request->renter, + 'RentalEnd' => $date, + 'Contact' => $contact, + 'Price' => $price['outofalliance'], + 'Type' => 'alliance', + 'Paid' => $paid, + 'Paid_Until' => $request->paid_until, + ]); + } + } else { + //If the entry is not found, then attempt to delete whatever existing data is there, then + //insert the new data + MoonRental::where([ 'System' => $request->system, 'Planet' => $request->planet, 'Moon' => $request->moon, - 'RentalCorp' => $request->renter, - 'RentalEnd' => $date, - 'Contact' => $contact, - 'Price' => $price['alliance'], - 'Type' => 'alliance', - 'Paid' => 'No', - ]); - } else { - MoonRental::insert([ - 'System' =>$request->system, - 'Planet' => $request->planet, - 'Moon' => $request->moon, - 'RentalCorp' => $request->renter, - 'RentalEnd' => $date, - 'Contact' => $contact, - 'Price' => $price['outofalliance'], - 'Type' => 'outofalliance', - 'Paid' => 'No', - ]); + ])->delete(); + + if($allianceId = 99004116) { + MoonRental::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 { + MoonRental::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 diff --git a/app/Library/Moons/MoonMailer.php b/app/Library/Moons/MoonMailer.php index e4fba4fd7..4bccf9ed8 100644 --- a/app/Library/Moons/MoonMailer.php +++ b/app/Library/Moons/MoonMailer.php @@ -29,13 +29,17 @@ class MoonMailer { } public function UpdateNotPaid(MoonRent $rental) { - MoonRent::where([ - 'System' => $rental->System, - 'Planet'=> $rental->Planet, - 'Moon'=> $rental->Moon, - ])->update([ - 'Paid' => 'No', - ]); + $today = Carbon::now(); + + if($today >= $rental->Paid_Until) { + MoonRent::where([ + 'System' => $rental->System, + 'Planet'=> $rental->Planet, + 'Moon'=> $rental->Moon, + ])->update([ + 'Paid' => 'No', + ]); + } } public function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {