Fix Pint formatting
This commit is contained in:
@@ -9,9 +9,7 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InventoryMovementService
|
||||
{
|
||||
public function __construct(private InventoryContextService $context)
|
||||
{
|
||||
}
|
||||
public function __construct(private InventoryContextService $context) {}
|
||||
|
||||
public function list(array $filters = []): array
|
||||
{
|
||||
@@ -51,7 +49,7 @@ class InventoryMovementService
|
||||
$qtyChange = (int) ($data['qty_change'] ?? 0);
|
||||
|
||||
$item = InventoryItem::query()->find($itemId);
|
||||
if (!$item) {
|
||||
if (! $item) {
|
||||
return ['ok' => false, 'message' => 'Selected item not found.'];
|
||||
}
|
||||
|
||||
@@ -78,7 +76,8 @@ class InventoryMovementService
|
||||
InventoryMovement::query()->create($payload);
|
||||
$this->recalcQuantity($itemId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory movement create failed: ' . $e->getMessage());
|
||||
Log::error('Inventory movement create failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Could not save movement.'];
|
||||
}
|
||||
|
||||
@@ -88,7 +87,7 @@ class InventoryMovementService
|
||||
public function update(int $id, array $data): array
|
||||
{
|
||||
$movement = InventoryMovement::query()->find($id);
|
||||
if (!$movement) {
|
||||
if (! $movement) {
|
||||
return ['ok' => false, 'message' => 'Movement not found.'];
|
||||
}
|
||||
|
||||
@@ -118,7 +117,8 @@ class InventoryMovementService
|
||||
$movement->update($payload);
|
||||
$this->recalcQuantity($itemId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory movement update failed: ' . $e->getMessage());
|
||||
Log::error('Inventory movement update failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Could not update movement.'];
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class InventoryMovementService
|
||||
public function delete(int $id): array
|
||||
{
|
||||
$movement = InventoryMovement::query()->find($id);
|
||||
if (!$movement) {
|
||||
if (! $movement) {
|
||||
return ['ok' => false, 'message' => 'Movement not found.'];
|
||||
}
|
||||
|
||||
@@ -139,7 +139,8 @@ class InventoryMovementService
|
||||
$this->recalcQuantity($itemId);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory movement delete failed: ' . $e->getMessage());
|
||||
Log::error('Inventory movement delete failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Could not delete movement.'];
|
||||
}
|
||||
|
||||
@@ -169,7 +170,8 @@ class InventoryMovementService
|
||||
$this->recalcQuantity($itemId);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory movement bulk delete failed: ' . $e->getMessage());
|
||||
Log::error('Inventory movement bulk delete failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Bulk delete failed.'];
|
||||
}
|
||||
|
||||
@@ -188,7 +190,7 @@ class InventoryMovementService
|
||||
): bool {
|
||||
$isInitial = ($type === 'initial');
|
||||
|
||||
if (!$isInitial) {
|
||||
if (! $isInitial) {
|
||||
$this->ensureInitialMovement($itemId);
|
||||
$this->ensureInitialMovementForYear($itemId, $this->context->schoolYear());
|
||||
$this->recalcQuantity($itemId);
|
||||
@@ -217,6 +219,7 @@ class InventoryMovementService
|
||||
]);
|
||||
|
||||
$this->recalcQuantity($itemId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -233,7 +236,7 @@ class InventoryMovementService
|
||||
}
|
||||
|
||||
$item = InventoryItem::query()->select('id', 'type', 'quantity', 'needs_repair_qty', 'good_qty')->find($itemId);
|
||||
if (!$item) {
|
||||
if (! $item) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,7 +253,7 @@ class InventoryMovementService
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updates)) {
|
||||
if (! empty($updates)) {
|
||||
$item->update($updates);
|
||||
}
|
||||
}
|
||||
@@ -281,7 +284,7 @@ class InventoryMovementService
|
||||
->where('school_year', $schoolYear)
|
||||
->exists();
|
||||
|
||||
if (!$hasAnyThisYear) {
|
||||
if (! $hasAnyThisYear) {
|
||||
$onHand = (int) (InventoryItem::query()->where('id', $itemId)->value('quantity') ?? 0);
|
||||
InventoryMovement::query()->create([
|
||||
'item_id' => $itemId,
|
||||
@@ -290,6 +293,7 @@ class InventoryMovementService
|
||||
'school_year' => $schoolYear,
|
||||
'semester' => $this->context->semester() ?: null,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -299,7 +303,7 @@ class InventoryMovementService
|
||||
->where('movement_type', 'initial')
|
||||
->exists();
|
||||
|
||||
if (!$hasInitial) {
|
||||
if (! $hasInitial) {
|
||||
$onHand = (int) (InventoryItem::query()->where('id', $itemId)->value('quantity') ?? 0);
|
||||
$netYear = (int) (InventoryMovement::query()
|
||||
->where('item_id', $itemId)
|
||||
@@ -322,12 +326,14 @@ class InventoryMovementService
|
||||
if (in_array($movementType, ['out', 'distribution'], true) && $qtyChange > 0) {
|
||||
return -abs($qtyChange);
|
||||
}
|
||||
|
||||
return $qtyChange;
|
||||
}
|
||||
|
||||
private function wouldGoNegative(int $itemId, int $delta): bool
|
||||
{
|
||||
$onHand = (int) (InventoryItem::query()->where('id', $itemId)->value('quantity') ?? 0);
|
||||
|
||||
return $onHand + $delta < 0;
|
||||
}
|
||||
|
||||
@@ -336,6 +342,7 @@ class InventoryMovementService
|
||||
if ($val === null || $val === '' || $val === '0') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $val;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user