created form for rental costs similar to flex structures

This commit is contained in:
2020-08-10 02:17:21 -05:00
parent 8dd1377090
commit 5fd183f95c
11 changed files with 478 additions and 2 deletions

View File

@@ -0,0 +1,133 @@
<?php
namespace App\Console\Commands\SystemRental;
//Internal Library
use Illuminate\Console\Command;
use Carbon\Carbon;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
//Library
use Command\Library\CommandHelper;
//Models
use App\Models\Rentals\RentalSystem;
use App\Models\Mail\SentMail;
class SystemRentalCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:SystemRentals';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Mail out bill for system rentals.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the new command helper container
$task = new CommandHelper('SystemRentalMailer');
//Add the entry into the jobs table saying the job has started
$task->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:<br>";
foreach($systems as $system) {
$body .= $system->system_name . "<br>";
}
//Create the rest of the email body
$body .= "Total Cost: " . number_format($totalCost, 2, ".", ",");
$body .= "Please remite payment to White Wolves Holding.<br>";
$body .= "Sincerely,<br>";
$body .= "Warped Intentions Leadership<br>";
//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();
}
}

View File

@@ -0,0 +1,142 @@
<?php
namespace App\Http\Controllers\SystemRentals;
//Internal Library
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Carbon\Carbon;
//Models
use App\Models\Rentals\RentalSystem;
//Library
use App\Library\Lookups\LookupHelper;
use App\Library\Esi\Esi;
class RentalAdminController extends Controller
{
//Constructor
public function __construct() {
$this->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.');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models\Rentals;
use Illuminate\Database\Eloquent\Model;
class RentalSystem extends Model
{
/**
* Table Name
*/
public $table = 'alliance_rental_systems';
/**
* Timestamps
*/
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'contact_id',
'contact_name',
'corporation_id',
'corporation_name',
'system_id',
'system_name',
'rental_cost',
'paid_until',
];
}

View File

@@ -0,0 +1,41 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRentalRecordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('alliance_rental_systems')) {
Schema::create('alliance_rental_systems', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -29,6 +29,9 @@
<!-- SRP Admin --> <!-- SRP Admin -->
@include('layouts.admin.sidebarmenu.srp') @include('layouts.admin.sidebarmenu.srp')
<!-- End SRP Admin --> <!-- End SRP Admin -->
<!-- System Rental Admin -->
@include('layouts.admin.sidebarmenu.rentalsystem')
<!-- End System Rental Admin -->
</ul> </ul>
</nav> </nav>
<!-- /.sidebar-menu --> <!-- /.sidebar-menu -->

View File

@@ -0,0 +1,27 @@
<!-- System Rentals -->
@if(auth()->user()->hasRole('Admin'))
<li class="nav-item has-treeview">
<a href="#" class="nav-link">
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
System Rental<br>
<i class="right fas fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="/system/rental/display" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Display</p>
</a>
</li>
<li class="nav-item">
<a href="/system/rental/add" class="nav-link">
<i class="far fa-circle nav-icon"></i>
<p>Add</p>
</a>
</li>
</u>
</li>
@endif
<!-- End System Rentals -->

View File

@@ -0,0 +1,31 @@
@extends('layouts.admn.b4')
@section('content')
<div class="container">
<div class="card">
<div class="card-header">
<h2>New Rental Contract</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'SystemRentals\RentalAdminController@addRentalSystem', 'method' => 'POST']) !!}
<div class="form-group">
{{ Form::label('contact_name', 'Contact Name') }}
{{ Form::text('contact_name', '', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('corporation_name', 'Corporation Name') }}
{{ Form::text('corporation_name', '', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('system', 'System') }}
{{ Form::text('system', '', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('rental_cost', 'Rental Cost') }}
{{ Form::text('rental_cost', '', ['class' => 'form-control']) }}
</div>
{{ Form::submit('Add Rental', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
</div>
</div>
</div>
@endsection

View File

@@ -0,0 +1,56 @@
@extends('layouts.admin.b4')
@section('content')
<br>
<div class="container">
<div class="card">
<div class="card-header">
<h2>Rental Systems</h2>
</div>
<div class="card-body">
<table clas="table table-bordered table-striped">
<thead>
<th>Contact</th>
<th>Corporation</th>
<th>System</th>
<th>Cost</th>
<th>Paid Until</th>
<th>Update</th>
<th>Remove?</th>
<th> </th>
</thead>
<tbody>
@foreach($rentals as $rental)
<tr>
<td>{{ $rental->contact_name }}</td>
<td>{{ $rental->corporation_name }}</td>
<td>{{ $rental->system }}</td>
<td>{{ number_format($rental->rental_cost, "2", ".", ",") }}</td>
<td>{{ $rental->paid_until }}</td>
<td>
{!! Form::open(['action' => 'SystemRentals\RentalAdminController@updateRentalSystem', 'method' => 'POST']) !!}
{{ Form::date('paid_until', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}
{{ Form::hidden('contact_id', $rental->contact_id) }}
{{ Form::hidden('corporation_id', $rental->corporation_id) }}
{{ Form::hidden('system_id', $rental->system_id) }}
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
</td>
<td>
{!! Form::open(['action' => 'SystemRentals\RentalAdminController@removeRentalSystem', 'method' => 'POST']) !!}
{{ Form::radio('remove', 'Yes', false, ['class' => 'form-control']) }}
{{ Form::hidden('contact_id', $rental->contact_id) }}
{{ Form::hidden('corporation_id', $rental->corporation_id) }}
{{ Form::hidden('system_id', $rental->system_id) }}
</td>
<td>
{{ Form::submit('Remove', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endsection

View File

@@ -191,6 +191,15 @@ Route::group(['middleware' => ['auth']], function(){
Route::get('/supplychain/modify/bid', 'Contracts\SupplyChainController@displayModifySupplyChainContractBid'); Route::get('/supplychain/modify/bid', 'Contracts\SupplyChainController@displayModifySupplyChainContractBid');
Route::post('/supplychain/modify/bid', 'Contracts\SupplyChainController@modifySupplyChainContractBid'); Route::post('/supplychain/modify/bid', 'Contracts\SupplyChainController@modifySupplyChainContractBid');
/**
* System Rentals Controller display pages
*/
Route::get('/system/rental/dashboard', 'RentalSystem\RentalAdminController@displayRentalSystems');
Route::get('/system/rental/add', 'RentalSystem\RentalAdminController@displayAddRentalSystem');
Route::post('/system/rental/add', 'RentalSystem\RentalAdminController@addRentalSystem');
Route::post('/system/rental/update', 'RentalSystem\RentalAdminController@updateRentalSystem');
Route::post('/system/rental/remove', 'RentalSystem\RentalAdminController@removeRentalSystem');
/** /**
* Test Controller display pages * Test Controller display pages
*/ */

View File

@@ -42,7 +42,7 @@ return array(
'App\\Http\\Controllers\\Moons\\MoonsAdminController' => $baseDir . '/app/Http/Controllers/Moons/MoonsAdminController.php', 'App\\Http\\Controllers\\Moons\\MoonsAdminController' => $baseDir . '/app/Http/Controllers/Moons/MoonsAdminController.php',
'App\\Http\\Controllers\\Moons\\MoonsController' => $baseDir . '/app/Http/Controllers/Moons/MoonsController.php', 'App\\Http\\Controllers\\Moons\\MoonsController' => $baseDir . '/app/Http/Controllers/Moons/MoonsController.php',
'App\\Http\\Controllers\\Moons\\RentalMoonsAdminController' => $baseDir . '/app/Http/Controllers/Moons/RentalMoonsAdminController.php', 'App\\Http\\Controllers\\Moons\\RentalMoonsAdminController' => $baseDir . '/app/Http/Controllers/Moons/RentalMoonsAdminController.php',
'App\\Http\\Controllers\\PublicContractController' => $baseDir . '/app/Http/Controllers/Contracts/PublicContractController.php', 'App\\Http\\Controllers\\RentalAdminController' => $baseDir . '/app/Http/Controllers/Rental/RentalAdminController.php',
'App\\Http\\Controllers\\SRP\\SRPAdminController' => $baseDir . '/app/Http/Controllers/SRP/SRPAdminController.php', 'App\\Http\\Controllers\\SRP\\SRPAdminController' => $baseDir . '/app/Http/Controllers/SRP/SRPAdminController.php',
'App\\Http\\Controllers\\SRP\\SRPController' => $baseDir . '/app/Http/Controllers/SRP/SRPController.php', 'App\\Http\\Controllers\\SRP\\SRPController' => $baseDir . '/app/Http/Controllers/SRP/SRPController.php',
'App\\Http\\Controllers\\Test\\TestController' => $baseDir . '/app/Http/Controllers/Test/TestController.php', 'App\\Http\\Controllers\\Test\\TestController' => $baseDir . '/app/Http/Controllers/Test/TestController.php',

View File

@@ -511,7 +511,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Http\\Controllers\\Moons\\MoonsAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/MoonsAdminController.php', 'App\\Http\\Controllers\\Moons\\MoonsAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/MoonsAdminController.php',
'App\\Http\\Controllers\\Moons\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/MoonsController.php', 'App\\Http\\Controllers\\Moons\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/MoonsController.php',
'App\\Http\\Controllers\\Moons\\RentalMoonsAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/RentalMoonsAdminController.php', 'App\\Http\\Controllers\\Moons\\RentalMoonsAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/Moons/RentalMoonsAdminController.php',
'App\\Http\\Controllers\\PublicContractController' => __DIR__ . '/../..' . '/app/Http/Controllers/Contracts/PublicContractController.php', 'App\\Http\\Controllers\\RentalAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/Rental/RentalAdminController.php',
'App\\Http\\Controllers\\SRP\\SRPAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/SRP/SRPAdminController.php', 'App\\Http\\Controllers\\SRP\\SRPAdminController' => __DIR__ . '/../..' . '/app/Http/Controllers/SRP/SRPAdminController.php',
'App\\Http\\Controllers\\SRP\\SRPController' => __DIR__ . '/../..' . '/app/Http/Controllers/SRP/SRPController.php', 'App\\Http\\Controllers\\SRP\\SRPController' => __DIR__ . '/../..' . '/app/Http/Controllers/SRP/SRPController.php',
'App\\Http\\Controllers\\Test\\TestController' => __DIR__ . '/../..' . '/app/Http/Controllers/Test/TestController.php', 'App\\Http\\Controllers\\Test\\TestController' => __DIR__ . '/../..' . '/app/Http/Controllers/Test/TestController.php',