/** * 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; }