You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.4 KiB
139 lines
4.4 KiB
<?php
|
|
|
|
use App\Attributes\LayoutData;
|
|
use App\Attributes\Seo;
|
|
use App\Domains\Academic\Models\StudyProgram;
|
|
use App\Domains\Admission\Actions\AdmissionPricing\SetUpAdmissionFeeRates;
|
|
use App\Domains\Admission\DTOs\AdmissionPricing\AdmissionFeeRatesDTO;
|
|
use App\Domains\Admission\Models\AcademicProgram;
|
|
use App\Domains\Admission\Models\AdmissionSchedule;
|
|
use App\Domains\Admission\Models\FeeRate;
|
|
use App\Domains\Admission\Models\FeeType;
|
|
use App\Domains\Finance\Support\ValueObjects\Money;
|
|
use App\Livewire\Concerns\HasLayoutDataAttributes;
|
|
use App\Livewire\Concerns\HasSeoAttributes;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
new #[Layout('components.layouts.app')]
|
|
#[Seo(title: 'domains/admission/seo.admission_schedule-detail.title', description: 'domains/admission/seo.admission_schedule-detail.description', keywords: 'domains/admission/seo.admission_schedule-detail.keywords')]
|
|
#[LayoutData(header: 'domains/admission/seo.admission_schedule.title', breadcrumbs: ['ui/menu.dashboard' => 'dashboard', 'domains/admission/seo.admission_schedule.title' => 'admission-schedules.index', '{admissionTrack.name} {term.name}' => ''], context: 'admissionSchedule')]
|
|
class extends Component
|
|
{
|
|
use HasLayoutDataAttributes;
|
|
use HasSeoAttributes;
|
|
use WithToast;
|
|
|
|
#[Locked]
|
|
public string $id;
|
|
|
|
public function mount($id): void
|
|
{
|
|
$this->id = $id;
|
|
}
|
|
|
|
#[Computed]
|
|
public function admissionSchedule(): AdmissionSchedule
|
|
{
|
|
return AdmissionSchedule::with(['admissionTrack', 'term'])
|
|
->where('ulid', $this->id)->first();
|
|
}
|
|
|
|
#[Computed]
|
|
public function studyPrograms(): Collection
|
|
{
|
|
return StudyProgram::all(['id', 'name', 'ulid']);
|
|
}
|
|
|
|
#[Computed]
|
|
public function academicPrograms(): Collection
|
|
{
|
|
return AcademicProgram::all(['id', 'name', 'ulid']);
|
|
}
|
|
|
|
#[Computed]
|
|
public function feeTypes(): Collection
|
|
{
|
|
return FeeType::all(['id', 'name', 'ulid']);
|
|
}
|
|
|
|
#[Computed]
|
|
public function feeRates(): Collection
|
|
{
|
|
return FeeRate::where('admission_schedule_id', $this->admissionSchedule->id)
|
|
->get()
|
|
->mapWithKeys(function (FeeRate $rate) {
|
|
$key = "{$rate->study_program_id}_{$rate->academic_program_id}_{$rate->fee_type_id}";
|
|
|
|
$amount = $rate->amount;
|
|
|
|
return [
|
|
$key => $amount,
|
|
];
|
|
});
|
|
}
|
|
|
|
public function checkFeeSetup($studyId): bool
|
|
{
|
|
$requiredCount = count($this->academicPrograms) * count($this->feeTypes);
|
|
|
|
if ($requiredCount === 0) {
|
|
return false;
|
|
}
|
|
|
|
$filledCount = 0;
|
|
|
|
foreach ($this->academicPrograms as $program) {
|
|
foreach ($this->feeTypes as $fee) {
|
|
$lookupKey = "{$studyId}_{$program->id}_{$fee->id}";
|
|
$amount = $this->feeRates[$lookupKey] ?? '0';
|
|
|
|
if ($amount instanceof Money) {
|
|
$amount = $amount->toFloat();
|
|
}
|
|
|
|
if ($amount !== '0' && $amount !== 0 && ! empty($amount)) {
|
|
$filledCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $filledCount === $requiredCount;
|
|
}
|
|
|
|
public function setBadgeVariant(mixed $amount): string
|
|
{
|
|
if (is_int($amount) && $amount !== 0) {
|
|
return 'success';
|
|
}
|
|
|
|
if ($amount instanceof Money && $amount->toFloat() != 0) {
|
|
return 'success';
|
|
}
|
|
|
|
return 'danger';
|
|
}
|
|
|
|
public function updateFee(string $feeTypeId, string $programId, string $studyId, int $value, SetUpAdmissionFeeRates $setUpAdmissionFeeRates): true
|
|
{
|
|
$feeType = $this->feeTypes->where('ulid', $feeTypeId)->first();
|
|
$program = $this->academicPrograms->where('ulid', $programId)->first();
|
|
$study = $this->studyPrograms->where('ulid', $studyId)->first();
|
|
|
|
$setUpAdmissionFeeRates->execute(new AdmissionFeeRatesDTO(
|
|
academicProgramId: $program->id,
|
|
admissionScheduleId: $this->admissionSchedule->id,
|
|
studyProgramId: $study->id,
|
|
feeTypeId: $feeType->id,
|
|
amount: $value
|
|
));
|
|
$this->success(__('ui/crud.success.updated', ['resource' => __('ui/label.fee_type')]));
|
|
$this->dispatch('$refresh');
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|