fix tests

This commit is contained in:
root
2026-06-11 11:46:12 -04:00
parent c91fa2ce4d
commit 5ead80fdc7
1489 changed files with 11349 additions and 10305 deletions
+23 -16
View File
@@ -2,8 +2,8 @@
namespace App\Services\Inventory;
use App\Models\InventoryItem;
use App\Models\InventoryCategory;
use App\Models\InventoryItem;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
@@ -14,8 +14,7 @@ class InventoryItemService
public function __construct(
private InventoryContextService $context,
private InventoryMovementService $movementService
) {
}
) {}
public function list(array $filters = []): array
{
@@ -32,7 +31,7 @@ class InventoryItemService
$builder->where('semester', $semester);
}
if ($q !== '') {
$builder->where('name', 'like', '%' . $q . '%');
$builder->where('name', 'like', '%'.$q.'%');
}
$items = $builder->orderBy('name')->get()->toArray();
@@ -62,6 +61,7 @@ class InventoryItemService
public function find(int $id): ?array
{
$item = InventoryItem::query()->find($id);
return $item ? $item->toArray() : null;
}
@@ -78,10 +78,12 @@ class InventoryItemService
} else {
$this->movementService->recalcQuantity((int) $item->id);
}
return ['ok' => true, 'item' => $item->toArray()];
});
} catch (\Throwable $e) {
Log::error('Inventory item create failed: ' . $e->getMessage());
Log::error('Inventory item create failed: '.$e->getMessage());
return ['ok' => false, 'message' => 'Failed to create item.'];
}
}
@@ -89,7 +91,7 @@ class InventoryItemService
public function update(int $id, array $data, ?int $userId = null): array
{
$item = InventoryItem::query()->find($id);
if (!$item) {
if (! $item) {
return ['ok' => false, 'message' => 'Item not found.'];
}
@@ -99,7 +101,8 @@ class InventoryItemService
try {
$item->update($payload);
} catch (\Throwable $e) {
Log::error('Inventory item update failed: ' . $e->getMessage());
Log::error('Inventory item update failed: '.$e->getMessage());
return ['ok' => false, 'message' => 'Failed to update item.'];
}
@@ -109,14 +112,15 @@ class InventoryItemService
public function delete(int $id): array
{
$item = InventoryItem::query()->find($id);
if (!$item) {
if (! $item) {
return ['ok' => false, 'message' => 'Item not found.'];
}
try {
$item->delete();
} catch (\Throwable $e) {
Log::error('Inventory item delete failed: ' . $e->getMessage());
Log::error('Inventory item delete failed: '.$e->getMessage());
return ['ok' => false, 'message' => 'Failed to delete item.'];
}
@@ -126,7 +130,7 @@ class InventoryItemService
public function auditClassroom(int $itemId, array $data, ?int $userId = null): array
{
$item = InventoryItem::query()->find($itemId);
if (!$item || $item->type !== 'classroom') {
if (! $item || $item->type !== 'classroom') {
return ['ok' => false, 'message' => 'Invalid classroom item.'];
}
@@ -159,7 +163,7 @@ class InventoryItemService
$totalIn += -$deltaMiss;
}
if ($totalOut > 0 && !$this->movementService->recordMovement($itemId, -$totalOut, 'out', 'Audit: loss/missing increased')) {
if ($totalOut > 0 && ! $this->movementService->recordMovement($itemId, -$totalOut, 'out', 'Audit: loss/missing increased')) {
return ['ok' => false, 'message' => 'Not enough stock to apply audit.'];
}
if ($totalIn > 0) {
@@ -182,7 +186,7 @@ class InventoryItemService
public function adjustStock(int $itemId, array $data, ?int $userId = null): array
{
$item = InventoryItem::query()->find($itemId);
if (!$item) {
if (! $item) {
return ['ok' => false, 'message' => 'Item not found.'];
}
@@ -199,7 +203,7 @@ class InventoryItemService
$type = ($mode === 'out') ? 'out' : (($mode === 'in') ? 'in' : 'adjust');
$ok = $this->movementService->recordMovement($itemId, $delta, $type, $reason, $note, null, null, $userId);
if (!$ok) {
if (! $ok) {
return ['ok' => false, 'message' => 'Not enough stock to apply adjustment.'];
}
@@ -242,6 +246,7 @@ class InventoryItemService
private function normalizeType(?string $type): string
{
$type = strtolower((string) $type);
return in_array($type, $this->types, true) ? $type : 'classroom';
}
@@ -267,8 +272,9 @@ class InventoryItemService
} else {
$out = [];
foreach ($ids as $id) {
$out[$id] = 'User #' . $id;
$out[$id] = 'User #'.$id;
}
return $out;
}
@@ -276,8 +282,9 @@ class InventoryItemService
$map = [];
foreach ($rows as $r) {
$disp = trim((string) ($r->display_name ?? ''));
$map[(int) $r->id] = $disp !== '' ? $disp : ('User #' . $r->id);
$map[(int) $r->id] = $disp !== '' ? $disp : ('User #'.$r->id);
}
return $map;
}
@@ -297,7 +304,7 @@ class InventoryItemService
->all();
$currentYear = $this->context->schoolYear();
if ($currentYear && !in_array($currentYear, $years, true)) {
if ($currentYear && ! in_array($currentYear, $years, true)) {
array_unshift($years, $currentYear);
}