add refund and event logic
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
namespace App\Http\Controllers\Api\Finance;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Finance\FeeRefundRequest;
|
||||
use App\Http\Requests\Finance\FeeTuitionTotalRequest;
|
||||
use App\Http\Resources\Fees\FeeRefundResource;
|
||||
use App\Http\Resources\Fees\FeeTuitionTotalResource;
|
||||
use App\Services\Fees\FeeRefundCalculatorService;
|
||||
use App\Services\Fees\FeeStudentFeeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FeeCalculationController extends BaseApiController
|
||||
{
|
||||
@@ -20,52 +21,47 @@ class FeeCalculationController extends BaseApiController
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function refund(Request $request): JsonResponse
|
||||
public function refund(FeeRefundRequest $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'students' => ['required', 'array'],
|
||||
'students.*.student_id' => ['nullable', 'integer'],
|
||||
'students.*.class_section_id' => ['required', 'integer', 'min:1'],
|
||||
'students.*.enrollment_status' => ['required', 'string', 'max:50'],
|
||||
'students.*.admission_status' => ['required', 'string', 'max:50'],
|
||||
'students.*.withdrawal_date' => ['nullable', 'date'],
|
||||
]);
|
||||
$payload = $request->validated();
|
||||
|
||||
try {
|
||||
$result = $this->refunds->calculateRefund($payload['students'], (int) $payload['parent_id']);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Fee refund calculation failed', [
|
||||
'parent_id' => $payload['parent_id'] ?? null,
|
||||
'exception' => $e,
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
'ok' => false,
|
||||
'message' => 'Unable to calculate refund.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
$result = $this->refunds->calculateRefund($payload['students'], (int) $payload['parent_id']);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'refund' => new FeeRefundResource($result),
|
||||
]);
|
||||
}
|
||||
|
||||
public function tuitionTotal(Request $request): JsonResponse
|
||||
public function tuitionTotal(FeeTuitionTotalRequest $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'students' => ['required', 'array'],
|
||||
'students.*.class_section_id' => ['required', 'integer', 'min:1'],
|
||||
'students.*.grade' => ['nullable', 'string', 'max:20'],
|
||||
]);
|
||||
$payload = $request->validated();
|
||||
|
||||
try {
|
||||
$total = $this->tuition->totalTuitionFee($payload['students']);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Fee tuition total calculation failed', [
|
||||
'exception' => $e,
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'message' => 'Validation failed.',
|
||||
'errors' => $validator->errors(),
|
||||
], 422);
|
||||
'ok' => false,
|
||||
'message' => 'Unable to calculate tuition total.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
$total = $this->tuition->totalTuitionFee($payload['students']);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'tuition' => new FeeTuitionTotalResource([
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Finance;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Refunds\RefundDecisionRequest;
|
||||
use App\Http\Requests\Refunds\RefundIndexRequest;
|
||||
use App\Http\Requests\Refunds\RefundPaymentRequest;
|
||||
use App\Http\Requests\Refunds\RefundRecalculateRequest;
|
||||
use App\Http\Requests\Refunds\RefundRejectRequest;
|
||||
use App\Http\Requests\Refunds\RefundStoreRequest;
|
||||
use App\Http\Resources\Refunds\RefundResource;
|
||||
use App\Models\Configuration;
|
||||
use App\Services\Refunds\RefundDecisionService;
|
||||
use App\Services\Refunds\RefundOverpaymentService;
|
||||
use App\Services\Refunds\RefundPayoutService;
|
||||
use App\Services\Refunds\RefundQueryService;
|
||||
use App\Services\Refunds\RefundRequestService;
|
||||
use App\Services\Refunds\RefundSummaryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RefundController extends BaseApiController
|
||||
{
|
||||
public function __construct(
|
||||
private RefundQueryService $queryService,
|
||||
private RefundRequestService $requestService,
|
||||
private RefundDecisionService $decisionService,
|
||||
private RefundPayoutService $payoutService,
|
||||
private RefundOverpaymentService $overpaymentService,
|
||||
private RefundSummaryService $summaryService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(RefundIndexRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$result = $this->queryService->list($payload);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'refunds' => RefundResource::collection($result['refunds']),
|
||||
'pagination' => $result['pagination'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $refundId): JsonResponse
|
||||
{
|
||||
$refund = $this->queryService->find($refundId);
|
||||
if (!$refund) {
|
||||
return response()->json(['ok' => false, 'message' => 'Refund not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'refund' => new RefundResource($refund),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(RefundStoreRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
try {
|
||||
$result = $this->requestService->requestRefund($payload, $actorId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Refund request failed.', ['error' => $e->getMessage()]);
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to submit refund request.'], 500);
|
||||
}
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $result['message'] ?? 'Failed to submit refund request.',
|
||||
'available' => $result['available'] ?? null,
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'refund_id' => $result['refund_id'] ?? null,
|
||||
'refund_amount' => $result['refund_amount'] ?? null,
|
||||
'status' => $result['status'] ?? null,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(RefundDecisionRequest $request, int $refundId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
$result = $this->decisionService->updateDecision(
|
||||
$refundId,
|
||||
(string) $payload['status'],
|
||||
(string) $payload['reason'],
|
||||
$actorId
|
||||
);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to update refund.'], 422);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function destroy(int $refundId): JsonResponse
|
||||
{
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
$result = $this->decisionService->cancel($refundId, $actorId);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to cancel refund.'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function approve(int $refundId): JsonResponse
|
||||
{
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
$result = $this->decisionService->approve($refundId, $actorId);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Approve failed.'], 422);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function reject(RefundRejectRequest $request, int $refundId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
$result = $this->decisionService->reject($refundId, (string) $payload['reason'], $actorId);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Reject failed.'], 422);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function recordPayment(RefundPaymentRequest $request, int $refundId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$payload['check_file'] = $request->file('check_file');
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
$result = $this->payoutService->recordPayment($refundId, $payload, $actorId);
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to update payment.'], 422);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function recalculateOverpayments(RefundRecalculateRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
$result = $this->overpaymentService->recalculate(true, $payload['invoice_number'] ?? null, $actorId);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'created_ids' => $result['created_ids'] ?? null,
|
||||
'updated_ids' => $result['updated_ids'] ?? null,
|
||||
'message' => $result['message'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function parentBalances(int $parentId): JsonResponse
|
||||
{
|
||||
$termSchoolYear = (string) (Configuration::getConfig('school_year') ?? '');
|
||||
$termSemester = (string) (Configuration::getConfig('semester') ?? '');
|
||||
|
||||
$summary = $this->summaryService->getParentFinancialSummary($parentId, $termSchoolYear, $termSemester);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'summary' => $summary,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\Api\BaseApiController;
|
||||
use App\Http\Requests\Events\EventChargeIndexRequest;
|
||||
use App\Http\Requests\Events\EventChargeUpdateRequest;
|
||||
use App\Http\Requests\Events\EventIndexRequest;
|
||||
use App\Http\Requests\Events\EventStoreRequest;
|
||||
use App\Http\Requests\Events\EventStudentsWithChargesRequest;
|
||||
use App\Http\Requests\Events\EventUpdateRequest;
|
||||
use App\Http\Resources\Events\EventChargeResource;
|
||||
use App\Http\Resources\Events\EventResource;
|
||||
use App\Http\Resources\Events\EventStudentChargeResource;
|
||||
use App\Services\Events\EventCategoryService;
|
||||
use App\Services\Events\EventChargeQueryService;
|
||||
use App\Services\Events\EventChargeService;
|
||||
use App\Services\Events\EventListService;
|
||||
use App\Services\Events\EventManagementService;
|
||||
use App\Services\Events\EventStudentChargeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EventController extends BaseApiController
|
||||
{
|
||||
public function __construct(
|
||||
private EventListService $listService,
|
||||
private EventManagementService $managementService,
|
||||
private EventChargeQueryService $chargeQueryService,
|
||||
private EventChargeService $chargeService,
|
||||
private EventStudentChargeService $studentChargeService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index(EventIndexRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$result = $this->listService->list($payload);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'events' => EventResource::collection($result['events']),
|
||||
'pagination' => $result['pagination'],
|
||||
'active_count' => $result['active_count'],
|
||||
'categories' => EventCategoryService::categories(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $eventId): JsonResponse
|
||||
{
|
||||
$event = $this->listService->find($eventId);
|
||||
if (!$event) {
|
||||
return response()->json(['ok' => false, 'message' => 'Event not found.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'event' => new EventResource($event),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(EventStoreRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
try {
|
||||
$result = $this->managementService->create($payload, $request->file('flyer'), $actorId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Event creation failed.', ['error' => $e->getMessage()]);
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to create event.'], 500);
|
||||
}
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => 'Failed to create event.'], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'event' => new EventResource($result['event']),
|
||||
'charges_created' => $result['charges_created'] ?? 0,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(EventUpdateRequest $request, int $eventId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
|
||||
$result = $this->managementService->update($eventId, $payload, $request->file('flyer'));
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to update event.'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'event' => new EventResource($result['event']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $eventId): JsonResponse
|
||||
{
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
$result = $this->managementService->delete($eventId, $actorId);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to delete event.'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function charges(EventChargeIndexRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$result = $this->chargeQueryService->list($payload);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'charges' => EventChargeResource::collection($result['charges']),
|
||||
'pagination' => $result['pagination'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateCharges(EventChargeUpdateRequest $request, int $eventId): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
$actorId = (int) (auth()->id() ?? 0);
|
||||
|
||||
$result = $this->chargeService->updateParticipation(
|
||||
(int) $payload['parent_id'],
|
||||
$eventId,
|
||||
$payload['participation'],
|
||||
(string) $payload['school_year'],
|
||||
(string) $payload['semester'],
|
||||
$actorId
|
||||
);
|
||||
|
||||
if (empty($result['ok'])) {
|
||||
return response()->json(['ok' => false, 'message' => $result['message'] ?? 'Failed to update charges.'], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'created' => $result['created'],
|
||||
'updated' => $result['updated'],
|
||||
'deleted' => $result['deleted'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function studentsWithCharges(EventStudentsWithChargesRequest $request): JsonResponse
|
||||
{
|
||||
$payload = $request->validated();
|
||||
|
||||
$students = $this->studentChargeService->listStudentsWithCharges(
|
||||
(int) $payload['parent_id'],
|
||||
(string) $payload['school_year'],
|
||||
(string) $payload['semester']
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'students' => EventStudentChargeResource::collection($students),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class EventChargeIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'parent_id' => ['nullable', 'integer', 'min:1'],
|
||||
'event_id' => ['nullable', 'integer', 'min:1'],
|
||||
'page' => ['nullable', 'integer', 'min:1'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class EventChargeUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'school_year' => ['required', 'string', 'max:20'],
|
||||
'semester' => ['required', 'string', 'max:20'],
|
||||
'participation' => ['required', 'array'],
|
||||
'participation.*' => ['required', 'string', 'in:yes,no'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class EventIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'q' => ['nullable', 'string', 'max:200'],
|
||||
'active' => ['nullable', 'boolean'],
|
||||
'page' => ['nullable', 'integer', 'min:1'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
'sort_by' => ['nullable', 'string', 'in:created_at,expiration_date,event_name'],
|
||||
'sort_dir' => ['nullable', 'string', 'in:asc,desc'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
use App\Services\Events\EventCategoryService;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EventStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'event_name' => ['required', 'string', 'max:150'],
|
||||
'event_category' => ['required', 'string', Rule::in(EventCategoryService::categories())],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'amount' => ['required', 'numeric', 'min:0'],
|
||||
'flyer' => ['nullable', 'file', 'mimes:pdf,jpg,jpeg,png'],
|
||||
'expiration_date' => ['required', 'date'],
|
||||
'semester' => ['required', 'string', 'max:20'],
|
||||
'school_year' => ['required', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class EventStudentsWithChargesRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'school_year' => ['required', 'string', 'max:20'],
|
||||
'semester' => ['required', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Events;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
use App\Services\Events\EventCategoryService;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EventUpdateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'event_name' => ['sometimes', 'required', 'string', 'max:150'],
|
||||
'event_category' => ['sometimes', 'required', 'string', Rule::in(EventCategoryService::categories())],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'amount' => ['sometimes', 'required', 'numeric', 'min:0'],
|
||||
'flyer' => ['nullable', 'file', 'mimes:pdf,jpg,jpeg,png'],
|
||||
'expiration_date' => ['sometimes', 'required', 'date'],
|
||||
'semester' => ['sometimes', 'required', 'string', 'max:20'],
|
||||
'school_year' => ['sometimes', 'required', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Finance;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class FeeRefundRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'students' => ['required', 'array'],
|
||||
'students.*.student_id' => ['nullable', 'integer'],
|
||||
'students.*.class_section_id' => ['required', 'integer', 'min:1'],
|
||||
'students.*.enrollment_status' => ['required', 'string', 'max:50'],
|
||||
'students.*.admission_status' => ['required', 'string', 'max:50'],
|
||||
'students.*.withdrawal_date' => ['nullable', 'date'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Finance;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class FeeTuitionTotalRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'students' => ['required', 'array'],
|
||||
'students.*.class_section_id' => ['required', 'integer', 'min:1'],
|
||||
'students.*.grade' => ['nullable', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
use App\Models\Refund;
|
||||
|
||||
class RefundDecisionRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'status' => ['required', 'string', 'in:' . implode(',', [
|
||||
Refund::STATUS_APPROVED,
|
||||
Refund::STATUS_REJECTED,
|
||||
])],
|
||||
'reason' => ['required', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
use App\Models\Refund;
|
||||
|
||||
class RefundIndexRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'status' => ['nullable', 'string', 'in:' . implode(',', [
|
||||
Refund::STATUS_PENDING,
|
||||
Refund::STATUS_APPROVED,
|
||||
Refund::STATUS_PARTIAL,
|
||||
Refund::STATUS_PAID,
|
||||
Refund::STATUS_REJECTED,
|
||||
Refund::STATUS_CANCELED,
|
||||
])],
|
||||
'request' => ['nullable', 'string', 'in:tuition,overpayment,duplicate,extra'],
|
||||
'parent_id' => ['nullable', 'integer', 'min:1'],
|
||||
'invoice_id' => ['nullable', 'integer', 'min:1'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
'q' => ['nullable', 'string', 'max:200'],
|
||||
'page' => ['nullable', 'integer', 'min:1'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
'sort_by' => ['nullable', 'string', 'in:created_at,updated_at,refund_amount,status,parent_id,invoice_id'],
|
||||
'sort_dir' => ['nullable', 'string', 'in:asc,desc'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class RefundPaymentRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'paid_amount' => ['required', 'numeric', 'min:0.01'],
|
||||
'payment_method' => ['required', 'string', 'max:50', 'in:Check,Online,Cash'],
|
||||
'check_number' => ['nullable', 'string', 'max:80'],
|
||||
'check_file' => ['nullable', 'file', 'mimes:pdf,jpg,jpeg,png'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class RefundRecalculateRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'invoice_number' => ['nullable', 'string', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class RefundRejectRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'reason' => ['required', 'string', 'max:2000'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Refunds;
|
||||
|
||||
use App\Http\Requests\ApiFormRequest;
|
||||
|
||||
class RefundStoreRequest extends ApiFormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => ['required', 'integer', 'min:1'],
|
||||
'request_type' => ['required', 'string', 'in:tuition,overpayment,duplicate,extra'],
|
||||
'amount' => ['required_unless:request_type,tuition', 'numeric', 'min:0.01'],
|
||||
'invoice_id' => ['nullable', 'integer', 'min:1'],
|
||||
'payment_id' => ['nullable', 'integer', 'min:1'],
|
||||
'reason' => ['nullable', 'string', 'max:2000'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'semester' => ['nullable', 'string', 'max:20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Events;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventChargeResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'event_id' => (int) ($this->event_id ?? 0),
|
||||
'event_name' => $this->event_name ?? null,
|
||||
'parent_id' => (int) ($this->parent_id ?? 0),
|
||||
'parent_name' => trim(($this->parent_firstname ?? '') . ' ' . ($this->parent_lastname ?? '')),
|
||||
'student_id' => (int) ($this->student_id ?? 0),
|
||||
'student_name' => trim(($this->student_firstname ?? '') . ' ' . ($this->student_lastname ?? '')),
|
||||
'participation' => $this->getRawOriginal('participation') ?? $this->participation,
|
||||
'charged' => (float) ($this->getRawOriginal('charged') ?? $this->charged ?? 0),
|
||||
'school_year' => $this->school_year,
|
||||
'semester' => $this->semester,
|
||||
'created_at' => optional($this->created_at)->toDateTimeString(),
|
||||
'updated_at' => optional($this->updated_at)->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Events;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'event_name' => $this->event_name,
|
||||
'event_category' => $this->event_category,
|
||||
'description' => $this->description,
|
||||
'amount' => (float) ($this->amount ?? 0),
|
||||
'flyer' => $this->flyer,
|
||||
'expiration_date' => optional($this->expiration_date)->format('Y-m-d'),
|
||||
'semester' => $this->semester,
|
||||
'school_year' => $this->school_year,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => optional($this->created_at)->toDateTimeString(),
|
||||
'updated_at' => optional($this->updated_at)->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Events;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventStudentChargeResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this['id'] ?? 0),
|
||||
'name' => $this['name'] ?? '',
|
||||
'charged' => (bool) ($this['charged'] ?? false),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Refunds;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RefundResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'parent_id' => (int) ($this->parent_id ?? 0),
|
||||
'invoice_id' => $this->invoice_id ? (int) $this->invoice_id : null,
|
||||
'school_year' => $this->school_year,
|
||||
'semester' => $this->semester,
|
||||
'request' => $this->request,
|
||||
'status' => $this->status,
|
||||
'reason' => $this->reason,
|
||||
'refund_amount' => (float) ($this->refund_amount ?? 0),
|
||||
'refund_paid_amount' => (float) ($this->refund_paid_amount ?? 0),
|
||||
'refund_method' => $this->refund_method,
|
||||
'check_nbr' => $this->check_nbr,
|
||||
'check_file' => $this->check_file,
|
||||
'note' => $this->note,
|
||||
'requested_at' => optional($this->requested_at)->toDateTimeString(),
|
||||
'approved_at' => optional($this->approved_at)->toDateTimeString(),
|
||||
'refunded_at' => optional($this->refunded_at)->toDateTimeString(),
|
||||
'created_at' => optional($this->created_at)->toDateTimeString(),
|
||||
'updated_at' => optional($this->updated_at)->toDateTimeString(),
|
||||
'parent_name' => $this->parent_name ?? null,
|
||||
'approved_by_name' => $this->approved_by_name ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user