diff --git a/app/Console/Commands/SystemRental/SystemRentalCommand.php b/app/Console/Commands/SystemRental/SystemRentalCommand.php new file mode 100644 index 000000000..f7ad23dfd --- /dev/null +++ b/app/Console/Commands/SystemRental/SystemRentalCommand.php @@ -0,0 +1,133 @@ +SetStartStatus(); + + //Create other variables + $body = null; + $delay = 30; + + //Get today's date + $today = Carbon::now(); + $today->second = 2; + $today->minute = 0; + $today->hour = 0; + + //Get the esi configuration + $config = config('esi'); + + //Get all of the contacts for the system rentals + $contacts = RentalSystem::select('contact_id')->orderBy('contact_id')->get(); + + //For each of the contacts send a reminder mail about the total of the systems they are paying for + foreach($contacts as $contact) { + //Get all of the systems + $systems = RentalSystem::where([ + 'contact_id' => $contact->contact_id, + ])->get(); + + //Totalize the total cost of all of the systems + $totalCost = $this->TotalizeCost($systems); + + //Build the body of the mail + $body = "System Rental Cost is due for the following systems:
"; + foreach($systems as $system) { + $body .= $system->system_name . "
"; + } + + //Create the rest of the email body + $body .= "Total Cost: " . number_format($totalCost, 2, ".", ","); + $body .= "Please remite payment to White Wolves Holding.
"; + $body .= "Sincerely,
"; + $body .= "Warped Intentions Leadership
"; + + //Fill in the subject + $subject = "Warped Intentions System Rental Bill Due"; + + //Dispatch the mail job + ProcessSendEveMailJob::dispatch($body, (int)$contact->contact_id, 'character', $subject, $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay)); + + //Increase the delay for the next mail job + $delay += 60; + + //After the mail is dispatched, save the sent mail record + $this->SaveSentRecord($config['primary'], $subject, $body, (int)$contact->contact_id, 'character'); + } + + //Mark the job as finished + $task->SetStopStatus(); + + } + + private function TotalizeCost($systems) { + //Declare the starting total cost + $totalCost = 0.00; + + foreach($systems as $system) { + $totalCost += $system->rental_cost; + } + + return $totalCost; + } + + private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) { + $sentmail = new SentMail; + $sentmail->sender = $sender; + $sentmail->subject = $subject; + $sentmail->body = $body; + $sentmail->recipient = $recipient; + $sentmail->recipient_type = $recipientType; + $sentmail->save(); + } +} diff --git a/app/Http/Controllers/SystemRentals/RentalAdminController.php b/app/Http/Controllers/SystemRentals/RentalAdminController.php new file mode 100644 index 000000000..83bd5916c --- /dev/null +++ b/app/Http/Controllers/SystemRentals/RentalAdminController.php @@ -0,0 +1,142 @@ +middleware('auth'); + $this->middleware('role:Admin'); + } + + /** + * Function to display all active rental systems and + * the information regarding the rental systems + */ + public function displayRentalSystems() { + //Get the rental systems form the database + $rentals = RentalSytem::all(); + + //Return the view with the data + return view('rental.list')->with('rentals', $rentals); + } + + /** + * Function to display form for adding new rental system + */ + public function displayAddRentalSystem() { + return view('rental.add'); + } + + /** + * Function to add new rental system to the database + */ + public function addRentalSystem(Request $request) { + $this->validate($request, [ + 'contact_name' => 'required', + 'contact_corp_name' => 'required', + 'system' => 'required', + 'rental_cost' => 'required', + 'paid_until' => 'required', + ]); + + //Declare the variables and classes needed + $lookup = new LookupHelper; + + //From the character name find the character id + $charId = $lookup->CharacterNameToId($request->contact_name); + + //From the corporation name find the corporation id + $corpId = $lookup->CorporationNameToId($request->contact_corp_name); + + //From the system name find the system id + $systemId = $lookup->SystemNameToId($request->system); + + //Sanitize the bid amount + if(preg_match('(m|M|b|B)', $request->rental_cost) === 1) { + if(preg_match('(m|M)', $request->rental_cost) === 1) { + $cStringSize = strlen($request->rental_cost); + $tempCol = str_split($request->rental_cost, $cStringSize - 1); + $rentalCost = $tempCol[0]; + $rentalCost = $rentalCost * 1000000000.00; + } else if(preg_match('(b|B)', $request->rental_cost) === 1) { + $cStringSize = strlen($request->rental_cost); + $tempCol = str_split($request->rental_cost, $cStringSize - 1); + $rentalCost = $tempCol[0]; + $rentalCost = $rentalCost * 1000000000000.00; + } + } else { + $rentalCost = $request->rental_cost; + } + + //Create the database model + $rental = new RentalSystem; + $rental->contact_id = $charId; + $rental->contact_name = $request->contact_name; + $rental->corporation_id = $corpId; + $rental->corporation_name = $request->contact_corp_name; + $rental->system_id = $systemId; + $rental->system_name = $system_name; + $rental->rental_cost = $rentalCost; + $rental->paid_until = $request->paid_until; + $rental->save(); + + return redirect('/rental/display')->with('success', 'Rental System Added.'); + } + + /** + * Function to update paid until section of the rental system in the database + */ + public function updateRentalSystem(Request $request) { + $this->validate($request, [ + 'paid_until' => 'required', + 'contact_id' => 'required', + 'corporation_id' => 'required', + 'system' => 'required', + ]); + + RentalSystem::where([ + 'character_id' => $request->contact_id, + 'corporation_id' => $request->corporation_id, + 'system_id' => $request->system, + ])->update([ + 'paid_until' => $request->paid_until, + ]); + + return redirect('/rental/display')->with('success', 'Rental System updated.'); + } + + /** + * Function to remove rental system from the database + */ + public function removeRentalSystem(Request $request) { + $this->validate($request, [ + 'contact_id' => 'required', + 'corporation_id' => 'required', + 'system' => 'reuquired', + ]); + + RentalSystem::where([ + 'contact_id' => $request->contact_id, + 'corporation_id' => $request->corporation_id, + 'system_id' => $request->system, + ])->delete(); + + return redirect('/rental/display')->with('success', 'Removed renter from database.'); + } +} diff --git a/app/Models/SystemRentals/RentalSystem.php b/app/Models/SystemRentals/RentalSystem.php new file mode 100644 index 000000000..a7017ccb7 --- /dev/null +++ b/app/Models/SystemRentals/RentalSystem.php @@ -0,0 +1,34 @@ +bigIncrements('id'); + $table->unsignedBigInteger('contact_id'); + $table->string('contact_name'); + $table->unsignedBigInteger('corporation_id'); + $table->string('corporation_name'); + $table->unsignedBigInteger('system_id'); + $table->string('system_name'); + $table->double('rental_cost', 20, 2); + $table->dateTime('paid_until'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('alliance_rental_systems'); + } +} diff --git a/resources/views/layouts/admin/dashboard/main.blade.php b/resources/views/layouts/admin/dashboard/main.blade.php index 81fd99818..10b8990bb 100644 --- a/resources/views/layouts/admin/dashboard/main.blade.php +++ b/resources/views/layouts/admin/dashboard/main.blade.php @@ -29,6 +29,9 @@ @include('layouts.admin.sidebarmenu.srp') + + @include('layouts.admin.sidebarmenu.rentalsystem') + diff --git a/resources/views/layouts/admin/sidebarmenu/rentalsystem.blade.php b/resources/views/layouts/admin/sidebarmenu/rentalsystem.blade.php new file mode 100644 index 000000000..1f829adb7 --- /dev/null +++ b/resources/views/layouts/admin/sidebarmenu/rentalsystem.blade.php @@ -0,0 +1,27 @@ + +@if(auth()->user()->hasRole('Admin')) +