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 //Mark the job as finished
$task->SetStopStatus(); $task->SetStopStatus();
} }

View File

@@ -62,37 +62,98 @@ class MoonsAdminController extends Controller
$contact = $lookup->CharacterNameToId($request->contact); $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 //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)); $allianceId = $lookup->LookupCorporation($lookup->LookupCharacter($contact));
//Create the date //Create the date
$date = new Carbon($request->date . '00:00:01'); $date = new Carbon($request->date . '00:00:01');
//Insert or update the moon rental database entry $found = MoonRental::where([
if($allianceId = 99004116) { 'System' => $request->system,
MoonRental::insert([ '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, 'System' => $request->system,
'Planet' => $request->planet, 'Planet' => $request->planet,
'Moon' => $request->moon, 'Moon' => $request->moon,
'RentalCorp' => $request->renter, ])->delete();
'RentalEnd' => $date,
'Contact' => $contact, if($allianceId = 99004116) {
'Price' => $price['alliance'], MoonRental::insert([
'Type' => 'alliance', 'System' => $request->system,
'Paid' => 'No', 'Planet' => $request->planet,
]); 'Moon' => $request->moon,
} else { 'RentalCorp' => $request->renter,
MoonRental::insert([ 'RentalEnd' => $date,
'System' =>$request->system, 'Contact' => $contact,
'Planet' => $request->planet, 'Price' => $price['alliance'],
'Moon' => $request->moon, 'Type' => 'alliance',
'RentalCorp' => $request->renter, 'Paid' => 'No',
'RentalEnd' => $date, ]);
'Contact' => $contact, } else {
'Price' => $price['outofalliance'], MoonRental::insert([
'Type' => 'outofalliance', 'System' =>$request->system,
'Paid' => 'No', '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 //Redirect to the update moon page

View File

@@ -29,13 +29,17 @@ class MoonMailer {
} }
public function UpdateNotPaid(MoonRent $rental) { public function UpdateNotPaid(MoonRent $rental) {
MoonRent::where([ $today = Carbon::now();
'System' => $rental->System,
'Planet'=> $rental->Planet, if($today >= $rental->Paid_Until) {
'Moon'=> $rental->Moon, MoonRent::where([
])->update([ 'System' => $rental->System,
'Paid' => 'No', 'Planet'=> $rental->Planet,
]); 'Moon'=> $rental->Moon,
])->update([
'Paid' => 'No',
]);
}
} }
public function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) { public function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) {