/** * Return JSON data to populate the components view, * * @author [A. Gianotto] [<*****@*****.**>] * @see ComponentsController::getView() method that returns the view. * @since [v3.0] * @param int $componentId * @return string JSON */ public function getDataView($componentId) { //$component = Component::find($componentID); $component = Component::with('assets')->find($componentId); if (!Company::isCurrentUserHasAccess($component)) { return ['total' => 0, 'rows' => []]; } $rows = array(); foreach ($component->assets as $component_assignment) { $rows[] = array('name' => (string) link_to('/hardware/' . $component_assignment->id . '/view', e($component_assignment->showAssetName())), 'qty' => e($component_assignment->pivot->assigned_qty), 'created_at' => $component_assignment->created_at->format('Y-m-d H:i:s') == '-0001-11-30 00:00:00' ? '' : $component_assignment->created_at->format('Y-m-d H:i:s')); } $componentCount = $component->assets->count(); $data = array('total' => $componentCount, 'rows' => $rows); return $data; }
/** * This nasty little method gets the low inventory info for the * alert dropdown **/ public static function checkLowInventory() { $consumables = Consumable::with('users')->whereNotNull('min_amt')->get(); $accessories = Accessory::with('users')->whereNotNull('min_amt')->get(); $components = Component::with('assets')->whereNotNull('min_amt')->get(); $avail_consumables = 0; $items_array = array(); $all_count = 0; foreach ($consumables as $consumable) { $avail = $consumable->numRemaining(); if ($avail < $consumable->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($consumable->total_qty > 0) { $percent = number_format($consumable->numRemaining() / $consumable->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $consumable->id; $items_array[$all_count]['name'] = $consumable->name; $items_array[$all_count]['type'] = 'consumables'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $consumable->numRemaining(); $items_array[$all_count]['min_amt'] = $consumable->min_amt; $all_count++; } } foreach ($accessories as $accessory) { $avail = $accessory->numRemaining(); if ($avail < $accessory->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($accessory->total_qty > 0) { $percent = number_format($accessory->numRemaining() / $accessory->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $accessory->id; $items_array[$all_count]['name'] = $accessory->name; $items_array[$all_count]['type'] = 'accessories'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $accessory->numRemaining(); $items_array[$all_count]['min_amt'] = $accessory->min_amt; $all_count++; } } foreach ($components as $component) { $avail = $component->numRemaining(); if ($avail < $component->min_amt + \App\Models\Setting::getSettings()->alert_threshold) { if ($component->total_qty > 0) { $percent = number_format($component->numRemaining() / $component->total_qty * 100, 0); } else { $percent = 100; } $items_array[$all_count]['id'] = $component->id; $items_array[$all_count]['name'] = $component->name; $items_array[$all_count]['type'] = 'components'; $items_array[$all_count]['percent'] = $percent; $items_array[$all_count]['remaining'] = $component->numRemaining(); $items_array[$all_count]['min_amt'] = $component->min_amt; $all_count++; } } return $items_array; }