Merge branch 'develop'

This commit is contained in:
snipe 2017-11-03 12:48:17 -07:00
commit 9e0b3afa91
15 changed files with 133 additions and 92 deletions

View file

@ -282,7 +282,8 @@ class AssetsController extends Controller
'assets.name', 'assets.name',
'assets.asset_tag', 'assets.asset_tag',
'assets.model_id', 'assets.model_id',
]))->with('model')->RTD(); 'assets.status_id'
])->with('model', 'assetstatus')->NotArchived());
if ($request->has('search')) { if ($request->has('search')) {
@ -300,6 +301,10 @@ class AssetsController extends Controller
// they may not have a ->name value but we want to display something anyway // they may not have a ->name value but we want to display something anyway
foreach ($assets as $asset) { foreach ($assets as $asset) {
$asset->use_text = $asset->present()->fullName; $asset->use_text = $asset->present()->fullName;
if ($asset->assetstatus->getStatuslabelType()=='pending') {
$asset->use_text = $asset->present()->fullName.' ('.$asset->assetstatus->getStatuslabelType().')';
}
$asset->use_image = ($asset->getImageUrl()) ? $asset->getImageUrl() : null; $asset->use_image = ($asset->getImageUrl()) ? $asset->getImageUrl() : null;
} }

View file

@ -21,7 +21,7 @@ class LicensesController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', License::class); $this->authorize('view', License::class);
$licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer', 'supplier')); $licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier')->withCount('freeSeats'));
if ($request->has('search')) { if ($request->has('search')) {
$licenses = $licenses->TextSearch($request->input('search')); $licenses = $licenses->TextSearch($request->input('search'));
@ -78,16 +78,16 @@ class LicensesController extends Controller
switch ($request->input('sort')) { switch ($request->input('sort')) {
case 'manufacturer': case 'manufacturer':
$licenses = $licenses->OrderManufacturer($order); $licenses = $licenses->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
break; break;
case 'supplier': case 'supplier':
$licenses = $licenses->OrderSupplier($order); $licenses = $licenses->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);
break; break;
case 'company': case 'company':
$licenses = $licenses->OrderCompany($order); $licenses = $licenses->leftJoin('companies', 'licenses.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
break; break;
default: default:
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','license_name','license_email']; $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','license_name','license_email','free_seats_count','seats'];
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
$licenses = $licenses->orderBy($sort, $order); $licenses = $licenses->orderBy($sort, $order);
break; break;
@ -95,6 +95,7 @@ class LicensesController extends Controller
$total = $licenses->count(); $total = $licenses->count();
$licenses = $licenses->skip($offset)->take($limit)->get(); $licenses = $licenses->skip($offset)->take($limit)->get();
return (new LicensesTransformer)->transformLicenses($licenses, $total); return (new LicensesTransformer)->transformLicenses($licenses, $total);

View file

@ -225,6 +225,10 @@ class UsersController extends Controller
$user = User::findOrFail($id); $user = User::findOrFail($id);
$user->fill($request->all()); $user->fill($request->all());
if ($user->id == $request->input('manager_id')) {
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot be your own manager'));
}
if ($request->has('password')) { if ($request->has('password')) {
$user->password = bcrypt($request->input('password')); $user->password = bcrypt($request->input('password'));
} }

View file

@ -239,16 +239,19 @@ class LicensesController extends Controller
* @param int $seatId * @param int $seatId
* @return \Illuminate\Contracts\View\View * @return \Illuminate\Contracts\View\View
*/ */
public function getCheckout($seatId) public function getCheckout($licenceId)
{ {
// Check if the license seat exists // Check that the license is valid
if (is_null($licenseSeat = LicenseSeat::find($seatId))) { if ($license = License::where('id',$licenceId)->first()) {
// Redirect to the asset management page with error
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); // If the license is valid, check that there is an available seat
if ($license->getAvailSeatsCountAttribute() < 1) {
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
}
} }
$this->authorize('checkout', $licenseSeat); $this->authorize('checkout', $license);
return view('licenses/checkout', compact('licenseSeat')); return view('licenses/checkout', compact('license'));
} }
@ -262,11 +265,22 @@ class LicensesController extends Controller
* @param int $seatId * @param int $seatId
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
*/ */
public function postCheckout(Request $request, $seatId) public function postCheckout(Request $request, $licenseId)
{ {
$licenseSeat = LicenseSeat::find($seatId);
$assigned_to = e($request->input('assigned_to')); // Check that the license is valid
$asset_id = e($request->input('asset_id')); if ($license = License::where('id',$licenseId)->first()) {
// If the license is valid, check that there is an available seat
if ($license->getAvailSeatsCountAttribute() < 1) {
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
}
$next = $license->freeSeat();
$licenseSeat = LicenseSeat::where('license_id',$license->id)->find($next)->first();
$assigned_to = $request->input('assigned_to');
$asset_id = $request->input('asset_id');
$this->authorize('checkout', $licenseSeat); $this->authorize('checkout', $licenseSeat);
@ -334,6 +348,12 @@ class LicensesController extends Controller
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.checkout.success')); return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.checkout.success'));
} }
}
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkout.error')); return redirect()->route("licenses.index")->with('error', trans('admin/licenses/message.checkout.error'));
} }

