moon update and flex structure update

This commit is contained in:
2020-02-03 23:35:38 -06:00
parent 4215dea758
commit 1f2686ed28
7 changed files with 106 additions and 31 deletions

View File

@@ -29,10 +29,10 @@ class FlexAdminController extends Controller
* the information regarding the flex structure
*/
public function displayFlexStructures() {
//Get the structures from the database
$structures = FlexStructure::all();
//Return the view with the data
return view('flex.list')->with('structures', $structures);
}
@@ -77,24 +77,51 @@ class FlexAdminController extends Controller
$flex->system = $request->system;
$flex->structure_type = $request->structure_type;
$flex->structure_cost = $request->structure_cost;
if(isset($request->paid_until)) {
$flex->paid_until = $request->paid_until;
}
$flex->save();
return redirect('/flex/display')->with('success', 'Flex Structure Added.');
}
/**
* Function to update paid until section of the flex structure in the database
*/
public function updateFlexStructure(Request $request) {
$this->validate($request, [
'paid_until' => 'required',
'requestor_id' => 'required',
'requestor_corp_id' => 'required',
'system_id' => 'required',
'structure_type' => 'required',
]);
FlexStructure::where([
'requestor_id' => $request->requestor_id,
'requestor_corp_id' => $request->requestor_corp_id,
'system_id' => $request->system_id,
'structure_type' => $request->structure_type,
])->update([
'paid_until' => $request->paid_until,
]);
}
/**
* Funciton to remove flex structure from the database
*/
public function removeFlexStructure(Request $request) {
$this->validate($request, [
'requestor_name' => 'required',
'system' => 'required',
'requestor_id' => 'required',
'requestor_corp_id' => 'required',
'system_id' => 'required',
'structure_type' => 'required',
]);
FlexStructure::where([
'requestor_name' => $request->requestor_name,
'system' => $request->system,
'requestor_id' => $request->requestor_id,
'requestor_corp_id' => $request->requestor_corp_id,
'system' => $request->system_id,
'structure_type' => $request->structure_type,
])->delete();

View File

@@ -225,6 +225,7 @@ class MoonsAdminController extends Controller
'spmn' => 'required',
'date' => 'required',
'contact' => 'required',
'paid_until' => 'required',
]);
//Decode the System, Planet, Moon, Name combinatio sent from the controller
@@ -255,13 +256,6 @@ class MoonsAdminController extends Controller
} else {
$paid = 'No';
}
//Update the paid unti value for the database entry
if(isset($request->Paid_Until)) {
$paidUntil = $request->Paid_Until;
} else {
$paidUntil = null;
}
//Create the rnetal ticker if the corp is in Warped Intentions, otherwise just display the alliance ticker
if($allianceId == 99004116) {
@@ -271,15 +265,11 @@ class MoonsAdminController extends Controller
}
//Create the date
$date = new Carbon($request->date . '00:00:01');
//Count how many rentals we find for later database processing
$count = MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $mn,
'Contact' => $contact,
])->count();
if(isset($request->paid_until)) {
$paidUntil = new Carbon($request->paid_until . '00:00:01');
} else {
$paidUntil = Carbon::now();
}
//Calculate the price of the moon for when it's updated
$moon = Moon::where([
@@ -291,10 +281,55 @@ class MoonsAdminController extends Controller
//Calculate the price of the rental and store it in the database
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
//Count how many rentals we find for later database processing
$count = MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $mn,
'Contact' => $contact,
])->count();
//If the database entry isn't found, then insert it into the database,
//otherwise, account for it being in the system already.
if($count != 0) {
//Also check for the weird condition of more than one moon entry existing
if($count > 1) {
//If more than one entry is found for a particular system, planet, moon combo, then delete all the entries, and put in
// a single new entry
MoonRental::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $moon,
])->delete();
if($allianceId == 99004116) {
$store = new MoonRental;
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $date;
$store->Contact = $contact;
$store->Price = $price['alliance'];
$store->Type = 'alliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
} else {
$store = new MoonRental;
$store->System = $system;
$store->Planet = $planet;
$store->Moon = $mn;
$store->RentalCorp = $renter;
$store->RentalEnd = $date;
$store->Contact = $contact;
$store->Price = $price['outofalliance'];
$store->Type = 'outofalliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
}
} else if($count == 1) {
if($allianceId = 99004116) {
MoonRental::where([
'System' => $system,
@@ -311,7 +346,7 @@ class MoonsAdminController extends Controller
'Price' => $price['alliance'],
'Type' => 'alliance',
'Paid' => $paid,
'Paid_Until' => $request->paid_until,
'Paid_Until' => $paidUntil,
]);
} else {
MoonRental::where([
@@ -329,7 +364,7 @@ class MoonsAdminController extends Controller
'Price' => $price['outofalliance'],
'Type' => 'outofalliance',
'Paid' => $paid,
'Paid_Until' => $request->paid_until,
'Paid_Until' => $paidUntil,
]);
}
} else {
@@ -352,6 +387,7 @@ class MoonsAdminController extends Controller
$store->Price = $price['alliance'];
$store->Type = 'alliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
} else {
$store = new MoonRental;
@@ -364,6 +400,7 @@ class MoonsAdminController extends Controller
$store->Price = $price['outofalliance'];
$store->Type = 'outofalliance';
$store->Paid = $paid;
$store->Paid_Until = $paidUntil;
$store->save();
}
}

