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.
108 lines
3.9 KiB
108 lines
3.9 KiB
<?php
|
|
|
|
namespace App\Domains\Admission\Integration\Mappers;
|
|
|
|
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 Illuminate\Database\Eloquent\Model;
|
|
use App\Domains\System\Support\Contract\DataPayloadMapper;
|
|
|
|
class FeeRateDataMapper implements DataPayloadMapper
|
|
{
|
|
private static array $cache = [];
|
|
|
|
public function __construct(
|
|
protected SetUpAdmissionFeeRates $setUpAdmissionFeeRates,
|
|
)
|
|
{
|
|
// Inject required Domain and Cross-Domain Actions via constructor composition
|
|
}
|
|
|
|
public function getLookupKey(): array
|
|
{
|
|
// Return the unique string key used to identify existing records (e.g., 'email')
|
|
return ['admission_schedule_id', 'fee_type_id', 'academic_program_id'];
|
|
}
|
|
|
|
public function transform(array $rawData): array
|
|
{
|
|
if(!isset($rawData['jalur'])){
|
|
dd($rawData);
|
|
}
|
|
// Normalize incoming data array formats into an internal domain-safe layout
|
|
return [
|
|
'admission_schedule_id' => $this->resolveAdmissionScheduleId($rawData['jalur'], $rawData['angkatan']),
|
|
'academic_program_id' => $this->resolveAcademicProgramId($rawData['kode_Skuliah']),
|
|
'study_program_id' => $this->resolveStudyProgramId($rawData['kode_prodi']),
|
|
'fee_type_id'=> $this->resolveFeeTypeId($rawData['kode_Jtagihan']),
|
|
'amount' => $rawData['nominal_TRFtagihan'],
|
|
];
|
|
}
|
|
|
|
public function updateOrCreateDomainState(array $payload, ?Model $existingModel = null): void
|
|
{
|
|
$this->setUpAdmissionFeeRates->execute(new AdmissionFeeRatesDTO(
|
|
academicProgramId: $payload['academic_program_id'],
|
|
admissionScheduleId: $payload['admission_schedule_id'],
|
|
studyProgramId: $payload['study_program_id'],
|
|
feeTypeId: $payload['fee_type_id'],
|
|
amount: $payload['amount'],
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @return class-string
|
|
*/
|
|
public function getModelClass(): string
|
|
{
|
|
return FeeRate::class;
|
|
}
|
|
|
|
public function resolveAdmissionScheduleId(string $admissionTrackSlug, int $yearStudy): int {
|
|
$key = hex2bin(md5("{$admissionTrackSlug}-{$yearStudy}") );
|
|
if (!isset(self::$cache['admission_schedule'][$key])) {
|
|
self::$cache['admission_schedule'][$key] = AdmissionSchedule::query()
|
|
->whereHas(
|
|
'admissionTrack',
|
|
fn($builder) => $builder->where('slug', str($admissionTrackSlug)->slug())
|
|
)->whereHas(
|
|
'term',
|
|
fn($builder) => $builder->where('year_study', $yearStudy)
|
|
)->first()?->id;
|
|
}
|
|
|
|
return self::$cache['admission_schedule'][$key];
|
|
}
|
|
|
|
public function resolveStudyProgramId($code): int {
|
|
if (!isset(self::$cache['study_program'][$code])) {
|
|
self::$cache['study_program'][$code] = StudyProgram::where('code', $code)->first()?->id;
|
|
}
|
|
|
|
return self::$cache['study_program'][$code];
|
|
}
|
|
|
|
public function resolveFeeTypeId(string $code): int {
|
|
$key = hex2bin(md5($code));
|
|
if (!isset(self::$cache['fee_type'][$key])) {
|
|
self::$cache['fee_type'][$key] = FeeType::where('code', $code)->first()?->id;
|
|
}
|
|
|
|
return self::$cache['fee_type'][$key];
|
|
}
|
|
|
|
|
|
public function resolveAcademicProgramId(string $code): int {
|
|
$key = hex2bin(md5($code));
|
|
if (!isset(self::$cache['academic_program'][$key])) {
|
|
self::$cache['academic_program'][$key] = AcademicProgram::where('code', $code)->first()?->id;
|
|
}
|
|
|
|
return self::$cache['academic_program'][$key];
|
|
}
|
|
}
|
|
|