update moon rental

This commit is contained in:
2019-05-05 21:45:08 -05:00
parent 4459080882
commit 4f891cc987
3 changed files with 94 additions and 98 deletions

View File

@@ -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 . "<br>";
$body .= "The price for next month's rent is " . $price['alliance'] . "<br>";
$body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.<br>";
$body .= "Sincerely,<br>";
$body .= "Spatial Forces<br>";
} else {
$body = "Moon Rent is due for " . $rental->System . " Planet: " . $rental->Planet . " Moon: " . $rental->Moon . "<br>";
$body .= "The price for next month's rent is " . $price['outofalliance'] . "<br>";
$body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.<br>";
$body .= "Sincerely,<br>";
$body .= "Spatial Forces<br>";
}
//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();
}

View File

@@ -62,13 +62,73 @@ 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
$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,
])->delete();
if($allianceId = 99004116) {
MoonRental::insert([
'System' => $request->system,
@@ -94,6 +154,7 @@ class MoonsAdminController extends Controller
'Paid' => 'No',
]);
}
}
//Redirect to the update moon page
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated');

View File

@@ -29,6 +29,9 @@ class MoonMailer {
}
public function UpdateNotPaid(MoonRent $rental) {
$today = Carbon::now();
if($today >= $rental->Paid_Until) {
MoonRent::where([
'System' => $rental->System,
'Planet'=> $rental->Planet,
@@ -37,6 +40,7 @@ class MoonMailer {
'Paid' => 'No',
]);
}
}
public function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {
$sentmail = new SentMail;