2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Assets;
|
|
|
|
use Input;
|
|
|
|
use Lang;
|
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use DB;
|
|
|
|
use Redirect;
|
|
|
|
use App\Models\LicenseSeat;
|
|
|
|
use App\Models\Depreciation;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Setting;
|
|
|
|
use App\Models\Supplier;
|
|
|
|
use Validator;
|
|
|
|
use View;
|
|
|
|
use Response;
|
|
|
|
use Slack;
|
|
|
|
use Config;
|
|
|
|
use Session;
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
use Auth;
|
2016-08-02 00:54:38 -07:00
|
|
|
use Gate;
|
2016-12-15 12:48:15 -08:00
|
|
|
use Illuminate\Http\Request;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to Licenses for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class LicensesController extends Controller
|
|
|
|
{
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
/**
|
|
|
|
* Returns a view that invokes the ajax tables which actually contains
|
|
|
|
* the content for the licenses listing, which is generated in getDatatable.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function index()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', License::class);
|
2016-03-25 01:18:05 -07:00
|
|
|
return View::make('licenses/index');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Returns a form view that allows an admin to create a new licence.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see AccessoriesController::getDatatable() method that generates the JSON response
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function create()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
return View::make('licenses/edit')
|
|
|
|
//->with('license_options',$license_options)
|
2016-08-16 18:49:54 -07:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
|
|
|
->with('supplier_list', Helper::suppliersList())
|
2016-03-25 01:18:05 -07:00
|
|
|
->with('maintained_list', $maintained_list)
|
2016-08-16 18:49:54 -07:00
|
|
|
->with('company_list', Helper::companyList())
|
|
|
|
->with('manufacturer_list', Helper::manufacturerList())
|
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
|
|
|
->with('item', new License);
|
2016-08-16 18:49:54 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license form data submitted from the new
|
|
|
|
* license form.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getCreate() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 15:15:11 -08:00
|
|
|
public function store(Request $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
2016-03-25 01:18:05 -07:00
|
|
|
// create a new model instance
|
|
|
|
$license = new License();
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('purchase_cost') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->purchase_cost = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_cost = Helper::ParseFloat($request->input('purchase_cost'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('supplier_id') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->supplier_id = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->supplier_id = $request->input('supplier_id');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('maintained') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->maintained = 0;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->maintained = $request->input('maintained');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('reassignable') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->reassignable = 0;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->reassignable = $request->input('reassignable');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('purchase_order') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->purchase_order = '';
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if (empty($request->input('manufacturer_id'))) {
|
2016-08-16 18:49:54 -07:00
|
|
|
$license->manufacturer_id = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->manufacturer_id = $request->input('manufacturer_id');
|
2016-08-16 18:49:54 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
// Save the license data
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->name = $request->input('name');
|
|
|
|
$license->serial = $request->input('serial');
|
|
|
|
$license->license_email = $request->input('license_email');
|
|
|
|
$license->license_name = $request->input('license_name');
|
|
|
|
$license->notes = $request->input('notes');
|
|
|
|
$license->order_number = $request->input('order_number');
|
|
|
|
$license->seats = $request->input('seats');
|
|
|
|
$license->purchase_date = $request->input('purchase_date');
|
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
|
|
|
$license->depreciation_id = $request->input('depreciation_id');
|
2016-12-15 12:48:15 -08:00
|
|
|
$license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->expiration_date = $request->input('expiration_date');
|
|
|
|
$license->termination_date = $request->input('termination_date');
|
|
|
|
$license->user_id = Auth::id();
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (($license->purchase_date == "") || ($license->purchase_date == "0000-00-00")) {
|
|
|
|
$license->purchase_date = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($license->expiration_date == "") || ($license->expiration_date == "0000-00-00")) {
|
|
|
|
$license->expiration_date = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($license->purchase_cost == "") || ($license->purchase_cost == "0.00")) {
|
|
|
|
$license->purchase_cost = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was the license created?
|
|
|
|
if ($license->save()) {
|
2016-10-12 18:45:32 -07:00
|
|
|
$license->logCreate();
|
2016-03-25 01:18:05 -07:00
|
|
|
$insertedId = $license->id;
|
2016-12-19 22:00:50 -08:00
|
|
|
// Save the license seat data
|
2016-06-22 12:27:41 -07:00
|
|
|
DB::transaction(function () use (&$insertedId, &$license) {
|
|
|
|
for ($x=0; $x<$license->seats; $x++) {
|
|
|
|
$license_seat = new LicenseSeat();
|
|
|
|
$license_seat->license_id = $insertedId;
|
2016-12-19 22:00:50 -08:00
|
|
|
$license_seat->user_id = Auth::id();
|
2016-06-22 12:27:41 -07:00
|
|
|
$license_seat->assigned_to = null;
|
|
|
|
$license_seat->notes = null;
|
|
|
|
$license_seat->save();
|
|
|
|
}
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the new license page
|
2016-12-15 11:57:19 -08:00
|
|
|
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.create.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($license->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Returns a form with existing license data to allow an admin to
|
|
|
|
* update license information.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function edit($licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
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 = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $item);
|
|
|
|
|
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 ($item->purchase_date == "0000-00-00") {
|
|
|
|
$item->purchase_date = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
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 ($item->purchase_cost == "0.00") {
|
|
|
|
$item->purchase_cost = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
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('licenses/edit', compact('item'))
|
2016-08-16 18:49:54 -07:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
|
|
|
->with('supplier_list', Helper::suppliersList())
|
|
|
|
->with('company_list', Helper::companyList())
|
|
|
|
->with('maintained_list', $maintained_list)
|
|
|
|
->with('manufacturer_list', Helper::manufacturerList());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license form data submitted from the edit
|
|
|
|
* license form.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getEdit() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $licenseId
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 12:48:15 -08:00
|
|
|
public function update(Request $request, $licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-03-25 17:20:28 -07:00
|
|
|
// Check if the license exists
|
2016-03-25 01:18:05 -07:00
|
|
|
if (is_null($license = License::find($licenseId))) {
|
|
|
|
// Redirect to the blogs management page
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $license);
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
// Update the license data
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->name = $request->input('name');
|
|
|
|
$license->serial = $request->input('serial');
|
|
|
|
$license->license_email = $request->input('license_email');
|
|
|
|
$license->license_name = $request->input('license_name');
|
|
|
|
$license->notes = $request->input('notes');
|
|
|
|
$license->order_number = $request->input('order_number');
|
|
|
|
$license->depreciation_id = $request->input('depreciation_id');
|
2016-12-15 12:48:15 -08:00
|
|
|
$license->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
|
|
|
$license->maintained = $request->input('maintained');
|
|
|
|
$license->reassignable = $request->input('reassignable');
|
2016-12-15 12:48:15 -08:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if (empty($request->input('manufacturer_id'))) {
|
2016-08-16 18:49:54 -07:00
|
|
|
$license->manufacturer_id = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->manufacturer_id = $request->input('manufacturer_id');
|
2016-08-16 18:49:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('supplier_id') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->supplier_id = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->supplier_id = $request->input('supplier_id');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the asset data
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('purchase_date') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->purchase_date = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_date = $request->input('purchase_date');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('expiration_date') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->expiration_date = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->expiration_date = $request->input('expiration_date');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('termination_date') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->termination_date = null;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->termination_date = $request->input('termination_date');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('purchase_cost') == '') {
|
2016-09-27 19:07:30 -07:00
|
|
|
$license->purchase_cost = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_cost = Helper::ParseFloat($request->input('purchase_cost'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('maintained') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->maintained = 0;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->maintained = $request->input('maintained');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('reassignable') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->reassignable = 0;
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->reassignable = $request->input('reassignable');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('purchase_order') == '') {
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->purchase_order = '';
|
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$license->purchase_order = $request->input('purchase_order');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//Are we changing the total number of seats?
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($license->seats != $request->input('seats')) {
|
2016-03-25 01:18:05 -07:00
|
|
|
//Determine how many seats we are dealing with
|
2016-12-19 22:00:50 -08:00
|
|
|
$difference = $request->input('seats') - $license->licenseseats()->count();
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if ($difference < 0) {
|
|
|
|
//Filter out any license which have a user attached;
|
|
|
|
$seats = $license->licenseseats->filter(function ($seat) {
|
|
|
|
return is_null($seat->user);
|
|
|
|
});
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
//If the remaining collection is as large or larger than the number of seats we want to delete
|
2016-03-25 01:18:05 -07:00
|
|
|
if ($seats->count() >= abs($difference)) {
|
|
|
|
for ($i=1; $i <= abs($difference); $i++) {
|
|
|
|
//Delete the appropriate number of seats
|
|
|
|
$seats->pop()->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Log the deletion of seats to the log
|
2016-12-19 22:00:50 -08:00
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = License::class;
|
|
|
|
$logAction->item_id = $license->id;
|
|
|
|
$logAction->user_id = Auth::user()->id;
|
|
|
|
$logAction->note = '-'.abs($difference)." seats";
|
|
|
|
$logAction->target_id = null;
|
|
|
|
$logAction->logaction('delete seats');
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
// Redirect to the license edit page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.assoc_users'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for ($i=1; $i <= $difference; $i++) {
|
|
|
|
//Create a seat for this license
|
|
|
|
$license_seat = new LicenseSeat();
|
|
|
|
$license_seat->license_id = $license->id;
|
|
|
|
$license_seat->user_id = Auth::user()->id;
|
|
|
|
$license_seat->assigned_to = null;
|
|
|
|
$license_seat->notes = null;
|
|
|
|
$license_seat->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Log the addition of license to the log.
|
2016-12-19 22:00:50 -08:00
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = License::class;
|
|
|
|
$logAction->item_id = $license->id;
|
|
|
|
$logAction->user_id = Auth::user()->id;
|
|
|
|
$logAction->note = '+'.abs($difference)." seats";
|
|
|
|
$logAction->target_id = null;
|
|
|
|
$logAction->logaction('add seats');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-15 12:48:15 -08:00
|
|
|
$license->seats = e($request->input('seats'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($license->save()) {
|
2016-12-15 12:48:15 -08:00
|
|
|
return redirect()->route('licenses.show', ['license' => $licenseId])->with('success', trans('admin/licenses/message.update.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/licenses/$licenseId/edit")->with('error', trans('admin/licenses/message.update.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Checks to see whether the selected license can be deleted, and
|
|
|
|
* if it can, marks it as deleted.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 04:09:40 -08:00
|
|
|
public function destroy($licenseId)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the license exists
|
|
|
|
if (is_null($license = License::find($licenseId))) {
|
|
|
|
// Redirect to the license management page
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('delete', $license);
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($license->assigned_seats_count == 0) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Delete the license and the associated license seats
|
|
|
|
DB::table('license_seats')
|
2016-12-19 22:00:50 -08:00
|
|
|
->where('id', $license->id)
|
|
|
|
->update(array('assigned_to' => null,'asset_id' => null));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeats = $license->licenseseats();
|
|
|
|
$licenseSeats->delete();
|
2016-03-25 01:18:05 -07:00
|
|
|
$license->delete();
|
|
|
|
|
|
|
|
// Redirect to the licenses management page
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.delete.success'));
|
2016-12-19 22:00:50 -08:00
|
|
|
// Redirect to the license management page
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 22:00:50 -08:00
|
|
|
// There are still licenses in use.
|
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.assoc_users'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Provides the form view for checking out a license to a user.
|
|
|
|
* Here we pass the license seat ID instead of the license ID,
|
|
|
|
* because licenses themselves are never checked out to anyone,
|
|
|
|
* only the seats associated with them.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getCheckout($seatId)
|
|
|
|
{
|
2016-03-25 17:20:28 -07:00
|
|
|
// Check if the license seat exists
|
2016-12-19 22:00:50 -08:00
|
|
|
if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$this->authorize('checkout', $licenseSeat);
|
|
|
|
return View::make('licenses/checkout', compact('licenseSeat'))
|
|
|
|
->with('users_list', Helper::usersList())
|
|
|
|
->with('asset_list', Helper::detailedAssetList());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-19 22:00:50 -08:00
|
|
|
* Validates and stores the license checkout action.
|
|
|
|
*
|
|
|
|
* @todo Switch to using a FormRequest for validation here.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param Request $request
|
|
|
|
* @param int $seatId
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-12-15 12:48:15 -08:00
|
|
|
public function postCheckout(Request $request, $seatId)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat = LicenseSeat::find($seatId);
|
2016-12-15 12:48:15 -08:00
|
|
|
$assigned_to = e($request->input('assigned_to'));
|
|
|
|
$asset_id = e($request->input('asset_id'));
|
2016-03-25 01:18:05 -07:00
|
|
|
$user = Auth::user();
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$this->authorize('checkout', $licenseSeat);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Declare the rules for the form validation
|
2016-12-19 22:00:50 -08:00
|
|
|
$rules = [
|
2016-03-25 01:18:05 -07:00
|
|
|
'note' => 'string',
|
|
|
|
'asset_id' => 'required_without:assigned_to',
|
2016-12-19 22:00:50 -08:00
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Create a new validator instance from our validation rules
|
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
// If validation fails, we'll exit the operation now.
|
|
|
|
if ($validator->fails()) {
|
|
|
|
// Ooops.. something went wrong
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($validator);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($assigned_to!='') {
|
|
|
|
// Check if the user exists
|
|
|
|
if (is_null($is_assigned_to = User::find($assigned_to))) {
|
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.user_does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($asset_id!='') {
|
2016-07-07 01:13:31 -07:00
|
|
|
if (is_null($asset = Asset::find($asset_id))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.asset_does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-07-07 01:13:31 -07:00
|
|
|
|
2016-08-16 18:49:54 -07:00
|
|
|
if (($asset->assigned_to!='') && (($asset->assigned_to!=$assigned_to)) && ($assigned_to!='')) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the asset exists
|
2016-12-19 22:00:50 -08:00
|
|
|
if (is_null($licenseSeat)) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-15 12:48:15 -08:00
|
|
|
if ($request->input('asset_id') == '') {
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat->asset_id = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat->asset_id = $request->input('asset_id');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the asset data
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('assigned_to') == '') {
|
|
|
|
$licenseSeat->assigned_to = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat->assigned_to = $request->input('assigned_to');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Was the asset updated?
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($licenseSeat->save()) {
|
|
|
|
$licenseSeat->logCheckout($request->input('note'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$data['license_id'] =$licenseSeat->license_id;
|
|
|
|
$data['note'] = $request->input('note');
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$license = License::find($licenseSeat->license_id);
|
2016-03-25 01:18:05 -07:00
|
|
|
$settings = Setting::getSettings();
|
|
|
|
|
|
|
|
// Update the asset data
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($request->input('assigned_to') == '') {
|
|
|
|
$slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name
|
|
|
|
.'> checked out to <'.route('hardware.show',$asset->id) .'|'.$asset->showAssetName()
|
|
|
|
.'> by <'.route('users.show', $user->id).'|'.$user->fullName().'>.';
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-12-19 22:00:50 -08:00
|
|
|
$slack_msg = 'License <'.route('licenses.show', $license->id).'|'.$license->name
|
|
|
|
.'> checked out to <'.route('users.show', $user->id).'|'.$is_assigned_to->fullName()
|
|
|
|
.'> by <'.route('users.show', $user->id) .'|'.$user->fullName().'>.';
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->slack_endpoint) {
|
|
|
|
$slack_settings = [
|
|
|
|
'username' => $settings->botname,
|
|
|
|
'channel' => $settings->slack_channel,
|
|
|
|
'link_names' => true
|
|
|
|
];
|
|
|
|
|
|
|
|
$client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$client->attach([
|
|
|
|
'color' => 'good',
|
|
|
|
'fields' => [
|
|
|
|
[
|
|
|
|
'title' => 'Checked Out:',
|
|
|
|
'value' => $slack_msg
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'title' => 'Note:',
|
2016-12-15 12:48:15 -08:00
|
|
|
'value' => e($request->input('note'))
|
2016-03-25 01:18:05 -07:00
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
])->send('License Checked Out');
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to the new asset page
|
2016-12-15 11:57:19 -08:00
|
|
|
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.checkout.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to the asset management page with error
|
2016-12-19 22:00:50 -08:00
|
|
|
return redirect()->to("admin/licenses/{$asset_id}/checkout")->with('error', trans('admin/licenses/message.create.error'))->with('license', new License);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Makes the form view to check a license seat back into inventory.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @param string $backTo
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getCheckin($seatId = null, $backTo = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the asset exists
|
|
|
|
if (is_null($licenseseat = LicenseSeat::find($seatId))) {
|
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('checkin', $licenseseat);
|
2016-12-19 22:00:50 -08:00
|
|
|
return View::make('licenses/checkin', compact('licenseseat'))->with('backto', $backTo);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Validates and stores the license checkin action.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getCheckin() method that provides the form view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $seatId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @param string $backTo
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postCheckin($seatId = null, $backTo = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the asset exists
|
2016-12-19 22:00:50 -08:00
|
|
|
if (is_null($licenseSeat = LicenseSeat::find($seatId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the asset management page with error
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$license = License::find($licenseSeat->license_id);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$this->authorize('checkin', $licenseSeat);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (!$license->reassignable) {
|
|
|
|
// Not allowed to checkin
|
|
|
|
Session::flash('error', 'License not reassignable.');
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput();
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Declare the rules for the form validation
|
|
|
|
$rules = array(
|
|
|
|
'note' => 'string',
|
|
|
|
'notes' => 'string',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create a new validator instance from our validation rules
|
|
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
|
|
|
|
|
|
// If validation fails, we'll exit the operation now.
|
|
|
|
if ($validator->fails()) {
|
|
|
|
// Ooops.. something went wrong
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($validator);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 22:00:50 -08:00
|
|
|
$return_to = User::find($licenseSeat->assigned_to);
|
2016-11-17 15:54:29 -08:00
|
|
|
if (!$return_to) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$return_to = Asset::find($licenseSeat->asset_id);
|
2016-11-17 15:54:29 -08:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
// Update the asset data
|
2016-12-19 22:00:50 -08:00
|
|
|
$licenseSeat->assigned_to = null;
|
|
|
|
$licenseSeat->asset_id = null;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
// Was the asset updated?
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($licenseSeat->save()) {
|
|
|
|
$licenseSeat->logCheckin($return_to, e($request->input('note')));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$settings = Setting::getSettings();
|
|
|
|
|
|
|
|
if ($settings->slack_endpoint) {
|
|
|
|
$slack_settings = [
|
|
|
|
'username' => $settings->botname,
|
|
|
|
'channel' => $settings->slack_channel,
|
|
|
|
'link_names' => true
|
|
|
|
];
|
|
|
|
|
|
|
|
$client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$client->attach([
|
|
|
|
'color' => 'good',
|
|
|
|
'fields' => [
|
|
|
|
[
|
|
|
|
'title' => 'Checked In:',
|
2016-12-19 11:04:28 -08:00
|
|
|
'value' => 'License: <'.route('licenses.show', $license->id).'|'.$license->name
|
|
|
|
.'> checked in by <'.route('users.show', $user->id).'|'.$user->fullName().'>.'
|
2016-03-25 01:18:05 -07:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'title' => 'Note:',
|
2016-12-15 12:48:15 -08:00
|
|
|
'value' => e($request->input('note'))
|
2016-03-25 01:18:05 -07:00
|
|
|
],
|
|
|
|
|
|
|
|
]
|
|
|
|
])->send('License Checked In');
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
if ($backTo=='user') {
|
|
|
|
return redirect()->route("users.show", $return_to->id)->with('success', trans('admin/licenses/message.checkin.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 22:00:50 -08:00
|
|
|
redirect()->route("licenses.show", $licenseSeat->license_id)->with('success', trans('admin/licenses/message.checkin.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
// Redirect to the license page with error
|
2016-12-15 11:57:19 -08:00
|
|
|
return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkin.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Makes the license detail page.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-12-15 11:57:19 -08:00
|
|
|
public function show($licenseId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
$license = License::find($licenseId);
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
|
|
|
|
$this->authorize('view', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
return View::make('licenses/view', compact('license'));
|
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
|
|
return redirect()->route('licenses.index')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getClone($licenseId = null)
|
|
|
|
{
|
|
|
|
if (is_null($license_to_clone = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('create', License::class);
|
|
|
|
|
2016-12-19 22:00:50 -08:00
|
|
|
$maintained_list = [
|
|
|
|
'' => 'Maintained',
|
|
|
|
'1' => 'Yes',
|
|
|
|
'0' => 'No'
|
|
|
|
];
|
2016-03-25 01:18:05 -07:00
|
|
|
//clone the orig
|
|
|
|
$license = clone $license_to_clone;
|
|
|
|
$license->id = null;
|
|
|
|
$license->serial = null;
|
|
|
|
|
|
|
|
// Show the page
|
|
|
|
return View::make('licenses/edit')
|
2016-12-19 22:00:50 -08:00
|
|
|
->with('depreciation_list', Helper::depreciationList())
|
|
|
|
->with('supplier_list', Helper::suppliersList())
|
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
|
|
|
->with('item', $license)
|
2016-03-25 01:18:05 -07:00
|
|
|
->with('maintained_list', $maintained_list)
|
2016-12-19 22:00:50 -08:00
|
|
|
->with('company_list', Helper::companyList())
|
2016-09-14 19:04:52 -07:00
|
|
|
->with('manufacturer_list', Helper::manufacturerList());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Validates and stores files associated with a license.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @todo Switch to using the AssetFileRequest form request validator.
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function postUpload($licenseId = null)
|
|
|
|
{
|
|
|
|
$license = License::find($licenseId);
|
|
|
|
// the license is valid
|
2016-03-25 15:50:08 -07:00
|
|
|
$destinationPath = config('app.private_uploads').'/licenses';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('update', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (Input::hasFile('licensefile')) {
|
|
|
|
|
|
|
|
foreach (Input::file('licensefile') as $file) {
|
|
|
|
|
|
|
|
$rules = array(
|
2016-11-29 08:01:08 -08:00
|
|
|
'licensefile' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar,rtf,xml,lic|max:2000'
|
2016-03-25 01:18:05 -07:00
|
|
|
);
|
|
|
|
$validator = Validator::make(array('licensefile'=> $file), $rules);
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
if ($validator->fails()) {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->with('error', trans('admin/licenses/message.upload.invalidfiles'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
$extension = $file->getClientOriginalExtension();
|
|
|
|
$filename = 'license-'.$license->id.'-'.str_random(8);
|
|
|
|
$filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension;
|
|
|
|
$upload_success = $file->move($destinationPath, $filename);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
//Log the upload to the log
|
|
|
|
$license->logUpload($filename, e($request->input('notes')));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($upload_success) {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->with('success', trans('admin/licenses/message.upload.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
return redirect()->back()->with('error', trans('admin/licenses/message.upload.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
return redirect()->back()->with('error', trans('admin/licenses/message.upload.nofiles'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
// Prepare the error message
|
|
|
|
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
|
|
return redirect()->route('licenses.index')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Deletes the selected license file.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
|
|
|
* @param int $fileId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getDeleteFile($licenseId = null, $fileId = null)
|
|
|
|
{
|
|
|
|
$license = License::find($licenseId);
|
2016-03-25 15:50:08 -07:00
|
|
|
$destinationPath = config('app.private_uploads').'/licenses';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// the license is valid
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('edit', $license);
|
2016-03-25 01:18:05 -07:00
|
|
|
$log = Actionlog::find($fileId);
|
|
|
|
$full_filename = $destinationPath.'/'.$log->filename;
|
|
|
|
if (file_exists($full_filename)) {
|
|
|
|
unlink($destinationPath.'/'.$log->filename);
|
|
|
|
}
|
|
|
|
$log->delete();
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
// Prepare the error message
|
|
|
|
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
|
|
|
|
|
|
// Redirect to the licence management page
|
|
|
|
return redirect()->route('licenses.index')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-25 17:20:28 -07:00
|
|
|
* Allows the selected file to be viewed.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
2016-03-25 17:20:28 -07:00
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.4]
|
|
|
|
* @param int $licenseId
|
|
|
|
* @param int $fileId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function displayFile($licenseId = null, $fileId = null)
|
|
|
|
{
|
|
|
|
|
|
|
|
$license = License::find($licenseId);
|
|
|
|
|
|
|
|
// the license is valid
|
|
|
|
if (isset($license->id)) {
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', $license);
|
|
|
|
$log = Actionlog::find($fileId);
|
|
|
|
$file = $log->get_src('licenses');
|
|
|
|
return Response::download($file);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
// Prepare the error message
|
|
|
|
$error = trans('admin/licenses/message.does_not_exist', compact('id'));
|
|
|
|
// Redirect to the licence management page
|
|
|
|
return redirect()->route('licenses.index')->with('error', $error);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a JSON response to populate the licence index datatables.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @see LicensesController::getIndex() method that provides the view
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return String JSON
|
|
|
|
*/
|
2016-12-15 12:48:15 -08:00
|
|
|
public function getDatatable(Request $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('view', License::class);
|
2016-10-28 14:15:13 -07:00
|
|
|
$licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
if (Input::has('search')) {
|
2016-12-15 12:48:15 -08:00
|
|
|
$licenses = $licenses->TextSearch($request->input('search'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-12-19 22:00:50 -08:00
|
|
|
$offset = request('offset', 0);
|
|
|
|
$limit = request('limit', 50);
|
2016-12-15 12:48:15 -08:00
|
|
|
|
2016-11-11 19:46:18 -08:00
|
|
|
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company'];
|
2016-12-15 12:48:15 -08:00
|
|
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-11-11 19:46:18 -08:00
|
|
|
switch ($sort) {
|
|
|
|
case 'manufacturer':
|
|
|
|
$licenses = $licenses->OrderManufacturer($order);
|
|
|
|
break;
|
|
|
|
case 'company':
|
|
|
|
$licenses = $licenses->OrderCompany($order);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$licenses = $licenses->orderBy($sort, $order);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
$licenseCount = $licenses->count();
|
2016-12-15 12:48:15 -08:00
|
|
|
$licenses = $licenses->skip($offset)->take($limit)->get();
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($licenses as $license) {
|
2016-08-02 00:54:38 -07:00
|
|
|
$actions = '<span style="white-space: nowrap;">';
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
if (Gate::allows('checkout', License::class)) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$actions .= Helper::generateDatatableButton(
|
|
|
|
'checkout',
|
|
|
|
route('licenses.freecheckout', $license->id),
|
|
|
|
$license->remaincount() > 0
|
|
|
|
);
|
2016-08-02 00:54:38 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
if (Gate::allows('create', $license)) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$actions .= Helper::generateDatatableButton('clone', route('clone/license', $license->id));
|
2016-08-02 00:54:38 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
if (Gate::allows('update', $license)) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $license->id));
|
2016-08-02 00:54:38 -07:00
|
|
|
}
|
2016-12-19 11:04:28 -08:00
|
|
|
if (Gate::allows('delete', $license)) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$actions .= Helper::generateDatatableButton(
|
|
|
|
'delete',
|
|
|
|
route('licenses.destroy', $license->id),
|
|
|
|
true, /*enabled*/
|
|
|
|
trans('admin/licenses/message.delete.confirm'),
|
|
|
|
$license->name
|
|
|
|
);
|
2016-08-02 00:54:38 -07:00
|
|
|
}
|
|
|
|
$actions .='</span>';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
$rows[] = array(
|
|
|
|
'id' => $license->id,
|
2016-12-15 11:57:19 -08:00
|
|
|
'name' => (string) link_to('/licenses/'.$license->id, $license->name),
|
|
|
|
'serial' => (string) link_to('/licenses/'.$license->id, mb_strimwidth($license->serial, 0, 50, "...")),
|
2016-10-28 14:15:13 -07:00
|
|
|
'totalSeats' => $license->licenseSeatsCount,
|
2016-03-25 01:18:05 -07:00
|
|
|
'remaining' => $license->remaincount(),
|
2016-03-25 15:24:12 -07:00
|
|
|
'license_name' => e($license->license_name),
|
2016-08-16 18:49:54 -07:00
|
|
|
'license_email' => e($license->license_email),
|
2016-03-25 01:18:05 -07:00
|
|
|
'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '',
|
|
|
|
'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '',
|
2016-08-16 18:47:53 -07:00
|
|
|
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
|
2016-03-25 15:24:12 -07:00
|
|
|
'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '',
|
|
|
|
'order_number' => ($license->order_number) ? e($license->order_number) : '',
|
|
|
|
'notes' => ($license->notes) ? e($license->notes) : '',
|
2016-03-25 01:18:05 -07:00
|
|
|
'actions' => $actions,
|
2016-11-11 19:46:18 -08:00
|
|
|
'company' => is_null($license->company) ? '' : e($license->company->name),
|
2016-12-15 13:07:34 -08:00
|
|
|
'manufacturer' => $license->manufacturer ? (string) link_to('settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : ''
|
2016-03-25 01:18:05 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array('total' => $licenseCount, 'rows' => $rows);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2016-03-25 17:20:28 -07:00
|
|
|
/**
|
|
|
|
* Generates the next free seat ID for checkout.
|
|
|
|
*
|
|
|
|
* @todo This is a dumb way to solve this problem.
|
|
|
|
* Author should refactor. And go hide in a hole and
|
|
|
|
* think about what she's done. And perhaps find a new
|
|
|
|
* line of work. And get in the sea.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
|
|
|
* @param int $licenseId
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getFreeLicense($licenseId)
|
|
|
|
{
|
2016-12-19 11:04:28 -08:00
|
|
|
$this->authorize('checkout', License::class);
|
2016-03-25 01:18:05 -07:00
|
|
|
if (is_null($license = License::find($licenseId))) {
|
2016-12-15 04:09:40 -08:00
|
|
|
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
$seatId = $license->freeSeat($licenseId);
|
2016-12-15 13:07:34 -08:00
|
|
|
return redirect()->route('licenses.checkout', $seatId);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|