|
@@ -0,0 +1,77 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Controllers;
|
|
|
|
|
+
|
|
|
|
|
+use App\Http\Controllers\Concerns\ResolvesActiveUnit;
|
|
|
|
|
+use App\Http\Requests\SettleReceivableRequest;
|
|
|
|
|
+use App\Http\Resources\UnitReceivableResource;
|
|
|
|
|
+use App\Services\UnitReceivableService;
|
|
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
|
+
|
|
|
|
|
+class UnitReceivableController extends Controller
|
|
|
|
|
+{
|
|
|
|
|
+ use ResolvesActiveUnit;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct(
|
|
|
|
|
+ protected UnitReceivableService $service,
|
|
|
|
|
+ ) {}
|
|
|
|
|
+
|
|
|
|
|
+ public function indexMe(Request $request): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $unitId = $this->activeUnitId();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$unitId) {
|
|
|
|
|
+ return $this->errorResponse(message: 'Unidade não encontrada', code: 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $filters = $request->only(['status', 'student_id', 'type']);
|
|
|
|
|
+ $items = $this->service->list($unitId, array_filter($filters, fn ($v) => $v !== null));
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse(payload: UnitReceivableResource::collection($items));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function settleMe(SettleReceivableRequest $request, int $id): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $unitId = $this->activeUnitId();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$unitId) {
|
|
|
|
|
+ return $this->errorResponse(message: 'Unidade não encontrada', code: 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $installment = $this->service->findForUnit($id, $unitId);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$installment) {
|
|
|
|
|
+ return $this->errorResponse(message: 'Recebível não encontrado', code: 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $item = $this->service->settle($installment, $request->validated());
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ payload: new UnitReceivableResource($item),
|
|
|
|
|
+ message: 'Baixa realizada com sucesso',
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function reopenMe(int $id): JsonResponse
|
|
|
|
|
+ {
|
|
|
|
|
+ $unitId = $this->activeUnitId();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$unitId) {
|
|
|
|
|
+ return $this->errorResponse(message: 'Unidade não encontrada', code: 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $installment = $this->service->findForUnit($id, $unitId);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$installment) {
|
|
|
|
|
+ return $this->errorResponse(message: 'Recebível não encontrado', code: 404);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $item = $this->service->reopen($installment);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->successResponse(
|
|
|
|
|
+ payload: new UnitReceivableResource($item),
|
|
|
|
|
+ message: 'Recebível reaberto',
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|