/** * Returns a form view to edit a selected 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 getEdit($assetMaintenanceId = null) { // Check if the asset maintenance exists if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) { // Redirect to the improvement 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 ($assetMaintenance->completion_date == '0000-00-00') { $assetMaintenance->completion_date = null; } if ($assetMaintenance->start_date == '0000-00-00') { $assetMaintenance->start_date = null; } if ($assetMaintenance->cost == '0.00') { $assetMaintenance->cost = null; } // Prepare Improvement Type List $assetMaintenanceType = ['' => 'Select an improvement type'] + AssetMaintenance::getImprovementOptions(); $assets = Company::scopeCompanyables(Asset::with('model', 'assignedUser')->get(), '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', $assets)->with('selectedAsset', null)->with('supplier_list', $supplier_list)->with('assetMaintenanceType', $assetMaintenanceType)->with('assetMaintenance', $assetMaintenance); }
/** * Exports the depreciations to CSV * * @deprecated Server-side exports have been replaced by datatables export since v2. * @author [A. Gianotto] [<*****@*****.**>] * @since [v1.0] * @return \Illuminate\Http\Response */ public function exportDeprecationReport() { // Grab all the assets $assets = Asset::with('model', 'assigneduser', 'assetstatus', 'defaultLoc', 'assetlog')->orderBy('created_at', 'DESC')->get(); $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject()); $csv->setOutputBOM(Reader::BOM_UTF16_BE); $rows = []; // Create the header row $header = [trans('admin/hardware/table.asset_tag'), trans('admin/hardware/table.title'), trans('admin/hardware/table.serial'), trans('admin/hardware/table.checkoutto'), trans('admin/hardware/table.location'), trans('admin/hardware/table.purchase_date'), trans('admin/hardware/table.purchase_cost'), trans('admin/hardware/table.book_value'), trans('admin/hardware/table.diff')]; //we insert the CSV header $csv->insertOne($header); // Create a row per asset foreach ($assets as $asset) { $row = []; $row[] = e($asset->asset_tag); $row[] = e($asset->name); $row[] = e($asset->serial); if ($asset->assigned_to > 0) { $user = User::find($asset->assigned_to); $row[] = e($user->fullName()); } else { $row[] = ''; // Empty string if unassigned } if ($asset->assigned_to > 0 && $asset->assigneduser->location_id > 0) { $location = Location::find($asset->assigneduser->location_id); if ($location->city) { $row[] = e($location->city) . ', ' . e($location->state); } elseif ($location->name) { $row[] = e($location->name); } else { $row[] = ''; } } else { $row[] = ''; // Empty string if location is not set } if ($asset->assetloc) { $currency = e($asset->assetloc->currency); } else { $currency = e(Setting::first()->default_currency); } $row[] = $asset->purchase_date; $row[] = $currency . Helper::formatCurrencyOutput($asset->purchase_cost); $row[] = $currency . Helper::formatCurrencyOutput($asset->getDepreciatedValue()); $row[] = $currency . Helper::formatCurrencyOutput($asset->purchase_cost - $asset->getDepreciatedValue()); $csv->insertOne($row); } $csv->output('depreciation-report-' . date('Y-m-d') . '.csv'); die; }
/** * Display the bulk edit page. * * @author [A. Gianotto] [<*****@*****.**>] * @param int $assetId * @since [v2.0] * @return View */ public function postBulkEdit($assets = null) { if (!Company::isCurrentUserAuthorized()) { return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions')); } elseif (!Input::has('edit_asset')) { return redirect()->back()->with('error', 'No assets selected'); } else { $asset_raw_array = Input::get('edit_asset'); foreach ($asset_raw_array as $asset_id => $value) { $asset_ids[] = $asset_id; } } if (Input::has('bulk_actions')) { // Create labels if (Input::get('bulk_actions') == 'labels') { $settings = Setting::getSettings(); $assets = Asset::find($asset_ids); $count = 0; return View::make('hardware/labels')->with('assets', $assets)->with('settings', $settings)->with('count', $count)->with('settings', $settings); } elseif (Input::get('bulk_actions') == 'delete') { $assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids); return View::make('hardware/bulk-delete')->with('assets', $assets); // Bulk edit } elseif (Input::get('bulk_actions') == 'edit') { $assets = Input::get('edit_asset'); $supplier_list = Helper::suppliersList(); $statuslabel_list = Helper::statusLabelList(); $location_list = Helper::locationsList(); $models_list = Helper::modelList(); $companies_list = array('' => '') + array('clear' => trans('general.remove_company')) + Helper::companyList(); return View::make('hardware/bulk')->with('assets', $assets)->with('supplier_list', $supplier_list)->with('statuslabel_list', $statuslabel_list)->with('location_list', $location_list)->with('models_list', $models_list)->with('companies_list', $companies_list); } } else { return redirect()->back()->with('error', 'No action selected'); } }
public function getRequestableIndex() { $assets = Asset::with('model', 'defaultLoc', 'assetloc', 'assigneduser')->Hardware()->RequestableAssets()->get(); return View::make('account/requestable-assets', compact('user', 'assets')); }