diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index b21ef96279..ec93eadbec 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -4,6 +4,7 @@ use AdminController; use Input; use Lang; use Asset; +use Statuslabel; use User; use Redirect; use DB; @@ -48,7 +49,10 @@ class AssetsController extends AdminController { $model_list = array('' => '') + Model::lists('name', 'id'); $depreciation_list = array('' => '') + Depreciation::lists('name', 'id'); - return View::make('backend/assets/edit')->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('asset',new Asset); + // Grab the dropdown list of status + $statuslabel_list = array('' => 'Ready to Deploy') + Statuslabel::lists('name', 'id'); + + return View::make('backend/assets/edit')->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('depreciation_list',$depreciation_list)->with('asset',new Asset); } @@ -80,6 +84,7 @@ class AssetsController extends AdminController { $asset->order_number = e(Input::get('order_number')); $asset->notes = e(Input::get('notes')); $asset->asset_tag = e(Input::get('asset_tag')); + $asset->status_id = e(Input::get('status_id')); $asset->user_id = Sentry::getId(); $asset->physical = '1'; @@ -122,9 +127,13 @@ class AssetsController extends AdminController { // Grab the dropdown list of models $model_list = array('' => '') + Model::lists('name', 'id'); + // Grab the dropdown list of status + $statuslabel_list = array('' => '') + Statuslabel::lists('name', 'id'); + // get depreciation list $depreciation_list = array('' => '') + Depreciation::lists('name', 'id'); - return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list); + + return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('statuslabel_list',$statuslabel_list); } @@ -171,6 +180,7 @@ class AssetsController extends AdminController { $asset->purchase_cost = e(Input::get('purchase_cost')); $asset->order_number = e(Input::get('order_number')); $asset->asset_tag = e(Input::get('asset_tag')); + $asset->status_id = e(Input::get('status_id')); $asset->notes = e(Input::get('notes')); $asset->physical = '1'; @@ -232,6 +242,9 @@ class AssetsController extends AdminController { // Get the dropdown of users and then pass it to the checkout view $users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name, id'))->lists('full_name', 'id'); + + + //print_r($users); return View::make('backend/assets/checkout', compact('asset'))->with('users_list',$users_list); diff --git a/app/controllers/admin/StatuslabelsController.php b/app/controllers/admin/StatuslabelsController.php index a139ce4610..8479bc52d1 100644 --- a/app/controllers/admin/StatuslabelsController.php +++ b/app/controllers/admin/StatuslabelsController.php @@ -3,7 +3,7 @@ use AdminController; use Input; use Lang; -use Location; +use Statuslabel; use Redirect; use DB; use Sentry; @@ -11,39 +11,38 @@ use Str; use Validator; use View; -class LocationsController extends AdminController { +class StatuslabelsController extends AdminController { /** - * Show a list of all the locations. + * Show a list of all the statuslabels. * * @return View */ public function getIndex() { - // Grab all the locations - $locations = Location::orderBy('created_at', 'DESC')->paginate(10); + // Grab all the statuslabels + $statuslabels = Statuslabel::orderBy('created_at', 'DESC')->paginate(10); // Show the page - return View::make('backend/locations/index', compact('locations')); + return View::make('backend/statuslabels/index', compact('statuslabels')); } /** - * Location create. + * Statuslabel create. * * @return View */ public function getCreate() { // Show the page - $location_options = array('0' => 'Top Level') + Location::lists('name', 'id'); - return View::make('backend/locations/edit')->with('location_options',$location_options)->with('location',new Location); + return View::make('backend/statuslabels/edit')->with('statuslabel',new Statuslabel); } /** - * Location create form processing. + * Statuslabel create form processing. * * @return Redirect */ @@ -54,75 +53,69 @@ class LocationsController extends AdminController { $new = Input::all(); // create a new model instance - $location = new Location(); + $statuslabel = new Statuslabel(); // attempt validation - if ($location->validate($new)) + if ($statuslabel->validate($new)) { - // Save the location data - $location->name = e(Input::get('name')); - $location->city = e(Input::get('city')); - $location->state = e(Input::get('state')); - $location->country = e(Input::get('country')); - $location->user_id = Sentry::getId(); + // Save the Statuslabel data + $statuslabel->name = e(Input::get('name')); + $statuslabel->user_id = Sentry::getId(); // Was the asset created? - if($location->save()) + if($statuslabel->save()) { - // Redirect to the new location page - return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success')); + // Redirect to the new Statuslabel page + return Redirect::to("admin/settings/statuslabels")->with('success', Lang::get('admin/statuslabels/message.create.success')); } } else { // failure - $errors = $location->errors(); + $errors = $statuslabel->errors(); return Redirect::back()->withInput()->withErrors($errors); } - // Redirect to the location create page - return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error')); + // Redirect to the Statuslabel create page + return Redirect::to('admin/settings/statuslabels/create')->with('error', Lang::get('admin/statuslabels/message.create.error')); } /** - * Location update. + * Statuslabel update. * - * @param int $locationId + * @param int $statuslabelId * @return View */ - public function getEdit($locationId = null) + public function getEdit($statuslabelId = null) { - // Check if the location exists - if (is_null($location = Location::find($locationId))) + // Check if the Statuslabel exists + if (is_null($statuslabel = Statuslabel::find($statuslabelId))) { // Redirect to the blogs management page - return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist')); + return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.does_not_exist')); } - // Show the page - //$location_options = array('' => 'Top Level') + Location::lists('name', 'id'); - $location_options = array('' => 'Top Level') + DB::table('locations')->where('id', '!=', $locationId)->lists('name', 'id'); - return View::make('backend/locations/edit', compact('location'))->with('location_options',$location_options); + return View::make('backend/statuslabels/edit', compact('statuslabel')); } /** - * Location update form processing page. + * Statuslabel update form processing page. * - * @param int $locationId + * @param int $statuslabelId * @return Redirect */ - public function postEdit($locationId = null) + public function postEdit($statuslabelId = null) { - // Check if the location exists - if (is_null($location = Location::find($locationId))) + // Check if the Statuslabel exists + if (is_null($statuslabel = Statuslabel::find($statuslabelId))) { // Redirect to the blogs management page - return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist')); + return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.does_not_exist')); } @@ -132,60 +125,57 @@ class LocationsController extends AdminController { // attempt validation - if ($location->validate($new)) + if ($statuslabel->validate($new)) { - // Update the location data - $location->name = e(Input::get('name')); - $location->city = e(Input::get('city')); - $location->state = e(Input::get('state')); - $location->country = e(Input::get('country')); + // Update the Statuslabel data + $statuslabel->name = e(Input::get('name')); // Was the asset created? - if($location->save()) + if($statuslabel->save()) { - // Redirect to the saved location page - return Redirect::to("admin/settings/locations/$locationId/edit")->with('success', Lang::get('admin/locations/message.update.success')); + // Redirect to the saved Statuslabel page + return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('success', Lang::get('admin/statuslabels/message.update.success')); } } else { // failure - $errors = $location->errors(); + $errors = $statuslabel->errors(); return Redirect::back()->withInput()->withErrors($errors); } - // Redirect to the location management page - return Redirect::to("admin/settings/locations/$locationId/edit")->with('error', Lang::get('admin/locations/message.update.error')); + // Redirect to the Statuslabel management page + return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', Lang::get('admin/statuslabels/message.update.error')); } /** - * Delete the given location. + * Delete the given Statuslabel. * - * @param int $locationId + * @param int $statuslabelId * @return Redirect */ - public function getDelete($locationId) + public function getDelete($statuslabelId) { - // Check if the location exists - if (is_null($location = Location::find($locationId))) + // Check if the Statuslabel exists + if (is_null($statuslabel = Statuslabel::find($statuslabelId))) { // Redirect to the blogs management page - return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found')); + return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.not_found')); } - if ($location->has_users() > 0) { + if ($statuslabel->has_assets() > 0) { // Redirect to the asset management page - return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users')); + return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.assoc_users')); } else { - $location->delete(); + $statuslabel->delete(); - // Redirect to the locations management page - return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success')); + // Redirect to the statuslabels management page + return Redirect::to('admin/settings/statuslabels')->with('success', Lang::get('admin/statuslabels/message.delete.success')); } diff --git a/app/database/migrations/2013_11_21_002321_add_uploads_table.php b/app/database/migrations/2013_11_21_002321_add_uploads_table.php new file mode 100644 index 0000000000..2a0e10c5a3 --- /dev/null +++ b/app/database/migrations/2013_11_21_002321_add_uploads_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->integer('user_id'); + $table->string('filename'); + $table->integer('asset_id'); + $table->string('filenotes')->nullable; + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('asset_uploads'); + } + +} \ No newline at end of file diff --git a/app/database/migrations/2013_11_21_024531_remove_deployable_boolean_from_status_labels.php b/app/database/migrations/2013_11_21_024531_remove_deployable_boolean_from_status_labels.php new file mode 100644 index 0000000000..966c5eb19d --- /dev/null +++ b/app/database/migrations/2013_11_21_024531_remove_deployable_boolean_from_status_labels.php @@ -0,0 +1,33 @@ +dropColumn('deployable'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('status_labels', function($table) + { + $table->boolean('deployable'); + }); + } + +} \ No newline at end of file diff --git a/app/database/seeds/StatuslabelsSeeder.php b/app/database/seeds/StatuslabelsSeeder.php index 635fc987f6..b967c3db8b 100644 --- a/app/database/seeds/StatuslabelsSeeder.php +++ b/app/database/seeds/StatuslabelsSeeder.php @@ -10,17 +10,9 @@ class StatuslabelsSeeder extends Seeder { $status = array(); $date = new DateTime; - $status[] = array( - 'name' => 'Ready to Deploy', - 'deployable' => '1', - 'created_at' => $date->modify('-10 day'), - 'updated_at' => $date->modify('-3 day'), - 'user_id' => 1, - ); $status[] = array( 'name' => 'Out for Diagnostics', - 'deployable' => '0', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, @@ -29,7 +21,6 @@ class StatuslabelsSeeder extends Seeder { $status[] = array( 'name' => 'Out for Repair', - 'deployable' => '0', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, @@ -38,7 +29,6 @@ class StatuslabelsSeeder extends Seeder { $status[] = array( 'name' => 'Broken - Not Fixable', - 'deployable' => '0', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, @@ -46,7 +36,6 @@ class StatuslabelsSeeder extends Seeder { $status[] = array( 'name' => 'Lost/Stolen', - 'deployable' => '0', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-3 day'), 'user_id' => 1, diff --git a/app/lang/en/admin/statuslabels/message.php b/app/lang/en/admin/statuslabels/message.php new file mode 100755 index 0000000000..626fb6bbfb --- /dev/null +++ b/app/lang/en/admin/statuslabels/message.php @@ -0,0 +1,24 @@ + 'Location does not exist.', + 'assoc_users' => 'This location is currently associated with at least one user and cannot be deleted. Please update your users to no longer reference this location and try again. ', + + + 'create' => array( + 'error' => 'Location was not created, please try again.', + 'success' => 'Location created successfully.' + ), + + 'update' => array( + 'error' => 'Location was not updated, please try again', + 'success' => 'Location updated successfully.' + ), + + 'delete' => array( + 'error' => 'There was an issue deleting the location. Please try again.', + 'success' => 'The location was deleted successfully.' + ) + +); diff --git a/app/lang/en/admin/statuslabels/table.php b/app/lang/en/admin/statuslabels/table.php new file mode 100755 index 0000000000..09abfd2937 --- /dev/null +++ b/app/lang/en/admin/statuslabels/table.php @@ -0,0 +1,11 @@ + 'ID', + 'name' => 'Name', + 'city' => 'City', + 'state' => 'State', + 'country' => 'Country', + +); diff --git a/app/models/Asset.php b/app/models/Asset.php index f45e1bc626..b7a356c6d0 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -94,6 +94,7 @@ class Asset extends Elegant { return DB::table('assets') ->where('physical', '=', '1') ->where('assigned_to', '=', '0') + ->whereNull('status_id','and') ->whereNull('deleted_at','and') ->count(); diff --git a/app/models/Statuslabel.php b/app/models/Statuslabel.php index 3b534cfb21..e484d577ae 100644 --- a/app/models/Statuslabel.php +++ b/app/models/Statuslabel.php @@ -1,6 +1,16 @@ 'required|min:2', + ); + + public function has_assets() + { + return $this->hasMany('Asset', 'status_id')->count(); + } } diff --git a/app/routes.php b/app/routes.php index 2512d19b2d..e3f670801c 100755 --- a/app/routes.php +++ b/app/routes.php @@ -121,6 +121,18 @@ Route::group(array('prefix' => 'admin'), function() Route::get('{locationId}/delete', array('as' => 'delete/location', 'uses' => 'Controllers\Admin\LocationsController@getDelete')); }); + # Status Labels + Route::group(array('prefix' => 'statuslabels'), function() + { + Route::get('/', array('as' => 'statuslabels', 'uses' => 'Controllers\Admin\StatuslabelsController@getIndex')); + Route::get('create', array('as' => 'create/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getCreate')); + Route::post('create', 'Controllers\Admin\StatuslabelsController@postCreate'); + Route::get('{statuslabelId}/edit', array('as' => 'update/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getEdit')); + Route::post('{statuslabelId}/edit', 'Controllers\Admin\StatuslabelsController@postEdit'); + Route::get('{statuslabelId}/delete', array('as' => 'delete/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getDelete')); + }); + + }); diff --git a/app/views/backend/assets/edit.blade.php b/app/views/backend/assets/edit.blade.php index ebf8d0f9cd..853565cf9a 100755 --- a/app/views/backend/assets/edit.blade.php +++ b/app/views/backend/assets/edit.blade.php @@ -105,8 +105,6 @@ - -