add inventory and supply logic
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Inventory;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Inventory\InventoryCategoryIndexRequest;
|
||||
use App\Http\Requests\Inventory\InventoryCategoryStoreRequest;
|
||||
use App\Http\Requests\Inventory\InventoryCategoryUpdateRequest;
|
||||
use App\Http\Resources\Inventory\InventoryCategoryResource;
|
||||
use App\Services\Inventory\InventoryCategoryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class InventoryCategoryController extends BaseApiController
|
||||
{
|
||||
public function __construct(private InventoryCategoryService $categories)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(InventoryCategoryIndexRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$rows = $this->categories->list($payload['type'] ?? null);
|
||||
|
||||
return $this->success([
|
||||
'categories' => InventoryCategoryResource::collection($rows),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(InventoryCategoryStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->categories->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondCreated(new InventoryCategoryResource($result['category']));
|
||||
}
|
||||
|
||||
public function update(InventoryCategoryUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->categories->update($id, $request->validated());
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return $this->error($e->getMessage(), Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(new InventoryCategoryResource($result['category']));
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondDeleted();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Inventory;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Inventory\InventoryAdjustRequest;
|
||||
use App\Http\Requests\Inventory\InventoryAuditRequest;
|
||||
use App\Http\Requests\Inventory\InventoryItemIndexRequest;
|
||||
use App\Http\Requests\Inventory\InventoryItemStoreRequest;
|
||||
use App\Http\Requests\Inventory\InventoryItemUpdateRequest;
|
||||
use App\Http\Requests\Inventory\InventoryTeacherDistributionRequest;
|
||||
use App\Http\Requests\Inventory\InventoryTeacherDistributionStoreRequest;
|
||||
use App\Http\Resources\Inventory\InventoryItemResource;
|
||||
use App\Services\Inventory\InventoryItemService;
|
||||
use App\Services\Inventory\InventorySummaryService;
|
||||
use App\Services\Inventory\InventoryTeacherDistributionService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class InventoryController extends BaseApiController
|
||||
{
|
||||
public function __construct(
|
||||
private InventoryItemService $items,
|
||||
private InventorySummaryService $summary,
|
||||
private InventoryTeacherDistributionService $distribution
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(InventoryItemIndexRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->items->list($request->validated());
|
||||
|
||||
return $this->success([
|
||||
'type' => $result['type'],
|
||||
'items' => InventoryItemResource::collection($result['items']),
|
||||
'categories' => $result['categories'],
|
||||
'conditionOptions' => $result['conditionOptions'],
|
||||
'schoolYears' => $result['schoolYears'],
|
||||
'selectedYear' => $result['selectedYear'],
|
||||
'currentYear' => $result['currentYear'],
|
||||
'semester' => $result['semester'],
|
||||
'userNames' => $result['userNames'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$item = $this->items->find($id);
|
||||
if (!$item) {
|
||||
return $this->error('Item not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return $this->success(new InventoryItemResource($item));
|
||||
}
|
||||
|
||||
public function store(InventoryItemStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->items->create($request->validated(), (int) auth()->id());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to create item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondCreated(new InventoryItemResource($result['item']));
|
||||
}
|
||||
|
||||
public function update(InventoryItemUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->items->update($id, $request->validated(), (int) auth()->id());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(new InventoryItemResource($result['item']));
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->items->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondDeleted();
|
||||
}
|
||||
|
||||
public function audit(InventoryAuditRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->items->auditClassroom($id, $request->validated(), (int) auth()->id());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to audit item.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(new InventoryItemResource($result['item']));
|
||||
}
|
||||
|
||||
public function adjust(InventoryAdjustRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->items->adjustStock($id, $request->validated(), (int) auth()->id());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to adjust stock.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
public function summary(string $type): JsonResponse
|
||||
{
|
||||
$payload = $this->summary->summary($type, request()->query('school_year'));
|
||||
return $this->success($payload);
|
||||
}
|
||||
|
||||
public function summaryAll(): JsonResponse
|
||||
{
|
||||
$payload = $this->summary->summaryAll(
|
||||
request()->query('school_year'),
|
||||
request()->query('type')
|
||||
);
|
||||
return $this->success($payload);
|
||||
}
|
||||
|
||||
public function teacherDistribution(InventoryTeacherDistributionRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$result = $this->distribution->formData(
|
||||
(int) auth()->id(),
|
||||
$payload['class_section_id'] ?? null,
|
||||
$payload['item_id'] ?? null
|
||||
);
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to load distribution form.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function teacherDistributionStore(InventoryTeacherDistributionStoreRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$result = $this->distribution->distribute((int) auth()->id(), $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Inventory distribution failed: ' . $e->getMessage());
|
||||
return $this->error('Unable to distribute inventory.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Unable to distribute inventory.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Inventory;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Inventory\InventoryMovementBulkDeleteRequest;
|
||||
use App\Http\Requests\Inventory\InventoryMovementIndexRequest;
|
||||
use App\Http\Requests\Inventory\InventoryMovementStoreRequest;
|
||||
use App\Http\Requests\Inventory\InventoryMovementUpdateRequest;
|
||||
use App\Http\Resources\Inventory\InventoryMovementResource;
|
||||
use App\Services\Inventory\InventoryMovementService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class InventoryMovementController extends BaseApiController
|
||||
{
|
||||
public function __construct(private InventoryMovementService $movements)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(InventoryMovementIndexRequest $request): JsonResponse
|
||||
{
|
||||
$rows = $this->movements->list($request->validated());
|
||||
|
||||
return $this->success([
|
||||
'movements' => InventoryMovementResource::collection($rows),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(InventoryMovementStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->movements->create($request->validated(), (int) auth()->id());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to create movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondCreated();
|
||||
}
|
||||
|
||||
public function update(InventoryMovementUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->movements->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->movements->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete movement.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondDeleted();
|
||||
}
|
||||
|
||||
public function bulkDelete(InventoryMovementBulkDeleteRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->movements->bulkDelete($request->validated()['ids']);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Bulk delete failed.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Inventory;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Inventory\SupplierIndexRequest;
|
||||
use App\Http\Requests\Inventory\SupplierStoreRequest;
|
||||
use App\Http\Requests\Inventory\SupplierUpdateRequest;
|
||||
use App\Http\Resources\Inventory\SupplierResource;
|
||||
use App\Services\Inventory\SupplierService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SupplierController extends BaseApiController
|
||||
{
|
||||
public function __construct(private SupplierService $suppliers)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(SupplierIndexRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$perPage = (int) ($payload['per_page'] ?? 20);
|
||||
$result = $this->suppliers->list($payload, $perPage);
|
||||
|
||||
return $this->success([
|
||||
'suppliers' => SupplierResource::collection($result['items']),
|
||||
'pagination' => $result['pagination'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(SupplierStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondCreated(new SupplierResource($result['supplier']));
|
||||
}
|
||||
|
||||
public function update(SupplierUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(new SupplierResource($result['supplier']));
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->suppliers->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete supplier.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondDeleted();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Inventory;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Inventory\SupplyCategoryStoreRequest;
|
||||
use App\Http\Requests\Inventory\SupplyCategoryUpdateRequest;
|
||||
use App\Http\Resources\Inventory\SupplyCategoryResource;
|
||||
use App\Services\Inventory\SupplyCategoryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SupplyCategoryController extends BaseApiController
|
||||
{
|
||||
public function __construct(private SupplyCategoryService $categories)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$rows = $this->categories->list();
|
||||
|
||||
return $this->success([
|
||||
'categories' => SupplyCategoryResource::collection($rows),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(SupplyCategoryStoreRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->categories->create($request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to save category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondCreated(new SupplyCategoryResource($result['category']));
|
||||
}
|
||||
|
||||
public function update(SupplyCategoryUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->update($id, $request->validated());
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to update category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->success(new SupplyCategoryResource($result['category']));
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$result = $this->categories->delete($id);
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return $this->error($result['message'] ?? 'Failed to delete category.', Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
return $this->respondDeleted();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryAdjustRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'mode' => ['required', 'in:in,out,adjust'],
|
||||
'quantity' => ['required', 'integer', 'min:1'],
|
||||
'reason' => ['nullable', 'string', 'max:120'],
|
||||
'note' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryAuditRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'needs_repair_qty' => ['nullable', 'integer', 'min:0'],
|
||||
'need_replace_qty' => ['nullable', 'integer', 'min:0'],
|
||||
'cannot_find_qty' => ['nullable', 'integer', 'min:0'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryCategoryIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => ['nullable', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryCategoryStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => ['required', 'string', 'max:20'],
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'grade_min' => ['nullable', 'integer', 'min:0', 'max:13'],
|
||||
'grade_max' => ['nullable', 'integer', 'min:0', 'max:13'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryCategoryUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => ['sometimes', 'string', 'max:20'],
|
||||
'name' => ['sometimes', 'string', 'max:120'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'grade_min' => ['nullable', 'integer', 'min:0', 'max:13'],
|
||||
'grade_max' => ['nullable', 'integer', 'min:0', 'max:13'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryItemIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => ['nullable', 'string', 'max:20'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'q' => ['nullable', 'string', 'max:120'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryItemStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'type' => ['required', 'string', 'max:20'],
|
||||
'category_id' => ['nullable', 'integer', 'min:1'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'quantity' => ['nullable', 'integer'],
|
||||
'unit' => ['nullable', 'string', 'max:50'],
|
||||
'condition' => ['nullable', 'string', 'max:50'],
|
||||
'isbn' => ['nullable', 'string', 'max:50'],
|
||||
'edition' => ['nullable', 'string', 'max:50'],
|
||||
'sku' => ['nullable', 'string', 'max:50'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryItemUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'category_id' => ['nullable', 'integer', 'min:1'],
|
||||
'name' => ['sometimes', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'quantity' => ['nullable', 'integer'],
|
||||
'unit' => ['nullable', 'string', 'max:50'],
|
||||
'condition' => ['nullable', 'string', 'max:50'],
|
||||
'isbn' => ['nullable', 'string', 'max:50'],
|
||||
'edition' => ['nullable', 'string', 'max:50'],
|
||||
'sku' => ['nullable', 'string', 'max:50'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryMovementBulkDeleteRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ids' => ['required', 'array', 'min:1'],
|
||||
'ids.*' => ['integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryMovementIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryMovementStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'item_id' => ['required', 'integer', 'min:1'],
|
||||
'qty_change' => ['required', 'integer'],
|
||||
'movement_type' => ['required', 'in:initial,in,out,adjust,distribution'],
|
||||
'reason' => ['nullable', 'string', 'max:120'],
|
||||
'note' => ['nullable', 'string'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'teacher_id' => ['nullable', 'integer', 'min:1'],
|
||||
'student_id' => ['nullable', 'integer', 'min:1'],
|
||||
'class_section_id' => ['nullable', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryMovementUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'qty_change' => ['required', 'integer'],
|
||||
'movement_type' => ['required', 'in:initial,in,out,adjust,distribution'],
|
||||
'reason' => ['nullable', 'string', 'max:120'],
|
||||
'note' => ['nullable', 'string'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'teacher_id' => ['nullable', 'integer', 'min:1'],
|
||||
'student_id' => ['nullable', 'integer', 'min:1'],
|
||||
'class_section_id' => ['nullable', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryTeacherDistributionRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'class_section_id' => ['nullable', 'integer', 'min:1'],
|
||||
'item_id' => ['nullable', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class InventoryTeacherDistributionStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'item_id' => ['required', 'integer', 'min:1'],
|
||||
'class_section_id' => ['nullable', 'integer', 'min:1'],
|
||||
'student_ids' => ['required', 'array', 'min:1'],
|
||||
'student_ids.*' => ['integer', 'min:1'],
|
||||
'note' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class SupplierIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'q' => ['nullable', 'string', 'max:120'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class SupplierStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'address' => ['nullable', 'string', 'max:255'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class SupplierUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['sometimes', 'string', 'max:255'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'address' => ['nullable', 'string', 'max:255'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class SupplyCategoryStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Inventory;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class SupplyCategoryUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InventoryCategoryResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'type' => (string) ($this['type'] ?? ''),
|
||||
'name' => (string) ($this['name'] ?? ''),
|
||||
'description' => $this['description'] ?? null,
|
||||
'grade_min' => $this['grade_min'] ?? null,
|
||||
'grade_max' => $this['grade_max'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InventoryItemResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'type' => (string) ($this['type'] ?? ''),
|
||||
'category_id' => $this['category_id'] ?? null,
|
||||
'name' => (string) ($this['name'] ?? ''),
|
||||
'description' => $this['description'] ?? null,
|
||||
'quantity' => (int) ($this['quantity'] ?? 0),
|
||||
'good_qty' => $this['good_qty'] ?? null,
|
||||
'needs_repair_qty' => $this['needs_repair_qty'] ?? null,
|
||||
'need_replace_qty' => $this['need_replace_qty'] ?? null,
|
||||
'cannot_find_qty' => $this['cannot_find_qty'] ?? null,
|
||||
'unit' => $this['unit'] ?? null,
|
||||
'condition' => $this['condition'] ?? null,
|
||||
'isbn' => $this['isbn'] ?? null,
|
||||
'edition' => $this['edition'] ?? null,
|
||||
'sku' => $this['sku'] ?? null,
|
||||
'notes' => $this['notes'] ?? null,
|
||||
'semester' => $this['semester'] ?? null,
|
||||
'school_year' => $this['school_year'] ?? null,
|
||||
'updated_by' => $this['updated_by'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InventoryMovementResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'item_id' => (int) ($this['item_id'] ?? 0),
|
||||
'item_name' => $this['item_name'] ?? null,
|
||||
'qty_change' => (int) ($this['qty_change'] ?? 0),
|
||||
'movement_type' => (string) ($this['movement_type'] ?? ''),
|
||||
'reason' => $this['reason'] ?? null,
|
||||
'note' => $this['note'] ?? null,
|
||||
'semester' => $this['semester'] ?? null,
|
||||
'school_year' => $this['school_year'] ?? null,
|
||||
'performed_by' => $this['performed_by'] ?? null,
|
||||
'performed_by_name' => $this['performed_by_name'] ?? null,
|
||||
'teacher_id' => $this['teacher_id'] ?? null,
|
||||
'teacher_name' => $this['teacher_name'] ?? null,
|
||||
'student_id' => $this['student_id'] ?? null,
|
||||
'student_name' => $this['student_name'] ?? null,
|
||||
'class_section_id' => $this['class_section_id'] ?? null,
|
||||
'class_section_name' => $this['class_section_name'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SupplierResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'name' => (string) ($this['name'] ?? ''),
|
||||
'email' => $this['email'] ?? null,
|
||||
'phone' => $this['phone'] ?? null,
|
||||
'address' => $this['address'] ?? null,
|
||||
'notes' => $this['notes'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SupplyCategoryResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'name' => (string) ($this['name'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user