View file

@ -106,7 +106,6 @@ class UsersController extends Controller
$user->password = bcrypt($request->input('password')); $user->password = bcrypt($request->input('password'));
$data['password'] = $request->input('password'); $data['password'] = $request->input('password');
} }
// Update the user
$user->first_name = $request->input('first_name'); $user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name'); $user->last_name = $request->input('last_name');
$user->locale = $request->input('locale'); $user->locale = $request->input('locale');
@ -278,6 +277,10 @@ class UsersController extends Controller
try { try {
$user = User::find($id); $user = User::find($id);
if ($user->id == $request->input('manager_id')) {
return redirect()->back()->withInput()->with('error', 'You cannot be your own manager.');
}
$this->authorize('update', $user); $this->authorize('update', $user);
// Figure out of this user was an admin before this edit // Figure out of this user was an admin before this edit
$orig_permissions_array = $user->decodePermissions(); $orig_permissions_array = $user->decodePermissions();

View file

@ -32,17 +32,15 @@ class LicensesTransformer
'purchase_cost' => e($license->purchase_cost), 'purchase_cost' => e($license->purchase_cost),
'notes' => e($license->notes), 'notes' => e($license->notes),
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'), 'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
'total_seats' => (int) $license->seats, 'seats' => (int) $license->seats,
'next_seat' => ($license->freeSeat()) ? (int) $license->freeSeat()->id : null, 'free_seats_count' => (int) $license->free_seats_count,
'remaining_qty' => (int) $license->remaincount(),
'min_qty' => $license->remaincount(),
'license_name' => e($license->license_name), 'license_name' => e($license->license_name),
'license_email' => e($license->license_email), 'license_email' => e($license->license_email),
'maintained' => ($license->maintained == 1) ? true : false, 'maintained' => ($license->maintained == 1) ? true : false,
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null, 'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id,'name'=> e($license->supplier->name)] : null,
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
'user_can_checkout' => (bool) ($license->remaincount() > 0), 'user_can_checkout' => (bool) ($license->free_seats_count > 0),
]; ];
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [

View file

@ -266,7 +266,9 @@ class License extends Depreciable
public function availCount() public function availCount()
{ {
return $this->licenseSeatsRelation() return $this->licenseSeatsRelation()
->whereNull('asset_id'); ->whereNull('asset_id')
->whereNull('assigned_to')
->whereNull('deleted_at');
} }
public function getAvailSeatsCountAttribute() public function getAvailSeatsCountAttribute()
@ -345,6 +347,15 @@ class License extends Depreciable
->first(); ->first();
} }
/*
* Get the next available free seat - used by
* the API to populate next_seat
*/
public function freeSeats()
{
return $this->hasMany('\App\Models\LicenseSeat')->whereNull('assigned_to')->whereNull('deleted_at')->whereNull('asset_id');
}
public static function getExpiringLicenses($days = 60) public static function getExpiringLicenses($days = 60)
{ {

View file

@ -61,7 +61,6 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
'email' => 'email|nullable', 'email' => 'email|nullable',
'password' => 'required|min:6', 'password' => 'required|min:6',
'locale' => 'max:10|nullable', 'locale' => 'max:10|nullable',
'manager_id' => 'nullable|different:id',
]; ];

View file

