Calculate the proper amount of assigned components

This commit is contained in:
Ivan Nieto Vivanco 2022-08-04 07:58:25 -05:00
parent b52c00d49b
commit ea8f12579d

View file

@ -623,7 +623,7 @@ class Helper
{
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
$accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
$components = Component::withCount('assets as assets_count')->whereNotNull('min_amt')->get();
$components = Component::whereNotNull('min_amt')->get();
$avail_consumables = 0;
$items_array = [];
@ -668,7 +668,9 @@ class Helper
}
foreach ($components as $component) {
$avail = $component->qty - $component->assets_count;
$assets_count = \DB::table('components_assets')->where('component_id', $component->id)->sum('assigned_qty');
$avail = $component->qty - $assets_count;
if ($avail < ($component->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
if ($component->qty > 0) {
$percent = number_format((($avail / $component->qty) * 100), 0);