Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2020-10-23 14:23:46 -07:00
commit 28612d8b61
10 changed files with 165 additions and 7 deletions

View file

@ -75,7 +75,8 @@ class AccessoryCheckoutController extends Controller
'accessory_id' => $accessory->id, 'accessory_id' => $accessory->id,
'created_at' => Carbon::now(), 'created_at' => Carbon::now(),
'user_id' => Auth::id(), 'user_id' => Auth::id(),
'assigned_to' => $request->get('assigned_to') 'assigned_to' => $request->get('assigned_to'),
'note' => $request->input('note')
]); ]);
DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first(); DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();

View file

@ -154,7 +154,6 @@ class AccessoriesController extends Controller
$offset = request('offset', 0); $offset = request('offset', 0);
$limit = request('limit', 50); $limit = request('limit', 50);
$accessory->lastCheckoutArray = $accessory->lastCheckout->toArray();
$accessory_users = $accessory->users; $accessory_users = $accessory->users;
$total = $accessory_users->count(); $total = $accessory_users->count();

View file

@ -76,9 +76,32 @@ class AssetCheckinController extends Controller
$asset->status_id = e($request->get('status_id')); $asset->status_id = e($request->get('status_id'));
} }
// This is just meant to correct legacy issues where some user data would have 0
// as a location ID, which isn't valid. Later versions of Snipe-IT have stricter validation
// rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
// people (and their data) in the long run
if ($asset->rtd_location_id=='0') {
\Log::debug('Manually override the RTD location IDs');
\Log::debug('Original RTD Location ID: '.$asset->rtd_location_id);
$asset->rtd_location_id = '';
\Log::debug('New RTD Location ID: '.$asset->rtd_location_id);
}
if ($asset->location_id=='0') {
\Log::debug('Manually override the location IDs');
\Log::debug('Original Location ID: '.$asset->location_id);
$asset->location_id = '';
\Log::debug('New RTD Location ID: '.$asset->location_id);
}
$asset->location_id = $asset->rtd_location_id; $asset->location_id = $asset->rtd_location_id;
\Log::debug('After Location ID: '.$asset->location_id);
\Log::debug('After RTD Location ID: '.$asset->rtd_location_id);
if ($request->filled('location_id')) { if ($request->filled('location_id')) {
\Log::debug('NEW Location ID: '.$request->get('location_id'));
$asset->location_id = e($request->get('location_id')); $asset->location_id = e($request->get('location_id'));
} }
@ -97,6 +120,6 @@ class AssetCheckinController extends Controller
return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkin.success')); return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkin.success'));
} }
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->route("hardware.index")->with('error', trans('admin/hardware/message.checkin.error')); return redirect()->route("hardware.index")->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
} }
} }

View file

