update api and add more features
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Fees;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ChargeActionResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return array_filter([
|
||||
'ok' => (bool) ($this->resource['ok'] ?? false),
|
||||
'charge_type' => $this->resource['charge_type'] ?? null,
|
||||
'id' => isset($this->resource['id']) ? (int) $this->resource['id'] : null,
|
||||
'parent_id' => isset($this->resource['parent_id']) ? (int) $this->resource['parent_id'] : null,
|
||||
'student_id' => isset($this->resource['student_id']) ? (int) $this->resource['student_id'] : null,
|
||||
'invoice_id' => isset($this->resource['invoice_id']) ? (int) $this->resource['invoice_id'] : null,
|
||||
'event_id' => isset($this->resource['event_id']) ? (int) $this->resource['event_id'] : null,
|
||||
'event_name' => $this->resource['event_name'] ?? null,
|
||||
'amount' => isset($this->resource['amount']) ? (float) $this->resource['amount'] : null,
|
||||
'status' => $this->resource['status'] ?? null,
|
||||
'payment_status' => $this->resource['payment_status'] ?? null,
|
||||
'participation_status' => $this->resource['participation_status'] ?? null,
|
||||
'cancellation_status' => $this->resource['cancellation_status'] ?? null,
|
||||
'account_credit_charge_id' => isset($this->resource['account_credit_charge_id'])
|
||||
? (int) $this->resource['account_credit_charge_id']
|
||||
: null,
|
||||
'message' => $this->resource['message'] ?? null,
|
||||
'error' => $this->resource['error'] ?? null,
|
||||
], fn ($value) => $value !== null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Fees;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ChargeListResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'parent_id' => (int) ($this->resource['parent_id'] ?? 0),
|
||||
'school_year' => $this->resource['school_year'] ?? null,
|
||||
'extra_charges' => $this->resource['extra_charges'] ?? [],
|
||||
'event_charges' => $this->resource['event_charges'] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Fees;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class FeeFamilyBalanceResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$charges = $this->resource['charges'] ?? [];
|
||||
$credits = $this->resource['credits'] ?? [];
|
||||
$students = $this->resource['students'] ?? [];
|
||||
|
||||
return [
|
||||
'parent_id' => (int) ($this->resource['parent_id'] ?? 0),
|
||||
'school_year' => $this->resource['school_year'] ?? null,
|
||||
'charges' => [
|
||||
'tuition' => (float) ($charges['tuition'] ?? 0),
|
||||
'extra_charges' => (float) ($charges['extra_charges'] ?? 0),
|
||||
'event_charges' => (float) ($charges['event_charges'] ?? 0),
|
||||
'late_fees' => (float) ($charges['late_fees'] ?? 0),
|
||||
'total' => (float) ($charges['total'] ?? 0),
|
||||
],
|
||||
'credits' => [
|
||||
'discounts' => (float) ($credits['discounts'] ?? 0),
|
||||
'total' => (float) ($credits['total'] ?? 0),
|
||||
],
|
||||
'payments' => (float) ($this->resource['payments'] ?? 0),
|
||||
'refunds_applied' => (float) ($this->resource['refunds_applied'] ?? 0),
|
||||
'remaining_balance' => (float) ($this->resource['remaining_balance'] ?? 0),
|
||||
'account_credit' => (float) ($this->resource['account_credit'] ?? 0),
|
||||
'students' => array_map(function (array $row): array {
|
||||
return [
|
||||
'student_id' => $row['student_id'] ?? null,
|
||||
'student_name' => $row['student_name'] ?? null,
|
||||
'grade' => $row['grade'] ?? null,
|
||||
'enrollment_status' => $row['enrollment_status'] ?? null,
|
||||
'tuition' => (float) ($row['tuition'] ?? 0),
|
||||
'extra_charges' => (float) ($row['extra_charges'] ?? 0),
|
||||
'event_charges' => (float) ($row['event_charges'] ?? 0),
|
||||
'total_charges' => (float) ($row['total_charges'] ?? 0),
|
||||
'payments_applied' => (float) ($row['payments_applied'] ?? 0),
|
||||
'credits_applied' => (float) ($row['credits_applied'] ?? 0),
|
||||
'refunds_applied' => (float) ($row['refunds_applied'] ?? 0),
|
||||
'remaining_balance' => (float) ($row['remaining_balance'] ?? 0),
|
||||
'account_credit' => (float) ($row['account_credit'] ?? 0),
|
||||
];
|
||||
}, $students),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ class FeeRefundResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$students = $this->resource['students'] ?? [];
|
||||
|
||||
return [
|
||||
'refund_amount' => (float) ($this->resource['refund_amount'] ?? 0),
|
||||
'total_paid' => (float) ($this->resource['total_paid'] ?? 0),
|
||||
@@ -16,6 +18,20 @@ class FeeRefundResource extends JsonResource
|
||||
'school_end_date' => $this->resource['school_end_date'] ?? null,
|
||||
'weeks_of_study' => (float) ($this->resource['weeks_of_study'] ?? 0),
|
||||
'withdrawn_students' => (int) ($this->resource['withdrawn_students'] ?? 0),
|
||||
'students' => array_map(function (array $row): array {
|
||||
return [
|
||||
'student_id' => $row['student_id'] ?? null,
|
||||
'grade' => $row['grade'] ?? null,
|
||||
'grade_level' => $row['grade_level'] ?? null,
|
||||
'fee_category' => $row['fee_category'] ?? null,
|
||||
'tuition_fee' => (float) ($row['tuition_fee'] ?? 0),
|
||||
'withdrawal_date' => $row['withdrawal_date'] ?? null,
|
||||
'weeks_remaining' => (int) ($row['weeks_remaining'] ?? 0),
|
||||
'refund_amount' => (float) ($row['refund_amount'] ?? 0),
|
||||
'eligible' => (bool) ($row['eligible'] ?? false),
|
||||
'reason' => $row['reason'] ?? null,
|
||||
];
|
||||
}, $students),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Fees;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class FeeTuitionBreakdownResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$students = $this->resource['students'] ?? [];
|
||||
$fees = $this->resource['fees'] ?? [];
|
||||
|
||||
return [
|
||||
'school_year' => $this->resource['school_year'] ?? null,
|
||||
'family_total' => (float) ($this->resource['family_total'] ?? 0),
|
||||
'billable_count' => (int) ($this->resource['billable_count'] ?? 0),
|
||||
'non_billable_count' => (int) ($this->resource['non_billable_count'] ?? 0),
|
||||
'fees' => [
|
||||
'first_student_fee' => (float) ($fees['first_student_fee'] ?? 0),
|
||||
'second_student_fee' => (float) ($fees['second_student_fee'] ?? 0),
|
||||
'youth_fee' => (float) ($fees['youth_fee'] ?? 0),
|
||||
],
|
||||
'students' => array_map(function (array $row): array {
|
||||
return [
|
||||
'student_id' => $row['student_id'] ?? null,
|
||||
'student_name' => $row['student_name'] ?? null,
|
||||
'grade' => $row['grade'] ?? null,
|
||||
'grade_level' => $row['grade_level'] ?? null,
|
||||
'enrollment_status' => $row['enrollment_status'] ?? null,
|
||||
'admission_status' => $row['admission_status'] ?? null,
|
||||
'fee_category' => $row['fee_category'] ?? null,
|
||||
'tuition_fee' => (float) ($row['tuition_fee'] ?? 0),
|
||||
'discount_amount' => (float) ($row['discount_amount'] ?? 0),
|
||||
'final_tuition_amount' => (float) ($row['final_tuition_amount'] ?? 0),
|
||||
];
|
||||
}, $students),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class LevelProgressionResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'current_level_id' => $this->current_level_id !== null ? (int) $this->current_level_id : null,
|
||||
'current_level_name' => (string) ($this->current_level_name ?? ''),
|
||||
'next_level_id' => $this->next_level_id !== null ? (int) $this->next_level_id : null,
|
||||
'next_level_name' => $this->next_level_name,
|
||||
'order_index' => (int) ($this->order_index ?? 0),
|
||||
'is_terminal' => (bool) $this->is_terminal,
|
||||
'is_active' => (bool) $this->is_active,
|
||||
'notes' => $this->notes,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PromotionAuditLogResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'promotion_id' => $this->promotion_id ? (int) $this->promotion_id : null,
|
||||
'student_id' => $this->student_id ? (int) $this->student_id : null,
|
||||
'user_id' => $this->user_id ? (int) $this->user_id : null,
|
||||
'action_type' => $this->action_type,
|
||||
'field' => $this->field,
|
||||
'old_value' => $this->old_value,
|
||||
'new_value' => $this->new_value,
|
||||
'notes' => $this->notes,
|
||||
'performed_at' => optional($this->performed_at)->toDateTimeString(),
|
||||
'created_at' => optional($this->created_at)->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PromotionReminderResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) ($this->id ?? 0),
|
||||
'promotion_id' => (int) ($this->promotion_id ?? 0),
|
||||
'student_id' => $this->student_id ? (int) $this->student_id : null,
|
||||
'parent_id' => $this->parent_id ? (int) $this->parent_id : null,
|
||||
'reminder_type' => $this->reminder_type,
|
||||
'channel' => $this->channel,
|
||||
'subject' => $this->subject,
|
||||
'message' => $this->message,
|
||||
'sent_at' => optional($this->sent_at)->toDateTimeString(),
|
||||
'sent_by' => $this->sent_by ? (int) $this->sent_by : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Promotions;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* Admin/list shape for `student_promotion_records`. Accepts either an
|
||||
* Eloquent model or an associative array (so list endpoints can
|
||||
* decorate the row with student/parent context once and pass it
|
||||
* through unchanged).
|
||||
*/
|
||||
class StudentPromotionResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
$r = $this->resource;
|
||||
$get = static function (string $key, $default = null) use ($r) {
|
||||
if (is_array($r)) {
|
||||
return $r[$key] ?? $default;
|
||||
}
|
||||
return $r->{$key} ?? $default;
|
||||
};
|
||||
|
||||
return [
|
||||
'promotion_id' => (int) ($get('promotion_id') ?? 0),
|
||||
'student_id' => (int) ($get('student_id') ?? 0),
|
||||
'student_name' => $get('student_name'),
|
||||
'school_id' => $get('school_id'),
|
||||
'parent_id' => $get('parent_id') ? (int) $get('parent_id') : null,
|
||||
'parent_name' => $get('parent_name'),
|
||||
'parent_email' => $get('parent_email'),
|
||||
'current_school_year' => $get('current_school_year'),
|
||||
'next_school_year' => $get('next_school_year'),
|
||||
'current_level' => $get('current_level') ?? $get('current_level_name'),
|
||||
'promoted_level' => $get('promoted_level') ?? $get('promoted_level_name'),
|
||||
'promotion_status' => $get('promotion_status'),
|
||||
'enrollment_status' => $get('enrollment_status'),
|
||||
'enrollment_deadline' => $get('enrollment_deadline'),
|
||||
'parent_notified_at' => $get('parent_notified_at'),
|
||||
'enrollment_started_at' => $get('enrollment_started_at'),
|
||||
'enrollment_completed_at' => $get('enrollment_completed_at'),
|
||||
'promotion_finalized_at' => $get('promotion_finalized_at'),
|
||||
'final_average' => $get('final_average') !== null ? (float) $get('final_average') : null,
|
||||
'passed_current_level' => $get('passed_current_level'),
|
||||
'checklist' => $get('checklist'),
|
||||
'eligibility_notes' => $get('eligibility_notes'),
|
||||
'enrollment_id' => $get('enrollment_id') ? (int) $get('enrollment_id') : null,
|
||||
'updated_by' => $get('updated_by') ? (int) $get('updated_by') : null,
|
||||
'updated_at' => $get('updated_at'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user