Pro.php 923 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. }