@ -80,7 +80,7 @@ class AssetCheckoutController extends Controller
} }
// Redirect to the asset management page with error // Redirect to the asset management page with error
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors()); return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors());
} catch (ModelNotFoundException $e) { } catch (ModelNotFoundException $e) {
return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors()); return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
} catch (CheckoutNotAllowed $e) { } catch (CheckoutNotAllowed $e) {

View file

@ -68,8 +68,13 @@ class AccessoriesTransformer
$array = array(); $array = array();
foreach ($accessory_users as $user) { foreach ($accessory_users as $user) {
\Log::debug(print_r($user->pivot, true));
\Log::debug(print_r($user->pivot, true));
$array[] = [ $array[] = [
'assigned_pivot_id' => $user->pivot->id, 'assigned_pivot_id' => $user->pivot->id,
'id' => (int) $user->id, 'id' => (int) $user->id,
'username' => e($user->username), 'username' => e($user->username),
@ -77,7 +82,8 @@ class AccessoriesTransformer
'first_name'=> e($user->first_name), 'first_name'=> e($user->first_name),
'last_name'=> e($user->last_name), 'last_name'=> e($user->last_name),
'employee_number' => e($user->employee_num), 'employee_number' => e($user->employee_num),
'checkout_notes' => $accessory->lastCheckoutArray[0]['note'], 'checkout_notes' => $user->pivot->note,
'last_checkout' => Helper::getFormattedDateObject($user->pivot->created_at, 'datetime'),
'type' => 'user', 'type' => 'user',
'available_actions' => ['checkin' => true] 'available_actions' => ['checkin' => true]
]; ];

View file

@ -234,7 +234,7 @@ class Accessory extends SnipeModel
public function users() public function users()
{ {
return $this->belongsToMany('\App\Models\User', 'accessories_users', 'accessory_id', 'assigned_to')->withPivot('id')->withTrashed(); return $this->belongsToMany('\App\Models\User', 'accessories_users', 'accessory_id', 'assigned_to')->withPivot('id', 'created_at', 'note')->withTrashed();
} }
/** /**

View file

@ -295,7 +295,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
*/ */
public function accessories() public function accessories()
{ {
return $this->belongsToMany('\App\Models\Accessory', 'accessories_users', 'assigned_to', 'accessory_id')->withPivot('id')->withTrashed(); return $this->belongsToMany('\App\Models\Accessory', 'accessories_users', 'assigned_to', 'accessory_id')
->withPivot('id', 'created_at', 'note')->withTrashed();
} }
/** /**

View file

@ -0,0 +1,89 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Accessory;
use App\Models\Actionlog;
class MoveAccessoryCheckoutNoteToJoinTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accessories_users', function (Blueprint $table) {
$table->string('note')->nullable(true)->default(null);
});
// Loop through the checked out accessories, find their related action_log entry, and copy over the note
// to the newly created note field
$accessories = Accessory::get();
$count = 0;
\Log::debug('Accessory Count: '. $accessories->count());
// Loop through all of the accessories
foreach ($accessories as $accessory) {
$count++;
\Log::debug('Querying join logs');
$join_logs = DB::table('accessories_users')->get();
// Loop through the accessories_users records
foreach ($join_logs as $join_log) {
\Log::debug($join_logs->count().' join log records');
\Log::debug('Looking for accessories_users that match '. $join_log->created_at);
// Get the records from action_logs so we can copy the notes over to the new notes field
// on the accessories_users table
$action_log_entries = Actionlog::where('created_at', '=',$join_log->created_at)
->where('target_id', '=',$join_log->assigned_to)
->where('item_id', '=',$accessory->id)
->where('target_type', '=','App\\Models\\User')
->where('action_type', '=', 'checkout')
->orderBy('created_at', 'DESC')->get();
\Log::debug($action_log_entries->count().' matching entries in the action_logs table');
\Log::debug('Looking for action_logs that match '. $join_log->created_at);
foreach ($action_log_entries as $action_log_entry) {
\Log::debug('Checkout date in asset log: '.$action_log_entry->created_at.' against accessories_users: '.$join_log->created_at);
\Log::debug('Action log: '.$action_log_entry->created_at);
\Log::debug('Join log: '.$join_log->created_at);
if ($action_log_entry->created_at == $join_log->created_at) {
DB::table('accessories_users')
->where('id', $join_log->id)
->update(['note' => $action_log_entry->note]);
} else {
\Log::debug('No match');
}
}
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('accessories_users', function (Blueprint $table) {
$table->dropColumn('note');
});
}
}

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\User;
use App\Models\Asset;
class FixZeroValuesForLocations extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
App\Models\Asset::where('location_id', '=', '0')
->update(['location_id' => null]);
App\Models\Asset::where('rtd_location_id', '=', '0')
->update(['rtd_location_id' => null]);
App\Models\User::where('location_id', '=', '0')
->update(['location_id' => null]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View file

@ -76,6 +76,7 @@
<tr> <tr>
<th data-searchable="false" data-formatter="usersLinkFormatter" data-sortable="false" data-field="name">{{ trans('general.user') }}</th> <th data-searchable="false" data-formatter="usersLinkFormatter" data-sortable="false" data-field="name">{{ trans('general.user') }}</th>
<th data-searchable="false" data-sortable="false" data-field="checkout_notes">{{ trans('general.notes') }}</th> <th data-searchable="false" data-sortable="false" data-field="checkout_notes">{{ trans('general.notes') }}</th>
<th data-searchable="false" data-formatter="dateDisplayFormatter" data-sortable="false" data-field="last_checkout">{{ trans('admin/hardware/table.checkout_date') }}</th>
<th data-searchable="false" data-sortable="false" data-field="actions" data-formatter="accessoriesInOutFormatter">{{ trans('table.actions') }}</th> <th data-searchable="false" data-sortable="false" data-field="actions" data-formatter="accessoriesInOutFormatter">{{ trans('table.actions') }}</th>
</tr> </tr>
</thead> </thead>