diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index adc444b7d3..34de89ece3 100755 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -14,6 +14,8 @@ class AdminController extends AuthorizedController // Apply the admin auth filter //$this->beforeFilter('admin-auth', array('except' => $this->whitelist)); + // CSRF Protection + $this->beforeFilter('csrf', array('on' => 'post')); } diff --git a/app/controllers/admin/AccessoriesController.php b/app/controllers/admin/AccessoriesController.php index 2d6d25b05c..589300647f 100755 --- a/app/controllers/admin/AccessoriesController.php +++ b/app/controllers/admin/AccessoriesController.php @@ -13,6 +13,7 @@ use Validator; use View; use User; use Actionlog; +use Company; use Mail; use Datatable; use Slack; @@ -41,7 +42,11 @@ class AccessoriesController extends AdminController { // Show the page $category_list = array('' => '') + DB::table('categories')->where('category_type','=','accessory')->whereNull('deleted_at')->orderBy('name','ASC')->lists('name', 'id'); - return View::make('backend/accessories/edit')->with('accessory',new Accessory)->with('category_list',$category_list); + $company_list = Company::getSelectList(); + return View::make('backend/accessories/edit') + ->with('accessory', new Accessory) + ->with('category_list', $category_list) + ->with('company_list', $company_list); } @@ -68,20 +73,21 @@ class AccessoriesController extends AdminController // Update the accessory data $accessory->name = e(Input::get('name')); $accessory->category_id = e(Input::get('category_id')); + $accessory->company_id = e(Input::get('company_id')); $accessory->order_number = e(Input::get('order_number')); - + if (e(Input::get('purchase_date')) == '') { $accessory->purchase_date = NULL; } else { $accessory->purchase_date = e(Input::get('purchase_date')); } - + if (e(Input::get('purchase_cost')) == '0.00') { $accessory->purchase_cost = NULL; } else { $accessory->purchase_cost = ParseFloat(e(Input::get('purchase_cost'))); } - + $accessory->qty = e(Input::get('qty')); $accessory->user_id = Sentry::getId(); @@ -113,7 +119,11 @@ class AccessoriesController extends AdminController } $category_list = array('' => '') + DB::table('categories')->where('category_type','=','accessory')->whereNull('deleted_at')->orderBy('name','ASC')->lists('name', 'id'); - return View::make('backend/accessories/edit', compact('accessory'))->with('category_list',$category_list); + $company_list = Company::getSelectList(); + + return View::make('backend/accessories/edit', compact('accessory')) + ->with('category_list',$category_list) + ->with('company_list', $company_list); } @@ -150,20 +160,21 @@ class AccessoriesController extends AdminController // Update the accessory data $accessory->name = e(Input::get('name')); $accessory->category_id = e(Input::get('category_id')); + $accessory->company_id = e(Input::get('company_id')); $accessory->order_number = e(Input::get('order_number')); - + if (e(Input::get('purchase_date')) == '') { $accessory->purchase_date = NULL; } else { $accessory->purchase_date = e(Input::get('purchase_date')); } - + if (e(Input::get('purchase_cost')) == '0.00') { $accessory->purchase_cost = NULL; } else { $accessory->purchase_cost = ParseFloat(e(Input::get('purchase_cost'))); } - + $accessory->qty = e(Input::get('qty')); // Was the accessory created? @@ -493,7 +504,7 @@ class AccessoriesController extends AdminController public function getDatatable() { - $accessories = Accessory::with('category') + $accessories = Accessory::with('category', 'company') ->whereNull('deleted_at'); if (Input::has('search')) { @@ -526,17 +537,19 @@ class AccessoriesController extends AdminController foreach ($accessories as $accessory) { $actions = 'numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').''; + $company = $accessory->company; $rows[] = array( 'name' => link_to('admin/accessories/'.$accessory->id.'/view', $accessory->name), 'category' => $accessory->category->name, 'qty' => $accessory->qty, 'order_number' => $accessory->order_number, - 'purchase_date' => $accessory->purchase_date, - 'purchase_cost' => $accessory->purchase_cost, + 'purchase_date' => $accessory->purchase_date, + 'purchase_cost' => $accessory->purchase_cost, 'numRemaining' => $accessory->numRemaining(), - 'actions' => $actions - ); + 'actions' => $actions, + 'companyName' => is_null($company) ? '' : e($company->name) + ); } $data = array('total'=>$accessCount, 'rows'=>$rows); diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index c2de106483..1fd98b3df6 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -12,6 +12,7 @@ use Setting; use Redirect; use DB; use Actionlog; +use Company; use Model; use Depreciation; use Sentry; @@ -63,11 +64,13 @@ class AssetsController extends AdminController $manufacturer_list = manufacturerList(); $category_list = categoryList(); $supplier_list = suppliersList(); + $company_list = Company::getSelectList(); $assigned_to = usersList(); $statuslabel_types = statusTypeList(); $view = View::make('backend/hardware/edit'); $view->with('supplier_list',$supplier_list); + $view->with('company_list',$company_list); $view->with('model_list',$model_list); $view->with('statuslabel_list',$statuslabel_list); $view->with('assigned_to',$assigned_to); @@ -160,7 +163,8 @@ class AssetsController extends AdminController // Save the asset data $asset->name = e(Input::get('name')); $asset->serial = e(Input::get('serial')); - $asset->model_id = e(Input::get('model_id')); + $asset->company_id = e(Input::get('company_id')); + $asset->model_id = e(Input::get('model_id')); $asset->order_number = e(Input::get('order_number')); $asset->notes = e(Input::get('notes')); $asset->asset_tag = e(Input::get('asset_tag')); @@ -213,12 +217,14 @@ class AssetsController extends AdminController $manufacturer_list = manufacturerList(); $category_list = categoryList(); $supplier_list = suppliersList(); + $company_list = Company::getSelectList(); $assigned_to = usersList(); $statuslabel_types = statusTypeList(); return View::make('backend/hardware/edit', compact('asset')) ->with('model_list',$model_list) ->with('supplier_list',$supplier_list) + ->with('company_list',$company_list) ->with('location_list',$location_list) ->with('statuslabel_list',$statuslabel_list) ->with('assigned_to',$assigned_to) @@ -300,13 +306,14 @@ class AssetsController extends AdminController $asset->mac_address = ($checkModel == true) ? e(Input::get('mac_address')) : NULL; // Update the asset data - $asset->name = e(Input::get('name')); - $asset->serial = e(Input::get('serial')); - $asset->model_id = e(Input::get('model_id')); - $asset->order_number = e(Input::get('order_number')); - $asset->asset_tag = e(Input::get('asset_tag')); - $asset->notes = e(Input::get('notes')); - $asset->physical = '1'; + $asset->name = e(Input::get('name')); + $asset->serial = e(Input::get('serial')); + $asset->company_id = e(Input::get('company_id')); + $asset->model_id = e(Input::get('model_id')); + $asset->order_number = e(Input::get('order_number')); + $asset->asset_tag = e(Input::get('asset_tag')); + $asset->notes = e(Input::get('notes')); + $asset->physical = '1'; // Was the asset updated? if($asset->save()) { @@ -1097,7 +1104,7 @@ class AssetsController extends AdminController { - $assets = Asset::with('model','assigneduser','assigneduser.userloc','assetstatus','defaultLoc','assetlog','model','model.category','assetstatus','assetloc') + $assets = Asset::with('model','assigneduser','assigneduser.userloc','assetstatus','defaultLoc','assetlog','model','model.category','assetstatus','assetloc', 'company') ->Hardware(); if (Input::has('search')) { @@ -1221,8 +1228,9 @@ class AssetsController extends AdminController 'last_checkout' => ($asset->last_checkout!='') ? $asset->last_checkout : '', 'expected_checkin' => ($asset->expected_checkin!='') ? $asset->expected_checkin : '', 'change' => ($inout) ? $inout : '', - 'actions' => ($actions) ? $actions : '' - ); + 'actions' => ($actions) ? $actions : '', + 'companyName' => is_null($asset->company) ? '' : e($asset->company->name) + ); } $data = array('total'=>$assetCount, 'rows'=>$rows); diff --git a/app/controllers/admin/CompaniesController.php b/app/controllers/admin/CompaniesController.php new file mode 100644 index 0000000000..85e10acba8 --- /dev/null +++ b/app/controllers/admin/CompaniesController.php @@ -0,0 +1,127 @@ +with('companies', Company::all()); + } + + public function getCreate() + { + return View::make('backend/companies/edit')->with('company', new Company); + } + + public function postCreate() + { + $company = new Company; + + if ($company->validate(Input::all())) + { + $company->name = e(Input::get('name')); + + if($company->save()) + { + return Redirect::to('admin/settings/companies') + ->with('success', Lang::get('admin/companies/message.create.success')); + } + else + { + return Redirect::to('admin/settings/companies/create') + ->with('error', Lang::get('admin/companies/message.create.error')); + } + } + else + { + return Redirect::back()->withInput()->withErrors($company->errors()); + } + } + + public function getEdit($companyId) + { + if (is_null($company = Company::find($companyId))) + { + return Redirect::to('admin/settings/companies') + ->with('error', Lang::get('admin/companies/message.does_not_exist')); + } + else + { + return View::make('backend/companies/edit')->with('company', $company); + } + } + + public function postEdit($companyId) + { + if (is_null($company = Company::find($companyId))) + { + return Redirect::to('admin/settings/companies')->with('error', Lang::get('admin/companies/message.does_not_exist')); + } + else + { + $validator = Validator::make(Input::all(), $company->validationRules($companyId)); + + if ($validator->fails()) + { + return Redirect::back()->withInput()->withErrors($validator->messages()); + } + else + { + $company->name = e(Input::get('name')); + + if($company->save()) + { + return Redirect::to('admin/settings/companies') + ->with('success', Lang::get('admin/companies/message.update.success')); + } + else + { + return Redirect::to("admin/settings/companies/$companyId/edit") + ->with('error', Lang::get('admin/companies/message.update.error')); + } + } + } + } + + public function postDelete($companyId) + { + if (is_null($company = Company::find($companyId))) + { + return Redirect::to('admin/settings/companies') + ->with('error', Lang::get('admin/companies/message.not_found')); + } + else + { + try + { + $company->delete(); + return Redirect::to('admin/settings/companies') + ->with('success', Lang::get('admin/companies/message.delete.success')); + } + catch (\Illuminate\Database\QueryException $exception) + { + /* + * NOTE: This happens when there's a foreign key constraint violation + * For example when rows in other tables are referencing this company + */ + if ($exception->getCode() == 23000) + { + return Redirect::to('admin/settings/companies') + ->with('error', Lang::get('admin/companies/message.assoc_users')); + } + else + { + throw $exception; + } + } + } + } +} diff --git a/app/controllers/admin/ConsumablesController.php b/app/controllers/admin/ConsumablesController.php index 173cbfd173..20b2a955e0 100644 --- a/app/controllers/admin/ConsumablesController.php +++ b/app/controllers/admin/ConsumablesController.php @@ -8,6 +8,7 @@ use Setting; use DB; use Sentry; use Consumable; +use Company; use Str; use Validator; use View; @@ -41,7 +42,12 @@ class ConsumablesController extends AdminController { // Show the page $category_list = array('' => '') + DB::table('categories')->where('category_type','=','consumable')->whereNull('deleted_at')->orderBy('name','ASC')->lists('name', 'id'); - return View::make('backend/consumables/edit')->with('consumable',new Consumable)->with('category_list',$category_list); + $company_list = Company::getSelectList(); + + return View::make('backend/consumables/edit') + ->with('consumable', new Consumable) + ->with('category_list', $category_list) + ->with('company_list', $company_list); } @@ -68,6 +74,7 @@ class ConsumablesController extends AdminController // Update the consumable data $consumable->name = e(Input::get('name')); $consumable->category_id = e(Input::get('category_id')); + $consumable->company_id = e(Input::get('company_id')); $consumable->order_number = e(Input::get('order_number')); if (e(Input::get('purchase_date')) == '') { @@ -113,7 +120,11 @@ class ConsumablesController extends AdminController } $category_list = array('' => '') + DB::table('categories')->where('category_type','=','consumable')->whereNull('deleted_at')->orderBy('name','ASC')->lists('name', 'id'); - return View::make('backend/consumables/edit', compact('consumable'))->with('category_list',$category_list); + $company_list = Company::getSelectList(); + + return View::make('backend/consumables/edit', compact('consumable')) + ->with('category_list', $category_list) + ->with('company_list', $company_list); } @@ -150,6 +161,7 @@ class ConsumablesController extends AdminController // Update the consumable data $consumable->name = e(Input::get('name')); $consumable->category_id = e(Input::get('category_id')); + $consumable->company_id = e(Input::get('company_id')); $consumable->order_number = e(Input::get('order_number')); if (e(Input::get('purchase_date')) == '') { @@ -365,8 +377,9 @@ class ConsumablesController extends AdminController public function getDatatable() { - $consumables = Consumable::select(array('id','name','qty')) - ->whereNull('deleted_at'); + $consumables = Consumable::select(array('id','name','qty', 'company_id')) + ->whereNull('deleted_at') + ->with('company'); if (Input::has('search')) { $consumables = $consumables->TextSearch(Input::get('search')); @@ -397,13 +410,15 @@ class ConsumablesController extends AdminController foreach($consumables as $consumable) { $actions = 'numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').''; + $company = $consumable->company; $rows[] = array( - 'id' => $consumable->id, + 'id' => $consumable->id, 'name' => link_to('admin/consumables/'.$consumable->id.'/view', $consumable->name), 'qty' => $consumable->qty, 'numRemaining' => $consumable->numRemaining(), - 'actions' => $actions + 'actions' => $actions, + 'companyName' => is_null($company) ? '' : e($company->name) ); } diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index fe7743b1af..7dfdc88911 100755 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -12,6 +12,7 @@ use DB; use Redirect; use LicenseSeat; use Depreciation; +use Company; use Setting; use Sentry; use Str; @@ -55,11 +56,14 @@ class LicensesController extends AdminController $depreciation_list = array('0' => Lang::get('admin/licenses/form.no_depreciation')) + Depreciation::lists('name', 'id'); $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->lists('name', 'id'); $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); + $company_list = Company::getSelectList(); + return View::make('backend/licenses/edit') ->with('license_options',$license_options) ->with('depreciation_list',$depreciation_list) ->with('supplier_list',$supplier_list) ->with('maintained_list',$maintained_list) + ->with('company_list', $company_list) ->with('license',new License); } @@ -124,6 +128,7 @@ class LicensesController extends AdminController $license->purchase_date = e(Input::get('purchase_date')); $license->purchase_order = e(Input::get('purchase_order')); $license->depreciation_id = e(Input::get('depreciation_id')); + $license->company_id = e(Input::get('company_id')); $license->expiration_date = e(Input::get('expiration_date')); $license->user_id = Sentry::getId(); @@ -195,10 +200,13 @@ class LicensesController extends AdminController $depreciation_list = array('0' => Lang::get('admin/licenses/form.no_depreciation')) + Depreciation::lists('name', 'id'); $supplier_list = array('' => 'Select Supplier') + Supplier::orderBy('name', 'asc')->lists('name', 'id'); $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); + $company_list = Company::getSelectList(); + return View::make('backend/licenses/edit', compact('license')) ->with('license_options',$license_options) ->with('depreciation_list',$depreciation_list) ->with('supplier_list',$supplier_list) + ->with('company_list', $company_list) ->with('maintained_list',$maintained_list); } @@ -234,6 +242,7 @@ class LicensesController extends AdminController $license->notes = e(Input::get('notes')); $license->order_number = e(Input::get('order_number')); $license->depreciation_id = e(Input::get('depreciation_id')); + $license->company_id = e(Input::get('company_id')); $license->purchase_order = e(Input::get('purchase_order')); $license->maintained = e(Input::get('maintained')); $license->reassignable = e(Input::get('reassignable')); @@ -887,7 +896,7 @@ class LicensesController extends AdminController } public function getDatatable() { - $licenses = License::select('id','name','serial','purchase_date','seats'); + $licenses = License::select('id','name','serial','purchase_date','seats', 'company_id')->with('company'); if (Input::has('search')) { $licenses = $licenses->TextSearch(Input::get('search')); @@ -914,8 +923,9 @@ class LicensesController extends AdminController 'totalSeats' => $license->totalSeatsByLicenseID(), 'remaining' => $license->remaincount(), 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', - 'actions' => $actions - ); + 'actions' => $actions, + 'companyName' => is_null($license->company) ? '' : e($license->company->name) + ); } $data = array('total' => $licenseCount, 'rows' => $rows); diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php index 34ac9af339..249fd39b72 100755 --- a/app/controllers/admin/UsersController.php +++ b/app/controllers/admin/UsersController.php @@ -14,6 +14,7 @@ use DB; use Input; use User; use Asset; +use Company; use Lang; use Actionlog; use Location; @@ -42,11 +43,12 @@ class UsersController extends AdminController { protected $validationRules = array( 'first_name' => 'required|alpha_space|min:2', 'last_name' => 'required|alpha_space|min:2', - 'location_id' => 'numeric', 'username' => 'required|min:2|unique:users,username', 'email' => 'email|unique:users,email', 'password' => 'required|min:6', 'password_confirm' => 'required|min:6|same:password', + 'company_id' => 'required|integer', + 'location_id' => 'numeric', ); /** @@ -82,6 +84,7 @@ class UsersController extends AdminController { $location_list = locationsList(); $manager_list = managerList(); + $company_list = Company::getSelectList(); /* echo '
';
           print_r($userPermissions);
