mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Remove remaining DB::Raw(concat) calls to make things more sqlite friendly. This adds one new method to the Asset Model to return the formatted string that was used by the license and asset maintence controller. It also fixes a potential sqlite-only issue where '' and null are different.
This commit is contained in:
parent
45d93ffa8c
commit
0fa82743a1
|
@ -155,41 +155,14 @@ class AssetMaintenancesController extends Controller
|
|||
] + AssetMaintenance::getImprovementOptions();
|
||||
// Mark the selected asset, if it came in
|
||||
$selectedAsset = $assetId;
|
||||
// Get the possible assets using a left join to get a list of assets and some other helpful info
|
||||
$asset = Company::scopeCompanyables(DB::table('assets'), 'assets.company_id')
|
||||
->leftJoin('users', 'users.id', '=', 'assets.assigned_to')
|
||||
->leftJoin('models', 'assets.model_id', '=', 'models.id')
|
||||
->select(
|
||||
'assets.id',
|
||||
'assets.name',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'asset_tag',
|
||||
DB::raw('concat(first_name," ",last_name) as full_name, assets.id as id, models.name as modelname')
|
||||
)
|
||||
->whereNull('assets.deleted_at')
|
||||
->get();
|
||||
$asset_array = json_decode(json_encode($asset), true);
|
||||
$asset_element[ '' ] = 'Please select an asset';
|
||||
|
||||
// Build a list out of the data results
|
||||
for ($x = 0; $x < count($asset_array); $x++) {
|
||||
$assets = Company::scopeCompanyables(Asset::all(), 'assets.company_id')->lists('detailed_name', 'id');
|
||||
|
||||
if ($asset_array[ $x ][ 'full_name' ] != '') {
|
||||
$full_name = ' (' . $asset_array[ $x ][ 'full_name' ] . ') ' . $asset_array[ $x ][ 'modelname' ];
|
||||
} else {
|
||||
$full_name = ' (Unassigned) ' . $asset_array[ $x ][ 'modelname' ];
|
||||
}
|
||||
$asset_element[ $asset_array[ $x ][ 'id' ] ] =
|
||||
$asset_array[ $x ][ 'asset_tag' ] . ' - ' . $asset_array[ $x ][ 'name' ] . $full_name;
|
||||
}
|
||||
|
||||
// Get Supplier List
|
||||
$supplier_list = Helper::suppliersList();
|
||||
|
||||
// Render the view
|
||||
return View::make('asset_maintenances/edit')
|
||||
->with('asset_list', $asset_element)
|
||||
->with('asset_list', $assets)
|
||||
->with('selectedAsset', $selectedAsset)
|
||||
->with('supplier_list', $supplier_list)
|
||||
->with('assetMaintenanceType', $assetMaintenanceType)
|
||||
|
@ -321,40 +294,13 @@ class AssetMaintenancesController extends Controller
|
|||
'' => 'Select an improvement type',
|
||||
] + AssetMaintenance::getImprovementOptions();
|
||||
|
||||
// Get the possible assets using a left join to get a list of assets and some other helpful info
|
||||
$asset = Company::scopeCompanyables(DB::table('assets'), 'assets.company_id')
|
||||
->leftJoin('users', 'users.id', '=', 'assets.assigned_to')
|
||||
->leftJoin('models', 'assets.model_id', '=', 'models.id')
|
||||
->select(
|
||||
'assets.id',
|
||||
'assets.name',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'asset_tag',
|
||||
DB::raw('concat(first_name," ",last_name) as full_name, assets.id as id, models.name as modelname')
|
||||
)
|
||||
->whereNull('assets.deleted_at')
|
||||
->get();
|
||||
$asset_array = json_decode(json_encode($asset), true);
|
||||
$asset_element[ '' ] = 'Please select an asset';
|
||||
|
||||
// Build a list out of the data results
|
||||
for ($x = 0; $x < count($asset_array); $x++) {
|
||||
|
||||
if ($asset_array[ $x ][ 'full_name' ] != '') {
|
||||
$full_name = ' (' . $asset_array[ $x ][ 'full_name' ] . ') ' . $asset_array[ $x ][ 'modelname' ];
|
||||
} else {
|
||||
$full_name = ' (Unassigned) ' . $asset_array[ $x ][ 'modelname' ];
|
||||
}
|
||||
$asset_element[ $asset_array[ $x ][ 'id' ] ] =
|
||||
$asset_array[ $x ][ 'asset_tag' ] . ' - ' . $asset_array[ $x ][ 'name' ] . $full_name;
|
||||
}
|
||||
$assets = Company::scopeCompanyables(Asset::all(), 'assets.company_id')->lists('detailed_name', 'id');
|
||||
// Get Supplier List
|
||||
$supplier_list = Helper::suppliersList();
|
||||
|
||||
// Render the view
|
||||
return View::make('asset_maintenances/edit')
|
||||
->with('asset_list', $asset_element)
|
||||
->with('asset_list', $assets)
|
||||
->with('selectedAsset', null)
|
||||
->with('supplier_list', $supplier_list)
|
||||
->with('assetMaintenanceType', $assetMaintenanceType)
|
||||
|
|
|
@ -439,37 +439,11 @@ class LicensesController extends Controller
|
|||
// Get the dropdown of users and then pass it to the checkout view
|
||||
$users_list = Helper::usersList();
|
||||
|
||||
// Left join to get a list of assets and some other helpful info
|
||||
$asset = DB::table('assets')
|
||||
->leftJoin('users', 'users.id', '=', 'assets.assigned_to')
|
||||
->leftJoin('models', 'assets.model_id', '=', 'models.id')
|
||||
->select(
|
||||
'assets.id',
|
||||
'assets.name',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'asset_tag',
|
||||
DB::raw('concat(first_name," ",last_name) as full_name, assets.id as id, models.name as modelname')
|
||||
)
|
||||
->whereNull('assets.deleted_at')
|
||||
->get();
|
||||
$assets = Company::scopeCompanyables(Asset::all(), 'assets.company_id')->lists('detailed_name', 'id');
|
||||
|
||||
$asset_array = json_decode(json_encode($asset), true);
|
||||
$asset_element[''] = 'Please select an asset';
|
||||
|
||||
// Build a list out of the data results
|
||||
for ($x=0; $x<count($asset_array); $x++) {
|
||||
|
||||
if ($asset_array[$x]['full_name']!='') {
|
||||
$full_name = ' ('.$asset_array[$x]['full_name'].') '.$asset_array[$x]['modelname'];
|
||||
} else {
|
||||
$full_name = ' (Unassigned) '.$asset_array[$x]['modelname'];
|
||||
}
|
||||
$asset_element[$asset_array[$x]['id']] = $asset_array[$x]['asset_tag'].' - '.$asset_array[$x]['name'].$full_name;
|
||||
|
||||
}
|
||||
|
||||
return View::make('licenses/checkout', compact('licenseseat'))->with('users_list', $users_list)->with('asset_list', $asset_element);
|
||||
return View::make('licenses/checkout', compact('licenseseat'))
|
||||
->with('users_list', $users_list)
|
||||
->with('asset_list', $assets);
|
||||
|
||||
}
|
||||
|
||||
|
@ -526,8 +500,8 @@ class LicensesController extends Controller
|
|||
// Redirect to the asset management page with error
|
||||
return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.asset_does_not_exist'));
|
||||
}
|
||||
|
||||
if (($is_asset_id->assigned_to!=$assigned_to) && ($assigned_to!='')) {
|
||||
$was_assigned_to = $is_asset_id->assigned_to;
|
||||
if (($was_assigned_to!=$assigned_to) && !is_null($was_assigned_to) && ($was_assigned_to != '')) {
|
||||
//echo 'asset assigned to: '.$is_asset_id->assigned_to.'<br>license assigned to: '.$assigned_to;
|
||||
return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset'));
|
||||
}
|
||||
|
|
|
@ -657,13 +657,7 @@ class UsersController extends Controller
|
|||
|
||||
$location_list = Helper::locationsList();
|
||||
$company_list = Helper::companyList();
|
||||
$manager_list = array('' => 'Select a User') + DB::table('users')
|
||||
->select(DB::raw('concat(last_name,", ",first_name," (",email,")") as full_name, id'))
|
||||
->whereNull('deleted_at')
|
||||
->where('id', '!=', $id)
|
||||
->orderBy('last_name', 'asc')
|
||||
->orderBy('first_name', 'asc')
|
||||
->lists('full_name', 'id');
|
||||
$manager_list = Helper::managerList();
|
||||
|
||||
// Show the page
|
||||
return View::make('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions'))
|
||||
|
|
|
@ -172,6 +172,15 @@ class Asset extends Depreciable
|
|||
}
|
||||
|
||||
|
||||
public function getDetailedNameAttribute() {
|
||||
$user = $this->assigneduser;
|
||||
if($user) {
|
||||
$user_name = $user->fullName();
|
||||
} else {
|
||||
$user_name = "Unassigned";
|
||||
}
|
||||
return $this->asset_tag . ' - ' . $this->name . ' (' . $user_name . ') ' . $this->model->name;
|
||||
}
|
||||
public function validationRules($id = '0')
|
||||
{
|
||||
return $this->rules;
|
||||
|
|
Loading…
Reference in a new issue