diff --git a/app/Console/Commands/moonmailer.php b/app/Console/Commands/moonmailer.php
index 788b838d9..0c14e749a 100644
--- a/app/Console/Commands/moonmailer.php
+++ b/app/Console/Commands/moonmailer.php
@@ -15,6 +15,7 @@ use DB;
use App\Models\Moon\Moon;
use App\Models\Moon\MoonRent;
use App\Models\Mail\EveMail;
+use App\Models\Mail\SentMail;
class MoonMailerCommand extends Command
{
@@ -63,6 +64,9 @@ class MoonMailerCommand extends Command
//Get all of the moons from the rental list
$rentals = MoonRent::all();
+ //Get today's date.
+ $today = Carbon::now();
+
//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
@@ -71,21 +75,22 @@ class MoonMailerCommand extends Command
'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 remite payment to Spatial Forces by the 1st should you continue to wish to rent the moon.
";
+ $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 remite payment to Spatial Forces by the 1st should you continue to wish to rent the moon.
";
+ $body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.
";
$body .= "Sincerely,
";
$body .= "Spatial Forces
";
}
@@ -100,11 +105,20 @@ class MoonMailerCommand extends Command
$mail->save();
//Dispatch the job and cycle to the next moon rental
- SendEveMail::dispatch($mail)->delay(Carbon::now()->addseconds(15));
- }
+ SendEveMail::dispatch($mail)->delay(Carbon::now());
- //Remove all moon rentals from the database
- DB::table('moon_rents')->delete();
+ //After the mail is dispatched, saved the sent mail record,
+ $sentmail = new SentMail;
+ $sentmail = $mail->sender;
+ $sentmail = $mail->subject;
+ $sentmail = $mail->body;
+ $sentmail = $mail->recipient;
+ $sentmail = $mail->recipient_type;
+ $sentmail->save();
+
+ //After saving the record, delete the record from the database
+ MoonRent::where(['id' => $rental->id])->delete();
+ }
//Mark the job as finished
$task->SetStopStatus();
diff --git a/app/Http/Controllers/MoonsAdminController.php b/app/Http/Controllers/MoonsAdminController.php
index 14db2ec46..181989715 100644
--- a/app/Http/Controllers/MoonsAdminController.php
+++ b/app/Http/Controllers/MoonsAdminController.php
@@ -84,7 +84,7 @@ class MoonsAdminController extends Controller
//Going to store moon price in a table for future reference
//We need to insert a price based on whether part of Legacy or part of Warped Intentions
//Will need an if then else statement to complete this operation
- if($allianceId = 99004116 || $allianceId = 99008072) {
+ if($allianceId = 99004116) {
MoonRent::insert([
'System' => $request->system,
'Planet' => $request->planet,
diff --git a/app/Models/Mail/SentMail.php b/app/Models/Mail/SentMail.php
new file mode 100644
index 000000000..b0e376303
--- /dev/null
+++ b/app/Models/Mail/SentMail.php
@@ -0,0 +1,22 @@
+increments('id');
+ $table->string('sender');
+ $table->string('subject');
+ $table->text('body');
+ $table->string('recipient');
+ $table->string('recipient_type');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('sent_mails');
+ }
+}