@ -76,14 +76,14 @@ class LicensePresenter extends Presenter
"title" => trans('general.manufacturer'), "title" => trans('general.manufacturer'),
"formatter" => "manufacturersLinkObjFormatter", "formatter" => "manufacturersLinkObjFormatter",
], [ ], [
"field" => "total_seats", "field" => "seats",
"searchable" => false, "searchable" => false,
"sortable" => false, "sortable" => true,
"title" => trans('admin/accessories/general.total'), "title" => trans('admin/accessories/general.total'),
], [ ], [
"field" => "remaining_qty", "field" => "free_seats_count",
"searchable" => false, "searchable" => false,
"sortable" => false, "sortable" => true,
"title" => trans('admin/accessories/general.remaining'), "title" => trans('admin/accessories/general.remaining'),
], [ ], [
"field" => "purchase_date", "field" => "purchase_date",

View file

@ -31,7 +31,7 @@ class MigrateDenormedAssetLocations extends Migration
$assigned_user_assets = Asset::where('assigned_type',User::class)->whereNotNull('assigned_to')->get(); $assigned_user_assets = Asset::where('assigned_type',User::class)->whereNotNull('assigned_to')->get();
\Log::debug('User-assigned assets:'); \Log::debug('User-assigned assets:');
foreach ($assigned_user_assets as $assigned_user_asset) { foreach ($assigned_user_assets as $assigned_user_asset) {
if ($assigned_user_asset->assignedTo->userLoc) { if (($assigned_user_asset->assignedTo) && ($assigned_user_asset->assignedTo->userLoc)) {
$new_location=$assigned_user_asset->assignedTo->userloc->id; $new_location=$assigned_user_asset->assignedTo->userloc->id;
\Log::info(' They are in '.$assigned_user_asset->assignedTo->userloc->name.' which is id: '.$new_location); \Log::info(' They are in '.$assigned_user_asset->assignedTo->userloc->name.' which is id: '.$new_location);
} else { } else {

View file

@ -38,7 +38,7 @@
@endif @endif
<!-- User --> <!-- User -->
@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to']) @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to', 'required'=> 'true'])
@if ($consumable->category->require_acceptance=='1') @if ($consumable->category->require_acceptance=='1')
<div class="form-group"> <div class="form-group">

View file

@ -21,7 +21,7 @@
<div class="box box-default"> <div class="box box-default">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"> {{ $licenseSeat->license->name }}</h3> <h3 class="box-title"> {{ $license->name }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
@ -29,7 +29,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{{ trans('admin/hardware/form.name') }}</label> <label class="col-sm-3 control-label">{{ trans('admin/hardware/form.name') }}</label>
<div class="col-md-6"> <div class="col-md-6">
<p class="form-control-static">{{ $licenseSeat->license->name }}</p> <p class="form-control-static">{{ $license->name }}</p>
</div> </div>
</div> </div>
@ -37,7 +37,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{{ trans('admin/hardware/form.serial') }}</label> <label class="col-sm-3 control-label">{{ trans('admin/hardware/form.serial') }}</label>
<div class="col-md-9"> <div class="col-md-9">
<p class="form-control-static" style="word-wrap: break-word;">{{ $licenseSeat->license->serial }}</p> <p class="form-control-static" style="word-wrap: break-word;">{{ $license->serial }}</p>
</div> </div>
</div> </div>
@ -54,7 +54,7 @@
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}"> <div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
<label for="note" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label> <label for="note" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label>
<div class="col-md-7"> <div class="col-md-7">
<textarea class="col-md-6 form-control" id="note" name="note">{{ Input::old('note', $licenseSeat->note) }}</textarea> <textarea class="col-md-6 form-control" id="note" name="note">{{ Input::old('note') }}</textarea>
{!! $errors->first('note', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!} {!! $errors->first('note', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div> </div>
</div> </div>

View file

@ -90,14 +90,14 @@
@can('checkout', $licensedto) @can('checkout', $licensedto)
@if (($licensedto->assigned_to) || ($licensedto->asset_id)) @if (($licensedto->assigned_to) || ($licensedto->asset_id))
@if ($license->reassignable) @if ($license->reassignable)
<a href="{{ route('licenses.checkin', $licensedto->id) }}" class="btn btn-primary btn-sm"> <a href="{{ route('licenses.checkin', $licensedto->id) }}" class="btn btn-sm bg-purple">
{{ trans('general.checkin') }} {{ trans('general.checkin') }}
</a> </a>
@else @else
<span>Assigned</span> <span>Assigned</span>
@endif @endif
@else @else
<a href="{{ route('licenses.checkout', $licensedto->id) }}" class="btn btn-info btn-sm"> <a href="{{ route('licenses.checkout', $license->id) }}" class="btn btn-sm bg-maroon">
{{ trans('general.checkout') }} {{ trans('general.checkout') }}
</a> </a>
@endif @endif

View file

@ -2,7 +2,7 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required"> <div class="col-md-7">
<select class="js-data-ajax" data-endpoint="departments" name="{{ $fieldname }}" style="width: 100%" id="department_select"> <select class="js-data-ajax" data-endpoint="departments" name="{{ $fieldname }}" style="width: 100%" id="department_select">
@if ($department_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : '')) @if ($department_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $department_id }}" selected="selected"> <option value="{{ $department_id }}" selected="selected">

View file

@ -2,7 +2,7 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required"> <div class="col-md-7{{ ((isset($required)) && ($required=='true')) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="users" name="{{ $fieldname }}" style="width: 100%" id="assigned_user_select"> <select class="js-data-ajax" data-endpoint="users" name="{{ $fieldname }}" style="width: 100%" id="assigned_user_select">
@if ($user_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : '')) @if ($user_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $user_id }}" selected="selected"> <option value="{{ $user_id }}" selected="selected">