@@ -93,6 +96,7 @@ class UsersController extends AdminController {
         return View::make('backend/users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions'))
                         ->with('location_list', $location_list)
                         ->with('manager_list', $manager_list)
+                        ->with('company_list', $company_list)
                         ->with('user', new User);
     }
 
@@ -267,6 +271,7 @@ class UsersController extends AdminController {
             $this->encodeAllPermissions($permissions);
 
             $location_list = array('' => '') + Location::lists('name', 'id');
+            $company_list = Company::getSelectList();
             $manager_list = array('' => 'Select a User') + DB::table('users')
                             ->select(DB::raw('concat(last_name,", ",first_name," (",email,")") as full_name, id'))
                             ->whereNull('deleted_at')
@@ -285,6 +290,7 @@ class UsersController extends AdminController {
         // Show the page
         return View::make('backend/users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions'))
                         ->with('location_list', $location_list)
+                        ->with('company_list', $company_list)
                         ->with('manager_list', $manager_list);
     }
 
@@ -357,6 +363,7 @@ class UsersController extends AdminController {
             $user->jobtitle = Input::get('jobtitle');
             $user->phone = Input::get('phone');
             $user->location_id = Input::get('location_id');
+            $user->company_id = Input::get('company_id');
             $user->manager_id = Input::get('manager_id');
             $user->notes = Input::get('notes');
 
@@ -845,7 +852,8 @@ class UsersController extends AdminController {
             $sort = e(Input::get('sort'));
         }
 
-        $users = User::select(array('users.id','users.email','users.username','users.location_id','users.manager_id','users.first_name','users.last_name','users.created_at','users.notes'))->with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'sentryThrottle', 'groups', 'userloc');
+        $users = User::select(array('id','email','username','location_id','manager_id','first_name','last_name','created_at','notes','company_id'))
+            ->with('assets','accessories','consumables','licenses','manager','sentryThrottle','groups','userloc','company');
 
         switch ($status) {
         case 'deleted':
@@ -927,7 +935,8 @@ class UsersController extends AdminController {
                 'consumables'        => $user->consumables->count(),
                 'groups'        => $group_names,
                 'notes'         => $user->notes,
-                'actions'       => ($actions) ? $actions : ''
+                'actions'       => ($actions) ? $actions : '',
+                'companyName'   => is_null($user->company) ? '' : e($user->company->name)
             );
         }
 
