Merge branch 'dmeltzer-checkout-to-things-v1' into develop
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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')));
|
||||
|
||||
@@ -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')) {
|
||||
|
||||
@@ -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, ',');
|
||||
}
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user