private function updateId() { $components = Component::all(); foreach ($components as $component) { $new = Component::find($component->id); $new->id = Component::get_uid(); $new->save(); } }
/** * Validate and store checkout data. * * @author [A. Gianotto] [<*****@*****.**>] * @see ComponentsController::getCheckout() method that returns the form. * @since [v3.0] * @param int $componentId * @return Redirect */ public function postCheckout(Request $request, $componentId) { // Check if the component exists if (is_null($component = Component::find($componentId))) { // Redirect to the component management page with error return redirect()->to('components')->with('error', trans('admin/components/message.not_found')); } elseif (!Company::isCurrentUserHasAccess($component)) { return redirect()->to('admin/components')->with('error', trans('general.insufficient_permissions')); } $max_to_checkout = $component->numRemaining(); $validator = Validator::make($request->all(), ["asset_id" => "required", "assigned_qty" => "required|numeric|between:1,{$max_to_checkout}"]); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $admin_user = Auth::user(); $asset_id = e(Input::get('asset_id')); // Check if the user exists if (is_null($asset = Asset::find($asset_id))) { // Redirect to the component management page with error return redirect()->to('admin/components')->with('error', trans('admin/components/message.asset_does_not_exist')); } // Update the component data $component->asset_id = $asset_id; $component->assets()->attach($component->id, array('component_id' => $component->id, 'user_id' => $admin_user->id, 'created_at' => date('Y-m-d h:i:s'), 'assigned_qty' => e(Input::get('assigned_qty')), 'asset_id' => $asset_id)); $logaction = new Actionlog(); $logaction->component_id = $component->id; $logaction->asset_id = $asset_id; $logaction->asset_type = 'component'; $logaction->location_id = $asset->location_id; $logaction->user_id = Auth::user()->id; $logaction->note = e(Input::get('note')); $settings = Setting::getSettings(); if ($settings->slack_endpoint) { $slack_settings = ['username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true]; $client = new \Maknz\Slack\Client($settings->slack_endpoint, $slack_settings); try { $client->attach(['color' => 'good', 'fields' => [['title' => 'Checked Out:', 'value' => strtoupper($logaction->asset_type) . ' <' . config('app.url') . '/admin/components/' . $component->id . '/view' . '|' . $component->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $admin_user->id . '/view' . '|' . $admin_user->fullName() . '>.'], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('Component Checked Out'); } catch (Exception $e) { } } $log = $logaction->logaction('checkout'); // Redirect to the new component page return redirect()->to("admin/components")->with('success', trans('admin/components/message.checkout.success')); }
public function getAcceptAsset($logID = null) { if (!($findlog = DB::table('asset_logs')->where('id', '=', $logID)->first())) { echo 'no record'; //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist')); } $user = Auth::user(); if ($user->id != $findlog->checkedout_to) { return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted')); } // Asset if ($findlog->asset_id != '' && $findlog->asset_type == 'hardware') { $item = Asset::find($findlog->asset_id); // software } elseif ($findlog->asset_id != '' && $findlog->asset_type == 'software') { $item = License::find($findlog->asset_id); // accessories } elseif ($findlog->accessory_id != '') { $item = Accessory::find($findlog->accessory_id); // consumable } elseif ($findlog->consumable_id != '') { $item = Consumable::find($findlog->consumable_id); // components } elseif ($findlog->component_id != '') { $item = Component::find($findlog->component_id); } // Check if the asset exists if (is_null($item)) { // Redirect to the asset management page return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist')); } elseif (!Company::isCurrentUserHasAccess($item)) { return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')); } else { return View::make('account/accept-asset', compact('item'))->with('findlog', $findlog); } }