diff --git a/app/Jobs/Commands/RentalMoons/SendMoonRentalPaymentReminderJob.php b/app/Jobs/Commands/RentalMoons/SendMoonRentalPaymentReminderJob.php
index 2abc85b74..133fd0b50 100644
--- a/app/Jobs/Commands/RentalMoons/SendMoonRentalPaymentReminderJob.php
+++ b/app/Jobs/Commands/RentalMoons/SendMoonRentalPaymentReminderJob.php
@@ -12,6 +12,7 @@ use Log;
use Carbon\Carbon;
//Library
+use App\Library\Lookups\LookupHelper;
//Jobs
use App\Jobs\ProcessSendEvveMailJob;
@@ -20,6 +21,14 @@ use App\Jobs\ProcessSendEvveMailJob;
use App\Models\MoonRentals\AllianceRentalMoon;
use App\Models\Mail\SentMail;
+
+/**
+ * This job will send out a reminder about the moon rental payment being due
+ * when it's due based on the rental paid date versus rental date. If the paid
+ * date is in the future from today, then we don't need to send out a reminder.
+ * If the paid date is today or less, then we need to send out a reminder about
+ * paying for the moon rental.
+ */
class SendMoonRentalPaymentReminderJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -56,6 +65,131 @@ class SendMoonRentalPaymentReminderJob implements ShouldQueue
*/
public function handle()
{
- //
+ //Get today's date
+ $today = Carbon::now();
+ $today->second = 1;
+ $today->minute = 0;
+ $today->hour = 0;
+ //Declare some other variables
+ $totalCost = 0.00;
+ $moonList = array();
+ $delay = 30;
+ $lookup = new LookupHelper;
+ $config = config('esi');
+
+ //Get all of the contacts from the rentals group
+ $contacts = AllianceMoonRental::select('rental_contact_id')->groupBy('rental_contact_id')->get();
+
+ //For each of the contacts, totalize the moon rentals, and create a reminder mail
+ foreach($contacts as $contact) {
+ //Get the moons the renter is renting, but only get the ones whose paid date is not after today.
+ $dues = $this->GetMoonDueList($contact->rental_contact_id);
+
+ //Get the list of moons for the mail body.
+ $alls = $this->GetMoonRentalList($contact->rental_contact_id);
+
+ //Totalize the cost for the moons whose rent is due
+ $cost = $this->TotalizeMoonCost($contact->rental_contact_id);
+
+ //For each of the rentals, build the mail body, and totalize the cost of the moon
+ $body = "Moon Rent is due for the following moons:
";
+ foreach($rentalsDue as $due) {
+ $body .= $due . "
";
+ }
+ //Put the price for the moons
+ $body .= "The price for next month's rent is " . number_format($cost, 0, ".", ",") . "
";
+ $body .= "Rental Payment is due on the 1st of the month should you continue to want to rent the moons.
";
+ $body .= "Rental Payment should be transferred to Spatial Forces.
";
+ $body .= "In the description of the payment please put the following transaction identification: " . $transId . "
";
+ $body .= "
";
+ $body .= $contact->contact_name . " is responsible for payment of the moons.
";
+ $body .= "The following moons are being rented:
";
+ foreach($alls as $all) {
+ $body .= $all . "
";
+ }
+ $body .= "
";
+ $body .= "Sincerely,
";
+ $body .= "Warped Intentions Leadership
";
+
+ //Create the subject line
+ $subject = "Warped Intentions Moon Rental Payment Due for " . $today->englishMonth;
+ //Dispatch the mail job if the contact type is a character, otherwise
+ //dispatch the job to the ceo of the corporation instead. If the contact is an alliance
+ //dispatch the job to the ceo of the holding corporation.
+ if($contact->contact_type == 'Character') {
+ ProcessSendEveMailJob::dispatch($body, (int)$contact->rental_contact_id, 'character', $subject, $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
+ //Increment the delay to get ready for the next mail job
+ $delay += 30;
+ } else if($contact->contact_type == 'Corporation') {
+ //Get the CEO of the corporation from the lookup helper
+ $corporation = $lookup->GetCorporationInfo($contact->rental_contact_id);
+ $charId = $corporation->ceo_id;
+ //Send out the mail
+ ProcessSendEveMailJob::dispatch($body, (int)$charId, 'character', $subject, $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
+ //Increment the delay to get ready for the next mail job
+ $delay += 30;
+ } else if($contact->contact_type == 'Alliance') {
+ //Get the holding corporation from the lookup helper
+ $alliance = $lookup->GetAllianceInfo($contact->rental_contact_id);
+ //Get the CEO of the corporation of the holding corp from the lookup helper
+ $corporation = $lookup->GetCorporationInfo($alliance->executor_corporation_id);
+ $charId = $corporation->ceo_id;
+ //Send out the mail
+ ProcessSendEveMailJob::dispatch($body, (int)$charId, 'character', $subject, $config['primaryh'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
+ //Increment the detaly to get ready for the next mail job
+ $delay += 30;
+ }
+ }
+ }
+
+ private function GetMoonRentalsList($contact) {
+ //Declare the variables
+ $list = array();
+
+ $moons = AllianceMoonRental::where([
+ 'rental_contact_id' => $contact,
+ ])->get();
+
+ foreach($moons as $moon) {
+ $temp = 'Rental: ' . $moon->region . ' - ' . $moon->system . ' - ' . $moon->planet . ' - ' . $moon->moon;
+ array_push($list, $temp);
+ }
+
+ //Return the list
+ return $list;
+ }
+
+ private function GetMoonDueList($contact) {
+ //Declare the variables
+ $list = array();
+
+ $moons = AllianceMoonRental::where([
+ 'rental_contact_id' => $contact,
+ ])->where('paid_until', '<=', $today)->get();
+
+ //Create the list
+ foreach($moons as $moon) {
+ $temp = 'Rental: ' . $moon->region . ' - ' . $moon->system . ' - ' . $moon->planet . ' - ' . $moon->moon;
+ array_push($list, $temp);
+ }
+
+ //Return the list
+ return $list;
+ }
+
+ private function TotalizeCost($rentals, $rentalType) {
+ //Declare the stuff we need
+ $totalCost = 0.00;
+
+ //Totalize the cost
+ foreach($rentals as $rental) {
+ if($rentalType = 'In Alliance') {
+ $totalCost += $rental->alliance_rental_price;
+ } else {
+ $totalCost += $rental->out_of_alliance_rental_price;
+ }
+ }
+
+ return $totalCost;
}
}
diff --git a/database/migrations/2020_05_28_064641_create_alliance_moon_rentals_table.php b/database/migrations/2020_05_28_064641_create_alliance_moon_rentals_table.php
index 84ae5048d..bc2732a28 100644
--- a/database/migrations/2020_05_28_064641_create_alliance_moon_rentals_table.php
+++ b/database/migrations/2020_05_28_064641_create_alliance_moon_rentals_table.php
@@ -41,7 +41,7 @@ class CreateAllianceMoonRentalsTable extends Migration
$table->dateTime('rental_until')->nullable();
$table->unsignedBigInteger('rental_contact_id')->default(0);
$table->enum('rental_contact_type', [
- 'Player',
+ 'Character',
'Corporation',
'Alliance',
'Unknown',