StudentContract.php 7.6 KB

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