diff --git a/app/Console/Commands/Moons/MoonMailer.php b/app/Console/Commands/Moons/MoonMailer.php deleted file mode 100644 index 98682a9a4..000000000 --- a/app/Console/Commands/Moons/MoonMailer.php +++ /dev/null @@ -1,216 +0,0 @@ -SetStartStatus(); - - //Create other variables - $body = null; - $delay = 5; - - //Get today's date. - $today = Carbon::now(); - $today->second = 1; - $today->minute = 0; - $today->hour = 0; - - //Get the esi configuration - $config = config('esi'); - - //Get all contacts from the rentals group - $contacts = MoonRental::select('Contact')->groupBy('Contact')->get(); - - //For each of the contacts totalize the moon rental, and create the mail to send to them, - //then update parameters of the moon - foreach($contacts as $contact) { - //Get the moons the renter is renting. Also only get the moons which are not paid as of today - $rentals = MoonRental::where(['Contact' => $contact->Contact])->get(); - - //Totalize the cost of the moons - $cost = $this->TotalizeMoonCost($rentals); - - //Get the list of moons in a list format - $listItems = $this->GetMoonList($rentals); - - //Build the mail body - $body = "Moon Rent is due for the following moons:
"; - foreach($listItems as $item) { - $body .= $item . "
"; - } - $body .= "The price for the next month's rent is " . number_format($cost, 2, ".", ",") . "
"; - $body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.
"; - $body .= "Sincerely,
"; - $body .= "Warped Intentions Leadership
"; - - //Dispatch the mail job - $subject = "Warped Intentions Moon Rental Payment Due for " . $today->englishMonth; - ProcessSendEveMailJob::dispatch($body, (int)$contact->Contact, 'character', $subject, $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay)); - //Increment the delay for the mail to not hit rate limits - $delay += 30; - - //Update the moon as not being paid for the next month? - foreach($rentals as $rental) { - $previous = new Carbon($rental->Paid_Until); - - if($today->greaterThanOrEqualTo($previous)) { - $this->UpdateNotPaid($rental); - } - } - } - - //Mark the job as finished - $task->SetStopStatus(); - } - - private function UpdateNotPaid(MoonRental $rental) { - MoonRental::where([ - 'System' => $rental->System, - 'Planet'=> $rental->Planet, - 'Moon'=> $rental->Moon, - ])->update([ - 'Paid' => 'No', - ]); - } - - private function GetMoonList($moons) { - //Declare the variable to be used as a global part of the function - $list = array(); - - //For each of the moons, build the System Planet and Moon. - foreach($moons as $moon) { - $temp = 'Moon: ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon; - array_push($list, $temp); - } - - //Return the list - return $list; - } - - private function GetRentalMoons($contact) { - $rentals = MoonRental::where([ - 'Contact' => $contact, - ])->get(); - - return $rentals; - } - - private function TotalizeMoonCost($rentals) { - //Delcare variables and classes - $moonCalc = new MoonCalc; - $totalCost = 0.00; - $price = null; - - //Create the date for today - $today = Carbon::now(); - $today->second = 1; - $today->minute = 0; - $today->hour = 0; - - foreach($rentals as $rental) { - $moon = RentalMoon::where([ - 'System' => $rental->System, - 'Planet' => $rental->Planet, - 'Moon' => $rental->Moon, - ])->first(); - - //Create the date time object for the rental end - $end = new Carbon($rental->Paid_Until); - - //If today is greater than the rental end, then calculate the moon cost - if($today->greaterThanOrEqualTo($end)) { - //Get the updated price for the moon - $price = $moonCalc->SpatialMoons($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, - $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); - - //Check the type and figure out which price to add in - if($rental->Type == 'alliance') { - $totalCost += $price['alliance']; - } else{ - $totalCost += $price['outofalliance']; - } - } - } - - //Return the total cost back to the calling function - return $totalCost; - } - - private function GetRentalType($rentals) { - $alliance = 0; - $outofalliance = 0; - - //Go through the data and log whether the renter is in the alliance, - //or the renter is out of the alliance - foreach($rentals as $rental) { - if($rental->Type == 'alliance') { - $alliance++; - } else { - $outofalliance++; - } - } - - //Return the rental type - if($alliance > $outofalliance) { - return 'alliance'; - } else { - return 'outofalliance'; - } - } -} diff --git a/app/Console/Commands/Moons/RentalMoonCommand.php b/app/Console/Commands/Moons/RentalMoonCommand.php deleted file mode 100644 index 6ee47a85c..000000000 --- a/app/Console/Commands/Moons/RentalMoonCommand.php +++ /dev/null @@ -1,74 +0,0 @@ -SetStartStatus(); - - //Get all of the contacts from the rentals group - $contacts = MoonRental::select('Contact')->groupBy('Contact')->get(); - - foreach($contacts as $contact) { - MoonRentalInvoiceCreate::dispatch($contact, $delay)->onQueue('moons'); - - //Increase the delay after each job to prevent mails from backing up later down the queue - $delay += 20; - } - - //Set the job as completed - $task->SetStopStatus(); - } -} diff --git a/app/Console/Commands/Moons/UpdateMoonPricing.php b/app/Console/Commands/Moons/UpdateMoonPricing.php deleted file mode 100644 index b1325f757..000000000 --- a/app/Console/Commands/Moons/UpdateMoonPricing.php +++ /dev/null @@ -1,55 +0,0 @@ -SetStartStatus(); - - $moonCalc = new MoonCalc(); - $moonCalc->FetchNewPrices(); - - //Mark the job as finished - $task->SetStopStatus(); - } -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 54962ed2e..7d60f24f7 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -49,18 +49,11 @@ class Kernel extends ConsoleKernel $schedule->command('services:HoldingJournal') ->hourlyAt('45') ->withoutOverlapping(); - //Command to update moon rental pricing - $schedule->command('services:UpdateMoonPrice') - ->hourlyAt('30'); //Get the corps within the alliance $schedule->command('services:GetCorps') ->monthlyOn(1, '09:00'); - //Update the moons, and send out mails for current moon rentals - $schedule->command('services:MoonMailer') - ->monthlyOn(1, '00:01'); - //Get the structures within the alliance and their information $schedule->command('services:GetStructures') ->dailyAt('09:00');