Merge branch 'dmeltzer-checkout-to-things-v1' into develop

This commit is contained in:
snipe 2016-12-29 16:20:37 -08:00
commit 199fdf39ec
36 changed files with 613 additions and 461 deletions

View file

@ -68,7 +68,7 @@ class SendExpirationAlerts extends Command
$asset_data['email_content'] .= '<td>'.e($asset->present()->warrantee_expires()).'</td>';
$asset_data['email_content'] .= '<td>'.$difference.' '.trans('mail.days').'</td>';
$asset_data['email_content'] .= '<td>'.($asset->supplier ? e($asset->supplier->name) : '').'</td>';
$asset_data['email_content'] .= '<td>'.($asset->assigneduser ? e($asset->assigneduser->present()->fullName()) : '').'</td>';
$asset_data['email_content'] .= '<td>'.($asset->assignedTo ? e($asset->assignedTo->present()->name()) : '').'</td>';
$asset_data['email_content'] .= '</tr>';
}

View file

@ -339,11 +339,11 @@ class Helper
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v2.5]
* @return Array
* @return array
*/
public static function detailedAssetList()
{
$assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedUser', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray();
$assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedTo', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray();
return $assets;
}

View file

@ -104,23 +104,26 @@ class AssetsController extends Controller
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0]
* @param integer $model_id
* @param Request $request
* @return View
* @internal param int $model_id
*/
public function create(Request $request)
{
$this->authorize('create', Asset::class);
$view = View::make('hardware/edit');
$view->with('supplier_list', Helper::suppliersList());
$view->with('company_list', Helper::companyList());
$view->with('model_list', Helper::modelList());
$view->with('statuslabel_list', Helper::statusLabelList());
$view->with('assigned_to', Helper::usersList());
$view->with('location_list', Helper::locationsList());
$view->with('item', new Asset);
$view->with('manufacturer', Helper::manufacturerList());
$view->with('category', Helper::categoryList('asset'));
$view->with('statuslabel_types', Helper::statusTypeList());
$view = View::make('hardware/edit')
->with('supplier_list', Helper::suppliersList())
->with('company_list', Helper::companyList())
->with('model_list', Helper::modelList())
->with('statuslabel_list', Helper::statusLabelList())
->with('location_list', Helper::locationsList())
->with('item', new Asset)
->with('manufacturer', Helper::manufacturerList())
->with('category', Helper::categoryList('asset'))
->with('statuslabel_types', Helper::statusTypeList())
->with('users_list', Helper::usersList())
->with('assets_list', Helper::assetsList())
->with('locations_list', Helper::locationsList());
if ($request->has('model_id')) {
$selected_model = AssetModel::find($request->input('model_id'));
@ -217,9 +220,15 @@ class AssetsController extends Controller
// Was the asset created?
if ($asset->save()) {
$asset->logCreate();
if (Input::get('assigned_to')!='') {
$user = User::find(e(Input::get('assigned_to')));
$asset->checkOutToUser($user, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name')));
if(request('assigned_user')) {
$target = User::find(request('assigned_user'));
} elseif(request('assigned_asset')) {
$target = Asset::find(request('assigned_asset'));
} elseif(request('assigned_location')) {
$target = Location::find(request('assigned_location'));
}
if ($target) {
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name')));
}
// Redirect to the asset listing page
\Session::flash('success', trans('admin/hardware/message.create.success'));
@ -416,7 +425,10 @@ class AssetsController extends Controller
$this->authorize('checkout', $asset);
// Get the dropdown of users and then pass it to the checkout view
return View::make('hardware/checkout', compact('asset'))->with('users_list', Helper::usersList());
return View::make('hardware/checkout', compact('asset'))
->with('users_list', Helper::usersList())
->with('assets_list', Helper::assetsList())
->with('locations_list', Helper::locationsList());
}
@ -431,7 +443,6 @@ class AssetsController extends Controller
*/
public function postCheckout(AssetCheckoutRequest $request, $assetId)
{
// Check if the asset exists
if (!$asset = Asset::find($assetId)) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
@ -440,7 +451,14 @@ class AssetsController extends Controller
}
$this->authorize('checkout', $asset);
$user = User::find(Input::get('assigned_to'));
if(request('assigned_user')) {
$target = User::find(request('assigned_user'));
} elseif(request('assigned_asset')) {
$target = Asset::find(request('assigned_asset'));
} elseif(request('assigned_location')) {
$target = Location::find(request('assigned_location'));
}
// $user = User::find(Input::get('assigned_to'));
$admin = Auth::user();
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
@ -454,7 +472,7 @@ class AssetsController extends Controller
} else {
$expected_checkin = '';
}
if ($asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), e(Input::get('name')))) {
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), e(Input::get('name')))) {
// Redirect to the new asset page
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
}
@ -509,7 +527,7 @@ class AssetsController extends Controller
$admin = Auth::user();
if (is_null($user = User::find($asset->assigned_to))) {
if (is_null($target = $asset->assignedTo)) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in'));
}
@ -518,19 +536,19 @@ class AssetsController extends Controller
$asset->expected_checkin = null;
$asset->last_checkout = null;
$asset->assigned_to = null;
$asset->assignedTo()->disassociate($asset);
$asset->accepted = null;
$asset->name = e(Input::get('name'));
if (Input::has('status_id')) {
$asset->status_id = e(Input::get('status_id'));
}
// Was the asset updated?
if ($asset->save()) {
$logaction = $asset->logCheckin($user, e(request('note')));
$logaction = $asset->logCheckin($target, e(request('note')));
$data['log_id'] = $logaction->id;
$data['first_name'] = $user->first_name;
$data['first_name'] = get_class($target) == User::class ? $target->first_name : '';
$data['item_name'] = $asset->present()->name();
$data['checkin_date'] = $logaction->created_at;
$data['item_tag'] = $asset->asset_tag;
@ -1155,9 +1173,9 @@ class AssetsController extends Controller
Setting::getSettings()
);
} elseif (Input::get('bulk_actions')=='delete') {
$assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids);
$assets->each(function ($asset) {
$this->authorize('delete', $asset);
$assets = Asset::with('assignedTo', 'assetloc')->find($asset_ids);
$assets->each(function($asset) {
$this->authorize('delete',$asset);
});
return View::make('hardware/bulk-delete')->with('assets', $assets);
// Bulk edit
@ -1309,9 +1327,10 @@ class AssetsController extends Controller
*/
public function getDatatable(Request $request, $status = null)
{
$this->authorize('index', Asset::class);
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company')
->Hardware();
$this->authorize('index', 'App\Models\Asset');
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with(
'assetLoc', 'assetstatus', 'defaultLoc', 'assetlog', 'company',
'model.category', 'model.manufacturer', 'model.fieldset');
if ($request->has('search')) {
$assets = $assets->TextSearch(e($request->get('search')));
@ -1417,9 +1436,7 @@ class AssetsController extends Controller
$rows = array();
foreach ($assets as $asset) {
$row = $asset->present()->forDataTable($all_custom_fields);
if (($request->has('report')) && ($request->get('report')=='true')) {
$rows[]= Helper::stripTagsFromJSON($row);
} else {

View file

@ -247,7 +247,7 @@ class CategoriesController extends Controller
public function getDataViewAssets(Request $request, $categoryID)
{
$category = Category::find($categoryID);
$category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assigneduser');
$category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assignedTo');
$category_assets = $category->assets();
if (Input::has('search')) {
$category_assets = $category_assets->TextSearch(e($request->input('search')));

View file

@ -246,7 +246,7 @@ class ManufacturersController extends Controller
protected function getDataAssetsView(Manufacturer $manufacturer, Request $request)
{
$manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company');
$manufacturer = $manufacturer->load('assets.model', 'assets.assignedTo', 'assets.assetstatus', 'assets.company');
$manufacturer_assets = $manufacturer->assets();
if ($request->has('search')) {

View file

@ -121,7 +121,7 @@ class ReportsController extends Controller
// Open output stream
$handle = fopen('php://output', 'w');
Asset::with('assigneduser', 'assetloc', 'defaultLoc', 'assigneduser.userloc', 'model', 'supplier', 'assetstatus', 'model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function ($assets) use ($handle, $customfields) {
Asset::with('assignedTo', 'assetLoc','defaultLoc','assignedTo','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) {
$headers=[
trans('general.company'),
trans('admin/hardware/table.asset_tag'),
@ -160,10 +160,9 @@ class ReportsController extends Controller
($asset->purchase_cost > 0) ? Helper::formatCurrencyOutput($asset->purchase_cost) : '',
($asset->order_number) ? e($asset->order_number) : '',
($asset->supplier) ? e($asset->supplier->name) : '',
($asset->assigneduser) ? e($asset->assigneduser->present()->fullName()) : '',
($asset->assignedTo) ? e($asset->assignedTo->present()->name()) : '',
($asset->last_checkout!='') ? e($asset->last_checkout) : '',
($asset->assigneduser && $asset->assigneduser->userloc!='') ?
e($asset->assigneduser->userloc->name) : ( ($asset->defaultLoc!='') ? e($asset->defaultLoc->name) : ''),
e($asset->assetLoc->present()->name()),
($asset->notes) ? e($asset->notes) : '',
];
foreach ($customfields as $field) {
@ -195,7 +194,7 @@ class ReportsController extends Controller
{
// Grab all the assets
$assets = Asset::with('model', 'assigneduser', 'assetstatus', 'defaultLoc', 'assetlog', 'company')
$assets = Asset::with('model', 'assignedTo', 'assetstatus', 'defaultLoc', 'assetlog', 'company')
->orderBy('created_at', 'DESC')->get();
return View::make('reports/depreciation', compact('assets'));
@ -213,7 +212,7 @@ class ReportsController extends Controller
{
// Grab all the assets
$assets = Asset::with('model', 'assigneduser', 'assetstatus', 'defaultLoc', 'assetlog')
$assets = Asset::with('model', 'assignedTo', 'assetstatus', 'defaultLoc', 'assetlog')
->orderBy('created_at', 'DESC')->get();
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
@ -244,15 +243,13 @@ class ReportsController extends Controller
$row[] = e($asset->name);
$row[] = e($asset->serial);
if ($asset->assigned_to > 0) {
$user = User::find($asset->assigned_to);
$row[] = e($user->present()->fullName());
if ($target = $asset->assignedTo) {
$row[] = e($target->present()->name());
} else {
$row[] = ''; // Empty string if unassigned
}
if (( $asset->assigned_to > 0 ) && ( $asset->assigneduser->location_id > 0 )) {
$location = Location::find($asset->assigneduser->location_id);
if (( $asset->assigned_to > 0 ) && ( $location = $asset->assetLoc )) {
if ($location->city) {
$row[] = e($location->city) . ', ' . e($location->state);
} elseif ($location->name) {
@ -365,8 +362,7 @@ class ReportsController extends Controller
$activity_target = '';
}
} elseif (($activity->action_type=='accepted') || ($activity->action_type=='declined')) {
$activity_target = '<a href="' . route('users.show', $activity->item->assigneduser->id) . '">' . e($activity->item->assigneduser->present()->fullName()) . '</a>';
$activity_target = $activity->item->assignedTo->nameUrl();
} elseif ($activity->action_type=='requested') {
if ($activity->user) {
$activity_target = '<a href="'.route('users.show', $activity->user_id).'">'.$activity->user->present()->fullName().'</a>';
@ -631,34 +627,25 @@ class ReportsController extends Controller
}
if (e(Input::get('location')) == '1') {
$show_loc = '';
if (($asset->assigned_to > 0) && ($asset->assigneduser) && ($asset->assigneduser->location)) {
$show_loc .= '"' .e($asset->assigneduser->location->name). '"';
} elseif ($asset->rtd_location_id!='') {
$location = Location::find($asset->rtd_location_id);
if ($location) {
$show_loc .= '"' .e($location->name). '"';
} else {
$show_loc .= 'Default location '.$asset->rtd_location_id.' is invalid';
}
if($asset->assetLoc) {
$show_loc = $asset->assetLoc->present()->name();
} else {
$show_loc = 'Default location '.$asset->rtd_location_id.' is invalid';
}
$row[] = $show_loc;
}
if (e(Input::get('assigned_to')) == '1') {
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->present()->fullName()). '"';
if ($asset->assignedTo) {
$row[] = '"' .e($asset->assignedTo->present()->name()). '"';
} else {
$row[] = ''; // Empty string if unassigned
}
}
if (e(Input::get('username')) == '1') {
// Only works if we're checked out to a user, not anything else.
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->username). '"';
} else {
@ -667,6 +654,7 @@ class ReportsController extends Controller
}
if (e(Input::get('employee_num')) == '1') {
// Only works if we're checked out to a user, not anything else.
if ($asset->assigneduser) {
$row[] = '"' .e($asset->assigneduser->employee_num). '"';
} else {
@ -859,7 +847,7 @@ class ReportsController extends Controller
$row[] = str_replace(',', '', e($assetItem->assetlog->model->name));
$row[] = str_replace(',', '', e($assetItem->assetlog->present()->name()));
$row[] = str_replace(',', '', e($assetItem->assetlog->asset_tag));
$row[] = str_replace(',', '', e($assetItem->assetlog->assigneduser->present()->fullName()));
$row[] = str_replace(',', '', e($assetItem->assetlog->assignedTo->present()->name()));
$rows[] = implode($row, ',');
}

View file

@ -365,9 +365,9 @@ class UsersController extends Controller
// Authorize takes care of many of our logic checks now.
$this->authorize('delete', User::class);
if ($user->assets()->count() > 0) {
if ($user->assignedAssets()->count() > 0) {
// Redirect to the user management page
return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.');
return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assignedAssets()->count() . ' assets associated with them.');
}
if ($user->licenses()->count() > 0) {
@ -551,7 +551,7 @@ class UsersController extends Controller
*/
public function show($userId = null)
{
if (!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
if(!$user = User::with('assignedAssets', 'assignedAssets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) {
$error = trans('admin/users/message.user_not_found', compact('id'));
// Redirect to the user management page
return redirect()->route('users.index')->with('error', $error);
@ -1133,7 +1133,7 @@ class UsersController extends Controller
// Open output stream
$handle = fopen('php://output', 'w');
User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company', 'throttle')->orderBy('created_at', 'DESC')->chunk(500, function ($users) use ($handle) {
User::with('assignedAssets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')->orderBy('created_at', 'DESC')->chunk(500, function($users) use($handle) {
$headers=[
// strtolower to prevent Excel from trying to open it as a SYLK file
strtolower(trans('general.id')),
@ -1175,7 +1175,7 @@ class UsersController extends Controller
$user->email,
($user->manager) ? $user->manager->present()->fullName() : '',
($user->userloc) ? $user->userloc->name : '',
$user->assets->count(),
$user->assignedAssets->count(),
$user->licenses->count(),
$user->accessories->count(),
$user->consumables->count(),

View file

@ -41,8 +41,7 @@ class ViewAssetsController extends Controller
{
$user = User::with(
'assets',
'assets.model',
'assignedAssets.model',
'consumables',
'accessories',
'licenses',
@ -69,7 +68,7 @@ class ViewAssetsController extends Controller
public function getRequestableIndex()
{
$assets = Asset::with('model', 'defaultLoc', 'assetloc', 'assigneduser')->Hardware()->RequestableAssets()->get();
$assets = Asset::with('model', 'defaultLoc', 'assetloc', 'assignedTo')->Hardware()->RequestableAssets()->get();
$models = AssetModel::with('category')->RequestableModels()->get();
return View::make('account/requestable-assets', compact('user', 'assets', 'models'));

View file

@ -24,7 +24,9 @@ class AssetCheckoutRequest extends Request
public function rules()
{
return [
"assigned_to" => 'required',
"assigned_user" => 'required_without_all:assigned_asset,assigned_location',
"assigned_asset" => 'required_without_all:assigned_user,assigned_location',
"assigned_location" => 'required_without_all:assigned_user,assigned_asset',
];
}
}

View file

@ -26,19 +26,21 @@ class AssetRequest extends Request
public function rules()
{
$rules = [
'name' => 'min:2|max:255',
'model_id' => 'required|integer',
'status_id' => 'required|integer',
'company_id' => 'integer|nullable',
'warranty_months' => 'numeric|nullable',
'physical' => 'integer|nullable',
'checkout_date' => 'date',
'checkin_date' => 'date',
'supplier_id' => 'integer|nullable',
'status' => 'integer|nullable',
'asset_tag' => 'required',
'purchase_cost' => 'numeric|nullable',
'name' => 'min:2|max:255',
'model_id' => 'required|integer',
'status_id' => 'required|integer',
'company_id' => 'integer|nullable',
'warranty_months' => 'numeric|nullable',
'physical' => 'integer|nullable',
'checkout_date' => 'date',
'checkin_date' => 'date',
'supplier_id' => 'integer|nullable',
'status' => 'integer|nullable',
'asset_tag' => 'required',
'purchase_cost' => 'numeric|nullable',
"assigned_user" => 'required_without_all:assigned_asset,assigned_location',
"assigned_asset" => 'required_without_all:assigned_user,assigned_location',
"assigned_location" => 'required_without_all:assigned_user,assigned_asset',
];
$model = AssetModel::find($this->request->get('model_id'));

View file

@ -22,6 +22,9 @@ class Asset extends Depreciable
use Loggable, Requestable, Presentable;
use SoftDeletes;
const LOCATION = 'location';
const ASSET = 'asset';
const USER = 'user';
/**
* The database table used by the model.
*
@ -91,9 +94,9 @@ class Asset extends Depreciable
* @param null $name
* @return bool
*/
public function checkOutToUser($user, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null)
public function checkOut($target, $admin, $checkout_at = null, $expected_checkin = null, $note = null, $name = null)
{
if (!$user) {
if (!$target) {
return false;
}
@ -103,7 +106,8 @@ class Asset extends Depreciable
$this->last_checkout = $checkout_at;
$this->assigneduser()->associate($user);
$this->assignedTo()->associate($target);
if ($name != null) {
$this->name = $name;
@ -113,13 +117,11 @@ class Asset extends Depreciable
$this->accepted="pending";
}
if ($this->save()) {
$log = $this->logCheckout($note);
if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
$this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
}
// if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) {
// $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note);
// }
return true;
}
return false;
@ -150,11 +152,10 @@ class Asset extends Depreciable
}
public function getDetailedNameAttribute()
{
if ($this->assignedUser) {
$user_name = $this->assignedUser->present()->fullName();
if ($this->assignedTo) {
$user_name = $this->assignedTo->present()->name();
} else {
$user_name = "Unassigned";
}
@ -203,24 +204,50 @@ class Asset extends Depreciable
->orderBy('created_at', 'desc');
}
/**
* Even though we allow allow for checkout to things beyond users
* this method is an easy way of seeing if we are checked out to a user.
* @return mixed
*/
public function assigneduser()
{
return $this->belongsTo('\App\Models\User', 'assigned_to')
->withTrashed();
}
public function assignedTo()
{
return $this->morphTo('assigned', 'assigned_type', 'assigned_to');
}
public function assignedAssets()
{
return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
}
/**
* Get the asset's location based on the assigned user
**/
public function assetloc()
public function assetLoc()
{
if ($this->assigneduser) {
return $this->assigneduser->userloc();
} else {
return $this->belongsTo('\App\Models\Location', 'rtd_location_id');
if(!empty($this->assignedType())) {
if ($this->assignedType() == self::ASSET) {
return $this->assignedTo->assetloc(); // Recurse until we have a final location
} elseif ($this->assignedType() == self::LOCATION) {
return $this->assignedTo();
}
// Default to User
// var_dump($this);
return $this->assignedTo->userLoc();
}
return $this->defaultLoc();
}
public function assignedType()
{
return strtolower(class_basename($this->assigned_type));
}
/**
* Get the asset's location based on default RTD location
**/

View file

@ -39,10 +39,8 @@ class CheckoutRequest extends Model
{
if ($this->itemType() == "asset") {
$asset = $this->itemRequested();
if ($asset->assigneduser && $asset->assetloc) {
if ($asset->assignedTo) {
return $asset->assetloc;
} elseif ($asset->defaultLoc) {
return $asset->defaultLoc;
}
}
return $this->itemRequested()->location;

View file

@ -55,9 +55,9 @@ class Location extends SnipeModel
return $this->hasManyThrough('\App\Models\Asset', '\App\Models\User', 'location_id', 'assigned_to', 'id');
}
public function assignedassets()
public function locationAssets()
{
return $this->hasMany('\App\Models\Asset', 'rtd_location_id');
return $this->hasMany('\App\Models\Asset', 'rtd_location_id')->orHas('assignedAssets');
}
public function parent()
@ -70,6 +70,12 @@ class Location extends SnipeModel
return $this->hasMany('\App\Models\Location', 'parent_id');
}
public function assignedAssets()
{
return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
// return $this->hasMany('\App\Models\Asset', 'assigned_to')->withTrashed();
}
public static function getLocationHierarchy($locations, $parent_id = null)
{

View file

@ -44,6 +44,7 @@ trait Loggable
$log->user_id = Auth::user()->id;
// @FIXME This needs to be generalized with new asset checkout.
if (!is_null($this->asset_id) || isset($target)) {
$log->target_type = Asset::class;
$log->target_id = $this->asset_id;
@ -53,7 +54,18 @@ trait Loggable
}
$item = call_user_func(array($log->target_type, 'find'), $log->target_id);
$log->location_id = $item->location_id;
if($this->assignedTo) {
$item = $this->assignedTo;
}
$class = get_class($item);
if($class == Location::class) {
// We can checkout to a location
$log->location_id = $item->id;
} else if ($class== Asset::class) {
$log->location_id = $item->rtd_location_id;
} else {
$log->location_id = $item->location_id;
}
$log->note = $note;
$log->logaction('checkout');

View file

@ -127,9 +127,10 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
/**
* Get assets assigned to this user
*/
public function assets()
public function assignedAssets()
{
return $this->hasMany('\App\Models\Asset', 'assigned_to')->withTrashed();
return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
// return $this->hasMany('\App\Models\Asset', 'assigned_to')->withTrashed();
}
/**

View file

@ -83,14 +83,14 @@ class AssetPresenter extends Presenter
$results['status_label'] = '';
$results['assigned_to'] = '';
if ($assigned = $this->model->assigneduser) {
if($assigned = $this->model->assignedTo) {
$results['status_label'] = 'Deployed';
$results['assigned_to'] = (string) link_to_route('users.show', $assigned->present()->fullName(), $this->assigned_to);
} elseif ($this->model->assetstatus) {
$results['assigned_to'] = $assigned->present()->nameUrl();
} else if($this->model->assetstatus) {
$results['status_label'] = $this->model->assetstatus->name;
}
$results['location'] = '';
if (isset($assigned) and !empty($assignedLoc = $assigned->userloc)) {
if (isset($assigned) and !empty($assignedLoc = $this->model->assetLoc)) {
$results['location'] = $assignedLoc->present()->nameUrl();
} elseif (!empty($this->model->defaultLoc)) {
$results['location'] = $this->model->defaultLoc->present()->nameUrl();

View file

@ -55,6 +55,15 @@ class LocationPresenter extends Presenter
return (string)link_to_route('locations.show', $this->name, $this->id);
}
/**
* Getter for Polymorphism.
* @return mixed
*/
public function name()
{
return $this->model->name;
}
/**
* Url to view this item.
* @return string

View file

@ -71,7 +71,7 @@ class UserPresenter extends Presenter
'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '',
'manager' => ($this->model->manager) ? $this->manager->present()->nameUrl() : '',
'employee_num' => $this->employee_num,
'assets' => $this->model->assets()->count(),
'assets' => $this->model->assignedAssets()->count(),
'licenses' => $this->model->licenses()->count(),
'accessories' => $this->model->accessories()->count(),
'consumables' => $this->model->consumables()->count(),
@ -108,6 +108,15 @@ class UserPresenter extends Presenter
return "{$this->first_name} {$this->last_name}";
}
/**
* Standard accessor.
* @TODO Remove presenter::fullName() entirely?
* @return string
*/
public function name()
{
return $this->fullName();
}
/**
* Returns the user Gravatar image url.
*

View file

@ -0,0 +1,39 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Models\Asset;
use App\Models\User;
class MakeAssetAssignedToPolymorphic extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('assets', function (Blueprint $table) {
//
$table->string('assigned_type')->nullable();
});
// Prior to this migration, asset's could only be assigned to users.
Asset::whereNotNull('assigned_to')->orWhere('assigned_to', '')->update(['assigned_type' => User::class]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('assets', function (Blueprint $table) {
//
$table->dropColumn('assigned_type');
});
}
}

View file

@ -60,11 +60,7 @@
<td>{{ $asset->serial }}</td>
<td>
@if ($asset->assigneduser && $asset->assetloc)
{{ $asset->assetloc->name }}
@elseif ($asset->defaultLoc)
{{ $asset->defaultLoc->name }}
@endif
</td>
@if ($asset->assigned_to != '' && $asset->assigned_to > 0)
<td>Checked out</td>

View file

@ -23,7 +23,7 @@ View Assets for {{ $user->present()->fullName() }}
<div class="box-body">
<!-- checked out assets table -->
@if (count($user->assets) > 0)
@if (count($user->assignedAssets) > 0)
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -35,7 +35,7 @@ View Assets for {{ $user->present()->fullName() }}
</tr>
</thead>
<tbody>
@foreach ($user->assets as $asset)
@foreach ($user->assignedAssets as $asset)
<tr>
<td>
@if ($asset->physical=='1')

View file

@ -47,8 +47,8 @@
@endif
</td>
<td>
@if ($asset->assigneduser)
{{ $asset->assigneduser->present()->fullName() }} ({{ $asset->assigneduser->username }})
@if ($asset->assignedTo)
{{ $asset->assignedTo->present()->name().' ' .$asset->assigneduser ? '('.$asset->assigneduser->username. ')' : ''}}
@endif
</td>
</tr>

View file

@ -47,14 +47,40 @@
<!-- User -->
<div id="assigned_user" class="form-group{{ $errors->has('assigned_to') ? ' has-error' : '' }}">
{{ Form::label('assigned_to', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
{{ Form::label('assigned_user', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required">
{{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $asset->assigned_to), array('class'=>'select2', 'id'=>'assigned_to', 'style'=>'width:100%')) }}
{{ Form::select('assigned_user', $users_list , Input::old('assigned_user', $asset->assigned_type == 'App\Models\User' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_user', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
{!! $errors->first('assigned_user', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_to' class="btn btn-sm btn-default">New</a>
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Assets -->
<div id="assigned_asset" class="form-group{{ $errors->has('assigned_to') ? ' has-error' : '' }}">
{{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required">
{{ Form::select('assigned_asset', $assets_list , Input::old('assigned_asset', $asset->assigned_type == 'App\Models\Asset' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_asset', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_asset', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_asset' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Locations -->
<div id="assigned_location" class="form-group{{ $errors->has('assigned_to') ? ' has-error' : '' }}">
{{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required">
{{ Form::select('assigned_location', $locations_list , Input::old('assigned_location', $asset->assigned_type == 'App\Models\Asset' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_location', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_location', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_location' class="btn btn-sm btn-default">New</a>
</div>
</div>

View file

@ -64,17 +64,41 @@
@if (!$item->id)
<!-- Assigned To -->
<div id="assigned_user" style="display: none;" class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}">
<div id="assigned_user" style="display: none;" class="form-group {{ $errors->has('assigned_user') ? ' has-error' : '' }}">
<label for="parent" class="col-md-3 control-label">
{{ trans('admin/hardware/form.checkout_to') }}
</label>
<div class="col-md-7 col-sm-12">
{{ Form::select('assigned_to', $assigned_to , Input::old('assigned_to', $item->assigned_to), array('class'=>'select2', 'id'=>'assigned_to', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
{{ Form::select('assigned_user', $users_list , Input::old('assigned_user', $item->assigned_type == 'App\Models\User' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_user', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_user', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left" style="margin-left: -20px; padding-top: 3px">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_to' class="btn btn-sm btn-default">New</a>
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Assets -->
<div id="assigned_asset" style="display: none;" class="form-group{{ $errors->has('assigned_asset') ? ' has-error' : '' }}">
{{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7">
{{ Form::select('assigned_asset', $assets_list , Input::old('assigned_asset', $item->assigned_type == 'App\Models\Asset' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_asset', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_asset', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_asset' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Locations -->
<div id="assigned_location" style="display: none;" class="form-group{{ $errors->has('assigned_location') ? ' has-error' : '' }}">
{{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7">
{{ Form::select('assigned_location', $locations_list , Input::old('assigned_location', $item->assigned_type == 'App\Models\Asset' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_location', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_location', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_location' class="btn btn-sm btn-default">New</a>
</div>
</div>
@endif
@ -136,281 +160,284 @@
<script>
function fetchCustomFields() {
var modelid=$('#model_select_id').val();
if(modelid=='') {
$('#custom_fields_content').html("");
} else {
$.get("{{url('/') }}/models/"+modelid+"/custom_fields",{_token: "{{ csrf_token() }}"},function (data) {
$('#custom_fields_content').html(data);
});
}
var modelid = $('#model_select_id').val();
if (modelid == '') {
$('#custom_fields_content').html("");
} else {
$.get("{{url('/') }}/models/" + modelid + "/custom_fields", {_token: "{{ csrf_token() }}"}, function (data) {
$('#custom_fields_content').html(data);
});
}
}
$(function() {
$('#model_select_id').on("change",fetchCustomFields);
$(function () {
$('#model_select_id').on("change", fetchCustomFields);
});
$(function() {
$(function () {
user_add($(".status_id option:selected").val());
});
var $statusSelect = $(".status_id");
$statusSelect.on("change", function () {
var $statusSelect = $(".status_id");
$statusSelect.on("change", function () {
user_add($statusSelect.val());
});
function user_add(status_id) {
function user_add(status_id) {
if(status_id!=''){
if (status_id != '') {
$(".status_spinner").css("display", "inline");
$.ajax({
url: "{{url('/') }}/api/v1/statuslabels/"+status_id+"/deployable",
success: function(data) {
$.ajax({
url: "{{url('/') }}/api/v1/statuslabels/" + status_id + "/deployable",
success: function (data) {
$(".status_spinner").css("display", "none");
if(data == true){
$("#assigned_user").css("display", "block");
} else {
$("#assigned_user").css("display", "none");
}
}
});
}
};
$(function () {
var model,select;
$('#createModal').on("show.bs.modal",function (event) {
var link = $(event.relatedTarget);
model=link.data("dependency");
select=link.data("select");
var modal = $(this);
modal.find('.modal-title').text('Add a new ' + model);
$('.dynamic-form-row').hide();
function show_er(selector) {
//$(selector).show().parent().show();
$(selector).parent().parent().show();
}
show_er('#modal-name');
switch(model) {
case 'model':
show_er('#modal-manufacturer_id');
show_er('#modal-category_id');
show_er('#modal-modelno');
show_er('#modal-fieldset_id');
break;
case 'user':
$('.dynamic-form-row').hide(); //we don't want a generic "name"
show_er("#modal-first_name");
show_er("#modal-last_name");
show_er("#modal-username");
show_er("#modal-password");
show_er("#modal-password_confirm");
break;
case 'location':
show_er('#modal-city');
show_er('#modal-country');
break;
case 'statuslabel':
show_er("#modal-statuslabel_types");
break;
case 'supplier':
//do nothing, they just need 'name'
}
//console.warn("The Model is: "+model+" and the select is: "+select);
});
$("form").submit( function(event) {
event.preventDefault();
return sendForm();
});
// Resize Files when chosen
//First check to see if there is a file before doing anything else
var imageData = "";
var $fileInput = $('#file-upload');
$fileInput.on('change', function(e) {
if( $fileInput != '' ) {
if(window.File && window.FileReader && window.FormData) {
var file = e.target.files[0];
if(file) {
if(/^image\//i.test(file.type)) {
readFile(file);
} else {
alert('Invalid Image File :(');
}
}
}
else {
console.log("File API not supported, not resizing");
}
}
});
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function() {
processFile(reader.result, file.type);
}
reader.onerror = function() {
alert("Unable to read file");
}
reader.readAsDataURL(file);
}
function processFile(dataURL, fileType) {
var maxWidth = 800;
var maxHeight = 800;
var image = new Image();
image.src = dataURL;
image.onload = function() {
var width = image.width;
var height = image.height;
var shouldResize = (width > maxWidth) || (height > maxHeight);
if(!shouldResize) {
imageData = dataURL;
return;
}
var newWidth;
var newHeight;
if( width > height) {
newHeight = height * (maxWidth/width);
newWidth = maxWidth;
} else {
newWidth = width * (maxHeight/height);
newHeight = maxHeight;
}
var canvas = document.createElement('canvas');
canvas.width = newWidth;
canvas.height = newHeight;
var context = canvas.getContext('2d');
context.drawImage(this, 0, 0, newWidth, newHeight);
dataURL = canvas.toDataURL( fileType );
imageData = dataURL;
};
image.onerror = function () {
alert('Unable to process file :(');
}
}
function sendForm() {
var form = $("#create-form").get(0);
var formData = $('#create-form').serializeArray();
formData.push({name:'image', value:imageData});
$.ajax({
type: 'POST',
url: form.action,
headers:{"X-Requested-With": 'XMLHttpRequest'},
data: formData,
dataType: 'json',
success: function(data) {
// AssetController flashes success to session, redirect to hardware page.
window.location.href = data.redirect_url;
// console.dir(data);
// console.log('submit was successful');
},
error: function(data) {
// AssetRequest Validator will flash all errors to session, this just refreshes to see them.
window.location.reload(true);
// console.log(JSON.stringify(data));
// console.log('error submitting');
}
});
return false;
}
$('#modal-save').on('click',function () {
var data={};
//console.warn("We are about to SAVE!!! for model: "+model+" and select ID: "+select);
$('.modal-body input:visible').each(function (index,elem) {
//console.warn("["+index+"]: "+elem.id+" = "+$(elem).val());
var bits=elem.id.split("-");
if(bits[0]==="modal") {
data[bits[1]]=$(elem).val();
}
});
$('.modal-body select:visible').each(function (index,elem) {
var bits=elem.id.split("-");
data[bits[1]]=$(elem).val();
});
data._token = '{{ csrf_token() }}',
//console.dir(data);
$.post("{{url('/') }}/api/v1/"+model+"s",data,function (result) {
var id=result.id;
var name=result.name || (result.first_name+" "+result.last_name);
$('.modal-body input:visible').val("");
$('#createModal').modal('hide');
//console.warn("The select ID thing we're going for is: "+select);
var selector=document.getElementById(select);
selector.options[selector.length]=new Option(name,id);
selector.selectedIndex=selector.length-1;
$(selector).trigger("change");
fetchCustomFields();
}).fail(function (result) {
//console.dir(result.responseJSON);
msg=result.responseJSON.error.message || result.responseJSON.error;
window.alert("Unable to add new "+model+" - error: "+msg);
});
});
});
</script>
<script src="{{ asset('assets/js/pGenerator.jquery.js') }}"></script>
<script>
$(document).ready(function(){
$('#genPassword').pGenerator({
'bind': 'click',
'passwordElement': '#modal-password',
'displayElement': '#generated-password',
'passwordLength': 16,
'uppercase': true,
'lowercase': true,
'numbers': true,
'specialChars': true,
'onPasswordGenerated': function(generatedPassword) {
$('#modal-password_confirm').val($('#modal-password').val());
if (data == true) {
$("#assigned_user").css("display", "block");
$("#assigned_location").css("display", "block");
$("#assigned_asset").css("display", "block");
} else {
$("#assigned_user").css("display", "none");
$("#assigned_location").css("display", "none");
$("#assigned_asset").css("display", "none");
}
}
});
}
}
;
$(function () {
var model, select;
$('#createModal').on("show.bs.modal", function (event) {
var link = $(event.relatedTarget);
model = link.data("dependency");
select = link.data("select");
var modal = $(this);
modal.find('.modal-title').text('Add a new ' + model);
$('.dynamic-form-row').hide();
function show_er(selector) {
//$(selector).show().parent().show();
$(selector).parent().parent().show();
}
show_er('#modal-name');
switch (model) {
case 'model':
show_er('#modal-manufacturer_id');
show_er('#modal-category_id');
show_er('#modal-modelno');
show_er('#modal-fieldset_id');
break;
case 'user':
$('.dynamic-form-row').hide(); //we don't want a generic "name"
show_er("#modal-first_name");
show_er("#modal-last_name");
show_er("#modal-username");
show_er("#modal-password");
show_er("#modal-password_confirm");
break;
case 'location':
show_er('#modal-city');
show_er('#modal-country');
break;
case 'statuslabel':
show_er("#modal-statuslabel_types");
break;
case 'supplier':
//do nothing, they just need 'name'
}
//console.warn("The Model is: "+model+" and the select is: "+select);
});
</script>
$("form").submit(function (event) {
event.preventDefault();
return sendForm();
});
// Resize Files when chosen
//First check to see if there is a file before doing anything else
var imageData = "";
var $fileInput = $('#file-upload');
$fileInput.on('change', function (e) {
if ($fileInput != '') {
if (window.File && window.FileReader && window.FormData) {
var file = e.target.files[0];
if (file) {
if (/^image\//i.test(file.type)) {
readFile(file);
} else {
alert('Invalid Image File :(');
}
}
}
else {
console.log("File API not supported, not resizing");
}
}
});
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function () {
processFile(reader.result, file.type);
}
reader.onerror = function () {
alert("Unable to read file");
}
reader.readAsDataURL(file);
}
function processFile(dataURL, fileType) {
var maxWidth = 800;
var maxHeight = 800;
var image = new Image();
image.src = dataURL;
image.onload = function () {
var width = image.width;
var height = image.height;
var shouldResize = (width > maxWidth) || (height > maxHeight);
if (!shouldResize) {
imageData = dataURL;
return;
}
var newWidth;
var newHeight;
if (width > height) {
newHeight = height * (maxWidth / width);
newWidth = maxWidth;
} else {
newWidth = width * (maxHeight / height);
newHeight = maxHeight;
}
var canvas = document.createElement('canvas');
canvas.width = newWidth;
canvas.height = newHeight;
var context = canvas.getContext('2d');
context.drawImage(this, 0, 0, newWidth, newHeight);
dataURL = canvas.toDataURL(fileType);
imageData = dataURL;
};
image.onerror = function () {
alert('Unable to process file :(');
}
}
function sendForm() {
var form = $("#create-form").get(0);
var formData = $('#create-form').serializeArray();
formData.push({name: 'image', value: imageData});
$.ajax({
type: 'POST',
url: form.action,
headers: {"X-Requested-With": 'XMLHttpRequest'},
data: formData,
dataType: 'json',
success: function (data) {
// AssetController flashes success to session, redirect to hardware page.
window.location.href = data.redirect_url;
// console.dir(data);
// console.log('submit was successful');
},
error: function (data) {
// AssetRequest Validator will flash all errors to session, this just refreshes to see them.
window.location.reload(true);
// console.log(JSON.stringify(data));
// console.log('error submitting');
}
});
return false;
}
$('#modal-save').on('click', function () {
var data = {};
//console.warn("We are about to SAVE!!! for model: "+model+" and select ID: "+select);
$('.modal-body input:visible').each(function (index, elem) {
//console.warn("["+index+"]: "+elem.id+" = "+$(elem).val());
var bits = elem.id.split("-");
if (bits[0] === "modal") {
data[bits[1]] = $(elem).val();
}
});
$('.modal-body select:visible').each(function (index, elem) {
var bits = elem.id.split("-");
data[bits[1]] = $(elem).val();
});
data._token = '{{ csrf_token() }}',
//console.dir(data);
$.post("{{url('/') }}/api/v1/" + model + "s", data, function (result) {
var id = result.id;
var name = result.name || (result.first_name + " " + result.last_name);
$('.modal-body input:visible').val("");
$('#createModal').modal('hide');
//console.warn("The select ID thing we're going for is: "+select);
var selector = document.getElementById(select);
selector.options[selector.length] = new Option(name, id);
selector.selectedIndex = selector.length - 1;
$(selector).trigger("change");
fetchCustomFields();
}).fail(function (result) {
//console.dir(result.responseJSON);
msg = result.responseJSON.error.message || result.responseJSON.error;
window.alert("Unable to add new " + model + " - error: " + msg);
});
});
});
</script>
<script src="{{ asset('assets/js/pGenerator.jquery.js') }}"></script>
<script>
$(document).ready(function () {
$('#genPassword').pGenerator({
'bind': 'click',
'passwordElement': '#modal-password',
'displayElement': '#generated-password',
'passwordLength': 16,
'uppercase': true,
'lowercase': true,
'numbers': true,
'specialChars': true,
'onPasswordGenerated': function (generatedPassword) {
$('#modal-password_confirm').val($('#modal-password').val());
}
});
});
</script>
@stop

View file

@ -336,13 +336,14 @@
@endif
@if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at==''))
{{-- @TODO This should be extnded for details about non users --}}
<h6><br>{{ trans('admin/hardware/form.checkedout_to') }}</h6>
<ul>
<li>
<img src="{{ $asset->assigneduser->present()->gravatar() }}" class="img-circle" style="width: 100px; margin-right: 20px;" /><br /><br />
</li>
<li>
<a href="{{ route('users.show', $asset->assigned_to) }}">{{ $asset->assigneduser->present()->fullName() }}</a>
{{ $asset->assignedTo->present()->nameUrl() }}
</li>
@if (isset($asset->assetloc->address))

View file

@ -229,7 +229,7 @@
@if ($asset->depreciation)
<tr>
<td>{{ trans('admin/hardware/form.depreciation') }}</td>
<td>{{ trans('general.depreciation') }}</td>
<td>
{{ $asset->depreciation->name }}
({{ $asset->depreciation->months }}
@ -347,11 +347,13 @@
<img src="{{ url('/') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail pull-right" style="height: 100px; width: 100px; margin-right: 10px;">
@endif
@if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at==''))
@if (($asset->assignedTo) && ($asset->deleted_at==''))
<h4>{{ trans('admin/hardware/form.checkedout_to') }}</h4>
<p>
<img src="{{ $asset->assigneduser->present()->gravatar() }}" class="user-image-inline" alt="{{ $asset->assigneduser->present()->fullName() }}">
<a href="{{ route('users.show', $asset->assigned_to) }}">{{ $asset->assigneduser->present()->fullName() }}</a>
@if($asset->assigned_type == User::class) <!-- Only users have avatars currently-->
<img src="{{ $asset->assignedTo->present()->gravatar() }}" class="user-image-inline" alt="{{ $asset->assigneduser->present()->fullName() }}">
@endif
{!! $asset->assignedTo->present()->nameUrl() !!}
</p>
<ul class="list-unstyled">
@ -363,37 +365,20 @@
<li><i class="fa fa-phone"></i> {{ $asset->assigneduser->phone }}</li>
@endif
@if (isset($asset->userloc))
<li>{{ $asset->userloc->name }}</li>
<li>{{ $asset->userloc->address }}
@if ($asset->userloc->address2!='')
{{ $asset->userloc->address2 }}
@if (isset($asset->assetLoc))
<li>{{ $asset->assetLoc->name }}</li>
<li>{{ $asset->assetLoc->address }}
@if ($asset->assetLoc->address2!='')
{{ $asset->assetLoc->address2 }}
@endif
</li>
<li>{{ $asset->userloc->city }}
@if (($asset->userloc->city!='') && ($asset->userloc->state!=''))
<li>{{ $asset->assetLoc->city }}
@if (($asset->assetLoc->city!='') && ($asset->assetLoc->state!=''))
,
@endif
{{ $asset->userloc->state }} {{ $asset->userloc->zip }}
{{ $asset->assetLoc->state }} {{ $asset->assetLoc->zip }}
</li>
@elseif (isset($asset->assetloc))
<li>{{ $asset->assetloc->name }}</li>
<li>{{ $asset->assetloc->address }}
@if ($asset->assetloc->address2!='')
{{ $asset->assetloc->address2 }}
@endif
</li>
<li>
{{ $asset->assetloc->city }}
@if (($asset->assetloc->city!='') && ($asset->assetloc->state!=''))
,
@endif
{{ $asset->assetloc->state }} {{ $asset->assetloc->zip }}
</li>
@endif
</ul>
@ -600,8 +585,8 @@
@endif
@elseif (($log->action_type=='accepted') || ($log->action_type=='declined'))
{{-- On a declined log, the asset isn't assigned to anyone when we look this up. --}}
@if ($log->item->assigneduser)
{{ $log->item->assigneduser->present()->fullName() }}
@if ($log->item->assignedTo)
{{ $log->item->assignedTo->present()->name() }}
@else
Unknown
@endif

View file

@ -68,11 +68,9 @@
@elseif ($licensedto->asset)
@if ($licensedto->asset->assigned_to != 0)
@can('users.view')
<a href="{{ route('users.show', $licensedto->asset->assigned_to) }}">
{{ $licensedto->asset->assigneduser->present()->fullName() }}
</a>
{!! $licensedto->asset->assignedTo->present()->nameUrl() !!}
@else
{{ $licensedto->asset->assigneduser->present()->fullName() }}
{{ $licensedto->asset->assignedTo->present()->name() }}
@endcan
@endif
@endif

View file

@ -74,13 +74,11 @@
@endif
</td>
<td>
@if ($asset->assigneduser)
@if ($asset->assigneduser->deleted_at!='')
<del>{{ $asset->assigneduser->present()->fullName() }}</del>
@if ($asset->assignedTo)
@if ($asset->assignedTo->deleted_at!='')
<del>{{ $asset->assignedTo->present()->name() }}</del>
@else
<a href="{{ route('users.show', $asset->assigned_to) }}">
{{ $asset->assigneduser->present()->fullName() }}
</a>
{!! $asset->assignedTo->present()->nameUrl() !!}
@endif
@endif
</td>

View file

@ -48,15 +48,12 @@
<td>{{ $asset->serial }}</td>
<td>
@if ($asset->assigned_to != '')
<a href="{{ route('users.show', $asset->assigned_to) }}">
{{ $asset->assigneduser->present()->fullName() }}
</a>
{!! $asset->assignedTo->present->nameUrl() !!}
@endif
</td>
<td>
@if (($asset->assigned_to > 0) && ($asset->assigneduser->location_id > 0)) {{ Location::find($asset->assigneduser->location_id)->city }}
,
{{ Location::find($asset->assigneduser->location_id)->state }}
@if (($asset->assignedTo) && ($asset->assigneduser->assetLoc))
{{ $asset->assignedTo->assetLoc->city }}, {{ $asset->assignedTo->assetLoc->state}}
@endif
</td>
<td>{{ $asset->purchase_date }}</td>

View file

@ -39,9 +39,9 @@
<td>{{ is_null($assetItem->company) ? '' : $assetItem->company->name }}</td>
<td>{{ $assetItem->model->category->name }}</td>
<td>{{ $assetItem->model->name }}</td>
<td>{{ link_to_route('hardware.show',$assetItem->present()->name(), [$assetItem->id]) }}</td>
<td>{!! $assetItem->present()->nameUrl() !!}</td>
<td>{{ $assetItem->asset_tag }}</td>
<td>{{ link_to_route('users.show', $assetItem->assigneduser->present()->fullName(), [$assetItem->assigned_to])}}</td>
<td>{!! $assetItem->assignedTo->present()->nameUrl() !!}</td>
</tr>
@endforeach
@endif

View file

@ -70,7 +70,7 @@ Bulk Checkin &amp; Delete
@endforeach
</td>
<td>
{{ number_format($user->assets()->count()) }}
{{ number_format($user->assignedAssets()->count()) }}
</td>
<td>
{{ number_format($user->accessories()->count()) }}

View file

@ -228,7 +228,7 @@
</tr>
</thead>
<tbody>
@foreach ($user->assets as $asset)
@foreach ($user->assignedAssets as $asset)
<tr>
<td>
@if ($asset->physical=='1')

View file

@ -19,7 +19,7 @@ use App\Models\Statuslabel;
Route::group(['prefix' => 'v1', 'middleware' => 'auth:api'], function () {
/*---Hardware API---*/
Route::group([ 'prefix' => 'hardware','middleware' => ['web','auth','authorize:assets.view']], function () {
Route::group([ 'prefix' => 'hardware','middleware' => ['web','auth']], function () {
Route::get('list/{status?}', [ 'as' => 'api.hardware.list', 'uses' => 'AssetsController@getDatatable' ]);

File diff suppressed because one or more lines are too long

View file

@ -35,11 +35,30 @@ class AssetsCest
{
$asset = factory(App\Models\Asset::class,'asset')->make();
$values = [
'company_id' => $asset->company_id,
'asset_tag' => $asset->asset_tag,
'model_id' => $asset->model_id,
'status_id' => $asset->status_id,
'assigned_user' => $I->getUserId(),
'serial' => $asset->serial,
'name' => $asset->name,
'purchase_date' => '2016-01-01',
'supplier_id' => $asset->supplier_id,
'order_number' => $asset->order_number,
'purchase_cost' => $asset->purchase_cost,
'warranty_months' => $asset->warranty_months,
'notes' => $asset->notes,
'rtd_location_id' => $asset->rtd_location_id,
'requestable' => $asset->requestable,
];
$seenValues = [
'company_id' => $asset->company_id,
'asset_tag' => $asset->asset_tag,
'model_id' => $asset->model_id,
'status_id' => $asset->status_id,
'assigned_to' => $I->getUserId(),
'assigned_type' => 'App\Models\User',
'serial' => $asset->serial,
'name' => $asset->name,
'purchase_date' => '2016-01-01',
@ -55,7 +74,7 @@ class AssetsCest
$I->wantTo("Test Validation Succeeds");
$I->amOnPage(route('hardware.create'));
$I->submitForm('form#create-form', $values);
$I->seeRecord('assets', $values);
$I->seeRecord('assets', $seenValues);
$I->dontSeeElement('.alert-danger'); // We should check for success, but we can't because of the stupid ajaxy way I did things. FIXME when the asset form is rewritten.
}

View file

@ -91,14 +91,9 @@ class UsersCest
public function allowsDelete(FunctionalTester $I)
{
$user = factory(App\Models\User::class, 'valid-user')->create();
$I->wantTo('Ensure I can delete a user');
$userId = User::doesntHave('assets')
->doesntHave('accessories')
->doesntHave('consumables')
->doesntHave('licenses')
->where('username', '!=', 'snipeit')
->first()->id;
$I->sendDelete(route('users.destroy', $userId), ['_token' => csrf_token()]);
$I->sendDelete(route('users.destroy', $user->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200);
}
}