diff --git a/app/database/migrations/2015_11_05_061015_create_companies_table.php b/app/database/migrations/2015_11_05_061015_create_companies_table.php
new file mode 100644
index 0000000000..c026a87787
--- /dev/null
+++ b/app/database/migrations/2015_11_05_061015_create_companies_table.php
@@ -0,0 +1,32 @@
+increments('id');
+            $table->string('name')->unique();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('companies');
+    }
+}
diff --git a/app/database/migrations/2015_11_05_061115_add_company_id_to_consumables_table.php b/app/database/migrations/2015_11_05_061115_add_company_id_to_consumables_table.php
new file mode 100644
index 0000000000..62360f7d93
--- /dev/null
+++ b/app/database/migrations/2015_11_05_061115_add_company_id_to_consumables_table.php
@@ -0,0 +1,35 @@
+integer('company_id')->unsigned()->nullable();
+            $table->foreign('company_id')->references('id')->on('companies');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('consumables', function(Blueprint $table)
+        {
+            $table->dropForeign('consumables_company_id_foreign');
+            $table->dropColumn('company_id');
+        });
+    }
+}
diff --git a/app/database/migrations/2015_11_06_092038_add_company_id_to_accessories_table.php b/app/database/migrations/2015_11_06_092038_add_company_id_to_accessories_table.php
new file mode 100644
index 0000000000..1d21d9ed8a
--- /dev/null
+++ b/app/database/migrations/2015_11_06_092038_add_company_id_to_accessories_table.php
@@ -0,0 +1,35 @@
+integer('company_id')->unsigned()->nullable();
+            $table->foreign('company_id')->references('id')->on('companies');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('accessories', function(Blueprint $table)
+        {
+            $table->dropForeign('accessories_company_id_foreign');
+            $table->dropColumn('company_id');
+        });
+    }
+}
diff --git a/app/database/migrations/2015_11_06_100045_add_company_id_to_users_table.php b/app/database/migrations/2015_11_06_100045_add_company_id_to_users_table.php
new file mode 100644
index 0000000000..90cf4bca9c
--- /dev/null
+++ b/app/database/migrations/2015_11_06_100045_add_company_id_to_users_table.php
@@ -0,0 +1,35 @@
+integer('company_id')->unsigned()->nullable();
+            $table->foreign('company_id')->references('id')->on('companies');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('users', function(Blueprint $table)
+        {
+            $table->dropForeign('users_company_id_foreign');
+            $table->dropColumn('company_id');
+        });
+    }
+}
diff --git a/app/database/migrations/2015_11_06_134742_add_company_id_to_licenses_table.php b/app/database/migrations/2015_11_06_134742_add_company_id_to_licenses_table.php
new file mode 100644
index 0000000000..ab38db622f
--- /dev/null
+++ b/app/database/migrations/2015_11_06_134742_add_company_id_to_licenses_table.php
@@ -0,0 +1,35 @@
+integer('company_id')->unsigned()->nullable();
+            $table->foreign('company_id')->references('id')->on('companies');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('licenses', function(Blueprint $table)
+        {
+            $table->dropForeign('licenses_company_id_foreign');
+            $table->dropColumn('company_id');
+        });
+    }
+}
diff --git a/app/database/migrations/2015_11_08_035832_add_company_id_to_assets_table.php b/app/database/migrations/2015_11_08_035832_add_company_id_to_assets_table.php
new file mode 100644
index 0000000000..14ab5b9a85
--- /dev/null
+++ b/app/database/migrations/2015_11_08_035832_add_company_id_to_assets_table.php
@@ -0,0 +1,35 @@
+integer('company_id')->unsigned()->nullable();
+            $table->foreign('company_id')->references('id')->on('companies');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('assets', function(Blueprint $table)
+        {
+            $table->dropForeign('assets_company_id_foreign');
+            $table->dropColumn('company_id');
+        });
+    }
+}
diff --git a/app/lang/en/admin/companies/message.php b/app/lang/en/admin/companies/message.php
new file mode 100644
index 0000000000..760a08bc91
--- /dev/null
+++ b/app/lang/en/admin/companies/message.php
@@ -0,0 +1,22 @@
+ 'Company does not exist.',
+    'assoc_users'    => 'This company is currently associated with at least one model and cannot be deleted. Please update your models to no longer reference this company and try again. ',
+
+    'create' => array(
+        'error'   => 'Company was not created, please try again.',
+        'success' => 'Company created successfully.'
+    ),
+
+    'update' => array(
+        'error'   => 'Company was not updated, please try again',
+        'success' => 'Company updated successfully.'
+    ),
+
+    'delete' => array(
+        'confirm' => 'Are you sure you wish to delete this company?',
+        'error'   => 'There was an issue deleting the company. Please try again.',
+        'success' => 'The Company was deleted successfully.'
+    )
+);
diff --git a/app/lang/en/admin/companies/table.php b/app/lang/en/admin/companies/table.php
new file mode 100644
index 0000000000..b40f460f41
--- /dev/null
+++ b/app/lang/en/admin/companies/table.php
@@ -0,0 +1,10 @@
+ 'Companies',
+    'create'    => 'Create Company',
+    'title'     => 'Company',
+    'update'    => 'Update Company',
+    'name'      => 'Company Name',
+    'id'        => 'ID',
+);
diff --git a/app/lang/en/general.php b/app/lang/en/general.php
index c9ddda5ab5..9d4613a7a0 100755
--- a/app/lang/en/general.php
+++ b/app/lang/en/general.php
@@ -30,6 +30,8 @@
     'checkin_from'  		=> 'Checkin from',
     'checkout'  			=> 'Checkout',
     'city'  				=> 'City',
