diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index d921065a5f..6a01b52c09 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -154,7 +154,6 @@ class AccessoriesController extends Controller $offset = request('offset', 0); $limit = request('limit', 50); - $accessory->lastCheckoutArray = $accessory->lastCheckout->toArray(); $accessory_users = $accessory->users; $total = $accessory_users->count(); diff --git a/database/migrations/2020_10_22_233743_move_accessory_checkout_note_to_join_table.php b/database/migrations/2020_10_22_233743_move_accessory_checkout_note_to_join_table.php new file mode 100644 index 0000000000..39920c2f67 --- /dev/null +++ b/database/migrations/2020_10_22_233743_move_accessory_checkout_note_to_join_table.php @@ -0,0 +1,84 @@ +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; + + foreach ($accessories as $accessory) { + $count++; + + foreach ($accessory->users as $join_log) { + + \Log::debug('Looking for accessories_users that match '. $join_log->created_at); + + $log_entries = $accessory + ->assetlog() + ->whereNotNull('note') + ->where('created_at', '=',$join_log->created_at) + ->where('action_type', '=', 'checkout') + ->orderBy('created_at', 'DESC') + ->take('1'); + + + \Log::debug($accessory->toSql()); + + $log_entries->get(); + + \Log::debug($count. '. Looking for action_logs that match '. $join_log->created_at); + + foreach ($log_entries as $log_entry) { + \Log::debug($log_entries->count().' action_logs that match'); + + \Log::debug($count. '. Checkout date in asset log: '.$log_entry->created_at.' against accessories_users: '.$join_log->created_at); + + if ($log_entry->created_at == $join_log->created_at) { + \Log::debug($count. '. Note for '.$accessory->name.' checked out on '.$log_entry->created_at.' to '.$log_entry->target_id.' is '.$log_entry->note); + } else { + \Log::debug('No match'); + + } + } + + } + + + + } + + die(); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accessory_checkout', function (Blueprint $table) { + $table->dropColumn('note'); + }); + } +}