] * @see ManufacturersController::getDatatable() method that generates the JSON response * @since [v1.0] * @return View */ public function index() { // Show the page return View::make('manufacturers/index', compact('manufacturers')); } /** * Returns a view that displays a form to create a new manufacturer. * * @author [A. Gianotto] [] * @see ManufacturersController::postCreate() * @since [v1.0] * @return View */ public function create() { return View::make('manufacturers/edit')->with('item', new Manufacturer); } /** * Validates and stores the data for a new manufacturer. * * @author [A. Gianotto] [] * @see ManufacturersController::postCreate() * @since [v1.0] * @return Redirect */ public function store(Request $request) { $manufacturer = new Manufacturer; $manufacturer->name = e($request->input('name')); $manufacturer->user_id = Auth::user()->id; if ($manufacturer->save()) { return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.create.success')); } return redirect()->back()->withInput()->withErrors($manufacturer->getErrors()); } /** * Returns a view that displays a form to edit a manufacturer. * * @author [A. Gianotto] [] * @see ManufacturersController::postEdit() * @param int $manufacturerId * @since [v1.0] * @return View */ public function edit($manufacturerId = null) { // Check if the manufacturer exists if (is_null($item = Manufacturer::find($manufacturerId))) { // Redirect to the manufacturer page return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist')); } // Show the page return View::make('manufacturers/edit', compact('item')); } /** * Validates and stores the updated manufacturer data. * * @author [A. Gianotto] [] * @see ManufacturersController::getEdit() * @param int $manufacturerId * @since [v1.0] * @return View */ public function update(Request $request, $manufacturerId = null) { // Check if the manufacturer exists if (is_null($manufacturer = Manufacturer::find($manufacturerId))) { // Redirect to the manufacturer page return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist')); } // Save the data $manufacturer->name = e($request->input('name')); // Was it created? if ($manufacturer->save()) { // Redirect to the new manufacturer page return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.update.success')); } return redirect()->back()->withInput()->withErrors($manufacturer->getErrors()); } /** * Deletes a manufacturer. * * @author [A. Gianotto] [] * @param int $manufacturerId * @since [v1.0] * @return View */ public function destroy($manufacturerId) { // Check if the manufacturer exists if (is_null($manufacturer = Manufacturer::find($manufacturerId))) { // Redirect to the manufacturers page return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.not_found')); } if ($manufacturer->has_models() > 0) { // Redirect to the asset management page return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.assoc_users')); } else { // Delete the manufacturer $manufacturer->delete(); // Redirect to the manufacturers management page return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.delete.success')); } } /** * Returns a view that invokes the ajax tables which actually contains * the content for the manufacturers detail listing, which is generated in getDatatable. * This data contains a listing of all assets that belong to that manufacturer. * * @author [A. Gianotto] [] * @see ManufacturersController::getDataView() * @param int $manufacturerId * @since [v1.0] * @return View */ public function show($manufacturerId = null) { $manufacturer = Manufacturer::find($manufacturerId); if (isset($manufacturer->id)) { return View::make('manufacturers/view', compact('manufacturer')); } else { // Prepare the error message $error = trans('admin/manufacturers/message.does_not_exist', compact('id')); // Redirect to the user management page return redirect()->route('manufacturers')->with('error', $error); } } /** * Generates the JSON used to display the manufacturer listings. * * @author [A. Gianotto] [] * @see ManufacturersController::getIndex() * @since [v1.0] * @return String JSON */ public function getDatatable(Request $request) { $manufacturers = Manufacturer::select(array('id','name'))->with('assets') ->whereNull('deleted_at'); if ($request->has('search')) { $manufacturers = $manufacturers->TextSearch(e($request->input('search'))); } if ($request->has('offset')) { $offset = e($request->input('offset')); } else { $offset = 0; } if ($request->has('limit')) { $limit = e($request->input('limit')); } else { $limit = 50; } $allowed_columns = ['id','name']; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $manufacturers->orderBy($sort, $order); $manufacturersCount = $manufacturers->count(); $manufacturers = $manufacturers->skip($offset)->take($limit)->get(); $rows = array(); foreach ($manufacturers as $manufacturer) { $actions = ''; $rows[] = array( 'id' => $manufacturer->id, 'name' => (string)link_to_route('manufacturers.show', e($manufacturer->name),['manufacturer' => $manufacturer->id]), 'assets' => $manufacturer->assets->count(), 'actions' => $actions ); } $data = array('total' => $manufacturersCount, 'rows' => $rows); return $data; } /** * Generates the JSON used to display the manufacturer detail. * This JSON returns data on all of the assets with the specified * manufacturer ID number. * * @author [A. Gianotto] [] * @see ManufacturersController::getView() * @param int $manufacturerId * @since [v1.0] * @return String JSON */ public function getDataView($manufacturerId, $itemtype = null) { $manufacturer = Manufacturer::find($manufacturerId); switch ($itemtype) { case "assets": return $this->getDataAssetsView($manufacturer); case "licenses": return $this->getDataLicensesView($manufacturer); case "accessories": return $this->getDataAccessoriesView($manufacturer); case "consumables": return $this->getDataConsumablesView($manufacturer); } throw new Exception("We shouldn't be here"); } protected function getDataAssetsView(Manufacturer $manufacturer) { $manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company'); $manufacturer_assets = $manufacturer->assets; if ($request->has('search')) { $manufacturer_assets = $manufacturer_assets->TextSearch(e($request->input('search'))); } if ($request->has('offset')) { $offset = e($request->input('offset')); } else { $offset = 0; } if ($request->has('limit')) { $limit = e($request->input('limit')); } else { $limit = 50; } $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $allowed_columns = ['id','name','serial','asset_tag']; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; $count = $manufacturer_assets->count(); $rows = array(); foreach ($manufacturer_assets as $asset) { $actions = ''; if ($asset->deleted_at=='') { $actions = '
'; } elseif ($asset->deleted_at!='') { $actions = ''; } if ($asset->availableForCheckout()) { if (Gate::allows('assets.checkout')) { $inout = ''.trans('general.checkout').''; } } else { if (Gate::allows('assets.checkin')) { $inout = ''.trans('general.checkin').''; } } $rows[] = array( 'id' => $asset->id, 'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())), 'model' => e($asset->model->name), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), 'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '', 'actions' => $actions, // 'companyName' => e(Company::getName($asset)), 'companyName' => is_null($asset->company) ? '' : $asset->company->name ); if (isset($inout)) { $row['change'] = $inout; } } $data = array('total' => $count, 'rows' => $rows); return $data; } protected function getDataLicensesView(Manufacturer $manufacturer) { $manufacturer = $manufacturer->load('licenses.company', 'licenses.manufacturer', 'licenses.licenseSeatsRelation'); $licenses = $manufacturer->licenses; if ($request->has('search')) { $licenses = $licenses->TextSearch($request->input('search')); } $licenseCount = $licenses->count(); $rows = array(); foreach ($licenses as $license) { $actions = ''; if (Gate::allows('licenses.checkout')) { $actions .= '' . trans('general.checkout') . ' '; } if (Gate::allows('licenses.create')) { $actions .= ''; } if (Gate::allows('licenses.edit')) { $actions .= ''; } if (Gate::allows('licenses.delete')) { $actions .= ''; } $actions .=''; $rows[] = array( 'id' => $license->id, 'name' => (string) link_to('/admin/licenses/'.$license->id.'/view', $license->name), 'serial' => (string) link_to('/admin/licenses/'.$license->id.'/view', mb_strimwidth($license->serial, 0, 50, "...")), 'totalSeats' => $license->licenseSeatCount, 'remaining' => $license->remaincount(), 'license_name' => e($license->license_name), 'license_email' => e($license->license_email), 'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '', 'expiration_date' => ($license->expiration_date) ? $license->expiration_date : '', 'purchase_cost' => ($license->purchase_cost) ? number_format($license->purchase_cost, 2) : '', 'purchase_order' => ($license->purchase_order) ? e($license->purchase_order) : '', 'order_number' => ($license->order_number) ? e($license->order_number) : '', 'notes' => ($license->notes) ? e($license->notes) : '', 'actions' => $actions, 'companyName' => is_null($license->company) ? '' : e($license->company->name), 'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : '' ); } $data = array('total' => $licenseCount, 'rows' => $rows); return $data; } public function getDataAccessoriesView(Manufacturer $manufacturer) { $manufacturer = $manufacturer->load( 'accessories.location', 'accessories.company', 'accessories.category', 'accessories.manufacturer', 'accessories.users' ); $accessories = $manufacturer->accessories; if ($request->has('search')) { $accessories = $accessories->TextSearch(e($request->input('search'))); } if ($request->has('limit')) { $limit = e($request->input('limit')); } else { $limit = 50; } $accessCount = $accessories->count(); $rows = array(); foreach ($accessories as $accessory) { $actions = ''; if (Gate::allows('accessories.checkout')) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } if (Gate::allows('accessories.edit')) { $actions .= ''; } if (Gate::allows('accessories.delete')) { $actions .= ''; } $actions .= ''; $company = $accessory->company; $rows[] = array( 'name' => ''. $accessory->name.'', 'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '', 'qty' => e($accessory->qty), 'order_number' => e($accessory->order_number), 'min_amt' => e($accessory->min_amt), 'location' => ($accessory->location) ? e($accessory->location->name): '', 'purchase_date' => e($accessory->purchase_date), 'purchase_cost' => number_format($accessory->purchase_cost, 2), 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), 'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : '' ); } $data = array('total'=>$accessCount, 'rows'=>$rows); return $data; } public function getDataConsumablesView($manufacturer) { $manufacturer = $manufacturer->load( 'consumables.location', 'consumables.company', 'consumables.category', 'consumables.manufacturer', 'consumables.users' ); $consumables = $manufacturer->consumables; if ($request->has('search')) { $consumables = $consumables->TextSearch(e($request->input('search'))); } if ($request->has('limit')) { $limit = e($request->input('limit')); } else { $limit = 50; } $consumCount = $consumables->count(); $rows = array(); foreach ($consumables as $consumable) { $actions = ''; if (Gate::allows('consumables.checkout')) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } if (Gate::allows('consumables.edit')) { $actions .= ''; } if (Gate::allows('consumables.delete')) { $actions .= ''; } $actions .=''; $company = $consumable->company; $rows[] = array( 'id' => $consumable->id, 'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)), 'location' => ($consumable->location) ? e($consumable->location->name) : '', 'min_amt' => e($consumable->min_amt), 'qty' => e($consumable->qty), 'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '', 'model_number' => e($consumable->model_number), 'item_no' => e($consumable->item_no), 'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category', 'order_number' => e($consumable->order_number), 'purchase_date' => e($consumable->purchase_date), 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , 'numRemaining' => $consumable->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), ); } $data = array('total' => $consumCount, 'rows' => $rows); return $data; } }