This commit is contained in:
snipe 2016-12-15 15:15:11 -08:00
parent 4603000d12
commit cf2b57cb15
11 changed files with 67 additions and 66 deletions

View file

@ -22,6 +22,7 @@ use App\Models\Asset;
use App\Helpers\Helper;
use Auth;
use Gate;
use Illuminate\Http\Request;
/**
* This controller handles all actions related to Asset Maintenance for
@ -43,7 +44,7 @@ class AssetMaintenancesController extends Controller
*/
private static function getInsufficientPermissionsRedirect()
{
return redirect()->route('asset_maintenances')
return redirect()->route('maintenances.index')
->with('error', trans('general.insufficient_permissions'));
}
@ -58,7 +59,7 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return View
*/
public function getIndex()
public function index()
{
return View::make('asset_maintenances/index');
@ -74,34 +75,30 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return String JSON
*/
public function getDatatable()
public function getDatatable(Request $request)
{
$maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company','admin');
if (Input::has('search')) {
$maintenances = $maintenances->TextSearch(e(Input::get('search')));
$maintenances = $maintenances->TextSearch(e($request->input('search')));
}
if (Input::has('offset')) {
$offset = e(Input::get('offset'));
if ($request->has('offset')) {
$offset = e($request->input('offset'));
} else {
$offset = 0;
}
if (Input::has('limit')) {
$limit = e(Input::get('limit'));
$limit = e($request->input('limit'));
} else {
$limit = 50;
}
$allowed_columns = ['id','title','asset_maintenance_time','asset_maintenance_type','cost','start_date','completion_date','notes','user_id'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
switch ($sort) {
case 'user_id':
@ -121,8 +118,8 @@ class AssetMaintenancesController extends Controller
foreach ($maintenances as $maintenance) {
$actions = '';
if (Gate::allows('assets.edit')) {
$actions .= '<nobr><a href="' . route('update/asset_maintenance',
$maintenance->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/asset_maintenance',
$actions .= '<nobr><a href="' . route('maintenances.edit',
$maintenance->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('maintenances.destroy',
$maintenance->id) . '" data-content="' . trans('admin/asset_maintenances/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($maintenance->title) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
}
@ -134,7 +131,7 @@ class AssetMaintenancesController extends Controller
$rows[] = array(
'id' => $maintenance->id,
'asset_name' => ($maintenance->asset) ? (string)link_to('/hardware/'.$maintenance->asset->id.'/view', $maintenance->asset->showAssetName()) : 'Deleted Asset' ,
'asset_name' => ($maintenance->asset) ? (string)link_to_route('maintenances.show', $maintenance->asset->showAssetName(), ['maintenance' => $maintenance->asset->id]) : 'Deleted Asset' ,
'title' => $maintenance->title,
'notes' => $maintenance->notes,
'supplier' => ($maintenance->supplier) ? (string)link_to('/admin/settings/suppliers/'.$maintenance->supplier->id.'/view', $maintenance->supplier->name) : 'Deleted Supplier',
@ -163,7 +160,7 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return mixed
*/
public function getCreate($assetId = null)
public function create($assetId = null)
{
// Prepare Asset Maintenance Type List
$assetMaintenanceType = [
@ -194,11 +191,11 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return mixed
*/
public function postCreate()
public function store(Request $request)
{
// get the POST data
$new = Input::all();
$new = $request->all();
// create a new model instance
$assetMaintenance = new AssetMaintenance();
@ -207,39 +204,39 @@ class AssetMaintenancesController extends Controller
if (e(Input::get('supplier_id')) == '') {
$assetMaintenance->supplier_id = null;
} else {
$assetMaintenance->supplier_id = e(Input::get('supplier_id'));
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
}
if (e(Input::get('is_warranty')) == '') {
$assetMaintenance->is_warranty = 0;
} else {
$assetMaintenance->is_warranty = e(Input::get('is_warranty'));
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
}
if (e(Input::get('cost')) == '') {
$assetMaintenance->cost = '';
} else {
$assetMaintenance->cost = Helper::ParseFloat(e(Input::get('cost')));
$assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost')));
}
if (e(Input::get('notes')) == '') {
$assetMaintenance->notes = null;
} else {
$assetMaintenance->notes = e(Input::get('notes'));
$assetMaintenance->notes = e($request->input('notes'));
}
$asset = Asset::find(e(Input::get('asset_id')));
$asset = Asset::find(e($request->input('asset_id')));
if (!Company::isCurrentUserHasAccess($asset)) {
return static::getInsufficientPermissionsRedirect();
}
// Save the asset maintenance data
$assetMaintenance->asset_id = e(Input::get('asset_id'));
$assetMaintenance->asset_maintenance_type = e(Input::get('asset_maintenance_type'));
$assetMaintenance->title = e(Input::get('title'));
$assetMaintenance->start_date = e(Input::get('start_date'));
$assetMaintenance->completion_date = e(Input::get('completion_date'));
$assetMaintenance->asset_id = e($request->input('asset_id'));
$assetMaintenance->asset_maintenance_type = e($request->input('asset_maintenance_type'));
$assetMaintenance->title = e($request->input('title'));
$assetMaintenance->start_date = e($request->input('start_date'));
$assetMaintenance->completion_date = e($request->input('completion_date'));
$assetMaintenance->user_id = Auth::user()->id;
if (( $assetMaintenance->completion_date == "" )
@ -262,7 +259,7 @@ class AssetMaintenancesController extends Controller
if ($assetMaintenance->save()) {
// Redirect to the new asset maintenance page
return redirect()->to("admin/asset_maintenances")
return redirect()->route('maintenances.index')
->with('success', trans('admin/asset_maintenances/message.create.success'));
}
@ -283,12 +280,12 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return mixed
*/
public function getEdit($assetMaintenanceId = null)
public function edit($assetMaintenanceId = null)
{
// Check if the asset maintenance exists
if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
// Redirect to the improvement management page
return redirect()->to('admin/asset_maintenances')
return redirect()->route('maintenances.index')
->with('error', trans('admin/asset_maintenances/message.not_found'));
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect();
@ -335,16 +332,16 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return mixed
*/
public function postEdit($assetMaintenanceId = null)
public function update(Request $request, $assetMaintenanceId = null)
{
// get the POST data
$new = Input::all();
$new = $request->all();
// Check if the asset maintenance exists
if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
// Redirect to the asset maintenance management page
return redirect()->to('admin/asset_maintenances')
return redirect()->route('maintenances.index')
->with('error', trans('admin/asset_maintenances/message.not_found'));
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect();
@ -355,25 +352,25 @@ class AssetMaintenancesController extends Controller
if (e(Input::get('supplier_id')) == '') {
$assetMaintenance->supplier_id = null;
} else {
$assetMaintenance->supplier_id = e(Input::get('supplier_id'));
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
}
if (e(Input::get('is_warranty')) == '') {
$assetMaintenance->is_warranty = 0;
} else {
$assetMaintenance->is_warranty = e(Input::get('is_warranty'));
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
}
if (e(Input::get('cost')) == '') {
$assetMaintenance->cost = '';
} else {
$assetMaintenance->cost = Helper::ParseFloat(e(Input::get('cost')));
$assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost')));
}
if (e(Input::get('notes')) == '') {
$assetMaintenance->notes = null;
} else {
$assetMaintenance->notes = e(Input::get('notes'));
$assetMaintenance->notes = e($request->input('notes'));
}
$asset = Asset::find(e(Input::get('asset_id')));
@ -383,11 +380,11 @@ class AssetMaintenancesController extends Controller
}
// Save the asset maintenance data
$assetMaintenance->asset_id = e(Input::get('asset_id'));
$assetMaintenance->asset_maintenance_type = e(Input::get('asset_maintenance_type'));
$assetMaintenance->title = e(Input::get('title'));
$assetMaintenance->start_date = e(Input::get('start_date'));
$assetMaintenance->completion_date = e(Input::get('completion_date'));
$assetMaintenance->asset_id = e($request->input('asset_id'));
$assetMaintenance->asset_maintenance_type = e($request->input('asset_maintenance_type'));
$assetMaintenance->title = e($request->input('title'));
$assetMaintenance->start_date = e($request->input('start_date'));
$assetMaintenance->completion_date = e($request->input('completion_date'));
if (( $assetMaintenance->completion_date == "" )
|| ( $assetMaintenance->completion_date == "0000-00-00" )
@ -414,10 +411,10 @@ class AssetMaintenancesController extends Controller
if ($assetMaintenance->save()) {
// Redirect to the new asset maintenance page
return redirect()->to("admin/asset_maintenances")
return redirect()->route('maintenances.index')
->with('success', trans('admin/asset_maintenances/message.create.success'));
}
return redirect()->back() ->withInput()->withErrors($assetMaintenance->getErrors());
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
}
@ -431,12 +428,12 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return mixed
*/
public function getDelete($assetMaintenanceId)
public function destroy($assetMaintenanceId)
{
// Check if the asset maintenance exists
if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
// Redirect to the asset maintenance management page
return redirect()->to('admin/asset_maintenances')
return redirect()->route('maintenances.index')
->with('error', trans('admin/asset_maintenances/message.not_found'));
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect();
@ -446,7 +443,7 @@ class AssetMaintenancesController extends Controller
$assetMaintenance->delete();
// Redirect to the asset_maintenance management page
return redirect()->to('admin/asset_maintenances')
return redirect()->route('maintenances.index')
->with('success', trans('admin/asset_maintenances/message.delete.success'));
}
@ -459,12 +456,12 @@ class AssetMaintenancesController extends Controller
* @since [v1.8]
* @return View
*/
public function getView($assetMaintenanceId)
public function show($assetMaintenanceId)
{
// Check if the asset maintenance exists
if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) {
// Redirect to the asset maintenance management page
return redirect()->to('admin/asset_maintenances')
return redirect()->route('maintenances.index')
->with('error', trans('admin/asset_maintenances/message.not_found'));
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect();

View file

@ -70,7 +70,7 @@ class AssetModelsController extends Controller
* @since [v1.0]
* @return Redirect
*/
public function postCreate()
public function store()
{
// Create a new asset model

View file

@ -271,7 +271,7 @@ class AssetsController extends Controller
}
// Redirect to the asset listing page
\Session::flash('success', trans('admin/hardware/message.create.success'));
return response()->json(['redirect_url' => route('hardware')]);
return response()->json(['redirect_url' => route('hardware.index')]);
}
\Input::flash();
\Session::flash('errors', $asset->getErrors());

View file

@ -232,7 +232,7 @@ class ConsumablesController extends Controller
* @param int $consumableId
* @return View
*/
public function getView($consumableId = null)
public function show($consumableId = null)
{
$consumable = Consumable::find($consumableId);

View file

@ -62,7 +62,7 @@ class DepreciationsController extends Controller
{
// get the POST data
$new = Input::all();
$new = $request->all();
// create a new instance
$depreciation = new Depreciation();

View file

@ -84,7 +84,7 @@ class LicensesController extends Controller
* @since [v1.0]
* @return Redirect
*/
public function store()
public function store(Request $request)
{
// create a new model instance

View file

@ -24,10 +24,14 @@
<div class="row">
<div class="col-md-9">
<form class="form-horizontal" method="post" action="" autocomplete="off">
<form class="form-horizontal" method="post" action="{{ route('maintenances.store') }}" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
@if ($item->id)
{{ method_field('PUT') }}
@endif
<div class="box box-default">
<div class="box-header with-border">

View file

@ -9,7 +9,7 @@
@section('header_right')
@can('assets.edit')
<a href="{{ route('create/asset_maintenances') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
<a href="{{ route('maintenances.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
@endcan
@stop

View file

@ -498,7 +498,7 @@
<div class="col-md-12">
@can('assets.edit')
<h6>{{ trans('general.asset_maintenances') }}
[ <a href="{{ route('create/asset_maintenances', $asset->id) }}">{{ trans('button.add') }}</a> ]
[ <a href="{{ route('maintenances.create', $asset->id) }}">{{ trans('button.add') }}</a> ]
</h6>
@endcan

View file

@ -151,14 +151,14 @@
@endcan
@can('consumables.view')
<li {!! (Request::is('consunmables*') ? ' class="active"' : '') !!}>
<a href="{{ URL::to('admin/consumables') }}">
<a href="{{ URL::to('consumables') }}">
<i class="fa fa-tint"></i>
</a>
</li>
@endcan
@can('components.view')
<li {!! (Request::is('components*') ? ' class="active"' : '') !!}>
<a href="{{ URL::to('admin/components') }}">
<a href="{{ URL::to('components') }}">
<i class="fa fa-hdd-o"></i>
</a>
</li>
@ -252,7 +252,7 @@
@for($i=0; count($alert_items) > $i; $i++)
<li><!-- Task item -->
<a href="{{ URL::to('/') }}/admin/{{ $alert_items[$i]['type'] }}/{{ $alert_items[$i]['id'] }}/view">
<a href="{{ URL::to('/') }}/{{ $alert_items[$i]['type'] }}/{{ $alert_items[$i]['id'] }}/view">
<h3>{{ $alert_items[$i]['name'] }}
<small class="pull-right">
{{ $alert_items[$i]['remaining'] }} remaining
@ -450,7 +450,7 @@
@endcan
@can('assets.create')
<li{!! (Request::query('Deleted') ? ' class="active"' : '') !!}><a href="{{ URL::to('hardware?status=Deleted') }}">@lang('general.deleted')</a></li>
<li><a href="{{ URL::to('admin/asset_maintenances') }}" >@lang('general.asset_maintenances') </a></li>
<li><a href="{{ route('maintenances.index') }}">@lang('general.asset_maintenances') </a></li>
<li><a href="{{ URL::to('hardware/import') }}">@lang('general.import') </a></li>
<li><a href="{{ URL::to('hardware/history') }}">@lang('general.import-history') </a></li>
@endcan
@ -475,7 +475,7 @@
@endcan
@can('consumables.view')
<li{!! (Request::is('consunmables*') ? ' class="active"' : '') !!}>
<a href="{{ URL::to('admin/consumables') }}">
<a href="{{ URL::to('consumables') }}">
<i class="fa fa-tint"></i>
<span>@lang('general.consumables')</span>
</a>

View file

@ -13,8 +13,8 @@ Route::group(
function () {
# Asset Maintenances
Route::resource('maintenance', 'AssetMaintenancesController', [
'parameters' => ['assetmaintenance' => 'maintenance_id', 'asset' => 'asset_id']
Route::resource('maintenances', 'AssetMaintenancesController', [
'parameters' => ['maintenance' => 'maintenance_id', 'asset' => 'asset_id']
]);