StudentContract.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Database\Eloquent\Relations\HasMany;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. /**
  10. * @property int $id
  11. * @property string|null $protocol
  12. * @property int $student_id
  13. * @property int $unit_id
  14. * @property int|null $class_package_unit_id
  15. * @property \Illuminate\Support\Carbon|null $end_date
  16. * @property string|null $start_time
  17. * @property string|null $end_time
  18. * @property string|null $tax_register
  19. * @property string|null $fine_cancelled
  20. * @property string|null $notes
  21. * @property string $status
  22. * @property \Illuminate\Support\Carbon|null $created_at
  23. * @property \Illuminate\Support\Carbon|null $updated_at
  24. * @property \Illuminate\Support\Carbon|null $deleted_at
  25. * @property \Illuminate\Support\Carbon|null $signature_date
  26. * @property int|null $class_quantity
  27. * @property int|null $weekday
  28. * @property int|null $second_weekday
  29. * @property string|null $second_start_time
  30. * @property string|null $second_end_time
  31. * @property int|null $recurring_day
  32. * @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\StudentContractInstallment> $installments
  33. * @property string|null $early_payment_discount
  34. * @property string|null $interest_rate
  35. * @property string|null $payment_method
  36. * @property string|null $file_url
  37. * @property string|null $file_type
  38. * @property \Illuminate\Support\Carbon|null $enrollment_due_date
  39. * @property string|null $package_value
  40. * @property int|null $package_installments
  41. * @property \Illuminate\Support\Carbon|null $package_due_date
  42. * @property int $version
  43. * @property int|null $derived_from_contract_id
  44. * @property int|null $created_by_user_id
  45. * @property string|null $signed_file_url
  46. * @property string|null $signed_file_type
  47. * @property-read \App\Models\ClassPackageUnit|null $classPackageUnit
  48. * @property-read \App\Models\User|null $createdBy
  49. * @property-read StudentContract|null $derivedFrom
  50. * @property-read \Illuminate\Database\Eloquent\Collection<int, StudentContract> $derivedVersions
  51. * @property-read int|null $derived_versions_count
  52. * @property-read int|null $installments_count
  53. * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\StudentMedia> $medias
  54. * @property-read int|null $medias_count
  55. * @property-read \App\Models\Student $student
  56. * @property-read \App\Models\Unit $unit
  57. * @method static Builder<static>|StudentContract latestVersion()
  58. * @method static Builder<static>|StudentContract newModelQuery()
  59. * @method static Builder<static>|StudentContract newQuery()
  60. * @method static Builder<static>|StudentContract onlyTrashed()
  61. * @method static Builder<static>|StudentContract query()
  62. * @method static Builder<static>|StudentContract whereClassPackageUnitId($value)
  63. * @method static Builder<static>|StudentContract whereClassQuantity($value)
  64. * @method static Builder<static>|StudentContract whereCreatedAt($value)
  65. * @method static Builder<static>|StudentContract whereCreatedByUserId($value)
  66. * @method static Builder<static>|StudentContract whereDeletedAt($value)
  67. * @method static Builder<static>|StudentContract whereDerivedFromContractId($value)
  68. * @method static Builder<static>|StudentContract whereEarlyPaymentDiscount($value)
  69. * @method static Builder<static>|StudentContract whereEndDate($value)
  70. * @method static Builder<static>|StudentContract whereEndTime($value)
  71. * @method static Builder<static>|StudentContract whereEnrollmentDueDate($value)
  72. * @method static Builder<static>|StudentContract whereFileType($value)
  73. * @method static Builder<static>|StudentContract whereFileUrl($value)
  74. * @method static Builder<static>|StudentContract whereFineCancelled($value)
  75. * @method static Builder<static>|StudentContract whereId($value)
  76. * @method static Builder<static>|StudentContract whereInstallments($value)
  77. * @method static Builder<static>|StudentContract whereInterestRate($value)
  78. * @method static Builder<static>|StudentContract whereNotes($value)
  79. * @method static Builder<static>|StudentContract wherePackageDueDate($value)
  80. * @method static Builder<static>|StudentContract wherePackageInstallments($value)
  81. * @method static Builder<static>|StudentContract wherePackageValue($value)
  82. * @method static Builder<static>|StudentContract wherePaymentMethod($value)
  83. * @method static Builder<static>|StudentContract whereProtocol($value)
  84. * @method static Builder<static>|StudentContract whereRecurringDay($value)
  85. * @method static Builder<static>|StudentContract whereSecondEndTime($value)
  86. * @method static Builder<static>|StudentContract whereSecondStartTime($value)
  87. * @method static Builder<static>|StudentContract whereSecondWeekday($value)
  88. * @method static Builder<static>|StudentContract whereSignatureDate($value)
  89. * @method static Builder<static>|StudentContract whereSignedFileType($value)
  90. * @method static Builder<static>|StudentContract whereSignedFileUrl($value)
  91. * @method static Builder<static>|StudentContract whereStartTime($value)
  92. * @method static Builder<static>|StudentContract whereStatus($value)
  93. * @method static Builder<static>|StudentContract whereStudentId($value)
  94. * @method static Builder<static>|StudentContract whereTaxRegister($value)
  95. * @method static Builder<static>|StudentContract whereUnitId($value)
  96. * @method static Builder<static>|StudentContract whereUpdatedAt($value)
  97. * @method static Builder<static>|StudentContract whereVersion($value)
  98. * @method static Builder<static>|StudentContract whereWeekday($value)
  99. * @method static Builder<static>|StudentContract withTrashed(bool $withTrashed = true)
  100. * @method static Builder<static>|StudentContract withoutTrashed()
  101. * @mixin \Eloquent
  102. */
  103. class StudentContract extends Model
  104. {
  105. use HasFactory, SoftDeletes;
  106. protected $table = 'student_contracts';
  107. protected $guarded = ['id'];
  108. protected $casts = [
  109. 'version' => 'integer',
  110. 'signature_date' => 'date:Y-m-d',
  111. 'end_date' => 'date:Y-m-d',
  112. 'enrollment_due_date' => 'date:Y-m-d',
  113. 'package_due_date' => 'date:Y-m-d',
  114. 'created_at' => 'datetime',
  115. 'updated_at' => 'datetime',
  116. ];
  117. public function scopeLatestVersion(Builder $query): Builder
  118. {
  119. return $query->whereDoesntHave(
  120. 'derivedVersions',
  121. fn (Builder $derivedQuery) => $derivedQuery->withTrashed(),
  122. );
  123. }
  124. public function derivedFrom(): BelongsTo
  125. {
  126. return $this->belongsTo(self::class, 'derived_from_contract_id');
  127. }
  128. public function derivedVersions(): HasMany
  129. {
  130. return $this->hasMany(self::class, 'derived_from_contract_id');
  131. }
  132. public function createdBy(): BelongsTo
  133. {
  134. return $this->belongsTo(User::class, 'created_by_user_id');
  135. }
  136. public function student(): BelongsTo
  137. {
  138. return $this->belongsTo(Student::class);
  139. }
  140. public function unit(): BelongsTo
  141. {
  142. return $this->belongsTo(Unit::class);
  143. }
  144. public function classPackageUnit(): BelongsTo
  145. {
  146. return $this->belongsTo(ClassPackageUnit::class);
  147. }
  148. public function medias(): HasMany
  149. {
  150. return $this->hasMany(StudentMedia::class);
  151. }
  152. public function installments(): HasMany
  153. {
  154. return $this->hasMany(StudentContractInstallment::class);
  155. }
  156. }