2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
2016-08-16 13:02:42 -07:00
|
|
|
use App\Models\Manufacturer;
|
|
|
|
use App\Models\Setting;
|
|
|
|
use Auth;
|
2016-08-16 18:49:54 -07:00
|
|
|
use Gate;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Input;
|
|
|
|
use Lang;
|
|
|
|
use Redirect;
|
|
|
|
use Str;
|
|
|
|
use View;
|
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to Manufacturers for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class ManufacturersController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
|
|
* the content for the manufacturers listing, which is generated in getDatatable.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getIndex()
|
|
|
|
{
|
|
|
|
// Show the page
|
|
|
|
return View::make('manufacturers/index', compact('manufacturers'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Returns a view that displays a form to create a new manufacturer.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::postCreate()
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getCreate()
|
|
|
|
{
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
return View::make('manufacturers/edit')->with('item', new Manufacturer);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Validates and stores the data for a new manufacturer.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::postCreate()
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function postCreate()
|
|
|
|
{
|
|
|
|
$manufacturer = new Manufacturer;
|
|
|
|
$manufacturer->name = e(Input::get('name'));
|
|
|
|
$manufacturer->user_id = Auth::user()->id;
|
|
|
|
|
|
|
|
if ($manufacturer->save()) {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/manufacturers")->with('success', trans('admin/manufacturers/message.create.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($manufacturer->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Returns a view that displays a form to edit a manufacturer.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::postEdit()
|
|
|
|
* @param int $manufacturerId
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getEdit($manufacturerId = null)
|
|
|
|
{
|
|
|
|
// Check if the manufacturer exists
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if (is_null($item = Manufacturer::find($manufacturerId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the manufacturer page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show the page
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
return View::make('manufacturers/edit', compact('item'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Validates and stores the updated manufacturer data.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getEdit()
|
|
|
|
* @param int $manufacturerId
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function postEdit($manufacturerId = null)
|
|
|
|
{
|
|
|
|
// Check if the manufacturer exists
|
|
|
|
if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
|
|
|
|
// Redirect to the manufacturer page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the data
|
|
|
|
$manufacturer->name = e(Input::get('name'));
|
|
|
|
|
|
|
|
// Was it created?
|
|
|
|
if ($manufacturer->save()) {
|
|
|
|
// Redirect to the new manufacturer page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/manufacturers")->with('success', trans('admin/manufacturers/message.update.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($manufacturer->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Deletes a manufacturer.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @param int $manufacturerId
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getDelete($manufacturerId)
|
|
|
|
{
|
|
|
|
// Check if the manufacturer exists
|
|
|
|
if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
|
|
|
|
// Redirect to the manufacturers page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($manufacturer->has_models() > 0) {
|
|
|
|
|
|
|
|
// Redirect to the asset management page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to('admin/settings/manufacturers')->with('error', trans('admin/manufacturers/message.assoc_users'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Delete the manufacturer
|
|
|
|
$manufacturer->delete();
|
|
|
|
|
|
|
|
// Redirect to the manufacturers management page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to('admin/settings/manufacturers')->with('success', trans('admin/manufacturers/message.delete.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
|
|
* the content for the manufacturers detail listing, which is generated in getDatatable.
|
|
|
|
* This data contains a listing of all assets that belong to that manufacturer.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-04-07 13:39:35 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getDataView()
|
|
|
|
* @param int $manufacturerId
|
|
|
|
* @since [v1.0]
|
2016-03-25 01:18:05 -07:00
|
|
|
* @return View
|
2016-04-07 13:39:35 -07:00
|
|
|
*/
|
|
|
|
public function getView($manufacturerId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-04-07 13:39:35 -07:00
|
|
|
$manufacturer = Manufacturer::find($manufacturerId);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (isset($manufacturer->id)) {
|
|
|
|
return View::make('manufacturers/view', compact('manufacturer'));
|
|
|
|
} else {
|
|
|
|
// Prepare the error message
|
2016-04-07 13:39:35 -07:00
|
|
|
$error = trans('admin/manufacturers/message.does_not_exist', compact('id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Redirect to the user management page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('manufacturers')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-07 13:39:35 -07:00
|
|
|
/**
|
|
|
|
* Generates the JSON used to display the manufacturer listings.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getIndex()
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return String JSON
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getDatatable()
|
|
|
|
{
|
|
|
|
$manufacturers = Manufacturer::select(array('id','name'))->with('assets')
|
|
|
|
->whereNull('deleted_at');
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$manufacturers = $manufacturers->TextSearch(e(Input::get('search')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('offset')) {
|
|
|
|
$offset = e(Input::get('offset'));
|
|
|
|
} else {
|
|
|
|
$offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('limit')) {
|
|
|
|
$limit = e(Input::get('limit'));
|
|
|
|
} else {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
$allowed_columns = ['id','name'];
|
|
|
|
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
|
|
|
|
|
|
|
$manufacturers->orderBy($sort, $order);
|
|
|
|
|
|
|
|
$manufacturersCount = $manufacturers->count();
|
|
|
|
$manufacturers = $manufacturers->skip($offset)->take($limit)->get();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($manufacturers as $manufacturer) {
|
2016-04-07 13:39:35 -07:00
|
|
|
$actions = '<a href="'.route('update/manufacturer', $manufacturer->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/manufacturer', $manufacturer->id).'" data-content="'.trans('admin/manufacturers/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($manufacturer->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'id' => $manufacturer->id,
|
2016-03-25 15:24:12 -07:00
|
|
|
'name' => (string)link_to('admin/settings/manufacturers/'.$manufacturer->id.'/view', e($manufacturer->name)),
|
2016-03-25 01:18:05 -07:00
|
|
|
'assets' => $manufacturer->assets->count(),
|
|
|
|
'actions' => $actions
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array('total' => $manufacturersCount, 'rows' => $rows);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-07 13:39:35 -07:00
|
|
|
/**
|
|
|
|
* Generates the JSON used to display the manufacturer detail.
|
|
|
|
* This JSON returns data on all of the assets with the specified
|
|
|
|
* manufacturer ID number.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see ManufacturersController::getView()
|
|
|
|
* @param int $manufacturerId
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return String JSON
|
|
|
|
*/
|
2016-08-16 18:49:54 -07:00
|
|
|
public function getDataView($manufacturerId, $itemtype = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$manufacturer = Manufacturer::find($manufacturerId);
|
2016-08-16 18:49:54 -07:00
|
|
|
|
|
|
|
switch ($itemtype) {
|
|
|
|
case "assets":
|
|
|
|
return $this->getDataAssetsView($manufacturer);
|
|
|
|
case "licenses":
|
|
|
|
return $this->getDataLicensesView($manufacturer);
|
|
|
|
case "accessories":
|
|
|
|
return $this->getDataAccessoriesView($manufacturer);
|
|
|
|
case "consumables":
|
|
|
|
return $this->getDataConsumablesView($manufacturer);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Exception("We shouldn't be here");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDataAssetsView(Manufacturer $manufacturer)
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company');
|
2016-03-25 01:18:05 -07:00
|
|
|
$manufacturer_assets = $manufacturer->assets;
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$manufacturer_assets = $manufacturer_assets->TextSearch(e(Input::get('search')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('offset')) {
|
|
|
|
$offset = e(Input::get('offset'));
|
|
|
|
} else {
|
|
|
|
$offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('limit')) {
|
|
|
|
$limit = e(Input::get('limit'));
|
|
|
|
} else {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
|
|
|
|
$allowed_columns = ['id','name','serial','asset_tag'];
|
|
|
|
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
|
|
|
$count = $manufacturer_assets->count();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($manufacturer_assets as $asset) {
|
|
|
|
|
|
|
|
$actions = '';
|
|
|
|
if ($asset->deleted_at=='') {
|
2016-12-15 04:09:40 -08:00
|
|
|
$actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><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/hardware', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
|
2016-03-25 01:18:05 -07:00
|
|
|
} elseif ($asset->deleted_at!='') {
|
|
|
|
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
|
2016-08-16 13:02:42 -07:00
|
|
|
if ($asset->availableForCheckout()) {
|
|
|
|
if (Gate::allows('assets.checkout')) {
|
|
|
|
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Gate::allows('assets.checkin')) {
|
|
|
|
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
$rows[] = array(
|
|
|
|
'id' => $asset->id,
|
|
|
|
'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())),
|
|
|
|
'model' => e($asset->model->name),
|
|
|
|
'asset_tag' => e($asset->asset_tag),
|
|
|
|
'serial' => e($asset->serial),
|
|
|
|
'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '',
|
|
|
|
'actions' => $actions,
|
2016-10-28 14:15:13 -07:00
|
|
|
// 'companyName' => e(Company::getName($asset)),
|
|
|
|
'companyName' => is_null($asset->company) ? '' : $asset->company->name
|
2016-08-16 18:49:54 -07:00
|
|
|
);
|
|
|
|
|
2016-10-28 14:15:13 -07:00
|
|
|
if (isset($inout)) {
|
|
|
|
$row['change'] = $inout;
|
2016-08-16 18:49:54 -07:00
|
|
|
}
|
2016-10-28 14:15:13 -07:00
|
|
|
}
|
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
$data = array('total' => $count, 'rows' => $rows);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDataLicensesView(Manufacturer $manufacturer)
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$manufacturer = $manufacturer->load('licenses.company', 'licenses.manufacturer', 'licenses.licenseSeatsRelation');
|
2016-08-16 18:49:54 -07:00
|
|
|
$licenses = $manufacturer->licenses;
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$licenses = $licenses->TextSearch(Input::get('search'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$licenseCount = $licenses->count();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($licenses as $license) {
|
|
|
|
$actions = '<span style="white-space: nowrap;">';
|
|
|
|
|
|
|
|
if (Gate::allows('licenses.checkout')) {
|
2016-12-15 13:07:34 -08:00
|
|
|
$actions .= '<a href="' . route('licenses.freecheckout', $license->id)
|
2016-08-16 18:49:54 -07:00
|
|
|
. '" class="btn btn-primary btn-sm' . (($license->remaincount() > 0) ? '' : ' disabled') . '" style="margin-right:5px;">' . trans('general.checkout') . '</a> ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Gate::allows('licenses.create')) {
|
|
|
|
$actions .= '<a href="' . route('clone/license', $license->id)
|
|
|
|
. '" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone asset"><i class="fa fa-files-o"></i></a>';
|
|
|
|
}
|
|
|
|
if (Gate::allows('licenses.edit')) {
|
2016-12-15 12:48:15 -08:00
|
|
|
$actions .= '<a href="' . route('licenses.edit', ['license' => $license->id])
|
2016-08-16 18:49:54 -07:00
|
|
|
. '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
if (Gate::allows('licenses.delete')) {
|
|
|
|
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'
|
|
|
|
. route('delete/license', $license->id)
|
|
|
|
. '" data-content="' . trans('admin/licenses/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($license->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
$actions .='</span>';
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'id' => $license->id,
|
|
|
|
'name' => (string) link_to('/admin/licenses/'.$license->id.'/view', $license->name),
|
|
|
|
'serial' => (string) link_to('/admin/licenses/'.$license->id.'/view', mb_strimwidth($license->serial, 0, 50, "...")),
|
2016-10-28 14:15:13 -07:00
|
|
|
'totalSeats' => $license->licenseSeatCount,
|
2016-08-16 18:49:54 -07:00
|
|
|
'remaining' => $license->remaincount(),
|
|
|
|
'license_name' => e($license->license_name),
|
|
|
|
'license_email' => e($license->license_email),
|
|
|
|
'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '',
|
|
|
|
'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '',
|
|
|
|
'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '',
|
|
|
|
'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '',
|
|
|
|
'order_number' => ($license->order_number) ? e($license->order_number) : '',
|
|
|
|
'notes' => ($license->notes) ? e($license->notes) : '',
|
|
|
|
'actions' => $actions,
|
|
|
|
'companyName' => is_null($license->company) ? '' : e($license->company->name),
|
|
|
|
'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : ''
|
2016-03-25 01:18:05 -07:00
|
|
|
);
|
2016-08-16 18:49:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = array('total' => $licenseCount, 'rows' => $rows);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDataAccessoriesView(Manufacturer $manufacturer)
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$manufacturer = $manufacturer->load(
|
|
|
|
'accessories.location',
|
|
|
|
'accessories.company',
|
|
|
|
'accessories.category',
|
|
|
|
'accessories.manufacturer',
|
|
|
|
'accessories.users'
|
|
|
|
);
|
2016-08-16 18:49:54 -07:00
|
|
|
$accessories = $manufacturer->accessories;
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$accessories = $accessories->TextSearch(e(Input::get('search')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('limit')) {
|
|
|
|
$limit = e(Input::get('limit'));
|
|
|
|
} else {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
$accessCount = $accessories->count();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($accessories as $accessory) {
|
|
|
|
|
|
|
|
$actions = '<nobr>';
|
|
|
|
if (Gate::allows('accessories.checkout')) {
|
|
|
|
$actions .= '<a href="' . route('checkout/accessory',
|
|
|
|
$accessory->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($accessory->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
|
|
|
|
}
|
|
|
|
if (Gate::allows('accessories.edit')) {
|
2016-12-15 04:09:40 -08:00
|
|
|
$actions .= '<a href="' . route('accessories.update',
|
2016-08-16 18:49:54 -07:00
|
|
|
$accessory->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
if (Gate::allows('accessories.delete')) {
|
2016-12-15 04:09:40 -08:00
|
|
|
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('accessories.destroy',
|
2016-08-16 18:49:54 -07:00
|
|
|
$accessory->id) . '" data-content="' . trans('admin/accessories/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($accessory->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-08-16 18:49:54 -07:00
|
|
|
$actions .= '</nobr>';
|
|
|
|
$company = $accessory->company;
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'name' => '<a href="'.url('admin/accessories/'.$accessory->id).'/view">'. $accessory->name.'</a>',
|
|
|
|
'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '',
|
|
|
|
'qty' => e($accessory->qty),
|
|
|
|
'order_number' => e($accessory->order_number),
|
|
|
|
'min_amt' => e($accessory->min_amt),
|
|
|
|
'location' => ($accessory->location) ? e($accessory->location->name): '',
|
|
|
|
'purchase_date' => e($accessory->purchase_date),
|
|
|
|
'purchase_cost' => number_format($accessory->purchase_cost, 2),
|
|
|
|
'numRemaining' => $accessory->numRemaining(),
|
|
|
|
'actions' => $actions,
|
|
|
|
'companyName' => is_null($company) ? '' : e($company->name),
|
|
|
|
'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : ''
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
$data = array('total'=>$accessCount, 'rows'=>$rows);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDataConsumablesView($manufacturer)
|
|
|
|
{
|
2016-10-28 14:15:13 -07:00
|
|
|
$manufacturer = $manufacturer->load(
|
|
|
|
'consumables.location',
|
|
|
|
'consumables.company',
|
|
|
|
'consumables.category',
|
|
|
|
'consumables.manufacturer',
|
|
|
|
'consumables.users'
|
|
|
|
);
|
2016-08-16 18:49:54 -07:00
|
|
|
$consumables = $manufacturer->consumables;
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$consumables = $consumables->TextSearch(e(Input::get('search')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('limit')) {
|
|
|
|
$limit = e(Input::get('limit'));
|
|
|
|
} else {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
$consumCount = $consumables->count();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($consumables as $consumable) {
|
|
|
|
$actions = '<nobr>';
|
|
|
|
if (Gate::allows('consumables.checkout')) {
|
|
|
|
$actions .= '<a href="' . route('checkout/consumable',
|
|
|
|
$consumable->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($consumable->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Gate::allows('consumables.edit')) {
|
2016-12-15 04:09:40 -08:00
|
|
|
$actions .= '<a href="' . route('consumables.edit',
|
2016-08-16 18:49:54 -07:00
|
|
|
$consumable->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
if (Gate::allows('consumables.delete')) {
|
2016-12-15 04:09:40 -08:00
|
|
|
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('consumables.destroy',
|
2016-08-16 18:49:54 -07:00
|
|
|
$consumable->id) . '" data-content="' . trans('admin/consumables/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($consumable->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions .='</nobr>';
|
|
|
|
|
|
|
|
$company = $consumable->company;
|
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'id' => $consumable->id,
|
|
|
|
'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)),
|
|
|
|
'location' => ($consumable->location) ? e($consumable->location->name) : '',
|
|
|
|
'min_amt' => e($consumable->min_amt),
|
|
|
|
'qty' => e($consumable->qty),
|
|
|
|
'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '',
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
'model_number' => e($consumable->model_number),
|
2016-08-16 18:49:54 -07:00
|
|
|
'item_no' => e($consumable->item_no),
|
|
|
|
'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category',
|
|
|
|
'order_number' => e($consumable->order_number),
|
|
|
|
'purchase_date' => e($consumable->purchase_date),
|
|
|
|
'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' ,
|
|
|
|
'numRemaining' => $consumable->numRemaining(),
|
|
|
|
'actions' => $actions,
|
|
|
|
'companyName' => is_null($company) ? '' : e($company->name),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array('total' => $consumCount, 'rows' => $rows);
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|