+    'companies'			=> 'Companies',
+    'company'				=> 'Company',
     'consumable'			=> 'Consumable',
     'consumables'			=> 'Consumables',
     'country'  				=> 'Country',
diff --git a/app/models/Accessory.php b/app/models/Accessory.php
index 0abed13fcb..d389264015 100755
--- a/app/models/Accessory.php
+++ b/app/models/Accessory.php
@@ -10,11 +10,17 @@ class Accessory extends Elegant
     * Category validation rules
     */
     public $rules = array(
-        'name'   => 'required|alpha_space|min:3|max:255',
-        'category_id'   	=> 'required|integer',
-        'qty'   	=> 'required|integer|min:1',
+        'name'        => 'required|alpha_space|min:3|max:255',
+        'qty'         => 'required|integer|min:1',
+        'category_id' => 'required|integer',
+        'company_id'  => 'required|integer',
     );
 
+    public function company()
+    {
+        return $this->belongsTo('Company', 'company_id');
+    }
+
     public function category()
     {
         return $this->belongsTo('Category', 'category_id')->where('category_type','=','accessory');
diff --git a/app/models/Asset.php b/app/models/Asset.php
index 05424e0811..6ad26d3922 100755
--- a/app/models/Asset.php
+++ b/app/models/Asset.php
@@ -11,6 +11,7 @@ class Asset extends Depreciable
             'name'            => 'alpha_space|min:2|max:255',
             'model_id'        => 'required',
             'status_id'       => 'required',
+            'company_id'      => 'required|integer',
             'warranty_months' => 'integer|min:0|max:240',
             'note'            => 'alpha_space',
             'notes'           => 'alpha_space',
@@ -22,6 +23,11 @@ class Asset extends Depreciable
             'status'          => 'integer'
         ];
 
