diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 3e74143715..c376e73410 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -27,6 +27,7 @@ use Mail; use Datatable; use TCPDF; use Slack; +use Manufacturer; //for embedded-create class AssetsController extends AdminController { @@ -77,6 +78,11 @@ class AssetsController extends AdminController // Grab the dropdown list of status $statuslabel_list = array('' => Lang::get('general.select_statuslabel')) + Statuslabel::orderBy('name', 'asc')->lists('name', 'id'); + + // grap dropdown lists for embedded create drop-downs + $manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id'); + $category_list = array('' => '') + DB::table('categories')->whereNull('deleted_at')->lists('name', 'id'); + $view = View::make('backend/hardware/edit'); $view->with('supplier_list',$supplier_list); @@ -85,6 +91,8 @@ class AssetsController extends AdminController $view->with('assigned_to',$assigned_to); $view->with('location_list',$location_list); $view->with('asset',new Asset); + $view->with('manufacturer',$manufacturer_list); + $view->with('category',$category_list); if (!is_null($model_id)) { $selected_model = Model::find($model_id); diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php index dc4d4174d1..22ce45cd62 100755 --- a/app/controllers/admin/LocationsController.php +++ b/app/controllers/admin/LocationsController.php @@ -12,6 +12,8 @@ use Str; use Validator; use View; +use Symfony\Component\HttpFoundation\JsonResponse; + class LocationsController extends AdminController { /** @@ -97,6 +99,52 @@ class LocationsController extends AdminController return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error')); } + + public function store() + { + $new = Input::all(); + + $new['currency']=Setting::first()->default_currency; + + // create a new location instance + $location = new Location(); + + // attempt validation + if ($location->validate($new)) { + + // Save the location data + $location->name = e(Input::get('name')); + // if (Input::get('parent_id')=='') { + // $location->parent_id = null; + // } else { + // $location->parent_id = e(Input::get('parent_id')); + // } + $location->currency = Setting::first()->default_currency; //e(Input::get('currency')); + $location->address = ''; //e(Input::get('address')); + // $location->address2 = e(Input::get('address2')); + $location->city = e(Input::get('city')); + $location->state = '';//e(Input::get('state')); + $location->country = e(Input::get('country')); + // $location->zip = e(Input::get('zip')); + $location->user_id = Sentry::getId(); + + // Was the asset created? + if($location->save()) { + // Redirect to the new location page + return JsonResponse::create($location); + //return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success')); + } else { + return JsonResponse::create(["error" => "Couldn't save Location"],500); + } + } else { + // failure + $errors = $location->errors(); + return JsonResponse::create(["error" => "Failed validation: ".print_r($errors->all('