StudentContract.php 7.7 KB

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