Refactor for fewer queries

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-19 19:27:10 +01:00
parent 5ebf0ed2b2
commit ebf6ce6980

View file

@ -38,7 +38,7 @@ class AccessoriesTransformer
'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost), 'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost),
'order_number' => ($accessory->order_number) ? e($accessory->order_number) : null, 'order_number' => ($accessory->order_number) ? e($accessory->order_number) : null,
'min_qty' => ($accessory->min_amt) ? (int) $accessory->min_amt : null, 'min_qty' => ($accessory->min_amt) ? (int) $accessory->min_amt : null,
'remaining_qty' => (int) $accessory->numRemaining(), 'remaining_qty' => (int) ($accessory->qty - $accessory->checkouts_count),
'checkouts_count' => $accessory->checkouts_count, 'checkouts_count' => $accessory->checkouts_count,
'created_by' => ($accessory->adminuser) ? [ 'created_by' => ($accessory->adminuser) ? [
'id' => (int) $accessory->adminuser->id, 'id' => (int) $accessory->adminuser->id,
@ -60,7 +60,7 @@ class AccessoriesTransformer
$permissions_array['user_can_checkout'] = false; $permissions_array['user_can_checkout'] = false;
if ($accessory->numRemaining() > 0) { if (($accessory->qty - $accessory->checkouts_count) > 0) {
$permissions_array['user_can_checkout'] = true; $permissions_array['user_can_checkout'] = true;
} }