fix gitlab tests
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Services\Inventory;
|
||||
|
||||
use App\Models\InventoryCategory;
|
||||
use App\Models\InventoryItem;
|
||||
use App\Models\InventoryCategory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -14,7 +14,8 @@ class InventoryItemService
|
||||
public function __construct(
|
||||
private InventoryContextService $context,
|
||||
private InventoryMovementService $movementService
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function list(array $filters = []): array
|
||||
{
|
||||
@@ -31,7 +32,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();
|
||||
@@ -61,7 +62,6 @@ class InventoryItemService
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
$item = InventoryItem::query()->find($id);
|
||||
|
||||
return $item ? $item->toArray() : null;
|
||||
}
|
||||
|
||||
@@ -78,12 +78,10 @@ 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.'];
|
||||
}
|
||||
}
|
||||
@@ -91,7 +89,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.'];
|
||||
}
|
||||
|
||||
@@ -101,8 +99,7 @@ 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.'];
|
||||
}
|
||||
|
||||
@@ -112,15 +109,14 @@ 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.'];
|
||||
}
|
||||
|
||||
@@ -130,7 +126,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.'];
|
||||
}
|
||||
|
||||
@@ -163,7 +159,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) {
|
||||
@@ -186,7 +182,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.'];
|
||||
}
|
||||
|
||||
@@ -203,7 +199,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.'];
|
||||
}
|
||||
|
||||
@@ -246,7 +242,6 @@ class InventoryItemService
|
||||
private function normalizeType(?string $type): string
|
||||
{
|
||||
$type = strtolower((string) $type);
|
||||
|
||||
return in_array($type, $this->types, true) ? $type : 'classroom';
|
||||
}
|
||||
|
||||
@@ -272,9 +267,8 @@ class InventoryItemService
|
||||
} else {
|
||||
$out = [];
|
||||
foreach ($ids as $id) {
|
||||
$out[$id] = 'User #'.$id;
|
||||
$out[$id] = 'User #' . $id;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
@@ -282,9 +276,8 @@ 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;
|
||||
}
|
||||
|
||||
@@ -304,7 +297,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user