public function testAssetAdd() { $asset = factory(Asset::class, 'asset')->make(); $values = ['name' => $asset->name, 'model_id' => $asset->model_id, 'status_id' => $asset->status_id, 'asset_tag' => $asset->asset_tag]; Asset::create($values); $this->tester->seeRecord('assets', $values); }
/** * Returns a new form for the specified asset. * * @param Asset $asset * * @return \Orchestra\Contracts\Html\Builder */ public function form(Asset $asset) { return $this->form->of('assets', function (FormGrid $form) use($asset) { if ($asset->exists) { $method = 'PATCH'; $route = route('maintenance.assets.update', [$asset->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $route = route('maintenance.assets.store'); $form->submit = 'Create'; } $categories = Category::getSelectHierarchy('assets'); $locations = Location::getSelectHierarchy(); $form->resource($this, $route, $asset, compact('method')); $form->fieldset(function (Fieldset $fieldset) use($categories, $locations) { $fieldset->control('input:text', 'tag')->attributes(['placeholder' => 'ex. 100010']); $fieldset->control('input:text', 'name')->attributes(['placeholder' => 'ex. Ford F150']); $fieldset->control('select', 'category')->options($categories)->value(function (Asset $asset) { return $asset->category_id; }); $fieldset->control('select', 'location')->options($locations)->value(function (Asset $asset) { return $asset->location_id; }); $fieldset->control('input:textarea', 'description'); $fieldset->control('select', 'condition')->options(trans('assets.conditions'))->value(function (Asset $asset) { return $asset->condition_number; }); $fieldset->control('input:text', 'vendor')->attributes(['placeholder' => 'ex. Ford']); $fieldset->control('input:text', 'make')->attributes(['placeholder' => 'ex. F']); $fieldset->control('input:text', 'model')->attributes(['placeholder' => 'ex. 150']); $fieldset->control('input:text', 'serial')->attributes(['placeholder' => 'ex. 153423-13432432-2342423']); $fieldset->control('input:text', 'size')->attributes(['placeholder' => 'ex. 1905 x 2463']); $fieldset->control('input:text', 'weight')->attributes(['placeholder' => 'ex. 1 Ton']); $fieldset->control('input:text', 'acquired_at')->attributes(['class' => 'pickadate', 'placeholder' => 'Click to Select a Date']); $fieldset->control('input:text', 'end_of_life')->attributes(['class' => 'pickadate', 'placeholder' => 'Click to Select a Date']); }); }); }
/** * Show a count of assets by status label * * @return View */ public function getAssetCountByStatuslabel() { $colors = []; $statuslabels = Statuslabel::get(); $labels = []; $points = []; foreach ($statuslabels as $statuslabel) { $labels[] = $statuslabel->name; $points[] = $statuslabel->assets()->whereNull('assigned_to')->count(); } $labels[] = 'Deployed'; $points[] = Asset::whereNotNull('assigned_to')->count(); $result = ["labels" => $labels, "datasets" => [["data" => $points, "backgroundColor" => Helper::chartColors(), "hoverBackgroundColor" => Helper::chartColors()]]]; return $result; }
/** * Check authorization and display admin dashboard, otherwise display * the user's checked-out assets. * * @author [A. Gianotto] [<*****@*****.**>] * @since [v1.0] * @return View */ public function getIndex() { // Show the page if (Auth::user()->hasAccess('admin')) { $recent_activity = Actionlog::orderBy('created_at', 'DESC')->with('accessorylog', 'consumablelog', 'licenselog', 'assetlog', 'adminlog', 'userlog', 'componentlog')->take(30)->get(); $asset_stats['total'] = Asset::Hardware()->count(); $asset_stats['rtd']['total'] = Asset::Hardware()->RTD()->count(); if ($asset_stats['rtd']['total'] > 0) { $asset_stats['rtd']['percent'] = round($asset_stats['rtd']['total'] / $asset_stats['total'] * 100); } else { $asset_stats['rtd']['percent'] = 0; } $asset_stats['pending']['total'] = Asset::Hardware()->Pending()->count(); if ($asset_stats['pending']['total'] > 0) { $asset_stats['pending']['percent'] = round($asset_stats['pending']['total'] / $asset_stats['total'] * 100); } else { $asset_stats['pending']['percent'] = 0; } $asset_stats['deployed']['total'] = Asset::Hardware()->Deployed()->count(); if ($asset_stats['deployed']['total'] > 0) { $asset_stats['deployed']['percent'] = round($asset_stats['deployed']['total'] / $asset_stats['total'] * 100); } else { $asset_stats['deployed']['percent'] = 0; } $asset_stats['undeployable']['total'] = Asset::Hardware()->Undeployable()->count(); if ($asset_stats['undeployable']['total'] > 0) { $asset_stats['undeployable']['percent'] = round($asset_stats['undeployable']['total'] / $asset_stats['total'] * 100); } else { $asset_stats['undeployable']['percent'] = 0; } $asset_stats['archived']['total'] = Asset::Hardware()->Archived()->count(); if ($asset_stats['archived']['total'] > 0) { $asset_stats['archived']['percent'] = round($asset_stats['archived']['total'] / $asset_stats['total'] * 100); } else { $asset_stats['archived']['percent'] = 0; } return View::make('dashboard')->with('asset_stats', $asset_stats)->with('recent_activity', $recent_activity); } else { // Redirect to the profile page return redirect()->route('view-assets'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Asset::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['TGL' => $this->TGL, 'KAS_BANK' => $this->KAS_BANK, 'TRAN_JALAN' => $this->TRAN_JALAN, 'INV_LAIN' => $this->INV_LAIN, 'STOK_SAHAM' => $this->STOK_SAHAM, 'HUTANG' => $this->HUTANG, 'HUT_LANCAR' => $this->HUT_LANCAR, 'MODAL' => $this->MODAL, 'CAD_LABA' => $this->CAD_LABA, 'LABA_JALAN' => $this->LABA_JALAN, 'UNIT' => $this->UNIT, 'NAV' => $this->NAV, 'TUMBUH' => $this->TUMBUH]); //if(!empty($start)){ //$query->andFilterWhere(['between', 'TGL', $this->start, $this->end]); $query->andFilterWhere(['>=', 'TGL', $this->start]); //} //if(!empty($end)){ $query->andFilterWhere(['<=', 'TGL', $this->end]); //} return $dataProvider; }
/** * Show a count of assets by status label * * @return View */ public function getAssetCountByStatuslabel() { $colors = []; $statuslabels = Statuslabel::with('assets')->get(); $labels = []; $points = []; $colors = []; foreach ($statuslabels as $statuslabel) { if ($statuslabel->assets->count() > 0) { $labels[] = $statuslabel->name; $points[] = $statuslabel->assets()->whereNull('assigned_to')->count(); if ($statuslabel->color != '') { $colors[] = $statuslabel->color; } } } $labels[] = 'Deployed'; $points[] = Asset::whereNotNull('assigned_to')->count(); $colors_array = array_merge($colors, Helper::chartColors()); $result = ["labels" => $labels, "datasets" => [["data" => $points, "backgroundColor" => $colors_array, "hoverBackgroundColor" => $colors_array]]]; return $result; }
/** * Execute the console command. * * @return mixed */ public function fire() { // Expiring Assets $expiring_assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); $this->info(count($expiring_assets) . ' expiring assets'); $asset_data['count'] = count($expiring_assets); $asset_data['email_content'] = ''; $now = date("Y-m-d"); foreach ($expiring_assets as $asset) { $expires = $asset->warrantee_expires(); $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400); if ($difference > 30) { $asset_data['email_content'] .= '<tr style="background-color: #fcffa3;">'; } else { $asset_data['email_content'] .= '<tr style="background-color:#d9534f;">'; } $asset_data['email_content'] .= '<td><a href="' . config('app.url') . '/hardware/' . e($asset->id) . '/view">'; $asset_data['email_content'] .= $asset->showAssetName() . '</a></td><td>' . e($asset->asset_tag) . '</td>'; $asset_data['email_content'] .= '<td>' . e($asset->warrantee_expires()) . '</td>'; $asset_data['email_content'] .= '<td>' . $difference . ' days</td>'; $asset_data['email_content'] .= '<td>' . ($asset->supplier ? e($asset->supplier->name) : '') . '</td>'; $asset_data['email_content'] .= '<td>' . ($asset->assigneduser ? e($asset->assigneduser->fullName()) : '') . '</td>'; $asset_data['email_content'] .= '</tr>'; } // Expiring licenses $expiring_licenses = License::getExpiringLicenses(Setting::getSettings()->alert_interval); $this->info(count($expiring_licenses) . ' expiring licenses'); $license_data['count'] = count($expiring_licenses); $license_data['email_content'] = ''; foreach ($expiring_licenses as $license) { $expires = $license->expiration_date; $difference = round(abs(strtotime($expires) - strtotime($now)) / 86400); if ($difference > 30) { $license_data['email_content'] .= '<tr style="background-color: #fcffa3;">'; } else { $license_data['email_content'] .= '<tr style="background-color:#d9534f;">'; } $license_data['email_content'] .= '<td><a href="' . config('app.url') . '/admin/licenses/' . $license->id . '/view">'; $license_data['email_content'] .= $license->name . '</a></td>'; $license_data['email_content'] .= '<td>' . $license->expiration_date . '</td>'; $license_data['email_content'] .= '<td>' . $difference . ' days</td>'; $license_data['email_content'] .= '</tr>'; } if (Setting::getSettings()->alert_email != '' && Setting::getSettings()->alerts_enabled == 1) { if (count($expiring_assets) > 0) { \Mail::send('emails.expiring-assets-report', $asset_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); $m->subject('Expiring Assets Report'); }); } if (count($expiring_licenses) > 0) { \Mail::send('emails.expiring-licenses-report', $license_data, function ($m) { $m->to(explode(',', Setting::getSettings()->alert_email), Setting::getSettings()->site_name); $m->subject('Expiring Licenses Report'); }); } } else { if (Setting::getSettings()->alert_email == '') { echo "Could not send email. No alert email configured in settings. \n"; } elseif (Setting::getSettings()->alerts_enabled != 1) { echo "Alerts are disabled in the settings. No mail will be sent. \n"; } } }
/** * Validates and stores an update to an asset maintenance * * @see AssetMaintenancesController::postEdit() method that stores the data * @author Vincent Sposato <*****@*****.**> * @param int $assetMaintenanceId * @version v1.0 * @since [v1.8] * @return mixed */ public function postEdit($assetMaintenanceId = null) { // get the POST data $new = Input::all(); // Check if the asset maintenance exists if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) { // Redirect to the asset maintenance management page return redirect()->to('admin/asset_maintenances')->with('error', trans('admin/asset_maintenances/message.not_found')); } elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) { return static::getInsufficientPermissionsRedirect(); } if (e(Input::get('supplier_id')) == '') { $assetMaintenance->supplier_id = null; } else { $assetMaintenance->supplier_id = e(Input::get('supplier_id')); } if (e(Input::get('is_warranty')) == '') { $assetMaintenance->is_warranty = 0; } else { $assetMaintenance->is_warranty = e(Input::get('is_warranty')); } if (e(Input::get('cost')) == '') { $assetMaintenance->cost = ''; } else { $assetMaintenance->cost = e(Input::get('cost')); } if (e(Input::get('notes')) == '') { $assetMaintenance->notes = null; } else { $assetMaintenance->notes = e(Input::get('notes')); } $asset = Asset::find(e(Input::get('asset_id'))); if (!Company::isCurrentUserHasAccess($asset)) { return static::getInsufficientPermissionsRedirect(); } // Save the asset maintenance data $assetMaintenance->asset_id = e(Input::get('asset_id')); $assetMaintenance->asset_maintenance_type = e(Input::get('asset_maintenance_type')); $assetMaintenance->title = e(Input::get('title')); $assetMaintenance->start_date = e(Input::get('start_date')); $assetMaintenance->completion_date = e(Input::get('completion_date')); if ($assetMaintenance->completion_date == "" || $assetMaintenance->completion_date == "0000-00-00") { $assetMaintenance->completion_date = null; if ($assetMaintenance->asset_maintenance_time !== 0 || !is_null($assetMaintenance->asset_maintenance_time)) { $assetMaintenance->asset_maintenance_time = null; } } if ($assetMaintenance->completion_date !== "" && $assetMaintenance->completion_date !== "0000-00-00" && $assetMaintenance->start_date !== "" && $assetMaintenance->start_date !== "0000-00-00") { $startDate = Carbon::parse($assetMaintenance->start_date); $completionDate = Carbon::parse($assetMaintenance->completion_date); $assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate); } // Was the asset maintenance created? if ($assetMaintenance->save()) { // Redirect to the new asset maintenance page return redirect()->to("admin/asset_maintenances")->with('success', trans('admin/asset_maintenances/message.create.success')); } return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors()); }
/** * Execute the console command. * * @return mixed */ public function handle() { if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) { if ($this->option('soft')) { Accessory::getQuery()->delete(); Asset::getQuery()->delete(); Category::getQuery()->delete(); Company::getQuery()->delete(); Component::getQuery()->delete(); Consumable::getQuery()->delete(); Depreciation::getQuery()->delete(); License::getQuery()->delete(); LicenseSeat::getQuery()->delete(); Location::getQuery()->delete(); Manufacturer::getQuery()->delete(); AssetModel::getQuery()->delete(); Statuslabel::getQuery()->delete(); Supplier::getQuery()->delete(); Group::getQuery()->delete(); DB::statement('delete from accessories_users'); DB::statement('delete from asset_logs'); DB::statement('delete from asset_maintenances'); DB::statement('delete from asset_uploads'); DB::statement('delete from consumables_users'); DB::statement('delete from custom_field_custom_fieldset'); DB::statement('delete from custom_fields'); DB::statement('delete from custom_fieldsets'); DB::statement('delete from components_assets'); DB::statement('delete from password_resets'); DB::statement('delete from requested_assets'); DB::statement('delete from requests'); DB::statement('delete from throttle'); DB::statement('delete from users_groups'); DB::statement('delete from users WHERE id!=1'); } else { \DB::statement('drop table IF EXISTS accessories_users'); \DB::statement('drop table IF EXISTS accessories'); \DB::statement('drop table IF EXISTS asset_logs'); \DB::statement('drop table IF EXISTS asset_maintenances'); \DB::statement('drop table IF EXISTS asset_uploads'); \DB::statement('drop table IF EXISTS assets'); \DB::statement('drop table IF EXISTS categories'); \DB::statement('drop table IF EXISTS companies'); \DB::statement('drop table IF EXISTS consumables_users'); \DB::statement('drop table IF EXISTS consumables'); \DB::statement('drop table IF EXISTS custom_field_custom_fieldset'); \DB::statement('drop table IF EXISTS custom_fields'); \DB::statement('drop table IF EXISTS custom_fieldsets'); \DB::statement('drop table IF EXISTS depreciations'); \DB::statement('drop table IF EXISTS groups'); \DB::statement('drop table IF EXISTS history'); \DB::statement('drop table IF EXISTS components'); \DB::statement('drop table IF EXISTS components_assets'); \DB::statement('drop table IF EXISTS license_seats'); \DB::statement('drop table IF EXISTS licenses'); \DB::statement('drop table IF EXISTS locations'); \DB::statement('drop table IF EXISTS manufacturers'); \DB::statement('drop table IF EXISTS models'); \DB::statement('drop table IF EXISTS migrations'); \DB::statement('drop table IF EXISTS password_resets'); \DB::statement('drop table IF EXISTS requested_assets'); \DB::statement('drop table IF EXISTS requests'); \DB::statement('drop table IF EXISTS settings'); \DB::statement('drop table IF EXISTS status_labels'); \DB::statement('drop table IF EXISTS suppliers'); \DB::statement('drop table IF EXISTS throttle'); \DB::statement('drop table IF EXISTS users_groups'); \DB::statement('drop table IF EXISTS users'); } } }
public function actionExportPdfDetail($tgl) { $dates = $this->getDates($tgl); $asset = Asset::find()->where(['TGL' => $dates[0]])->one(); $assetat = Assetat::find()->where(['TGL' => $dates[2]])->one(); $searchModel = new IndikatorSearch(['TGL' => $tgl]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $html = $this->renderPartial('_detail_pdf', ['asset' => $asset, 'assetat' => $assetat, 'dataProvider' => $dataProvider, 'dates' => $dates]); //function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') { $mpdf = new \mPDF('c', 'A4', 0, '', 15, 10, 15, 10, 10, 10); $header = ['L' => ['content' => date('d-M-Y H:i:s'), 'font-family' => 'sans', 'font-style' => '', 'font-size' => '9'], 'C' => [], 'R' => ['content' => 'Page {PAGENO} of {nbpg}', 'font-family' => 'sans', 'font-style' => '', 'font-size' => '9'], 'line' => 1]; $mpdf->SetFooter($header, 'O'); $mpdf->SetDisplayMode('fullpage'); $mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list $mpdf->WriteHTML($html); $mpdf->Output($this->id . '_' . date('YmdHis') . '.pdf', 'D'); exit; }
/** * getAssetsNotAcceptedYet * * @return array * @author Vincent Sposato <*****@*****.**> * @version v1.0 */ protected function getAssetsNotAcceptedYet() { return Asset::unaccepted(); }
public static function detailedAssetList() { $assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::all(), 'assets.company_id')->lists('detailed_name', 'id')->toArray(); return $assets; }
/** * Get the asset information to present to the model view detail page * * @author [A. Gianotto] [<*****@*****.**>] * @since [v2.0] * @param int $modelId * @return String JSON */ public function getDataView($modelID) { $assets = Asset::where('model_id', '=', $modelID)->with('company'); if (Input::has('search')) { $assets = $assets->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } $allowed_columns = ['name', 'serial', 'asset_tag']; $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at'; $assets = $assets->orderBy($sort, $order); $assetsCount = $assets->count(); $assets = $assets->skip($offset)->take($limit)->get(); $rows = array(); foreach ($assets as $asset) { $actions = ''; if ($asset->assetstatus) { if ($asset->assetstatus->deployable != 0) { if ($asset->assigned_to != '' && $asset->assigned_to > 0) { $actions = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm">' . trans('general.checkin') . '</a>'; } else { $actions = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm">' . trans('general.checkout') . '</a>'; } } } $rows[] = array('id' => $asset->id, 'name' => (string) link_to('/hardware/' . $asset->id . '/view', $asset->showAssetName()), 'asset_tag' => (string) link_to('hardware/' . $asset->id . '/view', $asset->asset_tag), 'serial' => $asset->serial, 'assigned_to' => $asset->assigned_to ? (string) link_to('/admin/users/' . $asset->assigned_to . '/view', $asset->assigneduser->fullName()) : '', 'actions' => $actions, 'companyName' => Company::getName($asset)); } $data = array('total' => $assetsCount, 'rows' => $rows); return $data; }
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); } }
/** * Validates and stores the license checkout action. * * @todo Switch to using a FormRequest for validation here. * @author [A. Gianotto] [<*****@*****.**>] * @since [v1.0] * @param int $seatId * @return Redirect */ public function postCheckout($seatId) { $licenseseat = LicenseSeat::find($seatId); $assigned_to = e(Input::get('assigned_to')); $asset_id = e(Input::get('asset_id')); $user = Auth::user(); if (!Company::isCurrentUserHasAccess($licenseseat->license)) { return redirect()->to('admin/licenses')->with('error', trans('general.insufficient_permissions')); } // Declare the rules for the form validation $rules = array('note' => 'string', 'asset_id' => 'required_without:assigned_to'); // Create a new validator instance from our validation rules $validator = Validator::make(Input::all(), $rules); // If validation fails, we'll exit the operation now. if ($validator->fails()) { // Ooops.. something went wrong return redirect()->back()->withInput()->withErrors($validator); } if ($assigned_to != '') { // Check if the user exists if (is_null($is_assigned_to = User::find($assigned_to))) { // Redirect to the asset management page with error return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.user_does_not_exist')); } } if ($asset_id != '') { if (is_null($asset = Asset::find($asset_id))) { // Redirect to the asset management page with error return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.asset_does_not_exist')); } if ($asset->assigned_to != '' && $asset->assigned_to != $assigned_to && $assigned_to != '') { return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.owner_doesnt_match_asset')); } } // Check if the asset exists if (is_null($licenseseat)) { // Redirect to the asset management page with error return redirect()->to('admin/licenses')->with('error', trans('admin/licenses/message.not_found')); } if (Input::get('asset_id') == '') { $licenseseat->asset_id = null; } else { $licenseseat->asset_id = e(Input::get('asset_id')); } // Update the asset data if (e(Input::get('assigned_to')) == '') { $licenseseat->assigned_to = null; } else { $licenseseat->assigned_to = e(Input::get('assigned_to')); } // Was the asset updated? if ($licenseseat->save()) { $logaction = new Actionlog(); //$logaction->location_id = $assigned_to->location_id; $logaction->asset_type = 'software'; $logaction->user_id = Auth::user()->id; $logaction->note = e(Input::get('note')); $logaction->asset_id = $licenseseat->license_id; $license = License::find($licenseseat->license_id); $settings = Setting::getSettings(); // Update the asset data if (e(Input::get('assigned_to')) == '') { $logaction->checkedout_to = null; $slack_msg = strtoupper($logaction->asset_type) . ' license <' . config('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked out to <' . config('app.url') . '/hardware/' . $asset->id . '/view|' . $asset->showAssetName() . '> by <' . config('app.url') . '/admin/users/' . $user->id . '/view' . '|' . $user->fullName() . '>.'; } else { $logaction->checkedout_to = e(Input::get('assigned_to')); $slack_msg = strtoupper($logaction->asset_type) . ' license <' . config('app.url') . '/admin/licenses/' . $license->id . '/view' . '|' . $license->name . '> checked out to <' . config('app.url') . '/admin/users/' . $user->id . '/view|' . $is_assigned_to->fullName() . '> by <' . config('app.url') . '/admin/users/' . $user->id . '/view' . '|' . $user->fullName() . '>.'; } 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' => $slack_msg], ['title' => 'Note:', 'value' => e($logaction->note)]]])->send('License Checked Out'); } catch (Exception $e) { } } $log = $logaction->logaction('checkout'); // Redirect to the new asset page return redirect()->to("admin/licenses")->with('success', trans('admin/licenses/message.checkout.success')); } // Redirect to the asset management page with error return redirect()->to('admin/licenses/$assetId/checkout')->with('error', trans('admin/licenses/message.create.error'))->with('license', new License()); }
/** * 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')); }
/** * Returns a JSON response that contains the assets association with the * selected location, to be used by the location detail view. * * @todo This is broken for accessories and consumables. * @todo This is a very naive implementation. Should clean this up with query scopes. * @author [A. Gianotto] [<*****@*****.**>] * @see LocationsController::getView() method that creates the display view * @param int $locationID * @since [v1.8] * @return View */ public function getDataViewAssets($locationID) { $location = Location::find($locationID)->load('assignedassets.model'); $assets = Asset::AssetsByLocation($location); if (Input::has('search')) { $assets = $assets->TextSearch(e(Input::get('search'))); } $assets = $assets->get(); $rows = array(); foreach ($assets as $asset) { $rows[] = array('name' => (string) link_to(config('app.url') . '/hardware/' . $asset->id . '/view', e($asset->showAssetName())), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), 'model' => e($asset->model->name)); } $data = array('total' => $assets->count(), 'rows' => $rows); return $data; }
/** * Deletes the specified asset. * * @param int|string $id * * @return bool */ public function destroy($id) { $asset = $this->asset->findOrFail($id); return $asset->delete(); }
$mahasiswa = Student::first(); $dosen = Lecturer::first(); $saya = Member::where('name', 'Saya')->first(); $kamu = Member::where('name', 'Kamu')->first(); $dosen->member()->save($saya); $mahasiswa->member()->save($kamu); dump($kamu->person); dump($saya->person); }); Route::get('coba_asset', function () { // Asset::create(['name' => 'meja']); // Asset::create(['name' => 'kursi']); // Asset::create(['name' => 'lemari']); $member = Member::first(); $assets = Asset::get(); $array = [1, 2, 3, 4]; $collection = collect($array); $reverse = $collection->reverse(); $asset_ids = $assets->pluck('id')->all(); // dd($asset_ids); // $asset = Asset::first(); $member->assets()->sync($asset_ids); // $member->assets()->detach($asset); // $member->assets()->attach($asset); dump($member->assets); $user->person; // Mahasiswa // Dosen dump(Asset::get()->toArray()); dump(Member::get()->toArray()); });
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('web-importer')) { $logFile = $this->option('logfile'); \Log::useFiles($logFile); if ($this->option('testrun')) { $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } else { $this->comment('======= Importing Assets from ' . $filename . ' ========='); } } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $results = $csv->fetchAssoc(); $newarray = null; foreach ($results as $index => $arraytoNormalize) { $internalnewarray = array_change_key_case($arraytoNormalize); $newarray[$index] = $internalnewarray; } $this->locations = Location::All(['name', 'id']); $this->categories = Category::All(['name', 'category_type', 'id']); $this->manufacturers = Manufacturer::All(['name', 'id']); $this->asset_models = AssetModel::All(['name', 'modelno', 'category_id', 'manufacturer_id', 'id']); $this->companies = Company::All(['name', 'id']); $this->status_labels = Statuslabel::All(['name', 'id']); $this->suppliers = Supplier::All(['name', 'id']); $this->assets = Asset::all(['asset_tag']); $this->accessories = Accessory::All(['name']); $this->consumables = Consumable::All(['name']); $this->customfields = CustomField::All(['name']); $bar = null; if (!$this->option('web-importer')) { $bar = $this->output->createProgressBar(count($newarray)); } // Loop through the records DB::transaction(function () use(&$newarray, $bar) { Model::unguard(); $item_type = strtolower($this->option('item-type')); foreach ($newarray as $row) { // Let's just map some of these entries to more user friendly words // Fetch general items here, fetch item type specific items in respective methods /** @var Asset, License, Accessory, or Consumable $item_type */ $item_category = $this->array_smart_fetch($row, "category"); $item_company_name = $this->array_smart_fetch($row, "company"); $item_location = $this->array_smart_fetch($row, "location"); $item_status_name = $this->array_smart_fetch($row, "status"); $item["item_name"] = $this->array_smart_fetch($row, "item name"); if ($this->array_smart_fetch($row, "purchase date") != '') { $item["purchase_date"] = date("Y-m-d 00:00:01", strtotime($this->array_smart_fetch($row, "purchase date"))); } else { $item["purchase_date"] = null; } $item["purchase_cost"] = $this->array_smart_fetch($row, "purchase cost"); $item["order_number"] = $this->array_smart_fetch($row, "order number"); $item["notes"] = $this->array_smart_fetch($row, "notes"); $item["quantity"] = $this->array_smart_fetch($row, "quantity"); $item["requestable"] = $this->array_smart_fetch($row, "requestable"); $item["asset_tag"] = $this->array_smart_fetch($row, "asset tag"); $this->current_assetId = $item["item_name"]; if ($item["asset_tag"] != '') { $this->current_assetId = $item["asset_tag"]; } $this->log('Category: ' . $item_category); $this->log('Location: ' . $item_location); $this->log('Purchase Date: ' . $item["purchase_date"]); $this->log('Purchase Cost: ' . $item["purchase_cost"]); $this->log('Company Name: ' . $item_company_name); $this->log('Status: ' . $item_status_name); $item["user"] = $this->createOrFetchUser($row); $item["location"] = $this->createOrFetchLocation($item_location); $item["category"] = $this->createOrFetchCategory($item_category, $item_type); $item["manufacturer"] = $this->createOrFetchManufacturer($row); $item["company"] = $this->createOrFetchCompany($item_company_name); $item["status_label"] = $this->createOrFetchStatusLabel($item_status_name); switch ($item_type) { case "asset": // ----------------------------- // CUSTOM FIELDS // ----------------------------- // Loop through custom fields in the database and see if we have any matches in the CSV foreach ($this->customfields as $customfield) { if ($item['custom_fields'][$customfield->db_column_name()] = $this->array_smart_custom_field_fetch($row, $customfield)) { $this->log('Custom Field ' . $customfield->name . ': ' . $this->array_smart_custom_field_fetch($row, $customfield)); } } $this->createAssetIfNotExists($row, $item); break; case "accessory": $this->createAccessoryIfNotExists($item); break; case 'consumable': $this->createConsumableIfNotExists($item); break; } if (!$this->option('web-importer')) { $bar->advance(); } $this->log('------------- Action Summary ----------------'); } }); if (!$this->option('web-importer')) { $bar->finish(); } $this->log('====================================='); if (!$this->option('web-importer')) { if (!empty($this->errors)) { $this->comment("The following Errors were encountered."); foreach ($this->errors as $asset => $error) { $this->comment('Error: Item: ' . $asset . 'failed validation: ' . json_encode($error)); } } else { $this->comment("All Items imported successfully!"); } } else { if (empty($this->errors)) { return 0; } else { $this->comment(json_encode($this->errors)); //Send a big string to the return 1; } } $this->comment(""); return 2; }
/** * Return JSON containing a list of assets assigned to a user. * * @author [A. Gianotto] [<*****@*****.**>] * @since [v3.0] * @return string JSON */ public function getAssetList($userId) { $assets = Asset::where('assigned_to', '=', $userId)->with('model')->get(); return response()->json($assets); }
public function postBulkCheckout(Request $request) { $this->validate($request, ["assigned_to" => 'required']); $user = User::find(e(Input::get('assigned_to'))); $admin = Auth::user(); $asset_ids = array_filter(Input::get('selected_assets')); if (Input::has('checkout_at') && Input::get('checkout_at') != date("Y-m-d")) { $checkout_at = e(Input::get('checkout_at')); } else { $checkout_at = date("Y-m-d H:i:s"); } if (Input::has('expected_checkin')) { $expected_checkin = e(Input::get('expected_checkin')); } else { $expected_checkin = ''; } $has_errors = false; $errors = []; DB::transaction(function () use($user, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids) { foreach ($asset_ids as $asset_id) { $asset = Asset::find($asset_id); $error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null); if ($error) { $has_errors = true; array_merge_recursive($errors, $asset->getErrors()->toArray()); } } }); if (!$errors) { // Redirect to the new asset page return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success')); } // Redirect to the asset management page with error return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors); }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing Assets from ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; // Let's just map some of these entries to more user friendly words // User's name if (array_key_exists('0', $row)) { $user_name = trim($row[0]); } else { $user_name = ''; } // User's email if (array_key_exists('1', $row)) { $user_email = trim($row[1]); } else { $user_email = ''; } // User's email if (array_key_exists('2', $row)) { $user_username = trim($row[2]); } else { $user_username = ''; } // Asset Name if (array_key_exists('3', $row)) { $user_asset_asset_name = trim($row[3]); } else { $user_asset_asset_name = ''; } // Asset Category if (array_key_exists('4', $row)) { $user_asset_category = trim($row[4]); } else { $user_asset_category = ''; } // Asset Name if (array_key_exists('5', $row)) { $user_asset_name = trim($row[5]); } else { $user_asset_name = ''; } // Asset Manufacturer if (array_key_exists('6', $row)) { $user_asset_mfgr = trim($row[6]); } else { $user_asset_mfgr = ''; } // Asset model number if (array_key_exists('7', $row)) { $user_asset_modelno = trim($row[7]); } else { $user_asset_modelno = ''; } // Asset serial number if (array_key_exists('8', $row)) { $user_asset_serial = trim($row[8]); } else { $user_asset_serial = ''; } // Asset tag if (array_key_exists('9', $row)) { $user_asset_tag = trim($row[9]); } else { $user_asset_tag = ''; } // Asset location if (array_key_exists('10', $row)) { $user_asset_location = trim($row[10]); } else { $user_asset_location = ''; } // Asset notes if (array_key_exists('11', $row)) { $user_asset_notes = trim($row[11]); } else { $user_asset_notes = ''; } // Asset purchase date if (array_key_exists('12', $row)) { if ($row[12] != '') { $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12])); } else { $user_asset_purchase_date = ''; } } else { $user_asset_purchase_date = ''; } // Asset purchase cost if (array_key_exists('13', $row)) { if ($row[13] != '') { $user_asset_purchase_cost = trim($row[13]); } else { $user_asset_purchase_cost = ''; } } else { $user_asset_purchase_cost = ''; } // Asset Company Name if (array_key_exists('14', $row)) { if ($row[14] != '') { $user_asset_company_name = trim($row[14]); } else { $user_asset_company_name = ''; } } else { $user_asset_company_name = ''; } // A number was given instead of a name if (is_numeric($user_name)) { $this->comment('User ' . $user_name . ' is not a name - assume this user already exists'); $user_username = ''; $first_name = ''; $last_name = ''; // No name was given } elseif ($user_name == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); $first_name = ''; $last_name = ''; //$user_username = ''; } else { $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name); $first_name = $user_email_array['first_name']; $last_name = $user_email_array['last_name']; if ($user_email == '') { $user_email = $user_email_array['username'] . '@' . config('app.domain'); } if ($user_username == '') { if ($this->option('username_format') == 'email') { $user_username = $user_email; } else { $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name); $user_username = $user_name_array['username']; } } } $this->comment('Full Name: ' . $user_name); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Username: '******'Email: ' . $user_email); $this->comment('Category Name: ' . $user_asset_category); $this->comment('Item: ' . $user_asset_name); $this->comment('Manufacturer ID: ' . $user_asset_mfgr); $this->comment('Model No: ' . $user_asset_modelno); $this->comment('Serial No: ' . $user_asset_serial); $this->comment('Asset Tag: ' . $user_asset_tag); $this->comment('Location: ' . $user_asset_location); $this->comment('Purchase Date: ' . $user_asset_purchase_date); $this->comment('Purchase Cost: ' . $user_asset_purchase_cost); $this->comment('Notes: ' . $user_asset_notes); $this->comment('Company Name: ' . $user_asset_company_name); $this->comment('------------- Action Summary ----------------'); if ($user_username != '') { if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) { $this->comment('User ' . $user_username . ' already exists'); } else { $user = new \App\Models\User(); $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $user->first_name = $first_name; $user->last_name = $last_name; $user->username = $user_username; $user->email = $user_email; $user->permissions = '{user":1}'; $user->password = bcrypt($password); $user->activated = 1; if ($user->save()) { $this->comment('User ' . $first_name . ' created'); } else { $this->error('ERROR CREATING User ' . $first_name . ' ' . $last_name); $this->error($user->getErrors()); } } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', e($user_asset_location))->first()) { $this->comment('Location ' . $user_asset_location . ' already exists'); } else { $location = new Location(); if ($user_asset_location != '') { $location->name = e($user_asset_location); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $user_asset_location . ' was created'); } else { $this->error('Something went wrong! Location ' . $user_asset_location . ' was NOT created'); $this->error($location->getErrors()); } } else { $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only'); } } else { $this->comment('No location given, so none created.'); } } if (e($user_asset_category) == '') { $category_name = 'Unnamed Category'; } else { $category_name = e($user_asset_category); } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) { $this->comment('Category ' . $category_name . ' already exists'); } else { $category = new Category(); $category->name = e($category_name); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $user_asset_category . ' was created'); } else { $this->error('Something went wrong! Category ' . $user_asset_category . ' was NOT created'); $this->error($category->getErrors()); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($user_asset_mfgr); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created'); } else { $this->error('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created: ' . $manufacturer->getErrors()->first()); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = AssetModel::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists'); } else { $asset_model = new AssetModel(); $asset_model->name = e($user_asset_name); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($user_asset_modelno); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created'); } else { $this->error('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created: ' . $asset_model->getErrors()->first()); } } // Check for the asset company match and create it if it doesn't exist if ($user_asset_company_name != '') { if ($company = Company::where('name', e($user_asset_company_name))->first()) { $this->comment('Company ' . $user_asset_company_name . ' already exists'); } else { $company = new Company(); $company->name = e($user_asset_company_name); if ($company->save()) { $this->comment('Company ' . $user_asset_company_name . ' was created'); } else { $this->error('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created: ' . $company->getErrors()->first()); } } } else { $company = new Company(); } // Check for the asset match and create it if it doesn't exist if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) { $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists'); } else { $asset = new Asset(); $asset->name = e($user_asset_asset_name); if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = null; } if ($user_asset_purchase_cost != '') { $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost)); } else { $asset->purchase_cost = 0.0; } $asset->serial = e($user_asset_serial); $asset->asset_tag = e($user_asset_tag); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; $asset->company_id = $company->id; if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = null; } $asset->notes = e($user_asset_notes); if ($asset->save()) { $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created'); } else { $this->error('Something went wrong! Asset ' . $user_asset_name . ' was NOT created: ' . $asset->getErrors()->first()); } } $this->comment('====================================='); return true; }); }
/** * Returns a new form for work orders. * * @param WorkOrder $workOrder * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder) { return $this->form->of('work-orders', function (FormGrid $form) use($workOrder) { if ($workOrder->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.update', [$workOrder->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.store'); $form->submit = 'Create'; } $form->with($workOrder); $form->attributes(compact('method', 'url')); $form->fieldset(function (Fieldset $fieldset) { $fieldset->control('select', 'category')->value(function (WorkOrder $workOrder) { return $workOrder->category_id; })->options(function () { return Category::getSelectHierarchy('work-orders'); }); $fieldset->control('select', 'location')->value(function (WorkOrder $workOrder) { return $workOrder->location_id; })->options(function () { return Location::getSelectHierarchy(); }); $fieldset->control('select', 'status')->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; }); $fieldset->control('select', 'priority')->value(function (WorkOrder $workOrder) { return $workOrder->priority_id; })->options(function () { $priorities = Priority::all()->pluck('name', 'id'); $priorities[0] = 'None'; return $priorities; }); $fieldset->control('select', 'assets[]')->label('Assets')->options(function () { return Asset::all()->pluck('name', 'id'); })->attributes(['class' => 'select2', 'multiple' => true]); $fieldset->control('input:text', 'subject')->attributes(['placeholder' => 'ex. Worked on HVAC']); $fieldset->control('input:textarea', 'description'); }); }); }
/** * Generates the JSON used to display the asset listing. * * @author [A. Gianotto] [<*****@*****.**>] * @param string $status * @since [v2.0] * @return String JSON */ public function getDatatable($status = null) { $assets = Asset::select('assets.*')->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company')->Hardware(); if (Input::has('search')) { $assets = $assets->TextSearch(e(Input::get('search'))); } if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { $offset = 0; } if (Input::has('limit')) { $limit = e(Input::get('limit')); } else { $limit = 50; } if (Input::has('order_number')) { $assets->where('order_number', '=', e(Input::get('order_number'))); } switch ($status) { case 'Deleted': $assets->withTrashed()->Deleted(); break; case 'Pending': $assets->Pending(); break; case 'RTD': $assets->RTD(); break; case 'Undeployable': $assets->Undeployable(); break; case 'Archived': $assets->Archived(); break; case 'Requestable': $assets->RequestableAssets(); break; case 'Deployed': $assets->Deployed(); break; } $allowed_columns = ['id', 'name', 'asset_tag', 'serial', 'model', 'model_number', 'last_checkout', 'category', 'manufacturer', 'notes', 'expected_checkin', 'order_number', 'companyName', 'location', 'image', 'status_label', 'assigned_to', 'created_at', 'purchase_date', 'purchase_cost']; $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load foreach ($all_custom_fields as $field) { $allowed_columns[] = $field->db_column_name(); } $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'asset_tag'; switch ($sort) { case 'model': $assets = $assets->OrderModels($order); break; case 'model_number': $assets = $assets->OrderModelNumber($order); break; case 'category': $assets = $assets->OrderCategory($order); break; case 'manufacturer': $assets = $assets->OrderManufacturer($order); break; case 'companyName': $assets = $assets->OrderCompany($order); break; case 'location': $assets = $assets->OrderLocation($order); break; case 'status_label': $assets = $assets->OrderStatus($order); break; case 'assigned_to': $assets = $assets->OrderAssigned($order); break; default: $assets = $assets->orderBy($sort, $order); break; } $assetCount = $assets->count(); $assets = $assets->skip($offset)->take($limit)->get(); $rows = array(); foreach ($assets as $asset) { $inout = ''; $actions = ''; if ($asset->deleted_at == '') { $actions = '<div style=" white-space: nowrap;"><a href="' . route('clone/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Clone asset" data-toggle="tooltip"><i class="fa fa-clone"></i></a> <a href="' . route('update/hardware', $asset->id) . '" class="btn btn-warning btn-sm" title="Edit asset" data-toggle="tooltip"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/hardware', $asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->asset_tag) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>'; } elseif ($asset->model->deleted_at == '') { $actions = '<a href="' . route('restore/hardware', $asset->id) . '" title="Restore asset" data-toggle="tooltip" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>'; } if ($asset->assetstatus) { if ($asset->assetstatus->deployable != 0 && $asset->deleted_at == '') { if ($asset->assigned_to != '' && $asset->assigned_to > 0) { $inout = '<a href="' . route('checkin/hardware', $asset->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>'; } else { $inout = '<a href="' . route('checkout/hardware', $asset->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>'; } } } $row = array('checkbox' => '<div class="text-center"><input type="checkbox" name="edit_asset[' . $asset->id . ']" class="one_required"></div>', 'id' => $asset->id, 'image' => $asset->image && $asset->image != '' ? '<img src="' . config('app.url') . '/uploads/assets/' . $asset->image . '" height=50 width=50>' : ($asset->model && $asset->model->image != '' ? '<img src="' . config('app.url') . '/uploads/models/' . $asset->model->image . '" height=40 width=50>' : ''), 'name' => '<a title="' . e($asset->name) . '" href="hardware/' . $asset->id . '/view">' . e($asset->name) . '</a>', 'asset_tag' => '<a title="' . e($asset->asset_tag) . '" href="hardware/' . $asset->id . '/view">' . e($asset->asset_tag) . '</a>', 'serial' => e($asset->serial), 'model' => $asset->model ? (string) link_to('/hardware/models/' . $asset->model->id . '/view', e($asset->model->name)) : 'No model', 'model_number' => $asset->model && $asset->model->modelno ? (string) $asset->model->modelno : '', 'status_label' => $asset->assigneduser ? 'Deployed' : (e($asset->assetstatus) ? e($asset->assetstatus->name) : ''), 'assigned_to' => $asset->assigneduser ? (string) link_to(config('app.url') . '/admin/users/' . $asset->assigned_to . '/view', e($asset->assigneduser->fullName())) : '', 'location' => $asset->assigneduser && $asset->assigneduser->userloc != '' ? (string) link_to('admin/settings/locations/' . $asset->assigneduser->userloc->id . '/view', e($asset->assigneduser->userloc->name)) : ($asset->defaultLoc != '' ? (string) link_to('admin/settings/locations/' . $asset->defaultLoc->id . '/edit', e($asset->defaultLoc->name)) : ''), 'category' => $asset->model && $asset->model->category ? (string) link_to('/admin/settings/categories/' . $asset->model->category->id . '/view', e($asset->model->category->name)) : '', 'manufacturer' => $asset->model && $asset->model->manufacturer ? (string) link_to('/admin/settings/manufacturers/' . $asset->model->manufacturer->id . '/view', e($asset->model->manufacturer->name)) : '', 'eol' => $asset->eol_date() ? $asset->eol_date() : '', 'purchase_cost' => $asset->purchase_cost ? number_format($asset->purchase_cost, 2) : '', 'purchase_date' => $asset->purchase_date ? $asset->purchase_date : '', 'notes' => e($asset->notes), 'order_number' => $asset->order_number != '' ? '<a href="' . config('app.url') . '/hardware?order_number=' . e($asset->order_number) . '">' . e($asset->order_number) . '</a>' : '', 'last_checkout' => $asset->last_checkout != '' ? e($asset->last_checkout) : '', 'expected_checkin' => $asset->expected_checkin != '' ? e($asset->expected_checkin) : '', 'created_at' => $asset->created_at != '' ? e($asset->created_at->format('F j, Y h:iA')) : '', 'change' => $inout ? $inout : '', 'actions' => $actions ? $actions : '', 'companyName' => is_null($asset->company) ? '' : e($asset->company->name)); foreach ($all_custom_fields as $field) { $row[$field->db_column_name()] = $asset->{$field->db_column_name()}; } $rows[] = $row; } $data = array('total' => $assetCount, 'rows' => $rows); return $data; }
/** * Get auto-increment */ public static function autoincrement_asset() { $settings = \App\Models\Setting::getSettings(); if ($settings->auto_increment_assets == '1') { $asset_tag = \DB::table('assets')->where('physical', '=', '1')->max('id'); if ($settings->zerofill_count > 0) { return $settings->auto_increment_prefix . Asset::zerofill($asset_tag + 1, $settings->zerofill_count); } return $settings->auto_increment_prefix . ($asset_tag + 1); } else { return false; } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $staff = Asset::find($id); $staff->delete(); return redirect()->route('asset.index')->withMessage('Asset Item Deleted')->withStatus('success'); }
/** * Execute the console command. * * @return mixed */ public function handle() { $force = $this->option('force'); if ($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]") || $force == 'true') { /** * Delete assets */ $assets = Asset::whereNotNull('deleted_at')->withTrashed()->get(); $assetcount = $assets->count(); $this->info($assets->count() . ' assets purged.'); $asset_assoc = 0; $asset_maintenances = 0; foreach ($assets as $asset) { $this->info('- Asset "' . $asset->showAssetName() . '" deleted.'); $asset_assoc += $asset->assetlog()->count(); $asset->assetlog()->forceDelete(); $asset_maintenances += $asset->assetmaintenances()->count(); $asset->assetmaintenances()->forceDelete(); $asset->forceDelete(); } $this->info($asset_assoc . ' corresponding log records purged.'); $this->info($asset_maintenances . ' corresponding maintenance records purged.'); $locations = Location::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($locations->count() . ' locations purged.'); foreach ($locations as $location) { $this->info('- Location "' . $location->name . '" deleted.'); $location->forceDelete(); } $accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get(); $accessory_assoc = 0; $this->info($accessories->count() . ' accessories purged.'); foreach ($accessories as $accessory) { $this->info('- Accessory "' . $accessory->name . '" deleted.'); $accessory_assoc += $accessory->assetlog()->count(); $accessory->assetlog()->forceDelete(); $accessory->forceDelete(); } $this->info($accessory_assoc . ' corresponding log records purged.'); $consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($consumables->count() . ' consumables purged.'); foreach ($consumables as $consumable) { $this->info('- Consumable "' . $consumable->name . '" deleted.'); $consumable->assetlog()->forceDelete(); $consumable->forceDelete(); } $components = Component::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($components->count() . ' components purged.'); foreach ($components as $component) { $this->info('- Component "' . $component->name . '" deleted.'); $component->assetlog()->forceDelete(); $component->forceDelete(); } $licenses = License::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($licenses->count() . ' licenses purged.'); foreach ($licenses as $license) { $this->info('- License "' . $license->name . '" deleted.'); $license->assetlog()->forceDelete(); $license->licenseseats()->forceDelete(); $license->forceDelete(); } $models = AssetModel::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($models->count() . ' asset models purged.'); foreach ($models as $model) { $this->info('- Asset Model "' . $model->name . '" deleted.'); $model->forceDelete(); } $categories = Category::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($categories->count() . ' categories purged.'); foreach ($categories as $category) { $this->info('- Category "' . $category->name . '" deleted.'); $category->forceDelete(); } $suppliers = Supplier::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($suppliers->count() . ' suppliers purged.'); foreach ($suppliers as $supplier) { $this->info('- Supplier "' . $supplier->name . '" deleted.'); $supplier->forceDelete(); } $users = User::whereNotNull('deleted_at')->where('show_in_list', '!=', '0')->withTrashed()->get(); $this->info($users->count() . ' users purged.'); $user_assoc = 0; foreach ($users as $user) { $this->info('- User "' . $user->username . '" deleted.'); $user_assoc += $user->userlog()->count(); $user->userlog()->forceDelete(); $user->forceDelete(); } $this->info($user_assoc . ' corresponding user log records purged.'); $manufacturers = Manufacturer::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($manufacturers->count() . ' manufacturers purged.'); foreach ($manufacturers as $manufacturer) { $this->info('- Manufacturer "' . $manufacturer->name . '" deleted.'); $manufacturer->forceDelete(); } $status_labels = Statuslabel::whereNotNull('deleted_at')->withTrashed()->get(); $this->info($status_labels->count() . ' status labels purged.'); foreach ($status_labels as $status_label) { $this->info('- Status Label "' . $status_label->name . '" deleted.'); $status_label->forceDelete(); } } else { $this->info('Action canceled. Nothing was purged.'); } }
/** * Return JSON containing a list of assets assigned to a user. * * @author [A. Gianotto] [<*****@*****.**>] * @since [v3.0] * @return string JSON */ public function getAssetList($userId) { $assets = Asset::where('assigned_to', '=', $userId)->get(); return response()->json($assets); //$foo = Asset::where('assigned_to','=',$userId)->get(); //print_r($foo); }