Skip to content

Commit

Permalink
Fetched shipment history using jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwebwiz committed Dec 13, 2017
1 parent 00d62da commit 10429df
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/Http/Controllers/TrackingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\ShipmentHistory;
use App\Tracking;
use Illuminate\Http\Request;

class TrackingsController extends Controller
Expand Down Expand Up @@ -112,4 +113,16 @@ public function delete($id)
\App\Tracking::where('trackingID', $id)->delete();
return back()->with('info', 'Tracking Information deleted');
}

public function newShipmentHistory(Request $request, $id)
{
$tracking = Tracking::where('trackingID', $id)->first();
$history = new ShipmentHistory;
$history->location = $request->shipping_location;
$history->date = $request->shipping_date;
$history->time = $request->shipping_time;
$history->status = $request->shipping_status;
$tracking->shipmentHistories()->save($history);
return back()->with('success', 'Shipment History Added');
}
}
169 changes: 169 additions & 0 deletions resources/views/tracking/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,154 @@
</form>
</div>
</div>

<!-- Shipment Details -->
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h4>Shipment History</h4>
<hr>
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<th>Location</th>
<th>Date</th>
<th>Time</th>
<th>Status/Activity</th>
<th>Action</th>
</thead>
<tbody>
@foreach ($tracking->shipmentHistories()->orderBy('created_at', 'desc')->get() as $history)
<tr>
<td class="location">{{ $history->location }}</td>
<td class="date">{{ date('d/m/Y', strtotime($history->date)) }}</td>
<td class="time">{{ date('H:ia', strtotime($history->time)) }}</td>
<td class="status">{{ $history->status }}</td>
<td>
<a href="#" class="edit btn btn-info">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<button class="btn btn-primary pull-right" data-toggle="modal" data-target="#myModal"
type="button">
Add New Shipment History
</button>
</div>
</div>
</div>

<!-- Modal to Add New Shipment History -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">New Shipment History</h4>
</div>
<div class="modal-body">
<form action="{{ route('addNewShipmentHistory', ['id'=>$tracking->trackingID]) }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label>Location</label>
<div>
<input type="text" name="shipping_location" placeholder="Shipment Location"
class="form-control" value="{{ old('shipping_location') }}">
</div>
</div>

<div class="form-group">
<label>Date</label>
<div>
<input type="date" name="shipping_date" placeholder="Shipment Date"
class="form-control" value="{{ old('shipping_date') }}">
</div>
</div>

<div class="form-group">
<label>Time</label>
<div>
<input type="time" name="shipping_time" placeholder="Shipment Time"
class="form-control" value="{{ old('shipping_time') }}">
</div>
</div>

<div class="form-group">
<label>Status</label>
<div>
<textarea name="shipping_status" rows="5" class="form-control"
placeholder="Shipment Status">{{ old('shipping_status') }}</textarea>
</div>
</div>

<div class="form-group">
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<!-- Modal to Edit Shipment History -->
<div id="editModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Edit Shipment History</h4>
</div>
<div class="modal-body">
<form action="{{ route('addNewShipmentHistory', ['id'=>$tracking->trackingID]) }}" method="post">
{{ csrf_field() }}
<div class="form-group">
<label>Location</label>
<div>
<input type="text" name="shipping_location" id="shipping_location" placeholder="Shipment Location"
class="form-control">
</div>
</div>

<div class="form-group">
<label>Date</label>
<div>
<input type="text" name="shipping_date" id="shipping_date" placeholder="Shipment Date"
class="form-control">
</div>
</div>

<div class="form-group">
<label>Time</label>
<div>
<input type="text" name="shipping_time" id="shipping_time" placeholder="Shipment Time"
class="form-control">
</div>
</div>

<div class="form-group">
<label>Status</label>
<div>
<textarea name="shipping_status" id="shipping_status" rows="5" class="form-control"
placeholder="Shipment Status"></textarea>
</div>
</div>

<div class="form-group">
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -223,6 +371,27 @@

<script type="text/javascript">
$(document).ready(function(){
// Edit Modal
$('.edit').on('click', function(event) {
event.preventDefault();
// Get the necessary fields
var shipping_location = $(this).parent().parent().find('td').eq(0).text();
var shipping_date = $(this).parent().parent().find('td').eq(1).text();
var shipping_time = $(this).parent().parent().find('td').eq(2).text();
var shipping_status = $(this).parent().parent().find('td').eq(3).text();
// Pass the values into the edit modal
$('#shipping_location').val(shipping_location);
$('#shipping_date').val(shipping_date);
$('#shipping_time').val(shipping_time);
$('#shipping_status').val(shipping_status);
// Initialize the modal
$('#editModal').modal();
});
// Geolocation
$('#geolocation, #coordinates').hide();
var locationType = $('#location-type');
locationType.on('click', function(){
Expand Down
5 changes: 2 additions & 3 deletions resources/views/tracking/new.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ class="form-control" value="{{ old('shipping_time') }}">
<div class="form-group">
<label class="control-label col-sm-4">Status</label>
<div class="col-sm-8">
<textarea name="shipping_status" rows="5" class="form-control" placeholder="Shipment Status">
{{ old('shipping_status') }}
</textarea>
<textarea name="shipping_status" rows="5" class="form-control"
placeholder="Shipment Status">{{ old('shipping_status') }}</textarea>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
Route::post('trackings/new', 'TrackingsController@addNewTracking')->name('addNewTracking');
Route::get('trackings/{id}/edit', 'TrackingsController@showEditTrackingForm')->name('showEditTrackingForm');
Route::put('trackings/{id}/edit', 'TrackingsController@editTracking')->name('editTracking');
Route::post('trackings/{id}/edit', 'TrackingsController@newShipmentHistory')->name('addNewShipmentHistory');
Route::get('trackings/{id}/delete', 'TrackingsController@delete')->name('delete');

0 comments on commit 10429df

Please sign in to comment.