+        public function company()
+        {
+            return $this->belongsTo('Company', 'company_id');
+        }
+
 
     /**
     * Checkout asset
diff --git a/app/models/Company.php b/app/models/Company.php
new file mode 100644
index 0000000000..b616dc7663
--- /dev/null
+++ b/app/models/Company.php
@@ -0,0 +1,14 @@
+ 'required|alpha_space|min:2|max:255|unique:companies,name,{id}'];
+
+    public static function getSelectList()
+    {
+        return array('' => '') + DB::table('companies')->orderBy('name', 'ASC')->lists('name', 'id');
+    }
+}
diff --git a/app/models/Consumable.php b/app/models/Consumable.php
index dad42a771d..c089188e71 100644
--- a/app/models/Consumable.php
+++ b/app/models/Consumable.php
@@ -10,11 +10,17 @@ class Consumable extends Elegant
     * Category validation rules
     */
     public $rules = array(
-        'name'   => 'required|alpha_space|min:3|max:255',
-        'category_id'   	=> 'required|integer',
-        'qty'   	=> 'required|integer|min:0',
+        'name'        => 'required|alpha_space|min:3|max:255',
+        'qty'         => 'required|integer|min:0',
+        'category_id' => 'required|integer',
+        'company_id'  => 'required|integer',
     );
 
