Fix Pint formatting
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace App\Services\Inventory;
|
||||
|
||||
use App\Models\InventoryCategory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InventoryCategoryService
|
||||
@@ -16,6 +15,7 @@ class InventoryCategoryService
|
||||
if ($type) {
|
||||
$query->where('type', $this->normalizeType($type));
|
||||
}
|
||||
|
||||
return $query->get()->toArray();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ class InventoryCategoryService
|
||||
try {
|
||||
$category = InventoryCategory::query()->create($payload);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory category create failed: ' . $e->getMessage());
|
||||
Log::error('Inventory category create failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to save category.'];
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ class InventoryCategoryService
|
||||
public function update(int $id, array $data): array
|
||||
{
|
||||
$category = InventoryCategory::query()->find($id);
|
||||
if (!$category) {
|
||||
if (! $category) {
|
||||
return ['ok' => false, 'message' => 'Category not found.'];
|
||||
}
|
||||
|
||||
@@ -68,7 +69,8 @@ class InventoryCategoryService
|
||||
try {
|
||||
$category->update($payload);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory category update failed: ' . $e->getMessage());
|
||||
Log::error('Inventory category update failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to save category.'];
|
||||
}
|
||||
|
||||
@@ -78,14 +80,15 @@ class InventoryCategoryService
|
||||
public function delete(int $id): array
|
||||
{
|
||||
$category = InventoryCategory::query()->find($id);
|
||||
if (!$category) {
|
||||
if (! $category) {
|
||||
return ['ok' => false, 'message' => 'Category not found.'];
|
||||
}
|
||||
|
||||
try {
|
||||
$category->delete();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory category delete failed: ' . $e->getMessage());
|
||||
Log::error('Inventory category delete failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to delete category.'];
|
||||
}
|
||||
|
||||
@@ -129,6 +132,7 @@ class InventoryCategoryService
|
||||
private function normalizeType(?string $type): string
|
||||
{
|
||||
$type = strtolower((string) $type);
|
||||
|
||||
return in_array($type, $this->types, true) ? $type : 'office';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InventorySummaryService
|
||||
{
|
||||
public function __construct(private InventoryContextService $context)
|
||||
{
|
||||
}
|
||||
public function __construct(private InventoryContextService $context) {}
|
||||
|
||||
public function summary(string $type, ?string $schoolYear): array
|
||||
{
|
||||
@@ -24,7 +22,7 @@ class InventorySummaryService
|
||||
|
||||
$itemIds = array_map(static fn ($i) => (int) ($i['id'] ?? 0), $items);
|
||||
$agg = [];
|
||||
if (!empty($itemIds)) {
|
||||
if (! empty($itemIds)) {
|
||||
$qb = DB::table('inventory_movements')
|
||||
->selectRaw('item_id,
|
||||
SUM(CASE WHEN qty_change>0 THEN qty_change ELSE 0 END) AS received,
|
||||
@@ -65,7 +63,7 @@ class InventorySummaryService
|
||||
->leftJoin('users as u', 'u.id', '=', 'i.updated_by')
|
||||
->orderBy('i.name');
|
||||
|
||||
if (!$isAllYears) {
|
||||
if (! $isAllYears) {
|
||||
$qbItems->where('i.school_year', $selectedYear);
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ class InventorySummaryService
|
||||
'variance' => 0,
|
||||
];
|
||||
|
||||
if (!empty($items)) {
|
||||
if (! empty($items)) {
|
||||
$itemIds = array_map('intval', array_column($items, 'id'));
|
||||
$aggById = [];
|
||||
$qb = DB::table('inventory_movements as m')
|
||||
@@ -102,7 +100,7 @@ class InventorySummaryService
|
||||
->whereIn('m.item_id', $itemIds)
|
||||
->groupBy('m.item_id');
|
||||
|
||||
if (!$isAllYears) {
|
||||
if (! $isAllYears) {
|
||||
$qb->where('m.school_year', $selectedYear);
|
||||
}
|
||||
|
||||
@@ -182,7 +180,7 @@ class InventorySummaryService
|
||||
->all();
|
||||
|
||||
$currentYear = $this->context->schoolYear();
|
||||
if ($currentYear && !in_array($currentYear, $years, true)) {
|
||||
if ($currentYear && ! in_array($currentYear, $years, true)) {
|
||||
array_unshift($years, $currentYear);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,20 +9,18 @@ use App\Models\StudentClass;
|
||||
use App\Models\TeacherClass;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class InventoryTeacherDistributionService
|
||||
{
|
||||
public function __construct(
|
||||
private InventoryContextService $context,
|
||||
private InventoryMovementService $movementService
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function formData(int $userId, ?int $classSectionId, ?int $itemId): array
|
||||
{
|
||||
$ctx = $this->buildTeacherClassContext($userId);
|
||||
if (!$ctx['ok']) {
|
||||
if (! $ctx['ok']) {
|
||||
return $ctx;
|
||||
}
|
||||
|
||||
@@ -33,7 +31,7 @@ class InventoryTeacherDistributionService
|
||||
: (int) ($classSectionId ?? ($ctx['defaultClassSectionId'] ?? 0));
|
||||
|
||||
$classID = null;
|
||||
if (!empty($selectedClassId)) {
|
||||
if (! empty($selectedClassId)) {
|
||||
$classID = ClassSection::getClassId($selectedClassId);
|
||||
$classID = $classID !== null ? (int) $classID : null;
|
||||
}
|
||||
@@ -43,7 +41,7 @@ class InventoryTeacherDistributionService
|
||||
->leftJoin('inventory_categories as c', 'c.id', '=', 'i.category_id')
|
||||
->where('i.type', 'book');
|
||||
|
||||
if (!empty($classID)) {
|
||||
if (! empty($classID)) {
|
||||
$builder->where(function ($q) use ($classID) {
|
||||
$q->where(function ($inner) use ($classID) {
|
||||
$inner->whereNotNull('c.grade_min')
|
||||
@@ -68,27 +66,34 @@ class InventoryTeacherDistributionService
|
||||
$name = $r['category_name'] ?? 'Uncategorized';
|
||||
$gmin = $r['grade_min'] ?? null;
|
||||
$gmax = $r['grade_max'] ?? null;
|
||||
if ($gmin === null && $gmax === null) return $name;
|
||||
if ($gmin !== null && $gmax !== null) return $name . ' (G' . (int) $gmin . '–G' . (int) $gmax . ')';
|
||||
if ($gmin !== null) return $name . ' (G' . (int) $gmin . '+)';
|
||||
return $name . ' (≤G' . (int) $gmax . ')';
|
||||
if ($gmin === null && $gmax === null) {
|
||||
return $name;
|
||||
}
|
||||
if ($gmin !== null && $gmax !== null) {
|
||||
return $name.' (G'.(int) $gmin.'–G'.(int) $gmax.')';
|
||||
}
|
||||
if ($gmin !== null) {
|
||||
return $name.' (G'.(int) $gmin.'+)';
|
||||
}
|
||||
|
||||
return $name.' (≤G'.(int) $gmax.')';
|
||||
};
|
||||
|
||||
$booksGrouped = [];
|
||||
foreach ($rows as $r) {
|
||||
$catId = (int) ($r['category_id'] ?? 0);
|
||||
if (!isset($booksGrouped[$catId])) {
|
||||
if (! isset($booksGrouped[$catId])) {
|
||||
$booksGrouped[$catId] = [
|
||||
'label' => $labelFor($r),
|
||||
'items' => [],
|
||||
];
|
||||
}
|
||||
$display = $r['name'];
|
||||
if (!empty($r['isbn'])) {
|
||||
$display .= ' — ISBN ' . $r['isbn'];
|
||||
if (! empty($r['isbn'])) {
|
||||
$display .= ' — ISBN '.$r['isbn'];
|
||||
}
|
||||
if (!empty($r['edition'])) {
|
||||
$display .= ' (' . $r['edition'] . ')';
|
||||
if (! empty($r['edition'])) {
|
||||
$display .= ' ('.$r['edition'].')';
|
||||
}
|
||||
|
||||
$booksGrouped[$catId]['items'][] = [
|
||||
@@ -123,7 +128,9 @@ class InventoryTeacherDistributionService
|
||||
->all();
|
||||
foreach ($rowsHist as $r) {
|
||||
$sid = (int) ($r['student_id'] ?? 0);
|
||||
if ($sid) $already[$sid] = (int) ($r['qty'] ?? 0);
|
||||
if ($sid) {
|
||||
$already[$sid] = (int) ($r['qty'] ?? 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +161,7 @@ class InventoryTeacherDistributionService
|
||||
public function distribute(int $userId, array $payload): array
|
||||
{
|
||||
$ctx = $this->buildTeacherClassContext($userId);
|
||||
if (!$ctx['ok']) {
|
||||
if (! $ctx['ok']) {
|
||||
return $ctx;
|
||||
}
|
||||
|
||||
@@ -168,12 +175,12 @@ class InventoryTeacherDistributionService
|
||||
? (int) $classIds[0]
|
||||
: (in_array($postedClassId, $classIds, true) ? $postedClassId : 0);
|
||||
|
||||
if (!$classSectionId) {
|
||||
if (! $classSectionId) {
|
||||
return ['ok' => false, 'message' => 'Invalid class selection.'];
|
||||
}
|
||||
|
||||
$book = InventoryItem::query()->find($itemId);
|
||||
if (!$book || $book->type !== 'book') {
|
||||
if (! $book || $book->type !== 'book') {
|
||||
return ['ok' => false, 'message' => 'Invalid book.'];
|
||||
}
|
||||
|
||||
@@ -181,7 +188,9 @@ class InventoryTeacherDistributionService
|
||||
$validIds = [];
|
||||
foreach ($students as $st) {
|
||||
$sid = $st['student_id'] ?? ($st['id'] ?? null);
|
||||
if ($sid) $validIds[(int) $sid] = true;
|
||||
if ($sid) {
|
||||
$validIds[(int) $sid] = true;
|
||||
}
|
||||
}
|
||||
$selectedIds = array_values(array_filter($selectedIds, fn ($sid) => isset($validIds[$sid])));
|
||||
|
||||
@@ -200,7 +209,9 @@ class InventoryTeacherDistributionService
|
||||
->all();
|
||||
foreach ($rows as $r) {
|
||||
$sid = (int) ($r['student_id'] ?? 0);
|
||||
if ($sid) $already[$sid] = (int) ($r['qty'] ?? 0);
|
||||
if ($sid) {
|
||||
$already[$sid] = (int) ($r['qty'] ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
$toGive = [];
|
||||
@@ -243,7 +254,7 @@ class InventoryTeacherDistributionService
|
||||
}
|
||||
|
||||
$user = User::query()->find($userId);
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return ['ok' => false, 'message' => 'User not found.'];
|
||||
}
|
||||
|
||||
@@ -253,13 +264,13 @@ class InventoryTeacherDistributionService
|
||||
->pluck('r.name')
|
||||
->toArray();
|
||||
|
||||
if (!in_array('teacher', $roles, true) && !in_array('teacher_assistant', $roles, true)) {
|
||||
if (! in_array('teacher', $roles, true) && ! in_array('teacher_assistant', $roles, true)) {
|
||||
return ['ok' => false, 'message' => 'Access denied.'];
|
||||
}
|
||||
|
||||
$classSectionIds = array_column($classes, 'class_section_id');
|
||||
$studentsData = [];
|
||||
if (!empty($classSectionIds)) {
|
||||
if (! empty($classSectionIds)) {
|
||||
$students = StudentClass::getStudentsByClassSectionIds($classSectionIds);
|
||||
foreach ($students as $student) {
|
||||
$studentsData[$student['class_section_id']][] = $student;
|
||||
@@ -278,7 +289,7 @@ class InventoryTeacherDistributionService
|
||||
$taUser = User::query()->find($ta['teacher_id'] ?? 0);
|
||||
if ($taUser) {
|
||||
$csid = $ta['class_section_id'];
|
||||
$taNames[$csid][] = trim(($taUser->firstname ?? '') . ' ' . ($taUser->lastname ?? ''));
|
||||
$taNames[$csid][] = trim(($taUser->firstname ?? '').' '.($taUser->lastname ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ class SupplierService
|
||||
$query = Supplier::query();
|
||||
if ($q !== '') {
|
||||
$query->where(function ($builder) use ($q) {
|
||||
$builder->where('name', 'like', '%' . $q . '%')
|
||||
->orWhere('email', 'like', '%' . $q . '%')
|
||||
->orWhere('phone', 'like', '%' . $q . '%');
|
||||
$builder->where('name', 'like', '%'.$q.'%')
|
||||
->orWhere('email', 'like', '%'.$q.'%')
|
||||
->orWhere('phone', 'like', '%'.$q.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ class SupplierService
|
||||
try {
|
||||
$supplier = Supplier::query()->create($this->payload($data));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supplier create failed: ' . $e->getMessage());
|
||||
Log::error('Supplier create failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to save supplier.'];
|
||||
}
|
||||
|
||||
@@ -47,14 +48,15 @@ class SupplierService
|
||||
public function update(int $id, array $data): array
|
||||
{
|
||||
$supplier = Supplier::query()->find($id);
|
||||
if (!$supplier) {
|
||||
if (! $supplier) {
|
||||
return ['ok' => false, 'message' => 'Supplier not found.'];
|
||||
}
|
||||
|
||||
try {
|
||||
$supplier->update($this->payload($data));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supplier update failed: ' . $e->getMessage());
|
||||
Log::error('Supplier update failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to update supplier.'];
|
||||
}
|
||||
|
||||
@@ -64,14 +66,15 @@ class SupplierService
|
||||
public function delete(int $id): array
|
||||
{
|
||||
$supplier = Supplier::query()->find($id);
|
||||
if (!$supplier) {
|
||||
if (! $supplier) {
|
||||
return ['ok' => false, 'message' => 'Supplier not found.'];
|
||||
}
|
||||
|
||||
try {
|
||||
$supplier->delete();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supplier delete failed: ' . $e->getMessage());
|
||||
Log::error('Supplier delete failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to delete supplier.'];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ class SupplyCategoryService
|
||||
'name' => (string) ($data['name'] ?? ''),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supply category create failed: ' . $e->getMessage());
|
||||
Log::error('Supply category create failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to save category.'];
|
||||
}
|
||||
|
||||
@@ -29,14 +30,15 @@ class SupplyCategoryService
|
||||
public function update(int $id, array $data): array
|
||||
{
|
||||
$category = SupplyCategory::query()->find($id);
|
||||
if (!$category) {
|
||||
if (! $category) {
|
||||
return ['ok' => false, 'message' => 'Category not found.'];
|
||||
}
|
||||
|
||||
try {
|
||||
$category->update(['name' => (string) ($data['name'] ?? '')]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supply category update failed: ' . $e->getMessage());
|
||||
Log::error('Supply category update failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to update category.'];
|
||||
}
|
||||
|
||||
@@ -46,14 +48,15 @@ class SupplyCategoryService
|
||||
public function delete(int $id): array
|
||||
{
|
||||
$category = SupplyCategory::query()->find($id);
|
||||
if (!$category) {
|
||||
if (! $category) {
|
||||
return ['ok' => false, 'message' => 'Category not found.'];
|
||||
}
|
||||
|
||||
try {
|
||||
$category->delete();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Supply category delete failed: ' . $e->getMessage());
|
||||
Log::error('Supply category delete failed: '.$e->getMessage());
|
||||
|
||||
return ['ok' => false, 'message' => 'Failed to delete category.'];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user