View File

@@ -30,5 +30,6 @@ class FlexStructure extends Model
'system',
'structure_type',
'structure_cost',
'paid_until',
];
}

View File

@@ -29,6 +29,7 @@ class CreateFlexStructuresTable extends Migration
'Super Construction Facilities',
]);
$table->double('structure_cost', 20, 2);
$table->dateTime('paid_until');
$table->timestamps();
});
}

View File

@@ -7,7 +7,6 @@
<h2>Flex Structures</h2>
</div>
<div class="card-body">
{!! Form::open(['action' => 'Flex\FlexAdminController@removeFlexStructure', 'method' => 'POST']) !!}
<table class="table table-bordered table-striped">
<thead>
<th>Requestor</th>
@@ -15,6 +14,7 @@
<th>System</th>
<th>Structure Type</th>
<th>Cost</th>
<th>Update</th>
<th>Remove?</th>
</thead>
<tbody>
@@ -26,17 +26,25 @@
<td>{{ $structure->structure_type }}</td>
<td>{{ number_format($structure->structure_cost, "2", ".", ",") }}</td>
<td>
{!! Form::open(['action' => 'Flex\FlexAdminController@updateFlexStructure', 'method' => 'POST']) !!}
{{ Form::date('paid_until', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}
{{ submit('Update', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
</td>
<td>
{!! Form::open(['action' => 'Flex\FlexAdminController@removeFlexStructure', 'method' => 'POST']) !!}
{{ Form::radio('remove', 'Yes', false, ['class' => 'form-control']) }}
{{ Form::hidden('requestor_name', $structure->requestor_name) }}
{{ Form::hidden('system', $structure->system) }}
{{ Form::hidden('structure_type', $structure->structure_type) }}
{{ Form::hidden('requestor_id', $structure->requestor_id) }}
{{ Form::hidden('requestor_corp_id', $structure->requestor_corp_id) }}
{{ Form::hidden('system_id', $structure->system_id) }}
{{ Form::submit('Remove', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
{{ Form::submit('Remove', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
</div>
</div>
</div>

View File

@@ -12,8 +12,8 @@
{{ Form::text('contact', '', ['class' => 'form-control', 'placeholder' => 'Character']) }}
</div>
<div class="form-group col-md-6">
{{ Form::label('date', 'Rental End Date') }}
{{ Form::date('date', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}
{{ Form::label('paid_until', 'Rental End Date') }}
{{ Form::date('paid_until', \Carbon\Carbon::now()->endOfMonth(), ['class' => 'form-control']) }}
</div>
<div class="form-group">
Paid?<br>

View File

@@ -116,6 +116,7 @@ Route::group(['middleware' => ['auth']], function(){
Route::get('/flex/display/add', 'Flex\FlexAdminController@displayAddFlexStructure');
Route::post('/flex/display/add', 'Flex\FlexAdminController@addFlexStructure');
Route::post('/flex/display/remove', 'Flex\FlexAdminController@removeFlexStructure');
Route::post('/flex/display/update', 'Flex\FlexAdminController@updateFlexStructure');
/**
* Fuel Controller display pages