+    public function company()
+    {
+        return $this->belongsTo('Company', 'company_id');
+    }
+
     public function category()
     {
         return $this->belongsTo('Category', 'category_id');
@@ -64,7 +70,7 @@ class Consumable extends Elegant
 	    $remaining = $total - $checkedout;
 	    return $remaining;
     }
-    
+
     /**
     * Query builder scope to search on text
     *
diff --git a/app/models/License.php b/app/models/License.php
index 08476fe646..3776e2004e 100755
--- a/app/models/License.php
+++ b/app/models/License.php
@@ -10,14 +10,20 @@ class License extends Depreciable
     protected $guarded = 'id';
     protected $table = 'licenses';
     protected $rules = array(
-            'name'   => 'required|alpha_space|min:3|max:255',
-            'serial'   => 'required|min:5',
-            'seats'   => 'required|min:1|max:10000|integer',
-            'license_email'   => 'email|min:0|max:120',
-            'license_name'   => 'alpha_space|min:0|max:100',
-            'note'   => 'alpha_space',
-            'notes'   => 'alpha_space|min:0',
-        );
+        'name'   => 'required|alpha_space|min:3|max:255',
+        'serial'   => 'required|min:5',
+        'seats'   => 'required|min:1|max:10000|integer',
+        'license_email'   => 'email|min:0|max:120',
+        'license_name'   => 'alpha_space|min:0|max:100',
+        'note'   => 'alpha_space',
+        'notes'   => 'alpha_space|min:0',
+        'company_id' => 'required|integer',
+    );
+
+    public function company()
+    {
+        return $this->belongsTo('Company', 'company_id');
+    }
 
     /**
      * Get the assigned user
diff --git a/app/models/User.php b/app/models/User.php
index 20fa1f9e3d..996a70e690 100755
--- a/app/models/User.php
+++ b/app/models/User.php
@@ -12,6 +12,11 @@ class User extends SentryUserModel
     use SoftDeletingTrait;
 	protected $dates = ['deleted_at'];
 
+    public function company()
+    {
+        return $this->belongsTo('Company', 'company_id');
+    }
+
 
     /**
      * Returns the user full name, it simply concatenates
diff --git a/app/routes.php b/app/routes.php
index b9b87e1cb5..1717faec93 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -356,6 +356,18 @@
                 Route::get( '/', [ 'as' => 'settings/backups', 'uses' => 'SettingsController@getBackups' ] );
             } );
 
+            # Companies
+            Route::group([ 'prefix' => 'companies' ], function () {
+
+                Route::get('{companyId}/edit', ['as' => 'update/company', 'uses' => 'CompaniesController@getEdit']);
+                Route::get('create', ['as' => 'create/company', 'uses' => 'CompaniesController@getCreate']);
+                Route::get('/', ['as' => 'companies', 'uses' => 'CompaniesController@getIndex']);
+
+                Route::post('{companyId}/delete', ['as' => 'delete/company', 'uses' => 'CompaniesController@postDelete']);
+                Route::post('{companyId}/edit', 'CompaniesController@postEdit');
+                Route::post('create', 'CompaniesController@postCreate');
+            });
+
             # Manufacturers
             Route::group( [ 'prefix' => 'manufacturers' ], function () {
 
diff --git a/app/views/backend/accessories/edit.blade.php b/app/views/backend/accessories/edit.blade.php
index 02ce60e0f0..5f23291fc3 100755
--- a/app/views/backend/accessories/edit.blade.php
+++ b/app/views/backend/accessories/edit.blade.php
@@ -35,30 +35,42 @@
     
     
 
+    
+    
+
+ {{ Form::label('company_id', Lang::get('general.company')) }} + +
+
+ {{ Form::select('company_id', $company_list , Input::old('company_id', $accessory->company_id), array('class'=>'select2', 'style'=>'width:350px')) }} + {{ $errors->first('company_id', ' :message') }} +
+
+
{{ Form::label('name', Lang::get('admin/accessories/general.accessory_name')) }} -
+
{{ $errors->first('name', ' :message') }}
- +
{{ Form::label('category_id', Lang::get('admin/accessories/general.accessory_category')) }} -
+
{{ Form::select('category_id', $category_list , Input::old('category_id', $accessory->category_id), array('class'=>'select2', 'style'=>'width:350px')) }} {{ $errors->first('category_id', ' :message') }}
- +
@@ -69,7 +81,7 @@ {{ $errors->first('order_number', '
:message') }}
- +
@@ -81,7 +93,7 @@ {{ $errors->first('purchase_date', '
:message') }}
- +
@@ -97,13 +109,13 @@
- +
{{ Form::label('qty', Lang::get('admin/accessories/general.qty')) }} -
+
@@ -117,7 +129,7 @@
- +
@lang('button.cancel') @@ -129,7 +141,7 @@
- +
@lang('admin/accessories/general.about_accessories_title')

@lang('admin/accessories/general.about_accessories_text')

diff --git a/app/views/backend/accessories/index.blade.php b/app/views/backend/accessories/index.blade.php index 7837d93aee..6b83ced8fb 100755 --- a/app/views/backend/accessories/index.blade.php +++ b/app/views/backend/accessories/index.blade.php @@ -28,6 +28,7 @@ data-cookie-id-table="accessoriesTable"> + @lang('admin/companies/table.title') {{Lang::get('admin/accessories/table.title')}} {{Lang::get('admin/accessories/general.accessory_category')}} {{Lang::get('admin/accessories/general.total')}} diff --git a/app/views/backend/companies/edit.blade.php b/app/views/backend/companies/edit.blade.php new file mode 100644 index 0000000000..86119000f5 --- /dev/null +++ b/app/views/backend/companies/edit.blade.php @@ -0,0 +1,94 @@ +@extends('backend/layouts/default') + +{{-- Page title --}} +@section('title') + @if ($company->id) + @lang('admin/companies/table.update') :: + @else + @lang('admin/companies/table.create') :: + @endif +@parent +@stop + +{{-- Page content --}} +@section('content') + +
+
+ + + @lang('general.back') + +

+ @if ($company->id) + @lang('admin/companies/table.update') + @else + @lang('admin/companies/table.create') + @endif +

+
+
+ + + +@stop diff --git a/app/views/backend/companies/index.blade.php b/app/views/backend/companies/index.blade.php new file mode 100644 index 0000000000..3101ec7317 --- /dev/null +++ b/app/views/backend/companies/index.blade.php @@ -0,0 +1,95 @@ +@extends('backend/layouts/default') + +{{-- Page title --}} +@section('title') +@lang('admin/companies/table.companies') :: +@parent +@stop + +{{-- Page content --}} +@section('content') + +
+
+ + + @lang('general.create') + +

@lang('admin/companies/table.companies')

+
+
+ + + +@stop diff --git a/app/views/backend/consumables/edit.blade.php b/app/views/backend/consumables/edit.blade.php index a33058b7c4..2e829f05f1 100644 --- a/app/views/backend/consumables/edit.blade.php +++ b/app/views/backend/consumables/edit.blade.php @@ -35,6 +35,18 @@ + +
+
+ {{ Form::label('company_id', Lang::get('general.company')) }} + +
+
+ {{ Form::select('company_id', $company_list , Input::old('company_id', $consumable->company_id), array('class'=>'select2', 'style'=>'width:350px')) }} + {{ $errors->first('company_id', ' :message') }} +
+
+
@@ -58,7 +70,7 @@ {{ $errors->first('category_id', ' :message') }}
- +
@@ -69,7 +81,7 @@ {{ $errors->first('order_number', '
:message') }}
- +
@@ -81,7 +93,7 @@ {{ $errors->first('purchase_date', '
:message') }}
- +
diff --git a/app/views/backend/consumables/index.blade.php b/app/views/backend/consumables/index.blade.php index c7c1d6f017..a99c091a70 100644 --- a/app/views/backend/consumables/index.blade.php +++ b/app/views/backend/consumables/index.blade.php @@ -29,6 +29,7 @@ @lang('general.id') + @lang('admin/companies/table.title') {{Lang::get('admin/consumables/table.title')}} {{Lang::get('admin/consumables/general.total')}} {{Lang::get('admin/consumables/general.remaining')}} diff --git a/app/views/backend/hardware/edit.blade.php b/app/views/backend/hardware/edit.blade.php index d313f3e418..018468c6a6 100755 --- a/app/views/backend/hardware/edit.blade.php +++ b/app/views/backend/hardware/edit.blade.php @@ -121,6 +121,18 @@ + +
+
+ {{ Form::label('company_id', Lang::get('general.company')) }} + +
+
+ {{ Form::select('company_id', $company_list , Input::old('company_id', $asset->company_id), array('class'=>'select2', 'style'=>'min-width:350px')) }} + {{ $errors->first('company_id', '
:message') }} +
+
+
@endif + @if ($asset->company) +
+ @lang('general.company'): + {{{ $asset->company->name }}} +
+ @endif + @if ($asset->serial)
@lang('admin/hardware/form.serial'): {{{ $asset->serial }}}
diff --git a/app/views/backend/layouts/default.blade.php b/app/views/backend/layouts/default.blade.php index e31cb12d88..eba9fd2ea0 100644 --- a/app/views/backend/layouts/default.blade.php +++ b/app/views/backend/layouts/default.blade.php @@ -199,6 +199,11 @@