Skip to content

Commit

Permalink
Merge pull request #15463 from snipe/consumables_order_by_remaining
Browse files Browse the repository at this point in the history
Added ability to sort on qty and remaining for consumables
  • Loading branch information
snipe authored Sep 9, 2024
2 parents e1fcfc8 + 7d9a0eb commit ce97e2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/Api/ConsumablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function index(Request $request) : array
case 'company':
$consumables = $consumables->OrderCompany($order);
break;
case 'remaining':
$consumables = $consumables->OrderRemaining($order);
break;
case 'supplier':
$consumables = $consumables->OrderSupplier($order);
break;
Expand Down
14 changes: 14 additions & 0 deletions app/Models/Consumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ public function scopeOrderCompany($query, $order)
return $query->leftJoin('companies', 'consumables.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
}

/**
* Query builder scope to order on remaining
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param string $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderRemaining($query, $order)
{
$order_by = 'consumables.qty - consumables_users_count ' . $order;
return $query->orderByRaw($order_by);
}

/**
* Query builder scope to order on supplier
*
Expand Down
4 changes: 2 additions & 2 deletions app/Presenters/ConsumablePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public static function dataTableLayout()
], [
'field' => 'qty',
'searchable' => false,
'sortable' => false,
'sortable' => true,
'title' => trans('admin/components/general.total'),
'visible' => true,
], [
'field' => 'remaining',
'searchable' => false,
'sortable' => false,
'sortable' => true,
'title' => trans('admin/components/general.remaining'),
'visible' => true,
], [
Expand Down

0 comments on commit ce97e2a

Please sign in to comment.