Pro.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. class Pro extends Model
  5. {
  6. protected $table = 'pro';
  7. public function displayName() {
  8. $name = [];
  9. if(!empty($this->name_last)) $name[] = $this->name_last;
  10. if(!empty($this->name_first)) $name[] = $this->name_first;
  11. if(!count($name)) {
  12. $name = $this->name_display;
  13. }
  14. else {
  15. $name = implode(", ", $name);
  16. }
  17. return $name;
  18. }
  19. public function cmBills()
  20. {
  21. return $this->hasMany(Bill::class, 'cm_pro_id');
  22. }
  23. public function hcpBills()
  24. {
  25. return $this->hasMany(Bill::class, 'hcp_pro_id');
  26. }
  27. public function lastPayment() {
  28. return ProTransaction
  29. ::where('pro_id', $this->id)
  30. ->where('plus_or_minus', 'PLUS')
  31. ->orderBy('created_at', 'desc')
  32. ->first();
  33. }
  34. public function hasRates() {
  35. $numRates = ProRate::where('is_active', true)->where('pro_id', $this->id)->count();
  36. return $numRates > 0;
  37. }
  38. }