File: /var/www/matriculas_api_dev/app/Models/ContractDetail.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ContractDetail extends Model
{
protected $table = 'contracts_detail';
protected $fillable = [
'contract_id',
'student_id',
// Student snapshot fields
'student_rut',
'student_first_name',
'student_second_name',
'student_last_name',
'student_second_last_name',
'student_birth_date',
'student_gender_id',
'student_address',
'student_course_id',
'student_course_letter_id',
'student_family',
// Payment fields
'payment_concept_detail_id',
'amount',
'amount_regular',
'amount_exceptional',
'amount_cash',
'paid',
'paid_at',
'student_religion_classes',
'student_religion_program',
'student_create_institutional_mail',
'code_toku',
'toku_subscription_id',
'toku_debt_ids',
'toku_payment_id',
'enrollment_period_id',
];
protected $casts = [
'toku_debt_ids' => 'array',
];
public function contract()
{
return $this->belongsTo(Contract::class, 'contract_id');
}
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
public function paymentConceptDetail()
{
return $this->belongsTo(PaymentConceptDetail::class, 'payment_concept_detail_id');
}
public function enrollmentPeriod()
{
return $this->belongsTo(Period::class, 'enrollment_period_id');
}
// Relaciones para snapshot de curso
public function studentCourse()
{
return $this->belongsTo(Course::class, 'student_course_id');
}
public function studentCourseLetter()
{
return $this->belongsTo(CourseLetter::class, 'student_course_letter_id');
}
/**
* Construir array de snapshot del estudiante desde un modelo Student.
*/
public static function buildStudentSnapshot(Student $student): array
{
return [
'student_rut' => $student->rut,
'student_first_name' => $student->first_name,
'student_second_name' => $student->second_name,
'student_last_name' => $student->last_name,
'student_second_last_name' => $student->second_last_name,
'student_birth_date' => $student->birth_date,
'student_gender_id' => $student->gender_id,
'student_address' => $student->address,
'student_course_id' => $student->course_id,
'student_course_letter_id' => $student->course_letter_id,
'student_family' => $student->family,
];
}
// Relaciones con el modelo Users
public function createdBy()
{
return $this->belongsTo(User::class, 'user_created');
}
public function updatedBy()
{
return $this->belongsTo(User::class, 'user_updated');
}
public function deletedBy()
{
return $this->belongsTo(User::class, 'user_deleted');
}
}