update to how moons are displayed for the admin page

This commit is contained in:
2019-04-24 00:59:37 -05:00
parent 03c3c7ac6d
commit 899db99955
4 changed files with 88 additions and 24 deletions

View File

@@ -124,6 +124,15 @@ class MoonMailerCommand extends Command
MoonRent::where(['id' => $rental->id])->delete(); MoonRent::where(['id' => $rental->id])->delete();
} }
//Mark the moon as not paid for the next month
Moon::where([
'System' => $rental->System,
'Planet' => $rental->Planet,
'Moon' => $rental->Moon,
])->update([
'Paid' => 'No',
]);
} }
//Mark the job as finished //Mark the job as finished

View File

@@ -186,13 +186,21 @@ class MoonsAdminController extends Controller
foreach($moons as $moon) { foreach($moons as $moon) {
//Setup formats as needed //Setup formats as needed
$spm = $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon; $spm = $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon;
//Set the rental end date
$rentalTemp = new Carbon($moon->RentalEnd); $rentalTemp = new Carbon($moon->RentalEnd);
//Set the rental end date as month / day
$rentalEnd = $rentalTemp->format('m-d'); $rentalEnd = $rentalTemp->format('m-d');
//Get today's date in order to create color later on in the table
$today = Carbon::now(); $today = Carbon::now();
//Calculate the prices of the moon based on what is in the moon
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
//Set the paid as yes or no for the check box in the blade template
$paid = $moon->Paid;
//Set the color for the table
if($rentalTemp->diffInDays($today) < 3 ) { if($rentalTemp->diffInDays($today) < 3 ) {
$color = 'table-warning'; $color = 'table-warning';
} else if( $today > $rentalTemp) { } else if( $today > $rentalTemp) {
@@ -205,22 +213,40 @@ class MoonsAdminController extends Controller
array_push($table, [ array_push($table, [
'SPM' => $spm, 'SPM' => $spm,
'StructureName' => $moon->StructureName, 'StructureName' => $moon->StructureName,
'FirstOre' => $moon->FirstOre,
'FirstQuantity' => $moon->FirstQuantity,
'SecondOre' => $moon->SecondOre,
'SecondQuantity' => $moon->SecondQuantity,
'ThirdOre' => $moon->ThirdOre,
'ThirdQuantity' => $moon->ThirdQuantity,
'FourthOre' => $moon->FourthOre,
'FourthQuantity' => $moon->FourthQuantity,
'AlliancePrice' => $price['alliance'], 'AlliancePrice' => $price['alliance'],
'OutOfAlliancePrice' => $price['outofalliance'], 'OutOfAlliancePrice' => $price['outofalliance'],
'Renter' => $moon->RentalCorp, 'Renter' => $moon->RentalCorp,
'RentalEnd' => $rentalEnd, 'RentalEnd' => $rentalEnd,
'RowColor' => $color, 'RowColor' => $color,
'Paid' => $paid,
]); ]);
} }
return view('moons/admin/adminmoon')->with('table', $table); return view('moons/admin/adminmoon')->with('table', $table);
} }
public function UpdateMoonPaid(Request $request) {
$this->validate($request, [
'paid' => 'required',
]);
$str_array = explode(" - ", $request->paid);
//Decode the value for the SPM into a system, planet, and moon for the database to update
$system = $str_array[0];
$planet = $str_array[1];
$moon = $str_array[2];
//Update the paid status of the moon
MoonRent::where([
'System' => $system,
'Planet' => $planet,
'Moon' => $moon,
])->update([
'Paid' => 'Yes',
]);
//Redirect back to the moon page, which should call the page to be displayed correctly
return redirect('moons/admin/adminmoon');
}
} }

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyMoonsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(Schema::hasTable('Moons')) {
Schema::table('Moons', function (Blueprint $table) {
$table->string('Paid');
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('Moons', function (Blueprint $table) {
$table->dropColumn('Paid');
});
}
}

View File

@@ -1,47 +1,42 @@
@extends('layouts.b4') @extends('layouts.b4')
@section('content') @section('content')
{!! Form::open(['action' => 'MoonsAdminController@updateMoonPaid', 'method' => 'POST']) !!}
<div class="container col-md-12"> <div class="container col-md-12">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<th>System</th> <th>System</th>
<th>Name</th> <th>Name</th>
<th>First Ore</th>
<th>Quantity</th>
<th>Second Ore</th>
<th>Quantity</th>
<th>Third Ore</th>
<th>Quantity</th>
<th>Fourth Ore</th>
<th>Quantity</th>
<th>Rental Price</th> <th>Rental Price</th>
<th>Ally Rental Price</th> <th>Ally Rental Price</th>
<th>Renter</th> <th>Renter</th>
<th>Rental End</th> <th>Rental End</th>
<th>Paid?</th>
</thead> </thead>
<tbody> <tbody>
@foreach($table as $row) @foreach($table as $row)
<tr class="{{ $row['RowColor'] }}"> <tr class="{{ $row['RowColor'] }}">
<td>{{ $row['SPM'] }}</td> <td>{{ $row['SPM'] }}</td>
<td>{{ $row['StructureName'] }}</td> <td>{{ $row['StructureName'] }}</td>
<td>{{ $row['FirstOre'] }}</td>
<td>{{ $row['FirstQuantity'] }}</td>
<td>{{ $row['SecondOre'] }}</td>
<td>{{ $row['SecondQuantity'] }}</td>
<td>{{ $row['ThirdOre'] }}</td>
<td>{{ $row['ThirdQuantity'] }}</td>
<td>{{ $row['FourthOre'] }}</td>
<td>{{ $row['FourthQuantity'] }}</td>
<td>{{ $row['AlliancePrice'] }}</td> <td>{{ $row['AlliancePrice'] }}</td>
<td>{{ $row['OutOfAlliancePrice'] }}</td> <td>{{ $row['OutOfAlliancePrice'] }}</td>
<td>{{ $row['Renter'] }}</td> <td>{{ $row['Renter'] }}</td>
<td>{{ $row['RentalEnd'] }}</td> <td>{{ $row['RentalEnd'] }}</td>
<td>
@if ($row['Paid'] == 'Yes')
{{ Form::radio('paid', $row['SPM'], true, ['class' => 'form-control']) }}
@elseif
{{ Form::radio('paid', null, false, ['class' => 'form-control']) }}
@endif
</td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
{!! Form::close() !!}
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">