Merge pull request #2050 from dmeltzer/sqlite-fixes

Sqlite fixes
This commit is contained in:
snipe 2016-05-31 17:45:04 -07:00
commit a542b18a04
8 changed files with 39 additions and 111 deletions

View file

@ -164,11 +164,11 @@ class Helper
public static function managerList()
{
$manager_list = array('' => '') + User::select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))
->whereNull('deleted_at', 'and')
->orderBy('last_name', 'asc')
->orderBy('first_name', 'asc')
->pluck('full_name', 'id')->toArray();
$manager_list = User::where('deleted_at', '=', null)
->orderBy('last_name', 'asc')
->orderBy('first_name', 'asc')->get()
->lists('full_name', 'id');
return $manager_list;
}
@ -187,13 +187,12 @@ class Helper
public static function usersList()
{
$users_list = array('' => trans('general.select_user')) + DB::table('users')
->select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))
->whereNull('deleted_at')
->where('show_in_list','=',1)
->orderBy('last_name', 'asc')
->orderBy('first_name', 'asc')
->pluck('full_name', 'id');
$users_list = User::where('deleted_at', '=', null)
->where('show_in_list','=',1)
->orderBy('last_name', 'asc')
->orderBy('first_name', 'asc')->get()
->lists('full_name', 'id');
return $users_list;
}

View file

@ -313,6 +313,7 @@ class AccessoriesController extends Controller
$logaction = new Actionlog();
$logaction->accessory_id = $accessory->id;
$logaction->asset_id = 0;
$logaction->checkedout_to = $accessory->assigned_to;
$logaction->asset_type = 'accessory';
$logaction->location_id = $user->location_id;

View file

@ -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)

View file

@ -319,6 +319,7 @@ class ConsumablesController extends Controller
$logaction->consumable_id = $consumable->id;
$logaction->checkedout_to = $consumable->assigned_to;
$logaction->asset_type = 'consumable';
$logaction->asset_id = 0;
$logaction->location_id = $user->location_id;
$logaction->user_id = Auth::user()->id;
$logaction->note = e(Input::get('note'));

View file

@ -156,6 +156,7 @@ class LicensesController extends Controller
$insertedId = $license->id;
// Save the license seat data
DB::transaction(function() use (&$insertedId,&$license) {
for ($x=0; $x<$license->seats; $x++) {
$license_seat = new LicenseSeat();
$license_seat->license_id = $insertedId;
@ -164,6 +165,7 @@ class LicensesController extends Controller
$license_seat->notes = null;
$license_seat->save();
}
});
// Redirect to the new license page
@ -435,40 +437,13 @@ class LicensesController extends Controller
}
// Get the dropdown of users and then pass it to the checkout view
$users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))->whereNull('deleted_at')->orderBy('last_name', 'asc')->orderBy('first_name', 'asc')->lists('full_name', 'id');
$users_list = Helper::usersList();
$assets = Company::scopeCompanyables(Asset::all(), 'assets.company_id')->lists('detailed_name', 'id');
// 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();
$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);
}
@ -525,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'));
}

View file

@ -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'))

View file

@ -172,6 +172,14 @@ class Asset extends Depreciable
}
public function getDetailedNameAttribute() {
if($this->assigned_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;

View file

@ -118,6 +118,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
return "{$this->first_name} {$this->last_name}";
}
public function getFullNameAttribute()
{
return $this->first_name . " " . $this->last_name;
}
/**
* Returns the user Gravatar image url.